Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-02-23 13:02:19 -0500
committerIgor Fedorenko2011-02-23 13:11:51 -0500
commit4a3ba6acf496dda6d16b53a69b72de35a6c62a95 (patch)
treee91df5a09ade413957a010d34c2513c4cf3c7d01 /org.eclipse.m2e.discovery/src
parent02e8c75779abfc23c664f77d8e3e600ced9d5ba9 (diff)
downloadm2e-core-4a3ba6acf496dda6d16b53a69b72de35a6c62a95.tar.gz
m2e-core-4a3ba6acf496dda6d16b53a69b72de35a6c62a95.tar.xz
m2e-core-4a3ba6acf496dda6d16b53a69b72de35a6c62a95.zip
335701 discover required m2e extensions during project import
Introduced ability to see project lifecycle mapping configuration as part of import wizard and to check m2e marketplace for extensions that provide support for non-covered mojo executions and unsupported packaging types. This is a proof-of-concept implemenation. UI is completely throw-away code. Backend requires significact work as well. Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Diffstat (limited to 'org.eclipse.m2e.discovery/src')
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java51
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java60
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java68
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java239
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java15
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java27
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogConfiguration.java10
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java26
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java2
9 files changed, 437 insertions, 61 deletions
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java
new file mode 100644
index 00000000..49ae0bcb
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMappingLabelProvider.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.m2e.internal.discovery;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
+
+
+@SuppressWarnings({"restriction", "unchecked", "rawtypes"})
+public class InstallCatalogItemMappingLabelProvider implements ILifecycleMappingLabelProvider, IAdapterFactory {
+
+ private final InstallCatalogItemMavenDiscoveryProposal proposal;
+
+ /**
+ * Factory instance constructor
+ */
+ public InstallCatalogItemMappingLabelProvider() {
+ this(null);
+ }
+
+ public InstallCatalogItemMappingLabelProvider(InstallCatalogItemMavenDiscoveryProposal proposal) {
+ this.proposal = proposal;
+ }
+
+ public String getMavenText() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public String getEclipseMappingText() {
+ return "INSTALL " + proposal.getCatalogItem().getName();
+ }
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adapterType.isAssignableFrom(ILifecycleMappingLabelProvider.class)
+ && adaptableObject instanceof InstallCatalogItemMavenDiscoveryProposal) {
+ return new InstallCatalogItemMappingLabelProvider((InstallCatalogItemMavenDiscoveryProposal) adaptableObject);
+ }
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[] {ILifecycleMappingLabelProvider.class};
+ }
+
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java
new file mode 100644
index 00000000..9e6c3797
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/InstallCatalogItemMavenDiscoveryProposal.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.m2e.internal.discovery;
+
+import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.IMavenDiscoveryProposal;
+
+
+/**
+ * InstallIUMavenDiscoveryProposal
+ *
+ * @author igor
+ */
+@SuppressWarnings("restriction")
+public class InstallCatalogItemMavenDiscoveryProposal implements IMavenDiscoveryProposal {
+
+ private final CatalogItem item;
+
+ public InstallCatalogItemMavenDiscoveryProposal(CatalogItem item) {
+ this.item = item;
+ }
+
+ public CatalogItem getCatalogItem() {
+ return item;
+ }
+
+ @Override
+ public String toString() {
+ return item.getDescription();
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = item.getSiteUrl().hashCode();
+ hash = 17 * hash + item.getInstallableUnits().hashCode();
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj == this) {
+ return true;
+ }
+
+ if(!(obj instanceof InstallCatalogItemMavenDiscoveryProposal)) {
+ return false;
+ }
+
+ InstallCatalogItemMavenDiscoveryProposal other = (InstallCatalogItemMavenDiscoveryProposal) obj;
+
+ return item.getSiteUrl().equals(other.item.getSiteUrl())
+ && item.getInstallableUnits().equals(other.item.getInstallableUnits());
+ }
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
index e77995a8..3fb0aca7 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java
@@ -11,26 +11,38 @@
package org.eclipse.m2e.internal.discovery;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.apache.maven.plugin.MojoExecution;
+import org.codehaus.plexus.util.IOUtil;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.DiscoveryCore;
import org.eclipse.equinox.internal.p2.discovery.compatibility.RemoteBundleDiscoveryStrategy;
+import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
import org.eclipse.equinox.internal.p2.discovery.model.Tag;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingFactory;
+import org.eclipse.m2e.core.internal.lifecycle.model.LifecycleMappingMetadataSource;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.internal.discovery.wizards.MavenCatalogConfiguration;
+import org.eclipse.m2e.internal.discovery.wizards.MavenCatalogViewer;
import org.eclipse.m2e.internal.discovery.wizards.MavenDiscoveryWizard;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.Workbench;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@SuppressWarnings("restriction")
public class MavenDiscovery {
+ private static final Logger log = LoggerFactory.getLogger(MavenDiscovery.class);
public static final Tag NO_RESTART_TAG = new Tag("norestart", "norestart"); //$NON-NLS-1$//$NON-NLS-2$
@@ -48,7 +60,7 @@ public class MavenDiscovery {
launchWizard(shell, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
}
- public static void launchWizard(final Collection<String> packagingTypes, final Collection<MojoExecution> mojos,
+ public static void launchWizard(final Collection<String> packagingTypes, final Collection<MojoExecutionKey> mojos,
final Collection<String> lifecycleIds, final Collection<String> configuratorIds) {
final Display display = Workbench.getInstance().getDisplay();
display.asyncExec(new Runnable() {
@@ -58,16 +70,9 @@ public class MavenDiscovery {
});
}
- public static void launchWizard(Shell shell, Collection<String> packagingTypes, Collection<MojoExecution> mojos,
+ public static void launchWizard(Shell shell, Collection<String> packagingTypes, Collection<MojoExecutionKey> mojos,
Collection<String> lifecycleIds, Collection<String> configuratorIds) {
- Catalog catalog = new Catalog();
- catalog.setEnvironment(DiscoveryCore.createEnvironment());
- catalog.setVerifyUpdateSiteAvailability(false);
-
- // look for remote descriptor
- RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy();
- remoteDiscoveryStrategy.setDirectoryUrl(PATH);
- catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy);
+ Catalog catalog = getCatalog();
// Build the list of tags to show in the Wizard header
List<Tag> tags = new ArrayList<Tag>(3);
@@ -99,4 +104,45 @@ public class MavenDiscovery {
WizardDialog dialog = new WizardDialog(shell, wizard);
dialog.open();
}
+
+ public static Catalog getCatalog() {
+ Catalog catalog = new Catalog();
+ catalog.setEnvironment(DiscoveryCore.createEnvironment());
+ catalog.setVerifyUpdateSiteAvailability(false);
+
+ // look for remote descriptor
+ RemoteBundleDiscoveryStrategy remoteDiscoveryStrategy = new RemoteBundleDiscoveryStrategy();
+ remoteDiscoveryStrategy.setDirectoryUrl(PATH);
+ catalog.getDiscoveryStrategies().add(remoteDiscoveryStrategy);
+ return catalog;
+ }
+
+ public static LifecycleMappingMetadataSource getLifecycleMappingMetadataSource(CatalogItem ci) {
+ try {
+ URL url = MavenCatalogViewer.getLifecycleMappingMetadataSourceURL(ci);
+ InputStream is = url.openStream();
+ try {
+ return LifecycleMappingFactory.createLifecycleMappingMetadataSource(is);
+ } finally {
+ IOUtil.close(is);
+ }
+ } catch(FileNotFoundException e) {
+ log.warn("CatalogItem {} does not contain lifecycle mapping metadata", ci.getId()); //$NON-NLS-1$
+ } catch(Exception e) {
+ log.warn(NLS.bind(Messages.MavenCatalogViewer_Error_loading_lifecycle, ci.getId()), e);
+ }
+ return null;
+ }
+
+ /*
+ * Restart is required when one or more CatalogItem lacks the norestart tag.
+ */
+ public static boolean requireRestart(Iterable<CatalogItem> catalogItems) {
+ for(CatalogItem item : catalogItems) {
+ if(!item.hasTag(NO_RESTART_TAG)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
new file mode 100644
index 00000000..a5a34a47
--- /dev/null
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.internal.discovery;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.IdentityHashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.internal.p2.discovery.Catalog;
+import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
+import org.eclipse.m2e.core.MavenPlugin;
+import org.eclipse.m2e.core.embedder.IMaven;
+import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingFactory;
+import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingResult;
+import org.eclipse.m2e.core.internal.lifecycle.MappingMetadataSource;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.ILifecycleMappingElementKey;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.IMavenDiscoveryProposal;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.IMavenDisovery;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.MojoExecutionMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecycle.discovery.PackagingTypeMappingConfiguration;
+import org.eclipse.m2e.core.internal.lifecycle.model.LifecycleMappingMetadata;
+import org.eclipse.m2e.core.internal.lifecycle.model.LifecycleMappingMetadataSource;
+import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionMetadata;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
+import org.eclipse.m2e.internal.discovery.operation.MavenDiscoveryInstallOperation;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+
+@SuppressWarnings({"restriction", "rawtypes"})
+public class MavenDiscoveryService implements IMavenDisovery, ServiceFactory {
+
+ private final boolean factory;
+
+ //private Catalog catalog;
+
+ private IdentityHashMap<CatalogItem, LifecycleMappingMetadataSource> items;
+
+ public MavenDiscoveryService() {
+ this(true);
+ }
+
+ public MavenDiscoveryService(boolean factory) {
+ this.factory = factory;
+ }
+
+ public Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> discover(MavenProject mavenProject,
+ List<MojoExecution> mojoExecutions, List<IMavenDiscoveryProposal> preselected, IProgressMonitor monitor)
+ throws CoreException {
+
+ if(items == null) {
+ items = new IdentityHashMap<CatalogItem, LifecycleMappingMetadataSource>();
+
+ Catalog catalog = MavenDiscovery.getCatalog();
+ IStatus status = catalog.performDiscovery(monitor);
+
+ if(!status.isOK()) {
+ // XXX log and/or throw something heavy at the caller
+ return null;
+ }
+
+ for(CatalogItem item : catalog.getItems()) {
+ LifecycleMappingMetadataSource metadataSource = MavenDiscovery.getLifecycleMappingMetadataSource(item);
+ if(metadataSource != null) {
+ addCatalogItem(item, metadataSource);
+ }
+ }
+ }
+
+ Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> proposals = new LinkedHashMap<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>>();
+
+ MavenPlugin mavenPlugin = MavenPlugin.getDefault();
+ IMaven maven = mavenPlugin.getMaven();
+
+ MavenExecutionRequest request = maven.createExecutionRequest(monitor); // TODO this ignores workspace dependencies
+
+ List<CatalogItem> selectedItems = toCatalogItems(preselected);
+ List<LifecycleMappingMetadataSource> selectedSources = toMetadataSources(preselected);
+
+ for(Map.Entry<CatalogItem, LifecycleMappingMetadataSource> itemEntry : items.entrySet()) {
+ CatalogItem item = itemEntry.getKey();
+ LifecycleMappingMetadataSource src = itemEntry.getValue();
+
+ boolean preselectItem = false;
+ for(CatalogItem selectedItem : selectedItems) {
+ if(selectedItem.getSiteUrl().equals(item.getSiteUrl())
+ && selectedItem.getInstallableUnits().equals(item.getInstallableUnits())) {
+ preselectItem = true;
+ break;
+ }
+ }
+
+ if(src != null) {
+ src.setSource(item);
+
+ LifecycleMappingResult mappingResult = new LifecycleMappingResult();
+
+ List<LifecycleMappingMetadataSource> sources = new ArrayList<LifecycleMappingMetadataSource>(selectedSources);
+ if(!preselectItem) {
+ sources.add(src);
+ }
+
+ List<MappingMetadataSource> metadataSources = LifecycleMappingFactory.getProjectMetadataSources(request,
+ mavenProject, sources, monitor);
+
+ LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(mappingResult, metadataSources,
+ mavenProject, mojoExecutions);
+
+ LifecycleMappingMetadata lifecycleMappingMetadata = mappingResult.getLifecycleMappingMetadata();
+ if(lifecycleMappingMetadata != null) {
+ IMavenDiscoveryProposal proposal = getProposal(lifecycleMappingMetadata.getSource());
+ if(proposal != null) {
+ put(proposals, new PackagingTypeMappingConfiguration.Key(mavenProject.getPackaging()), proposal);
+ }
+ }
+
+ for(Map.Entry<MojoExecutionKey, List<PluginExecutionMetadata>> entry : mappingResult.getMojoExecutionMapping()
+ .entrySet()) {
+ if(entry.getValue() != null) {
+ for(PluginExecutionMetadata executionMapping : entry.getValue()) {
+ IMavenDiscoveryProposal proposal = getProposal(executionMapping.getSource());
+ if(proposal != null) {
+ put(proposals, new MojoExecutionMappingConfiguration.Key(entry.getKey()), proposal);
+ }
+ // TODO match eclipse extensions provided by the catalog item
+ // User Story.
+ // Project pom.xml explicitly specifies lifecycle mapping strategy implementation,
+ // but the implementation is not currently installed. As a user I expect m2e to search
+ // marketplace for the implementation and offer installation if available
+ }
+ }
+ }
+ }
+ }
+
+ return proposals;
+ }
+
+ public void addCatalogItem(CatalogItem item, LifecycleMappingMetadataSource metadataSource) {
+ if(items == null) {
+ // for tests
+ items = new IdentityHashMap<CatalogItem, LifecycleMappingMetadataSource>();
+ }
+ items.put(item, metadataSource);
+ }
+
+ private IMavenDiscoveryProposal getProposal(LifecycleMappingMetadataSource src) {
+ if(src == null) {
+ return null;
+ }
+ if(src.getSource() instanceof CatalogItem) {
+ return new InstallCatalogItemMavenDiscoveryProposal((CatalogItem) src.getSource());
+ }
+ return null;
+ }
+
+ private List<LifecycleMappingMetadataSource> toMetadataSources(List<IMavenDiscoveryProposal> proposals) {
+ List<LifecycleMappingMetadataSource> sources = new ArrayList<LifecycleMappingMetadataSource>();
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
+ CatalogItem catalogItem = ((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem();
+ LifecycleMappingMetadataSource source = MavenDiscovery.getLifecycleMappingMetadataSource(catalogItem);
+ source.setSource(catalogItem);
+ sources.add(source);
+ }
+ }
+ return sources;
+ }
+
+ private void put(Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> allproposals,
+ ILifecycleMappingElementKey requirement, IMavenDiscoveryProposal proposal) {
+
+ List<IMavenDiscoveryProposal> proposals = allproposals.get(requirement);
+ if(proposals == null) {
+ proposals = new ArrayList<IMavenDiscoveryProposal>();
+ allproposals.put(requirement, proposals);
+ }
+
+ if(!proposals.contains(proposal)) {
+ proposals.add(proposal);
+ }
+ }
+
+ public void implement(List<IMavenDiscoveryProposal> proposals, IProgressMonitor monitor) {
+ List<CatalogItem> items = toCatalogItems(proposals);
+
+ MavenDiscoveryInstallOperation op = new MavenDiscoveryInstallOperation(items, false);
+ try {
+ op.run(monitor);
+ } catch(InvocationTargetException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch(InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private List<CatalogItem> toCatalogItems(List<IMavenDiscoveryProposal> proposals) {
+ List<CatalogItem> items = new ArrayList<CatalogItem>();
+ for(IMavenDiscoveryProposal proposal : proposals) {
+ if(proposal instanceof InstallCatalogItemMavenDiscoveryProposal) {
+ items.add(((InstallCatalogItemMavenDiscoveryProposal) proposal).getCatalogItem());
+ }
+ }
+ return items;
+ }
+
+ public boolean isRestartRequired(List<IMavenDiscoveryProposal> proposals, IProgressMonitor monitor) {
+ return MavenDiscovery.requireRestart(toCatalogItems(proposals));
+ }
+
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ return new MavenDiscoveryService(false); // not a factory instance
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
+ }
+
+}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
index e04bf4a7..ec41ed73 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/markers/DiscoveryWizardProposal.java
@@ -15,14 +15,13 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.MojoExecution;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.m2e.core.core.IMavenConstants;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
import org.eclipse.m2e.internal.discovery.MavenDiscoveryIcons;
import org.eclipse.m2e.internal.discovery.Messages;
@@ -76,7 +75,7 @@ public class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
public void run(IMarker[] markers, IProgressMonitor monitor) {
List<String> lifecycleIds = new ArrayList<String>();
List<String> packagingTypes = new ArrayList<String>();
- List<MojoExecution> mojos = new ArrayList<MojoExecution>();
+ List<MojoExecutionKey> mojos = new ArrayList<MojoExecutionKey>();
List<String> configuratorIds = new ArrayList<String>();
for(IMarker marker : markers) {
String type = marker.getAttribute(IMavenConstants.MARKER_ATTR_EDITOR_HINT, null);
@@ -93,7 +92,7 @@ public class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
MavenDiscovery.launchWizard(packagingTypes, mojos, lifecycleIds, configuratorIds);
}
- private MojoExecution getMojoExecution(IMarker marker) {
+ private MojoExecutionKey getMojoExecution(IMarker marker) {
// TODO Which of these are actually required?
String groupId = marker.getAttribute(IMavenConstants.MARKER_ATTR_GROUP_ID, null);
String artifactId = marker.getAttribute(IMavenConstants.MARKER_ATTR_ARTIFACT_ID, null);
@@ -102,13 +101,7 @@ public class DiscoveryWizardProposal extends WorkbenchMarkerResolution {
String goal = marker.getAttribute(IMavenConstants.MARKER_ATTR_GOAL, null);
String lifecyclePhase = marker.getAttribute(IMavenConstants.MARKER_ATTR_LIFECYCLE_PHASE, null);
if(goal != null && executionId != null && artifactId != null && groupId != null) {
- Plugin plugin = new Plugin();
- plugin.setArtifactId(artifactId);
- plugin.setGroupId(groupId);
- plugin.setVersion(version);
- MojoExecution mojoExecution = new MojoExecution(plugin, goal, executionId);
- mojoExecution.setLifecyclePhase(lifecyclePhase);
- return mojoExecution;
+ return new MojoExecutionKey(groupId, artifactId, version, goal, lifecyclePhase, executionId);
}
return null;
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java
index 29725ce7..fca24091 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/operation/MavenDiscoveryInstallOperation.java
@@ -25,6 +25,8 @@ import org.eclipse.equinox.internal.p2.ui.discovery.operations.DiscoveryInstallO
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.operations.ProvisioningJob;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
+import org.eclipse.equinox.p2.query.IQuery;
+import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.equinox.p2.ui.ProvisioningUI;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
import org.eclipse.m2e.internal.discovery.Messages;
@@ -41,9 +43,13 @@ public class MavenDiscoveryInstallOperation extends DiscoveryInstallOperation {
private List<CatalogItem> installableConnectors;
private ProvisioningSession session;
- public MavenDiscoveryInstallOperation(List<CatalogItem> installableConnectors) {
+
+ private final boolean restart;
+
+ public MavenDiscoveryInstallOperation(List<CatalogItem> installableConnectors, boolean restart) {
super(installableConnectors);
this.installableConnectors = installableConnectors;
+ this.restart = restart;
this.session = ProvisioningUI.getDefaultUI().getSession();
}
@@ -57,7 +63,7 @@ public class MavenDiscoveryInstallOperation extends DiscoveryInstallOperation {
checkCancelled(monitor);
final RestartInstallOperation installOperation = createAndResolve(monitor.newChild(50), ius, new URI[0],
- requireRestart(installableConnectors));
+ restart && MavenDiscovery.requireRestart(installableConnectors));
checkCancelled(monitor);
@@ -77,18 +83,6 @@ public class MavenDiscoveryInstallOperation extends DiscoveryInstallOperation {
}
/*
- * Restart is required when one or more CatalogItem lacks the norestart tag.
- */
- public static boolean requireRestart(Iterable<CatalogItem> catalogItems) {
- for(CatalogItem item : catalogItems) {
- if(!item.hasTag(MavenDiscovery.NO_RESTART_TAG)) {
- return true;
- }
- }
- return false;
- }
-
- /*
* Create a RestartInstallOperation and resolve
*/
private RestartInstallOperation createAndResolve(IProgressMonitor monitor, final IInstallableUnit[] ius,
@@ -113,4 +107,9 @@ public class MavenDiscoveryInstallOperation extends DiscoveryInstallOperation {
throw new OperationCanceledException();
}
}
+
+ @Override
+ protected IQuery<IInstallableUnit> createInstalledIUsQuery() {
+ return QueryUtil.createIUAnyQuery();
+ }
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogConfiguration.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogConfiguration.java
index 6a6201a5..e0232ce3 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogConfiguration.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogConfiguration.java
@@ -15,8 +15,8 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
-import org.apache.maven.plugin.MojoExecution;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogConfiguration;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
@SuppressWarnings("restriction")
@@ -24,7 +24,7 @@ public class MavenCatalogConfiguration extends CatalogConfiguration {
private Set<String> selectedPackagingTypes;
- private Set<MojoExecution> selectedMojos;
+ private Set<MojoExecutionKey> selectedMojos;
private Set<String> selectedLifecycleIds;
@@ -38,7 +38,7 @@ public class MavenCatalogConfiguration extends CatalogConfiguration {
return selectedConfiguratorIds;
}
- public Collection<MojoExecution> getSelectedMojos() {
+ public Collection<MojoExecutionKey> getSelectedMojos() {
return selectedMojos;
}
@@ -60,9 +60,9 @@ public class MavenCatalogConfiguration extends CatalogConfiguration {
/*
* Set the mojos that should be selected in the UI
*/
- public void setSelectedMojos(Collection<MojoExecution> mojos) {
+ public void setSelectedMojos(Collection<MojoExecutionKey> mojos) {
if(selectedMojos == null) {
- selectedMojos = new HashSet<MojoExecution>(mojos);
+ selectedMojos = new HashSet<MojoExecutionKey>(mojos);
} else {
selectedMojos.addAll(mojos);
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
index 2929989c..4257a6c7 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java
@@ -14,7 +14,6 @@ package org.eclipse.m2e.internal.discovery.wizards;
import java.net.URL;
import java.util.Collection;
-import org.apache.maven.plugin.MojoExecution;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
import org.eclipse.equinox.internal.p2.discovery.model.Tag;
@@ -22,20 +21,18 @@ import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogConfiguration
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogViewer;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.window.IShellProvider;
-import org.eclipse.m2e.core.internal.lifecycle.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecycle.model.LifecycleMappingMetadata;
import org.eclipse.m2e.core.internal.lifecycle.model.LifecycleMappingMetadataSource;
import org.eclipse.m2e.core.internal.lifecycle.model.PluginExecutionMetadata;
+import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.internal.discovery.MavenDiscovery;
-import org.eclipse.m2e.internal.discovery.Messages;
-import org.eclipse.osgi.util.NLS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SuppressWarnings("restriction")
public class MavenCatalogViewer extends CatalogViewer {
- private static final Logger log = LoggerFactory.getLogger(MavenCatalogViewer.class);
+ public static final Logger log = LoggerFactory.getLogger(MavenCatalogViewer.class);
private static final String CONFIGURATOR_PREFIX = "configurator:"; //$NON-NLS-1$
@@ -56,7 +53,7 @@ public class MavenCatalogViewer extends CatalogViewer {
final MavenCatalogConfiguration config = (MavenCatalogConfiguration) getConfiguration();
final Collection<String> selectedPackagingTypes = config.getSelectedPackagingTypes();
- final Collection<MojoExecution> selectedMojos = config.getSelectedMojos();
+ final Collection<MojoExecutionKey> selectedMojos = config.getSelectedMojos();
final Collection<String> selectedLifecycleIds = config.getSelectedLifecycleIds();
final Collection<String> selectedConfiguratorIds = config.getSelectedConfiguratorIds();
@@ -66,7 +63,7 @@ public class MavenCatalogViewer extends CatalogViewer {
for(CatalogItem ci : getCatalog().getItems()) {
boolean selected = false;
- LifecycleMappingMetadataSource src = getLifecycleMappingMetadataSource(ci);
+ LifecycleMappingMetadataSource src = MavenDiscovery.getLifecycleMappingMetadataSource(ci);
if(src != null) {
for(String packagingType : selectedPackagingTypes) {
if(hasPackaging(src, packagingType)) {
@@ -78,7 +75,7 @@ public class MavenCatalogViewer extends CatalogViewer {
if(selected) {
continue;
}
- for(MojoExecution mojoExecution : selectedMojos) {
+ for(MojoExecutionKey mojoExecution : selectedMojos) {
if(matchesFilter(src, mojoExecution)) {
selected = true;
select(ci);
@@ -119,7 +116,7 @@ public class MavenCatalogViewer extends CatalogViewer {
ci.addTag(MavenDiscovery.APPLICABLE_TAG);
}
- private static boolean matchesFilter(LifecycleMappingMetadataSource src, MojoExecution mojoExecution) {
+ private static boolean matchesFilter(LifecycleMappingMetadataSource src, MojoExecutionKey mojoExecution) {
for(PluginExecutionMetadata p : src.getPluginExecutions()) {
if(p.getFilter().match(mojoExecution)) {
return true;
@@ -128,16 +125,7 @@ public class MavenCatalogViewer extends CatalogViewer {
return false;
}
- private LifecycleMappingMetadataSource getLifecycleMappingMetadataSource(CatalogItem ci) {
- try {
- return LifecycleMappingFactory.createLifecycleMappingMetadataSource(getLifecycleMappingMetadataSourceURL(ci));
- } catch(Exception e) {
- log.warn(NLS.bind(Messages.MavenCatalogViewer_Error_loading_lifecycle, ci.getId()), e);
- return null;
- }
- }
-
- private static URL getLifecycleMappingMetadataSourceURL(CatalogItem ci) {
+ public static URL getLifecycleMappingMetadataSourceURL(CatalogItem ci) {
return ci.getSource().getResource(PATH + ci.getId() + EXT);
}
diff --git a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
index f55dc509..b7e56449 100644
--- a/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
+++ b/org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenDiscoveryUi.java
@@ -50,7 +50,7 @@ public abstract class MavenDiscoveryUi {
public static boolean install(List<CatalogItem> descriptors, IRunnableContext context) {
try {
- IRunnableWithProgress runner = new MavenDiscoveryInstallOperation(descriptors);
+ IRunnableWithProgress runner = new MavenDiscoveryInstallOperation(descriptors, true);
context.run(true, true, runner);
} catch (InvocationTargetException e) {
IStatus status = new Status(IStatus.ERROR, DiscoveryActivator.PLUGIN_ID, NLS.bind(

Back to the top