merge again RCL_2_4
authorfturovic <frank.turovich@nokia.com>
Thu, 21 Jan 2010 15:01:25 -0600
branchRCL_2_4
changeset 797 1fdd2927e980
parent 796 043c5c3bb50b (current diff)
parent 787 f90a80bff752 (diff)
child 801 3040875e1a74
merge again
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/HostOS.java	Thu Jan 21 15:01:25 2010 -0600
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Nokia - Initial API and implementation
+ *******************************************************************************/
+package com.nokia.carbide.cpp.internal.api.sdk;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+
+
+/**
+ * Utilities used for portability between hosts.
+ */
+public class HostOS {
+	/** Is the host Windows? */
+	public static boolean IS_WIN32 = File.separatorChar == '\\';
+	/** Is the host some Unix variant? */
+	public static boolean IS_UNIX = File.separatorChar == '/';
+	/** Executable file extension */
+	public static final String EXE_EXT = IS_WIN32 ? ".exe" : "";
+	
+	/**
+	 * Ensure that the executable name mentioned is canonical for the machine.
+	 * This only affects Windows, currently, ensuring that an ".exe" is attached.
+	 * @param executablePath
+	 * @return updated path
+	 */
+	public static String canonicalizeExecutableName(String executable) {
+		if (IS_WIN32) {
+			IPath executablePath = new Path(executable);
+			String ext = executablePath.getFileExtension();
+			if (ext == null) {
+				executable += EXE_EXT;
+			}
+		}
+		return executable;
+	}
+
+	/**
+	 * Scan the PATH variable and see if the given binary is visible on
+	 * the PATH that will be used at runtime (with the default environment and overrides).
+	 * @param pathValue the expected Path 
+	 * @param program
+	 * @return IPath if program is on PATH, else <code>null</code>
+	 */
+	public static IPath findProgramOnPath(String program, String pathValue) {
+		
+		// be sure proper path/extension are present
+		program = HostOS.canonicalizeExecutableName(program);
+		
+		IPath path = null;
+		
+		IPath[] pathEntries = getPathEntries(pathValue);
+		for (IPath pathEntry : pathEntries) {
+			IPath testPath = pathEntry.append(program);
+			if (testPath.toFile().exists()) {
+				path = testPath;
+				break;
+			}
+		}
+		
+		return path;
+	}
+	
+    /**
+	 * Get the PATH entries from the given path environment value or the
+	 * system environment.
+	 * @param pathValue the expected PATH/Path value, or <code>null</code> for the system value
+	 * @return array of IPath, never <code>null</code>
+	 */
+	private static IPath[] getPathEntries(String pathValue) {
+		String pathVar = null;
+		if (pathValue != null) {
+			pathVar = pathValue;
+		} else {
+			if (HostOS.IS_WIN32) {
+				// canonical name, plus fallback below
+				pathVar = System.getenv("Path"); //$NON-NLS-1$
+			}
+			if (pathVar == null) {
+				pathVar = System.getenv("PATH"); //$NON-NLS-1$
+			}
+		}
+		
+		if (pathVar == null)
+			pathVar = "";
+		
+		String pathSeparator = System.getProperty("path.separator");
+		String[] pathEntries = pathVar.split(pathSeparator);
+		IPath[] paths = new IPath[pathEntries.length];
+		for (int i = 0; i < pathEntries.length; i++) {
+			paths[i] = new Path(pathEntries[i]);
+		}
+		return paths;
+	}
+    
+	
+}
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Thu Jan 21 15:00:33 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/api/sdk/SBSv2Utils.java	Thu Jan 21 15:01:25 2010 -0600
@@ -14,20 +14,29 @@
 
 import java.io.File;
 import java.io.FileFilter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 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;
 import org.osgi.framework.Version;
-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.Logging;
 
@@ -40,6 +49,13 @@
 	private static final String SBSV2_FILTERED_CONFIGS_STORE = "sbsv2FilteredConfigs"; //$NON-NLS-1$
 	private static final String SBSV2_FILTERED_CONFIGS_DELIMETER = ";"; //$NON-NLS-1$
 
