You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/08/24 15:27:24 UTC
svn commit: r807204 - in /labs/magma/trunk/magma-eclipse: ./ META-INF/
src/org/maven/ src/org/maven/ide/ src/org/maven/ide/eclipse/
src/org/maven/ide/eclipse/internal/
src/org/maven/ide/eclipse/internal/launch/ src/org/maven/ide/eclipse/ui/
src/org/mav...
Author: simoneg
Date: Mon Aug 24 13:27:23 2009
New Revision: 807204
URL: http://svn.apache.org/viewvc?rev=807204&view=rev
Log:
LABS-417 : imported Maven stuff cause it is currently private for the M2e plugin
Added:
labs/magma/trunk/magma-eclipse/src/org/maven/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchDelegate.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchUtils.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLauncherConfigurationHandler.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourceLocator.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourcePathComputer.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenJRETab.java
labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenLaunchMainTab.java
Modified:
labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF
labs/magma/trunk/magma-eclipse/plugin.xml
Modified: labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF?rev=807204&r1=807203&r2=807204&view=diff
==============================================================================
--- labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF (original)
+++ labs/magma/trunk/magma-eclipse/META-INF/MANIFEST.MF Mon Aug 24 13:27:23 2009
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: Magma Eclipse
Bundle-SymbolicName: org.apache.magma.tools.magmaeclipse;singleton:=true
-Bundle-Version: 0.0.3.0005
+Bundle-Version: 0.0.3.0009
Bundle-Activator: org.apache.magma.tools.magmaeclipse.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
@@ -20,7 +20,11 @@
org.eclipse.core.expressions;bundle-version="3.4.100",
org.eclipse.contribution.weaving.jdt;bundle-version="2.0.0",
org.eclipse.equinox.weaving.aspectj;bundle-version="1.0.0",
- org.maven.ide.components.maven_embedder
+ org.maven.ide.components.maven_embedder,
+ org.eclipse.jdt.debug.ui;bundle-version="3.4.0",
+ org.eclipse.ui.externaltools;bundle-version="3.2.0",
+ org.eclipse.ui.console;bundle-version="3.4.0",
+ org.eclipse.core.variables;bundle-version="3.2.200"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.apache.maven,
org.eclipse.ui.actions
Modified: labs/magma/trunk/magma-eclipse/plugin.xml
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/plugin.xml?rev=807204&r1=807203&r2=807204&view=diff
==============================================================================
--- labs/magma/trunk/magma-eclipse/plugin.xml (original)
+++ labs/magma/trunk/magma-eclipse/plugin.xml Mon Aug 24 13:27:23 2009
@@ -342,7 +342,7 @@
</contextualLaunch>
</shortcut>
<shortcut id="org.apache.magma.tools.magmaeclipse.run"
- class="org.maven.ide.eclipse.actions.ExecutePomAction:magma:run"
+ class="org.apache.magma.tools.magmaeclipse.launch.MagmaLaunchShortcut"
icon="icons/magma_run.gif"
label="Magma run"
modes="run,debug">
@@ -372,6 +372,32 @@
name="Magma">
</configurator>
</extension>
+ <extension
+ point="org.eclipse.debug.core.launchConfigurationTypes">
+ <launchConfigurationType
+ delegate="org.apache.magma.tools.magmaeclipse.launch.MagmaLaunchDelegate"
+ id="org.apache.magma.tools.magmaeclipse.magmalaunch"
+ modes="run, debug"
+ name="Magma project"
+ public="true">
+ </launchConfigurationType>
+ </extension>
+ <extension
+ point="org.eclipse.debug.ui.launchConfigurationTypeImages">
+ <launchConfigurationTypeImage
+ configTypeID="org.apache.magma.tools.magmaeclipse.magmalaunch"
+ icon="icons/magma_icon.gif"
+ id="magma-eclipse.launchConfigurationTypeImage1">
+ </launchConfigurationTypeImage>
+ </extension>
+ <extension
+ point="org.eclipse.debug.ui.launchConfigurationTabGroups">
+ <launchConfigurationTabGroup
+ class="org.apache.magma.tools.magmaeclipse.launch.MagmaLaunchTabGroup"
+ id="magma-eclipse.launchConfigurationTabGroup1"
+ type="org.apache.magma.tools.magmaeclipse.magmalaunch">
+ </launchConfigurationTabGroup>
+ </extension>
</plugin>
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchDelegate.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchDelegate.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchDelegate.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchDelegate.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,364 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.internal.launch;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+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.ui.RefreshTab;
+import org.eclipse.jdt.launching.IVMRunner;
+import org.eclipse.jdt.launching.JavaLaunchDelegate;
+import org.eclipse.jdt.launching.VMRunnerConfiguration;
+import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
+import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.actions.MavenLaunchConstants;
+import org.maven.ide.eclipse.core.IMavenConstants;
+import org.maven.ide.eclipse.core.MavenConsole;
+import org.maven.ide.eclipse.core.MavenLogger;
+import org.maven.ide.eclipse.embedder.IMavenLauncherConfiguration;
+import org.maven.ide.eclipse.embedder.MavenRuntime;
+import org.maven.ide.eclipse.embedder.MavenRuntimeManager;
+import org.maven.ide.eclipse.util.Util;
+
+
+@SuppressWarnings("restriction")
+public class MavenLaunchDelegate extends JavaLaunchDelegate implements MavenLaunchConstants {
+
+ private static final String LAUNCHER_TYPE = "org.codehaus.classworlds.Launcher";
+ private static final String LAUNCH_M2CONF_FILE = "org.maven.ide.eclipse.internal.launch.M2_CONF";
+
+ private MavenRuntime runtime;
+ private MavenLauncherConfigurationHandler m2conf;
+ private File confFile;
+
+ public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ MavenConsole console = MavenPlugin.getDefault().getConsole();
+ console.logMessage("" + getWorkingDirectory(configuration));
+ console.logMessage(" mvn" + getProgramArguments(configuration));
+
+ runtime = MavenLaunchUtils.getMavenRuntime(configuration);
+
+ m2conf = new MavenLauncherConfigurationHandler();
+ if (shouldResolveWorkspaceArtifacts(configuration)) {
+ m2conf.addArchiveEntry(MavenLaunchUtils.getCliResolver());
+ }
+ MavenLaunchUtils.addUserComponents(configuration, m2conf);
+ runtime.createLauncherConfiguration(m2conf, new NullProgressMonitor());
+
+ File state = MavenPlugin.getDefault().getStateLocation().toFile();
+ try {
+ File dir = new File(state, "launches");
+ dir.mkdirs();
+ confFile = File.createTempFile("m2conf", ".tmp", dir);
+ 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, "Can't create m2.conf ", e));
+ }
+
+ super.launch(configuration, mode, launch, monitor);
+ }
+
+ 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) {
+ BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, launch);
+ refresher.init();
+ } else {
+ removeTempFiles(launch);
+ }
+ }
+ };
+ }
+
+ public String getMainTypeName(ILaunchConfiguration configuration) throws CoreException {
+ return LAUNCHER_TYPE;
+ }
+
+ public String[] getClasspath(ILaunchConfiguration configuration) throws CoreException {
+ List<String> cp = m2conf.getRealmEntries(IMavenLauncherConfiguration.LAUNCHER_REALM);
+ return cp.toArray(new String[cp.size()]);
+ }
+
+ public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
+ return getProperties(configuration) + //
+ getPreferences(configuration) + " " + //
+ getGoals(configuration);
+ }
+
+ public String getVMArguments(ILaunchConfiguration configuration) throws CoreException {
+ /*
+ * <pre>
+ * %MAVEN_JAVA_EXE% %MAVEN_OPTS%
+ * -classpath %CLASSWORLDS_JAR%
+ * "-Dclassworlds.conf=%M2_HOME%\bin\m2.conf"
+ * "-Dmaven.home=%M2_HOME%"
+ * org.codehaus.classworlds.Launcher
+ * %MAVEN_CMD_LINE_ARGS%
+ * </pre>
+ */
+
+ StringBuffer sb = new StringBuffer();
+
+ // workspace artifact resolution
+ if (shouldResolveWorkspaceArtifacts(configuration)) {
+ File state = MavenPlugin.getDefault().getMavenProjectManager().getWorkspaceStateFile();
+ sb.append("-Dm2eclipse.workspace.state=").append(quote(state.getAbsolutePath()));
+ }
+
+ // maven.home
+ String location = runtime.getLocation();
+ if (location != null) {
+ sb.append(" -Dmaven.home=").append(quote(location));
+ }
+
+ // m2.conf
+ sb.append(" -Dclassworlds.conf=").append(quote(confFile.getAbsolutePath()));
+
+ // user configured entries
+ sb.append(" ").append(super.getVMArguments(configuration));
+
+ return sb.toString();
+ }
+
+ private String quote(String string) {
+ return string.indexOf(' ') > -1 ? "\"" + string + "\"" : string;
+ }
+
+ private boolean shouldResolveWorkspaceArtifacts(ILaunchConfiguration configuration) throws CoreException {
+ return configuration.getAttribute(ATTR_WORKSPACE_RESOLUTION, false);
+ }
+
+ protected String getGoals(ILaunchConfiguration configuration) throws CoreException {
+ String buildType = ExternalToolBuilder.getBuildType();
+ String key = MavenLaunchConstants.ATTR_GOALS;
+ if(IExternalToolConstants.BUILD_TYPE_AUTO.equals(buildType)) {
+ key = MavenLaunchConstants.ATTR_GOALS_AUTO_BUILD;
+ } else if(IExternalToolConstants.BUILD_TYPE_CLEAN.equals(buildType)) {
+ key = MavenLaunchConstants.ATTR_GOALS_CLEAN;
+ } else if(IExternalToolConstants.BUILD_TYPE_FULL.equals(buildType)) {
+ key = MavenLaunchConstants.ATTR_GOALS_AFTER_CLEAN;
+ } else if(IExternalToolConstants.BUILD_TYPE_INCREMENTAL.equals(buildType)) {
+ key = MavenLaunchConstants.ATTR_GOALS_MANUAL_BUILD;
+ }
+ String goals = configuration.getAttribute(key, "");
+ if(goals==null || goals.length()==0) {
+ // use default goals when "full build" returns nothing
+ goals = configuration.getAttribute(MavenLaunchConstants.ATTR_GOALS, "");
+ }
+
+ MavenPlugin.getDefault().getConsole().logMessage("Build type " + buildType + " : " + goals);
+ return goals;
+ }
+
+ public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) {
+ return false;
+ }
+
+ /**
+ * Construct string with properties to pass to JVM as system properties
+ */
+ private String getProperties(ILaunchConfiguration configuration) {
+ StringBuffer sb = new StringBuffer();
+
+ try {
+ @SuppressWarnings("unchecked")
+ List<String> properties = configuration.getAttribute(ATTR_PROPERTIES, Collections.EMPTY_LIST);
+ for(String property : properties) {
+ int n = property.indexOf('=');
+ String name = property;
+ String value = null;
+
+ if(n > -1) {
+ name = property.substring(0, n);
+ if(n > 1) {
+ value = Util.substituteVar(property.substring(n + 1));
+ }
+ }
+
+ sb.append(" -D").append(name);
+ if(value != null) {
+ sb.append('=').append(quote(value));
+ }
+ }
+ } catch(CoreException e) {
+ String msg = "Exception while getting configuration attribute " + ATTR_PROPERTIES;
+ MavenLogger.log(msg, e);
+ }
+
+ try {
+ String profiles = configuration.getAttribute(ATTR_PROFILES, (String) null);
+ if(profiles != null && profiles.trim().length() > 0) {
+ sb.append(" -P").append(profiles.replaceAll("\\s+", ","));
+ }
+ } catch(CoreException ex) {
+ String msg = "Exception while getting configuration attribute " + ATTR_PROFILES;
+ MavenLogger.log(msg, ex);
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Construct string with preferences to pass to JVM as system properties
+ */
+ private String getPreferences(ILaunchConfiguration configuration) throws CoreException {
+ MavenRuntimeManager runtimeManager = MavenPlugin.getDefault().getMavenRuntimeManager();
+
+ StringBuffer sb = new StringBuffer();
+
+ sb.append(" -B");
+
+ if(configuration.getAttribute(MavenLaunchConstants.ATTR_DEBUG_OUTPUT, runtimeManager.isDebugOutput())) {
+ sb.append(" -X").append(" -e");
+ }
+ // sb.append(" -D").append(MavenPreferenceConstants.P_DEBUG_OUTPUT).append("=").append(debugOutput);
+
+ if(configuration.getAttribute(MavenLaunchConstants.ATTR_OFFLINE, runtimeManager.isOffline())) {
+ sb.append(" -o");
+ }
+ // sb.append(" -D").append(MavenPreferenceConstants.P_OFFLINE).append("=").append(offline);
+
+ if(configuration.getAttribute(MavenLaunchConstants.ATTR_UPDATE_SNAPSHOTS, false)) {
+ sb.append(" -U");
+ }
+
+ if(configuration.getAttribute(MavenLaunchConstants.ATTR_NON_RECURSIVE, false)) {
+ sb.append(" -N");
+ }
+
+ if(configuration.getAttribute(MavenLaunchConstants.ATTR_SKIP_TESTS, false)) {
+ sb.append(" -Dmaven.test.skip=true");
+ }
+
+ String settings = runtimeManager.getUserSettingsFile();
+// if(settings==null) {
+// settings = getMavenRuntime(configuration).getSettings();
+// }
+ if(settings != null && settings.trim().length() > 0) {
+ sb.append(" -s ").append(quote(settings));
+ }
+
+ // boolean b = preferenceStore.getBoolean(MavenPreferenceConstants.P_CHECK_LATEST_PLUGIN_VERSION);
+ // sb.append(" -D").append(MavenPreferenceConstants.P_CHECK_LATEST_PLUGIN_VERSION).append("=").append(b);
+
+ // b = preferenceStore.getBoolean(MavenPreferenceConstants.P_UPDATE_SNAPSHOTS);
+ // sb.append(" -D").append(MavenPreferenceConstants.P_UPDATE_SNAPSHOTS).append("=").append(b);
+
+ // String s = preferenceStore.getString(MavenPreferenceConstants.P_GLOBAL_CHECKSUM_POLICY);
+ // 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) {
+ 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
+ */
+ 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.
+ */
+ public void init() {
+ 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++) {
+ DebugEvent event = events[i];
+ if (event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) {
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ processResources();
+ break;
+ }
+ }
+ }
+
+ protected void processResources() {
+ removeTempFiles(launch);
+
+ Job job = new Job("Refreshing resources...") {
+ public IStatus run(IProgressMonitor monitor) {
+ try {
+ RefreshTab.refreshResources(configuration, monitor);
+ return Status.OK_STATUS;
+ } catch (CoreException e) {
+ MavenLogger.log(e);
+ return e.getStatus();
+ }
+ }
+ };
+ job.schedule();
+ }
+ }
+
+
+}
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchUtils.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchUtils.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchUtils.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLaunchUtils.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.internal.launch;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.embedder.MavenEmbedder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.actions.MavenLaunchConstants;
+import org.maven.ide.eclipse.core.IMavenConstants;
+import org.maven.ide.eclipse.core.MavenLogger;
+import org.maven.ide.eclipse.embedder.IMavenLauncherConfiguration;
+import org.maven.ide.eclipse.embedder.MavenEmbedderManager;
+import org.maven.ide.eclipse.embedder.MavenRuntime;
+import org.maven.ide.eclipse.embedder.MavenRuntimeManager;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+import org.maven.ide.eclipse.project.MavenProjectManager;
+
+
+/**
+ * MavenLaunchUtils
+ *
+ * @author Igor Fedorenko
+ */
+public class MavenLaunchUtils {
+
+ public static MavenRuntime getMavenRuntime(ILaunchConfiguration configuration) throws CoreException {
+ MavenRuntimeManager runtimeManager = MavenPlugin.getDefault().getMavenRuntimeManager();
+ String location = configuration.getAttribute(MavenLaunchConstants.ATTR_RUNTIME, "");
+ MavenRuntime runtime = runtimeManager.getRuntime(location);
+ if(runtime == null) {
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, //
+ "Can't find Maven installation " + location, null));
+ }
+ return runtime;
+ }
+
+ public static String getCliResolver() throws CoreException {
+ URL url = MavenPlugin.getDefault().getBundle().getEntry("org.maven.ide.eclipse.cliresolver.jar");
+ try {
+ URL fileURL = FileLocator.toFileURL(url);
+ // MNGECLIPSE-804 workaround for spaces in the original path
+ 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));
+ }
+ }
+
+ public static void addUserComponents(ILaunchConfiguration configuration, IMavenLauncherConfiguration collector)
+ throws CoreException {
+ @SuppressWarnings("unchecked")
+ List<String> list = configuration.getAttribute(MavenLaunchConstants.ATTR_FORCED_COMPONENTS_LIST, new ArrayList());
+ if(list == null) {
+ return;
+ }
+
+ MavenProjectManager projectManager = MavenPlugin.getDefault().getMavenProjectManager();
+ MavenEmbedderManager embedderManager = MavenPlugin.getDefault().getMavenEmbedderManager();
+ for(String gav : list) {
+ // groupId:artifactId:version
+ StringTokenizer st = new StringTokenizer(gav, ":");
+ String groupId = st.nextToken();
+ String artifactId = st.nextToken();
+ String version = st.nextToken();
+
+ IMavenProjectFacade facade = projectManager.getMavenProject(groupId, artifactId, version);
+
+ if(facade != null) {
+ collector.addProjectEntry(facade);
+ } else {
+ String name = groupId + ":" + artifactId + ":" + version;
+ try {
+ MavenEmbedder embedder = embedderManager.getWorkspaceEmbedder();
+ Artifact artifact = embedder.createArtifact(groupId, artifactId, version, null, "jar");
+ embedder.resolve(artifact, Collections.EMPTY_LIST, embedder.getLocalRepository());
+ File file = artifact.getFile();
+ if(file != null) {
+ collector.addArchiveEntry(file.getAbsolutePath());
+ }
+ } catch(ArtifactResolutionException ex) {
+ MavenLogger.log("Artifact resolution error " + name, ex);
+ } catch(ArtifactNotFoundException ex) {
+ MavenLogger.log("Artifact not found " + name, ex);
+ }
+ }
+ }
+ }
+}
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLauncherConfigurationHandler.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLauncherConfigurationHandler.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLauncherConfigurationHandler.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenLauncherConfigurationHandler.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.internal.launch;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.maven.ide.eclipse.embedder.IMavenLauncherConfiguration;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+
+/**
+ * MavenLauncherConfigurationHandler
+ *
+ * @author Igor Fedorenko
+ */
+public class MavenLauncherConfigurationHandler implements IMavenLauncherConfiguration {
+
+ private String mainType;
+ private String mainRealm;
+ private LinkedHashMap<String, List<String>> realms = new LinkedHashMap<String, List<String>>();
+ private List<String> forcedEntries = new ArrayList<String>();
+ private List<String> curEntries = forcedEntries;
+
+ public void addArchiveEntry(String entry) {
+ curEntries.add(entry);
+ }
+
+ public void addProjectEntry(IMavenProjectFacade facade) {
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IFolder output = root.getFolder(facade.getOutputLocation());
+ if (output.isAccessible()) {
+ addArchiveEntry(output.getLocation().toFile().getAbsolutePath());
+ }
+ }
+
+ public void addRealm(String realm) {
+ if (!realms.containsKey(realm)) {
+ curEntries = new ArrayList<String>();
+ realms.put(realm, curEntries);
+ }
+ }
+
+ public void setMainType(String type, String realm) {
+ this.mainType = type;
+ this.mainRealm = realm;
+ }
+
+ public void save(OutputStream os) throws IOException {
+ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
+ out.write("main is " + mainType + " from " + mainRealm + "\n");
+ for (Map.Entry<String, List<String>> realm : realms.entrySet()) {
+ if (LAUNCHER_REALM.equals(realm.getKey())) {
+ continue;
+ }
+ out.write("[" + realm.getKey() + "]\n");
+ if (mainRealm.equals(realm.getKey())) {
+ for (String entry : forcedEntries) {
+ out.write("load " + entry + "\n");
+ }
+ }
+ for (String entry : realm.getValue()) {
+ out.write("load " + entry + "\n");
+ }
+ }
+ out.flush();
+ }
+
+ public String getMainReal() {
+ return mainRealm;
+ }
+
+ public List<String> getRealmEntries(String realm) {
+ return realms.get(realm);
+ }
+}
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourceLocator.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourceLocator.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourceLocator.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourceLocator.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.internal.launch;
+
+import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
+import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
+import org.eclipse.jdt.launching.sourcelookup.containers.JavaSourceLookupParticipant;
+
+/**
+ * @author Eugene Kuleshov
+ */
+public class MavenSourceLocator extends AbstractSourceLookupDirector {
+
+ public void initializeParticipants() {
+ addParticipants(new ISourceLookupParticipant[] {new JavaSourceLookupParticipant()});
+ }
+
+}
+
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourcePathComputer.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourcePathComputer.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourcePathComputer.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/internal/launch/MavenSourcePathComputer.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.internal.launch;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.embedder.MavenEmbedder;
+import org.codehaus.plexus.util.DirectoryScanner;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.sourcelookup.ISourceContainer;
+import org.eclipse.debug.core.sourcelookup.ISourcePathComputer;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.embedder.IMavenLauncherConfiguration;
+import org.maven.ide.eclipse.embedder.MavenEmbedderManager;
+import org.maven.ide.eclipse.embedder.MavenRuntime;
+import org.maven.ide.eclipse.project.IMavenProjectFacade;
+
+
+/**
+ * Computes Maven launch configuration default source lookup path.
+ *
+ * Default source lookup includes Maven core libraries only.
+ * It does not (and cannot) include entries for any Maven plugins
+ * which are loaded dynamically at runtime.
+ *
+ * @author Eugene Kuleshov
+ */
+public class MavenSourcePathComputer implements ISourcePathComputer {
+
+ private MavenEmbedderManager embedderManager;
+
+ public MavenSourcePathComputer() {
+ embedderManager = MavenPlugin.getDefault().getMavenEmbedderManager();
+ }
+
+ public String getId() {
+ return "org.maven.ide.eclipse.launching.MavenSourceComputer";
+ }
+
+ public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor)
+ throws CoreException {
+ final List<IRuntimeClasspathEntry> entries = new ArrayList<IRuntimeClasspathEntry>();
+
+ IRuntimeClasspathEntry jreEntry = JavaRuntime.computeJREEntry(configuration);
+ if(jreEntry != null) {
+ entries.add(jreEntry);
+ }
+
+ MavenRuntime runtime = MavenLaunchUtils.getMavenRuntime(configuration);
+ IMavenLauncherConfiguration collector = new IMavenLauncherConfiguration() {
+ public void addArchiveEntry(String entry) throws CoreException {
+ addArchiveRuntimeClasspathEntry(entries, entry);
+ }
+ public void addProjectEntry(IMavenProjectFacade facade) {
+ IJavaProject javaProject = JavaCore.create(facade.getProject());
+ if(javaProject != null) {
+ entries.add(JavaRuntime.newDefaultProjectClasspathEntry(javaProject));
+ }
+ }
+ public void addRealm(String world) {
+ }
+ public void setMainType(String type, String world) {
+ }
+ };
+
+ collector.addArchiveEntry(MavenLaunchUtils.getCliResolver());
+ MavenLaunchUtils.addUserComponents(configuration, collector);
+ runtime.createLauncherConfiguration(collector, monitor);
+
+ IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath( //
+ entries.toArray(new IRuntimeClasspathEntry[entries.size()]), configuration);
+ return JavaRuntime.getSourceContainers(resolved);
+ }
+
+ protected void addArchiveRuntimeClasspathEntry(List<IRuntimeClasspathEntry> entries, String entryPath) throws CoreException {
+ File entryFile = new File(entryPath);
+
+ if (!entryFile.exists()) {
+ return;
+ }
+
+ if (entryFile.isDirectory()) {
+ DirectoryScanner ds = new DirectoryScanner();
+ ds.setBasedir(entryFile);
+ ds.setIncludes(new String[] {
+ "META-INF/maven/*/*/pom.properties",
+ });
+ ds.scan();
+ String[] files = ds.getIncludedFiles();
+ for (String file : files) {
+ try {
+ BufferedInputStream is = new BufferedInputStream(new FileInputStream(new File(entryFile, file)));
+ try {
+ addArchiveRuntimeClasspathEntry(entries, entryPath, is);
+ } finally {
+ is.close();
+ }
+ } catch (IOException e) {
+ // ignore it
+ }
+
+ }
+ } else {
+ try {
+ JarFile jar = new JarFile(entryFile);
+ try {
+ Enumeration<JarEntry> zes = jar.entries();
+ while (zes.hasMoreElements()) {
+ JarEntry ze = zes.nextElement();
+ String name = ze.getName();
+ if (!ze.isDirectory() && name.startsWith("META-INF/maven/") && name.endsWith("pom.properties")) {
+ addArchiveRuntimeClasspathEntry(entries, entryPath, jar.getInputStream(ze));
+ }
+ }
+ } finally {
+ jar.close();
+ }
+ } catch (IOException e) {
+ // ignore it
+ }
+ }
+
+ }
+
+ private void addArchiveRuntimeClasspathEntry(List<IRuntimeClasspathEntry> entries, String entryPath, InputStream is) throws IOException, CoreException {
+ Properties p = new Properties();
+ p.load(is);
+
+ String groupId = p.getProperty("groupId");
+ String artifactId = p.getProperty("artifactId");
+ String version = p.getProperty("version");
+
+ File sourcesJar = getSourcesJar(groupId, artifactId, version);
+ if (sourcesJar != null) {
+ IRuntimeClasspathEntry entry = null;
+ entry = JavaRuntime.newArchiveRuntimeClasspathEntry(Path.fromOSString(entryPath));
+ entry.setSourceAttachmentPath(Path.fromOSString(sourcesJar.getAbsolutePath()));
+ entries.add(entry);
+ }
+ }
+
+ private File getSourcesJar(String groupId, String artifactId, String version) throws CoreException {
+ if (groupId != null && artifactId != null && version != null) {
+ MavenEmbedder embedder = embedderManager.getWorkspaceEmbedder();
+ ArtifactRepository localRepository = embedder.getLocalRepository();
+ ArtifactRepositoryLayout localLayout = localRepository.getLayout();
+
+ Artifact artifact = embedder.createArtifactWithClassifier(groupId, artifactId, version, "jar", "sources");
+ File file = new File(localRepository.getBasedir(), localLayout.pathOf(artifact));
+
+ if (file.exists() && file.canRead()) {
+ return file;
+ }
+ }
+
+ return null;
+ }
+
+}
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenJRETab.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenJRETab.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenJRETab.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenJRETab.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.ui.internal.launch;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.jdt.debug.ui.launchConfigurations.JavaJRETab;
+import org.eclipse.jdt.internal.debug.ui.launcher.VMArgumentsBlock;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+
+
+@SuppressWarnings("restriction")
+public class MavenJRETab extends JavaJRETab {
+
+ private VMArgumentsBlock vmArgumentsBlock = new VMArgumentsBlock();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+
+ Composite comp = (Composite) fJREBlock.getControl();
+ ((GridData) comp.getLayoutData()).grabExcessVerticalSpace = true;
+ ((GridData) comp.getLayoutData()).verticalAlignment = SWT.FILL;
+
+ vmArgumentsBlock.createControl(comp);
+ ((GridData) vmArgumentsBlock.getControl().getLayoutData()).horizontalSpan = 2;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ super.performApply(configuration);
+ vmArgumentsBlock.performApply(configuration);
+ setLaunchConfigurationWorkingCopy(configuration);
+ }
+
+// private boolean useDefaultSeparateJRE(ILaunchConfigurationWorkingCopy configuration) {
+// boolean deflt = false;
+// String vmInstallType = null;
+// String jreContainerPath = null;
+// try {
+// vmInstallType = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String) null);
+// jreContainerPath = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
+// (String) null);
+// } catch(CoreException e) {
+// }
+// if(vmInstallType != null) {
+// configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String) null);
+// }
+// if(jreContainerPath != null) {
+// configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String) null);
+// }
+// IVMInstall defaultVMInstall = getDefaultVMInstall(configuration);
+// if(defaultVMInstall != null) {
+// IVMInstall vm = fJREBlock.getJRE();
+// deflt = defaultVMInstall.equals(vm);
+// }
+//
+// if(vmInstallType != null) {
+// configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmInstallType);
+// }
+// if(jreContainerPath != null) {
+// configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, jreContainerPath);
+// }
+// return deflt;
+// }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
+ */
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ super.initializeFrom(configuration);
+ vmArgumentsBlock.initializeFrom(configuration);
+ // fVMArgumentsBlock.setEnabled(!fJREBlock.isDefaultJRE());
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setLaunchConfigurationDialog(org.eclipse.debug.ui.ILaunchConfigurationDialog)
+ */
+ public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
+ super.setLaunchConfigurationDialog(dialog);
+ vmArgumentsBlock.setLaunchConfigurationDialog(dialog);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
+ setLaunchConfigurationWorkingCopy(workingCopy);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void setDefaults(ILaunchConfigurationWorkingCopy config) {
+ super.setDefaults(config);
+ IVMInstall defaultVMInstall = getDefaultVMInstall(config);
+ if(defaultVMInstall != null) {
+ setDefaultVMInstallAttributes(defaultVMInstall, config);
+ }
+
+ }
+
+ private IVMInstall getDefaultVMInstall(ILaunchConfiguration config) {
+ IVMInstall defaultVMInstall;
+ try {
+ defaultVMInstall = JavaRuntime.computeVMInstall(config);
+ } catch(CoreException e) {
+ //core exception thrown for non-Java project
+ defaultVMInstall = JavaRuntime.getDefaultVMInstall();
+ }
+ return defaultVMInstall;
+ }
+
+ @SuppressWarnings("deprecation")
+ private void setDefaultVMInstallAttributes(IVMInstall defaultVMInstall, ILaunchConfigurationWorkingCopy config) {
+ String vmName = defaultVMInstall.getName();
+ String vmTypeID = defaultVMInstall.getVMInstallType().getId();
+ config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, vmName);
+ config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, vmTypeID);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
+ */
+ public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
+ }
+}
Added: labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenLaunchMainTab.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenLaunchMainTab.java?rev=807204&view=auto
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenLaunchMainTab.java (added)
+++ labs/magma/trunk/magma-eclipse/src/org/maven/ide/eclipse/ui/internal/launch/MavenLaunchMainTab.java Mon Aug 24 13:27:23 2009
@@ -0,0 +1,740 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ *******************************************************************************/
+
+package org.maven.ide.eclipse.ui.internal.launch;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.debug.ui.StringVariableSelectionDialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+import org.eclipse.ui.dialogs.PreferencesUtil;
+import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
+import org.maven.ide.eclipse.MavenImages;
+import org.maven.ide.eclipse.MavenPlugin;
+import org.maven.ide.eclipse.actions.MavenLaunchConstants;
+import org.maven.ide.eclipse.core.Messages;
+import org.maven.ide.eclipse.embedder.MavenRuntime;
+import org.maven.ide.eclipse.embedder.MavenRuntimeManager;
+import org.maven.ide.eclipse.ui.dialogs.MavenGoalSelectionDialog;
+import org.maven.ide.eclipse.ui.dialogs.MavenPropertyDialog;
+import org.maven.ide.eclipse.util.Util;
+
+
+/**
+ * Maven Launch dialog Main tab
+ *
+ * @author Dmitri Maximovich
+ * @author Eugene Kuleshov
+ */
+@SuppressWarnings("restriction")
+public class MavenLaunchMainTab extends AbstractLaunchConfigurationTab implements MavenLaunchConstants {
+
+ public static final String ID_EXTERNAL_TOOLS_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$
+
+ private final boolean isBuilder;
+
+ protected Text pomDirNameText;
+
+ protected Text goalsText;
+ protected Text goalsAutoBuildText;
+ protected Text goalsManualBuildText;
+ protected Text goalsCleanText;
+ protected Text goalsAfterCleanText;
+
+ protected Text profilesText;
+ protected Table propsTable;
+
+ private Button offlineButton;
+
+ private Button updateSnapshotsButton;
+
+ private Button debugOutputButton;
+
+ private Button skipTestsButton;
+
+ private Button nonRecursiveButton;
+
+ private Button enableWorkspaceResolution;
+
+ ComboViewer runtimeComboViewer;
+
+
+ public MavenLaunchMainTab(boolean isBuilder) {
+ this.isBuilder = isBuilder;
+ }
+
+ public Image getImage() {
+ return MavenImages.IMG_LAUNCH_MAIN;
+ }
+
+ public void createControl(Composite parent) {
+ Composite mainComposite = new Composite(parent, SWT.NONE);
+ setControl(mainComposite);
+ //PlatformUI.getWorkbench().getHelpSystem().setHelp(mainComposite, IAntUIHelpContextIds.ANT_MAIN_TAB);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 5;
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ mainComposite.setLayout(layout);
+ mainComposite.setLayoutData(gridData);
+ mainComposite.setFont(parent.getFont());
+
+ class Listener implements ModifyListener, SelectionListener {
+ public void modifyText(ModifyEvent e) {
+ entriesChanged();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ entriesChanged();
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ entriesChanged();
+ }
+ }
+ Listener modyfyingListener = new Listener();
+
+ Label label = new Label(mainComposite, SWT.NONE);
+ label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 5, 1));
+ label.setText(Messages.getString("launch.pomGroup"));
+
+ this.pomDirNameText = new Text(mainComposite, SWT.BORDER);
+ this.pomDirNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 5, 1));
+ this.pomDirNameText.addModifyListener(modyfyingListener);
+
+ final Composite pomDirButtonsComposite = new Composite(mainComposite, SWT.NONE);
+ pomDirButtonsComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 5, 1));
+ final GridLayout pomDirButtonsGridLayout = new GridLayout();
+ pomDirButtonsGridLayout.marginWidth = 0;
+ pomDirButtonsGridLayout.marginHeight = 0;
+ pomDirButtonsGridLayout.numColumns = 3;
+ pomDirButtonsComposite.setLayout(pomDirButtonsGridLayout);
+
+ final Button browseWorkspaceButton = new Button(pomDirButtonsComposite, SWT.NONE);
+ browseWorkspaceButton.setText(Messages.getString("launch.browseWorkspace")); //$NON-NLS-1$
+ browseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), //
+ ResourcesPlugin.getWorkspace().getRoot(), false, Messages.getString("launch.choosePomDir")); //$NON-NLS-1$
+ dialog.showClosedProjects(false);
+
+ int buttonId = dialog.open();
+ if(buttonId == IDialogConstants.OK_ID) {
+ Object[] resource = dialog.getResult();
+ if(resource != null && resource.length > 0) {
+ String fileLoc = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression(
+ "workspace_loc", ((IPath) resource[0]).toString()); //$NON-NLS-1$
+ pomDirNameText.setText(fileLoc);
+ entriesChanged();
+ }
+ }
+ }
+ });
+
+ final Button browseFilesystemButton = new Button(pomDirButtonsComposite, SWT.NONE);
+ browseFilesystemButton.setText(Messages.getString("launch.browseFs")); //$NON-NLS-1$
+ browseFilesystemButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.NONE);
+ dialog.setFilterPath(pomDirNameText.getText());
+ String text = dialog.open();
+ if(text != null) {
+ pomDirNameText.setText(text);
+ entriesChanged();
+ }
+ }
+ });
+
+ final Button browseVariablesButton = new Button(pomDirButtonsComposite, SWT.NONE);
+ browseVariablesButton.setText(Messages.getString("launch.browseVariables")); //$NON-NLS-1$
+ browseVariablesButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
+ dialog.open();
+ String variable = dialog.getVariableExpression();
+ if(variable != null) {
+ pomDirNameText.insert(variable);
+ }
+ }
+ });
+
+ // pom file
+
+ // goals
+
+ if(isBuilder) {
+ Label autoBuildGoalsLabel = new Label(mainComposite, SWT.NONE);
+ GridData gd_autoBuildGoalsLabel = new GridData();
+ gd_autoBuildGoalsLabel.verticalIndent = 7;
+ autoBuildGoalsLabel.setLayoutData(gd_autoBuildGoalsLabel);
+ autoBuildGoalsLabel.setText("Auto &Build Goals:");
+ goalsAutoBuildText = new Text(mainComposite, SWT.BORDER);
+ GridData gd_goalsAutoBuildText = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+ gd_goalsAutoBuildText.verticalIndent = 7;
+ goalsAutoBuildText.setLayoutData(gd_goalsAutoBuildText);
+ goalsAutoBuildText.addModifyListener(modyfyingListener);
+ goalsAutoBuildText.addFocusListener(new GoalsFocusListener(goalsAutoBuildText));
+ Button goalsAutoBuildButton = new Button(mainComposite, SWT.NONE);
+ GridData gd_goalsAutoBuildButton = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd_goalsAutoBuildButton.verticalIndent = 7;
+ goalsAutoBuildButton.setLayoutData(gd_goalsAutoBuildButton);
+ goalsAutoBuildButton.setText("&Select...");
+ goalsAutoBuildButton.addSelectionListener(new GoalSelectionAdapter(goalsAutoBuildText));
+
+ Label manualBuildGoalsLabel = new Label(mainComposite, SWT.NONE);
+ manualBuildGoalsLabel.setText("Ma&nual Build Goals:");
+ goalsManualBuildText = new Text(mainComposite, SWT.BORDER);
+ goalsManualBuildText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
+ goalsManualBuildText.addModifyListener(modyfyingListener);
+ goalsManualBuildText.addFocusListener(new GoalsFocusListener(goalsManualBuildText));
+ Button goalsManualBuildButton = new Button(mainComposite, SWT.NONE);
+ goalsManualBuildButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ goalsManualBuildButton.setText("S&elect...");
+ goalsManualBuildButton.addSelectionListener(new GoalSelectionAdapter(goalsManualBuildText));
+
+ Label cleanBuildGoalsLabel = new Label(mainComposite, SWT.NONE);
+ cleanBuildGoalsLabel.setText("&During a Clean Goals:");
+ goalsCleanText = new Text(mainComposite, SWT.BORDER);
+ goalsCleanText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
+ goalsCleanText.addModifyListener(modyfyingListener);
+ goalsCleanText.addFocusListener(new GoalsFocusListener(goalsCleanText));
+ Button goalsCleanButton = new Button(mainComposite, SWT.NONE);
+ goalsCleanButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ goalsCleanButton.setText("Se&lect...");
+ goalsCleanButton.addSelectionListener(new GoalSelectionAdapter(goalsCleanText));
+
+ Label afterCleanGoalsLabel = new Label(mainComposite, SWT.NONE);
+ afterCleanGoalsLabel.setText("A&fter a Clean Goals:");
+ goalsAfterCleanText = new Text(mainComposite, SWT.BORDER);
+ goalsAfterCleanText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
+ goalsAfterCleanText.addModifyListener(modyfyingListener);
+ goalsAfterCleanText.addFocusListener(new GoalsFocusListener(goalsAfterCleanText));
+ Button goalsAfterCleanButton = new Button(mainComposite, SWT.NONE);
+ goalsAfterCleanButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ goalsAfterCleanButton.setText("Selec&t...");
+ goalsAfterCleanButton.addSelectionListener(new GoalSelectionAdapter(goalsAfterCleanText));
+
+ } else {
+ Label goalsLabel = new Label(mainComposite, SWT.NONE);
+ GridData gd_goalsLabel = new GridData();
+ gd_goalsLabel.verticalIndent = 7;
+ goalsLabel.setLayoutData(gd_goalsLabel);
+ goalsLabel.setText(Messages.getString("launch.goalsLabel")); //$NON-NLS-1$
+ goalsText = new Text(mainComposite, SWT.BORDER);
+ goalsText.setData("name", "goalsText");
+ GridData gd_goalsText = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
+ gd_goalsText.verticalIndent = 7;
+ goalsText.setLayoutData(gd_goalsText);
+ goalsText.addModifyListener(modyfyingListener);
+ goalsText.addFocusListener(new GoalsFocusListener(goalsText));
+
+ Button selectGoalsButton = new Button(mainComposite, SWT.NONE);
+ GridData gd_selectGoalsButton = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ gd_selectGoalsButton.verticalIndent = 7;
+ selectGoalsButton.setLayoutData(gd_selectGoalsButton);
+ selectGoalsButton.setText(Messages.getString("launch.goals")); //$NON-NLS-1$
+ selectGoalsButton.addSelectionListener(new GoalSelectionAdapter(goalsText));
+ }
+
+ Label profilesLabel = new Label(mainComposite, SWT.NONE);
+ profilesLabel.setText(Messages.getString("launch.profilesLabel")); //$NON-NLS-1$
+ // profilesLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+
+ profilesText = new Text(mainComposite, SWT.BORDER);
+ profilesText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
+ profilesText.addModifyListener(modyfyingListener);
+ new Label(mainComposite, SWT.NONE);
+
+ offlineButton = new Button(mainComposite, SWT.CHECK);
+ offlineButton.setToolTipText("-o");
+ GridData gd_offlineButton = new GridData();
+ offlineButton.setLayoutData(gd_offlineButton);
+ offlineButton.setText("&Offline");
+ offlineButton.addSelectionListener(modyfyingListener);
+
+ updateSnapshotsButton = new Button(mainComposite, SWT.CHECK);
+ updateSnapshotsButton.setToolTipText("-U");
+ updateSnapshotsButton.addSelectionListener(modyfyingListener);
+ GridData gd_updateSnapshotsButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
+ gd_updateSnapshotsButton.horizontalIndent = 10;
+ updateSnapshotsButton.setLayoutData(gd_updateSnapshotsButton);
+ updateSnapshotsButton.setText("&Update Snapshots");
+ new Label(mainComposite, SWT.NONE);
+
+ debugOutputButton = new Button(mainComposite, SWT.CHECK);
+ debugOutputButton.setToolTipText("-X -e");
+ debugOutputButton.addSelectionListener(modyfyingListener);
+ debugOutputButton.setLayoutData(new GridData());
+ debugOutputButton.setText("Debu&g Output");
+
+ skipTestsButton = new Button(mainComposite, SWT.CHECK);
+ skipTestsButton.setToolTipText("-Dmaven.test.skip=true");
+ skipTestsButton.addSelectionListener(modyfyingListener);
+ GridData gd_skipTestsButton = new GridData();
+ gd_skipTestsButton.horizontalIndent = 10;
+ skipTestsButton.setLayoutData(gd_skipTestsButton);
+ skipTestsButton.setText("S&kip Tests");
+
+ nonRecursiveButton = new Button(mainComposite, SWT.CHECK);
+ GridData gd_nonrecursiveButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
+ gd_nonrecursiveButton.horizontalIndent = 10;
+ nonRecursiveButton.setLayoutData(gd_nonrecursiveButton);
+ nonRecursiveButton.setText("Non-recursive");
+ nonRecursiveButton.setToolTipText("-N");
+ nonRecursiveButton.setData("name", "nonRecursiveButton");
+ nonRecursiveButton.addSelectionListener(modyfyingListener);
+
+ new Label(mainComposite, SWT.NONE);
+
+ enableWorkspaceResolution = new Button(mainComposite, SWT.CHECK);
+ enableWorkspaceResolution.addSelectionListener(modyfyingListener);
+ enableWorkspaceResolution.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
+ enableWorkspaceResolution.setText("Resolve Workspace artifacts");
+
+ TableViewer tableViewer = new TableViewer(mainComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
+ tableViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ TableItem[] selection = propsTable.getSelection();
+ if(selection.length == 1) {
+ editProperty(selection[0].getText(0), selection[0].getText(1));
+ }
+ }
+ });
+
+ this.propsTable = tableViewer.getTable();
+ //this.tProps.setItemCount(10);
+ this.propsTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 2));
+ this.propsTable.setLinesVisible(true);
+ this.propsTable.setHeaderVisible(true);
+
+ final TableColumn propColumn = new TableColumn(this.propsTable, SWT.NONE, 0);
+ propColumn.setWidth(120);
+ propColumn.setText(Messages.getString("launch.propName")); //$NON-NLS-1$
+
+ final TableColumn valueColumn = new TableColumn(this.propsTable, SWT.NONE, 1);
+ valueColumn.setWidth(200);
+ valueColumn.setText(Messages.getString("launch.propValue")); //$NON-NLS-1$
+
+ final Button addPropButton = new Button(mainComposite, SWT.NONE);
+ addPropButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+ addPropButton.setText(Messages.getString("launch.propAddButton")); //$NON-NLS-1$
+ addPropButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ addProperty();
+ }
+ });
+
+ final Button removePropButton = new Button(mainComposite, SWT.NONE);
+ removePropButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+ removePropButton.setText(Messages.getString("launch.propRemoveButton")); //$NON-NLS-1$
+ removePropButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ if(propsTable.getSelectionCount() > 0) {
+ propsTable.remove(propsTable.getSelectionIndices());
+ entriesChanged();
+ }
+ }
+ });
+
+ {
+ Composite composite = new Composite(mainComposite, SWT.NONE);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
+ GridLayout gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ composite.setLayout(gridLayout);
+
+ Label mavenRuntimeLabel = new Label(composite, SWT.NONE);
+ mavenRuntimeLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
+ mavenRuntimeLabel.setText("Maven Runt&ime:");
+
+ runtimeComboViewer = new ComboViewer(composite, SWT.BORDER | SWT.READ_ONLY);
+ runtimeComboViewer.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ runtimeComboViewer.setContentProvider(new IStructuredContentProvider() {
+
+ public Object[] getElements(Object input) {
+ return ((List<?>) input).toArray();
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ });
+
+ runtimeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ entriesChanged();
+ }
+ });
+
+ MavenRuntimeManager runtimeManager = MavenPlugin.getDefault().getMavenRuntimeManager();
+ runtimeComboViewer.setInput(runtimeManager.getMavenRuntimes());
+ runtimeComboViewer.setSelection(new StructuredSelection(runtimeManager.getDefaultRuntime()));
+ }
+
+ Button configureRuntimesButton = new Button(mainComposite, SWT.NONE);
+ GridData gd_configureRuntimesButton = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ configureRuntimesButton.setLayoutData(gd_configureRuntimesButton);
+ configureRuntimesButton.setText("Configure...");
+ configureRuntimesButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ PreferencesUtil.createPreferenceDialogOn(getShell(),
+ "org.maven.ide.eclipse.preferences.MavenInstallationsPreferencePage", null, null).open(); //$NON-NLS-1$
+ MavenRuntimeManager runtimeManager = MavenPlugin.getDefault().getMavenRuntimeManager();
+ runtimeComboViewer.setInput(runtimeManager.getMavenRuntimes());
+ runtimeComboViewer.setSelection(new StructuredSelection(runtimeManager.getDefaultRuntime()));
+ }
+ });
+
+ if(isBuilder) {
+ goalsAutoBuildText.setFocus();
+ } else {
+ goalsText.setFocus();
+ }
+ }
+
+ protected Shell getShell() {
+ return super.getShell();
+ }
+
+ void addProperty() {
+ MavenPropertyDialog dialog = getMavenPropertyDialog("Add Parameter", "", "");
+ if(dialog.open() == IDialogConstants.OK_ID) {
+ TableItem item = new TableItem(propsTable, SWT.NONE);
+ item.setText(0, dialog.getName());
+ item.setText(1, dialog.getValue());
+ entriesChanged();
+ }
+ }
+
+ void editProperty(String name, String value) {
+ MavenPropertyDialog dialog = getMavenPropertyDialog("Edit Parameter", name, value);
+ if(dialog.open() == IDialogConstants.OK_ID) {
+ TableItem[] item = propsTable.getSelection();
+ item[0].setText(0, dialog.getName());
+ item[0].setText(1, dialog.getValue());
+ entriesChanged();
+ }
+ }
+
+ private MavenPropertyDialog getMavenPropertyDialog(String title, String initName, String initValue) {
+ return new MavenPropertyDialog(getShell(), title, initName, initValue, null) {
+ protected Control createDialogArea(Composite parent) {
+ Composite comp = (Composite) super.createDialogArea(parent);
+
+ Button variablesButton = new Button(comp, SWT.PUSH);
+ GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
+ gd.horizontalSpan = 2;
+ gd.widthHint = Math.max(convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH), //
+ variablesButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
+ variablesButton.setLayoutData(gd);
+ variablesButton.setFont(comp.getFont());
+ variablesButton.setText(Messages.getString("launch.propertyDialog.browseVariables")); //$NON-NLS-1$;
+
+ variablesButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent se) {
+ StringVariableSelectionDialog variablesDialog = new StringVariableSelectionDialog(getShell());
+ if(variablesDialog.open() == IDialogConstants.OK_ID) {
+ String variable = variablesDialog.getVariableExpression();
+ if(variable != null) {
+ valueText.insert(variable.trim());
+ }
+ }
+ }
+ });
+
+ return comp;
+ }
+ };
+ }
+
+ public void initializeFrom(ILaunchConfiguration configuration) {
+ String pomDirName = getAttribute(configuration, ATTR_POM_DIR, ""); //$NON-NLS-1$
+ if(isBuilder && pomDirName.length()==0) {
+ pomDirName = "${workspace_loc:/" + configuration.getFile().getProject().getName() + "}";
+ }
+ this.pomDirNameText.setText(pomDirName);
+
+ if(isBuilder) {
+ this.goalsAutoBuildText.setText(getAttribute(configuration, ATTR_GOALS_AUTO_BUILD, "install")); //$NON-NLS-1$
+ this.goalsManualBuildText.setText(getAttribute(configuration, ATTR_GOALS_MANUAL_BUILD, "install")); //$NON-NLS-1$
+ this.goalsCleanText.setText(getAttribute(configuration, ATTR_GOALS_CLEAN, "clean")); //$NON-NLS-1$
+ this.goalsAfterCleanText.setText(getAttribute(configuration, ATTR_GOALS_AFTER_CLEAN, "install")); //$NON-NLS-1$
+ } else {
+ this.goalsText.setText(getAttribute(configuration, ATTR_GOALS, "")); //$NON-NLS-1$
+ }
+
+ this.profilesText.setText(getAttribute(configuration, ATTR_PROFILES, "")); //$NON-NLS-1$
+
+ MavenPlugin plugin = MavenPlugin.getDefault();
+ MavenRuntimeManager runtimeManager = plugin.getMavenRuntimeManager();
+
+ this.offlineButton.setSelection(getAttribute(configuration, ATTR_OFFLINE, runtimeManager.isOffline()));
+ this.debugOutputButton.setSelection(getAttribute(configuration, ATTR_DEBUG_OUTPUT, runtimeManager.isDebugOutput()));
+
+ this.updateSnapshotsButton.setSelection(getAttribute(configuration, ATTR_UPDATE_SNAPSHOTS, false));
+ this.skipTestsButton.setSelection(getAttribute(configuration, ATTR_SKIP_TESTS, false));
+ this.nonRecursiveButton.setSelection(getAttribute(configuration, ATTR_NON_RECURSIVE, false));
+ this.enableWorkspaceResolution.setSelection(getAttribute(configuration, ATTR_WORKSPACE_RESOLUTION, false));
+
+ String location = getAttribute(configuration, ATTR_RUNTIME, "");
+ MavenRuntime runtime = runtimeManager.getRuntime(location);
+ this.runtimeComboViewer.setSelection(new StructuredSelection(runtime));
+
+ try {
+ propsTable.removeAll();
+
+ @SuppressWarnings("unchecked")
+ List<String> properties = configuration.getAttribute(ATTR_PROPERTIES, Collections.EMPTY_LIST);
+ for(String property : properties) {
+ int n = property.indexOf('=');
+ String name = property;
+ String value = "";
+ if(n > -1) {
+ name = property.substring(0, n);
+ if(n > 1) {
+ value = property.substring(n + 1);
+ }
+ }
+
+ TableItem item = new TableItem(propsTable, SWT.NONE);
+ item.setText(0, name);
+ item.setText(1, value);
+ }
+ } catch(CoreException ex) {
+ }
+ setDirty(false);
+ }
+
+ private String getAttribute(ILaunchConfiguration configuration, String name, String defaultValue) {
+ try {
+ return configuration.getAttribute(name, defaultValue);
+ } catch(CoreException ex) {
+ return defaultValue;
+ }
+ }
+
+ private boolean getAttribute(ILaunchConfiguration configuration, String name, boolean defaultValue) {
+ try {
+ return configuration.getAttribute(name, defaultValue);
+ } catch(CoreException ex) {
+ return defaultValue;
+ }
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
+ configuration.setAttribute(ATTR_POM_DIR, this.pomDirNameText.getText());
+
+ if(isBuilder) {
+ configuration.setAttribute(ATTR_GOALS_AUTO_BUILD, goalsAutoBuildText.getText());
+ configuration.setAttribute(ATTR_GOALS_MANUAL_BUILD, this.goalsManualBuildText.getText());
+ configuration.setAttribute(ATTR_GOALS_CLEAN, this.goalsCleanText.getText());
+ configuration.setAttribute(ATTR_GOALS_AFTER_CLEAN, this.goalsAfterCleanText.getText());
+
+ StringBuffer sb = new StringBuffer();
+ if(goalsAfterCleanText.getText().trim().length()>0) {
+ sb.append(IExternalToolConstants.BUILD_TYPE_FULL).append(',');
+ }
+ if(goalsManualBuildText.getText().trim().length()>0) {
+ sb.append(IExternalToolConstants.BUILD_TYPE_INCREMENTAL).append(',');
+ }
+ if(goalsAutoBuildText.getText().trim().length()>0) {
+ sb.append(IExternalToolConstants.BUILD_TYPE_AUTO).append(',');
+ }
+ if(goalsCleanText.getText().trim().length()>0) {
+ sb.append(IExternalToolConstants.BUILD_TYPE_CLEAN);
+ }
+ configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, sb.toString());
+
+ } else {
+ configuration.setAttribute(ATTR_GOALS, this.goalsText.getText());
+ }
+
+ configuration.setAttribute(ATTR_PROFILES, this.profilesText.getText());
+
+ configuration.setAttribute(ATTR_OFFLINE, this.offlineButton.getSelection());
+ configuration.setAttribute(ATTR_UPDATE_SNAPSHOTS, this.updateSnapshotsButton.getSelection());
+ configuration.setAttribute(ATTR_SKIP_TESTS, this.skipTestsButton.getSelection());
+ configuration.setAttribute(ATTR_NON_RECURSIVE, this.nonRecursiveButton.getSelection());
+ configuration.setAttribute(ATTR_WORKSPACE_RESOLUTION, this.enableWorkspaceResolution.getSelection());
+ configuration.setAttribute(ATTR_DEBUG_OUTPUT, this.debugOutputButton.getSelection());
+
+ IStructuredSelection selection = (IStructuredSelection) runtimeComboViewer.getSelection();
+ MavenRuntime runtime = (MavenRuntime) selection.getFirstElement();
+ configuration.setAttribute(ATTR_RUNTIME, runtime.getLocation());
+
+ // store as String in "param=value" format
+ List<String> properties = new ArrayList<String>();
+ for(TableItem item : this.propsTable.getItems()) {
+ String p = item.getText(0);
+ String v = item.getText(1);
+ if(p != null && p.trim().length() > 0) {
+ String prop = p.trim() + "=" + (v == null ? "" : v); //$NON-NLS-1$ //$NON-NLS-2$
+ properties.add(prop);
+ }
+ }
+ configuration.setAttribute(ATTR_PROPERTIES, properties);
+ }
+
+ public String getName() {
+ return Messages.getString("launch.mainTabName"); //$NON-NLS-1$
+ }
+
+ public boolean isValid(ILaunchConfiguration launchConfig) {
+ setErrorMessage(null);
+
+ String pomFileName = this.pomDirNameText.getText();
+ if(pomFileName == null || pomFileName.trim().length() == 0) {
+ setErrorMessage(Messages.getString("launch.pomDirectoryEmpty"));
+ return false;
+ }
+ if(!isDirectoryExist(pomFileName)) {
+ setErrorMessage(Messages.getString("launch.pomDirectoryDoesntExist"));
+ return false;
+ }
+ return true;
+ }
+
+ protected boolean isDirectoryExist(String name) {
+ if(name == null || name.trim().length() == 0) {
+ return false;
+ }
+ String dirName = Util.substituteVar(name);
+ if(dirName == null) {
+ return false;
+ }
+ File pomDir = new File(dirName);
+ if(!pomDir.exists()) {
+ return false;
+ }
+ if(!pomDir.isDirectory()) {
+ return false;
+ }
+ return true;
+ }
+
+ void entriesChanged() {
+ setDirty(true);
+ updateLaunchConfigurationDialog();
+ }
+
+
+ private static final class GoalsFocusListener extends FocusAdapter {
+ private Text text;
+
+ public GoalsFocusListener(Text text) {
+ this.text = text;
+ }
+
+ public void focusGained(FocusEvent e) {
+ super.focusGained(e);
+ text.setData("focus");
+ }
+ }
+
+
+ private final class GoalSelectionAdapter extends SelectionAdapter {
+ private Text text;
+
+ public GoalSelectionAdapter(Text text) {
+ this.text = text;
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+// String fileName = Util.substituteVar(fPomDirName.getText());
+// if(!isDirectoryExist(fileName)) {
+// MessageDialog.openError(getShell(), Messages.getString("launch.errorPomMissing"),
+// Messages.getString("launch.errorSelectPom")); //$NON-NLS-1$ //$NON-NLS-2$
+// return;
+// }
+ MavenGoalSelectionDialog dialog = new MavenGoalSelectionDialog(getShell());
+ int rc = dialog.open();
+ if(rc == IDialogConstants.OK_ID) {
+ text.insert(""); // clear selected text
+
+ String txt = text.getText();
+ int len = txt.length();
+ int pos = text.getCaretPosition();
+
+ StringBuffer sb = new StringBuffer();
+ if((pos > 0 && txt.charAt(pos - 1) != ' ')) {
+ sb.append(' ');
+ }
+
+ String sep = "";
+ Object[] o = dialog.getResult();
+ for(int i = 0; i < o.length; i++ ) {
+ if(o[i] instanceof MavenGoalSelectionDialog.Entry) {
+ if(dialog.isQualifiedName()) {
+ sb.append(sep).append(((MavenGoalSelectionDialog.Entry) o[i]).getQualifiedName());
+ } else {
+ sb.append(sep).append(((MavenGoalSelectionDialog.Entry) o[i]).getName());
+ }
+ }
+ sep = " ";
+ }
+
+ if(pos < len && txt.charAt(pos) != ' ') {
+ sb.append(' ');
+ }
+
+ text.insert(sb.toString());
+ text.setFocus();
+ entriesChanged();
+ }
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org