core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java
branchC3_BUILDER_WORK
changeset 1476 09e768e53db5
parent 1459 51ff67a50dee
child 1478 69015f2143b2
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Tue Jun 15 23:12:37 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Wed Jun 16 11:49:20 2010 -0500
@@ -55,15 +55,17 @@
  */
 public class SBSv2Utils {
 
-	private static final String SBSV2_FILTERED_CONFIGS_STORE = "sbsv2FilteredConfigs"; //$NON-NLS-1$
-	private static final String SBSV2_FILTERED_CONFIGS_STORE_INITED = "sbsv2FilteredConfigsInited"; //$NON-NLS-1$
+	//private static final String SBSV2_FILTERED_CONFIGS_STORE = "sbsv2FilteredConfigs"; //$NON-NLS-1$
+	private static final String SBSV2_FILTERED_CONFIGS_STORE_V2 = "sbsv2FilteredConfigs_V2"; //$NON-NLS-1$
+	//private static final String SBSV2_FILTERED_CONFIGS_STORE_INITED = "sbsv2FilteredConfigsInited"; //$NON-NLS-1$
+	private static final String SBSV2_FILTERED_CONFIGS_STORE_INITED_V2 = "sbsv2FilteredConfigsInited_V2"; //$NON-NLS-1$
 	private static final String SBSV2_FILTERED_CONFIGS_DELIMETER = ";"; //$NON-NLS-1$
 	private static final long VALID_ABLD_SIZE = 1024;
 
 	/**
 	 * Map of usable Raptor alias for -c parameter and base platform: <alise, base plat>
 	 */
-	private static Map<String, String> unfilteredSBSv2ConfigNames;
+//	private static Map<String, String> unfilteredSBSv2ConfigNames;
 
 	/** Path, to and including the SBS script */
 	protected static IPath sbsPath;
@@ -90,44 +92,44 @@
      * @param refreshList whether or not to parse the configuration xml files again
      * @return A map of raptor aliases (key) to base build platform. Never null;
      */
-    public static Map<String, String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) {
-    	
-    	if (unfilteredSBSv2ConfigNames == null || refreshList || unfilteredSBSv2ConfigNames.size() == 0) {
-    		unfilteredSBSv2ConfigNames = new HashMap<String, String>();
-    		
-        	// parse the xml files in <sbs-install>/lib/config/ to get SBSv2 configs
-    		try {
-
-    			IPath configPath = getSBSBinDirectory();
-    			if (configPath != null) {
-    				configPath = configPath.removeLastSegments(1).append("lib/config"); //$NON-NLS-1$
-    				File configDir = configPath.toFile();
-    				if (configDir.exists() && configDir.isDirectory()) {
-    					File[] configFiles = FileUtils.listFilesInTree(configDir, new FileFilter() {
-
-    						public boolean accept(File arg0) {
-    							if (arg0.isDirectory()) {
-    								return true;
-    							}
-    							return arg0.getName().toLowerCase().endsWith("xml"); //$NON-NLS-1$
-    						}
-    						
-    					}, false);
-    					
-    					for (File file : configFiles) {
-    						getConfigsForFile(file);
-    					}
-    				}
-    			}
-
-    		} catch (Exception e) {
-        		e.printStackTrace();
-        		Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e));
-    		}
-    	}
-    	
-    	return unfilteredSBSv2ConfigNames;
-	}
+//    public static Map<String, String> getUnfilteredSBSv2BuildConfigurations(boolean refreshList) {
+//    	
+//    	if (unfilteredSBSv2ConfigNames == null || refreshList || unfilteredSBSv2ConfigNames.size() == 0) {
+//    		unfilteredSBSv2ConfigNames = new HashMap<String, String>();
+//    		
+//        	// parse the xml files in <sbs-install>/lib/config/ to get SBSv2 configs
+//    		try {
+//
+//    			IPath configPath = getSBSBinDirectory();
+//    			if (configPath != null) {
+//    				configPath = configPath.removeLastSegments(1).append("lib/config"); //$NON-NLS-1$
+//    				File configDir = configPath.toFile();
+//    				if (configDir.exists() && configDir.isDirectory()) {
+//    					File[] configFiles = FileUtils.listFilesInTree(configDir, new FileFilter() {
+//
+//    						public boolean accept(File arg0) {
+//    							if (arg0.isDirectory()) {
+//    								return true;
+//    							}
+//    							return arg0.getName().toLowerCase().endsWith("xml"); //$NON-NLS-1$
+//    						}
+//    						
+//    					}, false);
+//    					
+//    					for (File file : configFiles) {
+//    						getConfigsForFile(file);
+//    					}
+//    				}
+//    			}
+//
+//    		} catch (Exception e) {
+//        		e.printStackTrace();
+//        		Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e));
+//    		}
+//    	}
+//    	
+//    	return unfilteredSBSv2ConfigNames;
+//	}
 
     /**
      * Given a list of SDKs, returns the list of the SDK's supported by SBSv2
@@ -156,23 +158,27 @@
     
 	/**
 	 * Returns the list of SBSv2 build configuration names that should
-	 * be filtered out of any UI
+	 * INCLUDED in any UI. Only configs to be displayed are saved
 	 */
