aboutsummaryrefslogtreecommitdiff
path: root/basebuilder-3.6.2/org.eclipse.releng.basebuilder/plugins/org.eclipse.build.tools/src/org/eclipse/releng/ElementParser.java
blob: 01430e9ee764d6a6ab1406047cc2c3a17bc6fd40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/**
 * Parses feature.xml, plugin.xml, and fragment.xml files
 *
 */

package org.eclipse.releng;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.util.Vector;
import java.io.File;
import org.apache.tools.ant.BuildException;


public class ElementParser extends DefaultHandler {

	private SAXParser parser;
	private Vector plugins;	
	private Vector features;

	public Vector getPlugins(){return plugins;}
	public Vector getFeatures(){return features;}

    public ElementParser() {
        //  Create a Xerces SAX Parser
    	SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    	
    	try {
			parser = saxParserFactory.newSAXParser();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
		} catch (SAXException e) {
			e.printStackTrace();
		}
    	
        
        
        // instantiate vectors that will hold lists of plugins and features read from feature.xml
        plugins = new Vector();
        features = new Vector();
    }
    
    public void parse(String xmlFile){
			
	    //  Parse the Document      
        try {
            parser.parse(xmlFile,this);
        } catch (SAXException e) {
            System.err.println (e);
        } catch (IOException e) {
            System.err.println (e);
          
        }
    }

	public void parse(String install, String type, String id){
				
		String xmlFile=null;		
		
		if (type.equals("feature"))
			xmlFile=install+"/features/"+id+"/"+"feature.xml";
		if (type.equals("plugin"))
			xmlFile=install+"/plugins/"+id+"/"+"plugin.xml";
		if (type.equals("fragment"))
			xmlFile=install+"/plugins/"+"/"+id+"/"+"fragment.xml";

		if (new File(xmlFile).exists())	
			parse(xmlFile);
		
		else{
			throw new BuildException("The following "+type+" "+id+" did not get fetched.");
		}
	
	}
    
    //  Start Element Event Handler
    public void startElement (String uri, String local,
        String qName, Attributes atts)  {
        if (local.equals("plugin")||local.equals("fragment"))
    		add(atts.getValue("id"), plugins);
    	if (local.equals("feature"))
    		add(atts.getValue("id")+"-feature", features);
    }
    
    public void add(String element, Vector v){
    	if (!v.contains(element))
    		v.add(element);
    }
    
    // Test
    public static void main (String[] args) {
        ElementParser xmlParser = new ElementParser();
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.win32-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.linux.motif-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.linux.gtk-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.solaris.motif-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.aix.motif-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.qnx.photon-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.jdt-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.pde-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.sdk.examples-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.sdk.tests-feature");

        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.win32.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.linux.motif.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.linux.gtk.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.solaris.motif.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.aix.motif.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.platform.qnx.photon.source-feature");
        xmlParser.parse("l:/vabase/team/sonia", "feature", "org.eclipse.jdt.source-feature");

        System.out.println(xmlParser.plugins);
        System.out.println(xmlParser.features);
        
        System.out.println(xmlParser.plugins.size()+" plugins expected");
        System.out.println(xmlParser.features.size()+" features expected");
    }
}