587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.ant.data;
|
|
19 |
|
|
20 |
import java.io.File;
|
628
|
21 |
import java.io.FileReader;
|
587
|
22 |
import java.io.IOException;
|
|
23 |
import java.util.ArrayList;
|
|
24 |
import java.util.List;
|
|
25 |
|
|
26 |
import org.apache.tools.ant.Project;
|
|
27 |
import org.dom4j.Document;
|
|
28 |
import org.dom4j.Element;
|
|
29 |
import org.dom4j.Node;
|
628
|
30 |
import org.xml.sax.InputSource;
|
|
31 |
import org.xml.sax.SAXException;
|
|
32 |
import org.xml.sax.XMLReader;
|
|
33 |
import org.xml.sax.helpers.XMLReaderFactory;
|
587
|
34 |
|
|
35 |
/**
|
|
36 |
* An Ant build file. It could be a project file or an antlib file.
|
|
37 |
*/
|
|
38 |
public class AntFile {
|
|
39 |
private Database database;
|
|
40 |
private File path;
|
|
41 |
private Document doc;
|
|
42 |
private RootAntObjectMeta fileObjectMeta;
|
|
43 |
private Project rootProject;
|
|
44 |
|
|
45 |
public AntFile(Database database, String path) throws IOException {
|
|
46 |
this(database, path, Database.DEFAULT_SCOPE);
|
|
47 |
}
|
|
48 |
|
|
49 |
public AntFile(Database database, String path, String scope) throws IOException {
|
|
50 |
this.database = database;
|
|
51 |
this.path = new File(path);
|
628
|
52 |
|
|
53 |
readDoc();
|
|
54 |
Element node = doc.getRootElement();
|
|
55 |
if (node.getName().equals("project")) {
|
|
56 |
fileObjectMeta = new ProjectMeta(this, node);
|
|
57 |
}
|
|
58 |
else {
|
|
59 |
fileObjectMeta = new AntlibMeta(this, node);
|
|
60 |
}
|
|
61 |
|
|
62 |
fileObjectMeta.setScopeFilter(scope);
|
|
63 |
fileObjectMeta.setRuntimeProject(rootProject);
|
587
|
64 |
|
628
|
65 |
}
|
587
|
66 |
|
628
|
67 |
private void readDoc() throws IOException {
|
|
68 |
try {
|
|
69 |
DocumentFactoryWithLocator documentFactory = new DocumentFactoryWithLocator();
|
|
70 |
SAXContentHandlerExt contentHandler = new SAXContentHandlerExt(documentFactory);
|
|
71 |
documentFactory.setContentHandler(contentHandler);
|
|
72 |
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
|
|
73 |
xmlReader.setContentHandler(contentHandler);
|
|
74 |
xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", contentHandler);
|
|
75 |
xmlReader.parse(new InputSource(new FileReader(path)));
|
|
76 |
doc = contentHandler.getDocument();
|
587
|
77 |
}
|
628
|
78 |
catch (SAXException e) {
|
587
|
79 |
throw new IOException(e.getMessage());
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
public Project getProject() {
|
|
84 |
return rootProject;
|
|
85 |
}
|
|
86 |
|
|
87 |
public void setProject(Project project) {
|
|
88 |
this.rootProject = project;
|
|
89 |
fileObjectMeta.setRuntimeProject(rootProject);
|
|
90 |
}
|
|
91 |
|
|
92 |
public void setScope(String scope) {
|
|
93 |
fileObjectMeta.setScopeFilter(scope);
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Get the meta object for the Ant project in this build file.
|
|
98 |
*
|
|
99 |
* @return The project meta object.
|
|
100 |
*/
|
628
|
101 |
public RootAntObjectMeta getRootObjectMeta() {
|
587
|
102 |
return fileObjectMeta;
|
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* The File path of the Ant file.
|
|
107 |
*
|
|
108 |
* @return Path.
|
|
109 |
*/
|
|
110 |
public File getFile() {
|
|
111 |
return path;
|
|
112 |
}
|
|
113 |
|
|
114 |
public Database getDatabase() {
|
|
115 |
return database;
|
|
116 |
}
|
|
117 |
|
|
118 |
@SuppressWarnings("unchecked")
|
|
119 |
public List<AntFile> getAntlibs() throws IOException {
|
|
120 |
Element node = doc.getRootElement();
|
|
121 |
List<AntFile> antlibFiles = new ArrayList<AntFile>();
|
|
122 |
if (node.getName().equals("project")) {
|
628
|
123 |
List<Node> typedefs = node.selectNodes("//*[namespace-uri()='http://www.nokia.com/helium' and local-name()='typedef']");
|
587
|
124 |
for (Node typedefNode : typedefs) {
|
|
125 |
String filePath = ((Element) typedefNode).attributeValue("file");
|
|
126 |
filePath = getProject().replaceProperties(filePath);
|
|
127 |
antlibFiles.add(new AntFile(database, filePath));
|
|
128 |
}
|
|
129 |
}
|
|
130 |
return antlibFiles;
|
|
131 |
}
|
|
132 |
}
|