diff options
Diffstat (limited to 'org.eclipse.m2e.launching')
2 files changed, 113 insertions, 53 deletions
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 6734f4b4..922aa36d 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 @@ -14,10 +14,8 @@ package org.eclipse.m2e.internal.launch; import static org.eclipse.m2e.internal.launch.MavenLaunchUtils.quote; import java.io.File; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,11 +24,8 @@ import org.eclipse.core.runtime.CoreException; 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; import org.eclipse.jdt.launching.IVMRunner; import org.eclipse.jdt.launching.JavaLaunchDelegate; -import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; -import org.eclipse.osgi.util.NLS; import org.eclipse.m2e.actions.MavenLaunchConstants; import org.eclipse.m2e.core.MavenPlugin; @@ -50,17 +45,16 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun private IProgressMonitor monitor; - private List<IMavenLaunchParticipant> participants; - private String programArguments; private MavenRuntimeLaunchSupport launchSupport; + private MavenLaunchExtensionsSupport extensionsSupport; + public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { this.launch = launch; this.monitor = monitor; - this.participants = getParticipants(configuration, launch); this.programArguments = null; log.info("" + getWorkingDirectory(configuration)); //$NON-NLS-1$ @@ -68,27 +62,16 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun try { this.launchSupport = MavenRuntimeLaunchSupport.create(configuration, launch, monitor); + this.extensionsSupport = MavenLaunchExtensionsSupport.create(configuration, launch); - if(launch.getSourceLocator() instanceof MavenSourceLocator) { - final MavenSourceLocator sourceLocator = (MavenSourceLocator) launch.getSourceLocator(); - for(IMavenLaunchParticipant participant : participants) { - List<ISourceLookupParticipant> sourceLookupParticipants = participant.getSourceLookupParticipants( - configuration, launch, monitor); - if(sourceLookupParticipants != null && !sourceLookupParticipants.isEmpty()) { - 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())); - } + extensionsSupport.configureSourceLookup(configuration, launch, monitor); super.launch(configuration, mode, launch, monitor); } finally { this.launch = null; this.monitor = null; + this.launchSupport = null; + this.extensionsSupport = null; } } @@ -112,12 +95,8 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun sb.append(" ").append(getPreferences(configuration)); sb.append(" ").append(getGoals(configuration)); - for(IMavenLaunchParticipant participant : participants) { - String programArguments = participant.getProgramArguments(configuration, launch, monitor); - if(programArguments != null) { - sb.append(" ").append(programArguments); - } - } + extensionsSupport.appendProgramArguments(sb, configuration, launch, monitor); + programArguments = sb.toString(); } return programArguments; @@ -126,13 +105,11 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun public String getVMArguments(ILaunchConfiguration configuration) throws CoreException { VMArguments arguments = launchSupport.getVMArguments(); + extensionsSupport.appendVMArguments(arguments, configuration, launch, monitor); + // user configured entries arguments.append(super.getVMArguments(configuration)); - for(IMavenLaunchParticipant participant : participants) { - arguments.append(participant.getVMArguments(configuration, launch, monitor)); - } - return arguments.toString(); } @@ -253,24 +230,4 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun static void removeTempFiles(ILaunch launch) { MavenRuntimeLaunchSupport.removeTempFiles(launch); } - - 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>(); - - 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 participants; - } } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java new file mode 100644 index 00000000..011cc0ad --- /dev/null +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchExtensionsSupport.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2013 Igor Fedorenko + * 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: + * Igor Fedorenko - 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.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.runtime.CoreException; +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; +import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant; +import org.eclipse.osgi.util.NLS; + +import org.eclipse.m2e.actions.MavenLaunchConstants; +import org.eclipse.m2e.internal.launch.MavenRuntimeLaunchSupport.VMArguments; + + +/** + * @since 1.5 + */ +public class MavenLaunchExtensionsSupport { + + private static final Logger log = LoggerFactory.getLogger(MavenLaunchExtensionsSupport.class); + + private final List<IMavenLaunchParticipant> participants; + + private MavenLaunchExtensionsSupport(List<IMavenLaunchParticipant> participants) { + this.participants = participants; + } + + public void configureSourceLookup(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) { + if(launch.getSourceLocator() instanceof MavenSourceLocator) { + final MavenSourceLocator sourceLocator = (MavenSourceLocator) launch.getSourceLocator(); + for(IMavenLaunchParticipant participant : participants) { + List<ISourceLookupParticipant> sourceLookupParticipants = participant.getSourceLookupParticipants( + configuration, launch, monitor); + if(sourceLookupParticipants != null && !sourceLookupParticipants.isEmpty()) { + 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())); + } + } + + public static MavenLaunchExtensionsSupport create(ILaunchConfiguration configuration, ILaunch launch) + throws CoreException { + @SuppressWarnings("unchecked") + Set<String> disabledExtensions = configuration.getAttribute(MavenLaunchConstants.ATTR_DISABLED_EXTENSIONS, + Collections.EMPTY_SET); + + List<IMavenLaunchParticipant> participants = new ArrayList<IMavenLaunchParticipant>(); + + 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 new MavenLaunchExtensionsSupport(participants); + } + + public void appendProgramArguments(StringBuilder arguments, ILaunchConfiguration configuration, ILaunch launch, + IProgressMonitor monitor) { + for(IMavenLaunchParticipant participant : participants) { + String extensionArguments = participant.getProgramArguments(configuration, launch, monitor); + if(extensionArguments != null) { + arguments.append(" ").append(extensionArguments); + } + } + } + + public void appendVMArguments(VMArguments arguments, ILaunchConfiguration configuration, ILaunch launch, + IProgressMonitor monitor) { + for(IMavenLaunchParticipant participant : participants) { + arguments.append(participant.getVMArguments(configuration, launch, monitor)); + } + } + +} |