587
|
1 |
/*
|
628
|
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 |
|
587
|
18 |
package com.nokia.ant;
|
|
19 |
|
|
20 |
import info.bliki.wiki.model.WikiModel;
|
|
21 |
|
|
22 |
import java.io.BufferedReader;
|
|
23 |
import java.io.File;
|
|
24 |
import java.io.FileOutputStream;
|
|
25 |
import java.io.IOException;
|
|
26 |
import java.io.OutputStream;
|
|
27 |
import java.io.StringReader;
|
|
28 |
import java.util.ArrayList;
|
|
29 |
import java.util.Enumeration;
|
|
30 |
import java.util.HashMap;
|
|
31 |
import java.util.Hashtable;
|
|
32 |
import java.util.Iterator;
|
|
33 |
import java.util.List;
|
|
34 |
import java.util.Map;
|
|
35 |
import java.util.regex.Matcher;
|
|
36 |
import java.util.regex.Pattern;
|
|
37 |
|
|
38 |
import org.apache.tools.ant.BuildException;
|
|
39 |
import org.apache.tools.ant.Project;
|
|
40 |
import org.apache.tools.ant.Target;
|
|
41 |
import org.apache.tools.ant.Task;
|
|
42 |
import org.apache.tools.ant.types.Reference;
|
|
43 |
import org.apache.tools.ant.types.ResourceCollection;
|
|
44 |
import org.apache.tools.ant.types.resources.FileResource;
|
|
45 |
import org.dom4j.Attribute;
|
|
46 |
import org.dom4j.CDATA;
|
|
47 |
import org.dom4j.Comment;
|
|
48 |
import org.dom4j.Document;
|
|
49 |
import org.dom4j.DocumentException;
|
|
50 |
import org.dom4j.DocumentHelper;
|
|
51 |
import org.dom4j.Element;
|
|
52 |
import org.dom4j.Node;
|
|
53 |
import org.dom4j.Text;
|
|
54 |
import org.dom4j.Visitor;
|
|
55 |
import org.dom4j.VisitorSupport;
|
|
56 |
import org.dom4j.XPath;
|
|
57 |
import org.dom4j.io.OutputFormat;
|
|
58 |
import org.dom4j.io.SAXReader;
|
|
59 |
import org.dom4j.io.XMLWriter;
|
|
60 |
|
|
61 |
/**
|
|
62 |
* Reads the current ant project and a fileset and generates a xml file with a summary of targets,
|
|
63 |
* macros and properties.
|
|
64 |
*/
|
628
|
65 |
public class Database {
|
587
|
66 |
private Project project;
|
|
67 |
private ResourceCollection rc;
|
|
68 |
private Task task;
|
|
69 |
private boolean debug;
|
|
70 |
private boolean homeFilesOnly = true;
|
|
71 |
private HashMap<String, List<String>> globalSignalList = new HashMap<String, List<String>>();
|
|
72 |
private HashMap<String, String> map = new HashMap<String, String>();
|
|
73 |
private Document signaldoc;
|
628
|
74 |
|
|
75 |
public Database(Project project, ResourceCollection rc, Task task) {
|
587
|
76 |
this.project = project;
|
|
77 |
this.rc = rc;
|
|
78 |
this.task = task;
|
|
79 |
map.put("hlm", "http://www.nokia.com/helium");
|
|
80 |
}
|
|
81 |
|
|
82 |
public Project getProject() {
|
|
83 |
return project;
|
|
84 |
}
|
|
85 |
|
|
86 |
public void setDebug(boolean debug) {
|
|
87 |
this.debug = debug;
|
|
88 |
}
|
|
89 |
|
|
90 |
public void setHomeFilesOnly(boolean homeFilesOnly) {
|
|
91 |
this.homeFilesOnly = homeFilesOnly;
|
|
92 |
}
|
|
93 |
|
|
94 |
public void log(String msg, int level) {
|
|
95 |
if (task != null) {
|
|
96 |
task.log(msg, level);
|
628
|
97 |
}
|
|
98 |
else if (debug) {
|
587
|
99 |
project.log(msg, level);
|
|
100 |
}
|
|
101 |
}
|
|
102 |
|
628
|
103 |
public void setRefid(Reference r) {
|
588
|
104 |
Object object = r.getReferencedObject();
|
628
|
105 |
if (!(object instanceof ResourceCollection)) {
|
587
|
106 |
throw new BuildException(r.getRefId() + " doesn\'t denote a ResourceCollection");
|
|
107 |
}
|
588
|
108 |
rc = (ResourceCollection) object;
|
587
|
109 |
}
|
|
110 |
|
|
111 |
public Document createDOM() throws DocumentException, IOException {
|
628
|
112 |
// log("Building Ant project database", Project.MSG_DEBUG);
|
587
|
113 |
Element root = DocumentHelper.createElement("antDatabase");
|
|
114 |
Document outDoc = DocumentHelper.createDocument(root);
|
|
115 |
ArrayList<String> antFiles = getAntFiles(getProject(), homeFilesOnly);
|
628
|
116 |
for (String antFile : antFiles) {
|
|
117 |
readSignals(antFile);
|
587
|
118 |
}
|
628
|
119 |
for (String antFile : antFiles) {
|
587
|
120 |
parseAntFile(root, antFile);
|
|
121 |
}
|
|
122 |
|
|
123 |
buildTaskDefs(root);
|
|
124 |
|
|
125 |
return outDoc;
|
|
126 |
}
|
|
127 |
|
|
128 |
public void createXMLFile(File outputFile) {
|
|
129 |
try {
|
|
130 |
Document outDoc = createDOM();
|
|
131 |
OutputStream outStream = System.out;
|
|
132 |
if (outputFile != null) {
|
|
133 |
outStream = new FileOutputStream(outputFile);
|
|
134 |
}
|
|
135 |
XMLWriter out = new XMLWriter(outStream, OutputFormat.createPrettyPrint());
|
|
136 |
out.write(outDoc);
|
628
|
137 |
}
|
|
138 |
catch (DocumentException e) {
|
587
|
139 |
throw new BuildException(e.getMessage());
|
628
|
140 |
}
|
|
141 |
catch (IOException e) {
|
587
|
142 |
throw new BuildException(e.getMessage());
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
|
146 |
@SuppressWarnings("unchecked")
|
628
|
147 |
private void readSignals(String antFile) throws DocumentException, IOException {
|
587
|
148 |
SAXReader xmlReader = new SAXReader();
|
|
149 |
Document antDoc = xmlReader.read(new File(antFile));
|
|
150 |
|
|
151 |
XPath xpath = DocumentHelper.createXPath("//hlm:signalListenerConfig");
|
|
152 |
xpath.setNamespaceURIs(map);
|
|
153 |
List<Element> signalNodes = xpath.selectNodes(antDoc);
|
628
|
154 |
for (Element propertyNode : signalNodes) {
|
587
|
155 |
signaldoc = antDoc;
|
|
156 |
String signalid = propertyNode.attributeValue("id");
|
|
157 |
|
|
158 |
String signaltarget = propertyNode.attributeValue("target");
|
|
159 |
List<String> existinglist = globalSignalList.get(signaltarget);
|
|
160 |
String failbuild = signalType(signalid, signaldoc);
|
628
|
161 |
if (existinglist == null) {
|
587
|
162 |
existinglist = new ArrayList<String>();
|
628
|
163 |
}
|
587
|
164 |
existinglist.add(signalid + "," + failbuild);
|
|
165 |
globalSignalList.put(signaltarget, existinglist);
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
@SuppressWarnings("unchecked")
|
628
|
170 |
private String signalType(String signalid, Document antDoc) {
|
|
171 |
XPath xpath2 = DocumentHelper.createXPath("//hlm:signalListenerConfig[@id='" + signalid
|
|
172 |
+ "']/signalNotifierInput/signalInput");
|
587
|
173 |
xpath2.setNamespaceURIs(map);
|
|
174 |
List<Element> signalNodes3 = xpath2.selectNodes(antDoc);
|
|
175 |
|
628
|
176 |
for (Element propertyNode3 : signalNodes3) {
|
587
|
177 |
String signalinputid = propertyNode3.attributeValue("refid");
|
|
178 |
|
628
|
179 |
XPath xpath3 = DocumentHelper.createXPath("//hlm:signalInput[@id='" + signalinputid
|
|
180 |
+ "']");
|
587
|
181 |
xpath3.setNamespaceURIs(map);
|
|
182 |
List<Element> signalNodes4 = xpath3.selectNodes(antDoc);
|
628
|
183 |
for (Element propertyNode4 : signalNodes4) {
|
587
|
184 |
return propertyNode4.attributeValue("failbuild");
|
|
185 |
}
|
|
186 |
}
|
|
187 |
return null;
|
|
188 |
}
|
|
189 |
|
|
190 |
/**
|
|
191 |
* @param root
|
|
192 |
* @param antFile
|
|
193 |
* @throws DocumentException
|
|
194 |
* @throws IOException
|
|
195 |
*/
|
|
196 |
@SuppressWarnings("unchecked")
|
628
|
197 |
private void parseAntFile(Element root, String antFile) throws DocumentException, IOException {
|
587
|
198 |
log("Processing Ant file: " + antFile, Project.MSG_DEBUG);
|
|
199 |
SAXReader xmlReader = new SAXReader();
|
|
200 |
Document antDoc = xmlReader.read(new File(antFile));
|
|
201 |
|
|
202 |
// Element targetElement =
|
|
203 |
// DocumentHelper.createElement("target");
|
|
204 |
Element projectElement = root.addElement("project");
|
|
205 |
Element nameElement = projectElement.addElement("name");
|
|
206 |
String projectName = antDoc.valueOf("/project/@name");
|
|
207 |
|
|
208 |
nameElement.setText(projectName);
|
|
209 |
// Element descriptionElement =
|
|
210 |
// projectElement.addElement("description");
|
|
211 |
|
|
212 |
String description = antDoc.valueOf("/project/description");
|
|
213 |
insertDocumentation(projectElement, description);
|
|
214 |
|
|
215 |
// descriptionElement.setText(description);
|
|
216 |
|
628
|
217 |
if (!antFile.contains("antlib.xml") && description.equals("")) {
|
587
|
218 |
log("Project has no comment: " + projectName, Project.MSG_WARN);
|
|
219 |
}
|
|
220 |
|
|
221 |
Element defaultElement = projectElement.addElement("default");
|
|
222 |
defaultElement.setText(antDoc.valueOf("/project/@default"));
|
|
223 |
|
|
224 |
// Project import statements
|
|
225 |
List importNodes = antDoc.selectNodes("//import");
|
628
|
226 |
for (Iterator iterator = importNodes.iterator(); iterator.hasNext();) {
|
587
|
227 |
Element importCurrentNode = (Element) iterator.next();
|
628
|
228 |
addTextElement(projectElement, "fileDependency", importCurrentNode.attributeValue("file"));
|
587
|
229 |
}
|
|
230 |
|
|
231 |
projectElement.addElement("pythonDependency");
|
|
232 |
|
|
233 |
// Project exec statements
|
|
234 |
List<Element> execNodes = antDoc.selectNodes("//exec//arg");
|
628
|
235 |
for (Element argNode : execNodes) {
|
587
|
236 |
String argValue = argNode.attributeValue("value");
|
|
237 |
|
628
|
238 |
if (argValue == null) {
|
587
|
239 |
argValue = argNode.attributeValue("line");
|
628
|
240 |
}
|
587
|
241 |
|
628
|
242 |
if (argValue != null) {
|
587
|
243 |
Pattern filePattern = Pattern.compile(".pl|.py|.bat|.xml|.txt");
|
|
244 |
Matcher fileMatcher = filePattern.matcher(argValue);
|
628
|
245 |
if (fileMatcher.find()) {
|
587
|
246 |
addTextElement(projectElement, "fileDependency", argValue);
|
|
247 |
}
|
|
248 |
}
|
|
249 |
}
|
|
250 |
|
|
251 |
List<Element> targetNodes = antDoc.selectNodes("//target");
|
628
|
252 |
for (Element targetNode : targetNodes) {
|
587
|
253 |
processTarget(targetNode, projectElement);
|
|
254 |
}
|
|
255 |
|
|
256 |
// Process macrodef and scriptdef tasks
|
|
257 |
// TODO - maybe scriptdefs should be separate?
|
|
258 |
List macroNodes = antDoc.selectNodes("//macrodef | //scriptdef");
|
628
|
259 |
for (Iterator iterator = macroNodes.iterator(); iterator.hasNext();) {
|
587
|
260 |
Element macroNode = (Element) iterator.next();
|
|
261 |
processMacro(macroNode, projectElement, antFile);
|
|
262 |
}
|
|
263 |
|
|
264 |
// Project properties
|
|
265 |
List propertyNodes = antDoc.selectNodes("//property");
|
628
|
266 |
for (Iterator iterator = propertyNodes.iterator(); iterator.hasNext();) {
|
587
|
267 |
Element propertyNode = (Element) iterator.next();
|
|
268 |
processProperty(propertyNode, projectElement);
|
|
269 |
}
|
|
270 |
}
|
|
271 |
|
628
|
272 |
public ArrayList<String> getAntFiles() {
|
587
|
273 |
return getAntFiles(getProject(), true);
|
|
274 |
}
|
|
275 |
|
628
|
276 |
public ArrayList<String> getAntFiles(Project project) {
|
587
|
277 |
return getAntFiles(project, true);
|
|
278 |
}
|
|
279 |
|
|
280 |
/**
|
628
|
281 |
* Get the list of all Ant files we want to process. These can be project and antlib files.
|
587
|
282 |
*
|
|
283 |
* @return antFiles a list of ant files to be processed
|
|
284 |
*/
|
|
285 |
@SuppressWarnings("unchecked")
|
628
|
286 |
public ArrayList<String> getAntFiles(Project project, boolean homeOnly) {
|
587
|
287 |
ArrayList<String> antFiles = new ArrayList<String>();
|
|
288 |
|
|
289 |
Map<String, Target> targets = project.getTargets();
|
|
290 |
Iterator<Target> targetsIter = targets.values().iterator();
|
|
291 |
|
|
292 |
String projectHome = null;
|
|
293 |
try {
|
|
294 |
projectHome = new File(project.getProperty("helium.dir")).getCanonicalPath();
|
|
295 |
|
628
|
296 |
while (targetsIter.hasNext()) {
|
587
|
297 |
Target target = targetsIter.next();
|
|
298 |
String projectPath = new File(target.getLocation().getFileName()).getCanonicalPath();
|
|
299 |
|
628
|
300 |
if (!antFiles.contains(projectPath)) {
|
|
301 |
if (homeOnly) {
|
|
302 |
if (!projectPath.contains(projectHome)) {
|
587
|
303 |
antFiles.add(projectPath);
|
|
304 |
}
|
628
|
305 |
} else {
|
587
|
306 |
antFiles.add(projectPath);
|
|
307 |
}
|
|
308 |
}
|
|
309 |
}
|
|
310 |
|
628
|
311 |
if (rc != null) {
|
|
312 |
Iterator extraFilesIter = rc.iterator();
|
|
313 |
while (extraFilesIter.hasNext()) {
|
|
314 |
FileResource fileResource = (FileResource) extraFilesIter.next();
|
|
315 |
String extrafile = fileResource.getFile().getCanonicalPath();
|
|
316 |
|
|
317 |
if (!antFiles.contains(fileResource.toString())
|
|
318 |
&& !fileResource.getFile().getName().startsWith("test_")) {
|
|
319 |
if (homeOnly) {
|
|
320 |
if (!extrafile.contains(projectHome)) {
|
|
321 |
antFiles.add(extrafile);
|
|
322 |
}
|
|
323 |
}
|
|
324 |
else {
|
|
325 |
antFiles.add(extrafile);
|
|
326 |
}
|
|
327 |
}
|
|
328 |
}
|
|
329 |
}
|
|
330 |
|
|
331 |
}
|
|
332 |
catch (IOException e) {
|
|
333 |
log(e.getMessage(), Project.MSG_ERR);
|
587
|
334 |
e.printStackTrace();
|
|
335 |
}
|
|
336 |
return antFiles;
|
|
337 |
}
|
|
338 |
|
628
|
339 |
// --------------------------------- PRIVATE METHODS ------------------------------------------
|
587
|
340 |
|
|
341 |
@SuppressWarnings("unchecked")
|
|
342 |
private void processMacro(Element macroNode, Element outProjectNode, String antFile)
|
628
|
343 |
throws IOException, DocumentException {
|
587
|
344 |
String macroName = macroNode.attributeValue("name");
|
|
345 |
log("Processing macro: " + macroName, Project.MSG_DEBUG);
|
|
346 |
|
|
347 |
Element outmacroNode = outProjectNode.addElement("macro");
|
|
348 |
addTextElement(outmacroNode, "name", macroNode.attributeValue("name"));
|
|
349 |
addTextElement(outmacroNode, "description", macroNode.attributeValue("description"));
|
|
350 |
|
|
351 |
// Add location
|
|
352 |
// Project project = getProject();
|
|
353 |
// Macro antmacro = (Macro) project.getTargets().get(macroName);
|
|
354 |
// System.out.println(project.getMacroDefinitions());
|
|
355 |
// System.out.println(macroName);
|
|
356 |
// MacroInstance antmacro = (MacroInstance)
|
|
357 |
// project.getMacroDefinitions().get("http://www.nokia.com/helium:" +
|
|
358 |
// macroName);
|
|
359 |
|
|
360 |
// Add the location with just the file path for now and a dummy line
|
|
361 |
// number.
|
|
362 |
// TODO - Later we should find the line number from the XML input.
|
|
363 |
addTextElement(outmacroNode, "location", antFile + ":1:");
|
|
364 |
|
628
|
365 |
List<Node> statements = macroNode.selectNodes("//scriptdef[@name='" + macroName
|
|
366 |
+ "']/attribute | //macrodef[@name='" + macroName + "']/attribute");
|
587
|
367 |
String usage = "";
|
628
|
368 |
for (Node statement : statements) {
|
587
|
369 |
String defaultval = statement.valueOf("@default");
|
628
|
370 |
if (defaultval.equals("")) {
|
587
|
371 |
defaultval = "value";
|
628
|
372 |
} else {
|
587
|
373 |
defaultval = "<i>" + defaultval + "</i>";
|
628
|
374 |
}
|
587
|
375 |
usage = usage + " " + statement.valueOf("@name") + "=\"" + defaultval + "\"";
|
|
376 |
}
|
|
377 |
|
|
378 |
String macroElements = "";
|
628
|
379 |
statements = macroNode.selectNodes("//scriptdef[@name='" + macroName
|
|
380 |
+ "']/element | //macrodef[@name='" + macroName + "']/element");
|
|
381 |
for (Node statement : statements) {
|
587
|
382 |
macroElements = "<" + statement.valueOf("@name") + "/>\n" + macroElements;
|
|
383 |
}
|
628
|
384 |
if (macroElements.equals("")) {
|
587
|
385 |
addTextElement(outmacroNode, "usage", "<hlm:" + macroName + " " + usage + "/>");
|
628
|
386 |
} else {
|
|
387 |
addTextElement(outmacroNode, "usage", "<hlm:" + macroName + " " + usage + ">\n"
|
|
388 |
+ macroElements + "</hlm:" + macroName + ">");
|
|
389 |
}
|
587
|
390 |
|
|
391 |
// Add dependencies
|
|
392 |
// Enumeration dependencies = antmacro.getDependencies();
|
|
393 |
// while (dependencies.hasMoreElements())
|
|
394 |
// {
|
|
395 |
// String dependency = (String) dependencies.nextElement();
|
|
396 |
// Element dependencyElement = addTextElement(outmacroNode,
|
|
397 |
// "dependency", dependency);
|
|
398 |
// dependencyElement.addAttribute("type","direct");
|
|
399 |
// }
|
|
400 |
|
628
|
401 |
callAntTargetVisitor(macroNode, outmacroNode);
|
587
|
402 |
|
|
403 |
// Add documentation
|
|
404 |
// Get comment element before the macro element to extract macro doc
|
|
405 |
List<Node> children = macroNode.selectNodes("preceding-sibling::node()");
|
628
|
406 |
if (children.size() > 0) {
|
587
|
407 |
// Scan past the text nodes, which are most likely whitespace
|
|
408 |
int index = children.size() - 1;
|
|
409 |
Node child = (Node) children.get(index);
|
628
|
410 |
while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
|
587
|
411 |
index--;
|
|
412 |
child = (Node) children.get(index);
|
|
413 |
}
|
|
414 |
|
|
415 |
// Check if there is a comment node
|
|
416 |
String commentText = null;
|
628
|
417 |
if (child.getNodeType() == Node.COMMENT_NODE) {
|
587
|
418 |
Comment macroComment = (Comment) child;
|
|
419 |
commentText = macroComment.getStringValue().trim();
|
|
420 |
log(macroName + " comment: " + commentText, Project.MSG_DEBUG);
|
|
421 |
}
|
628
|
422 |
else {
|
587
|
423 |
log("Macro has no comment: " + macroName, Project.MSG_WARN);
|
|
424 |
}
|
|
425 |
|
|
426 |
insertDocumentation(outmacroNode, commentText);
|
|
427 |
}
|
|
428 |
|
|
429 |
// Get names of all properties used in this macro
|
|
430 |
ArrayList properties = new ArrayList();
|
|
431 |
Visitor visitor = new AntPropertyVisitor(properties);
|
|
432 |
macroNode.accept(visitor);
|
628
|
433 |
for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
|
587
|
434 |
String property = (String) iterator.next();
|
|
435 |
addTextElement(outmacroNode, "propertyDependency", property);
|
|
436 |
}
|
|
437 |
}
|
|
438 |
|
628
|
439 |
private void callAntTargetVisitor(Element targetNode, Element outTargetNode) {
|
587
|
440 |
// Add antcall/runtarget dependencies
|
|
441 |
ArrayList<String> antcallTargets = new ArrayList<String>();
|
|
442 |
ArrayList<String> logs = new ArrayList<String>();
|
|
443 |
ArrayList<String> signals = new ArrayList<String>();
|
|
444 |
ArrayList<String> executables = new ArrayList<String>();
|
|
445 |
Visitor visitorTarget = new AntTargetVisitor(antcallTargets, logs, signals, executables);
|
|
446 |
targetNode.accept(visitorTarget);
|
628
|
447 |
for (String antcallTarget : antcallTargets) {
|
587
|
448 |
Element dependencyElement = addTextElement(outTargetNode, "dependency", antcallTarget);
|
|
449 |
dependencyElement.addAttribute("type", "exec");
|
|
450 |
}
|
|
451 |
|
628
|
452 |
for (String log : logs) {
|
587
|
453 |
addTextElement(outTargetNode, "log", log);
|
|
454 |
}
|
|
455 |
|
628
|
456 |
if (globalSignalList.get(targetNode.attributeValue("name")) != null) {
|
587
|
457 |
signals.addAll(globalSignalList.get(targetNode.attributeValue("name")));
|
628
|
458 |
}
|
587
|
459 |
|
628
|
460 |
for (String signal : signals) {
|
587
|
461 |
addTextElement(outTargetNode, "signal", signal);
|
|
462 |
}
|
|
463 |
|
628
|
464 |
for (String executable : executables) {
|
587
|
465 |
addTextElement(outTargetNode, "executable", executable);
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
@SuppressWarnings("unchecked")
|
628
|
470 |
private void processTarget(Element targetNode, Element outProjectNode) throws IOException,
|
|
471 |
DocumentException {
|
587
|
472 |
String targetName = targetNode.attributeValue("name");
|
|
473 |
log("Processing target: " + targetName, Project.MSG_DEBUG);
|
|
474 |
|
|
475 |
// Add documentation
|
|
476 |
// Get comment element before the target element to extract target doc
|
|
477 |
String commentText = "";
|
|
478 |
List<Node> children = targetNode.selectNodes("preceding-sibling::node()");
|
628
|
479 |
if (children.size() > 0) {
|
587
|
480 |
// Scan past the text nodes, which are most likely whitespace
|
|
481 |
int index = children.size() - 1;
|
|
482 |
Node child = children.get(index);
|
628
|
483 |
while (index > 0 && child.getNodeType() == Node.TEXT_NODE) {
|
587
|
484 |
index--;
|
|
485 |
child = (Node) children.get(index);
|
|
486 |
}
|
|
487 |
|
|
488 |
// Check if there is a comment node
|
628
|
489 |
if (child.getNodeType() == Node.COMMENT_NODE) {
|
587
|
490 |
Comment targetComment = (Comment) child;
|
|
491 |
commentText = targetComment.getStringValue().trim();
|
|
492 |
|
|
493 |
log(targetName + " comment: " + commentText, Project.MSG_DEBUG);
|
|
494 |
}
|
628
|
495 |
else {
|
587
|
496 |
log("Target has no comment: " + targetName, Project.MSG_WARN);
|
|
497 |
}
|
|
498 |
}
|
|
499 |
|
628
|
500 |
if (!commentText.contains("Private:")) {
|
587
|
501 |
Element outTargetNode = outProjectNode.addElement("target");
|
|
502 |
|
|
503 |
addTextElement(outTargetNode, "name", targetNode.attributeValue("name"));
|
|
504 |
addTextElement(outTargetNode, "ifDependency", targetNode.attributeValue("if"));
|
|
505 |
addTextElement(outTargetNode, "unlessDependency", targetNode.attributeValue("unless"));
|
|
506 |
addTextElement(outTargetNode, "description", targetNode.attributeValue("description"));
|
|
507 |
addTextElement(outTargetNode, "tasks", String.valueOf(targetNode.elements().size()));
|
|
508 |
|
|
509 |
// Add location
|
|
510 |
Project project = getProject();
|
|
511 |
Target antTarget = (Target) project.getTargets().get(targetName);
|
|
512 |
|
628
|
513 |
if (antTarget == null) {
|
587
|
514 |
return;
|
628
|
515 |
}
|
587
|
516 |
|
|
517 |
addTextElement(outTargetNode, "location", antTarget.getLocation().toString());
|
|
518 |
|
|
519 |
// Add dependencies
|
|
520 |
Enumeration dependencies = antTarget.getDependencies();
|
628
|
521 |
while (dependencies.hasMoreElements()) {
|
587
|
522 |
String dependency = (String) dependencies.nextElement();
|
|
523 |
Element dependencyElement = addTextElement(outTargetNode, "dependency", dependency);
|
|
524 |
dependencyElement.addAttribute("type", "direct");
|
|
525 |
}
|
|
526 |
|
628
|
527 |
callAntTargetVisitor(targetNode, outTargetNode);
|
587
|
528 |
|
|
529 |
// Process the comment text as MediaWiki syntax and convert to HTML
|
|
530 |
insertDocumentation(outTargetNode, commentText);
|
|
531 |
|
|
532 |
// Get names of all properties used in this target
|
|
533 |
ArrayList properties = new ArrayList();
|
|
534 |
Visitor visitor = new AntPropertyVisitor(properties);
|
|
535 |
targetNode.accept(visitor);
|
628
|
536 |
for (Iterator iterator = properties.iterator(); iterator.hasNext();) {
|
587
|
537 |
String property = (String) iterator.next();
|
|
538 |
addTextElement(outTargetNode, "propertyDependency", property);
|
|
539 |
}
|
|
540 |
|
|
541 |
// Add the raw XML content of the element
|
|
542 |
String targetXml = targetNode.asXML();
|
|
543 |
// Replace the CDATA end notation to avoid nested CDATA sections
|
|
544 |
targetXml = targetXml.replace("]]>", "] ]>");
|
|
545 |
|
|
546 |
addTextElement(outTargetNode, "source", targetXml, true);
|
|
547 |
}
|
|
548 |
}
|
|
549 |
|
628
|
550 |
private void processProperty(Element propertyNode, Element outProjectNode) throws IOException {
|
587
|
551 |
String propertyName = propertyNode.attributeValue("name");
|
|
552 |
log("Processing Property: " + propertyName, Project.MSG_DEBUG);
|
|
553 |
|
|
554 |
Element outPropertyNode = outProjectNode.addElement("property");
|
|
555 |
addTextElement(outPropertyNode, "name", propertyNode.attributeValue("name"));
|
628
|
556 |
if (propertyNode.attributeValue("value") == null) {
|
587
|
557 |
addTextElement(outPropertyNode, "defaultValue", propertyNode.attributeValue("location"));
|
|
558 |
}
|
628
|
559 |
else {
|
587
|
560 |
addTextElement(outPropertyNode, "defaultValue", propertyNode.attributeValue("value"));
|
|
561 |
}
|
|
562 |
}
|
|
563 |
|
628
|
564 |
private void insertDocumentation(Element outNode, String commentText) throws IOException,
|
|
565 |
DocumentException {
|
|
566 |
if (commentText != null) {
|
587
|
567 |
WikiModel wikiModel = new WikiModel("", "");
|
628
|
568 |
if (!commentText.contains("</pre>")
|
|
569 |
&& (commentText.contains("**") || commentText.contains("==") || commentText.contains("- -"))) {
|
587
|
570 |
commentText = commentText.replace("**", "").replace("==", "").replace("- -", "").trim();
|
|
571 |
log("Warning: Comment code has invalid syntax: " + commentText, Project.MSG_WARN);
|
|
572 |
}
|
628
|
573 |
if (commentText.startsWith("-")) {
|
587
|
574 |
commentText = commentText.replace("-", "");
|
628
|
575 |
}
|
587
|
576 |
commentText = commentText.trim();
|
|
577 |
|
|
578 |
String commentTextCheck = commentText.replace("deprecated>", "").replace("tt>", "").replace("todo>", "");
|
628
|
579 |
if (commentTextCheck.contains(">") && !commentTextCheck.contains("</pre>")) {
|
587
|
580 |
log("Warning: Comment code needs <pre> tags around it: " + commentText, Project.MSG_WARN);
|
628
|
581 |
}
|
587
|
582 |
|
|
583 |
commentText = filterTextNewlines(commentText);
|
|
584 |
commentText = wikiModel.render(commentText);
|
|
585 |
|
|
586 |
// If <deprecated> tag exists in the comment, then parse the
|
|
587 |
// deprecated message.
|
628
|
588 |
if (commentText.indexOf("<deprecated>") != -1) {
|
587
|
589 |
int deprecatedMsgStart = commentText.indexOf("<deprecated>") + 20;
|
|
590 |
int deprecatedMsgEnd = commentText.indexOf("</deprecated>");
|
|
591 |
|
|
592 |
// Add deprecated element.
|
|
593 |
String deprecatedMsg = commentText.substring(deprecatedMsgStart, deprecatedMsgEnd);
|
|
594 |
addTextElement(outNode, "deprecated", deprecatedMsg);
|
|
595 |
|
|
596 |
// remove <deprecated> part from description field.
|
|
597 |
int commentTextLength = commentText.length();
|
|
598 |
String documentationMsgStart = commentText.substring(1, deprecatedMsgStart - 20);
|
628
|
599 |
String documentationMsgEnd = commentText.substring(deprecatedMsgEnd + 21, commentTextLength);
|
587
|
600 |
String documentationMsg = documentationMsgStart.concat(documentationMsgEnd);
|
|
601 |
commentText = documentationMsg.trim();
|
|
602 |
}
|
|
603 |
}
|
628
|
604 |
else {
|
587
|
605 |
commentText = "";
|
|
606 |
}
|
|
607 |
// Get the documentation element as a document
|
628
|
608 |
String documentationText = "<documentation>" + commentText + "</documentation>";
|
587
|
609 |
Document docDoc = DocumentHelper.parseText(documentationText);
|
|
610 |
outNode.add(docDoc.getRootElement());
|
|
611 |
log("HTML comment: " + commentText, Project.MSG_DEBUG);
|
|
612 |
}
|
|
613 |
|
628
|
614 |
private Element addTextElement(Element parent, String name, String text) {
|
587
|
615 |
Element element = addTextElement(parent, name, text, false);
|
|
616 |
|
|
617 |
return element;
|
|
618 |
}
|
|
619 |
|
628
|
620 |
private Element addTextElement(Element parent, String name, String text, boolean escape) {
|
587
|
621 |
Element element = parent.addElement(name);
|
628
|
622 |
if (text != null) {
|
|
623 |
if (escape) {
|
587
|
624 |
element.addCDATA(text);
|
|
625 |
}
|
628
|
626 |
else {
|
587
|
627 |
element.setText(text);
|
|
628 |
}
|
|
629 |
}
|
|
630 |
return element;
|
|
631 |
}
|
|
632 |
|
628
|
633 |
private String filterTextNewlines(String text) throws IOException {
|
587
|
634 |
BufferedReader in = new BufferedReader(new StringReader(text));
|
|
635 |
StringBuilder out = new StringBuilder();
|
|
636 |
String line = in.readLine();
|
628
|
637 |
while (line != null) {
|
587
|
638 |
out.append(line.trim());
|
|
639 |
out.append("\n");
|
|
640 |
line = in.readLine();
|
|
641 |
}
|
|
642 |
return out.toString();
|
|
643 |
}
|
|
644 |
|
|
645 |
/**
|
|
646 |
* Method adds taskdef nodes to the specified project.
|
|
647 |
*
|
|
648 |
* @param outProjectNode
|
|
649 |
* @throws IOException
|
|
650 |
*/
|
628
|
651 |
private void buildTaskDefs(Element root) throws DocumentException, IOException {
|
587
|
652 |
Element projectElement = root.addElement("project");
|
|
653 |
projectElement.addElement("name");
|
|
654 |
insertDocumentation(projectElement, "");
|
628
|
655 |
HashMap<String, String> tasks = getHeliumAntTasks();
|
587
|
656 |
|
628
|
657 |
for (String taskName : tasks.keySet()) {
|
|
658 |
String className = tasks.get(taskName);
|
587
|
659 |
log("Processing TaskDef: " + taskName, Project.MSG_DEBUG);
|
|
660 |
|
|
661 |
Element outTaskDefNode = projectElement.addElement("taskdef");
|
628
|
662 |
addTextElement(outTaskDefNode, "name", taskName);
|
|
663 |
addTextElement(outTaskDefNode, "classname", className);
|
587
|
664 |
}
|
|
665 |
}
|
|
666 |
|
|
667 |
/**
|
|
668 |
* Method returns all the helium ant tasks in the project.
|
|
669 |
*
|
|
670 |
* @return
|
|
671 |
*/
|
|
672 |
@SuppressWarnings("unchecked")
|
628
|
673 |
private HashMap<String, String> getHeliumAntTasks() {
|
587
|
674 |
|
|
675 |
// 1. Get all the task definitions from the project
|
628
|
676 |
Hashtable<String, Class<?>> allTaskdefs = getProject().getTaskDefinitions();
|
587
|
677 |
// 2. Filter the list by applying criteria
|
628
|
678 |
return filterTasks(allTaskdefs);
|
587
|
679 |
}
|
|
680 |
|
|
681 |
/**
|
628
|
682 |
* Method is used to filter tasks.
|
587
|
683 |
*
|
|
684 |
* @param allTaskdefs
|
|
685 |
* @param criteria
|
|
686 |
*/
|
628
|
687 |
private HashMap<String, String> filterTasks(Hashtable<String, Class<?>> allTaskdefs) {
|
|
688 |
HashMap<String, String> tasks = new HashMap<String, String>();
|
587
|
689 |
|
628
|
690 |
Enumeration<String> taskdefsenum = allTaskdefs.keys();
|
|
691 |
while (taskdefsenum.hasMoreElements()) {
|
587
|
692 |
String key = taskdefsenum.nextElement();
|
|
693 |
Class<?> clazz = allTaskdefs.get(key);
|
|
694 |
String className = clazz.getName();
|
628
|
695 |
if (key.contains("nokia.com") && className.startsWith("com.nokia")
|
|
696 |
&& className.contains("ant.taskdefs")) {
|
|
697 |
tasks.put(getTaskName(key), clazz.getName());
|
587
|
698 |
}
|
|
699 |
}
|
|
700 |
return tasks;
|
|
701 |
}
|
|
702 |
|
|
703 |
/**
|
|
704 |
* Returns the task name delimiting the helium namespace.
|
|
705 |
*
|
|
706 |
* @param text
|
|
707 |
* @return
|
|
708 |
*/
|
628
|
709 |
private String getTaskName(String text) {
|
587
|
710 |
int lastIndex = text.lastIndexOf(':');
|
628
|
711 |
return text.substring(lastIndex + 1);
|
587
|
712 |
}
|
|
713 |
|
628
|
714 |
// ----------------------------------- PRIVATE CLASSES -----------------------------------------
|
587
|
715 |
|
628
|
716 |
private class AntPropertyVisitor extends VisitorSupport {
|
587
|
717 |
private List<String> propertyList;
|
|
718 |
|
628
|
719 |
public AntPropertyVisitor(List<String> propertyList) {
|
587
|
720 |
this.propertyList = propertyList;
|
|
721 |
}
|
|
722 |
|
628
|
723 |
public void visit(Attribute node) {
|
587
|
724 |
String text = node.getStringValue();
|
|
725 |
extractUsedProperties(text);
|
|
726 |
}
|
|
727 |
|
628
|
728 |
public void visit(CDATA node) {
|
587
|
729 |
String text = node.getText();
|
|
730 |
extractUsedProperties(text);
|
|
731 |
}
|
|
732 |
|
628
|
733 |
public void visit(Text node) {
|
587
|
734 |
String text = node.getText();
|
|
735 |
extractUsedProperties(text);
|
|
736 |
}
|
|
737 |
|
628
|
738 |
public void visit(Element node) {
|
|
739 |
if (node.getName().equals("property")) {
|
587
|
740 |
String propertyName = node.attributeValue("name");
|
628
|
741 |
if (!propertyList.contains(propertyName)) {
|
587
|
742 |
propertyList.add(propertyName);
|
|
743 |
log("property matches :" + propertyName, Project.MSG_DEBUG);
|
|
744 |
}
|
|
745 |
}
|
|
746 |
}
|
|
747 |
|
628
|
748 |
private void extractUsedProperties(String text) {
|
587
|
749 |
Pattern p1 = Pattern.compile("\\$\\{([^@$}]*)\\}");
|
|
750 |
Matcher m1 = p1.matcher(text);
|
|
751 |
log(text, Project.MSG_DEBUG);
|
628
|
752 |
while (m1.find()) {
|
587
|
753 |
String group = m1.group(1);
|
628
|
754 |
if (!propertyList.contains(group)) {
|
587
|
755 |
propertyList.add(group);
|
|
756 |
}
|
|
757 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
758 |
}
|
|
759 |
|
|
760 |
Pattern p2 = Pattern.compile("\\$\\{([^\n]*\\})\\}");
|
|
761 |
Matcher m2 = p2.matcher(text);
|
|
762 |
log(text, Project.MSG_DEBUG);
|
628
|
763 |
while (m2.find()) {
|
587
|
764 |
String group = m2.group(1);
|
628
|
765 |
if (!propertyList.contains(group)) {
|
587
|
766 |
propertyList.add(group);
|
|
767 |
}
|
|
768 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
769 |
}
|
|
770 |
|
|
771 |
Pattern p3 = Pattern.compile("\\$\\{(\\@\\{[^\n]*)\\}");
|
|
772 |
Matcher m3 = p3.matcher(text);
|
|
773 |
log(text, Project.MSG_DEBUG);
|
628
|
774 |
while (m3.find()) {
|
587
|
775 |
String group = m3.group(1);
|
628
|
776 |
if (!propertyList.contains(group)) {
|
587
|
777 |
propertyList.add(group);
|
|
778 |
}
|
|
779 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
780 |
}
|
|
781 |
}
|
|
782 |
}
|
|
783 |
|
628
|
784 |
private class AntTargetVisitor extends VisitorSupport {
|
587
|
785 |
private List<String> targetList;
|
|
786 |
private List<String> logList;
|
|
787 |
private List<String> signalList;
|
|
788 |
private List<String> executableList;
|
|
789 |
|
628
|
790 |
public AntTargetVisitor(List<String> targetList, List<String> logList,
|
|
791 |
List<String> signalList, List<String> executableList) {
|
587
|
792 |
this.targetList = targetList;
|
|
793 |
this.logList = logList;
|
|
794 |
this.signalList = signalList;
|
|
795 |
this.executableList = executableList;
|
|
796 |
}
|
|
797 |
|
628
|
798 |
public void visit(Element node) {
|
587
|
799 |
String name = node.getName();
|
628
|
800 |
if (name.equals("antcall") || name.equals("runtarget")) {
|
587
|
801 |
String text = node.attributeValue("target");
|
|
802 |
extractTarget(text);
|
|
803 |
}
|
|
804 |
|
628
|
805 |
if (!name.equals("include") && !name.equals("exclude")) {
|
587
|
806 |
String text = node.attributeValue("name");
|
|
807 |
addLog(text);
|
|
808 |
text = node.attributeValue("output");
|
|
809 |
addLog(text);
|
|
810 |
text = node.attributeValue("value");
|
|
811 |
addLog(text);
|
|
812 |
text = node.attributeValue("log");
|
|
813 |
addLog(text);
|
|
814 |
text = node.attributeValue("line");
|
|
815 |
addLog(text);
|
|
816 |
text = node.attributeValue("file");
|
|
817 |
addLog(text);
|
|
818 |
}
|
|
819 |
|
628
|
820 |
if (name.equals("signal") || name.equals("execSignal")) {
|
587
|
821 |
String signalid = getProject().replaceProperties(node.attributeValue("name"));
|
|
822 |
String failbuild = signalType(signalid, signaldoc);
|
|
823 |
|
628
|
824 |
if (signalList != null) {
|
|
825 |
if (failbuild != null) {
|
587
|
826 |
signalList.add(signalid + "," + failbuild);
|
628
|
827 |
} else {
|
587
|
828 |
signalList.add(signalid);
|
628
|
829 |
}
|
587
|
830 |
}
|
|
831 |
}
|
|
832 |
|
628
|
833 |
if (name.equals("exec") || name.equals("preset.exec")) {
|
587
|
834 |
String text = node.attributeValue("executable");
|
|
835 |
executableList.add(text);
|
|
836 |
log("Executable: " + text, Project.MSG_DEBUG);
|
|
837 |
}
|
|
838 |
}
|
|
839 |
|
628
|
840 |
private void addLog(String text) {
|
|
841 |
if (text != null && logList != null) {
|
|
842 |
for (String log : text.split(" ")) {
|
587
|
843 |
String fulllogname = getProject().replaceProperties(log);
|
628
|
844 |
if (!logList.contains(log)
|
|
845 |
&& (fulllogname.endsWith(".log") || fulllogname.endsWith(".html"))) {
|
587
|
846 |
log = log.replace("--log=", "");
|
|
847 |
logList.add(log);
|
|
848 |
}
|
|
849 |
}
|
|
850 |
}
|
|
851 |
}
|
|
852 |
|
628
|
853 |
private void extractTarget(String text) {
|
587
|
854 |
String iText = getProject().replaceProperties(text);
|
|
855 |
targetList.add(iText);
|
|
856 |
}
|
|
857 |
|
|
858 |
}
|
|
859 |
}
|