initial implementation of scripting extension & Symbian SDK list retrieval and basic bld.inf project import.
authortimkelly
Fri, 23 Oct 2009 08:56:35 -0500
changeset 544 6911e366cafa
parent 541 37c8331f98f7
child 548 7b0ddf4b33fa
initial implementation of scripting extension & Symbian SDK list retrieval and basic bld.inf project import.
core/com.nokia.carbide.cpp.sdk.core/.project
core/com.nokia.carbide.cpp.sdk.core/plugin.xml
core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/scripting/SDKScriptManager.java
project/com.nokia.carbide.cpp.project.ui/plugin.xml
project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/scripting/ImportBldInfWrapper.java
project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/scripting/ImporterScritpingUtils.java
--- a/core/com.nokia.carbide.cpp.sdk.core/.project	Wed Oct 21 14:28:08 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/.project	Fri Oct 23 08:56:35 2009 -0500
@@ -6,6 +6,11 @@
 	</projects>
 	<buildSpec>
 		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
 			<name>org.eclipse.jdt.core.javabuilder</name>
 			<arguments>
 			</arguments>
@@ -30,5 +35,6 @@
 		<nature>org.eclipse.pde.PluginNature</nature>
 		<nature>org.eclipse.jdt.core.javanature</nature>
 		<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+		<nature>org.python.pydev.pythonNature</nature>
 	</natures>
 </projectDescription>
--- a/core/com.nokia.carbide.cpp.sdk.core/plugin.xml	Wed Oct 21 14:28:08 2009 -0500
+++ b/core/com.nokia.carbide.cpp.sdk.core/plugin.xml	Fri Oct 23 08:56:35 2009 -0500
@@ -22,5 +22,13 @@
        class="com.nokia.carbide.cpp.internal.sdk.core.gen.Devices.util.DevicesResourceFactoryImpl" />
   </extension>
 
+  <extension
+         point="org.eclipse.cdt.scripting.scriptableFeature">
+      <scriptableClass
+            class="com.nokia.carbide.cpp.internal.sdk.core.scripting.SDKScriptManager"
+            name="sdkScriptManager">
+      </scriptableClass>
+   </extension>
+
 </plugin>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/scripting/SDKScriptManager.java	Fri Oct 23 08:56:35 2009 -0500
@@ -0,0 +1,53 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+package com.nokia.carbide.cpp.internal.sdk.core.scripting;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.nokia.carbide.cpp.sdk.core.ISDKManager;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
+
+public class SDKScriptManager {
+	
+	private static final String KEY_SDK_ID = "KEY_SDK_ID";
+	private static final String KEY_SDK_EPOCROOT = "KEY_SDK_EPOCROOT";
+	private static final String KEY_SDK_NAME = "KEY_SDK_NAME";
+	
+	static private ISDKManager getSDKManager(){
+		return SDKCorePlugin.getSDKManager();
+	}
+		
+	static public Map<?, ?>[] getSDKMapList(){
+		ArrayList<Map<String,String>> sdkMapArray = new ArrayList<Map<String,String>>();
+		List<ISymbianSDK> sdkList = getSDKManager().getSDKList();
+		for (ISymbianSDK sdk : sdkList){
+			Map<String,String> mp = new HashMap<String, String>();
+			mp.put(KEY_SDK_ID, sdk.getUniqueId());
+			mp.put(KEY_SDK_NAME, sdk.getName());
+			mp.put(KEY_SDK_EPOCROOT, sdk.getEPOCROOT());
+			sdkMapArray.add(mp);
+		}
+		
+		
+		return sdkMapArray.toArray(new HashMap<?, ?>[sdkMapArray.size()]);
+	}
+	
+}
--- a/project/com.nokia.carbide.cpp.project.ui/plugin.xml	Wed Oct 21 14:28:08 2009 -0500
+++ b/project/com.nokia.carbide.cpp.project.ui/plugin.xml	Fri Oct 23 08:56:35 2009 -0500
@@ -534,4 +534,12 @@
       </keyword>
    </extension>
 
