diff options
author | Fred Bricon | 2013-08-28 16:55:24 +0000 |
---|---|---|
committer | Fred Bricon | 2013-09-30 07:53:54 +0000 |
commit | 601f18cf2f007d80e6347217c302989218e96f47 (patch) | |
tree | 838d412ff5e4b2af02445ea7df4aaf841974a9cc /org.eclipse.m2e.core | |
parent | bc2d4140e3aaf327ece012c4e42b6edc6bc5a38c (diff) | |
download | m2e-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>
Diffstat (limited to 'org.eclipse.m2e.core')
2 files changed, 46 insertions, 5 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>(); |