[Esbox-commits] r952 - in branches/work_Petr: org.maemo.esbox.maemosdk.core org.maemo.esbox.maemosdk.core/META-INF org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk org.maemo.esbox.scratchbox.sb1 org.maemo.esbox.scratchbox.sb1/META-INF org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk org.maemo.esbox.scratchbox.sb2 org.maemo.esbox.scratchbox.sb2/META-INF org.maemo.esbox.scratchbox.sb2/conf org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2 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 org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/preferences org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk

eswartz at garage.maemo.org eswartz at garage.maemo.org
Tue Nov 18 23:48:26 EET 2008


Author: eswartz
Date: 2008-11-18 23:48:25 +0200 (Tue, 18 Nov 2008)
New Revision: 952

Added:
   branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/BaseSb2Test.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapter.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapterFactory.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDKTarget.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/command/MaemoSdkCommand.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapterFactory.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java
Removed:
   branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoLauncher.java
   branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapter.java
   branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestCreateTargetSb2Command.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListSb2Commands.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateTargetSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetCurrentTargetSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListCompilersSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListTargetsCommand.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveTargetSb2Command.java
Modified:
   branches/work_Petr/org.maemo.esbox.maemosdk.core/META-INF/MANIFEST.MF
   branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml
   branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestProcessLauncher.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestSB2SDKProvider.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/AllTests.java
   branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java
   branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/META-INF/MANIFEST.MF
   branches/work_Petr/org.maemo.esbox.scratchbox.sb1/plugin.xml
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/META-INF/MANIFEST.MF
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/plugin.xml
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ShowPathMappingSb2Command.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2FileSystemMapping.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
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2EnvironmentProvider.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncherFactory.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/preferences/Scratchbox2PreferencesPage.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java
   branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java
Log:
Merge with rev 948 from sdkPlusSupport
-- Add support for deleting sessions 
-- Fix some egregrious failures in unit tests 
-- Create session files in SDK machine, not host machine
-- Log caught exceptions
-- Handle invalid targets

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.core/META-INF/MANIFEST.MF
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/META-INF/MANIFEST.MF	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/META-INF/MANIFEST.MF	2008-11-18 21:48:25 UTC (rev 952)
@@ -12,7 +12,7 @@
  org.maemo.mica.common.launch;bundle-version="2.0.0",
  org.maemo.mica.protocol.sbrsh;bundle-version="2.0.0",
  org.maemo.esbox.scratchbox.core;bundle-version="2.0.0",
- org.maemo.esbox.scratchbox.sb1;bundle-version="2.0.0"
+ org.maemo.mica.maemosdk.core;bundle-version="2.0.0"
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: org.maemo.esbox.internal.api.maemosdk.core,

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/plugin.xml	2008-11-18 21:48:25 UTC (rev 952)
@@ -46,13 +46,6 @@
                type="org.maemo.mica.common.core.adapters.IDefaultExecutionEnvironmentAdapter">
          </adapter>
        </factory>
-      <factory
-            adaptableType="org.maemo.mica.common.core.sdk.ISDKTarget"
-            class="org.maemo.esbox.internal.maemosdk.core.adapters.Scratchbox1PrepareTargetProcessLaunchAdapterFactory">
-         <adapter
-               type="org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter">
-         </adapter>
-      </factory>
    </extension>
 
   <extension

Added: branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *    Ed Swartz (Nokia)
+ *******************************************************************************/
+package org.maemo.esbox.internal.api.maemosdk.core.tools;
+
+import org.maemo.mica.common.core.MicaException;
+
+/**
+ * This adapter on ISDKTarget allows an SDK target to control how the maemo emulation 
+ * environment is controlled. 
+ * @author baranov
+ *
+ */
+public interface IMaemoLauncherAdapter {
+
+	/**
+	 * Start maemo if it's not running.
+	 * 
+	 * @param sdkTarget
+	 * @throws MicaException
+	 *             if already running or cannot be started
+	 */
+	public abstract void startMaemo() throws MicaException;
+
+	/**
+	 * Stop maemo if it's running
+	 * 
+	 * @param sdkTarget
+	 * @throws MicaException
+	 *             if not running or cannot be stopped
+	 */
+	public abstract void stopMaemo() throws MicaException;
+
+	/**
+	 * Restart maemo
+	 * 
+	 * @param sdkTarget
+	 * @throws MicaException
+	 *             if cannot be restarted
+	 */
+	public abstract void restartMaemo()
+			throws MicaException;
+
+	/**
+	 * Kill maemo by forcibly killing instances of the launcher left behind
+	 * 
+	 * @param sdkTarget
+	 * @throws MicaException
+	 */
+	public abstract void killMaemo() throws MicaException;
+
+	public abstract boolean isMaemoRunning() throws MicaException;
+
+}
\ No newline at end of file

Deleted: branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoLauncher.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoLauncher.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoLauncher.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,276 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation.
- * 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:
- *    Raul Herbster (UFCG) - initial implementation
- *    Ed Swartz (Nokia) - adaptation
- *******************************************************************************/
-
-package org.maemo.esbox.internal.api.maemosdk.core.tools;
-
-import java.io.IOException;
-import java.util.*;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.ui.console.*;
-import org.maemo.esbox.internal.api.maemosdk.core.MaemoEnvironmentUtils;
-import org.maemo.esbox.internal.maemosdk.core.Activator;
-import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
-import org.maemo.mica.common.core.*;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.machine.*;
-import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
-
-/**
- * This class maintains knowledge about whether maemo is running in a target and
- * controls access to starting, stopping, and querying status.
- * 
- * @author eswartz
- * 
- */
-public class MaemoLauncher {
-
-	private static final String MAEMO_LAUNCHER_APP = "maemo-launcher";
-	private static MaemoLauncher instance;
-
-	
-	public synchronized static MaemoLauncher getInstance() {
-		if (instance == null) {
-			instance = new MaemoLauncher();
-		}
-		return instance;
-	}
-	
-	static class MaemoCommand {
-
-		private ISDKTarget sdkTarget;
-
-		public MaemoCommand(ISDKTarget sdkTarget) {
-			this.sdkTarget = sdkTarget;
-		}
-
-		private void performCommand(List<String> params) throws MicaException {
-			String maemoCommand = sdkTarget.getPreferenceValue(
-					MaemoPreferenceConstants.MAEMO_COMMAND);
-			maemoCommand = this.replaceActions(maemoCommand,params.get(0));
-			
-			IProcessLauncherFactory processLauncherFactory = sdkTarget.getProcessLauncherFactory();
-			
-			IEnvironmentModifierBlock envBlock = processLauncherFactory.defaultEnvironmentModifierBlock();
-			MaemoEnvironmentUtils.defineEmulatorXDisplayVariable(sdkTarget.getMachine(), envBlock);
-			
-			IProcessLauncher processLauncher = ProcessLauncherCreator.createProcessLauncher(processLauncherFactory, null,
-					Collections.singletonList(maemoCommand), envBlock);
-
-			Process process = processLauncher.createProcess();
-
-			// spit the consumed output to the console
-			MessageConsole console = CoreConsoleManager.getInstance().getConsole(true,
-					sdkTarget, "Running Maemo command (" + params.get(0) + ")");
-
-			console.addPatternMatchListener(new IPatternMatchListener() {
-
-				public int getCompilerFlags() {
-					return 0;
-				}
-
-				public String getLineQualifier() {
-					return null;
-				}
-
-				public String getPattern() {
-					return "ERROR:.*";
-				}
-
-				public void connect(TextConsole console) {
-				}
-
-				public void disconnect() {
-				}
-
-				public void matchFound(PatternMatchEvent event) {
-					TextConsole console = (TextConsole) event.getSource();
-					String content;
-					try {
-						content = console.getDocument().get(event.getOffset(),
-								event.getLength());
-					} catch (BadLocationException e) {
-						content = console.getDocument().get();
-					}
-					ErrorLogger errorLogger = Activator.getErrorLogger();
-					errorLogger.logAndShowError("Error launching maemo",
-							new MicaException(content));
-				}
-
-			});
-
-			// emit everything else to the console
-			processLauncher.redirectToConsole(console);
-
-			// wait for it to finish
-			try {
-				process.waitFor();
-			} catch (InterruptedException e) {
-
-			}
-		}
-
-		public void startMaemoCommand(ISDKTarget sdkTarget) throws MicaException {
-			if (sdkTarget == null) {
-				throw new MicaException("No SDK target specified");
-			}
-
-			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_START_ACTION);
-
-			performCommand(params);
-		}
-
-		public void stopMaemoCommand(ISDKTarget sdkTarget) throws MicaException {
-			if (sdkTarget == null) {
-				throw new MicaException("No SDK target specified");
-			}
-
-			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_STOP_ACTION);
-			performCommand(params);
-		}
-
-		public void restartMaemoCommand(ISDKTarget sdkTarget)
-				throws MicaException {
-			if (sdkTarget == null) {
-				throw new MicaException("No SDK target specified");
-			}
-
-			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_RESTART_ACTION);
-			performCommand(params);
-		}
-
-		private List<String> getParamList(String key) {
-			List<String> params = new ArrayList<String>();
-			params.add(sdkTarget.getPreferenceValue(key));
-			return params;
-		}
-
-		private String replaceActions(String command, String action) {
-			return command.replaceAll("\\$\\{ACTIONS\\}", action);
-		}
-	}
-	
-
-	/**
-	 * Test whether maemo is running. We look for 'maemo-launcher' in the
-	 * process list.
-	 * 
-	 * @param sdkTarget
-	 * @return true if maemo process found
-	 * @throws MicaException
-	 *             if query is impossible
-	 */
-	private boolean testMaemoLauncher(ISDKTarget sdkTarget)
-			throws MicaException {
-		List<IProcess> runningProcesses = getMaemoLaunchers(sdkTarget.getMachine());
-		return runningProcesses.size() > 0;
-	}
-
-	private List<IProcess> getMaemoLaunchers(IMachine machine) {
-		// includes scratchbox call that launched maemo-launcher
-		List<IProcess> runningProcesses = machine.getProcessLister()
-				.getProcesses(
-						new ProcessFilterCmdLineRegexp(".*/"
-								+ MAEMO_LAUNCHER_APP + "\\s+.*"));
-		return runningProcesses;
-	}
-
-	/**
-	 * Test whether maemo is started by testing the existence of the
-	 * maemo-launcher daemon
-	 * 
-	 * @param sdkTarget
-	 * @return flag
-	 */
-	public boolean isMaemoRunning(ISDKTarget sdkTarget) throws MicaException {
-		return testMaemoLauncher(sdkTarget);
-	}
-
-	/**
-	 * Start maemo if it's not running.
-	 * 
-	 * @param sdkTarget
-	 * @throws MicaException
-	 *             if already running or cannot be started
-	 */
-	public void startMaemo(ISDKTarget sdkTarget) throws MicaException {
-		if (isMaemoRunning(sdkTarget))
-			throw new MicaException("Maemo is already running");
-
-		MaemoCommand maemoCommand = new MaemoCommand(sdkTarget);
-		maemoCommand.startMaemoCommand(sdkTarget);
-	}
-
-	/**
-	 * Stop maemo if it's running
-	 * 
-	 * @param sdkTarget
-	 * @throws MicaException
-	 *             if not running or cannot be stopped
-	 */
-	public void stopMaemo(ISDKTarget sdkTarget) throws MicaException {
-		// always try... may be half-initialized
-		// if (!isMaemoRunning(sdkTarget))
-		// throw new
-		// ScratchboxException("Maemo is not running, or failed to launch.");
-
-		MaemoCommand maemoCommand = new MaemoCommand(sdkTarget);
-		maemoCommand.stopMaemoCommand(sdkTarget);
-	}
-
-	/**
-	 * Restart maemo
-	 * 
-	 * @param sdkTarget
-	 * @throws MicaException
-	 *             if cannot be restarted
-	 */
-	public void restartMaemo(ISDKTarget sdkTarget) throws MicaException {
-		MaemoCommand maemoCommand = new MaemoCommand(sdkTarget);
-		maemoCommand.restartMaemoCommand(sdkTarget);
-	}
-
-	/**
-	 * Kill maemo by forcibly killing instances of the launcher left behind
-	 * 
-	 * @param sdkTarget
-	 * @throws MicaException
-	 */
-	public void killMaemo(ISDKTarget sdkTarget) throws MicaException {
-		List<IProcess> pids = getMaemoLaunchers(sdkTarget.getMachine());
-		if (pids.size() == 0)
-			return;
-
-		try {
-			for (IProcess process : pids) {
-				process.terminate();
-			}
-		} catch (IOException e) {
-
-		}
-
-		// try again
-		pids = getMaemoLaunchers(sdkTarget.getMachine());
-		if (pids.size() == 0)
-			return;
-
-		try {
-			for (IProcess process : pids) {
-				process.kill();
-			}
-		} catch (IOException e) {
-			throw new MicaException("Could not kill " + MAEMO_LAUNCHER_APP, e);
-		}
-
-	}
-}

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -32,12 +32,23 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.ui.console.MessageConsole;
-import org.maemo.mica.common.core.*;
-import org.maemo.mica.common.core.machine.*;
-import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.sdk.*;
+import org.maemo.esbox.internal.maemosdk.core.Activator;
+import org.maemo.mica.common.core.CoreConsoleManager;
+import org.maemo.mica.common.core.CorePreferenceManager;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.Policy;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.IProcess;
+import org.maemo.mica.common.core.machine.MachineManager;
+import org.maemo.mica.common.core.machine.ProcessFilterCmdLineRegexp;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.ProcessLauncherCreator;
+import org.maemo.mica.common.core.sdk.IPreferenceProvider;
+import org.maemo.mica.common.core.sdk.ISDK;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
 import org.maemo.mica.common.project.core.ProjectManager;
-import org.maemo.esbox.internal.maemosdk.core.Activator;
 
 /**
  * Class handle all methods that needs some graphical environment. It invokes
@@ -67,21 +78,19 @@
 	 */
 	public void startX() throws MicaException {
 
-		XLauncher.getInstance().startX(
-				CorePreferenceManager.getInstance().getPreferenceProvider());
+		XLauncher.getInstance().startX(CorePreferenceManager.getInstance().getPreferenceProvider());
 	}
 
 	/**
 	 * Method that stop X-environment for Scratchbox
 	 */
 	public void stopX(ISDKTarget sdkTarget) throws MicaException {
-
-		if (sdkTarget != null
-				&& MaemoLauncher.getInstance().isMaemoRunning(sdkTarget))
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		
+		if (launcher!=null && sdkTarget != null && launcher.isMaemoRunning())
 			throw new MicaException("Maemo is still running. Stop Maemo first");
 
-		XLauncher.getInstance().stopX(
-				CorePreferenceManager.getInstance().getPreferenceProvider());
+		XLauncher.getInstance().stopX(CorePreferenceManager.getInstance().getPreferenceProvider());
 	}
 
 	/**
@@ -409,8 +418,7 @@
 				project);
 		IPath wdInScratchbox = sdkTarget.convertHostToTargetPath(wd);
 
-		IProcessLauncherFactory launcherFactory = sdkTarget
-				.getProcessLauncherFactory();
+		IProcessLauncherFactory launcherFactory = sdkTarget.getProcessLauncherFactory();
 
 		final IProcessLauncher processLauncher = ProcessLauncherCreator
 				.createProcessLauncher(launcherFactory, wdInScratchbox,
@@ -630,18 +638,31 @@
 	}
 
 	public boolean isMaemoStarted(ISDKTarget sdkTarget) {
-		try {
-			if (!isXServerStarted(sdkTarget))
+//		try {
+//			if (!isXServerStarted(sdkTarget))
+//				return false;
+//		} catch (MicaException e1) {
+//		}
+
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher!=null){
+			try{
+				return launcher.isMaemoRunning();
+			}catch (MicaException e) {
+				Activator.getErrorLogger().logError("Cannot test maemo status", e);
 				return false;
-		} catch (MicaException e1) {
-		}
-
-		try {
-			return MaemoLauncher.getInstance().isMaemoRunning(sdkTarget);
-		} catch (MicaException e) {
-			Activator.getErrorLogger().logError("Cannot test maemo status", e);
+			}
+		}else{
+			// TODO: Throw exception here
 			return false;
 		}
+		
+//		try {
+//			return MaemoLauncher.getInstance().isMaemoRunning(sdkTarget);
+//		} catch (MicaException e) {
+//			Activator.getErrorLogger().logError("Cannot test maemo status", e);
+//			return false;
+//		}
 	}
 
 	public boolean isXServerStarted(IPreferenceProvider prefProvider)
@@ -681,7 +702,11 @@
 		// throw new
 		// ESboxException("Cannot stop Maemo. Start X Server first");
 
-		MaemoLauncher.getInstance().stopMaemo(sdkTarget);
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher!=null){
+			launcher.stopMaemo();
+		}
+//		MaemoLauncher.getInstance().stopMaemo(sdkTarget);
 	}
 
 	/**
@@ -691,13 +716,17 @@
 	 * X is killed.
 	 */
 	public void startMaemo(ISDKTarget sdkTarget) throws MicaException {
-		if (!XLauncher.getInstance().isXServerStarted(sdkTarget)) {
-			MaemoLauncher.getInstance().killMaemo(sdkTarget);
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher!=null){
+			launcher.startMaemo();
 		}
-		XLauncher.getInstance().startXIfNeeded(sdkTarget);
-		if (XLauncher.getInstance().isXServerStarted(sdkTarget)) {
-			MaemoLauncher.getInstance().startMaemo(sdkTarget);
-		}
+//		if (!XLauncher.getInstance().isXServerStarted(sdkTarget)) {
+//			MaemoLauncher.getInstance().killMaemo(sdkTarget);
+//		}
+//		XLauncher.getInstance().startXIfNeeded(sdkTarget);
+//		if (XLauncher.getInstance().isXServerStarted(sdkTarget)) {
+//			MaemoLauncher.getInstance().startMaemo(sdkTarget);
+//		}
 	}
 
 	/**
@@ -707,21 +736,29 @@
 	 * X is killed.
 	 */
 	public void restartMaemo(ISDKTarget sdkTarget) throws MicaException {
-		if (!XLauncher.getInstance().isXServerStarted(sdkTarget)) {
-			MaemoLauncher.getInstance().killMaemo(sdkTarget);
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher!=null){
+			launcher.restartMaemo();
 		}
-		XLauncher.getInstance().startXIfNeeded(sdkTarget);
-
-		if (XLauncher.getInstance().isXServerStarted(sdkTarget)) {
-			MaemoLauncher.getInstance().restartMaemo(sdkTarget);
-		}
+//		if (!XLauncher.getInstance().isXServerStarted(sdkTarget)) {
+//			MaemoLauncher.getInstance().killMaemo(sdkTarget);
+//		}
+//		XLauncher.getInstance().startXIfNeeded(sdkTarget);
+//
+//		if (XLauncher.getInstance().isXServerStarted(sdkTarget)) {
+//			MaemoLauncher.getInstance().restartMaemo(sdkTarget);
+//		}
 	}
 
 	/**
 	 * Kill maemo. Does not kill X.
 	 */
 	public void killMaemo(ISDKTarget target) throws MicaException {
-		MaemoLauncher.getInstance().killMaemo(target);
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)target.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher!=null){
+			launcher.killMaemo();
+		}
+//		MaemoLauncher.getInstance().killMaemo(target);
 	}
 
 	/**

Deleted: branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapter.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,163 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation.
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.maemosdk.core.adapters;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-import org.maemo.esbox.internal.api.maemosdk.core.tools.MaemoLauncher;
-import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
-import org.maemo.esbox.internal.maemosdk.core.Activator;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.GeneralUtils;
-import org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter;
-import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
-
-import java.text.MessageFormat;
-import java.util.List;
-
-/**
- * Utility class to handle switching scratchbox targets and get user approval to
- * kill existing sessions if needed.
- * 
- * @author eswartz
- * 
- */
-public class Scratchbox1PrepareTargetProcessLaunchAdapter implements IPrepareTargetProcessLaunchAdapter {
-
-	private final ISDKTarget sdkTarget;
-	public Scratchbox1PrepareTargetProcessLaunchAdapter(ISDKTarget sdkTarget) {
-		this.sdkTarget = sdkTarget;
-	}
-	
-	public void prepareTargetForProcessLaunch() throws MicaException {
-		IScratchbox1SDK sdk = ((IScratchbox1SDK) sdkTarget.getSDK());
-		final String currentTarget = sdk.getCurrentTarget();
-		final String targetName = sdkTarget.getName();
-		if (currentTarget.equals(targetName)) {
-			return;
-		}
-
-		// see if maemo is running, since it needs to be killed to switch
-		// targets
-		// but isn't considered a "session" every time
-		boolean isMaemoRunning = MaemoLauncher.getInstance().isMaemoRunning(sdkTarget);
-
-		// now try to switch and see if shells are open
-		boolean failedToSwitch = false;
-		try {
-			sdk.selectTarget(targetName);
-		} catch (final ScratchboxException e) {
-			// sb-conf: You must close your other Scratchbox sessions first
-			// or
-			// Note: Couldn't reselect the target. There are other Scratchbox
-			// sessions open.
-			if (e.getLocalizedMessage().contains("Scratchbox sessions")) {
-				failedToSwitch = true;
-			} else {
-				throw e;
-			}
-		}
-
-		if (isMaemoRunning || failedToSwitch) {
-			final boolean[] ret = { false };
-
-			if (!GeneralUtils.isJUnitRunning()) {
-				Display.getDefault().syncExec(new Runnable() {
-					public void run() {
-						ret[0] = MessageDialog.openQuestion(null,
-							"Scratchbox Target Conflict",
-							MessageFormat.format(
-								"The scratchbox 1 target needs to be switched from ''{0}'' to ''{1}'', but existing sessions are active.\n\n"
-									+ "Kill existing Scratchbox sessions?  (You may manually close them first, if desired, then select 'No' to retry)",
-							currentTarget,
-							targetName));
-					};
-				});
-			} else {
-				ret[0] = true;
-			}
-
-			// if user accepts, kill existing ones
-			if (ret[0]) {
-				if (isMaemoRunning) {
-					// a target selection may succeed even if X and maemo are
-					// running... kill them first.
-					// We kill X too because some processes won't be killed by
-					// maemo-launcher.
-					try {
-						MaemoLauncher.getInstance().killMaemo(sdkTarget);
-					} catch (MicaException e2) {
-						// ignore
-					}
-					try {
-						XLauncher.getInstance().stopX(sdkTarget);
-					} catch (MicaException e2) {
-						// ignore
-					}
-				}
-
-				// now kill the scratchbox sessions the "approved" way
-				try {
-					sdk.killProcess();
-
-					// wait politely
-					try {
-						Thread.sleep(1000);
-					} catch (InterruptedException e1) {
-
-					}
-
-				} catch (ScratchboxException e2) {
-					// sb-conf killall can fail in the event there is some
-					// process with a space in its
-					// name... just log it and keep going
-					Activator.getErrorLogger().logError(
-							"Problem killing scratchbox sessions", e2);
-				}
-
-				// double-check, since it doesn't really work!
-				List<String> sessions = sdk.getSessions();
-				if (sessions.size() > 0) {
-					// forcibly kill processes
-					List<String> cmdLine = CommandLineArguments
-							.createFromVarArgs("kill", "-9");
-					cmdLine.addAll(sessions);
-
-					IProcessLauncher processLauncher = ProcessLauncherCreator
-							.createProcessLauncher(sdk
-									.getMachineProcessLauncherFactory(), null,
-									cmdLine);
-					Process process;
-					try {
-						process = processLauncher.createProcess();
-						process.waitFor();
-					} catch (final Exception e1) {
-						Display.getDefault().syncExec(new Runnable() {
-							public void run() {
-								MessageDialog.openError(null, "Scratchbox Target Conflict",
-									MessageFormat.format(
-										"Couldn''t kill scratchbox processes:\n\n{0}\n\nRetrying the target selection anyway.",
-										e1.getLocalizedMessage()));
-							};
-						});
-					}
-				}
-
-			}
-
-			// always retry, and rethrow if fails
-			sdk.selectTarget(targetName);
-		}
-	}
-}

