[Esbox-commits] r1908 - in trunk: org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv 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/src/org/maemo/esbox/internal/scratchbox/sb1/core 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/src/org/maemo/esbox/internal/scratchbox/sb2/core org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Thu Jul 30 19:35:13 EEST 2009
Author: eswartz
Date: 2009-07-30 19:35:12 +0300 (Thu, 30 Jul 2009)
New Revision: 1908
Modified:
trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/AfSbInitMaemoLauncherAdapter.java
trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java
trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/XLauncher.java
trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/BaseEmulatorStartStopRestartControlAction.java
trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/MaemoDropdownMenuAction.java
trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/XDropdownMenuAction.java
trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/MaemoExecutionEnvironmentHandler.java
trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/X11ExecutionEnvironmentHandler.java
trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java
trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDK.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java
trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDK.java
trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java
trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListCommands.java
trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java
Log:
Merge revs 1870:1896 from work_Ed branch
Modified: trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/AfSbInitMaemoLauncherAdapter.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/AfSbInitMaemoLauncherAdapter.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/AfSbInitMaemoLauncherAdapter.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -15,14 +15,21 @@
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.console.MessageConsole;
+import org.maemo.esbox.internal.maemosdk.core.Activator;
import org.maemo.esbox.maemosdk.core.MaemoEnvironmentUtils;
import org.maemo.esbox.maemosdk.core.MaemoPreferenceConstants;
import org.maemo.mica.common.core.MicaException;
@@ -40,15 +47,22 @@
import org.maemo.mica.common.core.process.ProcessLauncherUtils;
import org.maemo.mica.common.core.process.StreamLineMonitorAdapter;
import org.maemo.mica.common.core.sdk.ISDKTarget;
+import org.maemo.mica.maemosdk.core.IMaemoSDKTarget;
+import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
+
/**
* Launch the Maemo AF using the "af-sb-init.sh" script.
* @author baranov
*
*/
public class AfSbInitMaemoLauncherAdapter implements IMaemoLauncherAdapter{
+ private static final QualifiedName WARN_ARMEL_TARGET_EXECUTION = new QualifiedName(
+ Activator.PLUGIN_ID, "WARN_ARMEL_TARGET_EXECUTION");
+
+ private static final String MAEMO_LAUNCHER_APP = "maemo-launcher";
+ private static final String HILDON_DESKTOP_APP = "hildon-desktop";
- private static final String MAEMO_LAUNCHER_APP = "maemo-launcher";
private final ISDKTarget target;
private final MaemoCommand command;
@@ -60,6 +74,44 @@
this.command = new MaemoCommand(target);
}
+ private void warnIfArmelTarget(final Shell shell) {
+ final String msg = "You are launching an application under an emulated ARMEL target.\n\n"
+ + "This is a one-time warning that the QEMU emulator has some limitations "
+ + "in system call support, multithreading support, and instruction set emulation "
+ + "which may trigger unexpected bugs in otherwise correct programs.\n\n"
+ + "We recommend using an X86 target for normal development activities.";
+
+ if (target.getArchitecture().equals(
+ IMaemoSDKTarget.ARCHITECTURE_ARMEL)) {
+
+ Boolean oneTimeWarn = null;
+ IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
+ try {
+ oneTimeWarn = (Boolean) workspaceRoot
+ .getSessionProperty(WARN_ARMEL_TARGET_EXECUTION);
+ } catch (CoreException e1) {
+ Activator.getErrorLogger().logError(null, e1);
+ }
+
+ if(oneTimeWarn != null && !oneTimeWarn.booleanValue())
+ return;
+
+ try {
+ workspaceRoot.setSessionProperty(WARN_ARMEL_TARGET_EXECUTION, Boolean.FALSE);
+ } catch (CoreException e1) {
+ Activator.getErrorLogger().logError(null, e1);
+ }
+
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openWarning(shell, "Warning", msg);
+ }
+ });
+ }
+
+ }
+
+
/* (non-Javadoc)
* @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#killMaemo()
*/
@@ -92,22 +144,18 @@
}
/* (non-Javadoc)
- * <p>
- * This kills maemo if X is not running, since maemo may be left hanging is
- * X is killed.
* @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#restartMaemo()
*/
public void restartMaemo(IProgressMonitor monitor) throws MicaException {
if (monitor == null)
monitor = new NullProgressMonitor();
monitor.beginTask("", 10);
- if (!XLauncher.getInstance().isXServerStarted(target)) {
- killMaemo();
- XLauncher.getInstance().startXIfNeeded(target, new SubProgressMonitor(monitor, 1));
- if (monitor.isCanceled())
- return;
- }
- command.restartMaemoCommand(new SubProgressMonitor(monitor, 9));
+
+ ensureCorrectXRunning(new SubProgressMonitor(monitor, 1));
+ if (monitor.isCanceled())
+ return;
+ command.performCommand(MaemoPreferenceConstants.MAEMO_RESTART_ACTION,
+ new SubProgressMonitor(monitor, 9));
monitor.done();
}
@@ -117,21 +165,51 @@
public void startMaemo(IProgressMonitor monitor) throws MicaException {
if (monitor == null)
monitor = new NullProgressMonitor();
- monitor.beginTask("", IProgressMonitor.UNKNOWN);
- XLauncher.getInstance().startXIfNeeded(target, new SubProgressMonitor(monitor, 1));
+ monitor.beginTask("", 10);
+
+ ensureCorrectXRunning(new SubProgressMonitor(monitor, 1));
if (monitor.isCanceled())
return;
- if (XLauncher.getInstance().isXServerStarted(target)) {
- command.startMaemoCommand(new SubProgressMonitor(monitor, 9));
- }
+
+ Shell shell = WorkbenchUtils.getSafeShell();
+ warnIfArmelTarget(shell);
+
+ command.performCommand(MaemoPreferenceConstants.MAEMO_START_ACTION,
+ new SubProgressMonitor(monitor, 9));
monitor.done();
}
+ /**
+ * @param subProgressMonitor
+ * @throws MicaException
+ */
+ private void ensureCorrectXRunning(IProgressMonitor monitor) throws MicaException {
+ if (!XLauncher.getInstance().isCorrectXServerRunning(target)) {
+ // usability: if X is not running, be sure any Maemo environment in that
+ // server is also killed, or else if the user tries to restart
+ // the Maemo AF, it will still appear to be running for a while
+ // until all the processes die from the X server socket timeout.
+ killMaemo();
+ XLauncher.getInstance().startXIfNeeded(target, monitor);
+ }
+ }
+
/* (non-Javadoc)
* @see org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter#stopMaemo()
*/
public void stopMaemo(IProgressMonitor monitor) throws MicaException {
- command.stopMaemoCommand(monitor);
+ if (monitor == null)
+ monitor = new NullProgressMonitor();
+ monitor.beginTask("", 10);
+
+ command.performCommand(MaemoPreferenceConstants.MAEMO_STOP_ACTION,
+ new SubProgressMonitor(monitor, 9));
+ try {
+ XLauncher.getInstance().stopX(target, new SubProgressMonitor(monitor, 1));
+ } catch (MicaException e) {
+ // ignore
+ }
+ monitor.done();
}
/* (non-Javadoc)
@@ -152,7 +230,8 @@
List<IProcess> runningProcesses = machine.getProcessLister()
.getProcesses(
new ProcessFilterCmdLineRegexp(".*/"
- + MAEMO_LAUNCHER_APP + "\\s+.*"));
+ + "(" + MAEMO_LAUNCHER_APP +
+ "|" + HILDON_DESKTOP_APP + ")\\b"));
return runningProcesses;
}
@@ -164,6 +243,11 @@
this.sdkTarget = sdkTarget;
}
+ public void performCommand(String command, IProgressMonitor monitor) throws MicaException {
+ List<String> params = getParamList(command);
+ performCommand(params, monitor);
+ }
+
private void performCommand(List<String> params, final IProgressMonitor monitor) throws MicaException {
String maemoCommand = sdkTarget.getPreferenceValue(
MaemoPreferenceConstants.MAEMO_COMMAND);
@@ -247,23 +331,6 @@
}
- public void startMaemoCommand(IProgressMonitor monitor) throws MicaException {
- List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_START_ACTION);
-
- performCommand(params, monitor);
- }
-
- public void stopMaemoCommand(IProgressMonitor monitor) throws MicaException {
- List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_STOP_ACTION);
- performCommand(params, monitor);
- }
-
- public void restartMaemoCommand(IProgressMonitor monitor)
- throws MicaException {
- List<String> params = getParamList(MaemoPreferenceConstants.MAEMO_RESTART_ACTION);
- performCommand(params, monitor);
- }
-
private List<String> getParamList(String key) {
List<String> params = new ArrayList<String>();
params.add(sdkTarget.getPreferenceValue(key));
Modified: trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/IMaemoLauncherAdapter.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -15,7 +15,7 @@
import org.maemo.mica.common.core.MicaException;
/**
- * This adapter on ISDKTarget allows an SDK target to control how the maemo emulation
+ * This adapter on ISDKTarget allows an SDK target to control how the Maemo emulation
* environment is controlled.
* @author baranov
*
@@ -23,44 +23,51 @@
public interface IMaemoLauncherAdapter {
/**
- * Start maemo if it's not running. This runs asynchronously.
+ * Start Maemo AF, and X if needed. This runs asynchronously.
* @param monitor
* @param sdkTarget
*
* @throws MicaException
* if already running or cannot be started
*/
- public abstract void startMaemo(IProgressMonitor monitor) throws MicaException;
+ void startMaemo(IProgressMonitor monitor) throws MicaException;
/**
- * Stop maemo if it's running. This runs asynchronously.
+ * Stop Maemo AF and X. This runs asynchronously.
* @param monitor
* @param sdkTarget
*
* @throws MicaException
* if not running or cannot be stopped
*/
- public abstract void stopMaemo(IProgressMonitor monitor) throws MicaException;
+ void stopMaemo(IProgressMonitor monitor) throws MicaException;
/**
- * Restart maemo. This runs asynchronously.
+ * Restart Maemo and X. This runs asynchronously.
* @param monitor
* @param sdkTarget
*
* @throws MicaException
* if cannot be restarted
*/
- public abstract void restartMaemo(IProgressMonitor monitor)
+ void restartMaemo(IProgressMonitor monitor)
throws MicaException;
/**
- * Kill maemo by forcibly killing instances of the launcher left behind
+ * Kill maemo by forcibly killing instances of the launcher left behind.
+ * This is a lower-level operation that will not kill X.
*
* @param sdkTarget
* @throws MicaException
*/
- public abstract void killMaemo() throws MicaException;
+ void killMaemo() throws MicaException;
- public abstract boolean isMaemoRunning() throws MicaException;
+ /**
+ * Tell whether the Maemo AF is properly running:
+ * X is running and Maemo AF key processes are running.
+ * @return
+ * @throws MicaException if cannot detect
+ */
+ boolean isMaemoRunning() throws MicaException;
}
\ No newline at end of file
Modified: trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/MaemoScriptLauncher.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -13,31 +13,22 @@
package org.maemo.esbox.internal.api.maemosdk.core.tools;
-import java.io.IOException;
-import java.util.List;
-import java.util.regex.Pattern;
-
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.maemo.esbox.internal.maemosdk.core.Activator;
import org.maemo.mica.common.core.MicaException;
-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.preferences.CorePreferenceManager;
import org.maemo.mica.common.core.sdk.ISDKTarget;
/**
*/
public class MaemoScriptLauncher {
- private static MaemoScriptLauncher singleton = new MaemoScriptLauncher();
+ private static final MaemoScriptLauncher singleton = new MaemoScriptLauncher();
+ protected ISDKTarget previousTarget;
- /**
- * Constructor
- */
private MaemoScriptLauncher() {
}
@@ -45,41 +36,6 @@
return singleton;
}
- public boolean isXServerStarted(ISDKTarget sdkTarget) {
- try {
- return XLauncher.getInstance().isXServerStarted(sdkTarget);
- } catch (MicaException e) {
- Activator.getErrorLogger().logError("Failed to query X status", e);
- return false;
- }
- }
-
- /**
- * Method that starts X server.
- * @param monitor
- */
- public void startX(ISDKTarget sdkTarget, IProgressMonitor monitor) throws MicaException {
- // use the synchronous version
- XLauncher.getInstance().startXIfNeeded(sdkTarget, monitor);
- }
-
- /**
- * Method that stops X server.
- * @param monitor
- */
- public void stopX(ISDKTarget sdkTarget, IProgressMonitor monitor) throws MicaException {
- if (sdkTarget != null) {
- IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter)sdkTarget.getAdapter(IMaemoLauncherAdapter.class);
-
- if (launcher != null && launcher.isMaemoRunning()) {
- // usability
- //throw new MicaException("Maemo Application Framework is still running. Stop Maemo first.");
- launcher.stopMaemo(new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN));
- }
- }
- XLauncher.getInstance().stopX(sdkTarget, monitor);
- }
-
public boolean isMaemoStarted(ISDKTarget sdkTarget) {
IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter) sdkTarget
.getAdapter(IMaemoLauncherAdapter.class);
@@ -104,6 +60,7 @@
IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter) sdkTarget
.getAdapter(IMaemoLauncherAdapter.class);
if (launcher != null) {
+ previousTarget = null;
launcher.stopMaemo(monitor);
} else {
throw new MicaException("I do not know how to stop Maemo AF for " + sdkTarget.getDisplayName());
@@ -118,6 +75,7 @@
IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter) sdkTarget
.getAdapter(IMaemoLauncherAdapter.class);
if (launcher != null) {
+ previousTarget = sdkTarget;
launcher.startMaemo(monitor);
} else {
throw new MicaException("I do not know how to start Maemo AF for " + sdkTarget.getDisplayName());
@@ -125,58 +83,19 @@
}
/**
- * Restart X and Maemo if it is running.
- * <p>
- * This kills maemo if X is not running, since maemo may be left hanging is
- * X is killed.
+ * Restart Maemo AF (starting if not yet started).
* @param monitor
*/
public void restartMaemo(ISDKTarget sdkTarget, IProgressMonitor monitor) throws MicaException {
IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter) sdkTarget
.getAdapter(IMaemoLauncherAdapter.class);
if (launcher != null) {
+ previousTarget = sdkTarget;
launcher.restartMaemo(monitor);
}
}
/**
- * Kill maemo.
- */
- public void killMaemo(ISDKTarget target) throws MicaException {
- IMaemoLauncherAdapter launcher = (IMaemoLauncherAdapter) target
- .getAdapter(IMaemoLauncherAdapter.class);
- if (launcher != null) {
- launcher.killMaemo();
- }
- }
-
- /**
- * Kill all instances of a given process
- *
- * @param processName
- * executable name
- * @param processLabel
- * the user-visible name for the process
- */
- public void killProcess(IMachine machine, String processName,
- String processLabel) throws MicaException {
- // resolve pure process name
- int slashIndex = processName.lastIndexOf("/");
- if(slashIndex != -1){
- processName = processName.substring(slashIndex+1);
- }
- List<IProcess> processes = machine.getProcessLister().getProcesses(
- new ProcessFilterCmdLineRegexp(".*" + processName + ".*",Pattern.CASE_INSENSITIVE));
- for (IProcess process : processes) {
- try {
- process.terminate();
- } catch (IOException e) {
- throw new MicaException("Error killing " + processName, e);
- }
- }
- }
-
- /**
* Create a job to start Maemo.
*/
public Job createStartMaemoJob(final ISDKTarget target) {
@@ -239,7 +158,6 @@
protected IStatus run(IProgressMonitor monitor) {
try {
MaemoScriptLauncher.getInstance().stopMaemo(target, monitor);
- MaemoScriptLauncher.getInstance().killMaemo(target);
} catch (MicaException e) {
Activator.getErrorLogger().showError(null, e);
}
@@ -272,13 +190,13 @@
/**
* Create a job to stop X.
*/
- public Job createStopXJob(final ISDKTarget target) {
+ public Job createStopXJob() {
Job job = new Job("Stopping X Server") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
- MaemoScriptLauncher.getInstance().stopX(target, monitor);
+ MaemoScriptLauncher.getInstance().stopX(monitor);
} catch (MicaException e) {
Activator.getErrorLogger().showError(null, e);
}
@@ -288,4 +206,28 @@
};
return job;
}
+
+ /**
+ * @return
+ */
+ public ISDKTarget getPreviousTarget() {
+ return previousTarget;
+ }
+
+ /**
+ * Stop the X server.
+ * @param monitor
+ */
+ public void stopX(IProgressMonitor monitor) throws MicaException {
+ XLauncher.getInstance().stopX(CorePreferenceManager.getInstance().getPreferenceProvider(), monitor);
+ }
+
+ /**
+ * Start the X server for the target if it is not already running.
+ * @param monitor
+ */
+ public void startX(ISDKTarget sdkTarget, IProgressMonitor monitor) throws MicaException {
+ XLauncher.getInstance().startXIfNeeded(sdkTarget, monitor);
+ previousTarget = sdkTarget;
+ }
}
Modified: trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/XLauncher.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/XLauncher.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.core/src/org/maemo/esbox/internal/api/maemosdk/core/tools/XLauncher.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -20,17 +20,21 @@
import org.maemo.mica.common.core.Policy;
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.MachineRegistry;
import org.maemo.mica.common.core.machine.MachineUtils;
+import org.maemo.mica.common.core.machine.ProcessFilterCmdLineRegexp;
import org.maemo.mica.common.core.preferences.CorePreferenceManager;
import org.maemo.mica.common.core.preferences.IPreferenceProvider;
import org.maemo.mica.common.core.process.*;
import org.maemo.mica.common.core.sdk.ISDKTarget;
import org.maemo.mica.maemosdk.core.IMaemoSDKPlatform;
+import java.io.IOException;
import java.net.Socket;
import java.text.MessageFormat;
import java.util.List;
+import java.util.regex.Pattern;
/**
* This class maintains knowledge about whether the X server is running in the
@@ -131,14 +135,14 @@
}
}
- private static XLauncher instance;
+ private static final XLauncher instance = new XLauncher();
private XLaunchingJob launchingXJob;
- public synchronized static XLauncher getInstance() {
- if (instance == null) {
- instance = new XLauncher();
- }
+ private List<String> previousCommandLine;
+ private String previousDisplay;
+
+ public static XLauncher getInstance() {
return instance;
}
@@ -189,11 +193,12 @@
}
/**
- * Test whether the X server is started by testing a connection to the
- * server.
+ * Test whether the X server is started and is compatible with
+ * the current settings.
*
* @param prefProvider
- * @return
+ * @return true if running
+ * @throws MicaException if X server display variable is invalid
*/
public boolean isXServerStarted(IPreferenceProvider prefProvider)
throws MicaException {
@@ -203,7 +208,72 @@
return testXConnection(getDisplayValue(prefProvider));
}
- /** Be nice and start X if needed before starting/restarting maemo
+ /**
+ * Test whether the X server is running with the same command line
+ * as before.
+ *
+ * @param prefProvider
+ * @return true if running
+ * @throws MicaException if X server display variable is invalid
+ */
+ public boolean isXServerCompatible(IPreferenceProvider prefProvider)
+ throws MicaException {
+ if (prefProvider == null)
+ prefProvider = CorePreferenceManager.getInstance().getPreferenceProvider();
+
+ // only test if we're making a server for the same display as before
+ String newDisplay = getDisplayValue(prefProvider);
+ if (previousDisplay != null && !newDisplay.equals(previousDisplay))
+ return true;
+
+ List<String> newCommandLine = getDisplayXServerCommand(prefProvider);
+ if (previousCommandLine != null) {
+ return previousCommandLine.equals(newCommandLine);
+ }
+
+ // we didn't launch it....
+ if (!newCommandLine.isEmpty()) {
+ IProcess[] processes = getMatchingXProcesses(newCommandLine.get(0));
+ if (processes.length > 0) {
+ boolean realCmdLinesAvailable = false;
+ for (IProcess process : processes) {
+ List<String> processCmdLine = CommandLineArguments.createFromCommandLine(process.getCommandLine());
+ if (processCmdLine.size() > 1) {
+ realCmdLinesAvailable = true;
+ // note: the argv[0] executable may now have a path
+ if (processCmdLine.subList(1, processCmdLine.size()).equals(
+ newCommandLine.subList(1, newCommandLine.size()))) {
+ return true;
+ }
+ }
+ }
+ if (realCmdLinesAvailable) {
+ // no exact matches
+ return false;
+ }
+ // probably on Windows, so assume the X server is ours
+ return true;
+ }
+ }
+
+ // no X server configured or no match
+ return false;
+ }
+
+ /**
+ * Tell if the X server is running, and if it is, whether it's the
+ * one we want to run.
+ * @param prefProvider
+ * @return flag true if server is running and compatible
+ * @throws MicaException if bad settings
+ */
+ public boolean isCorrectXServerRunning(IPreferenceProvider prefProvider) throws MicaException {
+ return isXServerStarted(prefProvider) && isXServerCompatible(prefProvider);
+ }
+
+ /**
+ * Start X if it is not running, or if we know it was previously launched with
+ * a different command line.
* */
public void startXIfNeeded(IPreferenceProvider prefProvider, IProgressMonitor monitor)
throws MicaException {
@@ -214,8 +284,23 @@
monitor = new NullProgressMonitor();
monitor.beginTask("", 3);
+
+ // if already starting, wait...
waitForXLaunch(new SubProgressMonitor(monitor, 1));
- if (!isXServerStarted(prefProvider)) {
+
+ // start X if it's not running or if the arguments have changed
+ boolean serverStarted = isXServerStarted(prefProvider);
+ boolean serverCompatible = isXServerCompatible(prefProvider);
+
+ if (!serverStarted || !serverCompatible) {
+ if (serverStarted && !serverCompatible) {
+ // stop an incompatible server
+ try {
+ stopX(prefProvider, new SubProgressMonitor(monitor, 0));
+ } catch (MicaException e) {
+ // ignore
+ }
+ }
startX(prefProvider, new SubProgressMonitor(monitor, 1));
waitForXLaunch(new SubProgressMonitor(monitor, 1));
}
@@ -270,12 +355,12 @@
final IPreferenceProvider prefProvider = prefProvider_;
- String viewer = getDisplayXServerCommand(prefProvider);
+ List<String> cmdLine = getDisplayXServerCommand(prefProvider);
final String display = getDisplayValue(prefProvider);
+
+ previousCommandLine = cmdLine;
+ previousDisplay = display;
- List<String> cmdLine = CommandLineArguments
- .createFromCommandLine(viewer);
-
if (cmdLine.size() > 0) {
IMachine localMachine = MachineRegistry.getInstance()
@@ -298,7 +383,7 @@
IProcessLauncher processLauncher = factory.createProcessLauncher(
params);
ProcessLauncherUtils.queueConsoleMonitor(processLauncher,
- true, null, "Starting X Server");
+ true, prefProvider instanceof ISDKTarget ? (ISDKTarget) prefProvider : null, "Starting X Server");
processLauncher.createProcess(null);
IProcessMonitor procMon = processLauncher.createProcessMonitor();
@@ -310,11 +395,17 @@
}
} else {
Activator.getErrorLogger().logAndShowError(
- "No X server configured in ESbox preferences", null);
+ "No X server configured in X Server preferences", null);
}
}
+ /**
+ * Stop X synchronously.
+ * @param prefProvider
+ * @param monitor
+ * @throws MicaException if server is not running or could not be killed.
+ */
public void stopX(IPreferenceProvider prefProvider, IProgressMonitor monitor) throws MicaException {
if (prefProvider == null)
prefProvider = CorePreferenceManager.getInstance().getPreferenceProvider();
@@ -328,24 +419,23 @@
throw new MicaException(
"X Server was not started. Start X Server first");
- String server = getDisplayXServerCommand(prefProvider);
+ List<String> cmdLine = getDisplayXServerCommand(prefProvider);
- List<String> cmdLine = CommandLineArguments
- .createFromCommandLine(server);
-
+ previousCommandLine = null;
+ previousDisplay = null;
+
// find server to kill
if (cmdLine.size() > 0) {
- IMachine localMachine = MachineRegistry.getInstance()
- .getLocalMachine();
- if (localMachine == null)
- throw new MicaException("Cannot find local machine");
-
- MaemoScriptLauncher.getInstance().killProcess(localMachine,
- cmdLine.get(0), "X Server");
+ killProcess(cmdLine.get(0), "Killing X Server");
}
}
- private String getDisplayXServerCommand(IPreferenceProvider prefProvider) {
+ /**
+ * Get the command line for launching the X server.
+ * @param prefProvider
+ * @return
+ */
+ private List<String> getDisplayXServerCommand(IPreferenceProvider prefProvider) {
String command = prefProvider
.getPreferenceValue(MaemoPreferenceConstants.DISPLAY_X_COMMAND);
@@ -359,7 +449,8 @@
//Defining specific platform RESOLUTION.
command = command.replaceAll("\\$\\{RESOLUTION\\}",
getResolutionParameter(prefProvider));
- return command;
+
+ return CommandLineArguments.createFromCommandLine(command);
}
/**
@@ -371,7 +462,7 @@
* {@link ISDKTarget} the default value is returned.
* @return the value for variable {PLATFORM_PARAMETERS}.
*/
- public String getPlatformParameters(IPreferenceProvider prefProvider) {
+ private String getPlatformParameters(IPreferenceProvider prefProvider) {
ISDKTarget sdkTarget = null;
if (prefProvider instanceof ISDKTarget)
sdkTarget = (ISDKTarget) prefProvider;
@@ -393,7 +484,7 @@
* {@link ISDKTarget} the default value is returned.
* @return the value for variable {RESOLUTION}.
*/
- public String getResolutionParameter(IPreferenceProvider prefProvider) {
+ private String getResolutionParameter(IPreferenceProvider prefProvider) {
ISDKTarget sdkTarget = null;
if (prefProvider instanceof ISDKTarget)
sdkTarget = (ISDKTarget) prefProvider;
@@ -413,4 +504,39 @@
else
return System.getenv("DISPLAY"); // get from system
}
+
+ /**
+ * Kill all instances of a given process
+ *
+ * @param processLabel
+ * the user-visible name for the process
+ */
+ private void killProcess(String processName,
+ String processLabel) throws MicaException {
+ IProcess[] processes = getMatchingXProcesses(processName);
+ for (IProcess process : processes) {
+ try {
+ process.terminate();
+ } catch (IOException e) {
+ throw new MicaException("Error killing " + processName, e);
+ }
+ }
+ }
+
+ /**
+ * @param machine
+ * @return
+ */
+ private IProcess[] getMatchingXProcesses(String processName) {
+ // resolve pure process name
+ int slashIndex = processName.lastIndexOf("/");
+ if(slashIndex != -1){
+ processName = processName.substring(slashIndex+1);
+ }
+ List<IProcess> processes = MachineRegistry.getInstance().getLocalMachine().
+ getProcessLister().getProcesses(
+ new ProcessFilterCmdLineRegexp(".*" + processName + ".*",Pattern.CASE_INSENSITIVE));
+ return (IProcess[]) processes.toArray(new IProcess[processes.size()]);
+ }
+
}
\ No newline at end of file
Modified: trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/BaseEmulatorStartStopRestartControlAction.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/BaseEmulatorStartStopRestartControlAction.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/BaseEmulatorStartStopRestartControlAction.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -32,9 +32,14 @@
import org.maemo.mica.common.core.sdk.ISDKTarget;
import org.maemo.mica.common.project.core.ProjectManager;
import org.maemo.mica.common.ui.dialogs.SelectSDKTargetDialog;
+import org.maemo.mica.internal.api.common.core.sdk.ISingleCurrentTargetOnlySDK;
/**
- * Basic action for a toolbar menu action.
+ * Basic support for a toolbar menu action that supports Start/Stop
+ * (and possibly Restart) and lets the user select an ISDKTarget
+ * in which to perform the action. The previously selected
+ * target -- or the currently active target for that target's SDK
+ * -- is used as a default if possible.
* @author eswartz
*
*/
@@ -49,7 +54,6 @@
protected abstract void startClicked();
protected IProject selectedProject;
- protected ISDKTarget previousTarget;
/**
*
@@ -80,7 +84,6 @@
mi.setImage(UIActivator.getImageDescriptor("./icons/full/etool16/start_co.gif").createImage());
mi.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
- previousTarget = null;
startClicked();
}
@@ -102,6 +105,8 @@
mi.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
stopClicked();
+ // ask next time
+ //previousTarget = null;
}
});
@@ -128,7 +133,7 @@
IResource resource = WorkspaceUtils.getResourceFromSelection(selection);
- // XXX: don't ask for ISDKTarget here since it can hang
+ // don't ask for ISDKTarget here since it can hang (UI thread)
this.selectedProject = null;
if (resource != null && resource.getProject().isOpen()) {
this.selectedProject = resource.getProject();
@@ -137,15 +142,10 @@
action.setEnabled(true);
}
- protected ISDKTarget getSDKTarget(final String prompt) {
-
- // XXX FIXME: the previous target may be different
- // if the environment was launched from MaemoExecutionEnvironmentAdapter
+ protected ISDKTarget getSDKTarget(final String prompt, ISDKTarget previousTarget) {
ISDKTarget sdkTarget = previousTarget;
- if (sdkTarget != null)
- return sdkTarget;
-
+ // figure out a viable target from the context
if (selectedProject != null) {
try {
ISDKTarget theSdkTarget = ProjectManager.getInstance().getSDKTarget(selectedProject);
@@ -169,8 +169,41 @@
});
- previousTarget = selected[0];
+ if (selected[0] != null)
+ previousTarget = selected[0];
return selected[0];
}
+ /**
+ * Get the ISDKTarget that is current, for the purpose of restarting
+ * or stopping. This might be the one we used when starting, or
+ * the user may have manually switched targets and launched in
+ * the meantime. If we can't tell, ask.
+ * @return ISDKTarget or <code>null</code> if we asked and the user canceled
+ * or we cannot tell
+ */
+ protected ISDKTarget getCurrentSDKTarget(ISDKTarget previousTarget) {
+ if (previousTarget != null) {
+ if (previousTarget.getSDK() instanceof ISingleCurrentTargetOnlySDK) {
+ try {
+ // the user may have switched targets in the meantime.
+ // If this is the kind of SDK where only one target
+ // is active at a time, use that one instead (Mica #4284)
+ String currentTargetName = ((ISingleCurrentTargetOnlySDK) previousTarget.getSDK()).getCurrentTarget();
+ if (currentTargetName != null) {
+ ISDKTarget currentTarget = previousTarget.getSDK().findSDKTarget(currentTargetName);
+ if (currentTarget != null) {
+ return currentTarget;
+ }
+ }
+ } catch (MicaException e) {
+ // can't be sure... fall through
+ }
+ }
+ return previousTarget;
+ }
+
+ // ask
+ return getSDKTarget("Select the target under which to operate:", previousTarget);
+ }
}
\ No newline at end of file
Modified: trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/MaemoDropdownMenuAction.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/MaemoDropdownMenuAction.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/MaemoDropdownMenuAction.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -11,10 +11,12 @@
*******************************************************************************/
package org.maemo.esbox.internal.maemosdk.ui.actions;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.maemo.esbox.internal.api.maemosdk.core.tools.IMaemoLauncherAdapter;
import org.maemo.esbox.internal.api.maemosdk.core.tools.MaemoScriptLauncher;
+import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.sdk.ISDKTarget;
/**
@@ -29,7 +31,8 @@
public class MaemoDropdownMenuAction extends BaseEmulatorStartStopRestartControlAction {
protected ISDKTarget getSDKTarget() {
- return getSDKTarget("Select an SDK under which to run the Maemo Application Framework:");
+ return getSDKTarget("Select an SDK under which to run the Maemo Application Framework:",
+ MaemoScriptLauncher.getInstance().getPreviousTarget());
}
@@ -39,10 +42,22 @@
if (target == null)
return;
if (MaemoScriptLauncher.getInstance().isMaemoStarted(target)) {
- MessageDialog.openInformation(null,
+ boolean restart = MessageDialog.openQuestion(null,
"Maemo AF is running",
- "The Maemo Application Framework appears to be already running.\n\nIf you do not see it, you may need to restart it or wait for its startup to complete.");
- return;
+ "The Maemo Application Framework appears to be already running.\n\nIf you do not see it, you may need to restart it or wait for its startup to complete.\n\nDo you want to restart it for " + target.getName() + "?");
+ if (!restart)
+ return;
+
+ ISDKTarget killTarget = MaemoScriptLauncher.getInstance().getPreviousTarget();
+ if (killTarget == null)
+ killTarget = target;
+
+ try {
+ MaemoScriptLauncher.getInstance().stopMaemo(killTarget,
+ new NullProgressMonitor());
+ } catch (MicaException e) {
+ // ignore
+ }
}
Job job = MaemoScriptLauncher.getInstance().createStartMaemoJob(target);
job.schedule();
@@ -50,7 +65,7 @@
@Override
protected void restartClicked() {
- ISDKTarget target = getSDKTarget();
+ ISDKTarget target = getCurrentSDKTarget(MaemoScriptLauncher.getInstance().getPreviousTarget());
if (target == null)
return;
Job job = MaemoScriptLauncher.getInstance().createRestartMaemoJob(target);
@@ -59,7 +74,7 @@
@Override
protected void stopClicked() {
- ISDKTarget target = getSDKTarget();
+ ISDKTarget target = getCurrentSDKTarget(MaemoScriptLauncher.getInstance().getPreviousTarget());
if (target == null)
return;
Job job = MaemoScriptLauncher.getInstance().createStopMaemoJob(target);
Modified: trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/XDropdownMenuAction.java
===================================================================
--- trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/XDropdownMenuAction.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.maemosdk.ui/src/org/maemo/esbox/internal/maemosdk/ui/actions/XDropdownMenuAction.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -19,6 +19,8 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.maemo.esbox.internal.api.maemosdk.core.tools.MaemoScriptLauncher;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
+import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.sdk.ISDKTarget;
/**
@@ -32,7 +34,8 @@
public class XDropdownMenuAction extends BaseEmulatorStartStopRestartControlAction {
protected ISDKTarget getSDKTarget() {
- return getSDKTarget("Select an SDK under which to run the X Server:");
+ return getSDKTarget("Select an SDK under which to run the X Server:",
+ MaemoScriptLauncher.getInstance().getPreviousTarget());
}
/* (non-Javadoc)
@@ -50,9 +53,13 @@
ISDKTarget target = getSDKTarget();
if (target == null)
return;
- if (MaemoScriptLauncher.getInstance().isXServerStarted(target)) {
- MessageDialog.openInformation(null, "X Running", "X is still running. Terminate it first if necessary.");
- return;
+ try {
+ if (XLauncher.getInstance().isCorrectXServerRunning(target)) {
+ MessageDialog.openInformation(null, "X Running", "X is still running. Terminate it first if necessary.");
+ return;
+ }
+ } catch (MicaException e) {
+ // failed, so definitely not running
}
Job job = MaemoScriptLauncher.getInstance().createStartXJob(target);
@@ -63,10 +70,7 @@
* Stop X
*/
protected void stopClicked() {
- ISDKTarget target = getSDKTarget();
- if (target == null)
- return;
- Job job = MaemoScriptLauncher.getInstance().createStopXJob(target);
+ Job job = MaemoScriptLauncher.getInstance().createStopXJob();
job.schedule();
}
Modified: trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/MaemoExecutionEnvironmentHandler.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/MaemoExecutionEnvironmentHandler.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/MaemoExecutionEnvironmentHandler.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -12,21 +12,20 @@
package org.maemo.esbox.internal.api.scratchbox.core.execEnv;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.maemo.esbox.internal.api.maemosdk.core.tools.MaemoScriptLauncher;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
import org.maemo.esbox.internal.scratchbox.core.Activator;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.execEnv.IExecutionEnvironmentHandler;
import org.maemo.mica.common.core.sdk.ISDKTarget;
import org.maemo.mica.common.project.core.ProjectManager;
-import org.maemo.mica.maemosdk.core.IMaemoSDKTarget;
+import org.maemo.mica.internal.api.common.core.sdk.ISingleCurrentTargetOnlySDK;
/**
* Environment for Maemo applications
@@ -36,79 +35,60 @@
*/
public class MaemoExecutionEnvironmentHandler implements
IExecutionEnvironmentHandler {
- public static final QualifiedName WARN_ARMEL_TARGET_EXECUTION = new QualifiedName(
- Activator.PLUGIN_ID, "WARN_ARMEL_TARGET_EXECUTION");
-
- public void establishEnvironment(Shell shell, IProject project,
+
+ public void establishEnvironment(final Shell shell, IProject project,
IProgressMonitor monitor)
throws CoreException {
- shouldNotRunArmelTarget(shell, project);
- // see if Maemo is running
- runMaemoIfNeeded(shell, project, monitor);
- }
-
- private void shouldNotRunArmelTarget(final Shell shell, IProject project) {
- final String msg = "You are launching an application under an emulated ARMEL target.\n\n"
- + "This is a one-time warning that the QEMU emulator has some limitations "
- + "in system call support, multithreading support, and instruction set emulation "
- + "which may trigger unexpected bugs in otherwise correct programs.\n\n"
- + "We recommend using an X86 target for normal development activities.";
-
- ISDKTarget sdkTarget;
- IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
- Boolean oneTimeWarn = null;
+ final ISDKTarget sdkTarget;
try {
sdkTarget = ProjectManager.getInstance().getSDKTarget(project);
- if (sdkTarget.getArchitecture().equals(
- IMaemoSDKTarget.ARCHITECTURE_ARMEL)) {
-
- try {
- oneTimeWarn = (Boolean) workspaceRoot
- .getSessionProperty(WARN_ARMEL_TARGET_EXECUTION);
- } catch (CoreException e1) {
- Activator.getErrorLogger().logError(null, e1);
+
+ boolean wrongOneRunning = false;
+ ISDKTarget wrongTarget = null;
+
+ // ensure that the previous target is actually active -- we may otherwise
+ // get a false positive when using a different SB1 target, which will just
+ // kill the emulator anyway.
+ if (sdkTarget.getSDK() instanceof ISingleCurrentTargetOnlySDK) {
+ String currentTarget = ((ISingleCurrentTargetOnlySDK)sdkTarget.getSDK()).getCurrentTarget();
+ if (!sdkTarget.getName().equals(
+ currentTarget)) {
+ wrongTarget = sdkTarget.getSDK().findSDKTarget(currentTarget);
+ wrongOneRunning = true;
}
-
- if(oneTimeWarn != null && !oneTimeWarn.booleanValue())
- return;
-
- try {
- workspaceRoot.setSessionProperty(WARN_ARMEL_TARGET_EXECUTION, Boolean.FALSE);
- } catch (CoreException e1) {
- Activator.getErrorLogger().logError(null, e1);
- }
-
- Display.getDefault().asyncExec(new Runnable() {
- public void run() {
- MessageDialog.openWarning(shell, "Warning", msg);
- }
- });
}
- } catch (MicaException e) {
- Activator.getErrorLogger().logAndShowError(
- "Error valdating Maemo execution environment", e);
- // don't fail the launch
- }
-
- }
-
- private void runMaemoIfNeeded(final Shell shell, IProject project, IProgressMonitor monitor) {
- final ISDKTarget sdkTarget;
- try {
- sdkTarget = ProjectManager.getInstance().getSDKTarget(project);
- if (!MaemoScriptLauncher.getInstance().isMaemoStarted(sdkTarget)
- || !MaemoScriptLauncher.getInstance().isXServerStarted(sdkTarget)) {
+
+ // See if X is running and it's the one we want. (If it's not running,
+ // any Maemo AF will die soon too.)
+ boolean wrongXRunning = !XLauncher.getInstance().isCorrectXServerRunning(sdkTarget);
+
+ if (wrongOneRunning
+ || !MaemoScriptLauncher.getInstance().isMaemoStarted(sdkTarget)
+ || wrongXRunning) {
final boolean[] doLaunch = { false };
+ final String message =
+ wrongOneRunning ?
+ "The Maemo Application Framework is running for a different target.\n\nThis may or may not be valid for the new application.\n\nSwitch to the new target (" + sdkTarget.getName() + ")?"
+ : "The Maemo Application Framework does not seem to be running.\n\nLaunch it now?";
Display.getDefault().syncExec(new Runnable() {
public void run() {
- doLaunch[0] = MessageDialog.openQuestion(shell, "Launch Maemo?",
- "The Maemo Application Framework does not seem to be running.\n\nLaunch it now?");
+ doLaunch[0] = MessageDialog.openQuestion(shell, "Launch Maemo AF?",
+ message);
}
});
if (doLaunch[0]) {
+ if (wrongOneRunning) {
+ Job stopJob = MaemoScriptLauncher.getInstance().createStopMaemoJob(wrongTarget);
+ stopJob.schedule();
+ try {
+ stopJob.join();
+ } catch (InterruptedException e) {
+ }
+ }
+
Job job = MaemoScriptLauncher.getInstance().createStartMaemoJob(sdkTarget);
job.schedule();
Modified: trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/X11ExecutionEnvironmentHandler.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/X11ExecutionEnvironmentHandler.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/execEnv/X11ExecutionEnvironmentHandler.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -18,6 +18,7 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.maemo.esbox.internal.api.maemosdk.core.tools.MaemoScriptLauncher;
+import org.maemo.esbox.internal.api.maemosdk.core.tools.XLauncher;
import org.maemo.esbox.internal.scratchbox.core.Activator;
import org.maemo.mica.common.core.JobUtils;
import org.maemo.mica.common.core.MicaException;
@@ -44,13 +45,19 @@
}
boolean serverRunning;
- serverRunning = MaemoScriptLauncher.getInstance().isXServerStarted(sdkTarget);
+ try {
+ serverRunning = XLauncher.getInstance().isCorrectXServerRunning(sdkTarget);
+ } catch (MicaException e) {
+ Activator.getErrorLogger().logAndShowError(
+ "Cannot validate the X server connection", e);
+ return;
+ }
if (!serverRunning) {
if (MessageDialog
.openQuestion(shell, "Launch X Server?",
- "The X server is not running. Would you like to launch it now?")) {
+ "The X server is not running or is running with different parameters.\n\nWould you like to launch it now?")) {
Job job = MaemoScriptLauncher.getInstance().createStartXJob(sdkTarget);
job.schedule();
JobUtils.waitForJob(job, monitor, "Waiting for startup...");
Modified: trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/internal/api/scratchbox/core/sdk/AbstractScratchboxSDK.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -15,7 +15,6 @@
import org.maemo.esbox.internal.api.scratchbox.core.commands.SDKCommandAbstractor;
import org.maemo.esbox.internal.api.scratchbox.core.commands.sbrsh.*;
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK;
-import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDKTarget;
import org.maemo.mica.common.core.MicaException;
import org.maemo.mica.common.core.env.IEnvironmentModifierBlock;
import org.maemo.mica.common.core.filesystem.IFileSystemAccess;
@@ -151,17 +150,6 @@
* (non-Javadoc)
*
* @see
- * org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK#getCurrentSDKTarget()
- */
- public IScratchboxSDKTarget getCurrentSDKTarget() throws MicaException {
- String targetName = getCurrentTarget();
- return (IScratchboxSDKTarget) this.findSDKTarget(targetName);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
* org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK#configureSbrsh(java.
* lang.String, java.lang.String, java.lang.String)
*/
Modified: trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.core/src/org/maemo/esbox/scratchbox/core/sdk/IScratchboxSDK.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -61,25 +61,6 @@
public List<String> getTargets() throws MicaException;
/**
- * Return the current target name of the Scratchbox.
- *
- *
- * @return the current target of the Scratchbox.
- * @throws MicaException
- * if some problem related to Scratchbox communication occurs.
- */
- public String getCurrentTarget() throws MicaException;
-
- /**
- * Return the current target of the Scratchbox.
- *
- * @return the current target of Scratchbox.
- * @throws MicaException
- * if some problem related to Scratchbox communication occurs.
- */
- public IScratchboxSDKTarget getCurrentSDKTarget() throws MicaException;
-
- /**
* Create a new target for Scratchbox. An target must have a name, and the
* compiler, devkits and cputransp must be available in Scratchbox.
*
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDK.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDK.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/core/Scratchbox1SDK.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -443,8 +443,11 @@
IScratchboxSDKTarget currentTarget = null;
try {
- currentTarget = getCurrentSDKTarget();
- } catch (ScratchboxException e) {
+ String currentTargetName = getCurrentTarget();
+ if (currentTargetName != null) {
+ currentTarget = (IScratchboxSDKTarget) findSDKTarget(currentTargetName);
+ }
+ } catch (MicaException e) {
// there may be no target, which is fine
}
@@ -457,18 +460,10 @@
// a target selection may succeed even if X and maemo are
// running... kill them first.
try {
- launcher.killMaemo();
+ launcher.stopMaemo(new NullProgressMonitor());
} catch (MicaException e2) {
// ignore
}
-
- // We kill X too because some processes won't be killed by
- // maemo-launcher.
- try {
- MaemoScriptLauncher.getInstance().stopX(currentTarget, new NullProgressMonitor());
- } catch (MicaException e) {
- // ignore
- }
}
}
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1PrepareTargetProcessLaunchAdapter.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -15,7 +15,6 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
-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.WorkspaceUtils;
@@ -40,7 +39,7 @@
IScratchbox1SDK sdk = ((IScratchbox1SDK) sdkTarget.getSDK());
final String currentTarget = sdk.getCurrentTarget();
final String targetName = sdkTarget.getName();
- if (currentTarget.equals(targetName)) {
+ if (targetName.equals(currentTarget)) {
return;
}
@@ -48,7 +47,7 @@
boolean failedToSwitch = false;
try {
sdk.selectTarget(targetName);
- } catch (final ScratchboxException e) {
+ } catch (final MicaException e) {
// sb-conf: You must close your other Scratchbox sessions first
// or
// Note: Couldn't reselect the target. There are other Scratchbox
@@ -60,7 +59,7 @@
}
}
- if (failedToSwitch || !sdk.getCurrentTarget().equals(targetName)) {
+ if (failedToSwitch || !targetName.equals(sdk.getCurrentTarget())) {
final boolean[] ret = { false };
if (!WorkspaceUtils.isJUnitRunning()) {
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/internal/scratchbox/sb1/launcher/Scratchbox1ProcessLauncher.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -13,6 +13,7 @@
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.*;
+import org.maemo.esbox.internal.scratchbox.sb1.Activator;
import org.maemo.esbox.internal.scratchbox.sb1.core.SB1PreferenceConstants;
import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDK;
import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDKTarget;
@@ -39,15 +40,19 @@
public class Scratchbox1ProcessLauncher extends AbstractSDKTargetProcessLauncher implements
IProcessLauncher {
+ private static int gRunScriptCounter;
+
/**
* The name of a file copied from the plugin to the sb environment
* which we generate to wrap the program.
*/
- private static final String RUN_SCRIPT_NAME = "run.sh";
+ private static final String RUN_SCRIPT_NAME = "run";
private Scratchbox1SDKTarget sdkTarget;
private String runScriptContents;
+
+ private String runScriptName;
public Scratchbox1ProcessLauncher(Scratchbox1SDKTarget sdkTarget,
ProcessLauncherParameters params) {
super(params, sdkTarget);
@@ -73,7 +78,12 @@
// it better not be null
substitutor.define("RUN_SCRIPT_DIRECTORY", targetRunScriptPath.toPortableString());
- substitutor.define("RUN_SCRIPT", RUN_SCRIPT_NAME);
+
+ // hack: for unit tests: we won't run #setupForLaunch() first
+ if (runScriptName == null)
+ runScriptName = "run.sh";
+
+ substitutor.define("RUN_SCRIPT", runScriptName);
// get the Scratchbox invocation pattern
String commandPattern = sdkTarget
@@ -122,8 +132,24 @@
IPath runScriptLocation = getRunScriptLocation(sdkTarget);
- IFileStore store = sdkTarget.getMachine().getFileSystemAccess().getFileStore(
- runScriptLocation.append(RUN_SCRIPT_NAME));
+ // make a unique run.sh script name, so we can run multiple programs simultaneously
+ runScriptName = RUN_SCRIPT_NAME + (gRunScriptCounter++) + ".sh";
+
+ final IFileStore store = sdkTarget.getMachine().getFileSystemAccess().getFileStore(
+ runScriptLocation.append(runScriptName));
+
+ // remove the script when we're done
+ queueStreamMonitor(new StreamMonitorAdapter() {
+ @Override
+ public void processExited(int exitCode) {
+ try {
+ store.delete(0, null);
+ } catch (CoreException e) {
+ Activator.getErrorLogger().logError("Error removing " + runScriptName, e);
+ }
+ }
+ });
+
try {
store.getParent().mkdir(0, null);
Modified: trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDK.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDK.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.sb1/src/org/maemo/esbox/scratchbox/sb1/sdk/IScratchbox1SDK.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -14,12 +14,13 @@
import org.maemo.esbox.scratchbox.core.sdk.IScratchboxSDK;
import org.maemo.mica.common.core.MicaException;
+import org.maemo.mica.internal.api.common.core.sdk.ISingleCurrentTargetOnlySDK;
/**
* @author baranov
*
*/
-public interface IScratchbox1SDK extends IScratchboxSDK {
+public interface IScratchbox1SDK extends IScratchboxSDK, ISingleCurrentTargetOnlySDK {
public static final String NAME = "Scratchbox 1";
/**
@@ -41,17 +42,6 @@
public List<String> getSessions() throws MicaException;
/**
- * Select another available target as current Scratchbox target.
- *
- * @param targetName
- * the name of the new target.
- * @throws MicaException
- * if the target to be selected does not exists or if some
- * problem related to Scratchbox communication occurs.
- */
- public void selectTarget(String targetName) throws MicaException;
-
- /**
* Kill an Scratchbox process.
*
* @return true, if the is performed successfully.
Modified: trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.sb2/src/org/maemo/esbox/internal/scratchbox/sb2/core/Scratchbox2SDK.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -201,15 +201,6 @@
/*
* (non-Javadoc)
*
- * @see org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#getCurrentTarget()
- */
- public String getCurrentTarget() throws MicaException {
- return getMaemoSdkCommand().getDefaultRootstrap();
- }
-
- /*
- * (non-Javadoc)
- *
* @see
* org.maemo.mica.maemosdk.core.sdk.IScratchboxSDK#removeTarget(java.lang
* .String)
Modified: trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/TestSB1ProcessLauncher.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -26,7 +26,9 @@
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.IProcessMonitor;
import org.maemo.mica.common.core.process.ProcessLauncherParameters;
+import org.maemo.mica.common.core.process.StreamLineMonitorAdapter;
import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
import org.maemo.mica.common.core.sdk.ISDK;
import org.maemo.mica.common.core.sdk.ISDKProvider;
@@ -198,5 +200,46 @@
}
});
}
+
+ @Test
+ public void testSimultaneousProcesses() throws Exception {
+ runOverTargets(new IRunner() {
+
+ public void run(ISDKTarget target) throws Exception {
+ IProcessLauncher launcher = target.getProcessLauncherFactory().createProcessLauncher(
+ ProcessLauncherParameters.create("sh", "-c", "sleep 10; echo a b c d e f g h i j k l m n o p q r s t u v w x y z"));
+
+ final String[] gotLine = { null };
+ StreamLineMonitorAdapter echoChecker = new StreamLineMonitorAdapter() {
+ public void handleLine(String line, boolean errorStream) throws InterruptedException {
+ gotLine[0] = line;
+ }
+ };
+
+ // launch in background
+ launcher.queueStreamMonitor(echoChecker);
+ launcher.createProcess(null);
+ IProcessMonitor monitor = launcher.createProcessMonitor();
+ monitor.runNonBlocking();
+
+ // now, launch something else
+ LaunchResults results = createAndLaunchStockProcessForScript(
+ target, null, "ls", null);
+ assertEquals(0, results.exitCode);
+ assertEquals("", results.stderr.toString());
+ assertTrue(results.toString().length() > 0);
+
+ // now, wait for the other one to finish
+
+ monitor.waitForCompletion(null);
+ assertEquals(0, monitor.getExitValue());
+
+ // if this doesn't match, it should be some random garbage
+ // from another process or a bash shell error
+ assertEquals("a b c d e f g h i j k l m n o p q r s t u v w x y z", gotLine[0]);
+ }
+ });
+ }
+
}
Modified: trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListCommands.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListCommands.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestListCommands.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -17,14 +17,8 @@
import org.maemo.esbox.internal.scratchbox.sb1.command.ListCompilersCommand;
import org.maemo.esbox.internal.scratchbox.sb1.command.ListCputranspCommand;
import org.maemo.esbox.internal.scratchbox.sb1.command.ListDevkitsCommand;
-import org.maemo.esbox.internal.scratchbox.sb1.command.ListSessionsCommand;
import org.maemo.esbox.internal.scratchbox.sb1.command.ListTargetsCommand;
-import org.maemo.esbox.internal.scratchbox.sb1.core.Scratchbox1SDK;
-import org.maemo.esbox.scratchbox.core.sdk.ScratchboxSDKFacade;
import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.process.IProcessLauncher;
-import org.maemo.mica.common.core.process.ProcessLauncherParameters;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
/**
* Please, read file TESTS.txt for more instructions about test.
@@ -226,62 +220,6 @@
}
/**
- * This is a broken test because we do not run with PTYs, ever, so no interactive programs
- * (or sessions) will launch under scratchbox and stay alive long enough to detect.
- * @throws Exception
- */
- public void __dont_testListSessionsCommand() throws Exception {
- List<String> fakeParam = new ArrayList<String>();
- fakeParam.add("param");
-
- int numberOfSessions = 0;
-
- ListSessionsCommand listSessionsCommand = new ListSessionsCommand(sb1Command);
- List<String> sessions = null;
-
- try {
- listSessionsCommand.performCommand(fakeParam);
- fail("Invalid number of param");
- } catch (MicaException e) {
- // expected
- }
-
- sessions = listSessionsCommand.performCommand(new ArrayList<String>());
-
- // make sure anything here is a pid
- for (String pid : sessions) {
- Integer.parseInt(pid);
- }
-
- numberOfSessions = sessions.size();
-
- // launch a new session (without switching targets!)
- ISDKTarget target = ScratchboxSDKFacade.getInstance().getScratchboxSDK(Scratchbox1SDK.class).get(0).getCurrentSDKTarget();
-
- Process process = null;
- try {
- IProcessLauncher launcher = target.getProcessLauncherFactory().createProcessLauncher(
- ProcessLauncherParameters.create("/usr/bin/yes"));
- process = launcher.createProcess(null);
-
- sessions = listSessionsCommand.performCommand(new ArrayList<String>());
-
- // this either launches 1 or 2 processes
- assertTrue(numberOfSessions < sessions.size());
-
- // make sure anything here is a pid
- for (String pid : sessions) {
- Integer.parseInt(pid);
- }
- } finally {
- // kill the shell (exit, then send ctrl-d)
- process.getOutputStream().write("exit\n004\004\004\004\004\004\004\004\004".getBytes());
- process.destroy();
- }
-
- }
-
- /**
* Test method for
* {@link embedded.core.scratchbox.command.ListTargetsCommand#performCommand(java.util.List)}.
*/
Modified: trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java
===================================================================
--- trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java 2009-07-30 16:18:21 UTC (rev 1907)
+++ trunk/org.maemo.esbox.scratchbox.tests/src/org/maemo/esbox/scratchbox/tests/commands/TestScratchboxFacade.java 2009-07-30 16:35:12 UTC (rev 1908)
@@ -24,9 +24,6 @@
import org.maemo.esbox.scratchbox.core.sdk.ScratchboxSDKFacade;
import org.maemo.esbox.scratchbox.sb1.sdk.IScratchbox1SDK;
import org.maemo.mica.common.core.MicaException;
-import org.maemo.mica.common.core.process.IProcessLauncher;
-import org.maemo.mica.common.core.process.ProcessLauncherParameters;
-import org.maemo.mica.common.core.sdk.ISDKTarget;
/**
* Please, read file TESTS.txt for more instructions about test.
@@ -253,62 +250,11 @@
/**
* Test method for
- * {@link org.maemo.esbox.common.core.scratchbox.ScratchboxFacade#getSessions()}.
+ * {@link org.maemo.esbox.common.core.scratchbox.ScratchboxFacade#getDefaultTarget()}.
*
- * This is broken because PTY support is no longer wired up. Thus, none of the
- * simple programs we launch via tests will run for long enough to be detected as a session.
* @throws MicaException
*/
@Test
- public void __dont__testGetSessions() throws Exception {
- if (sdk == null) return;
- int numberOfSessions = 0;
-
- List<String> sessions = sdk.getSessions();
-
- // make sure anything here is a pid
- for (String pid : sessions) {
- Integer.parseInt(pid);
- }
-
- numberOfSessions = sessions.size();
-
- // launch a new session (without switching targets!)
- ISDKTarget target = ScratchboxSDKFacade.getInstance().getScratchboxSDK(Scratchbox1SDK.class).get(0).getCurrentSDKTarget();
- Process process = null;
- try {
- IProcessLauncher launcher = target.getProcessLauncherFactory().createProcessLauncher(
- ProcessLauncherParameters.create("bin/sh"));
- process = launcher.createProcess(null);
-
- // wait for it to really start
- Thread.sleep(5000);
-
- sessions = sdk.getSessions();// ScratchboxFacade.getInstance().getSessions(sdk);
-
- // this either launches 1 or 2 processes
- assertTrue(numberOfSessions < sessions.size());
-
- // make sure anything here is a pid
- for (String pid : sessions) {
- Integer.parseInt(pid);
- }
- } catch (Exception e) {
- fail("Exception: "+e.getMessage());
- }finally {
- // kill the shell (exit, then send ctrl-d)
- process.getOutputStream().write("exit\n004\004\004\004\004\004\004\004\004".getBytes());
- process.destroy();
- }
- }
-
- /**
- * Test method for
- * {@link org.maemo.esbox.common.core.scratchbox.ScratchboxFacade#getCurrentTarget()}.
- *
- * @throws MicaException
- */
- @Test
public void testGetCurrentTarget() throws MicaException {
if (sdk == null) return;
String currentTarget = sdk.getCurrentTarget();//ScratchboxFacade.getInstance().getCurrentTarget(sdk);
More information about the Esbox-commits
mailing list