19 |
19 |
20 import java.io.File; |
20 import java.io.File; |
21 import java.io.IOException; |
21 import java.io.IOException; |
22 import java.text.BreakIterator; |
22 import java.text.BreakIterator; |
23 import java.util.ArrayList; |
23 import java.util.ArrayList; |
|
24 import java.util.Iterator; |
24 import java.util.List; |
25 import java.util.List; |
25 |
26 |
26 import org.dom4j.Comment; |
27 import org.dom4j.Comment; |
27 import org.dom4j.DocumentException; |
28 import org.dom4j.Document; |
|
29 import org.dom4j.DocumentHelper; |
28 import org.dom4j.Element; |
30 import org.dom4j.Element; |
29 import org.dom4j.Node; |
31 import org.dom4j.Node; |
|
32 import org.dom4j.XPath; |
30 |
33 |
31 /** |
34 /** |
32 * Meta object for an Ant project. |
35 * Meta object for an Ant project. |
33 */ |
36 */ |
34 public class ProjectMeta extends RootAntObjectMeta { |
37 public class ProjectMeta extends RootAntObjectMeta { |
35 private static final String DOC_COMMENT_MARKER = "*"; |
38 private static final String DOC_COMMENT_MARKER = "*"; |
36 |
39 |
37 private String description = ""; |
40 private String description = ""; |
38 |
41 |
39 public ProjectMeta(AntFile antFile, Element node) throws DocumentException, IOException { |
42 public ProjectMeta(AntFile antFile, Element node) throws IOException { |
40 super(antFile, node); |
43 super(antFile, node); |
41 |
44 |
42 // Only parse a project comment if it is marked |
45 // Only parse a project comment if it is marked |
43 if (!getComment().isMarkedComment()) { |
46 if (!getComment().isMarkedComment()) { |
44 setComment(getEmptyComment()); |
47 setComment(getEmptyComment()); |
45 } |
48 } |
46 |
49 |
47 Element descriptionNode = ((Element) getNode()).element("description"); |
50 Element descriptionNode = ((Element) getNode()).element("description"); |
48 // System.out.println(descriptionNode); |
|
49 if (descriptionNode != null) { |
51 if (descriptionNode != null) { |
50 description = AntComment.getCleanedDocNodeText(descriptionNode); |
52 description = AntComment.getCleanedDocNodeText(descriptionNode); |
51 } |
53 } |
52 } |
54 } |
53 |
55 |
71 String text = getDescription(); |
73 String text = getDescription(); |
72 if (text.length() == 0) { |
74 if (text.length() == 0) { |
73 text = getDocumentation(); |
75 text = getDocumentation(); |
74 } |
76 } |
75 BreakIterator iterator = BreakIterator.getSentenceInstance(); |
77 BreakIterator iterator = BreakIterator.getSentenceInstance(); |
76 // BreakIterator iterator = BreakIterator.getLineInstance(); |
|
77 iterator.setText(text); |
78 iterator.setText(text); |
78 String summary = ""; |
79 String summary = ""; |
79 if (iterator.next() > 0) { |
80 if (iterator.next() > 0) { |
80 summary = text.substring(0, iterator.current()).trim(); |
81 summary = text.substring(0, iterator.current()).trim(); |
81 } |
82 } |
82 return summary; |
83 return summary; |
83 } |
84 } |
84 |
85 |
85 @SuppressWarnings("unchecked") |
86 @SuppressWarnings("unchecked") |
86 public List<TargetMeta> getTargets() throws IOException { |
87 public List<TargetMeta> getTargets() { |
87 ArrayList<TargetMeta> objects = new ArrayList<TargetMeta>(); |
88 ArrayList<TargetMeta> objects = new ArrayList<TargetMeta>(); |
88 List<Node> nodes = getNode().selectNodes("target"); |
89 List<Node> nodes = getNode().selectNodes("target"); |
89 for (Node targetNode : nodes) { |
90 for (Node targetNode : nodes) { |
90 TargetMeta targetMeta = new TargetMeta(this, targetNode); |
91 TargetMeta targetMeta = new TargetMeta(this, targetNode); |
91 targetMeta.setRuntimeProject(getRuntimeProject()); |
92 targetMeta.setRuntimeProject(getRuntimeProject()); |
95 } |
96 } |
96 return objects; |
97 return objects; |
97 } |
98 } |
98 |
99 |
99 @SuppressWarnings("unchecked") |
100 @SuppressWarnings("unchecked") |
100 public List<PropertyMeta> getProperties() throws IOException { |
101 public List<PropertyMeta> getProperties() { |
101 List<PropertyMeta> properties = new ArrayList<PropertyMeta>(); |
102 List<PropertyMeta> properties = new ArrayList<PropertyMeta>(); |
102 List<Node> propertyNodes = getNode().selectNodes("//property[string-length(@name)>0]"); |
103 List<Node> propertyNodes = getNode().selectNodes("//property[string-length(@name)>0]"); |
103 for (Node propNode : propertyNodes) { |
104 for (Node propNode : propertyNodes) { |
104 PropertyMeta propertyMeta = new PropertyMeta(this, propNode); |
105 PropertyMeta propertyMeta = new PropertyMeta(this, propNode); |
105 propertyMeta.setRuntimeProject(getRuntimeProject()); |
106 propertyMeta.setRuntimeProject(getRuntimeProject()); |
109 } |
110 } |
110 return properties; |
111 return properties; |
111 } |
112 } |
112 |
113 |
113 @SuppressWarnings("unchecked") |
114 @SuppressWarnings("unchecked") |
114 public List<MacroMeta> getMacros() throws IOException { |
115 public List<MacroMeta> getMacros() { |
115 ArrayList<MacroMeta> objects = new ArrayList<MacroMeta>(); |
116 ArrayList<MacroMeta> objects = new ArrayList<MacroMeta>(); |
116 List<Element> nodes = getNode().selectNodes("//macrodef | //scriptdef"); |
117 List<Element> nodes = getNode().selectNodes("//macrodef | //scriptdef"); |
117 for (Element node : nodes) { |
118 for (Element node : nodes) { |
118 MacroMeta macroMeta = new MacroMeta(this, node); |
119 MacroMeta macroMeta = new MacroMeta(this, node); |
119 macroMeta.setRuntimeProject(getRuntimeProject()); |
120 macroMeta.setRuntimeProject(getRuntimeProject()); |
148 } |
149 } |
149 return objects; |
150 return objects; |
150 } |
151 } |
151 |
152 |
152 @SuppressWarnings("unchecked") |
153 @SuppressWarnings("unchecked") |
153 public List<PropertyCommentMeta> getPropertyCommentBlocks() throws IOException { |
154 public List<PropertyCommentMeta> getPropertyCommentBlocks() { |
154 ArrayList<PropertyCommentMeta> objects = new ArrayList<PropertyCommentMeta>(); |
155 ArrayList<PropertyCommentMeta> objects = new ArrayList<PropertyCommentMeta>(); |
155 List<Node> nodes = getNode().selectNodes("//comment()"); |
156 List<Node> nodes = getNode().selectNodes("//comment()"); |
156 for (Node node : nodes) { |
157 for (Node node : nodes) { |
157 String text = node.getText().trim(); |
158 String text = node.getText().trim(); |
158 if (text.startsWith(DOC_COMMENT_MARKER + " @property")) { |
159 if (text.startsWith(DOC_COMMENT_MARKER + " @property")) { |
159 PropertyCommentMeta propertyCommentMeta = new PropertyCommentMeta(this, (Comment) node); |
160 PropertyCommentMeta propertyCommentMeta = new PropertyCommentMeta(this, (Comment) node); |
160 propertyCommentMeta.setRuntimeProject(getRuntimeProject()); |
161 propertyCommentMeta.setRuntimeProject(getRuntimeProject()); |
161 objects.add(propertyCommentMeta); |
162 if (propertyCommentMeta.matchesScope(getScopeFilter())) { |
162 } |
163 objects.add(propertyCommentMeta); |
163 } |
164 } |
164 return objects; |
165 } |
|
166 } |
|
167 return objects; |
|
168 } |
|
169 |
|
170 @SuppressWarnings("unchecked") |
|
171 public void getConfigSignals(String targetName, List<String> signals) { |
|
172 XPath xpath = DocumentHelper.createXPath("//hlm:signalListenerConfig[@target='" |
|
173 + targetName + "']"); |
|
174 xpath.setNamespaceURIs(Database.NAMESPACE_MAP); |
|
175 List<Node> signalNodes = xpath.selectNodes(getNode()); |
|
176 for (Iterator<Node> iterator = signalNodes.iterator(); iterator.hasNext();) { |
|
177 Element propertyNode = (Element) iterator.next(); |
|
178 String signalid = propertyNode.attributeValue("id"); |
|
179 String failbuild = findSignalFailMode(signalid, getNode().getDocument()); |
|
180 signals.add(signalid + "(" + failbuild + ")"); |
|
181 } |
|
182 } |
|
183 |
|
184 @SuppressWarnings("unchecked") |
|
185 private String findSignalFailMode(String signalid, Document antDoc) { |
|
186 XPath xpath2 = DocumentHelper.createXPath("//hlm:signalListenerConfig[@id='" + signalid |
|
187 + "']/signalNotifierInput/signalInput"); |
|
188 xpath2.setNamespaceURIs(Database.NAMESPACE_MAP); |
|
189 List signalNodes3 = xpath2.selectNodes(antDoc); |
|
190 |
|
191 for (Iterator iterator3 = signalNodes3.iterator(); iterator3.hasNext();) { |
|
192 Element propertyNode3 = (Element) iterator3.next(); |
|
193 String signalinputid = propertyNode3.attributeValue("refid"); |
|
194 |
|
195 XPath xpath3 = DocumentHelper.createXPath("//hlm:signalInput[@id='" + signalinputid |
|
196 + "']"); |
|
197 xpath3.setNamespaceURIs(Database.NAMESPACE_MAP); |
|
198 List signalNodes4 = xpath3.selectNodes(antDoc); |
|
199 for (Iterator iterator4 = signalNodes4.iterator(); iterator4.hasNext();) { |
|
200 Element propertyNode4 = (Element) iterator4.next(); |
|
201 return propertyNode4.attributeValue("failbuild"); |
|
202 } |
|
203 } |
|
204 return null; |
165 } |
205 } |
166 } |
206 } |