You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/10/06 02:32:32 UTC
svn commit: r822096 -
/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
Author: simoneg
Date: Tue Oct 6 00:32:32 2009
New Revision: 822096
URL: http://svn.apache.org/viewvc?rev=822096&view=rev
Log:
LABS-442 : warn and eventually terminate a running magma:run when starting a new one.
Modified:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
Modified: labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java?rev=822096&r1=822095&r2=822096&view=diff
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java (original)
+++ labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java Tue Oct 6 00:32:32 2009
@@ -15,6 +15,7 @@
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -22,11 +23,12 @@
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchShortcut2;
import org.eclipse.debug.ui.RefreshTab;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
-import org.eclipse.wst.common.internal.emf.resource.RootTranslator;
import org.maven.ide.eclipse.actions.MavenLaunchConstants;
public class MagmaLaunchShortcut implements ILaunchShortcut2,
@@ -108,8 +110,42 @@
}
protected void launch(IProject prj, String mode) {
- ILaunchConfiguration config = findLaunchConfiguration(prj,
- getConfigurationType());
+ ILaunchConfigurationType myconftype = getConfigurationType();
+
+ // Check for another already running magma:run
+ String mygoals = this.goalName == null ? "magma:run" : this.goalName;
+ if (mygoals.equals("magma:run")) {
+ boolean killrunnings = false;
+ ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
+ for (ILaunch launch : launches) {
+ if (!launch.isTerminated()) {
+ ILaunchConfiguration conf = launch.getLaunchConfiguration();
+ if (conf != null) {
+ try {
+ ILaunchConfigurationType type = conf.getType();
+ if (type != null && type.getIdentifier().equals(myconftype.getIdentifier())) {
+ String goals = " " + conf.getAttribute(MavenLaunchConstants.ATTR_GOALS, "") + " ";
+ if (goals.indexOf(" magma:run ") != -1) {
+ if (killrunnings ||
+ MessageDialog.openQuestion(
+ Display.getCurrent().getActiveShell(),
+ "Magma:run already running",
+ "Magma is already running, and running two at the same time will probably cause port conflicts. Do you want to stop the currently running one?")) {
+ killrunnings = true;
+ launch.terminate();
+ }
+ }
+ }
+ } catch (CoreException e) {
+ MLog.exception(e, "While checking running configurations");
+ }
+ }
+ }
+ }
+ }
+
+
+ ILaunchConfiguration config = findLaunchConfiguration(prj, getConfigurationType());
if (config == null) {
config = createConfiguration(prj);
}
@@ -133,6 +169,7 @@
wc.setAttribute(MavenLaunchConstants.ATTR_GOALS, goals);
wc.setAttribute(RefreshTab.ATTR_REFRESH_SCOPE, "${project}");
wc.setAttribute(RefreshTab.ATTR_REFRESH_RECURSIVE, true);
+
config = wc.doSave();
} catch (CoreException ce) {
MLog.exception(ce, "Error setting up new configuration");
@@ -150,24 +187,27 @@
candidateConfigs = new ArrayList(configs.length);
String mygoals = this.goalName == null ? "magma:run" : this.goalName;
for (int i = 0; i < configs.length; i++) {
- ILaunchConfiguration config = configs[i];
- String pomDir = config.getAttribute(
- MavenLaunchConstants.ATTR_POM_DIR, "");
- String goals = " " + config.getAttribute(
- MavenLaunchConstants.ATTR_GOALS, "") + " ";
- pomDir = VariablesPlugin.getDefault()
- .getStringVariableManager().performStringSubstitution(
- pomDir);
- File accpd = new File(pomDir);
- if (accpd.equals(root)) {
- if (mygoals == null || goals.indexOf(" " + mygoals + " ") > -1) {
- candidateConfigs.add(config);
+ try {
+ ILaunchConfiguration config = configs[i];
+ String pomDir = config.getAttribute(
+ MavenLaunchConstants.ATTR_POM_DIR, "");
+ String goals = " " + config.getAttribute(
+ MavenLaunchConstants.ATTR_GOALS, "") + " ";
+ pomDir = VariablesPlugin.getDefault()
+ .getStringVariableManager().performStringSubstitution(pomDir);
+ File accpd = new File(pomDir);
+ if (accpd.equals(root)) {
+ if (mygoals == null || goals.indexOf(" " + mygoals + " ") > -1) {
+ candidateConfigs.add(config);
+ }
}
- }
+ } catch (CoreException e) {
+ MLog.exception(e, "Parsing a configuration");
+ }
}
} catch (CoreException e) {
MLog.exception(e, "Finding candidate configurations");
- }
+ }
int candidateCount = candidateConfigs.size();
if (candidateCount >= 1) {
return (ILaunchConfiguration) candidateConfigs.get(0);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org