[Esbox-commits] r947 - in branches/sdkPlusSupport: org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core 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/scratchbox/sb2/sdk
baranov at garage.maemo.org
baranov at garage.maemo.org
Tue Nov 18 13:36:44 EET 2008
Author: baranov
Date: 2008-11-18 13:36:44 +0200 (Tue, 18 Nov 2008)
New Revision: 947
Modified:
branches/sdkPlusSupport/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDKTarget.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java
branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java
Log:
sb2 to run maemo, build and execude applications
Modified: branches/sdkPlusSupport/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -419,7 +419,7 @@
IPath wdInScratchbox = sdkTarget.convertHostToTargetPath(wd);
IProcessLauncherFactory launcherFactory = sdkTarget
- .getProcessLauncherFactory();
+ .getMaemoLauncherFactory();
final IProcessLauncher processLauncher = ProcessLauncherCreator
.createProcessLauncher(launcherFactory, wdInScratchbox,
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDKTarget.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDKTarget.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDKTarget.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -70,6 +70,12 @@
return new Scratchbox1ProcessLauncherFactory(this, false);
}
+
+
+ public IProcessLauncherFactory getMaemoLauncherFactory() {
+ return getProcessLauncherFactory();
+ }
+
/*
* (non-Javadoc)
*
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/conf/sb2_prefs.xml 2008-11-18 11:36:44 UTC (rev 947)
@@ -12,12 +12,11 @@
<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>
- <entry key="SB2_EXEC_COMMAND">maemo-sdk enter runtime ${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/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/api/scratchbox/sb2/core/SB2PreferenceConstants.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -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/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/Activator.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -1,10 +1,18 @@
package org.maemo.esbox.internal.scratchbox.sb2;
+import java.io.File;
import java.io.FileInputStream;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
+import javax.net.ssl.HostnameVerifier;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Plugin;
@@ -14,7 +22,12 @@
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.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
import org.maemo.mica.common.core.ErrorLogger;
+import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.common.core.process.HostProcessLauncherFactory;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils;
import org.osgi.framework.BundleContext;
/**
@@ -30,6 +43,9 @@
private IPreferenceStore preferenceStore;
+ //configuration folder
+ private static File configurationDir = null;
+
/**
* The constructor
*/
@@ -54,10 +70,29 @@
* org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
+ removeSessions();
plugin = null;
super.stop(context);
}
+ private void removeSessions() {
+ File confDir = getConfigurationDir();
+ String[] activeSessions = confDir.list(new FilenameFilter(){
+ public boolean accept(File dir, String name) {
+ return name.endsWith(IScratchbox2SDKTarget.SESSION_SUFFIX);
+ }
+ });
+// for(String activeSession : activeSessions){
+// try{
+// //TODO: use correct IProcessLauncherFactory
+// AbstractSb2Command.runProcess(/*what to use here?*/,
+// "sb2","-D",activeSession);
+// }catch(MicaException e){
+// Activator.getErrorLogger().showError(e.getMessage(), e.getCause());
+// }
+// }
+ }
+
/**
* Returns the shared instance
*
@@ -154,4 +189,16 @@
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;
+ }
}
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/command/AbstractSb2Command.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -57,8 +57,7 @@
}
protected Results runProcess(String...args) throws MicaException{
- List<String> cli = Arrays.asList(args);
- return ProcessLauncherUtils.launchAndReadStandardStreams(processLauncherFactory, cli);
+ return runProcess(this.processLauncherFactory,args);
}
protected Results runProcess( IProgressMonitor monitor,String...args) throws MicaException{
@@ -66,4 +65,16 @@
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));
+ }
+
}
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -12,7 +12,6 @@
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDKTarget.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -10,9 +10,15 @@
*******************************************************************************/
package org.maemo.esbox.internal.scratchbox.sb2.core;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
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.AbstractSb2Command;
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;
@@ -22,6 +28,7 @@
import org.maemo.mica.common.core.process.IProcessLauncherFactory;
import org.maemo.mica.common.core.sdk.ISDKPlatform;
+import java.io.File;
import java.util.ArrayList;
import java.util.List;
@@ -32,6 +39,11 @@
public class Scratchbox2SDKTarget extends AbstractScratchboxSDKTarget implements IScratchbox2SDKTarget{
private IPath targetRoot;
private IPath rootstrapRoot;
+ private String session = null;
+
+ private IProcessLauncherFactory processLauncherFactory = null;
+ private IProcessLauncherFactory maemoProcessLauncherFactory = null;
+ private IProcessLauncherFactory installProcessLauncherFactory = null;
public Scratchbox2SDKTarget(Scratchbox2SDK sdk, ISDKPlatform platform,
String architecture, String target, IPath targetRoot) {
@@ -40,11 +52,28 @@
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() {
+ if(session==null){
+ //TODO: better way to define configuration dir
+ String sessionFile = Activator.getConfigurationDir().getAbsolutePath()+File.separator+this.getName()+SESSION_SUFFIX;
+ try{
+ AbstractSb2Command.runProcess(this.getSDK().getMachineProcessLauncherFactory(),
+ "sb2","-m","emulate","-m","devel","-S",sessionFile,"\'exit\'");
+ session = sessionFile;
+ }catch(MicaException e){
+ Activator.getErrorLogger().showError(e.getMessage(), e.getCause());
+ }
+ }
+ return session;
+ }
+
+
+
/*
* (non-Javadoc)
*
@@ -53,10 +82,24 @@
*/
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);
+ if(installProcessLauncherFactory == null)
+ installProcessLauncherFactory = new Scratchbox2ProcessLauncherFactory(this,
+ SB2PreferenceConstants.SB2_INSTALL_MAPPING_MODE, true);
+ return installProcessLauncherFactory;
}
+
+
+
+ public IProcessLauncherFactory getMaemoLauncherFactory() {
+ if(maemoProcessLauncherFactory==null)
+ maemoProcessLauncherFactory = new Scratchbox2ProcessLauncherFactory(this,
+ SB2PreferenceConstants.SB2_EMULATE_MAPPING_MODE, false);
+ return maemoProcessLauncherFactory;
+ }
+
+
+
/*
* (non-Javadoc)
*
@@ -74,8 +117,10 @@
*/
public IProcessLauncherFactory getProcessLauncherFactory() {
// default is build mode
- return new Scratchbox2ProcessLauncherFactory(this,
- SB2PreferenceConstants.SB2_MAPPING_MODE, false);
+ if(processLauncherFactory==null)
+ processLauncherFactory = new Scratchbox2ProcessLauncherFactory(this,
+ SB2PreferenceConstants.SB2_MAPPING_MODE, false);
+ return processLauncherFactory;
}
/*
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Sb2MaemoLauncherAdapter.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -10,11 +10,32 @@
*******************************************************************************/
package org.maemo.esbox.internal.scratchbox.sb2.launcher;
+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.sb2.Activator;
import org.maemo.esbox.internal.scratchbox.sb2.command.MaemoSdkCommand;
import org.maemo.esbox.internal.scratchbox.sb2.core.Scratchbox2SDK;
+import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
+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.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
@@ -22,18 +43,19 @@
*/
public class Sb2MaemoLauncherAdapter implements IMaemoLauncherAdapter {
private final IScratchbox2SDKTarget target;
- private MaemoSdkCommand command;
+// private MaemoSdkCommand command;
+ private MaemoCommand command;
public Sb2MaemoLauncherAdapter(IScratchbox2SDKTarget adaptableObject) {
target = adaptableObject;
- command = ((Scratchbox2SDK)target.getSDK()).getMaemoSdkCommand();
+ command = new MaemoCommand(target);
}
/* (non-Javadoc)
* @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#isMaemoRunning()
*/
public boolean isMaemoRunning() throws MicaException {
- return command.isUp(target.getName());
+ return false;//command.isUp(target.getName());
}
/* (non-Javadoc)
@@ -54,14 +76,146 @@
* @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#startMaemo()
*/
public void startMaemo() throws MicaException {
- command.startMaemo(target.getName());
+ 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());
+ //command.stopMaemo(target.getName());
}
+
+ 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.getMaemoLauncherFactory();
+
+ 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);
+ }
+ }
}
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/launcher/Scratchbox2ProcessLauncher.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -12,7 +12,6 @@
package org.maemo.esbox.internal.scratchbox.sb2.launcher;
import org.eclipse.core.runtime.IPath;
-import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
import org.maemo.esbox.internal.api.scratchbox.sb2.core.SB2PreferenceConstants;
import org.maemo.esbox.scratchbox.sb2.sdk.IScratchbox2SDKTarget;
import org.maemo.mica.common.core.MicaException;
@@ -20,8 +19,6 @@
import org.maemo.mica.common.core.process.*;
import org.maemo.mica.common.core.sdk.ISDKTarget;
-import java.io.File;
-import java.util.Arrays;
import java.util.List;
/**
@@ -43,9 +40,9 @@
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;
@@ -62,27 +59,19 @@
return sdkTarget + " ";
}
- @Override
- protected void setupForLaunch() throws MicaException {
- super.setupForLaunch();
- }
-
- private static List<String> encodeArgumentArray(ISDKTarget sdkTarget,
+ private static List<String> encodeArgumentArray(IScratchbox2SDKTarget sdkTarget,
List<String> cmdLine, String modeKey) {
-
- //workaround!!!!
- String sbPath = copyExecutableToTmp(sdkTarget.getSDK().getMachineProcessLauncherFactory(),CommandLineArguments.toCommandLine(cmdLine
- .subList(1, cmdLine.size())));
- //end of workaround!!!
-
+
// Encode the launch command by replacing the arguments
// representing template arguments with the actual values.
//
ShellTemplateSubstitutor substitutor = new ShellTemplateSubstitutor();
substitutor.define("TARGET", sdkTarget.getName());
+ substitutor.define("SESSION_FILE", sdkTarget.getSession());
substitutor.define("COMMAND", cmdLine.get(0));
- substitutor.define("ARGS", sbPath);
+ substitutor.define("ARGS", CommandLineArguments.toCommandLine(cmdLine
+ .subList(1, cmdLine.size())));
String level = sdkTarget
.getPreferenceValue(SB2PreferenceConstants.SB2_LOG_LEVEL);
@@ -93,6 +82,7 @@
}
String mapMode = sdkTarget.getPreferenceValue(modeKey);
+ //TODO: fix mapping mode
substitutor.define("MAPPING_MODE", mapMode);
// get the Scratchbox invocation pattern
@@ -101,19 +91,16 @@
// replace variables
commandPattern = substitutor.substitute(commandPattern);
-
+
List<String> commandArgs = CommandLineArguments
.createFromCommandLine(commandPattern);
return commandArgs;
}
- private static String copyExecutableToTmp(IProcessLauncherFactory factory,String hostPath) {
- String sbPath = "/tmp"+hostPath.substring(hostPath.lastIndexOf(File.separator));
- try{
- ProcessLauncherUtils.launchAndReadStandardStreams(factory, Arrays.asList("cp",hostPath,sbPath));
- }catch(MicaException e){
- }
- return sbPath;
+ @Override
+ protected void setupForLaunch() throws MicaException {
+ // nothing
+ super.setupForLaunch();
}
/*
@@ -124,8 +111,8 @@
@Override
protected Process doCreateProcess() throws Exception {
return sdkTarget.getSDK().getMachine().createProcess(
- getLaunchCurrentWorkingDirectory(),
- getLaunchCommandArguments(),
- getLaunchEnvironmentModifierBlock(), isUsePTY());
+ getLaunchCurrentWorkingDirectory(),
+ getLaunchCommandArguments(),
+ getLaunchEnvironmentModifierBlock(), isUsePTY());
}
}
Modified: branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java
===================================================================
--- branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java 2008-11-18 00:47:16 UTC (rev 946)
+++ branches/sdkPlusSupport/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/scratchbox/sb2/sdk/IScratchbox2SDKTarget.java 2008-11-18 11:36:44 UTC (rev 947)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * 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;
@@ -2,3 +12,14 @@
+/**
+ * @author baranov
+ *
+ */
public interface IScratchbox2SDKTarget extends IScratchboxSDKTarget {
+ static final String SESSION_SUFFIX = "-session";
+
+ /**
+ * 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();
More information about the Esbox-commits
mailing list