587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.helium.ant.data;
|
|
19 |
|
|
20 |
import java.util.ArrayList;
|
628
|
21 |
import java.util.Collection;
|
|
22 |
import java.util.Iterator;
|
587
|
23 |
import java.util.List;
|
|
24 |
import java.util.StringTokenizer;
|
|
25 |
import java.util.regex.Matcher;
|
|
26 |
import java.util.regex.Pattern;
|
|
27 |
|
|
28 |
import org.apache.tools.ant.Project;
|
|
29 |
import org.dom4j.Attribute;
|
|
30 |
import org.dom4j.CDATA;
|
|
31 |
import org.dom4j.Element;
|
|
32 |
import org.dom4j.Node;
|
|
33 |
import org.dom4j.Text;
|
|
34 |
import org.dom4j.Visitor;
|
|
35 |
import org.dom4j.VisitorSupport;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* Meta object representing a target.
|
|
39 |
*/
|
|
40 |
public class TargetMeta extends TaskContainerMeta {
|
|
41 |
|
628
|
42 |
public TargetMeta(AntObjectMeta parent, Node node) {
|
587
|
43 |
super(parent, node);
|
|
44 |
}
|
|
45 |
|
|
46 |
public String getIf() {
|
|
47 |
return getAttr("if");
|
|
48 |
}
|
|
49 |
|
|
50 |
public String getUnless() {
|
|
51 |
return getAttr("unless");
|
|
52 |
}
|
|
53 |
|
|
54 |
public String getDescription() {
|
|
55 |
return getAttr("description");
|
|
56 |
}
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Use the standard Ant description element if there is no summary in a
|
|
60 |
* comment.
|
|
61 |
*/
|
|
62 |
public String getSummary() {
|
|
63 |
String summary = super.getSummary();
|
|
64 |
if (summary.length() == 0) {
|
|
65 |
summary = getDescription();
|
|
66 |
}
|
|
67 |
return summary;
|
|
68 |
}
|
|
69 |
|
|
70 |
public List<String> getDepends() {
|
|
71 |
String dependsAttr = getAttr("depends");
|
|
72 |
StringTokenizer st = new StringTokenizer(dependsAttr, ",");
|
|
73 |
List<String> depends = new ArrayList<String>();
|
|
74 |
while (st.hasMoreTokens()) {
|
|
75 |
depends.add(st.nextToken().trim());
|
|
76 |
}
|
|
77 |
return depends;
|
|
78 |
}
|
|
79 |
|
|
80 |
public List<String> getSignals() {
|
|
81 |
List<String> signals = super.getSignals();
|
628
|
82 |
Collection<AntFile> antFiles = getDatabase().getAntFiles();
|
|
83 |
for (Iterator<AntFile> iterator = antFiles.iterator(); iterator.hasNext();) {
|
|
84 |
AntFile antFile = (AntFile) iterator.next();
|
|
85 |
RootAntObjectMeta rootObjectMeta = antFile.getRootObjectMeta();
|
|
86 |
if (rootObjectMeta instanceof ProjectMeta) {
|
|
87 |
ProjectMeta projectMeta = (ProjectMeta)rootObjectMeta;
|
|
88 |
projectMeta.getConfigSignals(getName(), signals);
|
|
89 |
}
|
587
|
90 |
}
|
|
91 |
return signals;
|
|
92 |
}
|
|
93 |
|
|
94 |
public List<String> getPropertyDependencies() {
|
|
95 |
ArrayList<String> properties = new ArrayList<String>();
|
|
96 |
Visitor visitor = new AntPropertyVisitor(properties);
|
|
97 |
getNode().accept(visitor);
|
|
98 |
return properties;
|
|
99 |
}
|
|
100 |
|
|
101 |
private class AntPropertyVisitor extends VisitorSupport {
|
|
102 |
private List<String> propertyList;
|
|
103 |
|
|
104 |
public AntPropertyVisitor(List<String> propertyList) {
|
|
105 |
this.propertyList = propertyList;
|
|
106 |
}
|
|
107 |
|
|
108 |
public void visit(Attribute node) {
|
|
109 |
String text = node.getStringValue();
|
|
110 |
extractUsedProperties(text);
|
|
111 |
}
|
|
112 |
|
|
113 |
public void visit(CDATA node) {
|
|
114 |
String text = node.getText();
|
|
115 |
extractUsedProperties(text);
|
|
116 |
}
|
|
117 |
|
|
118 |
public void visit(Text node) {
|
|
119 |
String text = node.getText();
|
|
120 |
extractUsedProperties(text);
|
|
121 |
}
|
|
122 |
|
|
123 |
public void visit(Element node) {
|
|
124 |
if (node.getName().equals("property")) {
|
|
125 |
String propertyName = node.attributeValue("name");
|
|
126 |
if (propertyName != null && !propertyList.contains(propertyName)) {
|
|
127 |
propertyList.add(propertyName);
|
|
128 |
log("property matches :" + propertyName, Project.MSG_DEBUG);
|
|
129 |
}
|
|
130 |
}
|
|
131 |
}
|
|
132 |
|
|
133 |
private void extractUsedProperties(String text) {
|
|
134 |
Pattern p1 = Pattern.compile("\\$\\{([^@$}]*)\\}");
|
|
135 |
Matcher m1 = p1.matcher(text);
|
|
136 |
while (m1.find()) {
|
|
137 |
String group = m1.group(1);
|
|
138 |
if (!propertyList.contains(group)) {
|
|
139 |
propertyList.add(group);
|
|
140 |
}
|
|
141 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
142 |
}
|
|
143 |
|
|
144 |
Pattern p2 = Pattern.compile("\\$\\{([^\n]*\\})\\}");
|
|
145 |
Matcher m2 = p2.matcher(text);
|
|
146 |
while (m2.find()) {
|
|
147 |
String group = m2.group(1);
|
|
148 |
if (!propertyList.contains(group)) {
|
|
149 |
propertyList.add(group);
|
|
150 |
}
|
|
151 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
152 |
}
|
|
153 |
|
|
154 |
Pattern p3 = Pattern.compile("\\$\\{(\\@\\{[^\n]*)\\}");
|
|
155 |
Matcher m3 = p3.matcher(text);
|
|
156 |
log(text, Project.MSG_DEBUG);
|
|
157 |
while (m3.find()) {
|
|
158 |
String group = m3.group(1);
|
|
159 |
if (!propertyList.contains(group)) {
|
|
160 |
propertyList.add(group);
|
|
161 |
}
|
|
162 |
log("property matches: " + group, Project.MSG_DEBUG);
|
|
163 |
}
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
}
|