-	public static String[] getSBSv2ConfigurationsToFilter() {
+	public static List<String> getSBSv2FilteredConfigs() {
+		List<String> buildAliasList = new ArrayList<String>();
 		IEclipsePreferences prefs = new InstanceScope().getNode(SDKCorePlugin.PLUGIN_ID);
 		if (prefs != null) {
-			String configs = prefs.get(SBSV2_FILTERED_CONFIGS_STORE, "");
-			return configs.split(SBSV2_FILTERED_CONFIGS_DELIMETER);
+			String configs = prefs.get(SBSV2_FILTERED_CONFIGS_STORE_V2, "");
+			String aliasesToInclude[] = configs.split(SBSV2_FILTERED_CONFIGS_DELIMETER);
+			for (String alias : aliasesToInclude){
+				buildAliasList.add(alias);
+			}
 		}
-		return new String[0];
+		return buildAliasList;
 	}
 
 	/**
-	 * Set the list of SBSv2 build configurations that should be filtered
-	 * out of any UI
+	 * Set the list of SBSv2 build configurations that should be included in a build config list
+	 * All others will be filtered out
 	 * @param configs configs to be filtered
 	 */
-	public static void setSBSv2ConfigurationsToFilter(String[] configs) {
+	public static void setSBSv2FilteredConfigs(String[] configs) {
 		IEclipsePreferences prefs = new InstanceScope().getNode(SDKCorePlugin.PLUGIN_ID);
 		if (prefs != null) {
 			String store = ""; //$NON-NLS-1$
@@ -186,7 +192,7 @@
 			}
 			if (store.length() >= 0){
 				// lenght of zero means there are not configs to filter (or show them all)
-				prefs.put(SBSV2_FILTERED_CONFIGS_STORE, store);
+				prefs.put(SBSV2_FILTERED_CONFIGS_STORE_V2, store);
 				try {
 					prefs.flush();
 				} catch (BackingStoreException e) {
@@ -198,118 +204,24 @@
 	}
 
 	/**
-	 * Gets the list of all SBSv2 build contexts for the given SDK
-	 * @param sdk the SDK to get the build contexts for
-	 * @return the list of SBSv2 build contexts.  the list may be empty
-	 */
-	public static List<ISymbianBuildContext> getAllSBSv2BuildContexts(ISymbianSDK sdk) {
-		List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>();
-		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();
-			// 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;
-			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$ //$NON-NLS-2$
-	    		targetString = ISymbianBuildContext.DEBUG_TARGET;
-	    	} else if (configTokens[1].toLowerCase().endsWith("rel")) { //$NON-NLS-1$ //$NON-NLS-2$
-	    		targetString = ISymbianBuildContext.RELEASE_TARGET;
-	    	}
-	    	
-	    	if (targetString != null) {
-	    		BuildContextSBSv2 context = null;
-	    		// TODO: Display String not properly set
-	    		String configID = ISBSv2BuildContext.BUILDER_ID + "." + alias + "." + sdk.getUniqueId();
-	    		String displayString = alias + " [" + sdk.getUniqueId() + "]";
-	    		context = new BuildContextSBSv2(sdk, basePlat, targetString, alias, displayString, configID);
-	    		if (context != null) 
-	    			contexts.add(context);
-	    	}
-		}
-		
-		return sortContexts(contexts);
-	}
-
-	/**
-	 * Gets the list of SBSv2 build contexts for the given SDK
-	 * @param sdk the SDK to get the build contexts for
-	 * @return the list of SBSv2 build contexts.  the list may be empty
-	 */
-	public static List<ISymbianBuildContext> getFilteredSBSv2BuildContexts(ISymbianSDK sdk) {
-		List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>();
-		
-		initDefaultConfigsToFilter();
-		
-		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(alias) == 0) {
-					addConfig = false;
-					break;
-				}
-			}
-
-			if (addConfig) {
-
-				// 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;
-				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$ //$NON-NLS-2$
-		    		targetString = ISymbianBuildContext.DEBUG_TARGET;
-		    	} else if (configTokens[1].toLowerCase().endsWith("rel")) { //$NON-NLS-1$ //$NON-NLS-2$
-		    		targetString = ISymbianBuildContext.RELEASE_TARGET;
-		    	}
-		    	
-		    	if (targetString != null) {
-		    		BuildContextSBSv2 context = null;
-		    		// TODO: Display String not properly set
-		    		String configID = ISBSv2BuildContext.BUILDER_ID + "." + alias + "." + sdk.getUniqueId();
-		    		String displayString = alias + " [" + sdk.getUniqueId() + "]";
-		    		context = new BuildContextSBSv2(sdk, basePlat, targetString, alias, displayString, configID);
-		    		if (context != null) 
-		    			contexts.add(context);
-		    	}
-			}
-		}
-		
-		return sortContexts(contexts);
-	}
-
-	/**
 	 * There are many build aliases presented by default from Raptor
 	 * Filter out those that are less commonly used on new workspace creation.
 	 */
 	public static void initDefaultConfigsToFilter() {
 		IEclipsePreferences prefs = new InstanceScope().getNode(SDKCorePlugin.getPluginId());
-		String inited = prefs.get(SBSV2_FILTERED_CONFIGS_STORE_INITED, "");
+		String inited = prefs.get(SBSV2_FILTERED_CONFIGS_STORE_INITED_V2, "");
 		if (inited == null || inited.length() == 0){
-			Iterator it = getUnfilteredSBSv2BuildConfigurations(false).entrySet().iterator(); 
 			List<String> defaultConfigsToFilter = new ArrayList<String>();
-			while (it.hasNext()){ 
-				Map.Entry buildConfigPair = (Map.Entry)it.next();
-				String buildAlias = (String)buildConfigPair.getKey();
-				if (buildAlias.toLowerCase().startsWith("armv6") ||
-					buildAlias.toLowerCase().startsWith("armv7") ||
-					buildAlias.toLowerCase().startsWith("armv9")){
-					defaultConfigsToFilter.add(buildAlias);
-				}
-			}
-			prefs.put(SBSV2_FILTERED_CONFIGS_STORE_INITED, "true");
-			setSBSv2ConfigurationsToFilter(defaultConfigsToFilter.toArray(new String[defaultConfigsToFilter.size()]));
+			
+			defaultConfigsToFilter.add("armv5_udeb");
+			defaultConfigsToFilter.add("armv5_urel");
+			defaultConfigsToFilter.add("armv5_udeb_gcce");
+			defaultConfigsToFilter.add("armv5_urel_gcce");
+			defaultConfigsToFilter.add("winscw_urel");
+			defaultConfigsToFilter.add("winscw_udeb");
+			
+			prefs.put(SBSV2_FILTERED_CONFIGS_STORE_INITED_V2, "true");
+			setSBSv2FilteredConfigs(defaultConfigsToFilter.toArray(new String[defaultConfigsToFilter.size()]));
 			
 		}
 	}
