Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2014-08-24 13:17:16 -0400
committerIgor Fedorenko2014-08-24 13:21:35 -0400
commitd82a57b87d796c105a7fdc859ceea042bf7c3a25 (patch)
tree20e264d4dcf2900498a8aca356a3f9c4790dddf3 /org.eclipse.m2e.launching
parentece431f25d356716ff7d95fefb0d0a25e8012cdd (diff)
downloadm2e-core-d82a57b87d796c105a7fdc859ceea042bf7c3a25.tar.gz
m2e-core-d82a57b87d796c105a7fdc859ceea042bf7c3a25.tar.xz
m2e-core-d82a57b87d796c105a7fdc859ceea042bf7c3a25.zip
Introduced MavenRuntimeLaunchSupport#builder() and other cleanup
Change-Id: I4691b7c986766ae68fa515cc0bc601d05d19e444 Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.launching')
-rw-r--r--org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenLaunchDelegate.java4
-rw-r--r--org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java232
2 files changed, 125 insertions, 111 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 d3e010f6..bc717288 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
@@ -226,8 +226,4 @@ public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaun
return sb.toString();
}
-
- static void removeTempFiles(ILaunch launch) {
- MavenRuntimeLaunchSupport.removeTempFiles(launch);
- }
}
diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java
index d3ef04b9..4ff1470a 100644
--- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java
+++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java
@@ -10,6 +10,7 @@ package org.eclipse.m2e.internal.launch;
import static org.eclipse.m2e.actions.MavenLaunchConstants.ATTR_WORKSPACE_RESOLUTION;
import static org.eclipse.m2e.actions.MavenLaunchConstants.PLUGIN_ID;
+import static org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration.LAUNCHER_REALM;
import static org.eclipse.m2e.internal.launch.MavenLaunchUtils.quote;
import java.io.File;
@@ -33,7 +34,6 @@ import org.eclipse.debug.ui.RefreshTab;
import org.eclipse.jdt.launching.IVMRunner;
import org.eclipse.jdt.launching.VMRunnerConfiguration;
-import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime;
import org.eclipse.m2e.workspace.WorkspaceState;
@@ -59,7 +59,6 @@ import org.eclipse.m2e.workspace.WorkspaceState;
*/
@SuppressWarnings("restriction")
public class MavenRuntimeLaunchSupport {
- private static final String LAUNCH_M2CONF_FILE = "org.eclipse.m2e.internal.launch.M2_CONF"; //$NON-NLS-1$
private final AbstractMavenRuntime runtime;
@@ -95,54 +94,132 @@ public class MavenRuntimeLaunchSupport {
}
}
- private MavenRuntimeLaunchSupport(AbstractMavenRuntime runtime, MavenLauncherConfigurationHandler cwconf,
- File cwconfFile, boolean resolveWorkspaceArtifacts) {
- this.runtime = runtime;
- this.cwconf = cwconf;
- this.cwconfFile = cwconfFile;
- this.resolveWorkspaceArtifacts = resolveWorkspaceArtifacts;
+ public static class Builder {
+ private final ILaunchConfiguration configuration;
+
+ private boolean resolveWorkspaceArtifacts;
+
+ private boolean injectWorkspaceResolver;
+
+ Builder(ILaunchConfiguration configuration) throws CoreException {
+ this.configuration = configuration;
+ enableWorkspaceResolution(configuration.getAttribute(ATTR_WORKSPACE_RESOLUTION, false));
+ }
+
+ public Builder enableWorkspaceResolution(boolean enable) {
+ this.resolveWorkspaceArtifacts = enable;
+ this.injectWorkspaceResolver = enable;
+ return this;
+ }
+
+ public Builder enableWorkspaceResolver(boolean enable) {
+ this.injectWorkspaceResolver = enable;
+ return this;
+ }
+
+ public MavenRuntimeLaunchSupport build(IProgressMonitor monitor) throws CoreException {
+
+ final AbstractMavenRuntime runtime = MavenLaunchUtils.getMavenRuntime(configuration);
+
+ final MavenLauncherConfigurationHandler cwconf = new MavenLauncherConfigurationHandler();
+ runtime.createLauncherConfiguration(cwconf, monitor);
+ if(injectWorkspaceResolver) {
+ for(String entry : MavenLaunchUtils.getCliResolver(runtime)) {
+ cwconf.forceArchiveEntry(entry);
+ }
+ }
+
+ final File cwconfFile;
+ try {
+ File state = MavenLaunchPlugin.getDefault().getStateLocation().toFile();
+ File dir = new File(state, "launches"); //$NON-NLS-1$
+ dir.mkdirs();
+ cwconfFile = File.createTempFile("m2conf", ".tmp", dir); //$NON-NLS-1$ //$NON-NLS-2$
+ OutputStream os = new FileOutputStream(cwconfFile);
+ try {
+ cwconf.save(os);
+ } finally {
+ os.close();
+ }
+ } catch(IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, -1,
+ Messages.MavenLaunchDelegate_error_cannot_create_conf, e));
+ }
+
+ return new MavenRuntimeLaunchSupport(runtime, cwconf, cwconfFile, resolveWorkspaceArtifacts);
+ }
}
- public static MavenRuntimeLaunchSupport create(ILaunchConfiguration configuration, ILaunch launch,
- IProgressMonitor monitor) throws CoreException {
- AbstractMavenRuntime runtime = MavenLaunchUtils.getMavenRuntime(configuration);
+ /**
+ * Refreshes resources as specified by a launch configuration, when an associated process terminates. Adapted from
+ * org.eclipse.ui.externaltools.internal.program.launchConfigurations.BackgroundResourceRefresher
+ */
+ private class BackgroundResourceRefresher implements IDebugEventSetListener {
+ final ILaunchConfiguration configuration;
- boolean resolveWorkspaceArtifacts = configuration.getAttribute(ATTR_WORKSPACE_RESOLUTION, false);
+ final IProcess process;
- MavenLauncherConfigurationHandler cwconf = new MavenLauncherConfigurationHandler();
- runtime.createLauncherConfiguration(cwconf, monitor);
- if(resolveWorkspaceArtifacts) {
- for(String entry : MavenLaunchUtils.getCliResolver(runtime)) {
- cwconf.forceArchiveEntry(entry);
+ public BackgroundResourceRefresher(ILaunchConfiguration configuration, ILaunch launch) {
+ this.configuration = configuration;
+ this.process = launch.getProcesses()[0];
+ }
+
+ /**
+ * 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()) {
+ processResources();
+ } else {
+ DebugPlugin.getDefault().addDebugEventListener(this);
+ }
}
}
- File cwconfFile;
- try {
- File state = MavenLaunchPlugin.getDefault().getStateLocation().toFile();
- File dir = new File(state, "launches"); //$NON-NLS-1$
- dir.mkdirs();
- cwconfFile = File.createTempFile("m2conf", ".tmp", dir); //$NON-NLS-1$ //$NON-NLS-2$
- launch.setAttribute(LAUNCH_M2CONF_FILE, cwconfFile.getCanonicalPath());
- OutputStream os = new FileOutputStream(cwconfFile);
- try {
- cwconf.save(os);
- } finally {
- os.close();
+ public void handleDebugEvents(DebugEvent[] events) {
+ for(int i = 0; i < events.length; i++ ) {
+ DebugEvent event = events[i];
+ if(event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) {
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ processResources();
+ break;
+ }
}
- } catch(IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, -1,
- Messages.MavenLaunchDelegate_error_cannot_create_conf, e));
}
- return new MavenRuntimeLaunchSupport(runtime, cwconf, cwconfFile, resolveWorkspaceArtifacts);
+ protected void processResources() {
+ getClassworldConfFile().delete();
+ Job job = new Job(Messages.MavenLaunchDelegate_job_name) {
+ public IStatus run(IProgressMonitor monitor) {
+ try {
+ RefreshTab.refreshResources(configuration, monitor);
+ return Status.OK_STATUS;
+ } catch(CoreException e) {
+ return e.getStatus();
+ }
+ }
+ };
+ job.schedule();
+ }
}
- public static void removeTempFiles(ILaunch launch) {
- String m2confName = launch.getAttribute(LAUNCH_M2CONF_FILE);
- if(m2confName != null) {
- new File(m2confName).delete();
- }
+ MavenRuntimeLaunchSupport(AbstractMavenRuntime runtime, MavenLauncherConfigurationHandler cwconf, File cwconfFile,
+ boolean resolveWorkspaceArtifacts) {
+ this.runtime = runtime;
+ this.cwconf = cwconf;
+ this.cwconfFile = cwconfFile;
+ this.resolveWorkspaceArtifacts = resolveWorkspaceArtifacts;
+ }
+
+ public static Builder builder(ILaunchConfiguration configuration) throws CoreException {
+ return new Builder(configuration);
+ }
+
+ public static MavenRuntimeLaunchSupport create(ILaunchConfiguration configuration, ILaunch launch,
+ IProgressMonitor monitor) throws CoreException {
+ return builder(configuration).build(monitor);
}
/**
@@ -162,8 +239,9 @@ public class MavenRuntimeLaunchSupport {
/**
* Bootstrap classpath of the Maven runtime, normally only contains classworlds jar.
*/
+ @SuppressWarnings("deprecation")
public List<String> getBootClasspath() {
- return cwconf.getRealmEntries(IMavenLauncherConfiguration.LAUNCHER_REALM);
+ return cwconf.getRealmEntries(LAUNCHER_REALM);
}
public String getVersion() {
@@ -175,7 +253,9 @@ public class MavenRuntimeLaunchSupport {
applyMavenRuntime(properties);
- applyWorkspaceArtifacts(properties); // workspace artifact resolution
+ if(resolveWorkspaceArtifacts) {
+ applyWorkspaceArtifacts(properties); // workspace artifact resolution
+ }
return properties;
}
@@ -191,11 +271,9 @@ public class MavenRuntimeLaunchSupport {
properties.appendProperty("classworlds.conf", quote(cwconfFile.getAbsolutePath())); //$NON-NLS-1$
}
- public void applyWorkspaceArtifacts(VMArguments properties) {
- if(resolveWorkspaceArtifacts) {
- File state = MavenPluginActivator.getDefault().getMavenProjectManager().getWorkspaceStateFile();
- properties.appendProperty(WorkspaceState.SYSPROP_STATEFILE_LOCATION, quote(state.getAbsolutePath())); //$NON-NLS-1$
- }
+ public static void applyWorkspaceArtifacts(VMArguments properties) {
+ File state = MavenPluginActivator.getDefault().getMavenProjectManager().getWorkspaceStateFile();
+ properties.appendProperty(WorkspaceState.SYSPROP_STATEFILE_LOCATION, quote(state.getAbsolutePath())); //$NON-NLS-1$
}
public IVMRunner decorateVMRunner(final IVMRunner runner) {
@@ -210,70 +288,10 @@ public class MavenRuntimeLaunchSupport {
BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, launch);
refresher.init();
} else {
- removeTempFiles(launch);
- }
- }
- };
- }
-}
-
-
-/**
- * Refreshes resources as specified by a launch configuration, when an associated process terminates. Adapted from
- * org.eclipse.ui.externaltools.internal.program.launchConfigurations.BackgroundResourceRefresher
- */
-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.
- */
- public void init() {
- synchronized(process) {
- if(process.isTerminated()) {
- processResources();
- } else {
- DebugPlugin.getDefault().addDebugEventListener(this);
- }
- }
- }
-
- public void handleDebugEvents(DebugEvent[] events) {
- for(int i = 0; i < events.length; i++ ) {
- DebugEvent event = events[i];
- if(event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) {
- DebugPlugin.getDefault().removeDebugEventListener(this);
- processResources();
- break;
- }
- }
- }
-
- protected void processResources() {
- MavenLaunchDelegate.removeTempFiles(launch);
-
- Job job = new Job(Messages.MavenLaunchDelegate_job_name) {
- public IStatus run(IProgressMonitor monitor) {
- try {
- RefreshTab.refreshResources(configuration, monitor);
- return Status.OK_STATUS;
- } catch(CoreException e) {
- MavenLaunchDelegate.log.error(e.getMessage(), e);
- return e.getStatus();
+ // the process didn't start, remove temp classworlds.conf right away
+ getClassworldConfFile().delete();
}
}
};
- job.schedule();
}
}

Back to the top