[Esbox-commits] r954 - in branches/work_Petr: org.maemo.esbox.maemosdk.core org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core

eswartz at garage.maemo.org eswartz at garage.maemo.org
Wed Nov 19 17:39:01 EET 2008


Author: eswartz
Date: 2008-11-19 17:39:00 +0200 (Wed, 19 Nov 2008)
New Revision: 954

Modified:
   branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml
   branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/CacheUtils.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
Log:
Fix some more unit test failures, re-implement caching of scanned targets, and fix a CacheUtils bug not remembering to cache a machine key.
Also, make the adapter for the target environment modifier be more specific (this is still on my branch too).

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml	2008-11-18 23:46:34 UTC (rev 953)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml	2008-11-19 15:39:00 UTC (rev 954)
@@ -4,7 +4,7 @@
    <extension
          point="org.eclipse.core.runtime.adapters">
        <factory
-            adaptableType="org.maemo.mica.common.core.sdk.ISDKTarget"
+            adaptableType="org.maemo.esbox.internal.api.scratchbox.core.sdk.AbstractScratchboxSDKTarget"
             class="org.maemo.esbox.internal.maemosdk.core.adapters.MaemoTargetEnvironmentModifierAdapterFactory">
          <adapter
                type="org.maemo.mica.common.launch.adapters.ITargetEnvironmentModifierAdapter">

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/CacheUtils.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/CacheUtils.java	2008-11-18 23:46:34 UTC (rev 953)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/CacheUtils.java	2008-11-19 15:39:00 UTC (rev 954)
@@ -98,14 +98,17 @@
 	public void ensureCurrentMachine(String machineKey, IMachine machine) {
 		String current = (String) CacheUtils.getInstance().getCachedValue(
 				machineKey);
+		String machineURIAndType = machine.getURI().toString() + ":" + machine.getClass().getSimpleName();
+		
+		// the same machine may be registered under different keys -- 
+		// don't clear the cache unless the value for this machineKey changed.
 		if (current != null) {
-			String machineURIAndType = machine.getURI().toString() + ":" + machine.getClass().getSimpleName();
 			if (!current.equals(machineURIAndType)) {
 				// just zap
 				clearCachedData();
 			}
-			setCachedValue(machineKey, machineURIAndType);
 		}
+		setCachedValue(machineKey, machineURIAndType);
 	}
 
 

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java	2008-11-18 23:46:34 UTC (rev 953)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java	2008-11-19 15:39:00 UTC (rev 954)
@@ -11,6 +11,7 @@
 package org.maemo.esbox.internal.scratchbox.sb2.command;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.maemo.esbox.internal.api.scratchbox.core.sdk.CacheUtils;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.process.IProcessLauncherFactory;
 import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
@@ -38,7 +39,12 @@
 
 	private static final String COMMAND_NEW = "new";
 	
+	/** Cache key for map of target name -> rootstrap location */
+	private static final String SB2_ROOTSTRAP_LOCATION_MAP = "sb2_rootstrap_location_map";
+	/** Cache key for map of target name -> architecture */
+	private static final String SB2_ROOTSTRAP_ARCHITECTURE_MAP = "sb2_rootstrap_arch_map";
 	
+	
 
 	public MaemoRootstrapCommand(ICommandAbstractor commandAbstractor, IProcessLauncherFactory launcherFactory) {
 		super(commandAbstractor,launcherFactory);
@@ -96,8 +102,29 @@
 	 * @param name
 	 */
 	public String showLocation(String name) throws MicaException{
-		Results result = runProcess(MAEMO_ROOTSTRAP,PATH,name);
-		return result.stdout;
+		// get cached value
+		Map<String, String> locationMap = (Map<String, String>) 
+			CacheUtils.getInstance().getCachedValue(SB2_ROOTSTRAP_LOCATION_MAP);
+		if (locationMap == null) {
+			locationMap = new HashMap<String, String>();
+		}
+		String location = locationMap.get(name);
+		
+		if (location == null) {
+			// do the hard work
+			Results result = runProcess(MAEMO_ROOTSTRAP,PATH,name);
+			if (result.exitCode != 0) {
+				throw new MicaException("Cannot determine rootstrap location for " + name 
+						+ ":\n\n"+result.stdout+result.stderr);
+			}
+			location = result.stdout.trim(); // remove newlines, carriage returns, etc
+		}
+		
+		// remember cached data
+		locationMap.put(name, location);
+		
+		CacheUtils.getInstance().setCachedValue(SB2_ROOTSTRAP_LOCATION_MAP, locationMap);
+		return location;
 	}
 
 	/**
@@ -107,11 +134,30 @@
 	 * @throws MicaException - when unknown architecture 
 	 */
 	public String showArchitecture(String name) throws MicaException{
-		Results result = runProcess(MAEMO_ROOTSTRAP,ARCH,name);
-		if(result.exitCode==0)
-			return result.stdout.trim();  // remove \r and \n and anything else
-		else
-			return null;
+		// get cached value
+		Map<String, String> archMap = (Map<String, String>) 
+			CacheUtils.getInstance().getCachedValue(SB2_ROOTSTRAP_ARCHITECTURE_MAP);
+		if (archMap == null) {
+			archMap = new HashMap<String, String>();
+		}
+		String arch = archMap.get(name);
+		
+		if (arch == null) {
+			// do the hard work
+			Results result = runProcess(MAEMO_ROOTSTRAP,ARCH,name);
+			if(result.exitCode==0)
+				arch = result.stdout.trim();  // remove \r and \n and anything else
+			else
+				throw new MicaException("Cannot determine architecture for " + name 
+						+ ":\n\n"+result.stdout+result.stderr);
+		}
+		
+		// remember cached data
+		archMap.put(name, arch);
+		
+		CacheUtils.getInstance().setCachedValue(SB2_ROOTSTRAP_ARCHITECTURE_MAP, archMap);
+		return arch;
+		
 	}
 
 	public boolean newRootstrap(String name) throws MicaException {

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java	2008-11-18 23:46:34 UTC (rev 953)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java	2008-11-19 15:39:00 UTC (rev 954)
@@ -10,10 +10,7 @@
  *******************************************************************************/
 package org.maemo.esbox.internal.scratchbox.sb2.core;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -141,7 +138,21 @@
 	 * @see org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#getTargets()
 	 */
 	public List<String> getTargets() throws MicaException {
-		return maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
+		// check cached value
+		CacheUtils.getInstance().ensureCurrentMachine(SB2_MACHINE, this.getMachine());
+
+		String[] targetsArray = (String[]) CacheUtils.getInstance()
+				.getCachedValue(SB_TARGETS);
+		if (targetsArray != null)
+			return Arrays.asList(targetsArray);
+		
+		// do the hard work
+		List<String> targets = maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
+		
+		CacheUtils.getInstance().setCachedValue(SB_TARGETS, 
+				(String[]) targets.toArray(new String[targets.size()]));
+		
+		return targets;
 	}
 
 	/*

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java	2008-11-18 23:46:34 UTC (rev 953)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java	2008-11-19 15:39:00 UTC (rev 954)
@@ -42,6 +42,7 @@
 		if (targetRoot == null)
 			throw new IllegalArgumentException();
 		this.targetRoot = targetRoot;
+		setRootstrapPath(targetRoot);
 		init(new Scratchbox2FileSystemMapping(this, targetRoot, target, sdk
 				.getPreferenceValue(CorePreferenceConstants.USER)));
 	}



More information about the Esbox-commits mailing list