bug 10674. Add support for long alias names from Carbide.xml (initial support)
authortimkelly
Fri, 26 Mar 2010 11:40:51 -0500
changeset 1134 081b99cb271a
parent 1133 31463ee29c35
child 1136 ca6770e516e2
bug 10674. Add support for long alias names from Carbide.xml (initial support)
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java
builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideSBSv2Builder.java
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java
core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/SBSv2PlatformFilterComposite.java
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideBuildConfiguration.java	Fri Mar 26 11:40:51 2010 -0500
@@ -70,7 +70,7 @@
 	
 
 	public CarbideBuildConfiguration(IProject project, ISymbianBuildContext context) {
-		super(context.getSDK(), context.getPlatformString(), context.getTargetString());
+		super(context.getSDK(), context.getPlatformString(), context.getTargetString(), context.getSBSv2Alias());
 		projectTracker = new TrackedResource(project);
 		sisBuilderInfoList = new ArrayList<ISISBuilderInfo>(0);
 		envVarsInfo = new EnvironmentVarsInfo2(project, context);
--- a/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideSBSv2Builder.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/builder/com.nokia.carbide.cdt.builder/src/com/nokia/carbide/cdt/internal/builder/CarbideSBSv2Builder.java	Fri Mar 26 11:40:51 2010 -0500
@@ -33,7 +33,6 @@
 import com.nokia.carbide.cdt.builder.project.ICarbideBuildConfiguration;
 import com.nokia.carbide.cdt.builder.project.ICarbideProjectInfo;
 import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils;
-import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
 
 public class CarbideSBSv2Builder implements ICarbideBuilder {
 
@@ -87,9 +86,9 @@
 		return true;
 	}
     
+    /** Get the build-able configuration from the command line (i.e. build alias). This is passed after the sbs -c parameter */
     protected String getConfigName(ICarbideBuildConfiguration buildConfig) {
-    	//TODO is this sufficient?
-    	return buildConfig.getPlatformString().toLowerCase() + "_" + buildConfig.getTargetString().toLowerCase(); //$NON-NLS-1$
+    	 return buildConfig.getSBSv2Alias();
     }
     
 	public boolean buildComponent(ICarbideBuildConfiguration buildConfig, IPath componentPath, boolean isTest, CarbideCommandLauncher launcher, IProgressMonitor monitor) {
@@ -497,6 +496,9 @@
 		args.add(cpi.getAbsoluteBldInfPath().toOSString());
 		args.add("-c"); //$NON-NLS-1$
 		String configName = getConfigName(buildConfig);
+		if (configName == null){
+			configName = "error_retrieving_sbs_config";
+		}
 		if (isTest) {
 			configName = configName + ".test"; //$NON-NLS-1$
 		}
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Fri Mar 26 11:40:51 2010 -0500
@@ -15,23 +15,34 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.text.MessageFormat;
-import java.util.*;
+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;
 
 import org.eclipse.cdt.utils.spawner.EnvironmentReader;
 import org.eclipse.core.filesystem.URIUtil;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
 import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.osgi.framework.Version;
 import org.osgi.service.prefs.BackingStoreException;
-import org.w3c.dom.*;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 import org.xml.sax.helpers.DefaultHandler;
 
-import com.nokia.carbide.cpp.sdk.core.*;
+import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
 import com.nokia.cpp.internal.api.utils.core.FileUtils;
 import com.nokia.cpp.internal.api.utils.core.HostOS;
 import com.nokia.cpp.internal.api.utils.core.Logging;
@@ -45,7 +56,10 @@
 	private static final String SBSV2_FILTERED_CONFIGS_STORE = "sbsv2FilteredConfigs"; //$NON-NLS-1$
 	private static final String SBSV2_FILTERED_CONFIGS_DELIMETER = ";"; //$NON-NLS-1$
 
-	private static List<String> unfilteredSBSv2ConfigNames;
+	/**
+	 * Map of usable Raptor alias for -c parameter and base platform: <alise, base plat>
+	 */
+	private static Map<String, String> unfilteredSBSv2ConfigNames;
 
 	protected static final String SBS_HOME = "SBS_HOME";
 	protected static String sbsHome;
@@ -70,12 +84,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 {
@@ -187,32 +201,40 @@
 	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;
 				}
 			}
 
 			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;
-		    	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$ //$NON-NLS-2$
 		    		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$ //$NON-NLS-2$
 		    		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);
-		    		}
 		    	}
 			}
 		}
@@ -278,7 +300,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) {
@@ -287,27 +309,38 @@
     	}
     }
     
-    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);
 			}
 		}
     }
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SymbianBuildContext.java	Fri Mar 26 11:40:51 2010 -0500
@@ -28,6 +28,7 @@
 	private String platform;
 	private String target;
 	private String displayString = null;
