Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2011-03-07 12:28:28 -0500
committerIgor Fedorenko2011-03-07 12:28:28 -0500
commit613458d7b452941a4d30828d255844165ce13fdc (patch)
tree870c7a4bdff100e3dd551e374eb732ef25f1b070 /org.eclipse.m2e.discovery/src
parent73fc418a25f3812d71487714c1521ded83db6be0 (diff)
downloadm2e-core-613458d7b452941a4d30828d255844165ce13fdc.tar.gz
m2e-core-613458d7b452941a4d30828d255844165ce13fdc.tar.xz
m2e-core-613458d7b452941a4d30828d255844165ce13fdc.zip
335701 discover lifecycleMapping and project configiguration extensions
Discover and offer installation of m2e extensions providing lifecycleMapping and project configiguration implementations. 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.java18
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscovery.java58
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java77
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/wizards/MavenCatalogViewer.java9
4 files changed, 120 insertions, 42 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
index bfbc1208..62c82698 100644
--- 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
@@ -9,13 +9,13 @@
package org.eclipse.m2e.internal.discovery;
import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingElementKey;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.LifecycleMappingConfiguration;
import org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider;
-import org.eclipse.m2e.core.ui.internal.lifecyclemapping.LifecycleMappingConfiguration;
//TODO : can probably be removed..
@SuppressWarnings({"restriction", "unchecked", "rawtypes"})
-public class InstallCatalogItemMappingLabelProvider implements ILifecycleMappingLabelProvider, IAdapterFactory {
+public class InstallCatalogItemMappingLabelProvider implements IAdapterFactory {
private final InstallCatalogItemMavenDiscoveryProposal proposal;
@@ -34,7 +34,7 @@ public class InstallCatalogItemMappingLabelProvider implements ILifecycleMapping
return ""; //$NON-NLS-1$
}
- public String getEclipseMappingText() {
+ public String getEclipseMappingText(LifecycleMappingConfiguration configuration) {
return "INSTALL " + proposal.getCatalogItem().getName();
}
@@ -51,14 +51,6 @@ public class InstallCatalogItemMappingLabelProvider implements ILifecycleMapping
}
/* (non-Javadoc)
- * @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#getEclipseMappingText(org.eclipse.m2e.core.ui.internal.lifecyclemapping.LifecycleMappingConfiguration)
- */
- public String getEclipseMappingText(LifecycleMappingConfiguration mappingConfiguration) {
- // TODO Auto-generated method getEclipseMappingText
- return null;
- }
-
- /* (non-Javadoc)
* @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#isError()
*/
public boolean isError() {
@@ -69,7 +61,7 @@ public class InstallCatalogItemMappingLabelProvider implements ILifecycleMapping
/* (non-Javadoc)
* @see org.eclipse.m2e.core.ui.internal.lifecyclemapping.ILifecycleMappingLabelProvider#getKey()
*/
- public ILifecycleMappingElementKey getKey() {
+ public ILifecycleMappingRequirement getKey() {
// TODO Auto-generated method getKey
return null;
}
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 7f7e30bb..ad477fa3 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
@@ -12,6 +12,7 @@
package org.eclipse.m2e.internal.discovery;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
@@ -20,6 +21,9 @@ import java.util.Collections;
import java.util.List;
import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.equinox.internal.p2.discovery.Catalog;
import org.eclipse.equinox.internal.p2.discovery.DiscoveryCore;
import org.eclipse.equinox.internal.p2.discovery.model.CatalogItem;
@@ -30,7 +34,6 @@ import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMeta
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.internal.discovery.strategy.M2ERemoteBundleDiscoveryStrategy;
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;
@@ -56,6 +59,12 @@ public class MavenDiscovery {
private static final String PATH = "http://download.eclipse.org/technology/m2e/discovery/directory.xml"; //$NON-NLS-1$
+ public static final String LIFECYCLE_PATH = "lifecycle/"; //$NON-NLS-1$
+
+ public static final String LIFECYCLE_EXT = ".xml"; //$NON-NLS-1$
+
+ public static final String PLUGINXML_EXT = ".pluginxml"; //$NON-NLS-1$
+
public static void launchWizard(Shell shell) {
launchWizard(shell, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
}
@@ -119,7 +128,7 @@ public class MavenDiscovery {
public static LifecycleMappingMetadataSource getLifecycleMappingMetadataSource(CatalogItem ci) {
try {
- URL url = MavenCatalogViewer.getLifecycleMappingMetadataSourceURL(ci);
+ URL url = getLifecycleMappingMetadataSourceURL(ci);
if(url == null) {
return null;
}
@@ -148,4 +157,49 @@ public class MavenDiscovery {
}
return false;
}
+
+ public static void getProvidedProjectConfigurators(CatalogItem ci, List<String> projectConfigurators,
+ List<String> mappingStrategies) {
+ try {
+ URL url = ci.getSource().getResource(LIFECYCLE_PATH + ci.getId() + PLUGINXML_EXT);
+ if(url != null) {
+ InputStream is = url.openStream();
+ parsePluginXml(is, projectConfigurators, mappingStrategies);
+ }
+ } 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);
+ }
+ }
+
+ public static void parsePluginXml(InputStream is, List<String> configurators, List<String> mappingStrategies)
+ throws XmlPullParserException, IOException {
+ Xpp3Dom plugin = Xpp3DomBuilder.build(is, "UTF-8"); //$NON-NLS-1$
+ Xpp3Dom[] extensions = plugin.getChildren("extension"); //$NON-NLS-1$
+ for(Xpp3Dom extension : extensions) {
+ String extensionPoint = extension.getAttribute("point"); //$NON-NLS-1$
+ if(LifecycleMappingFactory.EXTENSION_PROJECT_CONFIGURATORS.equals(extensionPoint)) {
+ Xpp3Dom[] configuratorsDom = extension.getChildren("configurator"); //$NON-NLS-1$
+ for(Xpp3Dom configurator : configuratorsDom) {
+ String id = configurator.getAttribute("id"); //$NON-NLS-1$
+ if(id != null) {
+ configurators.add(id);
+ }
+ }
+ } else if (LifecycleMappingFactory.EXTENSION_LIFECYCLE_MAPPINGS.equals(extensionPoint)) {
+ Xpp3Dom[] lifecycleMappingsDom = extension.getChildren("lifecycleMapping"); //$NON-NLS-1$
+ for(Xpp3Dom lifecycleMapping : lifecycleMappingsDom) {
+ String id = lifecycleMapping.getAttribute("id"); //$NON-NLS-1$
+ if(id != null) {
+ mappingStrategies.add(id);
+ }
+ }
+ }
+ }
+ }
+
+ public static URL getLifecycleMappingMetadataSourceURL(CatalogItem ci) {
+ return ci.getSource().getResource(LIFECYCLE_PATH + ci.getId() + LIFECYCLE_EXT);
+ }
}
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
index 7369c408..e4b457c1 100644
--- 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
@@ -47,13 +47,14 @@ import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult;
import org.eclipse.m2e.core.internal.lifecyclemapping.MappingMetadataSource;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingElementKey;
-import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.ILifecycleMappingRequirement;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscovery;
+import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.IMavenDiscoveryProposal;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.MojoExecutionMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.discovery.PackagingTypeMappingConfiguration;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadata;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.LifecycleMappingMetadataSource;
+import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionAction;
import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
import org.eclipse.m2e.core.ui.internal.wizards.IImportWizardPageFactory;
@@ -76,9 +77,16 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
private final LifecycleMappingMetadataSource metadataSource;
- public CatalogItemCacheEntry(CatalogItem item, LifecycleMappingMetadataSource metadataSource) {
+ private final List<String> projectConfigurators;
+
+ private final List<String> mappingStrategies;
+
+ public CatalogItemCacheEntry(CatalogItem item, LifecycleMappingMetadataSource metadataSource,
+ List<String> projectConfigurators, List<String> mappingStrategies) {
this.item = item;
this.metadataSource = metadataSource;
+ this.projectConfigurators = projectConfigurators;
+ this.mappingStrategies = mappingStrategies;
}
public CatalogItem getItem() {
@@ -88,6 +96,14 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
public LifecycleMappingMetadataSource getMetadataSource() {
return metadataSource;
}
+
+ public List<String> getProjectConfigurators() {
+ return projectConfigurators;
+ }
+
+ public List<String> getMappingStrategies() {
+ return mappingStrategies;
+ }
}
private List<CatalogItemCacheEntry> items;
@@ -99,7 +115,7 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
public MavenDiscoveryService(boolean factory) {
}
- public Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> discover(MavenProject mavenProject,
+ public Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> discover(MavenProject mavenProject,
List<MojoExecution> mojoExecutions, List<IMavenDiscoveryProposal> preselected, IProgressMonitor monitor)
throws CoreException {
@@ -116,13 +132,16 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
for(CatalogItem item : catalog.getItems()) {
LifecycleMappingMetadataSource metadataSource = MavenDiscovery.getLifecycleMappingMetadataSource(item);
+ List<String> projectConfigurators = new ArrayList<String>();
+ List<String> mappingStrategies = new ArrayList<String>();
+ MavenDiscovery.getProvidedProjectConfigurators(item, projectConfigurators, mappingStrategies);
if(metadataSource != null) {
- addCatalogItem(item, metadataSource);
+ addCatalogItem(item, metadataSource, projectConfigurators, mappingStrategies);
}
}
}
- Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> proposals = new LinkedHashMap<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>>();
+ Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> proposals = new LinkedHashMap<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>>();
MavenPlugin mavenPlugin = MavenPlugin.getDefault();
IMaven maven = mavenPlugin.getMaven();
@@ -159,13 +178,22 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
mavenProject, sources, monitor);
LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(mappingResult, request, metadataSources,
- mavenProject, mojoExecutions);
+ mavenProject, mojoExecutions, false);
LifecycleMappingMetadata lifecycleMappingMetadata = mappingResult.getLifecycleMappingMetadata();
if(lifecycleMappingMetadata != null) {
IMavenDiscoveryProposal proposal = getProposal(lifecycleMappingMetadata.getSource());
if(proposal != null) {
- put(proposals, new PackagingTypeMappingConfiguration.Key(mavenProject.getPackaging()), proposal);
+ put(proposals,
+ new PackagingTypeMappingConfiguration.PackagingTypeMappingRequirement(mavenProject.getPackaging()),
+ proposal);
+ } else if(!LifecycleMappingFactory.getLifecycleMappingExtensions().containsKey(
+ lifecycleMappingMetadata.getLifecycleMappingId())) {
+ if(itemEntry.getMappingStrategies().contains(lifecycleMappingMetadata.getLifecycleMappingId())) {
+ put(proposals, new PackagingTypeMappingConfiguration.LifecycleStrategyMappingRequirement(
+ lifecycleMappingMetadata.getPackagingType(), lifecycleMappingMetadata.getLifecycleMappingId()),
+ new InstallCatalogItemMavenDiscoveryProposal(item));
+ }
}
}
@@ -175,13 +203,25 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
for(PluginExecutionMetadata executionMapping : entry.getValue()) {
IMavenDiscoveryProposal proposal = getProposal(executionMapping.getSource());
if(proposal != null) {
- put(proposals, new MojoExecutionMappingConfiguration.Key(entry.getKey()), proposal);
+ // assumes installation of mapping proposal installs all required project configurators
+ put(proposals, new MojoExecutionMappingConfiguration.MojoExecutionMappingRequirement(entry.getKey()),
+ proposal);
+ } else if(executionMapping.getAction() == PluginExecutionAction.configurator) {
+ // we have <configurator/> mapping from pom.xml
+ String configuratorId = LifecycleMappingFactory.getProjectConfiguratorId(executionMapping);
+ if(!LifecycleMappingFactory.getProjectConfiguratorExtensions().containsKey(configuratorId)) {
+ // 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
+
+ if(itemEntry.getProjectConfigurators().contains(configuratorId)) {
+ put(proposals,
+ new MojoExecutionMappingConfiguration.ProjectConfiguratorMappingRequirement(entry.getKey(),
+ configuratorId), new InstallCatalogItemMavenDiscoveryProposal(item));
+ }
+ }
}
- // 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
}
}
}
@@ -191,12 +231,13 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
return proposals;
}
- public void addCatalogItem(CatalogItem item, LifecycleMappingMetadataSource metadataSource) {
+ public void addCatalogItem(CatalogItem item, LifecycleMappingMetadataSource metadataSource,
+ List<String> projectConfigurators, List<String> mappingStrategies) {
if(items == null) {
// for tests
items = new ArrayList<MavenDiscoveryService.CatalogItemCacheEntry>();
}
- items.add(new CatalogItemCacheEntry(item, metadataSource));
+ items.add(new CatalogItemCacheEntry(item, metadataSource, projectConfigurators, mappingStrategies));
}
private IMavenDiscoveryProposal getProposal(LifecycleMappingMetadataSource src) {
@@ -222,8 +263,8 @@ public class MavenDiscoveryService implements IImportWizardPageFactory, IMavenDi
return sources;
}
- private void put(Map<ILifecycleMappingElementKey, List<IMavenDiscoveryProposal>> allproposals,
- ILifecycleMappingElementKey requirement, IMavenDiscoveryProposal proposal) {
+ private void put(Map<ILifecycleMappingRequirement, List<IMavenDiscoveryProposal>> allproposals,
+ ILifecycleMappingRequirement requirement, IMavenDiscoveryProposal proposal) {
List<IMavenDiscoveryProposal> proposals = allproposals.get(requirement);
if(proposals == null) {
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 80085556..f517f5b6 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
@@ -12,7 +12,6 @@
package org.eclipse.m2e.internal.discovery.wizards;
import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
import java.util.Collection;
import java.util.Set;
@@ -50,10 +49,6 @@ public class MavenCatalogViewer extends CatalogViewer {
private static final String LIFECYCLE_PREFIX = "lifecycle:"; //$NON-NLS-1$
- private static final String PATH = "lifecycle/"; //$NON-NLS-1$
-
- private static final String EXT = ".xml"; //$NON-NLS-1$
-
private Set<String> installedFeatures;
/*
@@ -224,10 +219,6 @@ public class MavenCatalogViewer extends CatalogViewer {
return false;
}
- public static URL getLifecycleMappingMetadataSourceURL(CatalogItem ci) {
- return ci.getSource().getResource(PATH + ci.getId() + EXT);
- }
-
private static boolean hasPackaging(LifecycleMappingMetadataSource lifecycleMappingMetadataSource,
String packagingType) {
for(LifecycleMappingMetadata lifecycleMappingMetadata : lifecycleMappingMetadataSource.getLifecycleMappings()) {

Back to the top