@@ -346,66 +258,6 @@
 		return false;
 	}
 
-	private static void getConfigsForFile(File file) {
-    	
-    	try {
-    		Element root = null;
-    		DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-    		parser.setErrorHandler(new DefaultHandler());
-
-    		InputSource source = new InputSource(URIUtil.toURI(file.getAbsolutePath()).getPath());
-    		root = parser.parse(source).getDocumentElement();
-    		
-    		NodeList children = root.getChildNodes();
-    		for (int i=0; i< children.getLength(); i++) {
-    			getConfigsForNode(children.item(i), root);
-    		}
-    		
-    	} catch (Exception e) {
-    		e.printStackTrace();
-    		Logging.log(SDKCorePlugin.getDefault(), Logging.newStatus(SDKCorePlugin.getDefault(), e));
-    	}
-    }
-    
-    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$
-				if (namedNode != null) {
-					
-					// Get the parent base build platform
-					String baseBuildPlatform = null;
-					if (parentNode != null){
-						baseBuildPlatform = parentNode.getAttributes().getNamedItem("name").getNodeValue();
-						if (baseBuildPlatform.split("_").length > 1){
-							baseBuildPlatform = baseBuildPlatform.split("_")[0];
-						}
-					}
-					
-					// 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();
-					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), node);
-			}
-		}
-    }
-
 	/**
 	 * (Re-)scan the SBSv2 / Raptor configuration
 	 * @return message if error, else null
@@ -444,93 +296,14 @@
 	}
 	
 	private static List<ISymbianBuildContext> sortContexts(List<ISymbianBuildContext> contexts){ 
-    	
-		// 2 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) {
-				ISBSv2BuildContext sbsv2Context1 = null;
-				ISBSv2BuildContext sbsv2Context2 = null;
-				String sbsAlias1 = "";
-				String sbsAlias2 = "";
-				if (o1 instanceof ISBSv2BuildContext && o2 instanceof ISBSv2BuildContext){
-					sbsv2Context1 = ((ISBSv2BuildContext)o1);
-					sbsv2Context2 = ((ISBSv2BuildContext)o2);
-					sbsAlias1 = sbsv2Context1.getSBSv2Alias();
-					sbsAlias2 = sbsv2Context2.getSBSv2Alias();
-				}
-				if (o1.getPlatformString().equals(o2.getPlatformString())) {
-					if (sbsv2Context1.getSBSv2Alias().split("_").length != sbsv2Context1.getSBSv2Alias().split("_").length)
-						return o1.getTargetString().compareTo(o2.getTargetString());
-					else if (sbsAlias1.split("_").length >= 3){
-						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);
-					} 
-				} 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) {
-				ISBSv2BuildContext sbsv2Context1 = null;
-				ISBSv2BuildContext sbsv2Context2 = null;
-				String sbsAlias1 = "";
-				String sbsAlias2 = "";
-				if (o1 instanceof ISBSv2BuildContext && o2 instanceof ISBSv2BuildContext){
-					sbsv2Context1 = ((ISBSv2BuildContext)o1);
-					sbsv2Context2 = ((ISBSv2BuildContext)o2);
-					sbsAlias1 = sbsv2Context1.getSBSv2Alias();
-					sbsAlias2 = sbsv2Context2.getSBSv2Alias();
-				}
-				
-				if (sbsv2Context1.getSBSv2Alias().split("_").length == 3 && sbsv2Context2.getSBSv2Alias().split("_").length == 3 &&
-						o1.getPlatformString().equals(o2.getPlatformString()))
-					return o1.getTargetString().compareTo(o2.getTargetString());
-				else 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;	
+				return o2.getDisplayString().compareTo(o1.getDisplayString());
 			}
 		});
 		
-    	return contexts; 
-    }
+		return contexts; 
+	}
 	
 	/**
 	 * If a variant is defined and it changes the output directory, return the directory name.