Author: simoneg
Date: Mon Aug 24 13:28:18 2009
New Revision: 807206
URL: http://svn.apache.org/viewvc?rev=807206&view=rev
Log:
LABS-417 : Magma run configurations, shortcut, and toolbar calling
configurations
Added:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchDelegate.java
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchTabGroup.java
Modified:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/RunMagmaHandler.java
Modified:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/RunMagmaHandler.java
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/RunMagmaHandler.java?rev=807206&r1=807205&r2=807206&view=diff
==============================================================================
---
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/RunMagmaHandler.java
(original)
+++
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/RunMagmaHandler.java
Mon Aug 24 13:28:18 2009
@@ -2,6 +2,7 @@
import java.util.Iterator;
+import org.apache.magma.tools.magmaeclipse.launch.MagmaLaunchShortcut;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -24,7 +25,7 @@
String type = event.getParameter("type");
if (type == null) type = "run";
if (goals == null) goals = "clean install";
- ExecutePomAction epa = new ExecutePomAction();
+ MagmaLaunchShortcut epa = new MagmaLaunchShortcut();
epa.setInitializationData(null, null, goals);
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
IProject project = null;
Added:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchDelegate.java
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchDelegate.java?rev=807206&view=auto
==============================================================================
---
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchDelegate.java
(added)
+++
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchDelegate.java
Mon Aug 24 13:28:18 2009
@@ -0,0 +1,31 @@
+package org.apache.magma.tools.magmaeclipse.launch;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.maven.ide.eclipse.internal.launch.MavenLaunchDelegate;
+
+public class MagmaLaunchDelegate extends MavenLaunchDelegate {
+
+ @Override
+ public String getVMArguments(ILaunchConfiguration configuration)
+ throws CoreException {
+ String sup = super.getVMArguments(configuration);
+ if (sup == null) sup = "";
+ if (sup.indexOf("Xmx") == -1) {
+ sup += "-Xmx256m";
+ }
+ return sup;
+ }
+
+ @Override
+ protected String getGoals(ILaunchConfiguration configuration)
+ throws CoreException {
+ String sup = super.getGoals(configuration);
+ if (sup == null) sup = "";
+ if (sup.length() == 0) {
+ sup = "magma:run";
+ }
+ return sup;
+ }
+
+}
Added:
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=807206&view=auto
==============================================================================
---
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
(added)
+++
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchShortcut.java
Mon Aug 24 13:28:18 2009
@@ -0,0 +1,188 @@
+package org.apache.magma.tools.magmaeclipse.launch;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.magma.tools.magmaeclipse.MLog;
+import org.apache.magma.tools.magmaeclipse.basics.MagmaPDEUtils;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExecutableExtension;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.ILaunchShortcut2;
+import org.eclipse.debug.ui.RefreshTab;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchShortcut;
+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.maven.ide.eclipse.actions.MavenLaunchConstants;
+
+public class MagmaLaunchShortcut implements ILaunchShortcut2,
+ IExecutableExtension {
+
+ protected String goalName;
+
+ public ILaunchConfiguration[] getLaunchConfigurations(ISelection
selection) {
+ return null;
+ }
+
+ public ILaunchConfiguration[] getLaunchConfigurations(IEditorPart
editorpart) {
+ return null;
+ }
+
+ public IResource getLaunchableResource(ISelection selection) {
+ if (selection instanceof IStructuredSelection) {
+ IStructuredSelection ss = (IStructuredSelection)
selection;
+ if (ss.size() == 1) {
+ Object element = ss.getFirstElement();
+ if (element instanceof IResource) {
+ return
getLaunchableResource((IResource) element);
+ }
+ }
+ }
+ return null;
+ }
+
+ protected IResource getLaunchableResource(IResource element) {
+ return element.getProject();
+ }
+
+ public IResource getLaunchableResource(IEditorPart editorpart) {
+ return getLaunchableResource((IResource)
editorpart.getEditorInput()
+ .getAdapter(IResource.class));
+ }
+
+ public void launch(IEditorPart editor, String mode) {
+ IEditorInput input = editor.getEditorInput();
+ IResource mr = (IResource) input.getAdapter(IResource.class);
+ if (mr != null) {
+ searchAndLaunch(mr, mode);
+ }
+ }
+
+ public void launch(ISelection selection, String mode) {
+ if (selection instanceof IStructuredSelection) {
+ searchAndLaunch(((IStructuredSelection) selection)
+ .getFirstElement(), mode);
+ }
+ }
+
+ protected void searchAndLaunch(Object obj, String mode) {
+ IProject prj = null;
+ if (obj == null)
+ return;
+ if (obj instanceof IProject) {
+ prj = (IProject) obj;
+ } else if (obj instanceof IResource) {
+ prj = ((IResource) obj).getProject();
+ } else if (obj instanceof IAdaptable) {
+ prj = (IProject) ((IAdaptable)
obj).getAdapter(IProject.class);
+ if (prj == null) {
+ IResource res = (IResource) ((IAdaptable) obj)
+ .getAdapter(IResource.class);
+ if (res != null) {
+ prj = res.getProject();
+ }
+ }
+ }
+ if (prj == null)
+ return;
+ launch(prj, mode);
+ }
+
+ protected ILaunchConfigurationType getConfigurationType() {
+ ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
+ return
lm.getLaunchConfigurationType(MagmaPDEUtils.ID_LAUNCH_TYPE);
+ }
+
+ protected void launch(IProject prj, String mode) {
+ ILaunchConfiguration config = findLaunchConfiguration(prj,
+ getConfigurationType());
+ if (config == null) {
+ config = createConfiguration(prj);
+ }
+ if (config != null) {
+ DebugUITools.launch(config, mode);
+ }
+ }
+
+ protected ILaunchConfiguration createConfiguration(IProject prj) {
+ ILaunchConfiguration config = null;
+ try {
+ ILaunchConfigurationType configType =
getConfigurationType();
+ ILaunchConfigurationWorkingCopy wc =
configType.newInstance(null,
+
DebugPlugin.getDefault().getLaunchManager()
+
.generateUniqueLaunchConfigurationNameFrom(
+
prj.getName()));
+ wc.setAttribute(MavenLaunchConstants.ATTR_POM_DIR,
+ "${workspace_loc:" +
prj.getFullPath().toString() + "}");
+ wc.setAttribute(MavenLaunchConstants.ATTR_GOALS,
this.goalName == null ? "magma:run" : this.goalName);
+ 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");
+ }
+ return config;
+ }
+
+ protected ILaunchConfiguration findLaunchConfiguration(IProject type,
+ ILaunchConfigurationType configType) {
+ List candidateConfigs = Collections.EMPTY_LIST;
+ try {
+ File root = type.getLocation().toFile();
+ ILaunchConfiguration[] configs =
DebugPlugin.getDefault()
+
.getLaunchManager().getLaunchConfigurations(configType);
+ candidateConfigs = new ArrayList(configs.length);
+ 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.getAbsolutePath().startsWith(root.getAbsolutePath())) {
+ if (this.goalName == null ||
goals.indexOf(" " + this.goalName + " ") > -1) {
+ candidateConfigs.add(config);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ MLog.exception(e, "Finding candidate configurations");
+ }
+ int candidateCount = candidateConfigs.size();
+ if (candidateCount >= 1) {
+ return (ILaunchConfiguration) candidateConfigs.get(0);
+ }
+ return null;
+ }
+
+ public void setInitializationData(IConfigurationElement config,
+ String propertyName, Object data) {
+ if (data != null) {
+ this.goalName = (String) data;
+ }
+ }
+
+}
\ No newline at end of file
Added:
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchTabGroup.java
URL:
http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchTabGroup.java?rev=807206&view=auto
==============================================================================
---
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchTabGroup.java
(added)
+++
labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/launch/MagmaLaunchTabGroup.java
Mon Aug 24 13:28:18 2009
@@ -0,0 +1,39 @@
+package org.apache.magma.tools.magmaeclipse.launch;
+
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.EnvironmentTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+import org.eclipse.debug.ui.RefreshTab;
+import org.maven.ide.eclipse.actions.MavenLaunchConstants;
+import org.maven.ide.eclipse.ui.internal.launch.MavenJRETab;
+import org.maven.ide.eclipse.ui.internal.launch.MavenLaunchMainTab;
+
+...@suppresswarnings("restriction")
+public class MagmaLaunchTabGroup extends AbstractLaunchConfigurationTabGroup {
+
+ public void createTabs(ILaunchConfigurationDialog dialog, String mode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
+ new MavenLaunchMainTab(false),
+ new MavenJRETab(),
+ new RefreshTab(),
+ new EnvironmentTab(),
+ new CommonTab()};
+ setTabs(tabs);
+ }
+
+ @Override
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(MavenLaunchConstants.ATTR_GOALS,
"magma:run");
+ super.setDefaults(configuration);
+ }
+
+ @Override
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ super.initializeFrom(configuration);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]