+	protected static String sbsHome; 
+	protected static IPath sbsPath; 
+	
+	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;
 
 	
@@ -276,4 +292,35 @@
 			}
 		}
     }
+    
+    /**  
+     *  (Re-)scan the SBSv2 / Raptor configuration  
+     *   @return message if error, else null  
+     **/  
+    public static String scanSBSv2() {  
+    	// do some basic checks  
+    	sbsHome = System.getenv(SBS_HOME);  
+    	if (sbsHome == null) {  
+    		return "Please define the SBS_HOME environment (e.g. /path/to/raptor) and add $SBS_HOME/bin to your PATH before running Carbide.";
+    		}  
+    	
+    	sbsPath = HostOS.findProgramOnPath(sbsScriptName, null);
+    	if (sbsPath == null) {  
+    		return "Please add $SBS_HOME/bin to your PATH before running Carbide.";  
+    		}  
+    	
+    	return null; 
+    	}  
+    
+    /**  
+     * Get the path to SBSv2 (sbs.bat or sbs)  
+     **/  
+    public static IPath getSBSPath() {  
+    	if (!scannedSbsState) {  
+    		scanSBSv2();  
+    		scannedSbsState = true;  
+    		}  
+    	return sbsPath != null ? sbsPath : new Path(sbsScriptName); 
+    }
+    
 }
--- a/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java	Thu Jan 21 15:00:33 2010 -0600
+++ b/core/com.nokia.carbide.cpp.sdk.core/src/com/nokia/carbide/cpp/internal/sdk/core/model/SDKManager.java	Thu Jan 21 15:01:25 2010 -0600
@@ -60,6 +60,7 @@
 import com.nokia.carbide.cpp.internal.api.sdk.BuildPlat;
 import com.nokia.carbide.cpp.internal.api.sdk.ICarbideDevicesXMLChangeListener;
 import com.nokia.carbide.cpp.internal.api.sdk.ISDKManagerInternal;
+import com.nokia.carbide.cpp.internal.api.sdk.SBSv2Utils;
 import com.nokia.carbide.cpp.internal.api.sdk.SDKManagerInternalAPI;
 import com.nokia.carbide.cpp.internal.api.sdk.SymbianMacroStore;
 import com.nokia.carbide.cpp.internal.sdk.core.gen.Devices.DeviceType;
@@ -77,7 +78,6 @@
 import com.nokia.cpp.internal.api.utils.core.Logging;
 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
 import com.sun.org.apache.xpath.internal.XPathAPI;
-import com.sun.org.apache.xpath.internal.operations.Minus;
 
 public class SDKManager implements ISDKManager, ISDKManagerInternal {
 	
@@ -964,16 +964,30 @@
 			sbsV2Version = new Version(0, 0, 0);
 			
 			Runtime rt=Runtime.getRuntime();
+			IPath sbsPath = SBSv2Utils.getSBSPath();  
+			Process p = null; 
 			try {
-				Process p = rt.exec("sbs.bat -v");
+			
+				p = rt.exec(new String[] { sbsPath.toOSString(), "-v" });
 				
+			} 
+			catch (IOException e) {  
+				// no such process, SBSv2 not available  
+				Logging.log(SDKCorePlugin.getDefault(), Logging.newSimpleStatus(0, IStatus.WARNING,
+						MessageFormat.format("Could not find or launch Raptor script ''{0}''; SBSv2 support will not be available",
+								sbsPath), e));  
+				} 
+			if (p != null)	 {
 				BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
 				String overallOutput = null;
 				String stdErrLine = null;
-				while ((stdErrLine = br.readLine()) != null) {
-					overallOutput += stdErrLine;
+				try { 
+					while ((stdErrLine = br.readLine()) != null) { 
+						overallOutput += stdErrLine; 
+					}
+				} catch (IOException e) { 
+					e.printStackTrace();
 				}
-				
 				if (overallOutput != null) {
 				{
 					String[] tokens = overallOutput.split(" ");
@@ -1001,13 +1015,9 @@
 						}
 					
 					p.destroy();
+					}	
 				}
 			}
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-			
-			
 			
 		}
 		return sbsV2Version;