Deleted: branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/maemosdk/core/adapters/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *******************************************************************************/
-
-package org.maemo.esbox.internal.maemosdk.core.adapters;
-
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
-import org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
-
-/**
- * 
- * @author eswartz
- *
- */
-public class Scratchbox1PrepareTargetProcessLaunchAdapterFactory implements IAdapterFactory {
-
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
-	 */
-	public Object getAdapter(Object adaptableObject, Class adapterType) {
-		if (adapterType.equals(IPrepareTargetProcessLaunchAdapter.class)) {
-			if (adaptableObject instanceof ISDKTarget
-					&& ((ISDKTarget) adaptableObject).getSDK() instanceof IScratchbox1SDK) {
-				ISDKTarget sdkTarget = (ISDKTarget) adaptableObject;
-				return new Scratchbox1PrepareTargetProcessLaunchAdapter(sdkTarget);
-			}
-		}
-		return null;
-	}
-
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
-	 */
-	public Class[] getAdapterList() {
-		return new Class[] { IPrepareTargetProcessLaunchAdapter.class };
-	}
-
-}

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestProcessLauncher.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestProcessLauncher.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestProcessLauncher.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -234,6 +234,7 @@
 		
 		IPath scriptPath = target.getMachine().getUserHome().append(".tmp").append("foo.sh");
 		IPath targetPath = target.getMachineToSDKTargetFileSystemMapping().convertTargetToHostPath(scriptPath);
+		assertNotNull(target + ": could not create a file in " + scriptPath, targetPath);
 		target.getTargetFileSystemAccess().getFileStore(targetPath.removeLastSegments(1)).mkdir(0, null);
 		
 		IFileStore fileStore = target.getTargetFileSystemAccess().getFileStore(targetPath);

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestSB2SDKProvider.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestSB2SDKProvider.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/TestSB2SDKProvider.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -144,7 +144,7 @@
 				|| etcPath.equals(hostPath));
 		
 		IPath rootstrapPath = ((IScratchboxSDKTarget) target).getRootstrapPath();
