From 2423d3c11762f2c2295db757873b27c0a37ede17 Mon Sep 17 00:00:00 2001 From: Igor Fedorenko Date: Thu, 17 Apr 2014 16:45:35 -0400 Subject: 432436 mostly working add/edit/remove maven runtime wizard WIP ... also got rid of global settings nonesense, it was only used to calculate local repository location afaict, which does not make much sense, and significanly complicated maven installations preference page. Change-Id: I5d0edcbb2cd905ddbf6c174645591ceeccc87aa8 Signed-off-by: Igor Fedorenko --- org.eclipse.m2e.core.ui/plugin.xml | 2 +- .../org/eclipse/m2e/core/ui/internal/Messages.java | 38 +- .../components/MavenProjectLabelProvider.java | 51 ++ .../components/NestedProjectsComposite.java | 24 +- .../m2e/core/ui/internal/messages.properties | 33 +- .../MavenInstallationsPreferencePage.java | 687 --------------------- .../preferences/launch/ArchiveEntryNode.java | 28 + .../preferences/launch/ClassRealmNode.java | 46 ++ .../preferences/launch/ClasspathEntryNode.java | 27 + .../launch/MavenInstallationWizard.java | 55 ++ .../launch/MavenInstallationWizardPage.java | 351 +++++++++++ .../launch/MavenInstallationsPreferencePage.java | 326 ++++++++++ .../preferences/launch/ProjectEntryNode.java | 30 + org.eclipse.m2e.core/META-INF/MANIFEST.MF | 1 + .../eclipse/m2e/core/embedder/MavenRuntime.java | 2 + .../m2e/core/embedder/MavenRuntimeManager.java | 199 ++++-- .../m2e/core/internal/MavenPluginActivator.java | 6 - .../embedder/AbstractWorkspaceRuntime.java | 177 ------ .../internal/embedder/MavenEmbeddedRuntime.java | 289 --------- .../internal/embedder/MavenExternalRuntime.java | 264 -------- .../internal/embedder/MavenWorkspaceRuntime.java | 52 -- .../internal/embedder/TeslaWorkspaceRuntime.java | 52 -- .../core/internal/launch/AbstractMavenRuntime.java | 47 ++ .../internal/launch/AbstractWorkspaceRuntime.java | 176 ++++++ .../m2e/core/internal/launch/ClasspathEntry.java | 23 + .../core/internal/launch/MavenEmbeddedRuntime.java | 289 +++++++++ .../core/internal/launch/MavenExternalRuntime.java | 259 ++++++++ .../internal/launch/MavenWorkspaceRuntime.java | 52 ++ .../preferences/MavenPreferenceConstants.java | 8 +- 29 files changed, 1968 insertions(+), 1626 deletions(-) create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java delete mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenInstallationsPreferencePage.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ArchiveEntryNode.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClassRealmNode.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClasspathEntryNode.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java create mode 100644 org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ProjectEntryNode.java delete mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java delete mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java delete mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java delete mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java delete mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java create mode 100644 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java diff --git a/org.eclipse.m2e.core.ui/plugin.xml b/org.eclipse.m2e.core.ui/plugin.xml index 467cd3b9..fbc84159 100644 --- a/org.eclipse.m2e.core.ui/plugin.xml +++ b/org.eclipse.m2e.core.ui/plugin.xml @@ -415,7 +415,7 @@ diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java index 4f97e796..d6a84ce7 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java @@ -273,21 +273,13 @@ public class Messages extends NLS { public static String MavenInstallationsPreferencePage_error_global_parse; - public static String MavenInstallationsPreferencePage_error_message; - - public static String MavenInstallationsPreferencePage_error_title; - - public static String MavenInstallationsPreferencePage_error2_message; - public static String MavenInstallationsPreferencePage_error3_message; public static String MavenInstallationsPreferencePage_error4_message; public static String MavenInstallationsPreferencePage_job_updating; - public static String MavenInstallationsPreferencePage_lblNote1; - - public static String MavenInstallationsPreferencePage_lblNote2; + public static String MavenInstallationsPreferencePage_lblNote; public static String MavenInstallationsPreferencePage_link; @@ -911,6 +903,34 @@ public class Messages extends NLS { public static String NestedProjectsComposite_Single_OOD_Project_Link; + public static String ExternalInstallPage_pageName; + + public static String ExternalInstallPage_description; + + public static String ExternalInstallPage_lblInstallationLocation_text; + + public static String ExternalInstallPage_txtLocation_text; + + public static String ExternalInstallPage_btnDirectory_text; + + public static String ExternalInstallPage_lblInstallationLibraries_text; + + public static String ExternalInstallPage_btnRestoreDefault_text; + + public static String ExternalInstallPage_btnAddProject_text; + + public static String ExternalInstallPage_btnRemove_text; + + public static String ExternalInstallPage_btnUp_text; + + public static String ExternalInstallPage_btnDown_text; + + public static String ExternalInstallPage_lblInstallationName_text; + + public static String MavenInstallationsPreferencePage_tblclmnName_text; + + public static String MavenInstallationsPreferencePage_tblclmnDetails_text; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java new file mode 100644 index 00000000..8cbe6aca --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/MavenProjectLabelProvider.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.components; + +import java.beans.Beans; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.IDecoration; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +import org.eclipse.m2e.core.ui.internal.MavenImages; + + +/** + * @since 1.5 + */ +public class MavenProjectLabelProvider extends LabelProvider { + public Image getImage(Object element) { + if(Beans.isDesignTime()) { + // windowbuilder compat + return null; + } + ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); + if(element instanceof IProject && !((IProject) element).isAccessible()) { + return sharedImages.getImage(IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED); + } + + Image img = MavenImages.createOverlayImage(MavenImages.MVN_PROJECT, + sharedImages.getImage(IDE.SharedImages.IMG_OBJ_PROJECT), MavenImages.MAVEN_OVERLAY, IDecoration.TOP_LEFT); + + return img; + } + + public String getText(Object element) { + return element instanceof IProject ? ((IProject) element).getName() : ""; //$NON-NLS-1$ + } + +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java index b826ac86..3eab81dd 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/components/NestedProjectsComposite.java @@ -11,7 +11,6 @@ package org.eclipse.m2e.core.ui.internal.components; -import java.beans.Beans; import java.io.File; import java.net.URI; import java.util.ArrayList; @@ -45,7 +44,6 @@ import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.Viewer; import org.eclipse.osgi.util.NLS; @@ -64,9 +62,6 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.Tree; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.ui.internal.MavenImages; @@ -168,30 +163,15 @@ public class NestedProjectsComposite extends Composite implements IMenuListener return false; } }); - codebaseViewer.setLabelProvider(new LabelProvider() { + codebaseViewer.setLabelProvider(new MavenProjectLabelProvider() { public Image getImage(Object element) { - if(Beans.isDesignTime()) { - // windowbuilder compat - return null; - } - ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); - if(element instanceof IProject && !((IProject) element).isAccessible()) { - return sharedImages.getImage(IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED); - } - - Image img = MavenImages.createOverlayImage(MavenImages.MVN_PROJECT, - sharedImages.getImage(IDE.SharedImages.IMG_OBJ_PROJECT), MavenImages.MAVEN_OVERLAY, IDecoration.TOP_LEFT); + Image img = super.getImage(element); if(showOutOfDateUI && requiresUpdate((IProject) element)) { img = MavenImages.createOverlayImage(MavenImages.OOD_MVN_PROJECT, img, MavenImages.OUT_OF_DATE_OVERLAY, IDecoration.BOTTOM_RIGHT); } - return img; } - - public String getText(Object element) { - return element instanceof IProject ? ((IProject) element).getName() : ""; //$NON-NLS-1$ - } }); projects = getMavenCodebases(); codebaseViewer.setInput(projects); diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties index b7945f81..4247de28 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties @@ -1,5 +1,5 @@ #Eclipse modern messages class -#Thu Oct 10 22:33:49 EDT 2013 +#Fri Apr 18 19:09:55 MSK 2014 AddDependencyAction_error_msg=Can't add dependency to {0} AddDependencyAction_error_title=Add Dependency AddDependencyAction_searchDialog_title=Add Dependency @@ -46,6 +46,17 @@ EditDependencyDialog_type_label=Type\: EditDependencyDialog_version_label=Version\: EnableNatureAction_job_enable=Enabling Maven Dependency Management EnableNatureAction_wizard_shell=Create new POM +ExternalInstallPage_btnAddProject_text=Project... +ExternalInstallPage_btnDirectory_text=Directory... +ExternalInstallPage_btnDown_text=Down +ExternalInstallPage_btnRemove_text=Remove +ExternalInstallPage_btnRestoreDefault_text=Restore Default +ExternalInstallPage_btnUp_text=Up +ExternalInstallPage_description=Specify attributes for a Maven installation +ExternalInstallPage_lblInstallationLibraries_text=Installation libraries\: +ExternalInstallPage_lblInstallationLocation_text=Installation home\: +ExternalInstallPage_lblInstallationName_text=Installation name\: +ExternalInstallPage_pageName=External Installation GlobalRepositoriesNode_name=Global Repositories IndexedArtifactNode_no_pack=[No Packaging] LifecycleMappingPage_actionColumnTitle=Action @@ -166,21 +177,19 @@ MavenInstallationsPreferencePage_dialog_install_message=Select Maven installatio MavenInstallationsPreferencePage_dialog_install_title=Maven Installation MavenInstallationsPreferencePage_dialog_message=Select Maven installation directory MavenInstallationsPreferencePage_dialog_title=Maven Installation -MavenInstallationsPreferencePage_error2_message=The selected directory is not a valid Maven directory. MavenInstallationsPreferencePage_error3_message=The selected Maven install is already registered. MavenInstallationsPreferencePage_error4_message=Selected Maven install is already registered MavenInstallationsPreferencePage_error_global_missing=Global settings file doesn't exist MavenInstallationsPreferencePage_error_global_parse=Unable to parse global settings file; -MavenInstallationsPreferencePage_error_message=Select the directory where Maven is installed. -MavenInstallationsPreferencePage_error_title=Maven Install MavenInstallationsPreferencePage_job_updating=Updating Maven installation settings -MavenInstallationsPreferencePage_lblNote1=Note\: Embedded runtime is always used for dependency resolution, but -MavenInstallationsPreferencePage_lblNote2=does not use global settings when it is used to launch Maven. To learn more, visit the Maven web page. +MavenInstallationsPreferencePage_lblNote=Note\: Embedded runtime is always used for dependency resolution MavenInstallationsPreferencePage_link=Select the installation used to launch Maven\: MavenInstallationsPreferencePage_link_global=Open editor for global settings file MavenInstallationsPreferencePage_link_open=\ (open file) MavenInstallationsPreferencePage_settings=Global settings for embedded installation{0}\: MavenInstallationsPreferencePage_settings_install=Global settings from installation directory{0}\: +MavenInstallationsPreferencePage_tblclmnDetails_text=Details +MavenInstallationsPreferencePage_tblclmnName_text=Name MavenInstallationsPreferencePage_title=Maven Installations MavenModuleWizardParentPage_error=The parent project must have a packaging type of POM MavenPomSelectionComponent_detail1={0} ({1}) @@ -298,6 +307,12 @@ MavenSettingsPreferencePage_task_updating=Updating progress for {0} MavenSettingsPreferencePage_title=Maven User Settings MavenWarningsPreferencePage_groupidDupParent=Disable "{0}" warning MavenWarningsPreferencePage_versionDupParent=Disable "{0}" warning +NestedProjectsComposite_Add_OutOfDate=Add out-of-date +NestedProjectsComposite_Multiple_OOD_Projects_Link={0} unselected projects are out of date and should be updated. Click here to include them. +NestedProjectsComposite_OutOfDateProjectBtn_AddOneProject_Tooltip=Add out-of-date project to the selection +NestedProjectsComposite_OutOfDateProjectBtn_AddProjects_Tooltip=Add {0} out-of-date projects to the selection +NestedProjectsComposite_OutOfDateProjectBtn_Generic_Tooltip=Add out-of-date projects to the selection +NestedProjectsComposite_Single_OOD_Project_Link=One unselected project is out of date and should be updated. Click here to include it. OpenPomAction_33=Can't open editor for {0}\n{1} OpenPomAction_error_download=Can't download {0} OpenPomAction_error_download_source=Can't download sources for {0} @@ -362,12 +377,6 @@ locationComponentDirectory=&Location\: locationComponentInWorkspace=Create project in &workspace locationComponentLocation=Location locationComponentSelectLocation=Select Location -NestedProjectsComposite_Add_OutOfDate=Add out-of-date -NestedProjectsComposite_Single_OOD_Project_Link=One unselected project is out of date and should be updated. Click here to include it. -NestedProjectsComposite_Multiple_OOD_Projects_Link={0} unselected projects are out of date and should be updated. Click here to include them. -NestedProjectsComposite_OutOfDateProjectBtn_AddOneProject_Tooltip=Add out-of-date project to the selection -NestedProjectsComposite_OutOfDateProjectBtn_AddProjects_Tooltip=Add {0} out-of-date projects to the selection -NestedProjectsComposite_OutOfDateProjectBtn_Generic_Tooltip=Add out-of-date projects to the selection pomEditorDefaultPage=Open XML page in the POM editor by default preferencesDebugOutput=Debu&g Output preferencesDownloadJavadoc=Download Artifact &JavaDoc diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenInstallationsPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenInstallationsPreferencePage.java deleted file mode 100644 index c2105492..00000000 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenInstallationsPreferencePage.java +++ /dev/null @@ -1,687 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.ui.internal.preferences; - -import java.io.File; -import java.lang.reflect.Constructor; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.eclipse.core.filesystem.EFS; -import org.eclipse.core.filesystem.IFileStore; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IColorProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -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.graphics.Color; -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.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IPropertyListener; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.browser.IWebBrowser; -import org.eclipse.ui.ide.IDE; - -import org.apache.maven.settings.building.SettingsProblem; - -import org.eclipse.m2e.core.MavenPlugin; -import org.eclipse.m2e.core.embedder.IMaven; -import org.eclipse.m2e.core.embedder.IMavenConfiguration; -import org.eclipse.m2e.core.embedder.MavenRuntime; -import org.eclipse.m2e.core.embedder.MavenRuntimeManager; -import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime; -import org.eclipse.m2e.core.internal.index.IndexManager; -import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants; -import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; -import org.eclipse.m2e.core.ui.internal.Messages; - - -/** - * Maven installations preference page - * - * @author Eugene Kuleshov - */ -public class MavenInstallationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { - private static final Logger log = LoggerFactory.getLogger(MavenInstallationsPreferencePage.class); - - final MavenRuntimeManager runtimeManager; - - final IMavenConfiguration mavenConfiguration; - - final IMaven maven; - - MavenRuntime defaultRuntime; - - List runtimes; - - CheckboxTableViewer runtimesViewer; - - Text globalSettingsText; - - private String globalSettings; - - boolean dirty = false; - - public MavenInstallationsPreferencePage() { - setTitle(Messages.MavenInstallationsPreferencePage_title); - - this.runtimeManager = MavenPlugin.getMavenRuntimeManager(); - this.mavenConfiguration = MavenPlugin.getMavenConfiguration(); - this.maven = MavenPlugin.getMaven(); - } - - public void init(IWorkbench workbench) { - } - - @Override - protected void performDefaults() { - runtimeManager.reset(); - defaultRuntime = runtimeManager.getDefaultRuntime(); - runtimes = runtimeManager.getMavenRuntimes(); - - runtimesViewer.setInput(runtimes); - runtimesViewer.setChecked(defaultRuntime, true); - runtimesViewer.refresh(); - - storeCustom(""); //$NON-NLS-1$ - globalSettingsText.setText(""); //$NON-NLS-1$ - try { - mavenConfiguration.setGlobalSettingsFile(""); //$NON-NLS-1$ - } catch(CoreException e) { - log.error(e.getMessage(), e); - } - - updateGlobals(true); - super.performDefaults(); - setDirty(true); - } - - protected void storeCustom(String dir) { - M2EUIPluginActivator.getDefault().getPreferenceStore().setValue(P_MAVEN_CUSTOM_GLOBAL, dir == null ? "" : dir); //$NON-NLS-1$ - } - - @Override - protected void performApply() { - updateSettings(); - } - - private void updateSettings() { - new Job(Messages.MavenInstallationsPreferencePage_job_updating) { - protected IStatus run(IProgressMonitor monitor) { - String dir = getGlobalSettingsText(); - - runtimeManager.setRuntimes(runtimes); - runtimeManager.setDefaultRuntime(defaultRuntime); - String oldSettings = mavenConfiguration.getGlobalSettingsFile(); - - try { - mavenConfiguration.setGlobalSettingsFile(dir); - } catch(CoreException e) { - log.error(e.getMessage(), e); - throw new RuntimeException(e.getMessage(), e); - } - if(defaultRuntime == null || defaultRuntime instanceof MavenEmbeddedRuntime) { - storeCustom(dir); - } - IndexManager indexManager = MavenPlugin.getIndexManager(); - try { - indexManager.getWorkspaceIndex().updateIndex(true, monitor); - } catch(CoreException ex) { - return ex.getStatus(); - } - if((dir == null && oldSettings != null) || (dir != null && !(dir.equals(oldSettings)))) { - //mavenPlugin.getIndexManager().scheduleIndexUpdate(IndexManager.LOCAL_INDEX, true, 0L); - } - return Status.OK_STATUS; - } - }.schedule(); - } - - @Override - public boolean performOk() { - if(dirty) { - updateSettings(); - } - return true; - } - - public void setDirty(boolean dirty) { - this.dirty = dirty; - } - - public boolean isDirty() { - return this.dirty; - } - - protected boolean validateMavenInstall(String dir) { - if(dir == null || dir.length() == 0) { - return false; - } - File selectedDir = new File(dir); - if(!selectedDir.isDirectory()) { - MessageDialog.openError(getShell(), Messages.MavenInstallationsPreferencePage_error_title, - Messages.MavenInstallationsPreferencePage_error_message); - return false; - } - File binDir = new File(dir, "bin"); //$NON-NLS-1$ - File confDir = new File(dir, "conf"); //$NON-NLS-1$ - File libDir = new File(dir, "lib"); //$NON-NLS-1$ - if(!binDir.exists() || !confDir.exists() || !libDir.exists()) { - MessageDialog.openError(getShell(), Messages.MavenInstallationsPreferencePage_error_title, - Messages.MavenInstallationsPreferencePage_error2_message); - return false; - } - return true; - } - - protected Control createContents(Composite parent) { - - Composite composite = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(3, false); - gridLayout.marginBottom = 5; - gridLayout.marginRight = 5; - gridLayout.marginHeight = 0; - gridLayout.marginWidth = 0; - composite.setLayout(gridLayout); - - Label link = new Label(composite, SWT.NONE); - link.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1)); - link.setText(Messages.MavenInstallationsPreferencePage_link); - - createTable(composite); - createGlobalSettings(composite); - - defaultRuntime = runtimeManager.getDefaultRuntime(); - runtimes = runtimeManager.getMavenRuntimes(); - - runtimesViewer.setInput(runtimes); - runtimesViewer.setChecked(defaultRuntime, true); - runtimesViewer.refresh(); // should listen on property changes instead? - - checkSettings(); - updateGlobals(false); - globalSettingsText.addModifyListener(new ModifyListener() { - public void modifyText(ModifyEvent modifyevent) { - setGlobalSettingsText(globalSettingsText.getText()); - updateGlobalSettingsLink(); - checkSettings(); - setDirty(true); - } - }); - - return composite; - } - - /** - * - */ - private void updateGlobalSettingsText(boolean useLastCustomGlobal) { - String globalSettings = getGlobalSettingsFile(useLastCustomGlobal); - globalSettingsText.setText(globalSettings == null ? "" : globalSettings); //$NON-NLS-1$ - } - - /** - * Use this to retrieve the global settings file which has not been applied yet - * - * @return - */ - private String getGlobalSettingsFile(boolean useLastCustomGlobal) { - if(defaultRuntime == null || defaultRuntime instanceof MavenEmbeddedRuntime) { - String globalSettings = null; - if(useLastCustomGlobal) { - globalSettings = M2EUIPluginActivator.getDefault().getPreferenceStore().getString(P_MAVEN_CUSTOM_GLOBAL); - } else { - globalSettings = M2EUIPluginActivator.getDefault().getPreferenceStore() - .getString(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE); - } - return globalSettings.trim().length() == 0 ? null : globalSettings; - } - return defaultRuntime == null ? null : defaultRuntime.getSettings(); - } - - public void setGlobalSettingsText(String settings) { - this.globalSettings = settings; - } - - public String getGlobalSettingsText() { - return this.globalSettings; - } - - /** - * - */ - private void updateGlobals(boolean useLastCustomGlobal) { - updateGlobalSettingsText(useLastCustomGlobal); - updateGlobalSettingsLink(); - updateGlobalSettingsBrowseButton(); - } - - private Link globalSettingsLink; - - private Button globalSettingsBrowseButton; - - private MavenRuntime getCheckedRuntime() { - Object[] runtimes = runtimesViewer.getCheckedElements(); - if(runtimes != null && runtimes.length > 0) { - return (MavenRuntime) runtimes[0]; - } - return null; - } - - protected MavenRuntime getSelectedMavenRuntime() { - IStructuredSelection sel = (IStructuredSelection) runtimesViewer.getSelection(); - return (MavenRuntime) sel.getFirstElement(); - } - - private void updateGlobalSettingsLink() { - MavenRuntime runtime = getCheckedRuntime(); - String text = ""; //$NON-NLS-1$ - String currText = globalSettingsText.getText(); - boolean showURL = false; - - File f = new File(currText); - if(f.exists()) { - showURL = true; - } - String openFile = showURL ? Messages.MavenInstallationsPreferencePage_link_open : ""; //$NON-NLS-1$ - if(runtime instanceof MavenEmbeddedRuntime) { - text = NLS.bind(Messages.MavenInstallationsPreferencePage_settings, openFile); - } else { - text = NLS.bind(Messages.MavenInstallationsPreferencePage_settings_install, openFile); - } - globalSettingsLink.setText(text); - } - - private void updateGlobalSettingsBrowseButton() { - MavenRuntime runtime = getCheckedRuntime(); - boolean enabled = (runtime != null && (runtime instanceof MavenEmbeddedRuntime)); - globalSettingsBrowseButton.setEnabled(enabled); - globalSettingsText.setEditable(enabled); - } - - private void createGlobalSettings(Composite composite) { - globalSettingsLink = new Link(composite, SWT.NONE); - globalSettingsLink.setData("name", "globalSettingsLink"); //$NON-NLS-1$ //$NON-NLS-2$ - - globalSettingsLink.setToolTipText(Messages.MavenInstallationsPreferencePage_link_global); - GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1); - gd.verticalIndent = 25; - globalSettingsLink.setLayoutData(gd); - - globalSettingsLink.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String globalSettings = getGlobalSettings(); - if(globalSettings.length() == 0) { - globalSettings = defaultRuntime.getSettings(); - } - if(globalSettings != null && globalSettings.length() > 0) { - openEditor(globalSettings); - } - } - }); - - globalSettingsText = new Text(composite, SWT.BORDER); - globalSettingsText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); - globalSettingsText.setData("name", "globalSettingsText"); //$NON-NLS-1$ //$NON-NLS-2$ - globalSettingsBrowseButton = new Button(composite, SWT.NONE); - GridData gd_globalSettingsBrowseButton = new GridData(SWT.FILL, SWT.CENTER, false, false); - globalSettingsBrowseButton.setLayoutData(gd_globalSettingsBrowseButton); - globalSettingsBrowseButton.setText(Messages.MavenInstallationsPreferencePage_btnGlobalBrowse); - globalSettingsBrowseButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog(getShell(), SWT.OPEN); - if(getGlobalSettings().length() > 0) { - dialog.setFileName(getGlobalSettings()); - } - String file = dialog.open(); - if(file != null) { - file = file.trim(); - if(file.length() > 0) { - globalSettingsText.setText(file); - } - } - } - }); - } - - private void createTable(Composite composite) { - runtimesViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); - - runtimesViewer.setLabelProvider(new RuntimesLabelProvider()); - - runtimesViewer.setContentProvider(new IStructuredContentProvider() { - - @SuppressWarnings("unchecked") - public Object[] getElements(Object input) { - if(input instanceof List) { - List list = (List) input; - if(list.size() > 0) { - return list.toArray(new MavenRuntime[list.size()]); - } - } - return new Object[0]; - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - public void dispose() { - } - - }); - - Table table = runtimesViewer.getTable(); - table.setLinesVisible(false); - table.setHeaderVisible(false); - GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 3); - gd_table.heightHint = 151; - gd_table.widthHint = 333; - table.setLayoutData(gd_table); - - Button addButton = new Button(composite, SWT.NONE); - addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); - addButton.setText(Messages.MavenInstallationsPreferencePage_btnAdd); - addButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - DirectoryDialog dlg = new DirectoryDialog(getShell()); - dlg.setText(Messages.MavenInstallationsPreferencePage_dialog_install_title); - dlg.setMessage(Messages.MavenInstallationsPreferencePage_dialog_install_message); - String dir = dlg.open(); - if(dir == null) { - return; - } - boolean ok = validateMavenInstall(dir); - if(ok) { - MavenRuntime runtime = MavenRuntimeManager.createExternalRuntime(dir); - if(runtimes.contains(runtime)) { - MessageDialog.openError(getShell(), Messages.MavenInstallationsPreferencePage_error_title, - Messages.MavenInstallationsPreferencePage_error3_message); - } else { - runtimes.add(runtime); - runtimesViewer.refresh(); - runtimesViewer.setAllChecked(false); - runtimesViewer.setChecked(runtime, true); - if(runtime != null) { - setCheckedRuntime(runtime); - } - } - } - } - }); - - final Button editButton = new Button(composite, SWT.NONE); - editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); - editButton.setEnabled(false); - editButton.setText(Messages.MavenInstallationsPreferencePage_btnEdit); - editButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - MavenRuntime runtime = getSelectedMavenRuntime(); - DirectoryDialog dlg = new DirectoryDialog(Display.getCurrent().getActiveShell()); - dlg.setText(Messages.MavenInstallationsPreferencePage_dialog_title); - dlg.setMessage(Messages.MavenInstallationsPreferencePage_dialog_message); - dlg.setFilterPath(runtime.getLocation()); - String dir = dlg.open(); - boolean ok = validateMavenInstall(dir); - if(ok && !dir.equals(runtime.getLocation())) { - MavenRuntime newRuntime = MavenRuntimeManager.createExternalRuntime(dir); - if(runtimes.contains(newRuntime)) { - MessageDialog.openError(getShell(), Messages.MavenInstallationsPreferencePage_error_title, - Messages.MavenInstallationsPreferencePage_error4_message); - } else { - runtimes.set(runtimes.indexOf(runtime), newRuntime); - runtimesViewer.refresh(); - setDirty(true); - if(newRuntime != null) { - setCheckedRuntime(newRuntime); - } - } - } - } - }); - - final Button removeButton = new Button(composite, SWT.NONE); - removeButton.setEnabled(false); - removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); - removeButton.setText(Messages.MavenInstallationsPreferencePage_btnRemove); - removeButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - MavenRuntime runtime = getSelectedMavenRuntime(); - runtimes.remove(runtime); - runtimesViewer.refresh(); - Object[] checkedElements = runtimesViewer.getCheckedElements(); - if(checkedElements == null || checkedElements.length == 0) { - defaultRuntime = runtimeManager.getRuntime(MavenRuntimeManager.EMBEDDED); - runtimesViewer.setChecked(defaultRuntime, true); - setCheckedRuntime(defaultRuntime); - } - setDirty(true); - } - }); - - runtimesViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if(runtimesViewer.getSelection() instanceof IStructuredSelection) { - MavenRuntime runtime = getSelectedMavenRuntime(); - boolean isEnabled = runtime != null && runtime.isEditable(); - removeButton.setEnabled(isEnabled); - editButton.setEnabled(isEnabled); - } - } - }); - - runtimesViewer.addCheckStateListener(new ICheckStateListener() { - public void checkStateChanged(CheckStateChangedEvent event) { - if(event.getElement() != null && event.getChecked()) { - - setCheckedRuntime((MavenRuntime) event.getElement()); - } - } - }); - Link noteLabel = new Link(composite, SWT.WRAP | SWT.READ_ONLY); - GridData noteLabelData = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1); - noteLabelData.horizontalIndent = 15; - noteLabelData.widthHint = 100; - - noteLabel.setLayoutData(noteLabelData); - noteLabel.setText(Messages.MavenInstallationsPreferencePage_lblNote1 - + Messages.MavenInstallationsPreferencePage_lblNote2); - noteLabel.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - try { - URL url = new URL(e.text); - IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser(); - browser.openURL(url); - } catch(MalformedURLException ex) { - log.error("Malformed URL", ex); //$NON-NLS-1$ - } catch(PartInitException ex) { - log.error(ex.getMessage(), ex); - } - } - }); - } - - private static final String P_MAVEN_CUSTOM_GLOBAL = "customGlobalSettingsFile"; //$NON-NLS-1$ - - protected void setCheckedRuntime(MavenRuntime runtime) { - runtimesViewer.setAllChecked(false); - runtimesViewer.setChecked(runtime, true); - defaultRuntime = runtime; - boolean useDefault = (defaultRuntime == null || defaultRuntime instanceof MavenEmbeddedRuntime); - updateGlobals(useDefault); - setDirty(true); - } - - void checkSettings() { - setErrorMessage(null); - setMessage(null); - - String globalSettings = getGlobalSettings(); - if(globalSettings != null && globalSettings.length() > 0) { - File globalSettingsFile = new File(globalSettings); - if(!globalSettingsFile.exists()) { - setMessage(Messages.MavenInstallationsPreferencePage_error_global_missing, IMessageProvider.WARNING); - globalSettings = null; - } - } else { - globalSettings = null; - } - - List result = maven.validateSettings(globalSettings); - if(result.size() > 0) { - setMessage(Messages.MavenInstallationsPreferencePage_error_global_parse + result.get(0).getMessage(), - IMessageProvider.WARNING); - } - - } - - @SuppressWarnings("rawtypes") - void openEditor(final String fileName) { - // XXX create new settings.xml if does not exist - - IWorkbench workbench = PlatformUI.getWorkbench(); - IWorkbenchWindow window = workbench.getActiveWorkbenchWindow(); - IWorkbenchPage page = window.getActivePage(); - - IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor("settings.xml"); //$NON-NLS-1$ - - File file = new File(fileName); - IEditorInput input = null; - try { - //class implementing editor input for external file has been renamed in eclipse 3.3, hence reflection - Class javaInput = null; - try { - javaInput = Class.forName("org.eclipse.ui.internal.editors.text.JavaFileEditorInput"); //$NON-NLS-1$ - Constructor cons = javaInput.getConstructor(new Class[] {File.class}); - input = (IEditorInput) cons.newInstance(new Object[] {file}); - } catch(Exception e) { - try { - IFileStore fileStore = EFS.getLocalFileSystem().fromLocalFile(file); - Class storeInput = Class.forName("org.eclipse.ui.ide.FileStoreEditorInput"); //$NON-NLS-1$ - Constructor cons = storeInput.getConstructor(new Class[] {IFileStore.class}); - input = (IEditorInput) cons.newInstance(new Object[] {fileStore}); - } catch(Exception ex) { - //ignore... - } - } - final IEditorPart editor = IDE.openEditor(page, input, desc.getId()); - editor.addPropertyListener(new IPropertyListener() { - public void propertyChanged(Object source, int propId) { - if(!editor.isDirty()) { - log.info("Refreshing settings " + fileName); //$NON-NLS-1$ - invalidateMavenSettings(false); - } - } - }); - - } catch(PartInitException ex) { - log.error(ex.getMessage(), ex); - } - } - - void invalidateMavenSettings(final boolean reindex) { -// new Job("Invalidating Maven settings") { -// protected IStatus run(IProgressMonitor monitor) { -// mavenPlugin.getMavenEmbedderManager().invalidateMavenSettings(); -// if(reindex) { -// mavenPlugin.getIndexManager().scheduleIndexUpdate(IndexManager.LOCAL_INDEX, true, 0L); -// } -// return Status.OK_STATUS; -// } -// }.schedule(); - } - - String getGlobalSettings() { - return globalSettingsText.getText().trim(); - } - - static class RuntimesLabelProvider implements ITableLabelProvider, IColorProvider { - - public String getColumnText(Object element, int columnIndex) { - MavenRuntime runtime = (MavenRuntime) element; - return runtime.toString(); - } - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - public Color getBackground(Object element) { - return null; - } - - public Color getForeground(Object element) { - MavenRuntime runtime = (MavenRuntime) element; - if(!runtime.isEditable()) { - return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); - } - return null; - } - - public void dispose() { - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void addListener(ILabelProviderListener listener) { - } - - public void removeListener(ILabelProviderListener listener) { - } - - } - -} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ArchiveEntryNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ArchiveEntryNode.java new file mode 100644 index 00000000..d9c7bb23 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ArchiveEntryNode.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +public class ArchiveEntryNode extends ClasspathEntryNode { + + private String location; + + public ArchiveEntryNode(ClassRealmNode realm, String location) { + super(realm); + this.location = location; + } + + @Override + public String getName() { + return location; + } + +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClassRealmNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClassRealmNode.java new file mode 100644 index 00000000..52646d09 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClassRealmNode.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +import java.util.List; + + +public class ClassRealmNode { + private String name; + + private List classpath; + + public ClassRealmNode(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public List getClasspath() { + return classpath; + } + + public void setClasspath(List classpath) { + this.classpath = classpath; + } + + public int getIndex(ClasspathEntryNode entry) { + for(int i = 0; i < classpath.size(); i++ ) { + if(classpath.get(i) == entry) { + return i; + } + } + return 0; + } +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClasspathEntryNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClasspathEntryNode.java new file mode 100644 index 00000000..efb4661d --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ClasspathEntryNode.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +public abstract class ClasspathEntryNode { + + private ClassRealmNode realm; + + public ClasspathEntryNode(ClassRealmNode realm) { + this.realm = realm; + } + + public ClassRealmNode getRealm() { + return this.realm; + } + + public abstract String getName(); +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java new file mode 100644 index 00000000..f772b8b3 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizard.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +import org.eclipse.jface.wizard.Wizard; + +import org.eclipse.m2e.core.embedder.MavenRuntime; +import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime; + + +@SuppressWarnings("restriction") +public class MavenInstallationWizard extends Wizard { + + private final MavenInstallationWizardPage runtimePage; + + private MavenRuntime original; + + private MavenRuntime result; + + public MavenInstallationWizard() { + this.runtimePage = new MavenInstallationWizardPage(null); + setWindowTitle("New Maven Runtime"); + } + + public MavenInstallationWizard(MavenRuntime runtime) { + this.original = runtime; + this.runtimePage = new MavenInstallationWizardPage((AbstractMavenRuntime) original); + setWindowTitle("Edit Maven Runtime"); + } + + @Override + public void addPages() { + addPage(runtimePage); + } + + @Override + public boolean performFinish() { + result = runtimePage.getResult(); + return true; + } + + public MavenRuntime getResult() { + return result; + } + +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java new file mode 100644 index 00000000..3872207b --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationWizardPage.java @@ -0,0 +1,351 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.swt.SWT; +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.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.DirectoryDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.ui.dialogs.ListSelectionDialog; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime; +import org.eclipse.m2e.core.internal.launch.MavenExternalRuntime; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.ui.internal.Messages; +import org.eclipse.m2e.core.ui.internal.components.MavenProjectLabelProvider; + + +@SuppressWarnings("restriction") +public class MavenInstallationWizardPage extends WizardPage { + + private List realms; + + private Text location; + + private Button btnAddProject; + + private Button btnRemove; + + private Button btnUp; + + private Button btnDown; + + private TreeViewer treeViewerLibrariries; + + private Text name; + + private AbstractMavenRuntime original; + + class TreeContentProvider implements ITreeContentProvider { + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public Object[] getElements(Object inputElement) { + return ((Collection) inputElement).toArray(); + } + + public Object[] getChildren(Object parentElement) { + if(parentElement instanceof ClassRealmNode) { + return ((ClassRealmNode) parentElement).getClasspath().toArray(); + } + return null; + } + + public Object getParent(Object element) { + return null; + } + + public boolean hasChildren(Object element) { + return element instanceof ClassRealmNode; + } + + } + + class TreeLabelProvider implements ILabelProvider { + + public void addListener(ILabelProviderListener listener) { + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + } + + public Image getImage(Object element) { + return null; + } + + public String getText(Object element) { + if(element instanceof ClassRealmNode) { + return ((ClassRealmNode) element).getName(); + } else if(element instanceof ClasspathEntryNode) { + return ((ClasspathEntryNode) element).getName(); + } + return null; + } + } + + public MavenInstallationWizardPage(AbstractMavenRuntime original) { + super(Messages.ExternalInstallPage_pageName); + this.original = original; + setDescription(Messages.ExternalInstallPage_description); + + List realms = new ArrayList(); +// for(Map.Entry> realm : installation.getRealms().entrySet()) { +// ClassRealmNode realmNode = new ClassRealmNode(realm.getKey()); +// realmNode.setClasspath(toClasspathEntries(realmNode, realm.getValue())); +// realms.add(realmNode); +// } + this.realms = realms; + + } + + public List toClasspathEntries(ClassRealmNode realm, List classpath) { + List result = new ArrayList(); + for(String entry : classpath) { + result.add(new ArchiveEntryNode(realm, entry)); + } + return result; + } + + public void createControl(Composite parent) { + Composite container = new Composite(parent, SWT.NULL); + + setControl(container); + container.setLayout(new GridLayout(3, false)); + + Label lblInstallationLocation = new Label(container, SWT.NONE); + lblInstallationLocation.setText(Messages.ExternalInstallPage_lblInstallationLocation_text); + + location = new Text(container, SWT.BORDER); + location.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateStatus(); + } + }); + location.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + + Button btnDirectory = new Button(container, SWT.NONE); + btnDirectory.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + selectLocationAction(); + } + }); + btnDirectory.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + btnDirectory.setText(Messages.ExternalInstallPage_btnDirectory_text); + + Label lblInstallationName = new Label(container, SWT.NONE); + lblInstallationName.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblInstallationName.setText(Messages.ExternalInstallPage_lblInstallationName_text); + + name = new Text(container, SWT.BORDER); + name.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + updateStatus(); + } + }); + name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1)); + + Label lblInstallationLibraries = new Label(container, SWT.NONE); + lblInstallationLibraries.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); + lblInstallationLibraries.setText(Messages.ExternalInstallPage_lblInstallationLibraries_text); + + treeViewerLibrariries = new TreeViewer(container, SWT.BORDER); + treeViewerLibrariries.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateButtonsState(); + } + }); + treeViewerLibrariries.setContentProvider(new TreeContentProvider()); + treeViewerLibrariries.setLabelProvider(new TreeLabelProvider()); + treeViewerLibrariries.setInput(realms); + Tree treeLibraries = treeViewerLibrariries.getTree(); + treeLibraries.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 5)); + + btnAddProject = new Button(container, SWT.NONE); + btnAddProject.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + addProjectAction(); + } + }); + btnAddProject.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + btnAddProject.setText(Messages.ExternalInstallPage_btnAddProject_text); + + btnRemove = new Button(container, SWT.NONE); + btnRemove.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + btnRemove.setText(Messages.ExternalInstallPage_btnRemove_text); + + btnUp = new Button(container, SWT.NONE); + btnUp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + btnUp.setText(Messages.ExternalInstallPage_btnUp_text); + + btnDown = new Button(container, SWT.NONE); + btnDown.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1)); + btnDown.setText(Messages.ExternalInstallPage_btnDown_text); + + Button btnRestoreDefault = new Button(container, SWT.NONE); + btnRestoreDefault.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, false, false, 1, 1)); + btnRestoreDefault.setText(Messages.ExternalInstallPage_btnRestoreDefault_text); + + if(original != null) { + location.setText(original.getLocation()); + if(!original.isLegacy()) { + name.setText(original.getName()); + } + } + + updateButtonsState(); + updateStatus(); + } + + protected void updateButtonsState() { + Object selection = getSelectedElement(); + + // can move/remove classpath entries only + boolean editEnabled = selection instanceof ClasspathEntryNode; + btnUp.setEnabled(editEnabled); + btnDown.setEnabled(editEnabled); + btnRemove.setEnabled(editEnabled); + + // add project requires insertion point + btnAddProject.setEnabled(selection != null); + } + + private Object getSelectedElement() { + return ((IStructuredSelection) treeViewerLibrariries.getSelection()).getFirstElement(); + } + + protected void addProjectAction() { + List projects = new ArrayList(); + for(IMavenProjectFacade facade : MavenPlugin.getMavenProjectRegistry().getProjects()) { + projects.add(facade.getProject()); + } + ListSelectionDialog dialog = new ListSelectionDialog(getShell(), projects, new ArrayContentProvider(), + new MavenProjectLabelProvider(), "Select projects to add:"); + dialog.setTitle("Project selection"); + dialog.setHelpAvailable(false); + if(dialog.open() == Window.OK) { + Object insertionPoint = getSelectedElement(); + if(insertionPoint instanceof ClassRealmNode) { + ClassRealmNode realm = (ClassRealmNode) insertionPoint; + for(Object object : dialog.getResult()) { + realm.getClasspath().add(0, new ProjectEntryNode(realm, (IProject) object)); + } + } else if(insertionPoint instanceof ClasspathEntryNode) { + ClasspathEntryNode entry = (ClasspathEntryNode) insertionPoint; + ClassRealmNode realm = entry.getRealm(); + int idx = realm.getIndex(entry); + for(Object object : dialog.getResult()) { + realm.getClasspath().add(idx, new ProjectEntryNode(realm, (IProject) object)); + } + } else { + throw new IllegalStateException(); + } + treeViewerLibrariries.refresh(); + } + } + + protected void selectLocationAction() { + DirectoryDialog dlg = new DirectoryDialog(getShell()); + dlg.setText(Messages.MavenInstallationsPreferencePage_dialog_install_title); + dlg.setMessage(Messages.MavenInstallationsPreferencePage_dialog_install_message); + String dir = dlg.open(); + if(dir == null) { + return; + } + location.setText(dir); + } + + private boolean isValidMavenInstall(String dir) { + if(dir == null || dir.length() == 0) { + return false; + } + File selectedDir = new File(dir); + if(!selectedDir.isDirectory()) { + return false; + } + File binDir = new File(dir, "bin"); //$NON-NLS-1$ + File confDir = new File(dir, "conf"); //$NON-NLS-1$ + File libDir = new File(dir, "lib"); //$NON-NLS-1$ + if(!binDir.exists() || !confDir.exists() || !libDir.exists()) { + return false; + } + return true; + } + + protected void updateStatus() { + setPageComplete(false); + + if(location.getText().trim().isEmpty()) { + setMessage("Enter the home directory of the Maven Installation"); + return; + } + + if(!isValidMavenInstall(location.getText())) { + setErrorMessage("Target is not a Maven Home"); + return; + } + + if(name.getText().trim().isEmpty()) { + setMessage("Enter a name for the Maven Installation"); + return; + } + + // TODO name is unique + + setMessage(null); + setPageComplete(true); + } + + public AbstractMavenRuntime getResult() { + return new MavenExternalRuntime(name.getText(), location.getText()); + } +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java new file mode 100644 index 00000000..9a52aeb9 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/MavenInstallationsPreferencePage.java @@ -0,0 +1,326 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +import java.util.List; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.IColorProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +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.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +import org.eclipse.m2e.core.MavenPlugin; +import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.core.embedder.MavenRuntime; +import org.eclipse.m2e.core.embedder.MavenRuntimeManager; +import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime; +import org.eclipse.m2e.core.ui.internal.Messages; + + +/** + * Maven installations preference page + * + * @author Eugene Kuleshov + */ +@SuppressWarnings("restriction") +public class MavenInstallationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { + + final MavenRuntimeManager runtimeManager; + + final IMavenConfiguration mavenConfiguration; + + final IMaven maven; + + String defaultRuntime; + + List runtimes; + + CheckboxTableViewer runtimesViewer; + + public MavenInstallationsPreferencePage() { + setTitle(Messages.MavenInstallationsPreferencePage_title); + + this.runtimeManager = MavenPlugin.getMavenRuntimeManager(); + this.mavenConfiguration = MavenPlugin.getMavenConfiguration(); + this.maven = MavenPlugin.getMaven(); + } + + public void init(IWorkbench workbench) { + } + + @Override + protected void performDefaults() { + runtimeManager.reset(); + defaultRuntime = runtimeManager.getDefaultRuntime().getName(); + runtimes = runtimeManager.getMavenRuntimes(); + + runtimesViewer.setInput(runtimes); + refreshRuntimesViewer(); + + super.performDefaults(); + } + + @Override + public boolean performOk() { + runtimeManager.setRuntimes(runtimes); + runtimeManager.setDefaultRuntime(getDefaultRuntime()); + return true; + } + + protected Control createContents(Composite parent) { + + Composite composite = new Composite(parent, SWT.NONE); + GridLayout gridLayout = new GridLayout(3, false); + gridLayout.marginBottom = 5; + gridLayout.marginRight = 5; + gridLayout.marginHeight = 0; + gridLayout.marginWidth = 0; + composite.setLayout(gridLayout); + + Label link = new Label(composite, SWT.NONE); + link.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 3, 1)); + link.setText(Messages.MavenInstallationsPreferencePage_link); + + createTable(composite); + new Label(composite, SWT.NONE); + + defaultRuntime = runtimeManager.getDefaultRuntime().getName(); + runtimes = runtimeManager.getMavenRuntimes(); + + runtimesViewer.setInput(runtimes); + refreshRuntimesViewer(); + + return composite; + } + + private MavenRuntime getDefaultRuntime() { + MavenRuntime embedded = null; + for(MavenRuntime runtime : runtimes) { + if(defaultRuntime.equals(runtime.getName())) { + return runtime; + } else if(MavenRuntimeManager.EMBEDDED.equals(runtime.getName())) { + embedded = runtime; + } + } + return embedded; + } + + protected void refreshRuntimesViewer() { + runtimesViewer.refresh(); // should listen on property changes instead? + + Object[] checkedElements = runtimesViewer.getCheckedElements(); + if(checkedElements == null || checkedElements.length == 0) { + MavenRuntime runtime = getDefaultRuntime(); + runtimesViewer.setChecked(runtime, true); + defaultRuntime = runtime.getName(); + } + + for(TableColumn column : runtimesViewer.getTable().getColumns()) { + column.pack(); + } + } + + protected MavenRuntime getSelectedMavenRuntime() { + IStructuredSelection sel = (IStructuredSelection) runtimesViewer.getSelection(); + return (MavenRuntime) sel.getFirstElement(); + } + + private void createTable(Composite composite) { + runtimesViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION); + + runtimesViewer.setLabelProvider(new RuntimesLabelProvider()); + + runtimesViewer.setContentProvider(new IStructuredContentProvider() { + + public Object[] getElements(Object input) { + if(input instanceof List) { + List list = (List) input; + if(list.size() > 0) { + return list.toArray(new MavenRuntime[list.size()]); + } + } + return new Object[0]; + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + public void dispose() { + } + + }); + + Table table = runtimesViewer.getTable(); + table.setLinesVisible(true); + table.setHeaderVisible(true); + GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 3); + gd_table.heightHint = 151; + gd_table.widthHint = 333; + table.setLayoutData(gd_table); + + TableColumn tblclmnName = new TableColumn(table, SWT.NONE); + tblclmnName.setWidth(100); + tblclmnName.setText(Messages.MavenInstallationsPreferencePage_tblclmnName_text); + + TableColumn tblclmnDetails = new TableColumn(table, SWT.NONE); + tblclmnDetails.setWidth(100); + tblclmnDetails.setText(Messages.MavenInstallationsPreferencePage_tblclmnDetails_text); + + Button addButton = new Button(composite, SWT.NONE); + addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + addButton.setText(Messages.MavenInstallationsPreferencePage_btnAdd); + addButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + MavenInstallationWizard wizard = new MavenInstallationWizard(); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + if(dialog.open() == Window.OK) { + runtimes.add(wizard.getResult()); + refreshRuntimesViewer(); + } + } + }); + + final Button editButton = new Button(composite, SWT.NONE); + editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + editButton.setEnabled(false); + editButton.setText(Messages.MavenInstallationsPreferencePage_btnEdit); + editButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + MavenRuntime runtime = getSelectedMavenRuntime(); + MavenInstallationWizard wizard = new MavenInstallationWizard(runtime); + WizardDialog dialog = new WizardDialog(getShell(), wizard); + if(dialog.open() == Window.OK) { + MavenRuntime updatedRuntime = wizard.getResult(); + for(int i = 0; i < runtimes.size(); i++ ) { + if(runtime == runtimes.get(i)) { + runtimes.set(i, updatedRuntime); + break; + } + } + refreshRuntimesViewer(); + } + } + }); + + final Button removeButton = new Button(composite, SWT.NONE); + removeButton.setEnabled(false); + removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false)); + removeButton.setText(Messages.MavenInstallationsPreferencePage_btnRemove); + removeButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + MavenRuntime runtime = getSelectedMavenRuntime(); + runtimes.remove(runtime); + refreshRuntimesViewer(); + } + }); + + runtimesViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if(runtimesViewer.getSelection() instanceof IStructuredSelection) { + MavenRuntime runtime = getSelectedMavenRuntime(); + boolean isEnabled = runtime != null && runtime.isEditable(); + removeButton.setEnabled(isEnabled); + editButton.setEnabled(isEnabled); + } + } + }); + + runtimesViewer.addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + if(event.getElement() != null && event.getChecked()) { + setCheckedRuntime((MavenRuntime) event.getElement()); + } + } + }); + Label noteLabel = new Label(composite, SWT.WRAP); + GridData noteLabelData = new GridData(SWT.FILL, SWT.TOP, false, false, 2, 1); + noteLabelData.widthHint = 100; + + noteLabel.setLayoutData(noteLabelData); + noteLabel.setText(Messages.MavenInstallationsPreferencePage_lblNote); + } + + protected void setCheckedRuntime(MavenRuntime runtime) { + runtimesViewer.setAllChecked(false); + runtimesViewer.setChecked(runtime, true); + defaultRuntime = runtime.getName(); + } + + static class RuntimesLabelProvider implements ITableLabelProvider, IColorProvider { + + public String getColumnText(Object element, int columnIndex) { + AbstractMavenRuntime runtime = (AbstractMavenRuntime) element; + if(columnIndex == 0) { + return !runtime.isLegacy() ? runtime.getName() : null; + } + return runtime.toString(); + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public Color getBackground(Object element) { + return null; + } + + public Color getForeground(Object element) { + MavenRuntime runtime = (MavenRuntime) element; + if(!runtime.isEditable()) { + return Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY); + } + return null; + } + + public void dispose() { + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void addListener(ILabelProviderListener listener) { + } + + public void removeListener(ILabelProviderListener listener) { + } + + } + +} diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ProjectEntryNode.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ProjectEntryNode.java new file mode 100644 index 00000000..cec1e173 --- /dev/null +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/launch/ProjectEntryNode.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.ui.internal.preferences.launch; + +import org.eclipse.core.resources.IProject; + + +public class ProjectEntryNode extends ClasspathEntryNode { + + private IProject project; + + public ProjectEntryNode(ClassRealmNode realm, IProject project) { + super(realm); + this.project = project; + } + + @Override + public String getName() { + return project.getName(); + } +} diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF index fbd628c4..e1d7a9ba 100644 --- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF @@ -31,6 +31,7 @@ Export-Package: org.eclipse.m2e.core, org.eclipse.m2e.core.internal.index.filter;x-internal:=true, org.eclipse.m2e.core.internal.index.nexus;x-internal:=true, org.eclipse.m2e.core.internal.jobs;x-internal:=true, + org.eclipse.m2e.core.internal.launch;x-internal:=true, org.eclipse.m2e.core.internal.lifecyclemapping;x-internal:=true, org.eclipse.m2e.core.internal.lifecyclemapping.discovery;x-internal:=true, org.eclipse.m2e.core.internal.lifecyclemapping.model;x-internal:=true, diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntime.java index 65fc8fba..3f03aa03 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntime.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntime.java @@ -33,6 +33,8 @@ public interface MavenRuntime { public abstract void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor) throws CoreException; + public abstract String getName(); + public abstract String getLocation(); public abstract String getSettings(); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java index 28335f3a..73f38e50 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenRuntimeManager.java @@ -16,6 +16,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.osgi.service.prefs.BackingStoreException; +import org.osgi.service.prefs.Preferences; + import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; @@ -23,8 +26,12 @@ import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.m2e.core.internal.IMavenConstants; -import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime; -import org.eclipse.m2e.core.internal.embedder.MavenExternalRuntime; +import org.eclipse.m2e.core.internal.MavenPluginActivator; +import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime; +import org.eclipse.m2e.core.internal.launch.ClasspathEntry; +import org.eclipse.m2e.core.internal.launch.MavenEmbeddedRuntime; +import org.eclipse.m2e.core.internal.launch.MavenExternalRuntime; +import org.eclipse.m2e.core.internal.launch.MavenWorkspaceRuntime; import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants; @@ -46,56 +53,64 @@ public class MavenRuntimeManager { private final IPreferencesService preferenceStore; - private Map runtimes = new LinkedHashMap(); - - private MavenRuntime embeddedRuntime; - - private MavenRuntime defaultRuntime; - public MavenRuntimeManager() { this.preferenceStore = Platform.getPreferencesService(); - - this.preferencesLookup[0] = new InstanceScope().getNode(IMavenConstants.PLUGIN_ID); - this.preferencesLookup[1] = new DefaultScope().getNode(IMavenConstants.PLUGIN_ID); - - initRuntimes(); + this.preferencesLookup[0] = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); + this.preferencesLookup[1] = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); } + /** + * @deprecated this method does nothing + */ public void setEmbeddedRuntime(MavenRuntime embeddedRuntime) { - this.embeddedRuntime = embeddedRuntime; - runtimes.put(embeddedRuntime.getLocation(), embeddedRuntime); - } - - public void addWorkspaceRuntime(MavenRuntime workspaceRuntime) { - runtimes.put(workspaceRuntime.getLocation(), workspaceRuntime); } /** - * @deprecated use {@link addWorkspaceRuntime(runtime)} + * @deprecated this method does nothing */ @Deprecated public void setWorkspaceRuntime(MavenRuntime workspaceRuntime) { - addWorkspaceRuntime(workspaceRuntime); } public MavenRuntime getDefaultRuntime() { - if(defaultRuntime == null || !defaultRuntime.isAvailable()) { - return embeddedRuntime; + String selected = preferenceStore.get(MavenPreferenceConstants.P_DEFAULT_RUNTIME, null, preferencesLookup); + if(selected == null) { + return getEmbeddedRuntime(); } - return this.defaultRuntime; + MavenRuntime runtime = getRuntimeByName(selected); + return runtime != null ? runtime : getEmbeddedRuntime(); } + private MavenEmbeddedRuntime getEmbeddedRuntime() { + return new MavenEmbeddedRuntime(MavenPluginActivator.getDefault().getBundle()); + } + + /** + * @deprecated use {@link #getRuntimeByName(String)} + */ public MavenRuntime getRuntime(String location) { if(location == null || location.length() == 0 || DEFAULT.equals(location)) { return getDefaultRuntime(); } + for(MavenRuntime runtime : getRuntimes().values()) { + if(location.equals(runtime.getLocation())) { + return runtime; + } + } - return runtimes.get(location); + return null; + } + + /** + * @since 1.5 + */ + public MavenRuntime getRuntimeByName(String name) { + return getRuntimes().get(name); } public List getMavenRuntimes() { List mavenRuntimes = new ArrayList(); - for(MavenRuntime mavenRuntime : runtimes.values()) { + for(MavenRuntime mavenRuntime : getRuntimes().values()) { if(mavenRuntime.isAvailable()) { mavenRuntimes.add(mavenRuntime); } @@ -106,66 +121,142 @@ public class MavenRuntimeManager { public void reset() { preferencesLookup[0].remove(MavenPreferenceConstants.P_RUNTIMES); preferencesLookup[0].remove(MavenPreferenceConstants.P_DEFAULT_RUNTIME); - - initRuntimes(); + removeRuntimePreferences(); + flush(); } public void setDefaultRuntime(MavenRuntime runtime) { - this.defaultRuntime = runtime; - if(runtime == null) { preferencesLookup[0].remove(MavenPreferenceConstants.P_DEFAULT_RUNTIME); } else { - preferencesLookup[0].put(MavenPreferenceConstants.P_DEFAULT_RUNTIME, runtime.getLocation()); + preferencesLookup[0].put(MavenPreferenceConstants.P_DEFAULT_RUNTIME, runtime.getName()); } + flush(); } - public void setRuntimes(List runtimes) { - this.runtimes.clear(); + private void flush() { + try { + preferencesLookup[0].flush(); + } catch(BackingStoreException ex) { + // TODO do nothing + } + } - String separator = ""; //$NON-NLS-1$ - StringBuffer sb = new StringBuffer(); + public void setRuntimes(List runtimes) { + removeRuntimePreferences(); + StringBuilder sb = new StringBuilder(); for(MavenRuntime runtime : runtimes) { if(runtime.isEditable()) { - this.runtimes.put(runtime.getLocation(), runtime); - sb.append(separator).append(runtime.getLocation()); - separator = "|"; //$NON-NLS-1$ + AbstractMavenRuntime impl = (AbstractMavenRuntime) runtime; + if(sb.length() > 0) { + sb.append('|'); + } + sb.append(runtime.getName()); + if(!impl.isLegacy()) { + Preferences runtimeNode = getRuntimePreferences(runtime.getName(), true); + runtimeNode.put("location", runtime.getLocation()); + String extensions = encodeClasspath(impl.getExtensions()); + if(extensions != null) { + runtimeNode.put("extensions", extensions); + } else { + runtimeNode.remove("extensions"); + } + } } } preferencesLookup[0].put(MavenPreferenceConstants.P_RUNTIMES, sb.toString()); + flush(); } - private void initRuntimes() { + private void removeRuntimePreferences() { + try { + if(preferencesLookup[0].nodeExists(MavenPreferenceConstants.P_RUNTIMES_NODE)) { + preferencesLookup[0].node(MavenPreferenceConstants.P_RUNTIMES_NODE).removeNode(); + } + } catch(BackingStoreException ex) { + // assume the node does not exist + } + } - defaultRuntime = null; + private Preferences getRuntimePreferences(String name, boolean create) { + Preferences runtimesNode = preferencesLookup[0].node(MavenPreferenceConstants.P_RUNTIMES_NODE); + try { + if(runtimesNode.nodeExists(name) || create) { + return runtimesNode.node(name); + } + } catch(BackingStoreException ex) { + // assume the node does not exist + } + return null; + } - String selected = preferenceStore.get(MavenPreferenceConstants.P_DEFAULT_RUNTIME, null, preferencesLookup); + private String encodeClasspath(List classpath) { + if(classpath == null || classpath.isEmpty()) { + return null; + } + StringBuilder sb = new StringBuilder(); + for(ClasspathEntry cpe : classpath) { + if(sb.length() > 0) { + sb.append('|'); + } + sb.append(cpe.toExternalForm()); + } + return sb.toString(); + } + + private List decodeClasspath(String string) { + if(string == null || string.isEmpty()) { + return null; + } + List result = new ArrayList(); + for(String entry : string.split("\\|")) { + result.add(ClasspathEntry.fromExternalForm(entry)); + } + return result; + } + + private Map getRuntimes() { + Map runtimes = new LinkedHashMap(); + runtimes.put(EMBEDDED, getEmbeddedRuntime()); + runtimes.put(WORKSPACE, new MavenWorkspaceRuntime(MavenPluginActivator.getDefault().getMavenProjectManager())); String runtimesPreference = preferenceStore.get(MavenPreferenceConstants.P_RUNTIMES, null, preferencesLookup); if(runtimesPreference != null && runtimesPreference.length() > 0) { - String[] locations = runtimesPreference.split("\\|"); //$NON-NLS-1$ - for(int i = 0; i < locations.length; i++ ) { - MavenRuntime runtime = createExternalRuntime(locations[i]); - runtimes.put(runtime.getLocation(), runtime); - if(runtime.getLocation().equals(selected)) { - defaultRuntime = runtime; + for(String name : runtimesPreference.split("\\|")) { //$NON-NLS-1$ + Preferences preferences = getRuntimePreferences(name, false); + AbstractMavenRuntime runtime; + if(preferences == null) { + runtime = (AbstractMavenRuntime) createExternalRuntime(name); + } else { + runtime = createRuntime(name, preferences); } + runtimes.put(runtime.getName(), runtime); } } + + return runtimes; } + private AbstractMavenRuntime createRuntime(String name, Preferences preferences) { + String location = preferences.get("location", null); + List extensions = decodeClasspath(preferences.get("extensions", null)); + return new MavenExternalRuntime(name, location); + } + + /** + * @deprecated as of version 1.5, m2e does not provide public API to create MavenRuntime instances + */ public static MavenRuntime createExternalRuntime(String location) { return new MavenExternalRuntime(location); } + /** + * @deprecated global setting file is only used to determine localRepository location, which does not make much sense + */ public String getGlobalSettingsFile() { - //only return the preference store value for the global settings file if its an embedded runtime - if(defaultRuntime == null || defaultRuntime instanceof MavenEmbeddedRuntime) { - String globalSettings = preferenceStore.get(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, null, - preferencesLookup); - return globalSettings.trim().length() == 0 ? null : globalSettings; - } - return defaultRuntime == null ? null : defaultRuntime.getSettings(); + String globalSettings = preferenceStore.get(MavenPreferenceConstants.P_GLOBAL_SETTINGS_FILE, null, + preferencesLookup); + return globalSettings.trim().length() == 0 ? null : globalSettings; } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java index c89388ee..0f9a095a 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java @@ -62,10 +62,7 @@ import org.eclipse.m2e.core.embedder.MavenModelManager; import org.eclipse.m2e.core.embedder.MavenRuntimeManager; import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory; import org.eclipse.m2e.core.internal.archetype.ArchetypeManager; -import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime; import org.eclipse.m2e.core.internal.embedder.MavenImpl; -import org.eclipse.m2e.core.internal.embedder.MavenWorkspaceRuntime; -import org.eclipse.m2e.core.internal.embedder.TeslaWorkspaceRuntime; import org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager; import org.eclipse.m2e.core.internal.index.nexus.IndexesExtensionReader; import org.eclipse.m2e.core.internal.index.nexus.IndexingTransferListener; @@ -228,9 +225,6 @@ public class MavenPluginActivator extends Plugin { this.modelManager = new MavenModelManager(maven, projectManager); this.runtimeManager = new MavenRuntimeManager(); - this.runtimeManager.setEmbeddedRuntime(new MavenEmbeddedRuntime(bundleContext.getBundle())); - this.runtimeManager.addWorkspaceRuntime(new MavenWorkspaceRuntime(projectManager)); - this.runtimeManager.addWorkspaceRuntime(new TeslaWorkspaceRuntime(projectManager)); this.configurationManager = new ProjectConfigurationManager(maven, managerImpl, modelManager, mavenMarkerManager, mavenConfiguration); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java deleted file mode 100644 index 8d78b61f..00000000 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/AbstractWorkspaceRuntime.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.internal.embedder; - -import java.io.File; -import java.util.Set; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.versioning.DefaultArtifactVersion; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.project.MavenProject; - -import org.eclipse.m2e.core.embedder.ArtifactKey; -import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; -import org.eclipse.m2e.core.embedder.MavenRuntime; -import org.eclipse.m2e.core.embedder.MavenRuntimeManager; -import org.eclipse.m2e.core.project.IMavenProjectFacade; -import org.eclipse.m2e.core.project.IMavenProjectRegistry; - - -/** - * Maven 3.0-SNAPSHOT runtime loaded from the Eclipse Workspace - * - * @author Eugene Kuleshov - * @author Igor Fedorenko - * @author Jason van Zyl - */ -public abstract class AbstractWorkspaceRuntime implements MavenRuntime { - - private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey( - "org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private static final ArtifactKey PLEXUS_CLASSWORLDS = new ArtifactKey( - "org.codehaus.plexus", "plexus-classworlds", null, null); //$NON-NLS-1$ //$NON-NLS-2$ - - private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$ - - private static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$ - - private IMavenProjectRegistry projectManager; - - public AbstractWorkspaceRuntime(IMavenProjectRegistry projectManager) { - this.projectManager = projectManager; - } - - protected abstract ArtifactKey getDistributionArtifactKey(); - - protected abstract String getMainClass(); - - public String getLocation() { - return MavenRuntimeManager.WORKSPACE; - } - - public String getSettings() { - return null; - } - - public boolean isEditable() { - return false; - } - - public boolean isAvailable() { - return getMavenDistribution() != null; - } - - protected IMavenProjectFacade getMavenDistribution() { - try { - VersionRange range = VersionRange.createFromVersionSpec(getDistributionArtifactKey().getVersion()); - for(IMavenProjectFacade facade : projectManager.getProjects()) { - ArtifactKey artifactKey = facade.getArtifactKey(); - if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) // - && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())// - && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) { - return facade; - } - } - } catch(InvalidVersionSpecificationException e) { - // can't happen - } - return null; - } - - public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor) - throws CoreException { - IMavenProjectFacade maven = getMavenDistribution(); - if(maven != null) { - MavenProject mavenProject = maven.getMavenProject(monitor); - // - // main is org.apache.maven.cli.MavenCli from plexus.core - // - // set maven.home default ${user.home}/m2 - // - // [plexus.core] - // optionally ${maven.home}/lib/ext/*.jar - // load ${maven.home}/lib/*.jar - // load ${maven.home}/conf/logging - // - collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME); - collector.addRealm(PLEXUS_CLASSWORLD_NAME); - // - // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if - // we have a verion>3.1.x Maven-like runtime - // - for(IMavenProjectFacade facade : projectManager.getProjects()) { - ArtifactKey artifactKey = facade.getArtifactKey(); - if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) // - && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) { - File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(), "src/conf/logging"); - if(loggingConfigurationDirectory.exists()) { - collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath()); - } - } - } - Set artifacts = mavenProject.getArtifacts(); - Artifact launcherArtifact = null; - - for(Artifact artifact : artifacts) { - if(Artifact.SCOPE_TEST.equals(artifact.getScope())) { - continue; - } - - if(PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId()) - && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) { - launcherArtifact = artifact; - continue; - } - - addArtifact(collector, artifact); - } - - if(launcherArtifact != null) { - collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); - addArtifact(collector, launcherArtifact); - } - } - } - - public String toString() { - return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - protected void addArtifact(IMavenLauncherConfiguration collector, Artifact artifact) throws CoreException { - IMavenProjectFacade facade = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion()); - - if(facade != null) { - collector.addProjectEntry(facade); - } else { - File file = artifact.getFile(); - if(file != null) { - collector.addArchiveEntry(file.getAbsolutePath()); - } - } - } - - public String getVersion() { - IMavenProjectFacade maven = getMavenDistribution(); - if(maven != null) { - return maven.getArtifactKey().getVersion(); - } - return getDistributionArtifactKey().getVersion(); - } - -} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java deleted file mode 100644 index ae1a19ac..00000000 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenEmbeddedRuntime.java +++ /dev/null @@ -1,289 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.internal.embedder; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Properties; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; -import org.osgi.framework.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.osgi.util.ManifestElement; - -import org.codehaus.plexus.util.IOUtil; - -import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; -import org.eclipse.m2e.core.embedder.MavenRuntime; -import org.eclipse.m2e.core.embedder.MavenRuntimeManager; -import org.eclipse.m2e.core.internal.Bundles; -import org.eclipse.m2e.core.internal.Messages; -import org.eclipse.m2e.core.internal.e44.DevClassPathHelper; - - -/** - * Embedded Maven runtime - * - * @author Eugene Kuleshov - * @author Igor Fedorenko - */ -public class MavenEmbeddedRuntime implements MavenRuntime { - - private static final String MAVEN_CORE_POM_PROPERTIES = "META-INF/maven/org.apache.maven/maven-core/pom.properties"; //$NON-NLS-1$ - - private static final Logger log = LoggerFactory.getLogger(MavenEmbeddedRuntime.class); - - private static final String MAVEN_EMBEDDER_BUNDLE_SYMBOLICNAME = "org.eclipse.m2e.maven.runtime"; //$NON-NLS-1$ - - private static final String MAVEN_EXECUTOR_CLASS = org.apache.maven.cli.MavenCli.class.getName(); - - public static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$ - - private static String[] LAUNCHER_CLASSPATH; - - private static String[] CLASSPATH; - - private static volatile String mavenVersion; - - private Bundle m2eCore; - - public MavenEmbeddedRuntime(Bundle m2eCore) { - this.m2eCore = m2eCore; - } - - public boolean isEditable() { - return false; - } - - public String getLocation() { - return MavenRuntimeManager.EMBEDDED; - } - - public String getSettings() { - return null; - } - - public boolean isAvailable() { - return true; - } - - public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor) - throws CoreException { - collector.setMainType(MAVEN_EXECUTOR_CLASS, PLEXUS_CLASSWORLD_NAME); - - initClasspath(findMavenEmbedderBundle()); - - collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); - for(String entry : LAUNCHER_CLASSPATH) { - collector.addArchiveEntry(entry); - } - - collector.addRealm(PLEXUS_CLASSWORLD_NAME); - for(String entry : CLASSPATH) { - // https://issues.sonatype.org/browse/MNGECLIPSE-2507 - if(!entry.contains("plexus-build-api")) { - collector.addArchiveEntry(entry); - } - } - } - - private synchronized void initClasspath(Bundle mavenRuntimeBundle) { - if(CLASSPATH == null) { - LinkedHashSet allentries = new LinkedHashSet(); - - addBundleClasspathEntries(allentries, mavenRuntimeBundle); - - // find and add more bundles - for(String sname : new String[] {"org.slf4j.api", "org.eclipse.m2e.maven.runtime.slf4j.simple"}) { - Bundle dependency = Bundles.findDependencyBundle(mavenRuntimeBundle, sname); - if(dependency != null) { - addBundleClasspathEntries(allentries, dependency); - } else { - log.warn( - "Could not find OSGi bundle with symbolic name ''{}'' required to launch embedded maven runtime in external process", - sname); - } - } - - List cp = new ArrayList(); - List lcp = new ArrayList(); - - for(String entry : allentries) { - if(entry.contains("plexus-classworlds")) { //$NON-NLS-1$ - lcp.add(entry); - } else { - cp.add(entry); - } - } - - CLASSPATH = cp.toArray(new String[cp.size()]); - LAUNCHER_CLASSPATH = lcp.toArray(new String[lcp.size()]); - } - } - - private void addBundleClasspathEntries(Set entries, Bundle bundle) { - log.debug("addBundleClasspathEntries(Bundle={})", bundle.toString()); - - Set cp = new LinkedHashSet(); - if(DevClassPathHelper.inDevelopmentMode()) { - cp.addAll(Arrays.asList(DevClassPathHelper.getDevClassPath(bundle.getSymbolicName()))); - } - cp.addAll(Arrays.asList(parseBundleClasspath(bundle))); - for(String cpe : cp) { - String entry; - if(".".equals(cpe)) { - entry = getNestedJarOrDir(bundle, "/"); - } else { - entry = getNestedJarOrDir(bundle, cpe); - } - - if(entry != null) { - log.debug("\tEntry:{}", entry); - entries.add(entry); - } - } - } - - private String[] parseBundleClasspath(Bundle bundle) { - String[] result = new String[] {"."}; - String header = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); - ManifestElement[] classpathEntries = null; - try { - classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header); - } catch(BundleException ex) { - log.warn("Could not parse bundle classpath of {}", bundle.toString(), ex); - } - if(classpathEntries != null) { - result = new String[classpathEntries.length]; - for(int i = 0; i < classpathEntries.length; i++ ) { - result[i] = classpathEntries[i].getValue(); - } - } - return result; - } - - private String getNestedJarOrDir(Bundle bundle, String cp) { - // try embeded entries first - URL url = bundle.getEntry(cp); - if(url != null) { - try { - return FileLocator.toFileURL(url).getFile(); - } catch(IOException ex) { - log.warn("Could not get entry {} for bundle {}", new Object[] {cp, bundle.toString(), ex}); - } - } - - // in development mode entries can be absolute paths outside of bundle basedir - if(DevClassPathHelper.inDevelopmentMode()) { - File file = new File(cp); - if(file.exists() && file.isAbsolute()) { - return file.getAbsolutePath(); - } - } - - log.debug("Bundle {} does not have entry {}", bundle.toString(), cp); - return null; - } - - private Bundle findMavenEmbedderBundle() { - return Bundles.findDependencyBundle(m2eCore, MAVEN_EMBEDDER_BUNDLE_SYMBOLICNAME); - } - - public String toString() { - Bundle embedder = findMavenEmbedderBundle(); - - StringBuilder sb = new StringBuilder(); - sb.append("Embedded (").append(getVersion()); //$NON-NLS-1$ - if(embedder != null) { - String version = (String) embedder.getHeaders().get(Constants.BUNDLE_VERSION); - sb.append('/').append(version); - } - sb.append(')'); - - return sb.toString(); - } - - private synchronized String getVersion(Bundle bundle) { - if(mavenVersion != null) { - return mavenVersion; - } - initClasspath(bundle); - try { - String mavenCoreJarPath = null; - for(String path : CLASSPATH) { - if(path.contains("maven-core")) { - mavenCoreJarPath = path; - break; - } - } - - if(mavenCoreJarPath == null) { - throw new RuntimeException("Could not find maven core jar file"); - } - - Properties pomProperties = new Properties(); - - File mavenCoreJar = new File(mavenCoreJarPath); - if(mavenCoreJar.isFile()) { - ZipFile zip = new ZipFile(mavenCoreJarPath); - try { - ZipEntry zipEntry = zip.getEntry(MAVEN_CORE_POM_PROPERTIES); - if(zipEntry != null) { - pomProperties.load(zip.getInputStream(zipEntry)); - } - } finally { - zip.close(); - } - } else if(mavenCoreJar.isDirectory()) { - InputStream is = new BufferedInputStream(new FileInputStream(new File(mavenCoreJar, MAVEN_CORE_POM_PROPERTIES))); - try { - pomProperties.load(is); - } finally { - IOUtil.close(is); - } - } - - String version = pomProperties.getProperty("version"); //$NON-NLS-1$ - if(version != null) { - mavenVersion = version; - return mavenVersion; - } - - } catch(Exception e) { - log.warn("Could not determine embedded maven version", e); - } - - return Messages.MavenEmbeddedRuntime_unknown; - } - - public String getVersion() { - Bundle bundle = findMavenEmbedderBundle(); - return getVersion(bundle); - } -} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java deleted file mode 100644 index 0c1baf34..00000000 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExternalRuntime.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.internal.embedder; - -import java.io.File; -import java.io.FileInputStream; -import java.net.URL; -import java.util.Properties; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; - -import org.codehaus.plexus.classworlds.launcher.ConfigurationHandler; -import org.codehaus.plexus.classworlds.launcher.ConfigurationParser; -import org.codehaus.plexus.util.DirectoryScanner; - -import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; -import org.eclipse.m2e.core.embedder.MavenRuntime; -import org.eclipse.m2e.core.internal.IMavenConstants; -import org.eclipse.m2e.core.internal.Messages; - - -/** - * Maven external runtime using ClassWorlds launcher - * - * @author Eugene Kuleshov - * @author Igor Fedorenko - */ -public class MavenExternalRuntime implements MavenRuntime { - private static final Logger log = LoggerFactory.getLogger(MavenExternalRuntime.class); - - private static final String PROPERTY_MAVEN_HOME = "maven.home"; //$NON-NLS-1$ - - private final String location; - - public MavenExternalRuntime(String location) { - this.location = location; - } - - public boolean isEditable() { - return true; - } - - public boolean isAvailable() { - return new File(location, "bin").exists() && getLauncherClasspath() != null; //$NON-NLS-1$ - } - - public String getLocation() { - return location; - } - - public String getSettings() { - return location + File.separator + "conf" + File.separator + "settings.xml"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - public String getMainTypeName() { - return "org.codehaus.classworlds.Launcher"; //$NON-NLS-1$ - } - - private File getLauncherConfigurationFile() { - File m2Conf = new File(location, "bin/m2.conf"); - // Look for Tesla location - if(m2Conf.exists() == false) { - m2Conf = new File(location, "conf/m2.conf"); - } - return m2Conf; //$NON-NLS-1$ - } - - public void createLauncherConfiguration(final IMavenLauncherConfiguration collector, IProgressMonitor monitor) - throws CoreException { - - collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); - collector.addArchiveEntry(getLauncherClasspath()); - - ConfigurationHandler handler = new ConfigurationHandler() { - public void addImportFrom(String relamName, String importSpec) { - throw new UnsupportedOperationException(Messages.MavenExternalRuntime_exc_unsupported); - } - - public void addLoadFile(File file) { - try { - collector.addArchiveEntry(file.getAbsolutePath()); - } catch(CoreException ex) { - throw new ExceptionWrapper(ex); - } - } - - public void addLoadURL(URL url) { - try { - collector.addArchiveEntry(url.toExternalForm()); - } catch(CoreException ex) { - throw new ExceptionWrapper(ex); - } - } - - public void addRealm(String realmName) { - collector.addRealm(realmName); - } - - public void setAppMain(String mainClassName, String mainRealmName) { - collector.setMainType(mainClassName, mainRealmName); - } - }; - - Properties properties = new Properties(); - properties.putAll(System.getProperties()); - properties.put(PROPERTY_MAVEN_HOME, location); - - ConfigurationParser parser = new ConfigurationParser(handler, properties); - - try { - FileInputStream is = new FileInputStream(getLauncherConfigurationFile()); - try { - parser.parse(is); - } finally { - is.close(); - } - } catch(Exception e) { - if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) { - throw (CoreException) e.getCause(); - } - throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, - Messages.MavenExternalRuntime_error_cannot_parse, e)); - } - - // XXX show error dialog and fail launch - } - - public boolean equals(Object o) { - if(o instanceof MavenExternalRuntime) { - return location.equals(((MavenExternalRuntime) o).location); - } - return false; - } - - public int hashCode() { - return location.hashCode(); - } - - public String toString() { - return "External" + " " + location + " (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - - private static class ExceptionWrapper extends RuntimeException { - private static final long serialVersionUID = 8815818826909815028L; - - public ExceptionWrapper(Exception cause) { - super(cause); - } - } - - private String getLauncherClasspath() { - File mavenHome = new File(location); - DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir(mavenHome); - ds.setIncludes(new String[] {"core/boot/classworlds*.jar", // 2.0.4 //$NON-NLS-1$ - "boot/classworlds*.jar", // 2.0.7 //$NON-NLS-1$ - "boot/plexus-classworlds*.jar", // 2.1 as of 2008-03-27 //$NON-NLS-1$ - }); - ds.scan(); - String[] includedFiles = ds.getIncludedFiles(); - - if(includedFiles.length == 1) { - return new File(mavenHome, includedFiles[0]).getAbsolutePath(); - } - - return null; - } - - public String getVersion() { - - class VersionHandler implements ConfigurationHandler { - File mavenCore; - - File uber; - - public void addImportFrom(String relamName, String importSpec) { - } - - public void addLoadFile(File file) { - if(file.getName().contains("maven-core")) { //$NON-NLS-1$ - mavenCore = file; - } else if(file.getName().endsWith("uber.jar")) { //$NON-NLS-1$ - uber = file; - } - } - - public void addLoadURL(URL url) { - } - - public void addRealm(String realmName) { - } - - public void setAppMain(String mainClassName, String mainRealmName) { - } - } - - VersionHandler handler = new VersionHandler(); - - Properties properties = new Properties(); - properties.putAll(System.getProperties()); - properties.put(PROPERTY_MAVEN_HOME, location); - - ConfigurationParser parser = new ConfigurationParser(handler, properties); - - try { - FileInputStream is = new FileInputStream(getLauncherConfigurationFile()); - try { - parser.parse(is); - } finally { - is.close(); - } - - ZipFile zip = null; - if(handler.mavenCore != null) { - zip = new ZipFile(handler.mavenCore); - } else if(handler.uber != null) { - zip = new ZipFile(handler.uber); - } - if(zip != null) { - try { - String suffix = ""; - ZipEntry zipEntry = zip.getEntry("META-INF/maven/org.apache.maven/maven-core/pom.properties"); //$NON-NLS-1$ - if(zipEntry == null) { - suffix = "-tesla"; - zipEntry = zip.getEntry("META-INF/maven/io.tesla.maven/maven-core/pom.properties"); //$NON-NLS-1$ - } - if(zipEntry != null) { - Properties pomProperties = new Properties(); - pomProperties.load(zip.getInputStream(zipEntry)); - - String version = pomProperties.getProperty("version"); //$NON-NLS-1$ - if(version != null) { - return version + suffix; - } - } - } finally { - zip.close(); - } - } - } catch(Exception e) { - // most likely a bad location, but who knows - log.error("Could not parse classwords configuration file", e); - } - - return Messages.MavenExternalRuntime_unknown; - } -} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java deleted file mode 100644 index 5c92c2ad..00000000 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenWorkspaceRuntime.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ - -package org.eclipse.m2e.core.internal.embedder; - -import org.eclipse.m2e.core.embedder.ArtifactKey; -import org.eclipse.m2e.core.embedder.MavenRuntimeManager; -import org.eclipse.m2e.core.project.IMavenProjectRegistry; - - -/** - * Maven 3.0-SNAPSHOT runtime loaded from the Eclipse Workspace - * - * @author Eugene Kuleshov - * @author Igor Fedorenko - */ -public class MavenWorkspaceRuntime extends AbstractWorkspaceRuntime { - - private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey( - "org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$ - - public MavenWorkspaceRuntime(IMavenProjectRegistry projectManager) { - super(projectManager); - } - - protected ArtifactKey getDistributionArtifactKey() { - return MAVEN_DISTRIBUTION; - } - - protected String getMainClass() { - return MAVEN_EXECUTOR_CLASS; - } - - public String getLocation() { - return MavenRuntimeManager.WORKSPACE; - } - - public String toString() { - return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } - -} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java deleted file mode 100644 index 9ebf0561..00000000 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/TeslaWorkspaceRuntime.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2013 Sonatype, Inc., Jason van Zyl - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - * Jason van Zyl - extension to account for Tesla - *******************************************************************************/ - -package org.eclipse.m2e.core.internal.embedder; - -import org.eclipse.m2e.core.embedder.ArtifactKey; -import org.eclipse.m2e.core.project.IMavenProjectRegistry; - - -/** - * Tesla runtime loaded from the Eclipse Workspace - * - * @author Eugene Kuleshov - * @author Igor Fedorenko - * @author Jason van Zyl - */ -public class TeslaWorkspaceRuntime extends AbstractWorkspaceRuntime { - - private static final ArtifactKey TESLA_DISTRIBUTION = new ArtifactKey( - "io.tesla.maven", "apache-maven", "[3.1,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$ - - public TeslaWorkspaceRuntime(IMavenProjectRegistry projectManager) { - super(projectManager); - } - - protected ArtifactKey getDistributionArtifactKey() { - return TESLA_DISTRIBUTION; - } - - protected String getMainClass() { - return MAVEN_EXECUTOR_CLASS; - } - - public String getLocation() { - return "TESLA_WORKSPACE"; - } - - public String toString() { - return "Tesla Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - } -} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java new file mode 100644 index 00000000..f32de7ed --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +import java.util.List; + +import org.eclipse.m2e.core.embedder.MavenRuntime; + + +/** + * @since 1.5 + */ +public abstract class AbstractMavenRuntime implements MavenRuntime { + + private final String name; + + @Deprecated + protected AbstractMavenRuntime() { + this.name = null; + } + + protected AbstractMavenRuntime(String name) { + this.name = name; + } + + @Override + public String getName() { + return name != null ? name : getLocation(); + } + + public List getExtensions() { + return null; + } + + public boolean isLegacy() { + return name == null; + } +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java new file mode 100644 index 00000000..61986968 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractWorkspaceRuntime.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +import java.io.File; +import java.util.Set; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.project.MavenProject; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; +import org.eclipse.m2e.core.embedder.MavenRuntimeManager; +import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; + + +/** + * Maven 3.x runtime loaded from the Eclipse Workspace + * + * @author Eugene Kuleshov + * @author Igor Fedorenko + * @author Jason van Zyl + */ +public abstract class AbstractWorkspaceRuntime extends AbstractMavenRuntime { + + private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey( + "org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private static final ArtifactKey PLEXUS_CLASSWORLDS = new ArtifactKey( + "org.codehaus.plexus", "plexus-classworlds", null, null); //$NON-NLS-1$ //$NON-NLS-2$ + + private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$ + + private static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$ + + private IMavenProjectRegistry projectManager; + + public AbstractWorkspaceRuntime(IMavenProjectRegistry projectManager) { + this.projectManager = projectManager; + } + + protected abstract ArtifactKey getDistributionArtifactKey(); + + protected abstract String getMainClass(); + + public String getLocation() { + return MavenRuntimeManager.WORKSPACE; + } + + public String getSettings() { + return null; + } + + public boolean isEditable() { + return false; + } + + public boolean isAvailable() { + return getMavenDistribution() != null; + } + + protected IMavenProjectFacade getMavenDistribution() { + try { + VersionRange range = VersionRange.createFromVersionSpec(getDistributionArtifactKey().getVersion()); + for(IMavenProjectFacade facade : projectManager.getProjects()) { + ArtifactKey artifactKey = facade.getArtifactKey(); + if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) // + && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())// + && range.containsVersion(new DefaultArtifactVersion(artifactKey.getVersion()))) { + return facade; + } + } + } catch(InvalidVersionSpecificationException e) { + // can't happen + } + return null; + } + + public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor) + throws CoreException { + IMavenProjectFacade maven = getMavenDistribution(); + if(maven != null) { + MavenProject mavenProject = maven.getMavenProject(monitor); + // + // main is org.apache.maven.cli.MavenCli from plexus.core + // + // set maven.home default ${user.home}/m2 + // + // [plexus.core] + // optionally ${maven.home}/lib/ext/*.jar + // load ${maven.home}/lib/*.jar + // load ${maven.home}/conf/logging + // + collector.setMainType(getMainClass(), PLEXUS_CLASSWORLD_NAME); + collector.addRealm(PLEXUS_CLASSWORLD_NAME); + // + // plexus.core is the current realm, and now we want the add the SLF4J loggging configuration if + // we have a verion>3.1.x Maven-like runtime + // + for(IMavenProjectFacade facade : projectManager.getProjects()) { + ArtifactKey artifactKey = facade.getArtifactKey(); + if(getDistributionArtifactKey().getGroupId().equals(artifactKey.getGroupId()) // + && getDistributionArtifactKey().getArtifactId().equals(artifactKey.getArtifactId())) { + File loggingConfigurationDirectory = new File(facade.getPomFile().getParentFile(), "src/conf/logging"); + if(loggingConfigurationDirectory.exists()) { + collector.addArchiveEntry(loggingConfigurationDirectory.getAbsolutePath()); + } + } + } + Set artifacts = mavenProject.getArtifacts(); + Artifact launcherArtifact = null; + + for(Artifact artifact : artifacts) { + if(Artifact.SCOPE_TEST.equals(artifact.getScope())) { + continue; + } + + if(PLEXUS_CLASSWORLDS.getGroupId().equals(artifact.getGroupId()) + && PLEXUS_CLASSWORLDS.getArtifactId().equals(artifact.getArtifactId())) { + launcherArtifact = artifact; + continue; + } + + addArtifact(collector, artifact); + } + + if(launcherArtifact != null) { + collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); + addArtifact(collector, launcherArtifact); + } + } + } + + public String toString() { + return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + protected void addArtifact(IMavenLauncherConfiguration collector, Artifact artifact) throws CoreException { + IMavenProjectFacade facade = projectManager.getMavenProject(artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion()); + + if(facade != null) { + collector.addProjectEntry(facade); + } else { + File file = artifact.getFile(); + if(file != null) { + collector.addArchiveEntry(file.getAbsolutePath()); + } + } + } + + public String getVersion() { + IMavenProjectFacade maven = getMavenDistribution(); + if(maven != null) { + return maven.getArtifactKey().getVersion(); + } + return getDistributionArtifactKey().getVersion(); + } + +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java new file mode 100644 index 00000000..6572cca4 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2014 Takari, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Takari, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +/** + * @since 1.5 + */ +public abstract class ClasspathEntry { + public abstract String toExternalForm(); + + public static ClasspathEntry fromExternalForm(String str) { + return null; + } +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java new file mode 100644 index 00000000..afb2e2e6 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenEmbeddedRuntime.java @@ -0,0 +1,289 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.osgi.util.ManifestElement; + +import org.codehaus.plexus.util.IOUtil; + +import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; +import org.eclipse.m2e.core.embedder.MavenRuntimeManager; +import org.eclipse.m2e.core.internal.Bundles; +import org.eclipse.m2e.core.internal.Messages; +import org.eclipse.m2e.core.internal.e44.DevClassPathHelper; + + +/** + * Embedded Maven runtime + * + * @author Eugene Kuleshov + * @author Igor Fedorenko + */ +public class MavenEmbeddedRuntime extends AbstractMavenRuntime { + + private static final String MAVEN_CORE_POM_PROPERTIES = "META-INF/maven/org.apache.maven/maven-core/pom.properties"; //$NON-NLS-1$ + + private static final Logger log = LoggerFactory.getLogger(MavenEmbeddedRuntime.class); + + private static final String MAVEN_EMBEDDER_BUNDLE_SYMBOLICNAME = "org.eclipse.m2e.maven.runtime"; //$NON-NLS-1$ + + private static final String MAVEN_EXECUTOR_CLASS = org.apache.maven.cli.MavenCli.class.getName(); + + public static final String PLEXUS_CLASSWORLD_NAME = "plexus.core"; //$NON-NLS-1$ + + private static String[] LAUNCHER_CLASSPATH; + + private static String[] CLASSPATH; + + private static volatile String mavenVersion; + + private Bundle m2eCore; + + public MavenEmbeddedRuntime(Bundle m2eCore) { + super(MavenRuntimeManager.EMBEDDED); + this.m2eCore = m2eCore; + } + + public boolean isEditable() { + return false; + } + + public String getLocation() { + return MavenRuntimeManager.EMBEDDED; + } + + public String getSettings() { + return null; + } + + public boolean isAvailable() { + return true; + } + + public void createLauncherConfiguration(IMavenLauncherConfiguration collector, IProgressMonitor monitor) + throws CoreException { + collector.setMainType(MAVEN_EXECUTOR_CLASS, PLEXUS_CLASSWORLD_NAME); + + initClasspath(findMavenEmbedderBundle()); + + collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); + for(String entry : LAUNCHER_CLASSPATH) { + collector.addArchiveEntry(entry); + } + + collector.addRealm(PLEXUS_CLASSWORLD_NAME); + for(String entry : CLASSPATH) { + // https://issues.sonatype.org/browse/MNGECLIPSE-2507 + if(!entry.contains("plexus-build-api")) { + collector.addArchiveEntry(entry); + } + } + } + + private synchronized void initClasspath(Bundle mavenRuntimeBundle) { + if(CLASSPATH == null) { + LinkedHashSet allentries = new LinkedHashSet(); + + addBundleClasspathEntries(allentries, mavenRuntimeBundle); + + // find and add more bundles + for(String sname : new String[] {"org.slf4j.api", "org.eclipse.m2e.maven.runtime.slf4j.simple"}) { + Bundle dependency = Bundles.findDependencyBundle(mavenRuntimeBundle, sname); + if(dependency != null) { + addBundleClasspathEntries(allentries, dependency); + } else { + log.warn( + "Could not find OSGi bundle with symbolic name ''{}'' required to launch embedded maven runtime in external process", + sname); + } + } + + List cp = new ArrayList(); + List lcp = new ArrayList(); + + for(String entry : allentries) { + if(entry.contains("plexus-classworlds")) { //$NON-NLS-1$ + lcp.add(entry); + } else { + cp.add(entry); + } + } + + CLASSPATH = cp.toArray(new String[cp.size()]); + LAUNCHER_CLASSPATH = lcp.toArray(new String[lcp.size()]); + } + } + + private void addBundleClasspathEntries(Set entries, Bundle bundle) { + log.debug("addBundleClasspathEntries(Bundle={})", bundle.toString()); + + Set cp = new LinkedHashSet(); + if(DevClassPathHelper.inDevelopmentMode()) { + cp.addAll(Arrays.asList(DevClassPathHelper.getDevClassPath(bundle.getSymbolicName()))); + } + cp.addAll(Arrays.asList(parseBundleClasspath(bundle))); + for(String cpe : cp) { + String entry; + if(".".equals(cpe)) { + entry = getNestedJarOrDir(bundle, "/"); + } else { + entry = getNestedJarOrDir(bundle, cpe); + } + + if(entry != null) { + log.debug("\tEntry:{}", entry); + entries.add(entry); + } + } + } + + private String[] parseBundleClasspath(Bundle bundle) { + String[] result = new String[] {"."}; + String header = bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); + ManifestElement[] classpathEntries = null; + try { + classpathEntries = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, header); + } catch(BundleException ex) { + log.warn("Could not parse bundle classpath of {}", bundle.toString(), ex); + } + if(classpathEntries != null) { + result = new String[classpathEntries.length]; + for(int i = 0; i < classpathEntries.length; i++ ) { + result[i] = classpathEntries[i].getValue(); + } + } + return result; + } + + private String getNestedJarOrDir(Bundle bundle, String cp) { + // try embeded entries first + URL url = bundle.getEntry(cp); + if(url != null) { + try { + return FileLocator.toFileURL(url).getFile(); + } catch(IOException ex) { + log.warn("Could not get entry {} for bundle {}", new Object[] {cp, bundle.toString(), ex}); + } + } + + // in development mode entries can be absolute paths outside of bundle basedir + if(DevClassPathHelper.inDevelopmentMode()) { + File file = new File(cp); + if(file.exists() && file.isAbsolute()) { + return file.getAbsolutePath(); + } + } + + log.debug("Bundle {} does not have entry {}", bundle.toString(), cp); + return null; + } + + private Bundle findMavenEmbedderBundle() { + return Bundles.findDependencyBundle(m2eCore, MAVEN_EMBEDDER_BUNDLE_SYMBOLICNAME); + } + + public String toString() { + Bundle embedder = findMavenEmbedderBundle(); + + StringBuilder sb = new StringBuilder(); + sb.append("Embedded (").append(getVersion()); //$NON-NLS-1$ + if(embedder != null) { + String version = (String) embedder.getHeaders().get(Constants.BUNDLE_VERSION); + sb.append('/').append(version); + } + sb.append(')'); + + return sb.toString(); + } + + private synchronized String getVersion(Bundle bundle) { + if(mavenVersion != null) { + return mavenVersion; + } + initClasspath(bundle); + try { + String mavenCoreJarPath = null; + for(String path : CLASSPATH) { + if(path.contains("maven-core")) { + mavenCoreJarPath = path; + break; + } + } + + if(mavenCoreJarPath == null) { + throw new RuntimeException("Could not find maven core jar file"); + } + + Properties pomProperties = new Properties(); + + File mavenCoreJar = new File(mavenCoreJarPath); + if(mavenCoreJar.isFile()) { + ZipFile zip = new ZipFile(mavenCoreJarPath); + try { + ZipEntry zipEntry = zip.getEntry(MAVEN_CORE_POM_PROPERTIES); + if(zipEntry != null) { + pomProperties.load(zip.getInputStream(zipEntry)); + } + } finally { + zip.close(); + } + } else if(mavenCoreJar.isDirectory()) { + InputStream is = new BufferedInputStream(new FileInputStream(new File(mavenCoreJar, MAVEN_CORE_POM_PROPERTIES))); + try { + pomProperties.load(is); + } finally { + IOUtil.close(is); + } + } + + String version = pomProperties.getProperty("version"); //$NON-NLS-1$ + if(version != null) { + mavenVersion = version; + return mavenVersion; + } + + } catch(Exception e) { + log.warn("Could not determine embedded maven version", e); + } + + return Messages.MavenEmbeddedRuntime_unknown; + } + + public String getVersion() { + Bundle bundle = findMavenEmbedderBundle(); + return getVersion(bundle); + } +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java new file mode 100644 index 00000000..47420626 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java @@ -0,0 +1,259 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +import java.io.File; +import java.io.FileInputStream; +import java.net.URL; +import java.util.Properties; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; + +import org.codehaus.plexus.classworlds.launcher.ConfigurationHandler; +import org.codehaus.plexus.classworlds.launcher.ConfigurationParser; +import org.codehaus.plexus.util.DirectoryScanner; + +import org.eclipse.m2e.core.embedder.IMavenLauncherConfiguration; +import org.eclipse.m2e.core.internal.IMavenConstants; +import org.eclipse.m2e.core.internal.Messages; + + +/** + * Maven external runtime using ClassWorlds launcher + * + * @author Eugene Kuleshov + * @author Igor Fedorenko + */ +public class MavenExternalRuntime extends AbstractMavenRuntime { + private static final Logger log = LoggerFactory.getLogger(MavenExternalRuntime.class); + + private static final String PROPERTY_MAVEN_HOME = "maven.home"; //$NON-NLS-1$ + + private final String location; + + public MavenExternalRuntime(String location) { + this.location = location; + } + + public MavenExternalRuntime(String name, String location) { + super(name); + this.location = location; + } + + public boolean isEditable() { + return true; + } + + public boolean isAvailable() { + return new File(location, "bin").exists() && getLauncherClasspath() != null; //$NON-NLS-1$ + } + + public String getLocation() { + return location; + } + + public String getSettings() { + return location + File.separator + "conf" + File.separator + "settings.xml"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + public String getMainTypeName() { + return "org.codehaus.classworlds.Launcher"; //$NON-NLS-1$ + } + + private File getLauncherConfigurationFile() { + return new File(location, "bin/m2.conf"); //$NON-NLS-1$ + } + + public void createLauncherConfiguration(final IMavenLauncherConfiguration collector, IProgressMonitor monitor) + throws CoreException { + + collector.addRealm(IMavenLauncherConfiguration.LAUNCHER_REALM); + collector.addArchiveEntry(getLauncherClasspath()); + + ConfigurationHandler handler = new ConfigurationHandler() { + public void addImportFrom(String relamName, String importSpec) { + throw new UnsupportedOperationException(Messages.MavenExternalRuntime_exc_unsupported); + } + + public void addLoadFile(File file) { + try { + collector.addArchiveEntry(file.getAbsolutePath()); + } catch(CoreException ex) { + throw new ExceptionWrapper(ex); + } + } + + public void addLoadURL(URL url) { + try { + collector.addArchiveEntry(url.toExternalForm()); + } catch(CoreException ex) { + throw new ExceptionWrapper(ex); + } + } + + public void addRealm(String realmName) { + collector.addRealm(realmName); + } + + public void setAppMain(String mainClassName, String mainRealmName) { + collector.setMainType(mainClassName, mainRealmName); + } + }; + + Properties properties = new Properties(); + properties.putAll(System.getProperties()); + properties.put(PROPERTY_MAVEN_HOME, location); + + ConfigurationParser parser = new ConfigurationParser(handler, properties); + + try { + FileInputStream is = new FileInputStream(getLauncherConfigurationFile()); + try { + parser.parse(is); + } finally { + is.close(); + } + } catch(Exception e) { + if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) { + throw (CoreException) e.getCause(); + } + throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, + Messages.MavenExternalRuntime_error_cannot_parse, e)); + } + + // XXX show error dialog and fail launch + } + + public boolean equals(Object o) { + if(o instanceof MavenExternalRuntime) { + return getName().equals(((MavenExternalRuntime) o).getName()); + } + return false; + } + + public int hashCode() { + return getName().hashCode(); + } + + public String toString() { + return "External" + " " + location + " (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + } + + private static class ExceptionWrapper extends RuntimeException { + private static final long serialVersionUID = 8815818826909815028L; + + public ExceptionWrapper(Exception cause) { + super(cause); + } + } + + private String getLauncherClasspath() { + File mavenHome = new File(location); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(mavenHome); + ds.setIncludes(new String[] {"core/boot/classworlds*.jar", // 2.0.4 //$NON-NLS-1$ + "boot/classworlds*.jar", // 2.0.7 //$NON-NLS-1$ + "boot/plexus-classworlds*.jar", // 2.1 as of 2008-03-27 //$NON-NLS-1$ + }); + ds.scan(); + String[] includedFiles = ds.getIncludedFiles(); + + if(includedFiles.length == 1) { + return new File(mavenHome, includedFiles[0]).getAbsolutePath(); + } + + return null; + } + + public String getVersion() { + + class VersionHandler implements ConfigurationHandler { + File mavenCore; + + File uber; + + public void addImportFrom(String relamName, String importSpec) { + } + + public void addLoadFile(File file) { + if(file.getName().contains("maven-core")) { //$NON-NLS-1$ + mavenCore = file; + } else if(file.getName().endsWith("uber.jar")) { //$NON-NLS-1$ + uber = file; + } + } + + public void addLoadURL(URL url) { + } + + public void addRealm(String realmName) { + } + + public void setAppMain(String mainClassName, String mainRealmName) { + } + } + + VersionHandler handler = new VersionHandler(); + + Properties properties = new Properties(); + properties.putAll(System.getProperties()); + properties.put(PROPERTY_MAVEN_HOME, location); + + ConfigurationParser parser = new ConfigurationParser(handler, properties); + + try { + FileInputStream is = new FileInputStream(getLauncherConfigurationFile()); + try { + parser.parse(is); + } finally { + is.close(); + } + + ZipFile zip = null; + if(handler.mavenCore != null) { + zip = new ZipFile(handler.mavenCore); + } else if(handler.uber != null) { + zip = new ZipFile(handler.uber); + } + if(zip != null) { + try { + String suffix = ""; + ZipEntry zipEntry = zip.getEntry("META-INF/maven/org.apache.maven/maven-core/pom.properties"); //$NON-NLS-1$ + if(zipEntry != null) { + Properties pomProperties = new Properties(); + pomProperties.load(zip.getInputStream(zipEntry)); + + String version = pomProperties.getProperty("version"); //$NON-NLS-1$ + if(version != null) { + return version + suffix; + } + } + } finally { + zip.close(); + } + } + } catch(Exception e) { + // most likely a bad location, but who knows + log.error("Could not parse classwords configuration file", e); + } + + return Messages.MavenExternalRuntime_unknown; + } +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java new file mode 100644 index 00000000..346f0c13 --- /dev/null +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenWorkspaceRuntime.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008-2010 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ + +package org.eclipse.m2e.core.internal.launch; + +import org.eclipse.m2e.core.embedder.ArtifactKey; +import org.eclipse.m2e.core.embedder.MavenRuntimeManager; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; + + +/** + * Maven 3.0-SNAPSHOT runtime loaded from the Eclipse Workspace + * + * @author Eugene Kuleshov + * @author Igor Fedorenko + */ +public class MavenWorkspaceRuntime extends AbstractWorkspaceRuntime { + + private static final ArtifactKey MAVEN_DISTRIBUTION = new ArtifactKey( + "org.apache.maven", "apache-maven", "[3.0,)", null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private static final String MAVEN_EXECUTOR_CLASS = "org.apache.maven.cli.MavenCli"; //$NON-NLS-1$ + + public MavenWorkspaceRuntime(IMavenProjectRegistry projectManager) { + super(projectManager); + } + + protected ArtifactKey getDistributionArtifactKey() { + return MAVEN_DISTRIBUTION; + } + + protected String getMainClass() { + return MAVEN_EXECUTOR_CLASS; + } + + public String getLocation() { + return MavenRuntimeManager.WORKSPACE; + } + + public String toString() { + return "Maven Workspace (" + getVersion() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + } + +} diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java index b6b0b885..8a94dfdc 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenPreferenceConstants.java @@ -12,6 +12,9 @@ package org.eclipse.m2e.core.internal.preferences; +import org.eclipse.m2e.core.embedder.MavenRuntimeManager; + + /** * Maven preferences constants */ @@ -61,9 +64,12 @@ public interface MavenPreferenceConstants { /** boolean */ public static final String P_DISABLE_JDK_CHECK = PREFIX + "disableJdkCheck"; //$NON-NLS-1$ - /** String */ + /** String, list of configured maven installations separated by '|', see {@link MavenRuntimeManager} */ public static final String P_RUNTIMES = PREFIX + "runtimes"; //$NON-NLS-1$ + /** Root node of extended maven installation attributes, see {@link MavenRuntimeManager} */ + public static final String P_RUNTIMES_NODE = PREFIX + "runtimesNodes"; //$NON-NLS-1$ + /** String */ public static final String P_DEFAULT_RUNTIME = PREFIX + "defaultRuntime"; //$NON-NLS-1$ -- cgit v1.2.3