Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2013-08-28 12:55:24 -0400
committerFred Bricon2013-09-30 03:53:54 -0400
commit601f18cf2f007d80e6347217c302989218e96f47 (patch)
tree838d412ff5e4b2af02445ea7df4aaf841974a9cc
parentbc2d4140e3aaf327ece012c4e42b6edc6bc5a38c (diff)
downloadm2e-core-601f18cf2f007d80e6347217c302989218e96f47.tar.gz
m2e-core-601f18cf2f007d80e6347217c302989218e96f47.tar.xz
m2e-core-601f18cf2f007d80e6347217c302989218e96f47.zip
Minimize Lifecycle Mapping parsing during discovery
Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java49
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/SimpleMappingMetadataSource.java2
-rw-r--r--org.eclipse.m2e.discovery/src/org/eclipse/m2e/internal/discovery/MavenDiscoveryService.java11
3 files changed, 54 insertions, 8 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
index c52fea82..ca05305f 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java
@@ -247,8 +247,17 @@ public class LifecycleMappingFactory {
public static List<MappingMetadataSource> getProjectMetadataSources(MavenProject mavenProject,
List<LifecycleMappingMetadataSource> bundleMetadataSources, List<MojoExecution> mojoExecutions,
boolean includeDefault, IProgressMonitor monitor) throws CoreException, LifecycleMappingConfigurationException {
- List<MappingMetadataSource> metadataSources = new ArrayList<MappingMetadataSource>();
+ Map<String, List<MappingMetadataSource>> metadataSourcesMap = getProjectMetadataSourcesMap(mavenProject,
+ bundleMetadataSources, mojoExecutions, includeDefault, monitor);
+ return asList(metadataSourcesMap);
+ }
+
+ public static Map<String, List<MappingMetadataSource>> getProjectMetadataSourcesMap(MavenProject mavenProject,
+ List<LifecycleMappingMetadataSource> bundleMetadataSources, List<MojoExecution> mojoExecutions,
+ boolean includeDefault, IProgressMonitor monitor) throws CoreException, LifecycleMappingConfigurationException {
+
+ Map<String, List<MappingMetadataSource>> metadataSourcesMap = new HashMap<String, List<MappingMetadataSource>>();
// List order
// 1. preferences in project (*** not implemented yet)
// 2. preferences in ancestor project (*** not implemented yet)
@@ -260,28 +269,60 @@ public class LifecycleMappingFactory {
// TODO validate metadata and replace invalid entries with error mapping
+ List<MappingMetadataSource> metadataSources = new ArrayList<MappingMetadataSource>();
for(LifecycleMappingMetadataSource source : getPomMappingMetadataSources(mavenProject, monitor)) {
metadataSources.add(new SimpleMappingMetadataSource(source));
}
+ metadataSourcesMap.put("pomMappingMetadataSources", metadataSources);
- metadataSources.add(new SimpleMappingMetadataSource(getWorkspaceMetadata(false)));
+ metadataSourcesMap
+ .put(
+ "workspaceMetadataSources", //
+ Collections.singletonList((MappingMetadataSource) new SimpleMappingMetadataSource(
+ getWorkspaceMetadata(false))));
// TODO filter out invalid metadata from sources contributed by eclipse extensions and the default source
- metadataSources.add(new SimpleMappingMetadataSource(bundleMetadataSources));
+ if(bundleMetadataSources != null) {
+ metadataSourcesMap.put("bundleMetadataSources",
+ Collections.singletonList((MappingMetadataSource) new SimpleMappingMetadataSource(bundleMetadataSources)));
+ }
+
+ metadataSources = new ArrayList<MappingMetadataSource>();
for(LifecycleMappingMetadataSource source : getMavenPluginEmbeddedMetadataSources(mojoExecutions,
mavenProject.getPluginArtifactRepositories(), monitor)) {
metadataSources.add(new SimpleMappingMetadataSource(source));
}
+ metadataSourcesMap.put("mavenPluginEmbeddedMetadataSources", metadataSources);
+
if(includeDefault) {
LifecycleMappingMetadataSource defaultSource = getDefaultLifecycleMappingMetadataSource();
if(defaultSource != null) {
- metadataSources.add(new SimpleMappingMetadataSource(defaultSource));
+ metadataSourcesMap.put("defaultLifecycleMappingMetadataSource",
+ Collections.singletonList((MappingMetadataSource) new SimpleMappingMetadataSource(defaultSource)));
}
}
+ return metadataSourcesMap;
+ }
+
+ public static List<MappingMetadataSource> asList(Map<String, List<MappingMetadataSource>> map) {
+ if(map == null || map.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<MappingMetadataSource> metadataSources = new ArrayList<MappingMetadataSource>();
+ safeAddAll(map.get("pomMappingMetadataSources"), metadataSources);
+ safeAddAll(map.get("workspaceMetadataSources"), metadataSources);
+ safeAddAll(map.get("bundleMetadataSources"), metadataSources);
+ safeAddAll(map.get("mavenPluginEmbeddedMetadataSources"), metadataSources);
+ safeAddAll(map.get("defaultLifecycleMappingMetadataSource"), metadataSources);
return metadataSources;
}
+ private static <T> void safeAddAll(List<T> source, List<T> dest) {
+ if(source != null && dest != null)
+ dest.addAll(source);
+ }
+
private static List<LifecycleMappingMetadataSource> getMavenPluginEmbeddedMetadataSources(
List<MojoExecution> mojoExecutions, List<ArtifactRepository> remoteRepositories, IProgressMonitor monitor) {
Map<File, LifecycleMappingMetadataSource> result = new LinkedHashMap<File, LifecycleMappingMetadataSource>();
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/SimpleMappingMetadataSource.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/SimpleMappingMetadataSource.java
index 43f2b9cf..79052c2d 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/SimpleMappingMetadataSource.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/SimpleMappingMetadataSource.java
@@ -25,7 +25,7 @@ import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;
*
* @author igor
*/
-class SimpleMappingMetadataSource implements MappingMetadataSource {
+public class SimpleMappingMetadataSource implements MappingMetadataSource {
private final List<LifecycleMappingMetadata> lifecycleMappings = new ArrayList<LifecycleMappingMetadata>();
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 027ec208..dad800c6 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
@@ -57,6 +57,7 @@ import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
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.SimpleMappingMetadataSource;
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;
@@ -168,6 +169,9 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
Collection<CatalogItem> selectedItems = toCatalogItems(preselected);
List<LifecycleMappingMetadataSource> selectedSources = toMetadataSources(preselected);
+ Map<String, List<MappingMetadataSource>> metadataSourcesMap = LifecycleMappingFactory.getProjectMetadataSourcesMap(
+ mavenProject, null, mojoExecutions, false, monitor);
+
for(CatalogItemCacheEntry itemEntry : items) {
CatalogItem item = itemEntry.getItem();
LifecycleMappingMetadataSource src = itemEntry.getMetadataSource();
@@ -182,7 +186,7 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
}
if(src != null) {
- log.debug("Considering catalog item '{}'", item.getName()); //$NON-NLS-1$
+ log.debug("Considering catalog item '{}' for project {}", item.getName(), mavenProject.getName()); //$NON-NLS-1$
src.setSource(item);
@@ -193,9 +197,10 @@ public class MavenDiscoveryService implements IMavenDiscoveryUI, IMavenDiscovery
sources.add(src);
}
- List<MappingMetadataSource> metadataSources = LifecycleMappingFactory.getProjectMetadataSources(mavenProject,
- sources, mojoExecutions, false, monitor);
+ metadataSourcesMap.put("bundleMetadataSources",
+ Collections.singletonList((MappingMetadataSource) new SimpleMappingMetadataSource(sources)));
+ List<MappingMetadataSource> metadataSources = LifecycleMappingFactory.asList(metadataSourcesMap);
LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(mappingResult, metadataSources,
mavenProject, mojoExecutions, false, monitor);

Back to the top