[Esbox-commits] r2352 - branches/work_Ed/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/scratchbox/adapters

eswartz at garage.maemo.org eswartz at garage.maemo.org
Fri Oct 23 23:39:40 EEST 2009


Author: eswartz
Date: 2009-10-23 23:39:37 +0300 (Fri, 23 Oct 2009)
New Revision: 2352

Modified:
   branches/work_Ed/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/scratchbox/adapters/ESboxMaemoTargetEnvironmentModifierAdapter.java
Log:
Alternate solution to #4650 that cleans up the environment provider APIs and doesn't persist across launches.

Modified: branches/work_Ed/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/scratchbox/adapters/ESboxMaemoTargetEnvironmentModifierAdapter.java
===================================================================
--- branches/work_Ed/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/scratchbox/adapters/ESboxMaemoTargetEnvironmentModifierAdapter.java	2009-10-23 20:16:23 UTC (rev 2351)
+++ branches/work_Ed/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/scratchbox/adapters/ESboxMaemoTargetEnvironmentModifierAdapter.java	2009-10-23 20:39:37 UTC (rev 2352)
@@ -12,21 +12,12 @@
 package org.maemo.esbox.internal.scratchbox.adapters;
 
 import java.text.MessageFormat;
-import java.util.Properties;
 
-import org.maemo.esbox.internal.api.scratchbox.core.sdk.ScratchboxCacheUtils;
 import org.maemo.esbox.internal.scratchbox.core.Activator;
 import org.maemo.esbox.maemosdk.core.MaemoEnvironmentUtils;
-import org.maemo.mica.common.core.ICache;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.TimeoutProgressMonitor;
 import org.maemo.mica.common.core.env.EnvironmentModifierBlock;
-import org.maemo.mica.common.core.env.EnvironmentProperties;
 import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
 import org.maemo.mica.common.core.machine.IMachine;
-import org.maemo.mica.common.core.process.ProcessLauncherParameters;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
 import org.maemo.mica.common.core.sdk.ISDKTarget;
 import org.maemo.mica.common.launch.adapters.ITargetEnvironmentModifierAdapter;
 import org.maemo.mica.common.launch.core.ILaunchProxy;
@@ -34,7 +25,9 @@
 import org.maemo.mica.internal.api.common.launch.core.AbstractRemoteLaunchProxy;
 import org.maemo.mica.internal.api.common.launch.core.IRemoteLaunchParameterAccessor;
 import org.maemo.mica.internal.api.protocol.sbrsh.ISBRSHMachine;
+import org.maemo.mica.internal.api.protocol.ssh.SSHEnvironmentProvider;
 import org.maemo.mica.maemosdk.core.IMaemoSDKPlatform;
+import org.maemo.mica.protocol.ssh.ISSHMachine;
 
 /**
  * Provide the necessary variables for maemo launches.
@@ -44,6 +37,10 @@
 public class ESboxMaemoTargetEnvironmentModifierAdapter implements ITargetEnvironmentModifierAdapter {
 
 	/**
+	 * This command will ensure we see the variables for DBUS_*
+	 */
+	private static final String[] RUN_STANDALONE_SET = new String[] { "run-standalone.sh", "set" };
+	/**
 	 * 
 	 */
 	private static final String DBUS_SESSION_BUS_ADDRESS = "DBUS_SESSION_BUS_ADDRESS";
@@ -69,58 +66,42 @@
 		
 		// on remote Fremantle devices, we need to find out for real, since there is no
 		// longer a simple file
+		
+		// TODO: maybe use the /tmp/session_bus_address.<username> file instead...?
+		
 		if (launchProxy instanceof AbstractRemoteLaunchProxy
 				&& sdkTarget.getPlatform().getVersion().compareTo(IMaemoSDKPlatform.FREMANTLE.getVersion()) >= 0) {
 			// need to fetch from the actual environment
 			IRemoteLaunchParameterAccessor remoteLaunchParameterAccessor = (IRemoteLaunchParameterAccessor) ((AbstractRemoteLaunchProxy) launchProxy).getLaunchParameterAccessor();
 			IMachine machine = remoteLaunchParameterAccessor.getMachine();
-		
+			
 			// fetch directly from the device; don't be tricked by the host or build machine
 			if (machine instanceof ISBRSHMachine) {
 				machine = ((ISBRSHMachine) machine).getDeviceMachine();
 			}
 			
-			String value = null;
-			ICache cache = ScratchboxCacheUtils.getCache(machine);
-			value = (String) cache.get(DBUS_SESSION_BUS_ADDRESS, String.class);
-			
+			// this maintains a cache in memory
+			SSHEnvironmentProvider provider = new SSHEnvironmentProvider(
+					((ISSHMachine) machine).getSshConfiguration(),
+					RUN_STANDALONE_SET);
+
+			String value = provider.getRawEnvironment().getProperty(DBUS_SESSION_BUS_ADDRESS);
 			if (value == null) {
-				
-				LaunchResults results;
-				try {
-					results = ProcessLauncherUtils.launchAndReadStandardStreams(
-							machine.getProcessLauncherFactory().createProcessLauncher(
-									ProcessLauncherParameters.create("run-standalone.sh", "set")),
-									new TimeoutProgressMonitor(15 * 1000));
-					Properties env = EnvironmentProperties.createFromShellEnvDump(results.stdout);
-					value = env.getProperty(DBUS_SESSION_BUS_ADDRESS);
-					
-				} catch (MicaException e) {
-					Activator.getErrorLogger().logError(MessageFormat.format(
-							"Could not read environment from {0}",
-							machine.getName()), null);
-				}
-				
-				
+				// fallback
 				if (value == null) {
 					value = machine.getStandardEnvironmentVariable(DBUS_SESSION_BUS_ADDRESS);
 				}
 				
-				if (value != null) {
-					cache.set(DBUS_SESSION_BUS_ADDRESS, value);
-				}
-				
 				if (value == null) {
 					Activator.getErrorLogger().logError(MessageFormat.format(
-						"Could not detect DBUS_SESSION_BUS_ADDRESS from {0}; please refresh the Maemo > Installed Targets",
+						"Could not detect DBUS_SESSION_BUS_ADDRESS from {0}; using default value.  May lead to osso_initialize() failures.",
 						machine.getName()), null);
 					value = "unix:path=/tmp/session_bus_socket";
 				}
 				
-				
 			}
 			
-			envBlock.define(DBUS_SESSION_BUS_ADDRESS, "unix:path=/tmp/session_bus_socket");
+			envBlock.define(DBUS_SESSION_BUS_ADDRESS, value);
 		}
 		
 		if (launchProxy instanceof AbstractLocalLaunchProxy) {



More information about the Esbox-commits mailing list