core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java
branchRCL_2_4
changeset 1147 c2836b036bd5
parent 787 f90a80bff752
child 1181 9d05552239c2
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Wed Mar 31 13:19:37 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Wed Mar 31 16:21:55 2010 -0500
@@ -17,7 +17,10 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -55,9 +58,9 @@
 	private static boolean scannedSbsState = false; 
 	private static final String sbsScriptName = "sbs.bat"; 
 	protected static final String SBS_HOME = "SBS_HOME"; 
-	
-	private static List<String> unfilteredSBSv2ConfigNames;
 
+	/** Map of usable Raptor alias for -c parameter and base platform: <alias, base plat>  */
+	private static Map<String, String> unfilteredSBSv2ConfigNames; 
 	
 	/**
      * Get the path to the SBSv2 bin directory.  This is based on the SBS_HOME environment variable
@@ -75,12 +78,12 @@
     /**
      * Get the build configurations supported by SBSv2
      * @param refreshList whether or not to parse the configuration xml files again
-     * @return list of configuration names, never null
+     * @return A map of raptor aliases (key) to base build platform. Never null; 
      */
-    public static List<String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) {
+    public static Map<String, String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) { 
     	
     	if (unfilteredSBSv2ConfigNames == null || refreshList) {
-    		unfilteredSBSv2ConfigNames = new ArrayList<String>();
+    		unfilteredSBSv2ConfigNames = new HashMap<String, String>(); 
     		
         	// parse the xml files in SBS_HOME/lib/config/ to get SBSv2 configs
     		try {
@@ -182,11 +185,15 @@
 	public static List<ISymbianBuildContext> getFilteredSBSv2BuildContexts(ISymbianSDK sdk) {
 		List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>();
 		
-		for (String name : getUnfilteredSBSv2BuildConfigurations(false)) {
-
+		Iterator it = getUnfilteredSBSv2BuildConfigurations(false).entrySet().iterator(); 
+		while (it.hasNext()){ 
+			Map.Entry buildConfigPair = (Map.Entry)it.next(); 
+			String alias = (String)buildConfigPair.getKey(); // The sbsv2 alias 
+			String basePlat = (String)buildConfigPair.getValue(); 
+			
 			boolean addConfig = true;
 			for (String filteredConfig : getSBSv2ConfigurationsToFilter()) {
-				if (filteredConfig.compareTo(name) == 0) {
+				if (filteredConfig.compareTo(alias) == 0) {
 					addConfig = false;
 					break;
 				}
@@ -196,43 +203,25 @@
 				// only support configs that fall into something we can make a build context
 				// out of.  They must have a platform and a target.
 				String targetString = null;
-		    	if (name.toLowerCase().endsWith("_udeb") || name.toLowerCase().endsWith("_deb")) { //$NON-NLS-1$ //$NON-NLS-2$
+				String[] configTokens = alias.split("_"); // $//$NON-NLS-N$ 
+				// We presume that aliases have the second token as the "target". 
+				if (configTokens[1].toLowerCase().endsWith("deb")) { //$NON-NLS-1$
 		    		targetString = ISymbianBuildContext.DEBUG_TARGET;
-		    	} else if (name.toLowerCase().endsWith("_urel") || name.toLowerCase().endsWith("_rel")) { //$NON-NLS-1$ //$NON-NLS-2$
+				} else if (configTokens[1].toLowerCase().endsWith("rel")) { //$NON-NLS-1$
 		    		targetString = ISymbianBuildContext.RELEASE_TARGET;
 		    	}
 		    	
 		    	if (targetString != null) {
-		    		String[] parts = name.split("_"); //$NON-NLS-1$
-		    		if (parts.length == 2) {
-		    			SymbianBuildContext context = new SymbianBuildContext(sdk, parts[0].toUpperCase(), targetString);
+		    		
+		    		SymbianBuildContext context = null; 
+		    		context = new SymbianBuildContext(sdk, basePlat, targetString, alias); 	
+		    		if (context != null) 
 		    			contexts.add(context);
-		    		}
 		    	}
 			}
 		}
 		
-		Collections.sort(contexts, new Comparator<ISymbianBuildContext>() {
-
-			public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) {
-				String platform1 = o1.getPlatformString();
-				String platform2 = o2.getPlatformString();
-				if (platform1.equals(platform2)) {
-					return o1.getTargetString().compareTo(o2.getTargetString());
-				} else {
-					if (platform1.equals(ISymbianBuildContext.EMULATOR_PLATFORM)) {
-						return -1;
-					}
-					else if (platform2.equals(ISymbianBuildContext.EMULATOR_PLATFORM)) {
-						return 1;
-					}
-				}
-				return 0;
-			}
-			
-		});
-
-		return contexts;
+		return sortContexts(contexts);
 	}
 
 	/**
@@ -259,7 +248,7 @@
     		
     		NodeList children = root.getChildNodes();
     		for (int i=0; i< children.getLength(); i++) {
-    			getConfigsForNode(children.item(i));
+    			getConfigsForNode(children.item(i), root);
     		}
     		
     	} catch (Exception e) {
@@ -268,27 +257,37 @@
     	}
     }
     
-    private static void getConfigsForNode(Node node) {
+	private static void getConfigsForNode(Node node, Node parentNode) { 
 		if (node.getNodeName().equals("config")) { //$NON-NLS-1$
 			Node abstractNode = node.getAttributes().getNamedItem("abstract");  //$NON-NLS-1$
+			Node namedNode = node.getAttributes().getNamedItem("name"); //$NON-NLS-1$ 
 			if (abstractNode == null || abstractNode.getNodeValue().equals("false")) { //$NON-NLS-1$
-				Node namedNode = node.getAttributes().getNamedItem("name"); //$NON-NLS-1$
 				if (namedNode != null) {
+					
+					// Get the parent base build platform 
+					String baseBuildPlatform = null; 
+					if (parentNode != null){ 
+						baseBuildPlatform = parentNode.getAttributes().getNamedItem("name").getNodeValue(); 
+					}
 					// only support configs that fall into something we can make a build context
 					// out of.  They must have a platform and a target.
 					String configName = namedNode.getNodeValue();
-			    	if (configName.toLowerCase().endsWith("_udeb") || configName.toLowerCase().endsWith("_deb") || //$NON-NLS-1$ //$NON-NLS-2$
-		    			configName.toLowerCase().endsWith("_urel") || configName.toLowerCase().endsWith("_rel")) { //$NON-NLS-1$ //$NON-NLS-2$
-			    		if (configName.split("_").length == 2) { //$NON-NLS-1$
-							unfilteredSBSv2ConfigNames.add(configName);
-			    		}
-			    	}
+					String[] configTokens = configName.split("_"); 
+					if (configTokens.length >= 2) { //$NON-NLS-1$ 
+						String target = configTokens[1]; 
+						if (target.endsWith("deb") || target.endsWith("rel")){ //$NON-NLS-1$ 
+							if (baseBuildPlatform == null){ 
+								baseBuildPlatform = "unknown"; 
+							}
+							unfilteredSBSv2ConfigNames.put(configName, baseBuildPlatform); 
+						}
+					}
 				}
 			}
 
 			NodeList children = node.getChildNodes();
 			for (int i=0; i< children.getLength(); i++) {
-				getConfigsForNode(children.item(i));
+				getConfigsForNode(children.item(i), node);
 			}
 		}
     }
@@ -323,4 +322,89 @@
     	return sbsPath != null ? sbsPath : new Path(sbsScriptName); 
     }
     
+    private static List<ISymbianBuildContext> sortContexts(List<ISymbianBuildContext> contexts){ 
+    	
+		// 3 sorting stages to handle long Raptor aliases, and multiple aliases that have a similar platform and target prefix (e.g. armv5_urel)
+		
+		Collections.sort(contexts, new Comparator<ISymbianBuildContext>() {
+
+			// First sort the target name (Debug / Release) and push Emulation to the top
+			public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) {
+				String sbsAlias1 = o1.getSBSv2Alias();
+				String sbsAlias2 = o2.getSBSv2Alias();
+				
+				if (o1.getPlatformString().equals(o2.getPlatformString())) {
+					if (o1.getSBSv2Alias().split("_").length == 2 && o2.getSBSv2Alias().split("_").length == 2)
+						return o1.getTargetString().compareTo(o2.getTargetString());
+					else if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3)
+						return 1;
+				} else {
+					if (sbsAlias1.toUpperCase().startsWith(ISymbianBuildContext.EMULATOR_PLATFORM)) {
+						return -1;
+					}else if (sbsAlias2.toUpperCase().startsWith(ISymbianBuildContext.EMULATOR_PLATFORM)) {
+						return 1;
+					} 
+				}
+				return sbsAlias1.compareTo(sbsAlias2);
+				
+			}
+			
+		});
+
+		// Sort long alias names
+		Collections.sort(contexts, new Comparator<ISymbianBuildContext>() {
+
+			public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) {
+				String sbsAlias1 = o1.getSBSv2Alias();
+				String sbsAlias2 = o2.getSBSv2Alias();
+				
+				if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3 && !sbsAlias1.equals(sbsAlias2)){
+					String temp1[] = sbsAlias1.split("_");
+					String temp2[] = sbsAlias2.split("_");
+					String suffix1 = "";
+					String suffix2 = "";
+					for (int i = 2; i < temp1.length; i++){
+						suffix1 += temp1[i] + "_";
+					}
+					
+					for (int i = 2; i < temp2.length; i++){
+						suffix2 += temp2[i] + "_";
+					}
+					
+					return suffix1.compareTo(suffix2);
+				} 
+				
+				return 0;	
+			}
+		});
+		
+		// Sort the target string for long aliases
+		Collections.sort(contexts, new Comparator<ISymbianBuildContext>() {
+
+			public int compare(ISymbianBuildContext o1, ISymbianBuildContext o2) {
+				String sbsAlias1 = o1.getSBSv2Alias();
+				String sbsAlias2 = o2.getSBSv2Alias();
+				String temp1[] = sbsAlias1.split("_");
+				String temp2[] = sbsAlias2.split("_");
+				String suffix1 = "";
+				String suffix2 = "";
+				for (int i = 2; i < temp1.length; i++){
+					suffix1 += temp1[i] + "_";
+				}
+				
+				for (int i = 2; i < temp2.length; i++){
+					suffix2 += temp2[i] + "_";
+				}
+				
+				if (sbsAlias1.split("_").length >= 3 && sbsAlias1.split("_").length >= 3 && suffix1.equals(suffix2)){
+					return o1.getTargetString().compareTo(o2.getTargetString());
+				} 
+				
+				return 0;	
+			}
+		});
+		
+    	return contexts; 
+    }
+    
 }