diff options
author | Igor Fedorenko | 2011-12-19 03:48:22 +0000 |
---|---|---|
committer | Igor Fedorenko | 2011-12-19 03:48:22 +0000 |
commit | 3ecc071ad0eb0950c0369613b20e1fce4fc35cd2 (patch) | |
tree | f8ad4b09f6bc69b3fe4be0c48b99ee525b3c9dca /org.eclipse.m2e.launching/src | |
parent | b013a568c5946b1603b8659bf91423dc772d8942 (diff) | |
download | m2e-core-3ecc071ad0eb0950c0369613b20e1fce4fc35cd2.tar.gz m2e-core-3ecc071ad0eb0950c0369613b20e1fce4fc35cd2.tar.xz m2e-core-3ecc071ad0eb0950c0369613b20e1fce4fc35cd2.zip |
366998 maven launch configuration extensibility API
Collapsed mavenLaunchParticipants and sourceLookupParticipants extension
points. mavenLaunchParticipants can now provide list of source lookup
participants.
Introduced launch configuration tab to see, enable and disable available
launch participants.
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.launching/src')
10 files changed, 366 insertions, 111 deletions
diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/MavenLaunchConstants.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/MavenLaunchConstants.java index 0d48f535..88565093 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/MavenLaunchConstants.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/actions/MavenLaunchConstants.java @@ -14,6 +14,8 @@ package org.eclipse.m2e.actions; import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; public interface MavenLaunchConstants { + public final String PLUGIN_ID = "org.eclipse.m2e.launching"; + // this should correspond with launchConfigurationType.id attribute in plugin.xml! public final String LAUNCH_CONFIGURATION_TYPE_ID = "org.eclipse.m2e.Maven2LaunchConfigurationType"; //$NON-NLS-1$ public final String BUILDER_CONFIGURATION_TYPE_ID = "org.eclipse.m2e.Maven2BuilderConfigurationType"; //$NON-NLS-1$ @@ -43,4 +45,6 @@ public interface MavenLaunchConstants { // hidden (for now) list of workspace components to be pushed into maven runtime public final String ATTR_FORCED_COMPONENTS_LIST = "M2_FORCED_COMPONENTS_LIST"; //$NON-NLS-1$ + + public final String ATTR_DISABLED_EXTENSIONS = "M2_DISABLED_EXTENSIONS"; } 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 index 39c28190..01ed744b 100644 --- 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. + * Copyright (c) 2011 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 @@ -11,13 +11,16 @@ package org.eclipse.m2e.internal.launch; +import java.util.List; + import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; /** - * Participates in Maven luanch command line construction. + * Participates in Maven launch command line construction, execution and debug. * * @noimplement This is an experimental interface and can be changed or removed without notice. */ @@ -32,4 +35,10 @@ public interface IMavenLaunchParticipant { * Returns additional vm arguments or <code>null</code> */ public String getVMArguments(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor); + + /** + * Returns additional source lookup participants or <code>null</code> + */ + public List<ISourceLookupParticipant> getSourceLookupParticipants(ILaunchConfiguration configuration, ILaunch launch, + IProgressMonitor monitor); } 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 03b681dc..243f00af 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 @@ -18,15 +18,11 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; 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; @@ -35,16 +31,18 @@ import org.eclipse.debug.core.IDebugEventSetListener; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.model.IProcess; +import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant; import org.eclipse.debug.ui.RefreshTab; import org.eclipse.jdt.launching.IVMRunner; import org.eclipse.jdt.launching.JavaLaunchDelegate; import org.eclipse.jdt.launching.VMRunnerConfiguration; +import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; import org.eclipse.m2e.actions.MavenLaunchConstants; import org.eclipse.m2e.core.MavenPlugin; import org.eclipse.m2e.core.embedder.IMavenConfiguration; import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; -import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.osgi.util.NLS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,23 +53,29 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun private static final String LAUNCHER_TYPE = "org.codehaus.classworlds.Launcher"; //$NON-NLS-1$ private static final String LAUNCHER_TYPE3 = "org.codehaus.plexus.classworlds.launcher.Launcher"; // classworlds 2.0 //$NON-NLS-1$ + private static final String LAUNCH_M2CONF_FILE = "org.eclipse.m2e.internal.launch.M2_CONF"; //$NON-NLS-1$ private org.eclipse.m2e.core.embedder.MavenRuntime runtime; + private MavenLauncherConfigurationHandler m2conf; + private File confFile; private ILaunch launch; private IProgressMonitor monitor; + private List<IMavenLaunchParticipant> participants; + 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$ - this.launch = launch; this.monitor = monitor; + this.participants = getParticipants(configuration, launch); + + log.info("" + getWorkingDirectory(configuration)); //$NON-NLS-1$ + log.info(" mvn" + getProgramArguments(configuration)); //$NON-NLS-1$ try { runtime = MavenLaunchUtils.getMavenRuntime(configuration); @@ -96,10 +100,26 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun os.close(); } } catch(IOException e) { - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, + throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, -1, Messages.MavenLaunchDelegate_error_cannot_create_conf, e)); } + if(launch.getSourceLocator() instanceof MavenSourceLocator) { + MavenSourceLocator sourceLocator = (MavenSourceLocator) launch.getSourceLocator(); + for(IMavenLaunchParticipant participant : participants) { + List<ISourceLookupParticipant> sourceLookupParticipants = participant.getSourceLookupParticipants( + configuration, launch, monitor); + if(sourceLookupParticipants != null) { + sourceLocator.addParticipants(sourceLookupParticipants + .toArray(new ISourceLookupParticipant[sourceLookupParticipants.size()])); + } + } + sourceLocator.addParticipants(new ISourceLookupParticipant[] {new JavaSourceLookupParticipant()}); + } else { + log.warn(NLS.bind(Messages.MavenLaynchDelegate_unsupported_source_locator, launch.getSourceLocator().getClass() + .getCanonicalName())); + } + super.launch(configuration, mode, launch, monitor); } finally { this.launch = null; @@ -109,14 +129,14 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun public IVMRunner getVMRunner(final ILaunchConfiguration configuration, String mode) throws CoreException { final IVMRunner runner = super.getVMRunner(configuration, mode); - + return new IVMRunner() { public void run(VMRunnerConfiguration runnerConfiguration, ILaunch launch, IProgressMonitor monitor) throws CoreException { runner.run(runnerConfiguration, launch, monitor); - + IProcess[] processes = launch.getProcesses(); - if(processes!=null && processes.length>0) { + if(processes != null && processes.length > 0) { BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, launch); refresher.init(); } else { @@ -127,7 +147,7 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun } public String getMainTypeName(ILaunchConfiguration configuration) throws CoreException { - return runtime.getVersion().startsWith("3.0")? LAUNCHER_TYPE3: LAUNCHER_TYPE; //$NON-NLS-1$ + return runtime.getVersion().startsWith("3.0") ? LAUNCHER_TYPE3 : LAUNCHER_TYPE; //$NON-NLS-1$ } public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException { @@ -141,8 +161,8 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun sb.append(" ").append(getPreferences(configuration)); sb.append(" ").append(getGoals(configuration)); - for(IMavenLaunchParticipant delegate : getDelegates()) { - String programArguments = delegate.getProgramArguments(configuration, launch, monitor); + for(IMavenLaunchParticipant participant : participants) { + String programArguments = participant.getProgramArguments(configuration, launch, monitor); if(programArguments != null) { sb.append(" ").append(programArguments); } @@ -166,14 +186,14 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun StringBuffer sb = new StringBuffer(); // workspace artifact resolution - if (shouldResolveWorkspaceArtifacts(configuration)) { + if(shouldResolveWorkspaceArtifacts(configuration)) { File state = MavenPluginActivator.getDefault().getMavenProjectManager().getWorkspaceStateFile(); sb.append(" -Dm2eclipse.workspace.state=").append(quote(state.getAbsolutePath())); //$NON-NLS-1$ } // maven.home String location = runtime.getLocation(); - if (location != null) { + if(location != null) { sb.append(" -Dmaven.home=").append(quote(location)); //$NON-NLS-1$ } @@ -183,8 +203,8 @@ 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); + for(IMavenLaunchParticipant participant : participants) { + String vmArguments = participant.getVMArguments(configuration, launch, monitor); if(vmArguments != null) { sb.append(" ").append(vmArguments); } @@ -208,7 +228,7 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) { return false; } - + /** * Construct string with properties to pass to JVM as system properties */ @@ -276,11 +296,11 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun if(configuration.getAttribute(MavenLaunchConstants.ATTR_UPDATE_SNAPSHOTS, false)) { sb.append(" -U"); //$NON-NLS-1$ } - + if(configuration.getAttribute(MavenLaunchConstants.ATTR_NON_RECURSIVE, false)) { sb.append(" -N"); //$NON-NLS-1$ } - + if(configuration.getAttribute(MavenLaunchConstants.ATTR_SKIP_TESTS, false)) { sb.append(" -Dmaven.test.skip=true"); //$NON-NLS-1$ } @@ -306,63 +326,62 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun // if(s != null && s.trim().length() > 0) { // sb.append(" -D").append(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY).append("=").append(s); // } - + return sb.toString(); } static void removeTempFiles(ILaunch launch) { String m2confName = launch.getAttribute(LAUNCH_M2CONF_FILE); - if (m2confName != null) { + if(m2confName != null) { new File(m2confName).delete(); } } /** - * Refreshes resources as specified by a launch configuration, when - * an associated process terminates. - * - * Adapted from org.eclipse.ui.externaltools.internal.program.launchConfigurations.BackgroundResourceRefresher + * Refreshes resources as specified by a launch configuration, when an associated process terminates. Adapted from + * org.eclipse.ui.externaltools.internal.program.launchConfigurations.BackgroundResourceRefresher */ - public static class BackgroundResourceRefresher implements IDebugEventSetListener { + public static class BackgroundResourceRefresher implements IDebugEventSetListener { final ILaunchConfiguration configuration; + final IProcess process; + final ILaunch launch; - + public BackgroundResourceRefresher(ILaunchConfiguration configuration, ILaunch launch) { this.configuration = configuration; this.process = launch.getProcesses()[0]; this.launch = launch; } - + /** - * If the process has already terminated, resource refreshing is done - * immediately in the current thread. Otherwise, refreshing is done when the - * process terminates. + * If the process has already terminated, resource refreshing is done immediately in the current thread. Otherwise, + * refreshing is done when the process terminates. */ public void init() { - synchronized (process) { - if (process.isTerminated()) { + synchronized(process) { + if(process.isTerminated()) { processResources(); } else { DebugPlugin.getDefault().addDebugEventListener(this); } } } - + /* (non-Javadoc) * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[]) */ public void handleDebugEvents(DebugEvent[] events) { - for (int i = 0; i < events.length; i++) { + for(int i = 0; i < events.length; i++ ) { DebugEvent event = events[i]; - if (event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) { + if(event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) { DebugPlugin.getDefault().removeDebugEventListener(this); processResources(); break; } } } - + protected void processResources() { removeTempFiles(launch); @@ -371,35 +390,33 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun try { RefreshTab.refreshResources(configuration, monitor); return Status.OK_STATUS; - } catch (CoreException e) { + } catch(CoreException e) { log.error(e.getMessage(), e); return e.getStatus(); - } + } } }; job.schedule(); } } - private List<IMavenLaunchParticipant> getDelegates() { - List<IMavenLaunchParticipant> delegates = new ArrayList<IMavenLaunchParticipant>(); + private List<IMavenLaunchParticipant> getParticipants(ILaunchConfiguration configuration, ILaunch launch) + throws CoreException { + @SuppressWarnings("unchecked") + Set<String> disabledExtensions = configuration.getAttribute(ATTR_DISABLED_EXTENSIONS, Collections.EMPTY_SET); + + List<IMavenLaunchParticipant> participants = 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); - } + for(MavenLaunchParticipantInfo info : MavenLaunchParticipantInfo.readParticipantsInfo()) { + if(!disabledExtensions.contains(info.getId()) && info.getModes().contains(launch.getLaunchMode())) { + try { + participants.add(info.createParticipant()); + } catch(CoreException e) { + log.debug("Problem with external extension point", e); } } } - return delegates; + return participants; } } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchParticipantInfo.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchParticipantInfo.java new file mode 100644 index 00000000..36c78115 --- /dev/null +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchParticipantInfo.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2011 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 java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.StringTokenizer; + +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; + + +public class MavenLaunchParticipantInfo { + + private final IConfigurationElement extension; + + private MavenLaunchParticipantInfo(IConfigurationElement extension) { + this.extension = extension; + } + + public String getId() { + return extension.getAttribute("id"); + } + + public String getName() { + return extension.getAttribute("name"); + } + + public IMavenLaunchParticipant createParticipant() throws CoreException { + return (IMavenLaunchParticipant) extension.createExecutableExtension("class"); + } + + public List<String> getModes() { + String modes = extension.getAttribute("modes"); + if(modes == null) { + return Collections.emptyList(); + } + List<String> result = new ArrayList<String>(); + StringTokenizer st = new StringTokenizer(modes, ","); + while(st.hasMoreTokens()) { + result.add(st.nextToken().trim()); + } + return result; + } + + public static List<MavenLaunchParticipantInfo> readParticipantsInfo() { + List<MavenLaunchParticipantInfo> result = new ArrayList<MavenLaunchParticipantInfo>(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.m2e.launching.mavenLaunchParticipants"); + if(extensionPoint != null) { + for(IExtension extension : extensionPoint.getExtensions()) { + for(IConfigurationElement element : extension.getConfigurationElements()) { + result.add(new MavenLaunchParticipantInfo(element)); + } + } + } + + return result; + } +} 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 ed611805..ed51974d 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 @@ -29,7 +29,6 @@ import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; import org.eclipse.m2e.core.embedder.MavenRuntime; import org.eclipse.m2e.core.embedder.MavenRuntimeManager; -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; @@ -53,7 +52,7 @@ public class MavenLaunchUtils { String location = configuration.getAttribute(MavenLaunchConstants.ATTR_RUNTIME, ""); //$NON-NLS-1$ MavenRuntime runtime = runtimeManager.getRuntime(location); if(runtime == null) { - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, // + throw new CoreException(new Status(IStatus.ERROR, MavenLaunchConstants.PLUGIN_ID, -1, // NLS.bind(Messages.MavenLaunchUtils_error_no_maven_install, location), null)); } return runtime; @@ -81,14 +80,15 @@ public class MavenLaunchUtils { URI fileURI = new URI(fileURL.getProtocol(), fileURL.getHost(), fileURL.getPath(), fileURL.getQuery()); return new File(fileURI).getCanonicalPath(); } catch(Exception ex) { - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, ex.getMessage(), ex)); + throw new CoreException(new Status(IStatus.ERROR, MavenLaunchConstants.PLUGIN_ID, -1, ex.getMessage(), ex)); } } public static void addUserComponents(ILaunchConfiguration configuration, IMavenLauncherConfiguration collector) throws CoreException { @SuppressWarnings("unchecked") - List<String> list = configuration.getAttribute(MavenLaunchConstants.ATTR_FORCED_COMPONENTS_LIST, new ArrayList()); + List<String> list = configuration.getAttribute(MavenLaunchConstants.ATTR_FORCED_COMPONENTS_LIST, + new ArrayList<String>()); if(list == null) { return; } 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 62c11092..5cfb5901 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,51 +11,15 @@ 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() { - 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()])); + // enabled source lookup participants are calculated dynamically by MavenLaunchDelegate } } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/Messages.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/Messages.java index 6aafc24f..4bb742c3 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/Messages.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/Messages.java @@ -9,7 +9,6 @@ * Sonatype, Inc. - initial API and implementation *******************************************************************************/ - package org.eclipse.m2e.internal.launch; import org.eclipse.osgi.util.NLS; @@ -32,6 +31,8 @@ public class Messages extends NLS { public static String MavenLaunchDelegate_job_name; + public static String MavenLaynchDelegate_unsupported_source_locator; + public static String MavenLaunchMainTab_btnAfterClean; public static String MavenLaunchMainTab_btnAutoBuild; @@ -68,6 +69,10 @@ public class Messages extends NLS { public static String MavenLaunchMainTab_property_dialog_title; + public static String MavenLaunchExtensionsTab_name; + + public static String MavenLaunchExtensionsTab_lblExtensions; + public static String MavenLaunchUtils_error_no_maven_install; public static String launchPomGroup; diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/messages.properties b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/messages.properties index 18505e16..73e5aa22 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/messages.properties +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/messages.properties @@ -5,6 +5,7 @@ ExecutePomAction_executing=Executing {0} in {1} MavenFileEditorInput_0=Unable to open {0} MavenLaunchDelegate_error_cannot_create_conf=Can't create m2.conf MavenLaunchDelegate_job_name=Refreshing resources... +MavenLaynchDelegate_unsupported_source_locator=Unknown or unsupported source locator {0} MavenLaunchMainTab_btnAfterClean=Selec&t... MavenLaunchMainTab_btnAutoBuild=&Select... MavenLaunchMainTab_btnCleanBuild=Se&lect... @@ -23,6 +24,8 @@ MavenLaunchMainTab_lblManualGoals=Ma&nual Build Goals: MavenLaunchMainTab_lblRuntime=Maven Runt&ime: MavenLaunchMainTab_property_dialog_edit_title=Edit Parameter MavenLaunchMainTab_property_dialog_title=Add Parameter +MavenLaunchExtensionsTab_name=Launch Extensions +MavenLaunchExtensionsTab_lblExtensions=Maven Launch Extensions MavenLaunchUtils_error_no_maven_install=Can't find Maven installation {0} 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 0445adfb..2128066e 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 @@ -11,6 +11,9 @@ package org.eclipse.m2e.ui.internal.launch; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup; import org.eclipse.debug.ui.CommonTab; import org.eclipse.debug.ui.EnvironmentTab; @@ -18,18 +21,28 @@ 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; +import org.eclipse.m2e.internal.launch.MavenLaunchParticipantInfo; + public class MavenLaunchConfigurationTabGroup extends AbstractLaunchConfigurationTabGroup { - public void createTabs(ILaunchConfigurationDialog dialog, String mode) { - ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { - new MavenLaunchMainTab(false), - new MavenJRETab(), - new RefreshTab(), - new SourceLookupTab(), - new EnvironmentTab(), - new CommonTab()}; - setTabs(tabs); + public void createTabs(ILaunchConfigurationDialog dialog, String mode) { + List<ILaunchConfigurationTab> tabs = new ArrayList<ILaunchConfigurationTab>(); + + tabs.add(new MavenLaunchMainTab(false)); + tabs.add(new MavenJRETab()); + tabs.add(new RefreshTab()); + tabs.add(new SourceLookupTab()); + + List<MavenLaunchParticipantInfo> participants = MavenLaunchParticipantInfo.readParticipantsInfo(); + if(!participants.isEmpty()) { + tabs.add(new MavenLaunchExtensionsTab(participants)); } + tabs.add(new EnvironmentTab()); + tabs.add(new CommonTab()); + + setTabs(tabs.toArray(new ILaunchConfigurationTab[tabs.size()])); + } + } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java new file mode 100644 index 00000000..3bc9a981 --- /dev/null +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/ui/internal/launch/MavenLaunchExtensionsTab.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * 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.ui.internal.launch; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.ICheckStateProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.m2e.actions.MavenLaunchConstants; +import org.eclipse.m2e.internal.launch.MavenLaunchParticipantInfo; +import org.eclipse.m2e.internal.launch.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; + + +public class MavenLaunchExtensionsTab extends AbstractLaunchConfigurationTab { + + private Set<String> disabledParticipants; + + private final List<MavenLaunchParticipantInfo> participants; + + private CheckboxTableViewer checkboxTableViewer; + + public MavenLaunchExtensionsTab(List<MavenLaunchParticipantInfo> participants) { + this.participants = participants; + } + + /** + * @wbp.parser.entryPoint + */ + public void createControl(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + setControl(composite); + composite.setLayout(new GridLayout(1, false)); + + Label lblMavenLaunchExtensions = new Label(composite, SWT.NONE); + lblMavenLaunchExtensions.setText(Messages.MavenLaunchExtensionsTab_lblExtensions); + + checkboxTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); + checkboxTableViewer.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + if(event.getElement() instanceof MavenLaunchParticipantInfo) { + MavenLaunchParticipantInfo participant = (MavenLaunchParticipantInfo) event.getElement(); + if(event.getChecked()) { + disabledParticipants.remove(participant.getId()); + } else { + disabledParticipants.add(participant.getId()); + } + setDirty(true); + updateLaunchConfigurationDialog(); + } + } + }); + Table table = checkboxTableViewer.getTable(); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); + + checkboxTableViewer.setContentProvider(new IStructuredContentProvider() { + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public Object[] getElements(Object inputElement) { + if(inputElement instanceof Collection<?>) { + return ((Collection<?>) inputElement).toArray(); + } + return null; + } + }); + + checkboxTableViewer.setCheckStateProvider(new ICheckStateProvider() { + public boolean isChecked(Object element) { + if(element instanceof MavenLaunchParticipantInfo) { + return !disabledParticipants.contains(((MavenLaunchParticipantInfo) element).getId()); + } + return false; + } + + public boolean isGrayed(Object element) { + return false; + } + }); + + checkboxTableViewer.setLabelProvider(new ILabelProvider() { + + public void addListener(ILabelProviderListener listener) { + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + } + + public Image getImage(Object element) { + return null; + } + + public String getText(Object element) { + if(element instanceof MavenLaunchParticipantInfo) { + return ((MavenLaunchParticipantInfo) element).getName(); + } + return null; + } + }); + } + + public void setDefaults(ILaunchConfigurationWorkingCopy configuration) { + } + + @SuppressWarnings("unchecked") + public void initializeFrom(ILaunchConfiguration configuration) { + try { + disabledParticipants = new HashSet<String>(configuration.getAttribute( + MavenLaunchConstants.ATTR_DISABLED_EXTENSIONS, Collections.EMPTY_SET)); + } catch(CoreException ex) { + disabledParticipants = new HashSet<String>(); + } + + checkboxTableViewer.setInput(participants); + } + + public void performApply(ILaunchConfigurationWorkingCopy configuration) { + Set<String> disabledParticipants = this.disabledParticipants.isEmpty() ? null : this.disabledParticipants; + configuration.setAttribute(MavenLaunchConstants.ATTR_DISABLED_EXTENSIONS, disabledParticipants); + } + + public String getName() { + return Messages.MavenLaunchExtensionsTab_name; + } + +} |