-		if (target.getName().contains("chinook40"))
+		if (target.getName().contains("chinook40_armel"))
 			assertNotNull(rootstrapPath);
 		if (rootstrapPath != null) {
 			System.out.println(target + " root is -> " + rootstrapPath);

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/AllTests.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/AllTests.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/AllTests.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -29,7 +29,6 @@
 		suite.addTestSuite(TestSelectTargetCommand.class);
 		suite.addTestSuite(TestShowTargetCommand.class);
 		suite.addTestSuite(TestRemoveCommand.class);
-		suite.addTestSuite(TestCreateTargetSb2Command.class);
 		suite.addTestSuite(TestShowPathMappingSb2Command.class);
 		suite.addTestSuite(TestResetTargetCommand.class);
 		suite.addTestSuite(TestScratchboxCommand.class);
@@ -39,7 +38,6 @@
 		suite.addTestSuite(TestCreateTargetCommand.class);
 		suite.addTestSuite(TestGetCurrentTargetCommand.class);
 		suite.addTestSuite(TestScratchboxFacade.class);
-		suite.addTestSuite(TestListSb2Commands.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/BaseSb2Test.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/BaseSb2Test.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/BaseSb2Test.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation.
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.scratchbox.tests.commands;
+
+import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoRootstrapCommand;
+import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoSdkCommand;
+
+public class BaseSb2Test extends BaseTest {
+	protected MaemoSdkCommand maemoSdkCommand;
+	protected MaemoRootstrapCommand maemoRootstrapCommand;
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+		if(sb2Sdk!=null){
+			maemoSdkCommand = new MaemoSdkCommand(sb2Command,
+					sb2Sdk.getMachineProcessLauncherFactory());
+			maemoRootstrapCommand = new MaemoRootstrapCommand(sb2Command,
+					sb2Sdk.getMachineProcessLauncherFactory());
+		}else{
+			fail("Scratchbox2 is not supported in current environment.");
+		}
+		
+	}
+}

Deleted: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestCreateTargetSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestCreateTargetSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestCreateTargetSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,79 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation.
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.scratchbox.tests.commands;
-
-import org.maemo.esbox.internal.scratchbox.sb2.command.CreateTargetSb2Command;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxCommand;
-import org.maemo.mica.common.core.MicaException;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class TestCreateTargetSb2Command extends BaseTest {
-
-	private final String TARGET_NAME = "TEST_TARGET";
-	private final String COMPILER = "/opt/maemo/tools/arm-2007q3/bin/arm-none-linux-gnueabi-gcc";
-	private final String CPUTRANSP = "sb2-qemu-arm";
-	
-	public void testPerformCommand() throws MicaException {
-		MockCommandAbstractor mockCommandAbstractor = getSb2MockCommandAbstractor(null);
-		ScratchboxCommand createTargetCommand = new CreateTargetSb2Command(sb2Sdk, 
-				mockCommandAbstractor);
-
-		List<String> param = new ArrayList<String>();
-
-		param.add(TARGET_NAME);
-		param.add(COMPILER);
-		try {
-			createTargetCommand.performCommand(param);
-			fail("Number of args is invalid");
-		} catch (MicaException e) {
-			// expected
-		}
-		param.add(CPUTRANSP);
-		createTargetCommand.performCommand(param);
-
-		List<String> lastCmdLine = mockCommandAbstractor.getLastCommandLine();
-		assertEquals("/bin/bash", lastCmdLine.get(0));
-		assertEquals("-c", lastCmdLine.get(1));
-		
-		String command = lastCmdLine.get(2);
-		assertEquals("sb2-init -c " + CPUTRANSP + " " + TARGET_NAME + " " + COMPILER, command);
-	}
-
-	public void testPerformCommandNoCpuTransp() throws MicaException {
-		MockCommandAbstractor mockCommandAbstractor = getSb2MockCommandAbstractor(null);
-		ScratchboxCommand createTargetCommand = new CreateTargetSb2Command(sb2Sdk, 
-				mockCommandAbstractor);
-
-		List<String> param = new ArrayList<String>();
-
-		param.add(TARGET_NAME);
-		param.add(COMPILER);
-		try {
-			createTargetCommand.performCommand(param);
-			fail("Number of args is invalid");
-		} catch (MicaException e) {
-			// expected
-		}
-		param.add(null);
-		createTargetCommand.performCommand(param);
-
-		List<String> lastCmdLine = mockCommandAbstractor.getLastCommandLine();
-		assertEquals("/bin/bash", lastCmdLine.get(0));
-		assertEquals("-c", lastCmdLine.get(1));
-		
-		String command = lastCmdLine.get(2);
-		assertEquals("sb2-init  " + TARGET_NAME + " " + COMPILER, command);
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListSb2Commands.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListSb2Commands.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListSb2Commands.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,229 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.scratchbox.tests.commands;
-
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.maemo.esbox.internal.scratchbox.sb2.command.*;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
-import org.maemo.mica.common.core.*;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.machine.IFileSystemAccess;
-import org.maemo.mica.common.core.process.IProcessLauncher;
-import org.maemo.mica.common.core.process.IProcessLauncherFactory;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.*;
-
-/**
- */
-public class TestListSb2Commands extends BaseTest {
-	private final String COMPILER = "arm-none-linux-gnueabi-gcc";
-
-	public void testListCompilersCommand() throws MicaException {
-		List<String> fakeParam = new ArrayList<String>();
-		fakeParam.add("fake");
-		
-		List<String> compilersExpected = new ArrayList<String>();
-		compilersExpected.add(COMPILER);
-
-		ListCompilersSb2Command listCompilersCommand = new ListCompilersSb2Command(sb2Command);
-		List<String> compilers = null;
-		try {
-			listCompilersCommand.performCommand(fakeParam);
-			fail("Invalid number of param");
-		} catch (MicaException e) {
-			// expected
-		}
-		compilers = listCompilersCommand
-				.performCommand(new ArrayList<String>());
-
-		// just make sure there is more than one devkit and that one of them looks like
-		// something we recognize
-		boolean matched = false;
-		for (String compiler : compilers) {
-			assertTrue(compiler.length() > 0);
-			assertTrue(sb2Sdk.getMachineFileSystemAccess().getFileStore(new Path(compiler)).fetchInfo().exists());
-			for (String exp : compilersExpected) {
-				if (compiler.endsWith(exp)) {
-					matched = true;
-					break;
-				}
-			}
-		}
-		assertTrue(matched);
-	}
-
-	/**
-	 * Test method for
-	 * {@link embedded.core.scratchbox.command.ListCputranspCommand#performCommand(java.util.List)}.
-	 */
-	public void testListCputranspCommand() throws MicaException {
-		List<String> fakeParam = new ArrayList<String>();
-		fakeParam.add("param");
-
-		List<String> cputranspExpected = new ArrayList<String>();
-		cputranspExpected
-				.add("sb2-qemu-arm");
-		cputranspExpected
-				.add("sbrsh");
-
-		ListCputranspSb2Command listCputranspCommand = new ListCputranspSb2Command(sb2Command);
-		List<String> cputransps = null;
-
-		try {
-			listCputranspCommand.performCommand(fakeParam);
-			fail("Invalid number of param");
-		} catch (MicaException e) {
-			// expected
-		}
-
-		cputransps = listCputranspCommand
-				.performCommand(new ArrayList<String>());
-
-		// just make sure there is more than one devkit and that one of them looks like
-		// something we recognize
-		boolean matched = false;
-		for (String cputransp : cputransps) {
-			assertTrue(cputransp.length() > 0);
-			assertTrue(sb2Sdk.getMachineFileSystemAccess().getFileStore(new Path(cputransp)).fetchInfo().exists());
-			for (String exp : cputranspExpected) {
-				if (cputransp.endsWith(exp)) {
-					matched = true;
-					break;
-				}
-			}
-		}
-		assertTrue(matched);
-	}
-
-
-	/**
-	 * Test method for
-	 * {@link embedded.core.scratchbox.command.ListTargetsCommand#performCommand(java.util.List)}.
-	 */
-	public void testListTargetsCommand() throws MicaException {
-		List<String> fakeParam = new ArrayList<String>();
-		fakeParam.add("param");
-
-		List<String> targetsExpected = new ArrayList<String>();
-		targetsExpected.add("bora31_armel");
-		targetsExpected.add("chinook40_armel");
-		targetsExpected.add("diablo41_armel");
-
-		ListTargetsCommand listTargetsCommand = new ListTargetsCommand(sb2Command);
-		List<String> targets = null;
-
-		try {
-			listTargetsCommand.performCommand(fakeParam);
-			fail("Invalid number of param");
-		} catch (MicaException e) {
-			// expected
-		}
-
-		targets = listTargetsCommand.performCommand(new ArrayList<String>());
-
-		// just make sure there is at least one target and that one of them looks like
-		// something we recognize
-		assertTrue(targets.size() > 0);
-		boolean matched = false;
-		for (String target : targets) {
-			assertTrue(target.length() > 0);
-			if (targetsExpected.contains(target)) {
-				matched = true;
-			}
-		}
-		assertTrue(matched);
-	}
-	
-	public void testListAvailableRootstrapsCommand() throws MicaException {
-		List<String> fakeParam = new ArrayList<String>();
-		fakeParam.add("param");
-
-		List<String> targetsExpected = new ArrayList<String>();
-		targetsExpected.add("bora31_armel");
-		targetsExpected.add("chinook40_armel");
-
-		ListAvailableMaemoRootstrapsSb2Command listRootstrapsCommand 
-			= new ListAvailableMaemoRootstrapsSb2Command(sb2Command);
-		List<MaemoRootstrap> rootstraps = null;
-
-		try {
-			listRootstrapsCommand.performCommand(fakeParam);
-			fail("Invalid number of param");
-		} catch (MicaException e) {
-			// expected
-		}
-		
-		IPreferenceStore store = CorePreferenceConstants.getPreferenceStore();
-		store.setValue(CorePreferenceConstants.LOG_COMMANDS.toString(), true);
-		store.setValue(CorePreferenceConstants.LOG_COMMANDS_PATH.toString(),
-				HostUtils.getTemporaryPath().append("esbox_commands.txt").toOSString());
-		try {
-			rootstraps = listRootstrapsCommand.performCommand(new ArrayList<String>());
-		} catch (MicaException e) {
-			// try again with proxy, manually set -- the JUnit workspace is prolly empty.
-			
-			ICommandAbstractor altCommandAbstractor = new ICommandAbstractor() {
-
-				public String getPreferenceValue(String key) {
-					return sb2Command.getPreferenceValue(key);
-				}
-
-				public IProcessLauncherFactory getProcessLauncherFactory() {
-					final IProcessLauncherFactory factory = sb2Command.getProcessLauncherFactory();
-					return new IProcessLauncherFactory() {
-
-						public IProcessLauncher createProcessLauncher(
-								IPath workingDirectory,
-								List<String> commandLine,
-								IEnvironmentModifierBlock environment) {
-							return factory.createProcessLauncher(workingDirectory, commandLine, environment);
-						}
-
-						public IEnvironmentModifierBlock defaultEnvironmentModifierBlock() {
-							return factory.defaultEnvironmentModifierBlock();
-						}
-						public Properties getRawEnvironment() {
-							return factory.getRawEnvironment();
-						}
-					};
-				}
-				
-				/* (non-Javadoc)
-				 * @see org.maemo.esbox.internal.common.core.command.ICommandAbstractor#getFileSystemAccess()
-				 */
-				public IFileSystemAccess getFileSystemAccess() {
-					return sb2Sdk.getMachineFileSystemAccess();
-				}
-				
-			};
-			
-			listRootstrapsCommand = new ListAvailableMaemoRootstrapsSb2Command(altCommandAbstractor);
-			rootstraps = listRootstrapsCommand.performCommand(new ArrayList<String>());
-		}
-
-		// just make sure there is more than one rootstrap and that one of them looks like
-		// something we recognize
-		assertTrue(rootstraps.size() > 0);
-		boolean matched = false;
-		for (MaemoRootstrap rootstrap : rootstraps) {
-			assertTrue(rootstrap.getName().length() > 0);
-			assertTrue(rootstrap.getArchitecture().length() > 0);
-			assertTrue(rootstrap.getDescription().length() > 0);
-			if (targetsExpected.contains(rootstrap.getName())) {
-				matched = true;
-			}
-		}
-		assertTrue(matched);
-	}
-}

Modified: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestRemoveSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,25 +10,23 @@
  *******************************************************************************/
 package org.maemo.esbox.scratchbox.tests.commands;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.maemo.esbox.internal.api.scratchbox.core.sdk.CacheUtils;
-import org.maemo.esbox.internal.scratchbox.sb2.command.RemoveTargetSb2Command;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxCommand;
 import org.maemo.mica.common.core.MicaException;
 
-import java.util.*;
-
 /**
  */
-public class TestRemoveSb2Command extends BaseTest {
+public class TestRemoveSb2Command extends BaseSb2Test {
 
 	public void testPerformCommand() throws MicaException {
 		final String TARGET_DOESNT_EXIST = "GHOST";
-		ScratchboxCommand removeCommand = new RemoveTargetSb2Command(sb2Sdk, sb2Command);
-
+		
 		List<String> param = new ArrayList<String>();
 
 		try {
-			removeCommand.performCommand(param);
+			maemoRootstrapCommand.remove(TARGET_DOESNT_EXIST);
 			fail("Invalid number of param");
 		} catch (MicaException e) {
 			// TODO: handle exception
@@ -37,7 +35,7 @@
 		param.add(TARGET_DOESNT_EXIST);
 
 		try {
-			removeCommand.performCommand(param);
+			maemoRootstrapCommand.showLocation(TARGET_DOESNT_EXIST);
 			fail("The target " + TARGET_DOESNT_EXIST
 					+ " does not exist. An error must be throwed.");
 		} catch (MicaException e) {
@@ -63,12 +61,9 @@
 		}
 		
 		if (targets.contains(TARGET)) {
-			ScratchboxCommand removeCommand = new RemoveTargetSb2Command(sb2Sdk, sb2Command);
-
-			List<String> param = Collections.singletonList(TARGET);
 			try {
 				CacheUtils.getInstance().clearCachedData();
-				removeCommand.performCommand(param);
+				maemoRootstrapCommand.remove(TARGET);
 				
 				CacheUtils.getInstance().clearCachedData();
 				targets = sb2Sdk.getTargets();

Added: branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.maemosdk.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchbox2SDK.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.scratchbox.tests.commands;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.maemo.esbox.internal.api.scratchbox.core.sdk.IScratchboxSDKPlatformArchitectureProvider;
+import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+import org.maemo.mica.common.core.sdk.ISDKPlatform;
+
+public class TestScratchbox2SDK extends BaseSb2Test {
+	Set<String> possibleRootstraps = null;
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+		possibleRootstraps = new HashSet<String>();
+		possibleRootstraps.add("diablo41_armel");
+		possibleRootstraps.add("diablo4.1.1_i386");
+		possibleRootstraps.add("chinook40_armel");
+		possibleRootstraps.add("bora31_armel");
+		possibleRootstraps.add("scirocco22_armel");
+		possibleRootstraps.add("mistral20_armel");
+	}
+	@Override
+	protected void tearDown() throws Exception {
+		possibleRootstraps = null;
+		super.tearDown();
+	}
+	
+	public void testInstalledMaemoRootstraps() throws Exception {
+		List<String> rootstraps =sb2Sdk.getInstalledMaemoRootstraps();
+		assertFalse("No rootstraps instaleld", rootstraps.isEmpty());
+		for(String rootstrap : rootstraps)
+			assertTrue(rootstrap+" is not in possible rootstraps set", possibleRootstraps.contains(rootstrap));
+		
+	}
+	
+	public void testAvailableMaemoRootstraps() throws Exception {
+		List<String> rootstraps = sb2Sdk.getAvailableMaemoRootstraps(null);
+		assertTrue("Available rootstrap list is not same as predefined possible rootstraps list.",
+				rootstraps.containsAll(possibleRootstraps) && rootstraps.size()==possibleRootstraps.size());
+		
+	}
+	
+	public void testGetArchitecture() throws Exception {
+		IScratchboxSDKPlatformArchitectureProvider 
+			provider = (IScratchboxSDKPlatformArchitectureProvider)sb2Sdk;
+		assertEquals(IScratchboxSDKTarget.ARCHITECTURE_ARMEL,provider.getArchitecture("diablo41_armel"));
+		assertEquals(IScratchboxSDKTarget.ARCHITECTURE_UNKNOWN,provider.getArchitecture("WRONG_TARGET"));
+	}
+	
+	public void testGetPlatform() throws Exception {
+		ISDKPlatform platform = sb2Sdk.getPlatform("diablo41_armel");
+		assertEquals("Diablo", platform.getName());
+		assertEquals("4.1", platform.getVersion());
+		
+		platform = sb2Sdk.getPlatform("diablo41_x86");
+		assertEquals("Diablo", platform.getName());
+		assertEquals("4.1", platform.getVersion());
+		
+		platform = sb2Sdk.getPlatform("diablo41_i386");
+		assertEquals("Diablo", platform.getName());
+		assertEquals("4.1", platform.getVersion());
+	}
+	
+	
+}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -28,8 +28,7 @@
 import org.maemo.mica.internal.api.common.core.machine.HostUnixMachine;
 import org.maemo.mica.internal.api.common.core.sdk.BaseSDK;
 
-public abstract class AbstractScratchboxSDK extends BaseSDK implements
-		IScratchboxSDK, IScratchboxSDKPlatformArchitectureProvider {
+public abstract class AbstractScratchboxSDK extends BaseSDK implements IScratchboxSDK {
 
 	protected IPreferenceProvider prefProvider = null;
 

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -13,6 +13,7 @@
 
 import java.util.List;
 
+import org.maemo.esbox.internal.api.scratchbox.core.sdk.IScratchboxSDKPlatformArchitectureProvider;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.sdk.ISDK;
 
@@ -22,7 +23,7 @@
  * @author baranov
  * 
  */
-public interface IScratchboxSDK extends ISDK {
+public interface IScratchboxSDK extends ISDK, IScratchboxSDKPlatformArchitectureProvider {
 	/**
 	 * If appropriate, get the cached value of the scratchbox target.
 	 * 

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/META-INF/MANIFEST.MF
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/META-INF/MANIFEST.MF	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/META-INF/MANIFEST.MF	2008-11-18 21:48:25 UTC (rev 952)
@@ -9,7 +9,8 @@
  org.eclipse.ui.ide,
  org.maemo.mica.maemosdk.ui;bundle-version="2.0.0",
  org.maemo.esbox.scratchbox.core;bundle-version="2.0.0",
- org.maemo.esbox.scratchbox.ui;bundle-version="2.0.0"
+ org.maemo.esbox.scratchbox.ui;bundle-version="2.0.0",
+ org.maemo.esbox.maemosdk.core;bundle-version="2.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-Vendor: INdT / Nokia

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/plugin.xml
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/plugin.xml	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/plugin.xml	2008-11-18 21:48:25 UTC (rev 952)
@@ -25,7 +25,22 @@
                type="org.maemo.mica.common.core.adapters.ISDKManageTargetAdapter">
          </adapter>
       </factory>
+      <factory
+            adaptableType="org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDKTarget"
+            class="org.maemo.esbox.internal.scratchbox.sb1.launcher.Scratchbox1PrepareTargetProcessLaunchAdapterFactory">
+         <adapter
+               type="org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter">
+         </adapter>
+      </factory>
+      <factory
+            adaptableType="org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDKTarget"
+            class="org.maemo.esbox.internal.scratchbox.sb1.launcher.Sb1MaemoLauncherAdapterFactory">
+         <adapter
+               type="org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter">
+         </adapter>
+      </factory>
    </extension>
+   
    <extension
          point="org.maemo.mica.common.core.preference_set_provider">
       <preferenceSetProvider

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapter.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,268 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb1.launcher;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.ui.console.IPatternMatchListener;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.PatternMatchEvent;
+import org.eclipse.ui.console.TextConsole;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
+import org.maemo.esbox.internal.scratchbox.sb1.Activator;
+import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDKTarget;
+import org.maemo.mica.common.core.CoreConsoleManager;
+import org.maemo.mica.common.core.CorePreferenceManager;
+import org.maemo.mica.common.core.ErrorLogger;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.machine.IProcess;
+import org.maemo.mica.common.core.machine.ProcessFilterCmdLineRegexp;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.ProcessLauncherCreator;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
+
+/**
+ * @author baranov
+ *
+ */
+public class Sb1MaemoLauncherAdapter implements IMaemoLauncherAdapter{
+	
+	private static final String MAEMO_LAUNCHER_APP = "maemo-launcher";
+	private final IScratchbox1SDKTarget target;
+	private final MaemoCommand command;
+	
+	/**
+	 * @param target
+	 */
+	public Sb1MaemoLauncherAdapter(IScratchbox1SDKTarget target){
+		this.target = target;
+		this.command = new MaemoCommand(target);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#killMaemo()
+	 */
+	public void killMaemo() throws MicaException {
+		List<IProcess> pids = getMaemoLaunchers(target.getSDK().getMachine());
+		if (pids.size() == 0)
+			return;
+
+		try {
+			for (IProcess process : pids) {
+				process.terminate();
+			}
+		} catch (IOException e) {
+
+		}
+
+		// try again
+		pids = getMaemoLaunchers(target.getSDK().getMachine());
+		if (pids.size() == 0)
+			return;
+
+		try {
+			for (IProcess process : pids) {
+				process.kill();
+			}
+		} catch (IOException e) {
+			throw new MicaException("Could not kill " + MAEMO_LAUNCHER_APP, e);
+		}
+		
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#restartMaemo()
+	 */
+	public void restartMaemo() throws MicaException {
+		command.restartMaemoCommand();
+		
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#startMaemo()
+	 */
+	public void startMaemo() throws MicaException {
+		if (isMaemoRunning())
+			throw new MicaException("Maemo is already running");
+		XLauncher.getInstance().startXIfNeeded(target);
+		if (XLauncher.getInstance().isXServerStarted(target)) {
+			command.startMaemoCommand();
+		}
+		
+		
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#stopMaemo()
+	 */
+	public void stopMaemo() throws MicaException {
+		command.stopMaemoCommand();
+		
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#isMaemoRunning()
+	 */
+	public boolean isMaemoRunning() throws MicaException {
+		List<IProcess> runningProcesses = getMaemoLaunchers(target.getSDK()
+				.getMachine());
+		return runningProcesses.size() > 0;
+	}
+
+	/**
+	 * @param machine
+	 * @return
+	 */
+	private List<IProcess> getMaemoLaunchers(IMachine machine) {
+		// includes scratchbox call that launched maemo-launcher
+		List<IProcess> runningProcesses = machine.getProcessLister()
+				.getProcesses(
+						new ProcessFilterCmdLineRegexp(".*/"
+								+ MAEMO_LAUNCHER_APP + "\\s+.*"));
+		return runningProcesses;
+	}
+	
+	static class MaemoCommand {
+
+		private ISDKTarget sdkTarget;
+
+		public MaemoCommand(ISDKTarget sdkTarget) {
+			this.sdkTarget = sdkTarget;
+		}
+
+		private void performCommand(List<String> params) throws MicaException {
+			String maemoCommand = sdkTarget.getPreferenceValue(
+					MaemoPreferenceConstants.MAEMO_COMMAND);
+			maemoCommand = this.replaceActions(maemoCommand,params.get(0));
+			
+			IProcessLauncherFactory processLauncherFactory = sdkTarget.getProcessLauncherFactory();
+			
+			IEnvironmentModifierBlock envBlock = processLauncherFactory.defaultEnvironmentModifierBlock();
+			
+			defineEmulatorXDisplayVariable(sdkTarget.getSDK().getMachine(), envBlock);
+			
+			IProcessLauncher processLauncher = ProcessLauncherCreator.createProcessLauncher(processLauncherFactory, null,
+					Collections.singletonList(maemoCommand), envBlock);
+
+			Process process = processLauncher.createProcess();
+
+			// spit the consumed output to the console
+			MessageConsole console = CoreConsoleManager.getInstance().getConsole(true,
+					sdkTarget, "Running Maemo command (" + params.get(0) + ")");
+
+			console.addPatternMatchListener(new IPatternMatchListener() {
+
+				public int getCompilerFlags() {
+					return 0;
+				}
+
+				public String getLineQualifier() {
+					return null;
+				}
+
+				public String getPattern() {
+					return "ERROR:.*";
+				}
+
+				public void connect(TextConsole console) {
+				}
+
+				public void disconnect() {
+				}
+
+				public void matchFound(PatternMatchEvent event) {
+					TextConsole console = (TextConsole) event.getSource();
+					String content;
+					try {
+						content = console.getDocument().get(event.getOffset(),
+								event.getLength());
+					} catch (BadLocationException e) {
+						content = console.getDocument().get();
+					}
+					ErrorLogger errorLogger = Activator.getErrorLogger();
+					errorLogger.logAndShowError("Error launching maemo",
+							new MicaException(content));
+				}
+
+			});
+
+			// emit everything else to the console
+			processLauncher.redirectToConsole(console);
+
+			// wait for it to finish
+			try {
+				process.waitFor();
+			} catch (InterruptedException e) {
+
+			}
+		}
+
+		public static void defineEmulatorXDisplayVariable(IMachine serverMachine, IEnvironmentModifierBlock envBlock) {
+			// local launches need DISPLAY that points back to the host machine
+			String display = CorePreferenceManager.getInstance().getRegisteredKeyValue(
+					MaemoPreferenceConstants.X_DISPLAY);
+			if (display != null && display.length() > 0) {
+				String host = serverMachine.getLocalMachineAddress();
+				if (host.equals(IMachine.LOCALHOST_ADDRESS)) {
+					host = "";
+				}
+				envBlock.define("DISPLAY", host + display);
+			}
+		}
+		
+		public void startMaemoCommand() throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_START_ACTION);
+
+			performCommand(params);
+		}
+
+		public void stopMaemoCommand() throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_STOP_ACTION);
+			performCommand(params);
+		}
+
+		public void restartMaemoCommand()
+				throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_RESTART_ACTION);
+			performCommand(params);
+		}
+
+		private List<String> getParamList(String key) {
+			List<String> params = new ArrayList<String>();
+			params.add(sdkTarget.getPreferenceValue(key));
+			return params;
+		}
+
+		private String replaceActions(String command, String action) {
+			return command.replaceAll("\\$\\{ACTIONS\\}", action);
+		}
+	}
+}

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapterFactory.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapterFactory.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Sb1MaemoLauncherAdapterFactory.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb1.launcher;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDKTarget;
+
+/**
+ * @author baranov
+ *
+ */
+public class Sb1MaemoLauncherAdapterFactory implements IAdapterFactory {
+
+	private static final Class<IMaemoLauncherAdapter> MAEMO_LAUNCHER_ADAPTER = IMaemoLauncherAdapter.class;
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		if (adapterType.equals(MAEMO_LAUNCHER_ADAPTER)) {
+			if (adaptableObject instanceof IScratchbox1SDKTarget) {
+				return new Sb1MaemoLauncherAdapter((IScratchbox1SDKTarget)adaptableObject);
+			}
+		}
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+	 */
+	public Class[] getAdapterList() {
+		return new Class[]{MAEMO_LAUNCHER_ADAPTER};
+	}
+
+}

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation.
+ * 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:
+ *    Ed Swartz (Nokia) - initial API and implementation
+ *	  Petr Baranov (Noki) - move to sb1 
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb1.launcher;
+
+import java.text.MessageFormat;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
+import org.maemo.esbox.internal.scratchbox.sb1.Activator;
+import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
+import org.maemo.mica.common.core.GeneralUtils;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter;
+import org.maemo.mica.common.core.process.CommandLineArguments;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.ProcessLauncherCreator;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
+
+/**
+ * Utility class to handle switching scratchbox targets and get user approval to
+ * kill existing sessions if needed.
+ * 
+ * @author eswartz
+ * 
+ */
+public class Scratchbox1PrepareTargetProcessLaunchAdapter implements IPrepareTargetProcessLaunchAdapter {
+
+	private final ISDKTarget sdkTarget;
+	public Scratchbox1PrepareTargetProcessLaunchAdapter(ISDKTarget sdkTarget) {
+		this.sdkTarget = sdkTarget;
+	}
+	
+	public void prepareTargetForProcessLaunch() throws MicaException {
+		IScratchbox1SDK sdk = ((IScratchbox1SDK) sdkTarget.getSDK());
+		final String currentTarget = sdk.getCurrentTarget();
+		final String targetName = sdkTarget.getName();
+		if (currentTarget.equals(targetName)) {
+			return;
+		}
+
+		// see if maemo is running, since it needs to be killed to switch
+		// targets
+		// but isn't considered a "session" every time
+		IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
+		if(launcher == null){
+			throw new MicaException("Cannot find IMaemoLauncherAdapter for " + sdkTarget);
+		}
+
+		// now try to switch and see if shells are open
+		boolean failedToSwitch = false;
+		try {
+			sdk.selectTarget(targetName);
+		} catch (final ScratchboxException e) {
+			// sb-conf: You must close your other Scratchbox sessions first
+			// or
+			// Note: Couldn't reselect the target. There are other Scratchbox
+			// sessions open.
+			if (e.getLocalizedMessage().contains("Scratchbox sessions")) {
+				failedToSwitch = true;
+			} else {
+				throw e;
+			}
+		}
+
+		if (launcher.isMaemoRunning() || failedToSwitch) {
+			final boolean[] ret = { false };
+
+			if (!GeneralUtils.isJUnitRunning()) {
+				Display.getDefault().syncExec(new Runnable() {
+					public void run() {
+						ret[0] = MessageDialog.openQuestion(null,
+							"Scratchbox Target Conflict",
+							MessageFormat.format(
+								"The scratchbox 1 target needs to be switched from ''{0}'' to ''{1}'', but existing sessions are active.\n\n"
+									+ "Kill existing Scratchbox sessions?  (You may manually close them first, if desired, then select 'No' to retry)",
+							currentTarget,
+							targetName));
+					};
+				});
+			} else {
+				ret[0] = true;
+			}
+
+			// if user accepts, kill existing ones
+			if (ret[0]) {
+				if (launcher.isMaemoRunning()) {
+					// a target selection may succeed even if X and maemo are
+					// running... kill them first.
+					// We kill X too because some processes won't be killed by
+					// maemo-launcher.
+					try {
+						launcher.killMaemo();
+					} catch (MicaException e2) {
+						// ignore
+					}
+					try {
+						XLauncher.getInstance().stopX(sdkTarget);
+					} catch (MicaException e2) {
+						// ignore
+					}
+				}
+
+				// now kill the scratchbox sessions the "approved" way
+				try {
+					sdk.killProcess();
+
+					// wait politely
+					try {
+						Thread.sleep(1000);
+					} catch (InterruptedException e1) {
+
+					}
+
+				} catch (ScratchboxException e2) {
+					// sb-conf killall can fail in the event there is some
+					// process with a space in its
+					// name... just log it and keep going
+					Activator.getErrorLogger().logError(
+							"Problem killing scratchbox sessions", e2);
+				}
+
+				// double-check, since it doesn't really work!
+				List<String> sessions = sdk.getSessions();
+				if (sessions.size() > 0) {
+					// forcibly kill processes
+					List<String> cmdLine = CommandLineArguments
+							.createFromVarArgs("kill", "-9");
+					cmdLine.addAll(sessions);
+
+					IProcessLauncher processLauncher = ProcessLauncherCreator
+							.createProcessLauncher(sdk
+									.getMachineProcessLauncherFactory(), null,
+									cmdLine);
+					Process process;
+					try {
+						process = processLauncher.createProcess();
+						process.waitFor();
+					} catch (final Exception e1) {
+						Display.getDefault().syncExec(new Runnable() {
+							public void run() {
+								MessageDialog.openError(null, "Scratchbox Target Conflict",
+									MessageFormat.format(
+										"Couldn''t kill scratchbox processes:\n\n{0}\n\nRetrying the target selection anyway.",
+										e1.getLocalizedMessage()));
+							};
+						});
+					}
+				}
+
+			}
+
+			// always retry, and rethrow if fails
+			sdk.selectTarget(targetName);
+		}
+	}
+}

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapterFactory.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Ed Swartz (Nokia) - initial API and implementation
+ *    Petr Baranov (Nokia) - move to sb1
+ *******************************************************************************/
+
+package org.maemo.esbox.internal.scratchbox.sb1.launcher;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
+import org.maemo.mica.common.core.adapters.IPrepareTargetProcessLaunchAdapter;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
+
+/**
+ * 
+ * @author eswartz
+ *
+ */
+public class Scratchbox1PrepareTargetProcessLaunchAdapterFactory implements IAdapterFactory {
+
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		if (adapterType.equals(IPrepareTargetProcessLaunchAdapter.class)) {
+			if (adaptableObject instanceof ISDKTarget
+					&& ((ISDKTarget) adaptableObject).getSDK() instanceof IScratchbox1SDK) {
+				ISDKTarget sdkTarget = (ISDKTarget) adaptableObject;
+				return new Scratchbox1PrepareTargetProcessLaunchAdapter(sdkTarget);
+			}
+		}
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+	 */
+	public Class[] getAdapterList() {
+		return new Class[] { IPrepareTargetProcessLaunchAdapter.class };
+	}
+
+}

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDKTarget.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDKTarget.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDKTarget.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.scratchbox.sb1.sdk;
+
+import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+
+public interface IScratchbox1SDKTarget extends IScratchboxSDKTarget {
+
+}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/META-INF/MANIFEST.MF
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/META-INF/MANIFEST.MF	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/META-INF/MANIFEST.MF	2008-11-18 21:48:25 UTC (rev 952)
@@ -9,7 +9,8 @@
  org.eclipse.ui.ide,
  org.maemo.mica.maemosdk.ui;bundle-version="2.0.0",
  org.maemo.esbox.scratchbox.core;bundle-version="2.0.0",
- org.maemo.esbox.scratchbox.ui;bundle-version="2.0.0"
+ org.maemo.esbox.scratchbox.ui;bundle-version="2.0.0",
+ org.maemo.esbox.maemosdk.core;bundle-version="2.0.0"
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Export-Package: org.maemo.esbox.internal.api.scratchbox.sb2.core,

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,11 +10,12 @@
 		WHEN ANYTHING ELSE CHANGED which can be merged into existing prefs, 
 		adjust ESboxPreferenceInitializer#RPEFS_VERSION_MINOR -->
 
-	<entry key="SB2_MAPPING_MODE">maemo</entry>
+	<entry key="SB2_MAPPING_MODE">devel</entry>
 	<entry key="SB2_INSTALL_MAPPING_MODE">emulate</entry>
+	<entry key="SB2_EMULATE_MAPPING_MODE">emulate</entry>
 	<entry key="SB2_LOG_LEVEL"></entry>
 	
-	<entry key="SB2_EXEC_COMMAND">sb2 -Qx -m ${MAPPING_MODE} ${LOG_OPTION} -t ${TARGET} "${{COMMAND}} ${{ARGS}}"</entry>
+	<entry key="SB2_EXEC_COMMAND">sb2 -J ${SESSION_FILE} -Qx -m ${MAPPING_MODE} ${LOG_OPTION} -t ${TARGET} "${{COMMAND}} ${{ARGS}}"</entry>
 
 	<!-- this qemu-arm link is expected to be valid; we don't try to substitute unlike for sb1: see GetGdbQemuCommandPatternCommand -->
 	<entry key="SB2_GDB_REMOTE_QEMU">sb2-qemu-arm -g ${PORT}</entry>

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/plugin.xml
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/plugin.xml	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/plugin.xml	2008-11-18 21:48:25 UTC (rev 952)
@@ -25,6 +25,13 @@
                type="org.maemo.mica.common.core.adapters.ISDKManageTargetAdapter">
          </adapter>
       </factory>
+      <factory
+            adaptableType="org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget"
+            class="org.maemo.esbox.internal.scratchbox.sb2.launcher.Sb2MaemoLauncherAdapterFactory">
+         <adapter
+               type="org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter">
+         </adapter>
+      </factory>
    </extension>
    <extension
          point="org.maemo.mica.common.core.preference_set_provider">

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -39,6 +39,7 @@
 	public static final String SB2_LIST_ACT = "SB2_LIST_ACT";
 	public static final String SB2_MAPPING_MODE = "SB2_MAPPING_MODE";
 	public static final String SB2_INSTALL_MAPPING_MODE = "SB2_INSTALL_MAPPING_MODE";
+	public static final String SB2_EMULATE_MAPPING_MODE = "SB2_EMULATE_MAPPING_MODE";
 	public static final String SB2_LOG_LEVEL = "SB2_LOG_LEVEL";
 	public static final String SB2_INIT_OPT_COMPILER = "SB2_INIT_OPT_COMPILER";
 	public static final String SB2_MAEMO_ROOTSTRAP_COMMAND = "SB2_MAEMO_ROOTSTRAP_COMMAND";

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,25 +10,32 @@
  *******************************************************************************/
 package org.maemo.esbox.internal.scratchbox.sb2;
 
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import com.nokia.cpp.internal.api.utils.core.Pair;
 
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
 import org.eclipse.core.runtime.preferences.InstanceScope;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.eclipse.ui.preferences.ScopedPreferenceStore;
+import org.maemo.esbox.internal.scratchbox.sb2.command.AbstractSb2Command;
 import org.maemo.mica.common.core.ErrorLogger;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.sdk.ISDK;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
 import org.osgi.framework.BundleContext;
 
+import java.io.*;
+import java.util.HashMap;
+import java.util.Map;
+
 /**
- * The activator class controls the plug-in life cycle
+ * The activator class controls the plug-in life cycle. For Scratchbox 2 it also manages
+ * the sessions for sb2 targets.  A session has the full lifetime of Eclipse independent
+ * of multiple refreshes of the SDK factory.
  */
 public class Activator extends Plugin {
 
@@ -39,7 +46,18 @@
 	private static Activator plugin;
 
 	private IPreferenceStore preferenceStore;
+	
+	// map of ISDKTarget name to session path on target machine
+	private Map<String, Pair<ISDK, String>> activeSessionMap = new HashMap<String, Pair<ISDK,String>>();
 
+	//configuration folder
+	private static File configurationDir = null; 
+	
+	static final String SESSION_SUFFIX = "-session";
+
+	private static final int MAX_SESSIONS = 100;
+	
+
 	/**
 	 * The constructor
 	 */
@@ -64,6 +82,7 @@
 	 * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
 	 */
 	public void stop(BundleContext context) throws Exception {
+		removeSessions();
 		plugin = null;
 		super.stop(context);
 	}
@@ -164,4 +183,90 @@
 	public static IStatus createErrorStatus(String msg, Throwable t) {
 		return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
 	}
+
+	public static File getConfigurationDir(){
+		if(configurationDir==null){
+			IWorkspace ws = ResourcesPlugin.getWorkspace();
+			IWorkspaceRoot wsRoot = ws.getRoot();
+			IPath location = wsRoot.getLocation();
+			configurationDir = new File(location.toOSString()+File.separator+".esbox");
+			if(!configurationDir.exists())
+				configurationDir.mkdirs();
+		}
+		return configurationDir;
+	}
+
+	/**
+	 * Allocate a session for the given SDK target.  This will keep the lifetime of
+	 * the Eclipse session.
+	 * @param sdkTarget the target owning the session
+	 * @return path to session on target machine
+	 */
+	public String findOrCreateSession(ISDKTarget sdkTarget) throws MicaException {
+		// check for existing session
+		Pair<ISDK, String> sessionInfo;
+		synchronized (activeSessionMap) {
+			sessionInfo = activeSessionMap.get(sdkTarget.getName());
+		}
+		if (sessionInfo != null) {
+			return sessionInfo.second;
+		}
+		
+		// first, create the .esbox folder
+		IPath esboxPath = sdkTarget.getMachine().getUserHome().append(".esbox");
+		IFileStore esbox = sdkTarget.getMachineFileSystemAccess().getFileStore(esboxPath);
+		if (!esbox.fetchInfo().exists()) {
+			try {
+				esbox.mkdir(EFS.NONE, null);
+			} catch (CoreException e) {
+				throw new MicaException("Cannot create directory for sessions: " + esbox, e);
+			}
+		}
+		
+		// find a unique session for this target under the machine's home directory;
+		// allow up to 10 sessions at a time -- any more probably indicates we've incorrectly
+		// forgotten to delete old ones.
+		boolean foundUniqueSession = false;
+		IFileStore sessionFile = null;
+		String sessionPattern = sdkTarget.getName() + SESSION_SUFFIX;
+		for (int sessionIter = 0; sessionIter < MAX_SESSIONS; sessionIter++) {
+			sessionFile = esbox.getChild(sessionPattern + 
+					(sessionIter > 1 ? "-" + sessionIter : ""));
+			if (!sessionFile.fetchInfo().exists()) {
+				foundUniqueSession = true;
+				break;
+			}
+		}
+		if (!foundUniqueSession) {
+			Activator.getErrorLogger().logError("Cannot create unique session file; overwriting "
+					+ sessionFile.toURI().getPath(), null);
+		}
+		
+		String session = sessionFile.toURI().getPath();
+		AbstractSb2Command.runProcess(sdkTarget.getSDK().getMachineProcessLauncherFactory(), 
+				"sb2", "-m", "emulate", "-m", "devel", "-S",
+						session, "\'exit\'");
+		
+		synchronized (activeSessionMap) {
+			activeSessionMap.put(sdkTarget.getName(), 
+					new Pair<ISDK, String>(sdkTarget.getSDK(), session));
+		}
+		return session;
+	}
+	
+	private void removeSessions() {
+		synchronized (activeSessionMap) {
+			for (Map.Entry<String, Pair<ISDK, String>> entry : activeSessionMap.entrySet()) {
+				try{
+					Pair<ISDK, String> sessionInfo = entry.getValue();
+					AbstractSb2Command.runProcess(
+							sessionInfo.first.getMachineProcessLauncherFactory(),
+							"sb2","-D", sessionInfo.second);
+				} catch (MicaException e) {
+					Activator.getErrorLogger().logError("Failed to remove sb2 session " + entry.getValue(), e);
+				}
+			}
+		}
+	}
+
 }

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,18 +10,31 @@
  *******************************************************************************/
 package org.maemo.esbox.internal.scratchbox.sb2.command;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
 import org.maemo.esbox.scratchbox.core.command.AbstractSDKCommand;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.process.*;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
 import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
 
 import java.security.InvalidParameterException;
+import java.util.Arrays;
+import java.util.List;
 
 public abstract class AbstractSb2Command extends AbstractSDKCommand {
 
-	public AbstractSb2Command(ICommandAbstractor commandAbstractor) {
+	private final IProcessLauncherFactory processLauncherFactory;
+	
+	public AbstractSb2Command(ICommandAbstractor commandAbstractor, IProcessLauncherFactory launcherFactory) {
 		super(commandAbstractor);
+		processLauncherFactory = launcherFactory;
 	}
 
+	public AbstractSb2Command(ICommandAbstractor commandAbstractor){
+		super(commandAbstractor);
+		processLauncherFactory = null;
+	}
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -38,4 +51,25 @@
 		return replaceScratchboxCommand(sboxCommand, action, options);
 	}
 
+	protected Results runProcess(String...args) throws MicaException{
+		return runProcess(this.processLauncherFactory,args);
+	}
+	
+	protected Results runProcess( IProgressMonitor monitor,String...args) throws MicaException{
+		List<String> cli = Arrays.asList(args);
+		IProcessLauncher launcher = processLauncherFactory.createProcessLauncher(null, cli,null);
+		return ProcessLauncherUtils.launchAndReadStandardStreams(launcher, monitor);
+	}
+	
+	/**
+	 * run process in host environment
+	 * @param processLauncherFactory
+	 * @param command with arguments to be run
+	 * @return Results of the process execution
+	 * @throws MicaException
+	 */
+	public static Results runProcess(IProcessLauncherFactory processLauncherFactory,String...args)throws MicaException{
+		return ProcessLauncherUtils.launchAndReadStandardStreams(processLauncherFactory, Arrays.asList(args));
+	}
+	
 }

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateMaemoRootstrapSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.CoreConsoleManager;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils;
-import org.maemo.mica.common.core.sdk.ISDK;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Creates a new rootstrap for a target, if it does not exist. This command
- * wraps the callback to service:
- * <p>
- * maemo-rootstrap [--force] install &lt;target&gt;
- * 
- */
-public class CreateMaemoRootstrapSb2Command extends MaemoRootstrapSb2Command {
-
-	private ISDK sdk;
-	private IProgressMonitor monitor;
-
-	public CreateMaemoRootstrapSb2Command(ISDK sdk,
-			ICommandAbstractor commandAbstractor, IProgressMonitor monitor) {
-		super(commandAbstractor);
-		this.sdk = sdk;
-		this.monitor = monitor;
-	}
-
-	protected boolean checkParameters(List<String> param) {
-		return param.size() == 3;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public Boolean performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String targetName = param.get(0);
-		String useHostToolsFlag = param.get(1);
-		String forceFlag = param.get(2);
-
-		List<String> params = new ArrayList<String>();
-		if (useHostToolsFlag.equals(Boolean.TRUE.toString())) {
-			params
-					.add(commandAbstractor
-							.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_HOST_TOOLS_OPT));
-		}
-		if (forceFlag.equals(Boolean.TRUE.toString())) {
-			params
-					.add(commandAbstractor
-							.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_FORCE_OPT));
-		}
-		params
-				.add(commandAbstractor
-						.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_INSTALL_ACT));
-		params.add(targetName);
-
-		IEnvironmentModifierBlock envBlock = commandAbstractor
-				.getProcessLauncherFactory().defaultEnvironmentModifierBlock();
-		ProcessLauncherUtils.defineProxyVariables(envBlock);
-
-		setMonitorAndConsole(monitor, CoreConsoleManager.getInstance().getConsole(true,
-				null, "Installing rootstrap " + targetName));
-		doPerformCommand(params, envBlock, 0);
-
-		sdk.refresh();
-
-		return true;
-	}
-
-	public int getParametersSize() {
-		return 1;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateTargetSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateTargetSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/CreateTargetSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.internal.scratchbox.sb2.Activator;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.sdk.ISDK;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.List;
-
-/**
- * Creates a new target, if it does not exist. This command wraps the callback
- * to service:
- * <p>
- * sb2-init {flags} [targetname] [compiler]
- * 
- */
-public class CreateTargetSb2Command extends AbstractSb2Command {
-
-	private ISDK sdk;
-
-	public CreateTargetSb2Command(ISDK sdk, ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-		this.sdk = sdk;
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return param.size() >= 3;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public Object performCommand(List<String> param) throws MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String targetName = param.get(0);
-		String compilerName = param.get(1);
-		String cpuTransp = param.get(2);
-
-		// remaining arguments are flags
-		String pattern = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_INIT_COMMAND);
-
-		ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
-		substitutor.define("TARGET", targetName);
-		substitutor.define("COMPILER", compilerName);
-
-		String options = "";
-		if (cpuTransp != null && cpuTransp.length() > 0) {
-			options += "-c " + cpuTransp;
-		}
-		substitutor.define("OPTIONS", options);
-
-		pattern = substitutor.substitute(pattern);
-
-		List<String> cmdLine = CommandLineArguments
-				.createFromCommandLine(pattern);
-
-		IProcessLauncher processLauncher = ProcessLauncherCreator
-				.createProcessLauncher(commandAbstractor
-						.getProcessLauncherFactory(), null, cmdLine);
-
-		Process process = processLauncher.createProcess();
-
-		processLauncher.redirectToConsole(true, null,
-				"Installing scratchbox2 target " + targetName);
-
-		try {
-			process.waitFor();
-		} catch (InterruptedException e) {
-			Activator.getErrorLogger().logError("Target installation aborted",
-					e);
-		}
-
-		sdk.refresh();
-
-		return true;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 3;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetCurrentTargetSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetCurrentTargetSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetCurrentTargetSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2008 INdT, (c) 2008 Nokia Corporation
- * 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:
- *    Raul Herbster (UFCG) - initial API and implementation
- *    Ed Swartz (Nokia)
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.*;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.io.*;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Get the current Scratchgox 2 target. There is no command to do this, so read
- * $HOME/.scratchbox2/config
- */
-public class GetCurrentTargetSb2Command extends AbstractSb2Command {
-
-	public GetCurrentTargetSb2Command(ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public String performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		IFileStore config = commandAbstractor
-				.getFileSystemAccess()
-				.getFileStore(
-						new Path("home")
-								.append(
-										commandAbstractor
-												.getPreferenceValue(CorePreferenceConstants.USER))
-								.append(".scratchbox2").append("config"));
-
-		InputStream is = null;
-		try {
-			is = config.openInputStream(EFS.NONE, null);
-			BufferedReader reader = new BufferedReader(
-					new InputStreamReader(is));
-			Pattern varPattern = Pattern
-					.compile("\\s*DEFAULT_TARGET\\s*=\\s*(\\S+)\\s*");
-			String line;
-			while ((line = reader.readLine()) != null) {
-				Matcher matcher = varPattern.matcher(line.trim());
-				if (matcher.matches()) {
-					return matcher.group(1);
-				}
-			}
-
-			return null;
-		} catch (IOException e) {
-			throw new ScratchboxException("Cannot read target from " + config
-					+ ": " + e.getMessage());
-		} catch (CoreException e) {
-			throw new ScratchboxException("Cannot read target from " + config
-					+ ": " + e.getMessage());
-		} finally {
-			Policy.close(is);
-		}
-
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/GetMaemoRootstrapLocationCommand.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,90 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation.
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author eswartz
- * 
- */
-public class GetMaemoRootstrapLocationCommand extends MaemoRootstrapSb2Command {
-
-	private IScratchboxSDKTarget sdkTarget;
-
-	public GetMaemoRootstrapLocationCommand(
-			ICommandAbstractor commandAbstractor, IScratchboxSDKTarget sdkTarget) {
-		super(commandAbstractor);
-		this.sdkTarget = sdkTarget;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return param.size() == 0;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * org.maemo.mica.internal.common.core.command.ICommand#performCommand(java.util
-	 * .List)
-	 */
-	public Object performCommand(List<String> params)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(params))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		List<String> rsCommands = new ArrayList<String>(2);
-
-		String pathAction = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_PATH_ACT);
-
-		rsCommands.add(pathAction);
-		rsCommands.add(sdkTarget.getName());
-
-		List<String> results = doPerformCommand(rsCommands, null, 0);
-		if (results.size() == 0)
-			throw new ScratchboxException(
-					"Could not detect rootstrap location for " + sdkTarget
-							+ "\ngot:\n" + catenateLines(results));
-
-		// ignore bogus report of deleted rootstrap
-		IPath root = new Path(results.get(0).trim());
-		IFileStore store = sdkTarget.getMachineFileSystemAccess().getFileStore(
-				root);
-		if (store.fetchInfo().exists())
-			return root;
-		else
-			throw new ScratchboxException("Rootstrap location for " + sdkTarget
-					+ " does not exist: " + store);
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListAvailableMaemoRootstrapsSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.*;
-
-/**
- * List the maemo rootstraps available for installation.
- */
-public class ListAvailableMaemoRootstrapsSb2Command extends
-		MaemoRootstrapSb2Command {
-
-	private static final int LIST_TIMEOUT = 10000;
-
-	public ListAvailableMaemoRootstrapsSb2Command(
-			ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return param.size() == 0;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public List<MaemoRootstrap> performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String availableAction = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_AVAILABLE_ACT);
-
-		// ensure the proxy is established
-		IEnvironmentModifierBlock proxyEnvBlock = commandAbstractor
-				.getProcessLauncherFactory().defaultEnvironmentModifierBlock();
-		ProcessLauncherUtils.defineProxyVariables(proxyEnvBlock);
-
-		List<String> available = doPerformCommand(Collections
-				.singletonList(availableAction), proxyEnvBlock, LIST_TIMEOUT);
-
-		// this output has a few header lines
-		List<MaemoRootstrap> targetsAvailable = new ArrayList<MaemoRootstrap>();
-
-		boolean gotHeader = false;
-		for (String line : available) {
-			if (line.contains("Nickname,")) {
-				gotHeader = true;
-				continue;
-			}
-			if (line.trim().length() == 0) {
-				continue;
-			}
-			if (!gotHeader) {
-				continue;
-			}
-
-			String[] tokens = line.split(",\\s*");
-			if (tokens.length == 3) {
-				targetsAvailable.add(new MaemoRootstrap(tokens[0], tokens[1],
-						tokens[2]));
-			}
-
-		}
-		return targetsAvailable;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListCompilersSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListCompilersSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListCompilersSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,80 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.maemo.esbox.internal.scratchbox.sb2.Activator;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * List the installed compilers. There's no known command for this, but we can
- * look in specific places.
- * 
- */
-public class ListCompilersSb2Command extends AbstractSb2Command {
-
-	public ListCompilersSb2Command(ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public List<String> performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		List<String> compilersAvailable = new ArrayList<String>();
-
-		try {
-			IFileStore baseToolDir = commandAbstractor.getFileSystemAccess()
-					.getFileStore(new Path("/opt/maemo/tools"));
-			IFileStore[] kids = baseToolDir.childStores(EFS.NONE, null);
-			for (IFileStore baseDir : kids) {
-				IFileStore dir = baseDir.getChild("bin");
-				if (dir.fetchInfo().isDirectory()) {
-					IFileStore[] files = dir.childStores(EFS.NONE, null);
-					for (IFileStore file : files) {
-						if (file.getName().endsWith("-gcc")) {
-							compilersAvailable.add(file.toURI().getPath());
-							break;
-						}
-					}
-				}
-			}
-		} catch (CoreException e) {
-			Activator.getErrorLogger().logError("Error scanning compilers", e);
-		}
-		return compilersAvailable;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListInstalledMaemoRootstrapsSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,66 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * List the maemo rootstraps installed
- */
-public class ListInstalledMaemoRootstrapsSb2Command extends
-		MaemoRootstrapSb2Command {
-
-	public ListInstalledMaemoRootstrapsSb2Command(
-			ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return param.size() == 0;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public List<String> performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String availableAction = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_LIST_ACT);
-
-		List<String> installed = doPerformCommand(Collections
-				.singletonList(availableAction), null, 0);
-
-		return installed;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListTargetsCommand.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListTargetsCommand.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ListTargetsCommand.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2008 INdT, (c) 2008 Nokia Corporation
- * 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:
- *    Raul Herbster (UFCG) - initial API and implementation
- *    Ed Swartz (Nokia)
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.List;
-
-/**
- * List the installed targets. This command wraps the callback to service (sb1)
- * sb-conf list --targets or sb2-config -l (sb2)
- * 
- */
-public class ListTargetsCommand extends AbstractSb2Command {
-
-	public ListTargetsCommand(ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public List<String> performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String listAction;
-		String targetsOption;
-		listAction = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_LIST_ACT);
-		targetsOption = "";
-
-		String listTargetsCommandString = this.replaceScratchboxConfigCommand(
-				listAction, new String[] { targetsOption });
-
-		Process process = createProcess(listTargetsCommandString, null);
-
-		List<String> targetsAvailable = getLineInputFromProcessAndWait(process,
-				true, 0);
-
-		return targetsAvailable;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java (from rev 951, branches/sdkPlusSupport/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	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapCommand.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.*;
+
+public class MaemoRootstrapCommand extends AbstractSb2Command {
+	
+	public static final int INSTALLED_TARGETS = 0;
+	public static final int AVAILABLE_TARGETS = 1;
+	
+	private static final String MAEMO_ROOTSTRAP = "maemo-rootstrap";
+	
+	private static final String COMMAND_INSTALL = "install";
+	private static final String COMMAND_LIST = "list";
+	private static final String COMMAND_AVAILABLE = "available";
+
+	private static final String PATH = "path";
+	private static final String ARCH = "arch";
+
+	private static final String COMMAND_REMOVE = "remove";
+
+	private static final String OPTION_FORCE = "--force";
+
+	private static final String COMMAND_NEW = "new";
+	
+	
+
+	public MaemoRootstrapCommand(ICommandAbstractor commandAbstractor, IProcessLauncherFactory launcherFactory) {
+		super(commandAbstractor,launcherFactory);
+	}
+
+	@Override
+	public int getParametersSize() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
+	public Object performCommand(List<String> params) throws MicaException {
+		return null;
+	}
+	
+	/**
+	 * maemo-rootstrap install rootstrap
+	 * @param monitor 
+	 */
+	public void install(String rootstrapName, IProgressMonitor monitor) throws MicaException{
+		runProcess(monitor,MAEMO_ROOTSTRAP,COMMAND_INSTALL,rootstrapName);
+	}
+
+	/**
+	 * run maemo-rootstrap list
+	 * @return
+	 */
+	public List<String> list(int type, IProgressMonitor monitor) throws MicaException{
+		Results result = null;
+		switch(type){
+		case INSTALLED_TARGETS:
+			result = runProcess(monitor,MAEMO_ROOTSTRAP,COMMAND_LIST);
+			break;
+		case AVAILABLE_TARGETS:
+			result = runProcess(monitor,MAEMO_ROOTSTRAP,COMMAND_AVAILABLE);
+			break;
+		}
+		if(result.exitCode==0)
+			return Arrays.asList(result.getStdoutLines());
+		else
+			return new ArrayList<String>();
+	}
+	
+	/**
+	 * sudo maemo-rootstrap remove <rootstrapName>
+	 * @return
+	 * @throws MicaException
+	 */
+	public void remove(String name) throws MicaException{
+		runProcess(MAEMO_ROOTSTRAP,OPTION_FORCE,COMMAND_REMOVE,name);
+	}
+	
+	/**
+	 * run maemo-rootstrap path <name>
+	 * @param name
+	 */
+	public String showLocation(String name) throws MicaException{
+		Results result = runProcess(MAEMO_ROOTSTRAP,PATH,name);
+		return result.stdout;
+	}
+
+	/**
+	 * run maemo-rootstrap arch <name>
+	 * @param rootstrap name, e.g. diablo41_armel
+	 * @return architecture name
+	 * @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;
+	}
+
+	public boolean newRootstrap(String name) throws MicaException {
+		Results result =  runProcess(MAEMO_ROOTSTRAP,COMMAND_NEW,name);
+		return result.exitCode==0;
+		
+	}
+
+	
+	
+}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoRootstrapSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.process.CommandLineArguments;
-import org.maemo.mica.common.core.process.ShellTemplateSubstitutor;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Base class for maemo rootstrap command.
- */
-public abstract class MaemoRootstrapSb2Command extends AbstractSb2Command {
-
-	public MaemoRootstrapSb2Command(ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return true;
-	}
-
-	/**
-	 * Override if stderr output is allowed.
-	 * 
-	 * @return false
-	 */
-	protected boolean allowErrors() {
-		return false;
-
-	}
-
-	/**
-	 * Perform the command with the given params as command line arguments, with
-	 * an optional timeout (triggering ScratchboxException if reached)
-	 * 
-	 * @param params
-	 *            command line parameters to maemo-rootstrap
-	 * @param envBlock
-	 *            any environment needed or <code>null</code>
-	 * @param timeout
-	 *            if not 0, timeout in milliseconds
-	 * @return lines from stdout
-	 * @throws ScratchboxException
-	 *             if command execution fails or if timeout reached
-	 */
-	@SuppressWarnings("unchecked")
-	protected List<String> doPerformCommand(List<String> params,
-			IEnvironmentModifierBlock envBlock, long timeout)
-			throws MicaException {
-		String rootstrapCommand = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_COMMAND);
-
-		String options = CommandLineArguments.toCommandLine(params);
-
-		ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
-		substitutor.define("OPTIONS", options);
-
-		rootstrapCommand = substitutor.substitute(rootstrapCommand);
-
-		if (console == null) {
-			Process process = createProcess(rootstrapCommand, envBlock);
-			List<String> results = getLineInputFromProcessAndWait(process,
-					allowErrors(), timeout);
-			return results;
-		} else {
-			runAndWaitForProcess("Running " + rootstrapCommand,
-					rootstrapCommand, envBlock, timeout);
-			return Collections.EMPTY_LIST;
-		}
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Copied: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoSdkCommand.java (from rev 951, branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoSdkCommand.java)
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoSdkCommand.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/MaemoSdkCommand.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.command;
+
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
+import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class MaemoSdkCommand extends AbstractSb2Command{
+
+	public static final String STATUS_UP = "up";
+	public static final String STATUS_DOWN = "down";
+	
+	private static final String MAEMO_SDK = "maemo-sdk";
+	
+	private static final String COMMAND_START = "start";
+	private static final String SPECIFIER_GUI = "gui";
+	private static final String COMMAND_STOP = "stop";
+	private static final String COMMAND_SHOW = "show";
+	private static final String SPECIFIER_ROOTSTRAP = "rootstrap";
+	private static final String COMMAND_LIST = "list";
+	private static final String SPECIFIER_TOOLCHAINS = "toolchains";
+	private static final String COMMAND_ENTER = "enter";
+	private static final String SPECIFIER_RUNTIME = "runtime";
+
+	public MaemoSdkCommand(ICommandAbstractor commandAbstractor, IProcessLauncherFactory launcherFactory) {
+		super(commandAbstractor,launcherFactory);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	public int getParametersSize() {
+		return 0;
+	}
+
+	public Object performCommand(List<String> params) throws MicaException {
+		return null;
+	}
+
+	/**
+	 * @param targetName
+	 * @throws MicaException
+	 */
+	public void startMaemo(String targetName) throws MicaException{
+		runProcess(MAEMO_SDK,COMMAND_START,SPECIFIER_GUI,targetName);
+	}
+
+	/**
+	 * @param targetName
+	 * @throws MicaException
+	 */
+	public void stopMaemo(String targetName) throws MicaException{
+		runProcess(MAEMO_SDK,COMMAND_STOP,SPECIFIER_GUI,targetName);
+	}
+
+	/**
+	 * @param targetName
+	 * @return
+	 * @throws MicaException
+	 */
+	public boolean isUp(String targetName) throws MicaException{
+		Results result = runProcess(MAEMO_SDK,COMMAND_SHOW,SPECIFIER_GUI,targetName);
+		return result.stdout.replaceAll("\\n", "").toLowerCase().equals(STATUS_UP);
+	}
+	
+	/**
+	 * run maemo-sdk show rootstrap
+	 * @return
+	 * @throws MicaException
+	 */
+	public String getDefaultRootstrap() throws MicaException{
+		Results result = runProcess(MAEMO_SDK,COMMAND_SHOW,SPECIFIER_ROOTSTRAP);
+		return result.stdout;
+	}
+	
+	/**
+	 * maemo-sdk list toolchains
+	 * @return
+	 * @throws MicaException
+	 */
+	public List<String> listCompilers() throws MicaException{
+		Results result = runProcess(MAEMO_SDK,COMMAND_LIST,SPECIFIER_TOOLCHAINS);
+		return Arrays.asList(result.getStdoutLines());
+	}
+
+}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveMaemoRootstrapSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.CoreConsoleManager;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
-import org.maemo.mica.common.core.process.ProcessLauncherUtils;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Remove a maemo rootstrap. Parameters are target name and force boolean flag.
- */
-public class RemoveMaemoRootstrapSb2Command extends MaemoRootstrapSb2Command {
-
-	private final IProgressMonitor monitor;
-
-	public RemoveMaemoRootstrapSb2Command(ICommandAbstractor commandAbstractor,
-			IProgressMonitor monitor) {
-		super(commandAbstractor);
-		this.monitor = monitor;
-	}
-
-	@Override
-	protected boolean checkParameters(List<String> param) {
-		return param.size() == 2;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public Boolean performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String targetName = param.get(0);
-		String forceFlag = param.get(1);
-
-		String action = commandAbstractor
-				.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_REMOVE_ACT);
-
-		List<String> commands = new ArrayList<String>();
-
-		if (forceFlag.equals(Boolean.TRUE.toString())) {
-			String force = commandAbstractor
-					.getPreferenceValue(SB2PreferenceConstants.SB2_MAEMO_ROOTSTRAP_FORCE_OPT);
-			commands.add(force);
-		}
-		commands.add(action);
-		commands.add(targetName);
-
-		IEnvironmentModifierBlock envBlock = commandAbstractor
-				.getProcessLauncherFactory().defaultEnvironmentModifierBlock();
-		ProcessLauncherUtils.defineProxyVariables(envBlock);
-
-		setMonitorAndConsole(monitor, CoreConsoleManager.getInstance().getConsole(true,
-				null, "Removing rootstrap " + targetName));
-
-		doPerformCommand(commands, envBlock, 0);
-
-		return Boolean.TRUE;
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 0;
-	}
-
-}

Deleted: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveTargetSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveTargetSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/RemoveTargetSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Nokia Corporation
- * 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:
- *    Ed Swartz (Nokia) - initial API and implementation
- *    Petr Baranov (Nokia)
- *******************************************************************************/
-package org.maemo.esbox.internal.scratchbox.sb2.command;
-
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
-import org.eclipse.core.runtime.CoreException;
-import org.maemo.esbox.internal.scratchbox.sb2.core.Scratchbox2SDK;
-import org.maemo.esbox.scratchbox.core.command.ScratchboxInvalidParameterException;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
-import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.sdk.ISDK;
-import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Remove a Scratchbox 2 target. There's no known command for this, but we can
- * manually fix up the system.
- * 
- */
-public class RemoveTargetSb2Command extends AbstractSb2Command {
-
-	private Scratchbox2SDK sdk;
-
-	public RemoveTargetSb2Command(ISDK sdk, ICommandAbstractor commandAbstractor) {
-		super(commandAbstractor);
-		this.sdk = (Scratchbox2SDK) sdk;
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see
-	 * embedded.core.scratchbox.command.IScratchboxCommand#performCommand(java
-	 * .lang.Object)
-	 */
-	public Object performCommand(List<String> param)
-			throws ScratchboxException, MicaException {
-		if (!this.checkParameters(param))
-			throw new ScratchboxInvalidParameterException(
-					"Invalid number of parameters");
-
-		String targetToRemove = param.get(0);
-		if (!targetExist(targetToRemove))
-			throw new ScratchboxInvalidParameterException("Target "
-					+ targetToRemove + " does not exist.");
-
-		IFileStore sb2Dir = commandAbstractor.getFileSystemAccess()
-				.getFileStore(sdk.getScratchbox2ConfigDirectory());
-		IFileStore targetDir = sb2Dir.getChild(targetToRemove);
-
-		if (!targetDir.fetchInfo().exists()) {
-			throw new ScratchboxInvalidParameterException("Target "
-					+ targetToRemove
-					+ " does not exist at the expected location: " + targetDir);
-		}
-
-		try {
-			targetDir.delete(EFS.NONE, null);
-		} catch (CoreException e) {
-			throw new ScratchboxException("Failed to delete rootstrap", e);
-		} finally {
-			sdk.refresh();
-		}
-
-		return true;
-	}
-
-	/**
-	 * Verify if a target exists.
-	 * 
-	 * @param targetToRemove
-	 *            the target to verify.
-	 * 
-	 * @return true, if the target exists in Scratchbox; false, otherwise.
-	 * @throws ScratchboxException
-	 *             if some problem occurrs while requesting Scratchbox services.
-	 */
-	private boolean targetExist(String targetToRemove) throws MicaException {
-		List<String> targetsAvailable = new ListTargetsCommand(
-				commandAbstractor).performCommand(new ArrayList<String>());
-		return targetsAvailable.contains(targetToRemove);
-	}
-
-	@Override
-	public int getParametersSize() {
-		return 1;
-	}
-
-}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ShowPathMappingSb2Command.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ShowPathMappingSb2Command.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/ShowPathMappingSb2Command.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -60,11 +60,11 @@
 
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
 		ByteArrayOutputStream err = new ByteArrayOutputStream();
-		launcher.waitAndRead(out, err);
+		int exit = launcher.waitAndRead(out, err);
 
-		if (err.size() != 0)
+		if (exit != 0)
 			throw new ScratchboxException(
-					"Cannot resolve scratchbox2 path mappings:\n" + err);
+					"Cannot resolve scratchbox2 path mappings:\n" + out + err);
 
 		String resolveInfo = out.toString().trim();
 		String[] lines = resolveInfo.split("\r\n|\r|\n");

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2FileSystemMapping.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2FileSystemMapping.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2FileSystemMapping.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -14,7 +14,6 @@
 
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
-import org.maemo.esbox.internal.scratchbox.sb2.Activator;
 import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.internal.api.common.core.machine.FileSystemMapping;
@@ -39,7 +38,7 @@
 	 * @param target
 	 */
 	public Scratchbox2FileSystemMapping(IScratchboxSDKTarget sdkTarget,
-			IPath scratchboxBase, String target, String user) {
+			IPath scratchboxBase, String target, String user) throws MicaException {
 
 		super(FileSystemMapping.getMachineCanonicalizer(true),
 				FileSystemMapping.getMachineCanonicalizer(true));
@@ -66,16 +65,10 @@
 		}
 
 		Map<IPath, IPath> pathMapping = null;
-		try {
-			pathMapping = Scratchbox2SDK.getSb2PathMapping(sdkTarget,
-					topLevelPaths);
-			// pathMapping = ScratchboxFacade.getInstance().getSb2PathMapping(
-			// sdkTarget, topLevelPaths);
-		} catch (MicaException e) {
-			Activator.getErrorLogger().logError(
-					"Unable to map Scratchbox 2 paths", e);
-			return;
-		}
+		pathMapping = Scratchbox2SDK.getSb2PathMapping(sdkTarget,
+				topLevelPaths);
+		// pathMapping = ScratchboxFacade.getInstance().getSb2PathMapping(
+		// sdkTarget, topLevelPaths);
 
 		for (Map.Entry<IPath, IPath> entry : pathMapping.entrySet()) {
 			map(mappings, entry.getValue(), entry.getKey());

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 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,25 +10,36 @@
  *******************************************************************************/
 package org.maemo.esbox.internal.scratchbox.sb2.core;
 
-import org.eclipse.core.runtime.*;
-import org.maemo.esbox.internal.api.scratchbox.core.sdk.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.maemo.esbox.internal.api.scratchbox.core.sdk.AbstractScratchboxSDK;
+import org.maemo.esbox.internal.api.scratchbox.core.sdk.CacheUtils;
 import org.maemo.esbox.internal.scratchbox.sb2.Activator;
-import org.maemo.esbox.internal.scratchbox.sb2.command.*;
+import org.maemo.esbox.internal.scratchbox.sb2.command.GetVersionScratchboxCommand;
+import org.maemo.esbox.internal.scratchbox.sb2.command.ListCputranspSb2Command;
+import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoRootstrapCommand;
+import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoSdkCommand;
+import org.maemo.esbox.internal.scratchbox.sb2.command.ShowPathMappingSb2Command;
 import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
 import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
-import org.maemo.mica.common.core.CorePreferenceConstants;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.machine.IMachine;
 import org.maemo.mica.common.core.machine.MachineUtils;
-import org.maemo.mica.common.core.sdk.*;
+import org.maemo.mica.common.core.process.IProcessLauncherFactory;
+import org.maemo.mica.common.core.sdk.IPreferenceProvider;
+import org.maemo.mica.common.core.sdk.ISDKPlatform;
+import org.maemo.mica.common.core.sdk.ISDKTarget;
 import org.maemo.mica.common.core.sdk.commands.ICommandAbstractor;
 import org.maemo.mica.internal.api.common.core.sdk.BaseSDKPlatform;
 
-import java.util.*;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 /**
  * @author baranov
  * 
@@ -38,18 +49,46 @@
 
 	private static final IPath ROOT_PATH = new Path("/");
 	private static Pattern TARGET_PLATFORM_VERSION_ARCHITECTURE_PATTERN = Pattern
-			.compile("([a-zA-Z_]+)(\\d+)_([a-zA-Z]+)");
+			.compile("([a-zA-Z_]+)(\\d+)_([a-zA-Z\\d]+)");
 
 	private static final String SB2_MACHINE = "sb2_machine";
 	private static final String SB2_VERSION = "sb2_version";
 
+	private MaemoSdkCommand maemoSdkCommand;
+	
+
+
+	private MaemoRootstrapCommand maemoRootstrapCommand;
+	
 	public Scratchbox2SDK(IMachine machine, String version,
 			IPreferenceProvider prefProvider) {
 		super(machine, version, "Scratchbox 2", SB2_MACHINE, SB2_VERSION,
 				"sb2_targets", 2);
 		this.prefProvider = prefProvider;
+		
+		createCommands();
 	}
 
+
+
+	private void createCommands() {
+		ICommandAbstractor commandAbstractor = null;
+		IProcessLauncherFactory launcherFactory = this.getMachineProcessLauncherFactory();
+		try{
+			commandAbstractor = getCommandAbstractor();
+		}catch(MicaException e){
+			//TODO: confirm that MicaException is needed.
+		}
+		if(commandAbstractor != null && launcherFactory != null){
+			maemoSdkCommand = new MaemoSdkCommand(commandAbstractor,launcherFactory);
+			maemoRootstrapCommand = new MaemoRootstrapCommand(commandAbstractor,launcherFactory);
+		}
+	}
+
+	public MaemoSdkCommand getMaemoSdkCommand() {
+		return maemoSdkCommand;
+	}
+	
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -64,51 +103,45 @@
 			Activator.getErrorLogger().logError("Could not refresh targets", e);
 			return;
 		}
+		
 		List<ISDKTarget> newTargets = new ArrayList<ISDKTarget>();
 		for (String target : targetNames) {
 			// ignore this one, left behind by errant rootstrap installations
 			if (target.equals("libtool_build"))
 				continue;
-			IPath config = getScratchbox2ConfigDirectory();
-			IPath sb2BasePath = config.append(target);
-			Scratchbox2SDKTarget sdkTarget = new Scratchbox2SDKTarget(this,
-					getPlatform(target), getArchitecture(target), target,
-					sb2BasePath);
-			newTargets.add(sdkTarget);
-
-			try {
-				IPath sb2RootstrapPath = getMaemoRootstrapPath(sdkTarget);
-				sdkTarget.setRootstrapPath(sb2RootstrapPath);
+			
+			IPath rootstrapLocation = null;
+			try{
+				rootstrapLocation = new Path(maemoRootstrapCommand.showLocation(target));
+			
+				Scratchbox2SDKTarget sdkTarget = new Scratchbox2SDKTarget(this,
+						getPlatform(target), getArchitecture(target), target,
+						rootstrapLocation);
+				
+				newTargets.add(sdkTarget);
 			} catch (MicaException e) {
-				Activator.getErrorLogger().logError(null, e);
+				Activator.getErrorLogger().logError("Invalid scratchbox 2 target, ignoring: " + target, e);
 			}
-
 		}
 		this.targets = newTargets;
 	}
 
+	
+	
+	public int installRootstrap(String rootstrap, IProgressMonitor monitor) throws MicaException {
+		maemoRootstrapCommand.install(rootstrap,monitor);
+		return 0;
+	}
+
+
+
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#getTargets()
 	 */
 	public List<String> getTargets() throws MicaException {
-		CacheUtils.getInstance().ensureCurrentMachine(SB_MACHINE, this.getMachine());
-
-		String[] targetsArray = (String[]) CacheUtils.getInstance()
-				.getCachedValue(SB_TARGETS);
-		if (targetsArray != null)
-			return Arrays.asList(targetsArray);
-
-		ListTargetsCommand listTargetsCommand = new ListTargetsCommand(
-				getCommandAbstractor());
-		List<String> targets = listTargetsCommand
-				.performCommand(new ArrayList<String>());
-
-		CacheUtils.getInstance().setCachedValue(SB_TARGETS,
-				(String[]) targets.toArray(new String[targets.size()]));
-
-		return targets;
+		return maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
 	}
 
 	/*
@@ -126,38 +159,13 @@
 	/*
 	 * (non-Javadoc)
 	 * 
-	 * @seeorg.maemo.esbox.maemosdk.sb2.core.IScratchbox2SDK#
-	 * getScratchbox2ConfigDirectory()
-	 */
-	public IPath getScratchbox2ConfigDirectory() {
-		String userName = prefProvider
-				.getPreferenceValue(CorePreferenceConstants.USER);
-		if (userName.length() == 0)
-			userName = "ubuntu";
-		return new Path("home").append(userName).append(".scratchbox2")
-				.makeAbsolute();
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
 	 * @see
 	 * org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#createTarget(java.lang
 	 * .String, java.lang.String, java.lang.String, java.lang.String)
 	 */
 	public boolean createTarget(String targetName, String compiler,
 			String devkits, String cputransp) throws MicaException {
-		List<String> params = new ArrayList<String>();
-		params.add(targetName);
-		params.add(compiler);
-		params.add(cputransp);
-
-		CreateTargetSb2Command createTargetCommand = new CreateTargetSb2Command(
-				this, getCommandAbstractor());
-
-		CacheUtils.getInstance().setCachedValue(SB_TARGETS, null);
-
-		return (Boolean) createTargetCommand.performCommand(params);
+		return maemoRootstrapCommand.newRootstrap(targetName);
 	}
 
 	/*
@@ -166,9 +174,7 @@
 	 * @see org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#getCompilers()
 	 */
 	public List<String> getCompilers() throws MicaException {
-		ListCompilersSb2Command listCompilersCommand = new ListCompilersSb2Command(
-				getCommandAbstractor());
-		return listCompilersCommand.performCommand(EMPTY_ARGS);
+		return maemoSdkCommand.listCompilers();
 	}
 
 	/*
@@ -188,10 +194,7 @@
 	 * @see org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#getCurrentTarget()
 	 */
 	public String getCurrentTarget() throws MicaException {
-		GetCurrentTargetSb2Command getCurrentTargetCommand = new GetCurrentTargetSb2Command(
-				getCommandAbstractor());
-		return (String) getCurrentTargetCommand
-				.performCommand(new ArrayList<String>());
+		return maemoSdkCommand.getDefaultRootstrap();
 	}
 
 	/*
@@ -202,18 +205,8 @@
 	 * .String)
 	 */
 	public boolean removeTarget(String targetName) throws MicaException {
-		List<String> params = new ArrayList<String>();
-		params.add(targetName);
-
-		RemoveTargetSb2Command removeTargetCommand;
-		removeTargetCommand = new RemoveTargetSb2Command(this,
-				getCommandAbstractor());
-		CacheUtils.getInstance().setCachedValue(SB_TARGETS, null);
-		CacheUtils.getInstance().setCachedValue(
-				SB2_TARGET_TO_PATH_MAPPINGS_MAP, null);
-		CacheUtils.getInstance().setCachedValue(SB2_TARGET_TO_ROOTSTRAP_MAP,
-				null);
-		return (Boolean) removeTargetCommand.performCommand(params);
+		maemoRootstrapCommand.remove(targetName);
+		return true;
 	}
 
 	/*
@@ -225,22 +218,21 @@
 		return ROOT_PATH;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @seeorg.maemo.esbox.internal.maemosdk.core.sdk.
-	 * IScratchboxSDKPlatformArchitectureProvider
-	 * #getArchitecture(java.lang.String)
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.scratchbox.core.sdk.IScratchboxSDKPlatformArchitectureProvider#getArchitecture(java.lang.String)
 	 */
 	public String getArchitecture(String target) {
-		// convention says this is the part of the target after the underscore
-		Matcher matcher = TARGET_PLATFORM_VERSION_ARCHITECTURE_PATTERN
-				.matcher(target);
-		if (matcher.matches()) {
-			return matcher.group(3).toUpperCase();
-		} else {
+		String arch;
+		try{
+			arch = maemoRootstrapCommand.showArchitecture(target);
+			if (arch.equalsIgnoreCase("I386"))
+				arch = IScratchboxSDKTarget.ARCHITECTURE_X86;
+			else if (arch.equalsIgnoreCase("armel"))
+				arch = IScratchboxSDKTarget.ARCHITECTURE_ARMEL;
+		}catch(MicaException e){
 			return IScratchboxSDKTarget.ARCHITECTURE_UNKNOWN;
 		}
+		return arch.toUpperCase();
 	}
 
 	public ISDKPlatform getPlatform(String target) {
@@ -275,9 +267,7 @@
 	 */
 	public synchronized List<String> getInstalledMaemoRootstraps()
 			throws MicaException {
-		ListInstalledMaemoRootstrapsSb2Command command = new ListInstalledMaemoRootstrapsSb2Command(
-				MachineUtils.getHostCommandAbstractor(this.getMachine()));
-		return command.performCommand(EMPTY_ARGS);
+		return maemoRootstrapCommand.list(MaemoRootstrapCommand.INSTALLED_TARGETS,null);
 	}
 
 	/*
@@ -287,11 +277,10 @@
 	 * org.maemo.mica.maemosdk.sb2.core.IScratchbox2SDK#getAvailableMaemoRootstraps
 	 * (org.maemo.mica.common.core.machine.IMachine)
 	 */
-	public List<MaemoRootstrap> getAvailableMaemoRootstraps(IMachine machine)
+	
+	public List<String> getAvailableMaemoRootstraps(IProgressMonitor monitor)
 			throws MicaException {
-		ListAvailableMaemoRootstrapsSb2Command command = new ListAvailableMaemoRootstrapsSb2Command(
-				MachineUtils.getHostCommandAbstractor(machine));
-		return command.performCommand(EMPTY_ARGS);
+		return maemoRootstrapCommand.list(MaemoRootstrapCommand.AVAILABLE_TARGETS,monitor);
 	}
 
 	/*
@@ -305,17 +294,7 @@
 	public boolean createRootstrapTarget(String targetName,
 			boolean useHostTools, boolean force, IProgressMonitor monitor)
 			throws MicaException {
-		List<String> params = new ArrayList<String>();
-		params.add(targetName);
-		params.add(Boolean.toString(useHostTools));
-		params.add(Boolean.toString(force));
-
-		CreateMaemoRootstrapSb2Command createTargetCommand = new CreateMaemoRootstrapSb2Command(
-				this, getCommandAbstractor(), monitor);
-
-		CacheUtils.getInstance().setCachedValue(SB_TARGETS, null);
-
-		return createTargetCommand.performCommand(params);
+		return maemoRootstrapCommand.newRootstrap(targetName);
 	}
 
 	/*
@@ -325,22 +304,9 @@
 	 * org.maemo.mica.maemosdk.sb2.core.IScratchbox2SDK#removeRootstrap(java
 	 * .lang.String, boolean, org.eclipse.core.runtime.IProgressMonitor)
 	 */
-	public boolean removeRootstrap(String targetName, boolean force,
+	public void removeRootstrap(String targetName, boolean force,
 			IProgressMonitor monitor) throws MicaException {
-		List<String> params = new ArrayList<String>();
-		params.add(targetName);
-		params.add(Boolean.toString(force));
-
-		RemoveMaemoRootstrapSb2Command removeTargetCommand = new RemoveMaemoRootstrapSb2Command(
-				getCommandAbstractor(), monitor);
-
-		CacheUtils.getInstance().setCachedValue(SB_TARGETS, null);
-		CacheUtils.getInstance().setCachedValue(SB2_TARGET_TO_ROOTSTRAP_MAP,
-				null);
-		CacheUtils.getInstance().setCachedValue(
-				SB2_TARGET_TO_PATH_MAPPINGS_MAP, null);
-
-		return removeTargetCommand.performCommand(params);
+		maemoRootstrapCommand.remove(targetName);
 	}
 
 	/**
@@ -452,57 +418,7 @@
 		return currentVersion;
 	}
 
-	/**
-	 * Get the path where a maemo rootstrap is installed
-	 * 
-	 * @param scratchbox2SDKTarget
-	 * @return path of rootstrap
-	 * @throws MicaException
-	 *             if not located
-	 */
-	private synchronized IPath getMaemoRootstrapPath(
-			Scratchbox2SDKTarget sdkTarget) throws MicaException {
-		// find cached value
-		CacheUtils.getInstance().ensureCurrentMachine(SB_MACHINE, sdkTarget.getMachine());
-		Map<String, String> targetToRootstrapMap = null;
-		targetToRootstrapMap = (Map<String, String>) CacheUtils.getInstance()
-				.getCachedValue(SB2_TARGET_TO_ROOTSTRAP_MAP);
-		if (targetToRootstrapMap != null) {
-			String rootstrap = targetToRootstrapMap.get(sdkTarget.getName());
-			if (rootstrap != null) {
-				return new Path(rootstrap);
-			}
-		}
 
-		// do the hard work
-		GetMaemoRootstrapLocationCommand command = new GetMaemoRootstrapLocationCommand(
-				getCommandAbstractor(), sdkTarget);
-		IPath rootstrapPath;
-
-		// be sure to record something in the cache for broken targets so
-		// we don't keep asking all the time
-		MicaException caughtException = null;
-		try {
-			rootstrapPath = (IPath) command.performCommand(EMPTY_ARGS);
-		} catch (MicaException e) {
-			rootstrapPath = Path.EMPTY;
-			caughtException = e;
-		}
-
-		// store cached value
-		if (targetToRootstrapMap == null)
-			targetToRootstrapMap = new HashMap<String, String>();
-		targetToRootstrapMap.put(sdkTarget.getName(), rootstrapPath
-				.toPortableString());
-		CacheUtils.getInstance().setCachedValue(SB2_TARGET_TO_ROOTSTRAP_MAP,
-				targetToRootstrapMap);
-
-		if (caughtException != null)
-			throw caughtException;
-
-		return rootstrapPath;
-	}
-
 	/**
 	 * Get a command abstractor that updates the PATH if sb2 tools are not on
 	 * the path.

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 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -13,9 +13,11 @@
 import org.eclipse.core.runtime.IPath;
 import org.maemo.esbox.internal.api.scratchbox.core.sdk.AbstractScratchboxSDKTarget;
 import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.internal.scratchbox.sb2.Activator;
 import org.maemo.esbox.internal.scratchbox.sb2.command.GetGdbQemuCommandPatternCommand;
 import org.maemo.esbox.internal.scratchbox.sb2.launcher.Scratchbox2ProcessLauncherFactory;
 import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
 import org.maemo.mica.common.core.CorePreferenceConstants;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.process.IProcessLauncherFactory;
@@ -25,25 +27,34 @@
 import java.util.List;
 
 /**
+ * @author eswartz
  * @author baranov
  * 
  */
-public class Scratchbox2SDKTarget extends AbstractScratchboxSDKTarget {
+public class Scratchbox2SDKTarget extends AbstractScratchboxSDKTarget implements IScratchbox2SDKTarget{
 	private IPath targetRoot;
 	private IPath rootstrapRoot;
-
+	private String session = null;
+	
 	public Scratchbox2SDKTarget(Scratchbox2SDK sdk, ISDKPlatform platform,
-			String architecture, String target, IPath targetRoot) {
+			String architecture, String target, IPath targetRoot) throws MicaException {
 		super(sdk, platform, architecture, target);
 		if (targetRoot == null)
 			throw new IllegalArgumentException();
 		this.targetRoot = targetRoot;
 		init(new Scratchbox2FileSystemMapping(this, targetRoot, target, sdk
-				.getPreferenceValue(CorePreferenceConstants.USER))
-		// ,new AptPackageManager(this)
-		);
+				.getPreferenceValue(CorePreferenceConstants.USER)));
 	}
 
+	
+	
+	public String getSession() throws MicaException {
+		if (session == null) {
+			session = Activator.getDefault().findOrCreateSession(this);
+		}
+		return session;
+	}
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -53,9 +64,19 @@
 	public IProcessLauncherFactory getProcessLauncherFactoryForInstall() {
 		// install mode needs to be a different mapping and also run as root
 		return new Scratchbox2ProcessLauncherFactory(this,
-				SB2PreferenceConstants.SB2_INSTALL_MAPPING_MODE, true);
+					SB2PreferenceConstants.SB2_INSTALL_MAPPING_MODE, true);
 	}
 
+	
+	
+	
+	public IProcessLauncherFactory getMaemoLauncherFactory() {
+		return new Scratchbox2ProcessLauncherFactory(this,
+					SB2PreferenceConstants.SB2_EMULATE_MAPPING_MODE, false);
+	}
+
+
+
 	/*
 	 * (non-Javadoc)
 	 * 
@@ -74,7 +95,7 @@
 	public IProcessLauncherFactory getProcessLauncherFactory() {
 		// default is build mode
 		return new Scratchbox2ProcessLauncherFactory(this,
-				SB2PreferenceConstants.SB2_MAPPING_MODE, false);
+					SB2PreferenceConstants.SB2_MAPPING_MODE, false);
 	}
 
 	/*

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.launcher;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.ui.console.*;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
+import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.internal.scratchbox.sb2.core.Scratchbox2SDKTarget;
+import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
+import org.maemo.mica.common.core.*;
+import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
+import org.maemo.mica.common.core.machine.IMachine;
+import org.maemo.mica.common.core.process.*;
+
+import java.util.*;
+
+/**
+ * @author baranov
+ *
+ */
+public class Sb2MaemoLauncherAdapter implements IMaemoLauncherAdapter {
+	private final IScratchbox2SDKTarget target;
+//	private MaemoSdkCommand command;
+	private MaemoCommand command;
+	
+	public Sb2MaemoLauncherAdapter(IScratchbox2SDKTarget adaptableObject) {
+		target = adaptableObject;
+		command =  new MaemoCommand((Scratchbox2SDKTarget) target);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#isMaemoRunning()
+	 */
+	public boolean isMaemoRunning() throws MicaException {
+		return false;//command.isUp(target.getName());
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#killMaemo()
+	 */
+	public void killMaemo() throws MicaException {
+		stopMaemo();
+	}
+	
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#restartMaemo()
+	 */
+	public void restartMaemo() throws MicaException {
+		startMaemo();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#startMaemo()
+	 */
+	public void startMaemo() throws MicaException {
+		if (isMaemoRunning())
+			throw new MicaException("Maemo is already running");
+		XLauncher.getInstance().startXIfNeeded(target);
+		if (XLauncher.getInstance().isXServerStarted(target)) {
+			command.startMaemoCommand();
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#stopMaemo()
+	 */
+	public void stopMaemo() throws MicaException {
+		//command.stopMaemo(target.getName());
+	}
+
+	static class MaemoCommand {
+
+		private Scratchbox2SDKTarget sdkTarget;
+
+		public MaemoCommand(Scratchbox2SDKTarget sdkTarget) {
+			this.sdkTarget = sdkTarget;
+		}
+
+		private void performCommand(List<String> params) throws MicaException {
+			String maemoCommand = sdkTarget.getPreferenceValue(
+					MaemoPreferenceConstants.MAEMO_COMMAND);
+			maemoCommand = this.replaceActions(maemoCommand,params.get(0));
+			
+			IProcessLauncherFactory processLauncherFactory = sdkTarget.getMaemoLauncherFactory();
+			
+			IEnvironmentModifierBlock envBlock = processLauncherFactory.defaultEnvironmentModifierBlock();
+			
+			defineEmulatorXDisplayVariable(sdkTarget.getMachine(), envBlock);
+			
+			IProcessLauncher processLauncher = ProcessLauncherCreator.createProcessLauncher(processLauncherFactory, null,
+					Collections.singletonList(maemoCommand), envBlock);
+
+			Process process = processLauncher.createProcess();
+
+			// spit the consumed output to the console
+			MessageConsole console = CoreConsoleManager.getInstance().getConsole(true,
+					sdkTarget, "Running Maemo command (" + params.get(0) + ")");
+
+			console.addPatternMatchListener(new IPatternMatchListener() {
+
+				public int getCompilerFlags() {
+					return 0;
+				}
+
+				public String getLineQualifier() {
+					return null;
+				}
+
+				public String getPattern() {
+					return "ERROR:.*";
+				}
+
+				public void connect(TextConsole console) {
+				}
+
+				public void disconnect() {
+				}
+
+				public void matchFound(PatternMatchEvent event) {
+					TextConsole console = (TextConsole) event.getSource();
+					String content;
+					try {
+						content = console.getDocument().get(event.getOffset(),
+								event.getLength());
+					} catch (BadLocationException e) {
+						content = console.getDocument().get();
+					}
+					ErrorLogger errorLogger = Activator.getErrorLogger();
+					errorLogger.logAndShowError("Error launching maemo",
+							new MicaException(content));
+				}
+
+			});
+
+			// emit everything else to the console
+			processLauncher.redirectToConsole(console);
+
+			// wait for it to finish
+			try {
+				process.waitFor();
+			} catch (InterruptedException e) {
+
+			}
+		}
+
+		public static void defineEmulatorXDisplayVariable(IMachine serverMachine, IEnvironmentModifierBlock envBlock) {
+			// local launches need DISPLAY that points back to the host machine
+			String display = CorePreferenceManager.getInstance().getRegisteredKeyValue(
+					MaemoPreferenceConstants.X_DISPLAY);
+			if (display != null && display.length() > 0) {
+				String host = serverMachine.getLocalMachineAddress();
+				if (host.equals(IMachine.LOCALHOST_ADDRESS)) {
+					host = "";
+				}
+				envBlock.define("DISPLAY", host + display);
+			}
+		}
+		
+		public void startMaemoCommand() throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_START_ACTION);
+
+			performCommand(params);
+		}
+
+		public void stopMaemoCommand() throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_STOP_ACTION);
+			performCommand(params);
+		}
+
+		public void restartMaemoCommand()
+				throws MicaException {
+			if (sdkTarget == null) {
+				throw new MicaException("No SDK target specified");
+			}
+
+			List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_RESTART_ACTION);
+			performCommand(params);
+		}
+
+		private List<String> getParamList(String key) {
+			List<String> params = new ArrayList<String>();
+			params.add(sdkTarget.getPreferenceValue(key));
+			return params;
+		}
+
+		private String replaceActions(String command, String action) {
+			return command.replaceAll("\\$\\{ACTIONS\\}", action);
+		}
+	}
+	
+}

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapterFactory.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapterFactory.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapterFactory.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.internal.scratchbox.sb2.launcher;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
+
+/**
+ * @author baranov
+ *
+ */
+public class Sb2MaemoLauncherAdapterFactory implements IAdapterFactory {
+
+	private static final Class<IMaemoLauncherAdapter> MAEMO_LAUNCHER_ADAPTER = IMaemoLauncherAdapter.class;
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		if (adapterType.equals(MAEMO_LAUNCHER_ADAPTER)) {
+			if (adaptableObject instanceof IScratchbox2SDKTarget) {
+				return new Sb2MaemoLauncherAdapter((IScratchbox2SDKTarget)adaptableObject);
+			}
+		}
+		return null;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+	 */
+	public Class[] getAdapterList() {
+		return new Class[]{MAEMO_LAUNCHER_ADAPTER};
+	}
+
+}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2EnvironmentProvider.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2EnvironmentProvider.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2EnvironmentProvider.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -14,6 +14,7 @@
 
 import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
 import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.process.*;
 import org.maemo.mica.common.core.process.ProcessLauncherUtils.Results;
@@ -29,12 +30,12 @@
 public class Scratchbox2EnvironmentProvider implements
 		IStandardEnvironmentProvider {
 	public static Map<ISDKTarget, Properties> cachedStdEnvMap = new HashMap<ISDKTarget, Properties>();
-	private final ISDKTarget sdkTarget;
+	private final IScratchbox2SDKTarget sdkTarget;
 
 	/**
 	 * @param sdkTarget
 	 */
-	public Scratchbox2EnvironmentProvider(ISDKTarget sdkTarget) {
+	public Scratchbox2EnvironmentProvider(IScratchbox2SDKTarget sdkTarget) {
 		this.sdkTarget = sdkTarget;
 	}
 

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -13,10 +13,11 @@
 
 import org.eclipse.core.runtime.IPath;
 import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
+import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
 import org.maemo.mica.common.core.process.*;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
 
 import java.util.List;
 
@@ -30,18 +31,18 @@
 public class Scratchbox2ProcessLauncher extends BaseSDKTargetProcessLauncher implements
 		IProcessLauncher {
 
-	private ISDKTarget sdkTarget;
+	private IScratchbox2SDKTarget sdkTarget;
 
-	public Scratchbox2ProcessLauncher(ISDKTarget sdkTarget,
+	public Scratchbox2ProcessLauncher(IScratchbox2SDKTarget sdkTarget,
 			IPath workingDirectory, List<String> cmdLine,
 			IEnvironmentModifierBlock environmentModifierBlock, String modeKey,
 			boolean runAsRoot) {
 		super(encodeArgumentArray(sdkTarget, cmdLine, modeKey),
 				environmentModifierBlock, workingDirectory,
 				sdkTarget);
-		if (runAsRoot) {
-			getLaunchCommandArguments().add(0, "sudo");
-		}
+//		if (runAsRoot) {
+//			getLaunchCommandArguments().add(0, "sudo");
+//		}
 		if (sdkTarget == null)
 			throw new IllegalArgumentException();
 		this.sdkTarget = sdkTarget;
@@ -58,7 +59,7 @@
 		return sdkTarget + " ";
 	}
 
-	private static List<String> encodeArgumentArray(ISDKTarget sdkTarget,
+	private static List<String> encodeArgumentArray(IScratchbox2SDKTarget sdkTarget,
 			List<String> cmdLine, String modeKey) {
 
 		// Encode the launch command by replacing the arguments
@@ -67,6 +68,13 @@
 		ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
 
 		substitutor.define("TARGET", sdkTarget.getName());
+		try {
+			substitutor.define("SESSION_FILE", sdkTarget.getSession());
+		} catch (MicaException e) {
+			Activator.getErrorLogger().logError("Cannot launch a scratchbox 2 program in a session", e);
+			substitutor.define("SESSION_FILE", ".dummy-session-see-error-log");
+		}
+		
 		substitutor.define("COMMAND", cmdLine.get(0));
 		substitutor.define("ARGS", CommandLineArguments.toCommandLine(cmdLine
 				.subList(1, cmdLine.size())));
@@ -80,6 +88,7 @@
 		}
 
 		String mapMode = sdkTarget.getPreferenceValue(modeKey);
+		//TODO: fix mapping mode
 		substitutor.define("MAPPING_MODE", mapMode);
 
 		// get the Scratchbox invocation pattern

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncherFactory.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncherFactory.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncherFactory.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -12,9 +12,9 @@
 package org.maemo.esbox.internal.scratchbox.sb2.launcher;
 
 import org.eclipse.core.runtime.IPath;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
 import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
 import org.maemo.mica.common.core.process.IProcessLauncher;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
 import org.maemo.mica.internal.api.common.core.BaseProcessLauncherFactory;
 
 import java.util.List;
@@ -26,7 +26,7 @@
 public class Scratchbox2ProcessLauncherFactory extends
 		BaseProcessLauncherFactory {
 
-	protected ISDKTarget sdkTarget;
+	protected IScratchbox2SDKTarget sdkTarget;
 	private String mappingModeKey;
 	private final boolean runAsRoot;
 
@@ -41,7 +41,7 @@
 	 * @param isBuildMode
 	 *            true: build mode, false: installation mode
 	 */
-	public Scratchbox2ProcessLauncherFactory(ISDKTarget sdkTarget,
+	public Scratchbox2ProcessLauncherFactory(IScratchbox2SDKTarget sdkTarget,
 			String mappingModeKey, boolean runAsRoot) {
 		super(new Scratchbox2EnvironmentProvider(sdkTarget), false);
 		if (sdkTarget == null)

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/adapters/MaemoScratchbox2SDKManageTargetAdapter.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -20,7 +20,6 @@
 import org.maemo.esbox.internal.scratchbox.sb2.Activator;
 import org.maemo.esbox.internal.scratchbox.sb2.ui.wizard.NewScratchbox2TargetWizard;
 import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
 import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.Policy;
 import org.maemo.mica.common.core.adapters.ISDKManageTargetAdapter;
@@ -98,10 +97,9 @@
 			try {
 				// see if a rootstrap -- possibly disconnected from the target --
 				// exists
-				List<MaemoRootstrap> rootstraps = sdk
-						.getAvailableMaemoRootstraps(selectedTarget.getMachine());
-				for (MaemoRootstrap rootstrap : rootstraps) {
-					if (rootstrap.getName().equals(selectedTarget.getName())) {
+				List<String> rootstraps = sdk.getAvailableMaemoRootstraps(null);
+				for (String rootstrap : rootstraps) {
+					if (rootstrap.equals(selectedTarget.getName())) {
 						rootstrapUsed_ = true;
 						break;
 					}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/preferences/Scratchbox2PreferencesPage.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/preferences/Scratchbox2PreferencesPage.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/preferences/Scratchbox2PreferencesPage.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -11,9 +11,7 @@
 
 package org.maemo.esbox.internal.scratchbox.sb2.ui.preferences;
 
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.jface.preference.RadioGroupFieldEditor;
-import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.jface.preference.*;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.GC;
 import org.eclipse.swt.layout.GridData;
@@ -44,6 +42,7 @@
 	private RadioGroupFieldEditor feSbox2LogLevel = null;
 
 	private StringFieldEditor feSbox2CommandLine;
+	private StringFieldEditor feSbox2EmulateMappingMode;
 
 	/**
 	 * The constructor
@@ -71,6 +70,10 @@
 				SB2PreferenceConstants.SB2_INSTALL_MAPPING_MODE.toString(),
 				"Install mapping mode:", getFieldEditorParent());
 
+		feSbox2EmulateMappingMode = new StringFieldEditor(
+				SB2PreferenceConstants.SB2_EMULATE_MAPPING_MODE.toString(),
+				"Emulate mapping mode:", getFieldEditorParent());
+		
 		feSbox2LogLevel = new RadioGroupFieldEditor(
 				SB2PreferenceConstants.SB2_LOG_LEVEL.toString(),
 				"Logging level:", 1, new String[][] { { "none", "" }, //$NON-NLS-1$
@@ -96,6 +99,7 @@
 
 		addField(feSbox2BuildMappingMode);
 		addField(feSbox2InstallMappingMode);
+		addField(feSbox2EmulateMappingMode);
 		addField(feSbox2LogLevel);
 		addField(feSbox2CommandLine);
 	}

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/MaemoRootstrapContentLabelProvider.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -12,19 +12,28 @@
 
 package org.maemo.esbox.internal.scratchbox.sb2.ui.wizard;
 
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.*;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.widgets.Display;
-import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
-import org.maemo.mica.common.core.MicaException;
-
+import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IColorProvider;
+import org.eclipse.jface.viewers.IFontProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
+import org.maemo.esbox.internal.scratchbox.sb2.Activator;
+import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
+import org.maemo.mica.common.core.ErrorLogger;
+import org.maemo.mica.common.core.MicaException;
+
 /**
  * This class provides installable rootstraps, descriptions, etc. from the
  * result of 'maemo-rootstrap'.
@@ -39,64 +48,40 @@
 	static final int COLUMN_ARCHITECTURE = 1;
 	static final int COLUMN_DESCRIPTION = 2;
 
-	public static Object NO_ROOTSTRAP = new Object();
-	public static Object LOADING_LABEL = new Object();
 
 	private boolean rootstrapsFetched;
-	// either MaemoRootstrap or NO_ROOTSTRAP
-	private List<Object> rootstraps;
-	private Thread rootstrapThread;
+	private List<String> rootstraps;
 	private final IScratchbox2SDK sdk;
+	private final IWizardContainer wizardContainer;
 
-	public MaemoRootstrapContentLabelProvider(IScratchbox2SDK sdk) {
+	public MaemoRootstrapContentLabelProvider(IScratchbox2SDK sdk,IWizardContainer wizardContainer) {
 		this.sdk = sdk;
+		this.wizardContainer = wizardContainer;
 	}
 
 	public Object[] getElements(Object inputElement) {
 		if (!rootstrapsFetched) {
-			rootstraps = new ArrayList<Object>();
-			rootstraps.add(NO_ROOTSTRAP);
-			rootstraps.add(LOADING_LABEL);
-
-			if (rootstrapThread == null) {
-				rootstrapThread = new Thread(new Runnable() {
-
-					public void run() {
+			rootstraps = new ArrayList<String>();
+			try {
+				wizardContainer.run(true, true,new IRunnableWithProgress(){
+					public void run(IProgressMonitor monitor)
+							throws InvocationTargetException, InterruptedException {
+						monitor.beginTask("Loading...",
+								IProgressMonitor.UNKNOWN);
 						try {
-							List<MaemoRootstrap> realRootstraps = sdk
-									.getAvailableMaemoRootstraps(sdk
-											.getMachine());
-							synchronized (rootstraps) {
-								rootstraps.remove(1);
-								rootstraps.addAll(realRootstraps);
-							}
-						} catch (final MicaException e) {
-							Display.getDefault().syncExec(new Runnable() {
-
-								public void run() {
-									MessageDialog.openError(null,
-											"Rootstrap lookup failed",
-											"Error fetching rootstraps: check proxy settings?\n\n"
-													+ e.getMessage());
-								}
-
-							});
+							rootstraps = 
+								sdk.getAvailableMaemoRootstraps(new SubProgressMonitor(monitor, 1));
+						}catch(MicaException e) {
+							throw new InvocationTargetException(e);
 						}
-						rootstrapsFetched = true;
-						rootstrapThread = null;
-						Display.getDefault().asyncExec(new Runnable() {
-
-							public void run() {
-								fireLabelProviderChanged(new LabelProviderChangedEvent(
-										MaemoRootstrapContentLabelProvider.this));
-							}
-
-						});
+						monitor.done();
 					}
-
 				});
-				rootstrapThread.start();
+			}catch(Exception e){
+				ErrorLogger errorLogger = Activator.getErrorLogger();
+				errorLogger.logAndShowError("Cannot get available rootstraps.", e);
 			}
+			rootstrapsFetched=true;
 		}
 		synchronized (rootstraps) {
 			return rootstraps.toArray();
@@ -130,28 +115,13 @@
 	public String getColumnText(Object element, int columnIndex) {
 		switch (columnIndex) {
 		case COLUMN_NAME:
-			if (element == NO_ROOTSTRAP) {
-				return "Custom target";
-			} else if (element == LOADING_LABEL) {
-				return "Loading...";
-			} else {
-				return ((MaemoRootstrap) element).getName();
-			}
+			return (String) element;
 
 		case COLUMN_ARCHITECTURE:
-			if (element == NO_ROOTSTRAP || element == LOADING_LABEL) {
-				return null;
-			}
-			return ((MaemoRootstrap) element).getArchitecture();
+			return sdk.getArchitecture((String)element);
 
 		case COLUMN_DESCRIPTION:
-			if (element == NO_ROOTSTRAP) {
-				return "User-defined name and compiler, manually installed rootstrap";
-			} else if (element == LOADING_LABEL) {
-				return null;
-			} else {
-				return ((MaemoRootstrap) element).getDescription();
-			}
+			return "";
 		}
 		return null;
 	}
@@ -161,18 +131,11 @@
 	}
 
 	public Color getForeground(Object element) {
-		if (element == LOADING_LABEL)
-			return Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
-		else
-			return null;
+		return null;
 	}
 
 	public Font getFont(Object element) {
-		if (element == LOADING_LABEL)
-			return JFaceResources.getFontRegistry().getItalic(
-					JFaceResources.DIALOG_FONT);
-		else
-			return null;
+		return null;
 	}
 
 }

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/NewScratchbox2TargetWizard.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -13,33 +13,26 @@
  *******************************************************************************/
 package org.maemo.esbox.internal.scratchbox.sb2.ui.wizard;
 
+import java.lang.reflect.InvocationTargetException;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.wizard.*;
-import org.eclipse.swt.widgets.TableItem;
-import org.eclipse.ui.*;
-import org.maemo.esbox.internal.api.scratchbox.ui.wizards.*;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.maemo.esbox.internal.api.scratchbox.ui.wizards.TargetWizardPageFactory;
 import org.maemo.esbox.internal.scratchbox.sb2.Activator;
-import org.maemo.esbox.scratchbox.core.scratchbox.ScratchboxException;
 import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDK;
-import org.maemo.esbox.scratchbox.sb2.sdk.MaemoRootstrap;
-import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.ErrorLogger;
+import org.maemo.mica.common.core.MicaException;
 import org.maemo.mica.common.core.sdk.ISDKTarget;
-import org.maemo.mica.internal.api.maemosdk.ui.wizards.sbrsh.SbrshConfigurationNFSServer;
-import org.maemo.mica.internal.api.maemosdk.ui.wizards.sbrsh.SbrshConfigurationTargetDevice;
 
-import java.lang.reflect.InvocationTargetException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.text.MessageFormat;
-import java.util.List;
-
 /**
  * The target wizard provides a easy way to create a target for Scratchbox. As
  * Scratchbox target configuration, the user can configure your target.
@@ -47,11 +40,6 @@
  */
 public class NewScratchbox2TargetWizard extends Wizard implements INewWizard {
 
-	protected WizardPage targetNamePage;
-	protected WizardPage compilerNamePage;
-	protected WizardPage cpuMethodName;
-	protected WizardPage sbrshConfigTargetDevice;
-	protected WizardPage sbrshConfigNFSServer;
 	protected IProject generatedProject;
 
 	private IScratchbox2SDK sdk;
@@ -88,21 +76,6 @@
 		if (sdk != null) {
 			maemoRootstrapPage = new TargetWizardRootstrapSb2Page(sdk);
 			addPage(maemoRootstrapPage);
-			targetNamePage = TargetWizardPageFactory.getInstance()
-					.createNamePage(sdk);
-			addPage(targetNamePage);
-			compilerNamePage = TargetWizardPageFactory.getInstance()
-					.createCompilerPage(sdk);
-			addPage(compilerNamePage);
-			cpuMethodName = TargetWizardPageFactory.getInstance()
-					.createCPUMethod(sdk);
-			addPage(cpuMethodName);
-			sbrshConfigTargetDevice = TargetWizardPageFactory.getInstance()
-					.createSbrshConfigDeviceTargetPage();
-			addPage(sbrshConfigTargetDevice);
-			sbrshConfigNFSServer = TargetWizardPageFactory.getInstance()
-					.createSbrshConfigNFSSServer();
-			addPage(sbrshConfigNFSServer);
 		} else {
 			addPage(TargetWizardPageFactory.getInstance()
 					.createBadInstallationPage());
@@ -110,150 +83,25 @@
 	}
 
 	public boolean canFinish() {
-		if (sdk == null)
-			return false;
-
-		boolean nonCustomRootstrap = true;
-		if (maemoRootstrapPage != null)
-			nonCustomRootstrap = ((TargetWizardRootstrapSb2Page) maemoRootstrapPage)
-					.canFinish();
-		boolean cpuPage = ((TargetWizardCPUMethod) cpuMethodName).canFinish();
-		boolean configDevice = ((SbrshConfigurationTargetDevice) sbrshConfigTargetDevice)
-				.canFinish();
-		boolean NFSServer = ((SbrshConfigurationNFSServer) sbrshConfigNFSServer)
-				.canFinish();
-		boolean sbrshConfigAccepted = ((TargetWizardCPUMethod) cpuMethodName)
-				.getSbrshConfigure();
-
-		if (!sbrshConfigAccepted && (nonCustomRootstrap || cpuPage))
-			return true;
-		if (sbrshConfigAccepted && NFSServer && configDevice)
-			return true;
-
-		return false;
+		return true;
 	}
 
-	@Override
-	public IWizardPage getNextPage(IWizardPage page) {
-		if (page == maemoRootstrapPage) {
-			boolean nonCustomRootstrap = ((TargetWizardRootstrapSb2Page) maemoRootstrapPage)
-					.canFinish();
-			if (nonCustomRootstrap)
-				return null;
-			else
-				return super.getNextPage(page);
-		}
-		if (page == cpuMethodName) {
-			boolean sbrshConfigAccepted = ((TargetWizardCPUMethod) cpuMethodName)
-					.getSbrshConfigure();
-			if (!sbrshConfigAccepted) // user does not want to configure sbrsh
-				return null;
-			else
-				// user wants to configure sbrsh
-				return super.getNextPage(page);
-		}
-		return super.getNextPage(page);
-	}
-
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see org.eclipse.jface.wizard.IWizard#performFinish()
 	 */
 	public boolean performFinish() {
-		if (getRootstrap() != null) {
-			if (!setupTargetFromRootstrap())
-				return false;
-		} else {
-			if (!setupTargetFromScratch())
-				return false;
-		}
-
-		boolean sbrshConfigSelected = ((TargetWizardCPUMethod) cpuMethodName)
-				.getSbrshConfigure();
-		if (sbrshConfigSelected) {
-			configureSbrshService();
-			showsDialog();
-		}
-
-		return true;
-	}
-
-	private boolean setupTargetFromScratch() {
-		String targetName;
-		// in this mode, construct a target from the user's settings
-		targetName = getTargetNameSelected();
-		String compilerName = getCompilerNameSelected();
-		String cpuMethod = getCputranspSelected();
+		final String rootstrap = getRootstrap();
 		try {
-			sdk.createTarget(targetName, compilerName, null, cpuMethod);
-			createdTarget = sdk.findSDKTarget(targetName);
-			return true;
-		} catch (MicaException e) {
-			ErrorLogger errorLogger = Activator.getErrorLogger();
-			errorLogger.logAndShowError("Cannot get create target "
-					+ targetName, e);
-			return false;
-		}
-	}
-
-	private boolean setupTargetFromRootstrap() {
-		String targetName;
-		// in this mode, make a predefined target from a maemo rootstrap
-		targetName = getRootstrap().getName();
-		boolean create = true;
-
-		if (true) {
-			// see if the rootstrap (not necessarily the target) already exists,
-			// and ask user, in case this will overwrite their customizations
-			try {
-				List<String> installedRootstraps = sdk
-						.getInstalledMaemoRootstraps();
-				if (installedRootstraps.contains(targetName)) {
-					create = MessageDialog
-							.openConfirm(
-									getShell(),
-									"Reinstall rootstrap?",
-									MessageFormat
-											.format(
-													"The rootstrap ''{0}'' appears to be already installed, though it may be disconnected from scratchbox.\n\n"
-															+ "At this time, we can't recreate a target for this rootstrap, but "
-															+ "you could do it manually with 'sb2-init'.\n\n"
-															+ "Do you want to overwrite the rootstrap?",
-													targetName));
-				}
-			} catch (MicaException e) {
-				ErrorLogger errorLogger = Activator.getErrorLogger();
-				errorLogger.logError("Cannot detect installed rootstraps", e);
-			}
-		}
-
-		if (create) {
-			try {
-				createRootstrap(targetName, useHostTools());
-			} catch (MicaException e) {
-				ErrorLogger errorLogger = Activator.getErrorLogger();
-				errorLogger.logAndShowError(
-						"Cannot get create rootstrap target " + targetName, e);
-				return false;
-			}
-		}
-		return true;
-	}
-
-	private void createRootstrap(final String targetName,
-			final boolean useHostTools) throws ScratchboxException {
-		try {
 			getContainer().run(true, true, new IRunnableWithProgress() {
 
 				public void run(IProgressMonitor monitor)
 						throws InvocationTargetException, InterruptedException {
-					monitor.beginTask("Creating rootstrap",
+					monitor.beginTask("Installing rootstrap...",
 							IProgressMonitor.UNKNOWN);
 					try {
-						sdk.createRootstrapTarget(targetName, useHostTools,
-								true, new SubProgressMonitor(monitor, 1));
-						createdTarget = sdk.findSDKTarget(targetName);
+						sdk.installRootstrap(rootstrap,new SubProgressMonitor(monitor, 1));
 					} catch (MicaException e) {
 						throw new InvocationTargetException(e);
 					}
@@ -261,127 +109,21 @@
 				}
 
 			});
-		} catch (InvocationTargetException e) {
-			if (e.getCause() instanceof ScratchboxException)
-				throw (ScratchboxException) e.getCause();
-			else
-				throw new ScratchboxException(e);
-		} catch (InterruptedException e) {
-			throw new ScratchboxException(e);
+		} catch (Exception e) {
+			ErrorLogger errorLogger = Activator.getErrorLogger();
+			errorLogger.logAndShowError("Cannot install rootstrap "
+					+ rootstrap, e);
 		}
+		return true;
 	}
 
-	private MaemoRootstrap getRootstrap() {
+	private String getRootstrap() {
 		return ((TargetWizardRootstrapSb2Page) maemoRootstrapPage)
 				.getRootstrap();
 	}
 
-	private boolean useHostTools() {
-		return ((TargetWizardRootstrapSb2Page) maemoRootstrapPage)
-				.useHostTools();
-	}
 
 	/**
-	 * Return the name of the target to be created.
-	 * 
-	 * @return the name of the target to be created.
-	 */
-	private String getTargetNameSelected() {
-		return ((TargetWizardNamePage) targetNamePage).getTextControl()
-				.getText();
-	}
-
-	/**
-	 * Return the compiler name of the target to be created.
-	 * 
-	 * @return the compiler name of the target to be created.
-	 */
-	private String getCompilerNameSelected() {
-		TableItem item = ((TargetWizardCompilerPage) compilerNamePage)
-				.getTableControl().getSelection()[0];
-		return item.getText();
-	}
-
-	/**
-	 * Return the cputransp name of the target to be created.
-	 * 
-	 * @return the cputransp name of the target to be created.
-	 */
-	private String getCputranspSelected() {
-		TableItem item = ((TargetWizardCPUMethod) cpuMethodName).getTable()
-				.getSelection()[0];
-		return item.getText();
-	}
-
-	/**
-	 * Configure sbrsh service.
-	 */
-	private void configureSbrshService() {
-		String targetName = getTargetNameSelected();
-		String deviceTargetAddr = ((SbrshConfigurationTargetDevice) sbrshConfigTargetDevice)
-				.getTargetDeviceAddr();
-		String nfsHostname = ((SbrshConfigurationNFSServer) sbrshConfigNFSServer)
-				.getNFSHostname();
-
-		try {
-			sdk.configureSbrsh(targetName, deviceTargetAddr, nfsHostname);
-		} catch (MicaException e) {
-			ErrorLogger errorLogger = Activator.getErrorLogger();
-			errorLogger.logAndShowError("Cannot configure sbrsh", e);
-		}
-	}
-
-	/**
-	 * Add user at access list of the sbrshd running at the target device.
-	 */
-	private void addUser() {
-		String deviceTargetIP = ((SbrshConfigurationTargetDevice) sbrshConfigTargetDevice)
-				.getTargetDeviceIP();
-		String username = System.getProperty("user.name");
-		ErrorLogger errorLogger = Activator.getErrorLogger();
-
-		try {
-			String localAddr = getLocalIP();
-			sdk.addSbrshAccessList(deviceTargetIP, username, localAddr);
-		} catch (MicaException e) {
-			errorLogger
-					.logAndShowError(
-							"Cannot add user to the access list of sbrshd at the target device",
-							e);
-		} catch (UnknownHostException e) {
-			errorLogger.logAndShowError("Cannot get local IP address", e);
-		}
-	}
-
-	/**
-	 * Shows the dialog to ask the user if s/he wants to add his/herself to the
-	 * acess list of the sbrshd.
-	 */
-	private void showsDialog() {
-		String deviceTargetAddr = ((SbrshConfigurationTargetDevice) sbrshConfigTargetDevice)
-				.getTargetDeviceIP();
-		String text = "Do you want to add yourself to the access list of the sbrshd running on target device? \n";
-		text += "(This requires that "
-				+ deviceTargetAddr
-				+ " has ssh daemon running and sbrshd already installed, and that you have root access).";
-		boolean userAddedAtAccessList = MessageDialog.openQuestion(getShell(),
-				"Scratchbox Configuration", text);
-		if (userAddedAtAccessList) {
-			addUser();
-		}
-	}
-
-	/**
-	 * Get the local IP address.
-	 * 
-	 * @return the local IP address.
-	 * @throws UnknownHostException
-	 */
-	private String getLocalIP() throws UnknownHostException {
-		return InetAddress.getLocalHost().getHostAddress();
-	}
-
-	/**
 	 * We will accept the selection in the workbench to see if we can initialize
 	 * from it.
 	 * 

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/ui/wizard/TargetWizardRootstrapSb2Page.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -42,7 +42,7 @@
 	protected Object selection;
 	private MaemoRootstrapContentLabelProvider provider;
 	private Button showExistingTargets;
-	private Button useHostTools;
+//	private Button useHostTools;
 
 	/**
 	 * Constructs a NewTargetWizardNamePage.
@@ -55,7 +55,7 @@
 					"This page only expects a scratchbox 2 SDK");
 		}
 		setTitle("Select maemo SDK+ Rootstrap");
-		setDescription("Select the maemo rootstrap to install, or manually configure a target.");
+		setDescription("Select the maemo rootstrap to install.");
 		setPageComplete(false);
 	}
 
@@ -84,15 +84,8 @@
 		showExistingTargets
 				.setToolTipText("If checked, rootstraps with names matching existing targets will be shown.  This is the only way to reinstall a target.");
 
-		useHostTools = new Button(composite, SWT.CHECK);
-		useHostTools.setText("Use host's build tools");
-		useHostTools.setSelection(false);
-		useHostTools
-				.setToolTipText("If checked, configure the rootstrap to use the host versions of autotools, bison, flex, docbook, etc. instead of standard versions (c.f. devkits in scratchbox 1).  We recommend leaving this unchecked and invoking maemo-tools to install official build tools.");
 
-		// / setup rootstrap target tree
-
-		provider = new MaemoRootstrapContentLabelProvider(sdk);
+		provider = new MaemoRootstrapContentLabelProvider(sdk,this.getContainer());
 		rootstrapTargetViewer.setContentProvider(provider);
 		rootstrapTargetViewer.setLabelProvider(provider);
 
@@ -120,7 +113,7 @@
 
 		TreeColumn nameColumn = new TreeColumn(rootstrapTargetViewer.getTree(),
 				SWT.LEFT);
-		nameColumn.setText("Target Name");
+		nameColumn.setText("Rootstrap Name");
 		nameColumn.setWidth(200);
 		nameColumn.setResizable(true);
 
@@ -159,9 +152,9 @@
 						@Override
 						public boolean select(Viewer viewer,
 								Object parentElement, Object element) {
-							if (element instanceof MaemoRootstrap) {
-								MaemoRootstrap rootstrap = (MaemoRootstrap) element;
-								if (sdk.findSDKTarget(rootstrap.getName()) != null)
+							if (element instanceof String) {
+								String rootstrap = (String) element;
+								if (sdk.findSDKTarget(rootstrap) != null)
 									return false;
 							}
 							return true;
@@ -184,8 +177,7 @@
 	 * #perfomeAction()
 	 */
 	public boolean validatePage() {
-		setPageComplete(selection instanceof MaemoRootstrap
-				|| selection == MaemoRootstrapContentLabelProvider.NO_ROOTSTRAP);
+		setPageComplete(selection != null);
 		return true;
 	}
 
@@ -193,18 +185,7 @@
 		return selection instanceof MaemoRootstrap;
 	}
 
-	public MaemoRootstrap getRootstrap() {
-		if (!(selection instanceof MaemoRootstrap))
-			return null;
-		return (MaemoRootstrap) selection;
+	public String getRootstrap() {
+			return (String) selection;
 	}
-
-	public boolean isShowingExisting() {
-		return showExistingTargets.getSelection();
-	}
-
-	public boolean useHostTools() {
-		return useHostTools.getSelection();
-	}
-
 }
\ No newline at end of file

Modified: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java	2008-11-18 15:53:14 UTC (rev 951)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDK.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -10,14 +10,12 @@
  *******************************************************************************/
 package org.maemo.esbox.scratchbox.sb2.sdk;
 
-import java.util.List;
-
-import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK;
 import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.machine.IMachine;
 
+import java.util.List;
+
 public interface IScratchbox2SDK extends IScratchboxSDK {
 
 	/**
@@ -28,10 +26,10 @@
 	/** Map<String,String> of sb2 target names to rootstrap paths */
 	static final String SB2_TARGET_TO_ROOTSTRAP_MAP = "sb2_target_to_rootstrap_map";
 
-	/**
-	 * @return
-	 */
-	public IPath getScratchbox2ConfigDirectory();
+//	/**
+//	 * @return
+//	 */
+//	public IPath getScratchbox2ConfigDirectory();
 
 	/**
 	 * Create a new rootstrap target for Scratchbox 2. The target is named after
@@ -68,7 +66,7 @@
 	 * @throws MicaException
 	 *             if some problem related to Scratchbox communication occurs.
 	 */
-	public boolean removeRootstrap(String targetName, boolean force,
+	public void removeRootstrap(String targetName, boolean force,
 			IProgressMonitor monitor) throws MicaException;
 
 	/**
@@ -85,11 +83,22 @@
 	/**
 	 * Get the MaemoRootstrap items available for installation. This includes
 	 * any that might already be defined.
+	 * @param mnitor 
 	 * 
 	 * @return List, never null
 	 * @throws MicaException
 	 */
-	public List<MaemoRootstrap> getAvailableMaemoRootstraps(IMachine machine)
+	public List<String> getAvailableMaemoRootstraps(IProgressMonitor mnitor)
 			throws MicaException;
 
+	/**
+	 * Install rootstrap, return 0 if success
+	 * 
+	 * @param rootstrap - nickname of the rootstrap
+	 * @param monitor 
+	 *
+	 * @return 0 - if success
+	 */
+	public int installRootstrap(String rootstrap, IProgressMonitor monitor) throws MicaException;
+
 }

Added: branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java
===================================================================
--- branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java	                        (rev 0)
+++ branches/work_Petr/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java	2008-11-18 21:48:25 UTC (rev 952)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Nokia Corporation
+ * 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:
+ *    Petr Baranov (Nokia) - initial API and implementation
+ *******************************************************************************/
+package org.maemo.esbox.scratchbox.sb2.sdk;
+
+import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
+import org.maemo.mica.common.core.MicaException;
+
+/**
+ * @author baranov
+ *
+ */
+public interface IScratchbox2SDKTarget extends IScratchboxSDKTarget {
+	/**
+	 * Check target session file. If it does not exist, create one using sb2 -S <PATH> command.
+	 * @return - absolute path of the session file
+	 */
+	String getSession() throws MicaException;
+
+}



More information about the Esbox-commits mailing list