+  <extension
+         point="org.eclipse.cdt.scripting.scriptableFeature">
+      <scriptableClass
+            class="com.nokia.carbide.cpp.internal.scripting.ImportBldInfWrapper"
+            name="importBldInfWrapper">
+      </scriptableClass>
+   </extension>
+
  </plugin>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/scripting/ImportBldInfWrapper.java	Fri Oct 23 08:56:35 2009 -0500
@@ -0,0 +1,93 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+package com.nokia.carbide.cpp.internal.scripting;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+
+import com.nokia.carbide.cpp.internal.api.sdk.SymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISDKManager;
+import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
+
+
+public class ImportBldInfWrapper {
+	
+	private static final String KEY_SDKID = "KEY_SDKID";
+	private static final String KEY_PLATFORM = "KEY_PLATFORM";
+	private static final String KEY_TARGET = "KEY_TARGET";
+	
+	static public String importBldInf(String projectName, String rootDirectory,
+		String bldInfFile, String[] buildComponents,
+		Map<String, String>[] buildContextMap) {
+
+		List<ISymbianBuildContext> contexts = new ArrayList<ISymbianBuildContext>();
+		ISDKManager sdkMgr = SDKCorePlugin.getSDKManager();
+		for (Map<String, String> currMap : buildContextMap) {
+			ISymbianSDK sdk = sdkMgr.getSDK(currMap.get(KEY_SDKID), false);
+			if (sdk != null) {
+				if (!ImporterScritpingUtils.checkProjectIsOnSDKDrive(
+						rootDirectory, sdk)) {
+					// AssertTestCase.fail("!" + projectPath +
+					// " is not on the same drive as SDK: " + sdkName
+					// + " and could not import: " + projectName);
+				}
+				contexts.add(new SymbianBuildContext(sdk, currMap
+						.get(KEY_PLATFORM), currMap.get(KEY_TARGET)));
+			}
+		}
+
+		IProject project = ImporterScritpingUtils.importINF(projectName,
+				bldInfFile, contexts, 0, false);
+
+		if (project == null)
+			return null;
+		else
+			return projectName;
+	}
+	
+	static public Map<String, String> createSymbianBuildContext(String sdkID, String platform, String target){
+		Map<String,String> mp = new HashMap<String, String>();
+
+		mp.put(KEY_SDKID, sdkID);
+		mp.put(KEY_PLATFORM, platform);
+		mp.put(KEY_TARGET, target);
+		
+		return mp;
+	}
+	
+	static public boolean buildProject(String projectName){
+		// TODO:
+		return false;
+	}
+	
+	static public boolean cleanProject(int cleanLevel){
+		// TODO:
+		return false;
+	}
+	
+	static public boolean changeBuildConfiguration(Map<String, String> buildContextMap){
+		// TODO:
+		return false;
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/com.nokia.carbide.cpp.project.ui/src/com/nokia/carbide/cpp/internal/scripting/ImporterScritpingUtils.java	Fri Oct 23 08:56:35 2009 -0500
@@ -0,0 +1,129 @@
+package com.nokia.carbide.cpp.internal.scripting;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+
+import com.nokia.carbide.cdt.builder.EpocEngineHelper;
+import com.nokia.carbide.cpp.internal.api.sdk.SymbianBuildContext;
+import com.nokia.carbide.cpp.internal.project.utils.BldInfImportWrapper;
+import com.nokia.carbide.cpp.sdk.core.ISymbianBuildContext;
+import com.nokia.carbide.cpp.sdk.core.ISymbianSDK;
+import com.nokia.carbide.cpp.sdk.core.SDKCorePlugin;
+
+public class ImporterScritpingUtils {
+
+	/**
+	 * Import a project from bld.inf
+	 * 
+	 * @param sdkName - The SDK to use.
+	 * @param projectName - The project to import.
+	 * @param projectPath - The path of the project to import.
+	 * @changelog
+	 * ARH 04/03/2009 Added an assert to reject a project path that is too long.
+	 */
+	public static IProject importINF(String projectName, String projectPath,
+			List<ISymbianBuildContext> buildContexts, int rootPathIndex,
+			boolean isSBSv2) {
+
+		IProject project = null;
+
+		IPath bldInf = new Path(projectPath);
+
+		// AssertTestCase.assertFalse("The project: " + projectName +
+		// " could not be imported from " +
+		// projectPath + " because the path is " +
+		// ProjectUtils.getProjectPathOverflowLength(bldInf) +
+		// " too many character long.",
+		// ProjectUtils.isProjectPathToLong(bldInf));
+
+		List<IPath> projectRoots = EpocEngineHelper.getProjectRoots(bldInf,
+				buildContexts, new NullProgressMonitor());
+		IPath rootDirectoryPath = projectRoots.get(rootPathIndex);
+
+		final List<String> components = new ArrayList<String>(); // should be
+																	// empty
+																	// list,
+																	// same as
+																	// all MMP
+																	// components
+																	// checked
+		final List<String> refs = new ArrayList<String>(); // refs should be
+															// empty, we'll
+															// build from
+															// bld.inf
+		BldInfImportWrapper infWrapper = new BldInfImportWrapper(projectName,
+				rootDirectoryPath, bldInf, components, refs, buildContexts);
+
+		infWrapper.createProjectFromBldInf(isSBSv2);
+
+		project = infWrapper.getProject();
+
+		return project;
+	}
+	
+	/**
+	 * Validate that the project and SDK are compatible.  If the SDK and project are not on the
+	 * same drive, then return false.  If they are on the same drive, then return true
+	 * @param projectPath the path to the project to check
+	 * @param sdk the SDK to check against the project
+	 * @return true if projectPath is on the same drive as sdkName
+	 */
+	public static boolean checkProjectIsOnSDKDrive(String projectPath, ISymbianSDK sdk) {
+		// The drive letter of the SDK
+		String expectedDrive = sdk.getEPOCROOT().substring( 0, 1 );
+
+		// The drive letter of the project
+		String actualDrive = projectPath.substring( 0, 1 );
+		
+		// Check if drive letters are different of the SDK versus the project to import
+		if ( expectedDrive.equalsIgnoreCase( actualDrive ) ) {
+			return true;
+		}
+		
+		return false;
+	}
+	
+	/**
+	 * Given an sdk and a comma deliminated list of build targets, return a List of ISymbianBuildContext
+	 * An example build target string would be "WINSCW UDEB,GCCE UREL" and would return
+	 * @param sdk
+	 * @param buildTargets
+	 * @return
+	 */
+	public static List<ISymbianBuildContext> getSymbianBuildContextsFromString(ISymbianSDK sdk, String buildTargets) {
+		List<ISymbianBuildContext> selectedConfigs;
+
+		// Create a selectConfigs list with all elements contained in buildTargets string
+		if (buildTargets != null && buildTargets.length() > 0) {
+			selectedConfigs = new ArrayList<ISymbianBuildContext>();
+			StringTokenizer targetT = new StringTokenizer(buildTargets, ",");
+			String buildTarget;
+			String buildContext;
+			while(targetT.hasMoreElements()) {
+				// Get the element, separated by a comma, e.g. "GCCE UDEB".  Needs to be split further
+				buildTarget = targetT.nextToken(); 
+				// Within the element, get the context, which should be either "UDEB" or "UREL"
+				buildContext = buildTarget.substring(buildTarget.indexOf(" ")+1);
+				// Backfill with buildTarget with just the target
+				buildTarget = buildTarget.substring(0, buildTarget.indexOf(" "));
+				
+				// Validate target and context strings against ISymbianBuildContext
+//				AssertTestCase.assertTrue("!Invalid build target, should be ARMV5, GCCE, WINSCW, etc.. but was: " + buildTarget, validateBuildTarget(buildTarget));
+//				AssertTestCase.assertTrue("!Invalid build context, should be UREL or UDEB, but was: " + buildContext, validateBuildContext(buildContext));
+				ISymbianBuildContext context = new SymbianBuildContext(sdk, buildTarget, buildContext);
+				selectedConfigs.add(context);		
+			}
+		}
+		else {
+			selectedConfigs = sdk.getFilteredBuildConfigurations();
+		}
+		return selectedConfigs;
+	}
+	
+}