15 import java.io.File; |
15 import java.io.File; |
16 import java.io.FileFilter; |
16 import java.io.FileFilter; |
17 import java.util.ArrayList; |
17 import java.util.ArrayList; |
18 import java.util.Collections; |
18 import java.util.Collections; |
19 import java.util.Comparator; |
19 import java.util.Comparator; |
|
20 import java.util.HashMap; |
|
21 import java.util.Iterator; |
20 import java.util.List; |
22 import java.util.List; |
|
23 import java.util.Map; |
21 |
24 |
22 import javax.xml.parsers.DocumentBuilder; |
25 import javax.xml.parsers.DocumentBuilder; |
23 import javax.xml.parsers.DocumentBuilderFactory; |
26 import javax.xml.parsers.DocumentBuilderFactory; |
24 |
27 |
25 import org.eclipse.cdt.utils.spawner.EnvironmentReader; |
28 import org.eclipse.cdt.utils.spawner.EnvironmentReader; |
53 protected static IPath sbsPath; |
56 protected static IPath sbsPath; |
54 |
57 |
55 private static boolean scannedSbsState = false; |
58 private static boolean scannedSbsState = false; |
56 private static final String sbsScriptName = "sbs.bat"; |
59 private static final String sbsScriptName = "sbs.bat"; |
57 protected static final String SBS_HOME = "SBS_HOME"; |
60 protected static final String SBS_HOME = "SBS_HOME"; |
58 |
61 |
59 private static List<String> unfilteredSBSv2ConfigNames; |
62 /** Map of usable Raptor alias for -c parameter and base platform: <alias, base plat> */ |
60 |
63 private static Map<String, String> unfilteredSBSv2ConfigNames; |
61 |
64 |
62 /** |
65 /** |
63 * Get the path to the SBSv2 bin directory. This is based on the SBS_HOME environment variable |
66 * Get the path to the SBSv2 bin directory. This is based on the SBS_HOME environment variable |
64 * and may or may not actually exist. |
67 * and may or may not actually exist. |
65 * @return absolute path to the bin directory, or null if SBS_HOME is not set |
68 * @return absolute path to the bin directory, or null if SBS_HOME is not set |
73 } |
76 } |
74 |
77 |
75 /** |
78 /** |
76 * Get the build configurations supported by SBSv2 |
79 * Get the build configurations supported by SBSv2 |
77 * @param refreshList whether or not to parse the configuration xml files again |
80 * @param refreshList whether or not to parse the configuration xml files again |
78 * @return list of configuration names, never null |
81 * @return A map of raptor aliases (key) to base build platform. Never null; |
79 */ |
82 */ |
80 public static List<String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) { |
83 public static Map<String, String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) { |
81 |
84 |
82 if (unfilteredSBSv2ConfigNames == null || refreshList) { |
85 if (unfilteredSBSv2ConfigNames == null || refreshList) { |
83 unfilteredSBSv2ConfigNames = new ArrayList<String>(); |
86 unfilteredSBSv2ConfigNames = new HashMap<String, String>(); |
84 |
87 |
85 // parse the xml files in SBS_HOME/lib/config/ to get SBSv2 configs |
88 // parse the xml files in SBS_HOME/lib/config/ to get SBSv2 configs |
86 try { |
89 try { |
87 |
90 |
88 IPath configPath = getSBSBinDirectory(); |
91 IPath configPath = getSBSBinDirectory(); |
180 * @return the list of SBSv2 build contexts. the list may be empty |
183 * @return the list of SBSv2 build contexts. the list may be empty |
181 */ |
184 */ |
182 public static List<ISymbianBuildContext> getFilteredSBSv2BuildContexts(ISymbianSDK sdk) { |
185 public static List<ISymbianBuildContext> getFilteredSBSv2BuildContexts(ISymbianSDK sdk) { |
183 List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>(); |
186 List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>(); |
184 |
187 |
185 for (String name : getUnfilteredSBSv2BuildConfigurations(false)) { |
188 Iterator it = getUnfilteredSBSv2BuildConfigurations(false).entrySet().iterator(); |
186 |
189 while (it.hasNext()){ |
|
190 Map.Entry buildConfigPair = (Map.Entry)it.next(); |
|
191 String alias = (String)buildConfigPair.getKey(); // The sbsv2 alias |
|
192 String basePlat = (String)buildConfigPair.getValue(); |
|
193 |
187 boolean addConfig = true; |
194 boolean addConfig = true; |
188 for (String filteredConfig : getSBSv2ConfigurationsToFilter()) { |
195 for (String filteredConfig : getSBSv2ConfigurationsToFilter()) { |
189 if (filteredConfig.compareTo(name) == 0) { |
196 if (filteredConfig.compareTo(alias) == 0) { |
190 addConfig = false; |
197 addConfig = false; |
191 break; |
198 break; |
192 } |
199 } |
193 } |
200 } |
194 |
201 |
195 if (addConfig) { |
202 if (addConfig) { |
196 // only support configs that fall into something we can make a build context |
203 // only support configs that fall into something we can make a build context |
197 // out of. They must have a platform and a target. |
204 // out of. They must have a platform and a target. |
198 String targetString = null; |
205 String targetString = null; |
199 if (name.toLowerCase().endsWith("_udeb") || name.toLowerCase().endsWith("_deb")) { //$NON-NLS-1$ //$NON-NLS-2$ |
206 String[] configTokens = alias.split("_"); // $//$NON-NLS-N$ |
|
207 // We presume that aliases have the second token as the "target". |
|
208 if (configTokens[1].toLowerCase().endsWith("deb")) { //$NON-NLS-1$ |
200 targetString = ISymbianBuildContext.DEBUG_TARGET; |
209 targetString = ISymbianBuildContext.DEBUG_TARGET; |
201 } else if (name.toLowerCase().endsWith("_urel") || name.toLowerCase().endsWith("_rel")) { //$NON-NLS-1$ //$NON-NLS-2$ |
210 } else if (configTokens[1].toLowerCase().endsWith("rel")) { //$NON-NLS-1$ |
202 targetString = ISymbianBuildContext.RELEASE_TARGET; |
211 targetString = ISymbianBuildContext.RELEASE_TARGET; |
203 } |
212 } |
204 |
213 |
205 if (targetString != null) { |
214 if (targetString != null) { |
206 String[] parts = name.split("_"); //$NON-NLS-1$ |
215 |
207 if (parts.length == 2) { |
216 SymbianBuildContext context = null; |
208 SymbianBuildContext context = new SymbianBuildContext(sdk, parts[0].toUpperCase(), targetString); |
217 context = new SymbianBuildContext(sdk, basePlat, targetString, alias); |
|
218 if (context != null) |
209 contexts.add(context); |
219 contexts.add(context); |
210 } |
|
211 } |
220 } |
212 } |
221 } |
213 } |
222 } |
214 |
223 |
215 Collections.sort(contexts, new Comparator<ISymbianBuildContext>() { |
224 return sortContexts(contexts); |
216 |
|
217 public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) { |
|
218 String platform1 = o1.getPlatformString(); |
|
219 String platform2 = o2.getPlatformString(); |
|
220 if (platform1.equals(platform2)) { |
|
221 return o1.getTargetString().compareTo(o2.getTargetString()); |
|
222 } else { |
|
223 if (platform1.equals(ISymbianBuildContext.EMULATOR_PLATFORM)) { |
|
224 return -1; |
|
225 } |
|
226 else if (platform2.equals(ISymbianBuildContext.EMULATOR_PLATFORM)) { |
|
227 return 1; |
|
228 } |
|
229 } |
|
230 return 0; |
|
231 } |
|
232 |
|
233 }); |
|
234 |
|
235 return contexts; |
|
236 } |
225 } |
237 |
226 |
238 /** |
227 /** |
239 * Whether or not to display SBSv2 builder UI |
228 * Whether or not to display SBSv2 builder UI |
240 * @return true if SBSv2 is installed, false otherwise |
229 * @return true if SBSv2 is installed, false otherwise |
257 InputSource source = new InputSource(URIUtil.toURI(file.getAbsolutePath()).getPath()); |
246 InputSource source = new InputSource(URIUtil.toURI(file.getAbsolutePath()).getPath()); |
258 root = parser.parse(source).getDocumentElement(); |
247 root = parser.parse(source).getDocumentElement(); |
259 |
248 |
260 NodeList children = root.getChildNodes(); |
249 NodeList children = root.getChildNodes(); |
261 for (int i=0; i< children.getLength(); i++) { |
250 for (int i=0; i< children.getLength(); i++) { |
262 getConfigsForNode(children.item(i)); |
251 getConfigsForNode(children.item(i), root); |
263 } |
252 } |
264 |
253 |
265 } catch (Exception e) { |
254 } catch (Exception e) { |
266 e.printStackTrace(); |
255 e.printStackTrace(); |
267 Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); |
256 Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e)); |
268 } |
257 } |
269 } |
258 } |
270 |
259 |
271 private static void getConfigsForNode(Node node) { |
260 private static void getConfigsForNode(Node node, Node parentNode) { |
272 if (node.getNodeName().equals("config")) { //$NON-NLS-1$ |
261 if (node.getNodeName().equals("config")) { //$NON-NLS-1$ |
273 Node abstractNode = node.getAttributes().getNamedItem("abstract"); //$NON-NLS-1$ |
262 Node abstractNode = node.getAttributes().getNamedItem("abstract"); //$NON-NLS-1$ |
|
263 Node namedNode = node.getAttributes().getNamedItem("name"); //$NON-NLS-1$ |
274 if (abstractNode == null || abstractNode.getNodeValue().equals("false")) { //$NON-NLS-1$ |
264 if (abstractNode == null || abstractNode.getNodeValue().equals("false")) { //$NON-NLS-1$ |
275 Node namedNode = node.getAttributes().getNamedItem("name"); //$NON-NLS-1$ |
|
276 if (namedNode != null) { |
265 if (namedNode != null) { |
|
266 |
|
267 // Get the parent base build platform |
|
268 String baseBuildPlatform = null; |
|
269 if (parentNode != null){ |
|
270 baseBuildPlatform = parentNode.getAttributes().getNamedItem("name").getNodeValue(); |
|
271 } |
277 // only support configs that fall into something we can make a build context |
272 // only support configs that fall into something we can make a build context |
278 // out of. They must have a platform and a target. |
273 // out of. They must have a platform and a target. |
279 String configName = namedNode.getNodeValue(); |
274 String configName = namedNode.getNodeValue(); |
280 if (configName.toLowerCase().endsWith("_udeb") || configName.toLowerCase().endsWith("_deb") || //$NON-NLS-1$ //$NON-NLS-2$ |
275 String[] configTokens = configName.split("_"); |
281 configName.toLowerCase().endsWith("_urel") || configName.toLowerCase().endsWith("_rel")) { //$NON-NLS-1$ //$NON-NLS-2$ |
276 if (configTokens.length >= 2) { //$NON-NLS-1$ |
282 if (configName.split("_").length == 2) { //$NON-NLS-1$ |
277 String target = configTokens[1]; |
283 unfilteredSBSv2ConfigNames.add(configName); |
278 if (target.endsWith("deb") || target.endsWith("rel")){ //$NON-NLS-1$ |
284 } |
279 if (baseBuildPlatform == null){ |
285 } |
280 baseBuildPlatform = "unknown"; |
|
281 } |
|
282 unfilteredSBSv2ConfigNames.put(configName, baseBuildPlatform); |
|
283 } |
|
284 } |
286 } |
285 } |
287 } |
286 } |
288 |
287 |
289 NodeList children = node.getChildNodes(); |
288 NodeList children = node.getChildNodes(); |
290 for (int i=0; i< children.getLength(); i++) { |
289 for (int i=0; i< children.getLength(); i++) { |
291 getConfigsForNode(children.item(i)); |
290 getConfigsForNode(children.item(i), node); |
292 } |
291 } |
293 } |
292 } |
294 } |
293 } |
295 |
294 |
296 /** |
295 /** |
321 scannedSbsState = true; |
320 scannedSbsState = true; |
322 } |
321 } |
323 return sbsPath != null ? sbsPath : new Path(sbsScriptName); |
322 return sbsPath != null ? sbsPath : new Path(sbsScriptName); |
324 } |
323 } |
325 |
324 |
|
325 private static List<ISymbianBuildContext> sortContexts(List<ISymbianBuildContext> contexts){ |
|
326 |
|
327 // 3 sorting stages to handle long Raptor aliases, and multiple aliases that have a similar platform and target prefix (e.g. armv5_urel) |
|
328 |
|
329 Collections.sort(contexts, new Comparator<ISymbianBuildContext>() { |
|
330 |
|
331 // First sort the target name (Debug / Release) and push Emulation to the top |
|
332 public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) { |
|
333 String sbsAlias1 = o1.getSBSv2Alias(); |
|
334 String sbsAlias2 = o2.getSBSv2Alias(); |
|
335 |
|
336 if (o1.getPlatformString().equals(o2.getPlatformString())) { |
|
337 if (o1.getSBSv2Alias().split("_").length == 2 && o2.getSBSv2Alias().split("_").length == 2) |
|
338 return o1.getTargetString().compareTo(o2.getTargetString()); |
|
339 else if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3) |
|
340 return 1; |
|
341 } else { |
|
342 if (sbsAlias1.toUpperCase().startsWith(ISymbianBuildContext.EMULATOR_PLATFORM)) { |
|
343 return -1; |
|
344 }else if (sbsAlias2.toUpperCase().startsWith(ISymbianBuildContext.EMULATOR_PLATFORM)) { |
|
345 return 1; |
|
346 } |
|
347 } |
|
348 return sbsAlias1.compareTo(sbsAlias2); |
|
349 |
|
350 } |
|
351 |
|
352 }); |
|
353 |
|
354 // Sort long alias names |
|
355 Collections.sort(contexts, new Comparator<ISymbianBuildContext>() { |
|
356 |
|
357 public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) { |
|
358 String sbsAlias1 = o1.getSBSv2Alias(); |
|
359 String sbsAlias2 = o2.getSBSv2Alias(); |
|
360 |
|
361 if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3 && !sbsAlias1.equals(sbsAlias2)){ |
|
362 String temp1[] = sbsAlias1.split("_"); |
|
363 String temp2[] = sbsAlias2.split("_"); |
|
364 String suffix1 = ""; |
|
365 String suffix2 = ""; |
|
366 for (int i = 2; i < temp1.length; i++){ |
|
367 suffix1 += temp1[i] + "_"; |
|
368 } |
|
369 |
|
370 for (int i = 2; i < temp2.length; i++){ |
|
371 suffix2 += temp2[i] + "_"; |
|
372 } |
|
373 |
|
374 return suffix1.compareTo(suffix2); |
|
375 } |
|
376 |
|
377 return 0; |
|
378 } |
|
379 }); |
|
380 |
|
381 // Sort the target string for long aliases |
|
382 Collections.sort(contexts, new Comparator<ISymbianBuildContext>() { |
|
383 |
|
384 public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) { |
|
385 String sbsAlias1 = o1.getSBSv2Alias(); |
|
386 String sbsAlias2 = o2.getSBSv2Alias(); |
|
387 String temp1[] = sbsAlias1.split("_"); |
|
388 String temp2[] = sbsAlias2.split("_"); |
|
389 String suffix1 = ""; |
|
390 String suffix2 = ""; |
|
391 for (int i = 2; i < temp1.length; i++){ |
|
392 suffix1 += temp1[i] + "_"; |
|
393 } |
|
394 |
|
395 for (int i = 2; i < temp2.length; i++){ |
|
396 suffix2 += temp2[i] + "_"; |
|
397 } |
|
398 |
|
399 if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3 && suffix1.equals(suffix2)){ |
|
400 return o1.getTargetString().compareTo(o2.getTargetString()); |
|
401 } |
|
402 |
|
403 return 0; |
|
404 } |
|
405 }); |
|
406 |
|
407 return contexts; |
|
408 } |
|
409 |
326 } |
410 } |