1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.codehaus.mojo.javascript;
15
16 import org.apache.commons.jxpath.ri.compiler.Path;
17 import org.apache.maven.plugin.MojoExecutionException;
18 import org.apache.maven.plugin.logging.Log;
19 import org.codehaus.mojo.javascript.titanium.TitaniumUtils;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22 import org.w3c.dom.NodeList;
23 import org.xml.sax.SAXException;
24
25 import javax.xml.parsers.DocumentBuilder;
26 import javax.xml.parsers.DocumentBuilderFactory;
27 import javax.xml.parsers.ParserConfigurationException;
28 import javax.xml.xpath.*;
29 import java.io.*;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.List;
33 import java.util.regex.Matcher;
34 import java.util.regex.Pattern;
35
36
37
38
39 public class TitaniumSettings {
40
41
42
43
44
45
46 protected File androidBuilder;
47
48
49
50
51
52
53 protected File iosBuilder;
54
55
56
57
58
59
60
61 protected File androidSDK;
62
63
64
65
66
67 private String keystore;
68
69
70
71
72
73 private String keystorePassword = "tirocks";
74
75
76
77
78
79 private String keystoreAlias = "tidev";
80
81
82
83
84
85
86
87
88 protected String iosDevelopmentProvisioningProfile;
89
90
91
92
93
94
95
96 protected String iosDistributionProvisioningProfile;
97
98
99
100
101
102
103
104
105 protected String iosDevelopmentCertificate;
106
107
108
109
110
111
112
113 protected String iosDistributionCertificate;
114
115
116 public void setKeystoreAlias(String keystoreAlias) {
117 this.keystoreAlias = keystoreAlias;
118 }
119
120 public void setKeystorePassword(String keystorePassword) {
121 this.keystorePassword = keystorePassword;
122 }
123
124 public void setKeystore(String keystore) {
125 this.keystore = keystore;
126 }
127
128 public String getKeystore(String version, File targetDir) throws MojoExecutionException {
129 if (keystore == null) {
130 ensureKeystore(version, targetDir);
131 }
132 return keystore;
133 }
134
135 public String getKeystoreAlias() {
136 return keystoreAlias;
137 }
138
139 public String getKeystorePassword() {
140 return keystorePassword;
141 }
142
143 public File getAndroidBuilder(String version) {
144 if (androidBuilder != null) {
145 return androidBuilder;
146 } else {
147 String sdkPath = TitaniumUtils.getTitaniumSdkPath(version);
148 if (sdkPath != null) {
149 return new File(sdkPath + "android" + File.separator + "builder.py");
150 }
151 }
152 return androidBuilder;
153 }
154
155 public void setAndroidBuilder(File androidBuilder) {
156 this.androidBuilder = androidBuilder;
157 }
158
159 public File getAndroidSdk() throws MojoExecutionException {
160 if (androidSDK == null) {
161 androidSDK = new File(TitaniumUtils.getAndroidHome());
162 }
163 return androidSDK;
164 }
165
166 public void setAndroidSdk(File androidSdk) {
167 this.androidSDK = androidSdk;
168 }
169
170 public File getIosBuilder(String version) {
171 if (iosBuilder != null) {
172 return iosBuilder;
173 } else {
174 String sdkPath = TitaniumUtils.getTitaniumSdkPath(version);
175 if (sdkPath != null) {
176 return new File(sdkPath + "iphone" + File.separator + "builder.py");
177 }
178 }
179 return iosBuilder;
180 }
181
182 public void setIosBuilder(File iosBuilder) {
183 this.iosBuilder = iosBuilder;
184 }
185
186 public String getIosDistributionCertificate() {
187 return iosDistributionCertificate;
188 }
189
190 public void setIosDistributionCertificate(String iosDistributionCertificate) {
191 this.iosDistributionCertificate = iosDistributionCertificate;
192 }
193
194 public String getIosDevelopmentCertificate() {
195 return iosDevelopmentCertificate;
196 }
197
198 public void setIosDevelopmentCertificate(String iosDevelopmentCertificate) {
199 this.iosDevelopmentCertificate = iosDevelopmentCertificate;
200 }
201
202 public String getIosDevelopmentProvisioningProfile() {
203 return iosDevelopmentProvisioningProfile;
204 }
205
206 public void setIosDevelopmentProvisioningProfile(String iosDevelopmentProvisioningProfile) {
207 this.iosDevelopmentProvisioningProfile = iosDevelopmentProvisioningProfile;
208 }
209
210 public String getIosDistributionProvisioningProfile() {
211 return iosDistributionProvisioningProfile;
212 }
213
214 public void setIosDistributionProvisioningProfile(String iosDistributionProvisioningProfile) {
215 this.iosDistributionProvisioningProfile = iosDistributionProvisioningProfile;
216 }
217
218 private void ensureKeystore(String version, File targetDir) throws MojoExecutionException{
219 if (keystore == null) {
220 String sdk = TitaniumUtils.getTitaniumSdkPath(version);
221 if (sdk == null) {
222 sdk = TitaniumUtils.getTitaniumArtifactSdkPath(version, targetDir);
223 }
224 if (sdk != null) {
225 File keystoreFile = new File(sdk, "android" + File.separator + "dev_keystore");
226 if (keystoreFile.exists()) {
227 keystore = keystoreFile.getAbsolutePath();
228 }
229 }
230 }
231 if (keystore == null) {
232 keystore = "";
233 }
234
235 File keystoreFile = new File(keystore);
236 if (!keystoreFile.exists()) {
237 throw new MojoExecutionException("Invalid keystore location: " + keystoreFile.getAbsolutePath());
238 }
239 }
240
241 public Tiapp getTiappFromXML(File xmlFile) throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
242 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
243 factory.setNamespaceAware(true);
244 DocumentBuilder builder = factory.newDocumentBuilder();
245 Document doc = builder.parse(xmlFile);
246
247 XPath xpath = XPathFactory.newInstance().newXPath();
248
249 Tiapp tiapp = new Tiapp();
250
251 tiapp.setName(getFromXPath(doc, xpath, "/ti:app/ti:name/text()"));
252 tiapp.setAnalytics(getFromXPathAsBoolean(doc, xpath, "/ti:app/ti:analytics/text()"));
253 tiapp.setCopyright(getFromXPath(doc, xpath, "/ti:app/ti:copyright/text()"));
254 tiapp.setDescription(getFromXPath(doc, xpath, "/ti:app/ti:description/text()"));
255 tiapp.setFullScreen(getFromXPathAsBoolean(doc, xpath, "/ti:app/ti:fullscreen/text()"));
256 tiapp.setGuid(getFromXPath(doc, xpath, "/ti:app/ti:guid/text()"));
257 if (tiapp.getGuid().trim().equals("")) {
258 tiapp.setGuid(getFromXPath(doc, xpath, "/ti:app/guid/text()"));
259 }
260 if (tiapp.getGuid().equals("")) {
261 NodeList nl = doc.getDocumentElement().getElementsByTagName("guid");
262 if (nl != null && nl.getLength() > 0) {
263 Element guidElem = (Element) nl.item(0);
264 tiapp.setGuid(guidElem.getTextContent());
265 }
266 }
267
268 NodeList nl = doc.getDocumentElement().getElementsByTagName("id");
269 if (nl != null && nl.getLength() > 0) {
270 Element idElem = (Element) nl.item(0);
271 tiapp.setProjectId(idElem.getTextContent());
272 }
273 return tiapp;
274 }
275
276 private String getFromXPath(Document doc, XPath xpath, String query) throws XPathExpressionException {
277 return (String) xpath.evaluate(query, doc, XPathConstants.STRING);
278 }
279
280 private boolean getFromXPathAsBoolean(Document doc, XPath xpath, String query) throws XPathExpressionException {
281 String result = getFromXPath(doc, xpath, query);
282 if (result != null && result.compareToIgnoreCase("true") == 0) {
283 return true;
284 } else {
285 return false;
286 }
287 }
288 }