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