+	private String sbsv2Alias = null;
 	
 	private static String EMULATOR_DISPLAY_TEXT = "Emulator"; //$NON-NLS-1$
 	private static String PHONE_DISPLAY_TEXT = "Phone"; //$NON-NLS-1$
@@ -46,6 +47,15 @@
 		
 		getDisplayString();
 	}
+	
+	public SymbianBuildContext(ISymbianSDK theSDK, String thePlatform, String theTarget, String theSBSv2Alias) {
+		sdkId = theSDK.getUniqueId();
+		platform = thePlatform;
+		target = theTarget;
+		sbsv2Alias = theSBSv2Alias;
+		
+		getDisplayString();
+	}
 
 	
 	@Override
@@ -121,8 +131,14 @@
 			} else {
 				displayString = displayString + SPACE_DISPLAY_TEXT + RELEASE_DISPLAY_TEXT;
 			}
-
-			displayString = displayString + " (" + platform + ") [" + getSDK().getUniqueId() + "]"; //$NON-NLS-1$
+			
+			String basePlatform;
+			if (sbsv2Alias != null)
+				basePlatform = sbsv2Alias;
+			else
+				basePlatform = platform;
+			
+			displayString = displayString + " (" + basePlatform + ") [" + getSDK().getUniqueId() + "]"; //$NON-NLS-1$
 		}
 		return displayString;
 	}
@@ -136,15 +152,43 @@
 				sdk = SDKManagerInternalAPI.addMissingSdk(sdkId);
 			}
 						
-			return new SymbianBuildContext(sdk, getPlatformFromBuildConfigName(displayName), getTargetFromBuildConfigName(displayName));
+			return new SymbianBuildContext(sdk, 
+						getPlatformFromBuildConfigName(displayName), 
+						getTargetFromBuildConfigName(displayName),
+						getSBSv2AliasFromConfigName(displayName));
 		}
 		return new SymbianBuildContext(fallbackForBadSdk, SDK_NOT_INSTALLED, SDK_NOT_INSTALLED);
 	}
 
+	/**
+	 * See if the build configuration is an SBSv2 alias, and if so get the build-able alias name 
+	 * @param displayName
+	 * @return The full SBSv2 alias that can be used with -c, otherwise null if not SBSv2
+	 */
+	private static String getSBSv2AliasFromConfigName(String displayName) {
+		int indexBegin = displayName.indexOf("(");  //$NON-NLS-1$
+		int indexEnd = displayName.indexOf(")");  //$NON-NLS-1$
+		if (indexBegin > 0 && indexEnd > 0){
+			String configPart =  displayName.substring(indexBegin+1, indexEnd);
+			if (configPart.split("_").length > 0){
+				return configPart;
+			}
+		} 
+		
+		return null;
+	}
+
 	private static String getPlatformFromBuildConfigName(String configName) {
 		String[] tokens = configName.split(SPACE_DISPLAY_TEXT);
 		String sdkIdToken = tokens[2];
-		return sdkIdToken.substring(1, sdkIdToken.length()-1);
+		if (sdkIdToken.contains("_")){
+			sdkIdToken = sdkIdToken.substring(1, sdkIdToken.length()-1);
+			String[] aliasTokens = sdkIdToken.split("_");
+			return aliasTokens[0];
+		} else {
+			return sdkIdToken.substring(1, sdkIdToken.length()-1);
+		}
+		
 	}
 
 	public static String getSDKIDFromConfigName(String configName) {
@@ -388,4 +432,8 @@
 		return getCachedData().getSystemIncludePaths();
 	}
 
+	public String getSBSv2Alias() {
+		return sbsv2Alias;
+	}
+
 }
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/sdk/core/ISymbianBuildContext.java	Fri Mar 26 11:40:51 2010 -0500
@@ -143,4 +143,11 @@
 	 * @since 2.0
 	 */
 	public boolean isSymbianBinaryVariation();
+	
+	/**
+	 * Retrieve the build-able configuration; a valid command that cab be passed with Raptor's -c parameter.
+	 * This should not be used and should return null for abld-configurations.
+	 * @return the configuration name, or null if none.
+	 */
+	public String getSBSv2Alias();
 }
--- a/core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/SBSv2PlatformFilterComposite.java	Fri Mar 26 10:52:52 2010 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.ui/src/com/nokia/carbide/cpp/internal/api/sdk/ui/SBSv2PlatformFilterComposite.java	Fri Mar 26 11:40:51 2010 -0500
@@ -97,7 +97,7 @@
 	
 	private void initTable(boolean refreshList) {
 
-		tableViewer.setInput(SBSv2Utils.getUnfilteredSBSv2BuildConfigurations(refreshList));
+		tableViewer.setInput(SBSv2Utils.getUnfilteredSBSv2BuildConfigurations(refreshList).keySet());
 
 		// check all configs
 		tableViewer.setAllChecked(true);