diff options
11 files changed, 389 insertions, 35 deletions
diff --git a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF index 6b5060b3..2ef8d4e4 100644 --- a/org.eclipse.m2e.launching/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.launching/META-INF/MANIFEST.MF @@ -21,11 +21,14 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.m2e.core;bundle-version="[1.1.0,1.2.0)", com.ibm.icu;bundle-version="4.0.1", org.eclipse.m2e.core.ui;bundle-version="[1.1.0,1.2.0)", - org.slf4j.api;bundle-version="1.6.1" + org.slf4j.api;bundle-version="1.6.1", + org.eclipse.jdt.debug Eclipse-LazyStart: true Bundle-RequiredExecutionEnvironment: J2SE-1.5, JavaSE-1.6 Bundle-Vendor: %Bundle-Vendor -Export-Package: org.eclipse.m2e.actions;x-internal:=true +Export-Package: org.eclipse.m2e.actions;x-internal:=true, + org.eclipse.m2e.internal.launch;x-internal:=true, + org.eclipse.m2e.ui.internal.launch;x-internal:=true Bundle-Activator: org.eclipse.m2e.internal.launch.MavenLaunchPlugin Import-Package: org.slf4j diff --git a/org.eclipse.m2e.launching/build.properties b/org.eclipse.m2e.launching/build.properties index 76e37f3e..a2e0058c 100644 --- a/org.eclipse.m2e.launching/build.properties +++ b/org.eclipse.m2e.launching/build.properties @@ -16,7 +16,8 @@ bin.includes = META-INF/,\ icons/,\ org.eclipse.m2e.cliresolver.jar,\ org.eclipse.m2e.cliresolver30.jar,\ - about.html + about.html,\ + schema/ jars.compile.order = . source.. = src/ output.. = target/classes/ diff --git a/org.eclipse.m2e.launching/plugin.xml b/org.eclipse.m2e.launching/plugin.xml index a75d4e88..0bfc1fdb 100644 --- a/org.eclipse.m2e.launching/plugin.xml +++ b/org.eclipse.m2e.launching/plugin.xml @@ -8,6 +8,8 @@ --> <?eclipse version="3.0"?> <plugin> + <extension-point id="sourceLookupParticipants" name="sourceLookupParticipants" schema="schema/sourceLookupParticipants.exsd"/> + <extension-point id="mavenLaunchParticipants" name="mavenLaunchParticipants" schema="schema/mavenLaunchParticipants.exsd"/> <extension point="org.eclipse.ui.commands"> <command id="org.eclipse.m2e.core.pomFileAction.run" diff --git a/org.eclipse.m2e.launching/schema/mavenLaunchParticipants.exsd b/org.eclipse.m2e.launching/schema/mavenLaunchParticipants.exsd new file mode 100644 index 00000000..7d5d412a --- /dev/null +++ b/org.eclipse.m2e.launching/schema/mavenLaunchParticipants.exsd @@ -0,0 +1,102 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.m2e.launching" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.m2e.launching" id="mavenLaunchDelegates" name="mavenLaunchDelegates"/> + </appInfo> + <documentation> + Maven launch participants can contribute additional program and vm arguments to Maven launch command line. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence> + <element ref="mavenLaunchParticipant"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="mavenLaunchParticipant"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.m2e.internal.launch.IMavenLaunchDelegate"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 1.1 + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + EXPERIMENTAL + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/org.eclipse.m2e.launching/schema/sourceLookupParticipants.exsd b/org.eclipse.m2e.launching/schema/sourceLookupParticipants.exsd new file mode 100644 index 00000000..bf1f49f1 --- /dev/null +++ b/org.eclipse.m2e.launching/schema/sourceLookupParticipants.exsd @@ -0,0 +1,102 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.m2e.launching" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appInfo> + <meta.schema plugin="org.eclipse.m2e.launching" id="sourceLookupParticipants" name="sourceLookupParticipants"/> + </appInfo> + <documentation> + Maven launches source lookup participants. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appInfo> + <meta.element /> + </appInfo> + </annotation> + <complexType> + <sequence minOccurs="1" maxOccurs="unbounded"> + <element ref="sourceLookupParticipant"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute translatable="true"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="sourceLookupParticipant"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + <appInfo> + <meta.attribute kind="java" basedOn=":org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant"/> + </appInfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appInfo> + <meta.section type="since"/> + </appInfo> + <documentation> + 1.1 + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="examples"/> + </appInfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="apiinfo"/> + </appInfo> + <documentation> + EXPERIMENTAL + </documentation> + </annotation> + + <annotation> + <appInfo> + <meta.section type="implementation"/> + </appInfo> + <documentation> + [Enter information about supplied implementation of this extension point.] + </documentation> + </annotation> + + +</schema> diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/IMavenLaunchParticipant.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/IMavenLaunchParticipant.java new file mode 100644 index 00000000..39c28190 --- /dev/null +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/IMavenLaunchParticipant.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * 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: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.internal.launch; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; + + +/** + * Participates in Maven luanch command line construction. + * + * @noimplement This is an experimental interface and can be changed or removed without notice. + */ +public interface IMavenLaunchParticipant { + + /** + * Returns additional program arguments or <code>null</code>. + */ + public String getProgramArguments(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor); + + /** + * Returns additional vm arguments or <code>null</code> + */ + public String getVMArguments(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor); +} diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/LaunchingUtils.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/LaunchingUtils.java index e78938c4..ea553e23 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/LaunchingUtils.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/LaunchingUtils.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * 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: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ package org.eclipse.m2e.internal.launch; import org.eclipse.core.runtime.CoreException; diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java index 00d965af..03b681dc 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java @@ -15,12 +15,18 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.debug.core.DebugEvent; @@ -55,37 +61,50 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun private MavenLauncherConfigurationHandler m2conf; private File confFile; + private ILaunch launch; + + private IProgressMonitor monitor; + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { log.info("" + getWorkingDirectory(configuration)); //$NON-NLS-1$ log.info(" mvn" + getProgramArguments(configuration)); //$NON-NLS-1$ - runtime = MavenLaunchUtils.getMavenRuntime(configuration); + this.launch = launch; + this.monitor = monitor; - m2conf = new MavenLauncherConfigurationHandler(); - if (shouldResolveWorkspaceArtifacts(configuration)) { - m2conf.addArchiveEntry(MavenLaunchUtils.getCliResolver(runtime)); - } - MavenLaunchUtils.addUserComponents(configuration, m2conf); - runtime.createLauncherConfiguration(m2conf, monitor); - - File state = MavenPluginActivator.getDefault().getStateLocation().toFile(); try { - File dir = new File(state, "launches"); //$NON-NLS-1$ - dir.mkdirs(); - confFile = File.createTempFile("m2conf", ".tmp", dir); //$NON-NLS-1$ //$NON-NLS-2$ - launch.setAttribute(LAUNCH_M2CONF_FILE, confFile.getCanonicalPath()); - OutputStream os = new FileOutputStream(confFile); + runtime = MavenLaunchUtils.getMavenRuntime(configuration); + + m2conf = new MavenLauncherConfigurationHandler(); + if(shouldResolveWorkspaceArtifacts(configuration)) { + m2conf.addArchiveEntry(MavenLaunchUtils.getCliResolver(runtime)); + } + MavenLaunchUtils.addUserComponents(configuration, m2conf); + runtime.createLauncherConfiguration(m2conf, monitor); + + File state = MavenPluginActivator.getDefault().getStateLocation().toFile(); try { - m2conf.save(os); - } finally { - os.close(); + File dir = new File(state, "launches"); //$NON-NLS-1$ + dir.mkdirs(); + confFile = File.createTempFile("m2conf", ".tmp", dir); //$NON-NLS-1$ //$NON-NLS-2$ + launch.setAttribute(LAUNCH_M2CONF_FILE, confFile.getCanonicalPath()); + OutputStream os = new FileOutputStream(confFile); + try { + m2conf.save(os); + } finally { + os.close(); + } + } catch(IOException e) { + throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, + Messages.MavenLaunchDelegate_error_cannot_create_conf, e)); } - } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, Messages.MavenLaunchDelegate_error_cannot_create_conf, e)); + + super.launch(configuration, mode, launch, monitor); + } finally { + this.launch = null; + this.monitor = null; } - - super.launch(configuration, mode, launch, monitor); } public IVMRunner getVMRunner(final ILaunchConfiguration configuration, String mode) throws CoreException { @@ -117,9 +136,19 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun } public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException { - return getProperties(configuration) + // - getPreferences(configuration) + " " + // //$NON-NLS-1$ - getGoals(configuration); + StringBuilder sb = new StringBuilder(); + sb.append(getProperties(configuration)); + sb.append(" ").append(getPreferences(configuration)); + sb.append(" ").append(getGoals(configuration)); + + for(IMavenLaunchParticipant delegate : getDelegates()) { + String programArguments = delegate.getProgramArguments(configuration, launch, monitor); + if(programArguments != null) { + sb.append(" ").append(programArguments); + } + } + + return sb.toString(); } public String getVMArguments(ILaunchConfiguration configuration) throws CoreException { @@ -139,7 +168,7 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun // workspace artifact resolution if (shouldResolveWorkspaceArtifacts(configuration)) { File state = MavenPluginActivator.getDefault().getMavenProjectManager().getWorkspaceStateFile(); - sb.append("-Dm2eclipse.workspace.state=").append(quote(state.getAbsolutePath())); //$NON-NLS-1$ + sb.append(" -Dm2eclipse.workspace.state=").append(quote(state.getAbsolutePath())); //$NON-NLS-1$ } // maven.home @@ -154,6 +183,13 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun // user configured entries sb.append(" ").append(super.getVMArguments(configuration)); //$NON-NLS-1$ + for(IMavenLaunchParticipant delegate : getDelegates()) { + String vmArguments = delegate.getVMArguments(configuration, launch, monitor); + if(vmArguments != null) { + sb.append(" ").append(vmArguments); + } + } + return sb.toString(); } @@ -345,5 +381,25 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun } } - + private List<IMavenLaunchParticipant> getDelegates() { + List<IMavenLaunchParticipant> delegates = new ArrayList<IMavenLaunchParticipant>(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.m2e.launching.mavenLaunchParticipants"); + if(extensionPoint != null) { + IExtension[] extensions = extensionPoint.getExtensions(); + for(IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for(IConfigurationElement element : elements) { + try { + delegates.add((IMavenLaunchParticipant) element.createExecutableExtension("class")); + } catch(CoreException ex) { + log.debug("Problem with external extension point", ex); + } + } + } + } + + return delegates; + } } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchUtils.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchUtils.java index a3dd41db..ed611805 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchUtils.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchUtils.java @@ -33,11 +33,13 @@ import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.core.project.IMavenProjectRegistry; import org.eclipse.osgi.util.NLS; +import org.osgi.framework.Bundle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.ibm.icu.util.StringTokenizer; + /** * MavenLaunchUtils * @@ -60,12 +62,19 @@ public class MavenLaunchUtils { public static String getCliResolver(MavenRuntime runtime) throws CoreException { String jarname; String runtimeVersion = runtime.getVersion(); - if (runtimeVersion.startsWith("3.")) { //$NON-NLS-1$ + if(runtimeVersion.startsWith("3.")) { //$NON-NLS-1$ jarname = "org.eclipse.m2e.cliresolver30.jar"; //$NON-NLS-1$ } else { jarname = "org.eclipse.m2e.cliresolver.jar"; //$NON-NLS-1$ } - URL url = MavenLaunchPlugin.getDefault().getBundle().getEntry(jarname); + return getBundleEntry(MavenLaunchPlugin.getDefault().getBundle(), jarname); + } + + /** + * Returns bundle entry path on local filesystem. + */ + public static String getBundleEntry(Bundle bundle, String entryPath) throws CoreException { + URL url = bundle.getEntry(entryPath); try { URL fileURL = FileLocator.toFileURL(url); // MNGECLIPSE-804 workaround for spaces in the original path diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenSourceLocator.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenSourceLocator.java index 581e969e..62c11092 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenSourceLocator.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenSourceLocator.java @@ -11,18 +11,51 @@ package org.eclipse.m2e.internal.launch; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author Eugene Kuleshov */ public class MavenSourceLocator extends AbstractSourceLookupDirector { + private static final Logger log = LoggerFactory.getLogger(MavenSourceLocator.class); public void initializeParticipants() { - addParticipants(new ISourceLookupParticipant[] {new JavaSourceLookupParticipant()}); - } + List<ISourceLookupParticipant> participants = new ArrayList<ISourceLookupParticipant>(); -} + // TODO is it possible to avoid unconditional activation of all registered participants? + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.m2e.launching.sourceLookupParticipants"); + if(extensionPoint != null) { + IExtension[] extensions = extensionPoint.getExtensions(); + for(IExtension extension : extensions) { + IConfigurationElement[] elements = extension.getConfigurationElements(); + for(IConfigurationElement element : elements) { + try { + participants.add((ISourceLookupParticipant) element.createExecutableExtension("class")); + } catch(CoreException ex) { + log.debug("Problem with external extension point", ex); + } + } + } + } + + participants.add(new JavaSourceLookupParticipant()); + + addParticipants(participants.toArray(new ISourceLookupParticipant[participants.size()])); + } +} diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchConfigurationTabGroup.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchConfigurationTabGroup.java index 0326c590..0445adfb 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchConfigurationTabGroup.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchConfigurationTabGroup.java @@ -17,6 +17,7 @@ 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.eclipse.debug.ui.sourcelookup.SourceLookupTab; public class MavenLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup { @@ -25,10 +26,10 @@ public class MavenLaunchConfigurationTabGroup extends AbstractLaunchConfiguratio new MavenLaunchMainTab(false), new MavenJRETab(), new RefreshTab(), + new SourceLookupTab(), new EnvironmentTab(), new CommonTab()}; setTabs(tabs); } } - |