diff options
2 files changed, 41 insertions, 25 deletions
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 1187e20f..1abff2b9 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 @@ -13,6 +13,8 @@ package org.eclipse.m2e.core.internal; import java.io.File; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; import org.osgi.framework.Constants; import org.osgi.framework.Version; import org.slf4j.Logger; @@ -63,6 +65,7 @@ import org.eclipse.m2e.core.internal.embedder.MavenWorkspaceRuntime; import org.eclipse.m2e.core.internal.index.IndexesExtensionReader; import org.eclipse.m2e.core.internal.index.IndexingTransferListener; import org.eclipse.m2e.core.internal.index.NexusIndexManager; +import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager; import org.eclipse.m2e.core.internal.markers.MavenMarkerManager; import org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl; @@ -117,6 +120,13 @@ public class MavenPluginActivator extends Plugin { private String qualifiedVersion = "0.0.0.qualifier"; //$NON-NLS-1$ private IMavenConfiguration mavenConfiguration; + + private BundleListener bundleListener = new BundleListener() { + + public void bundleChanged(BundleEvent event) { + LifecycleMappingFactory.setBundleMetadataSources(null); + } + }; private MavenImpl maven; @@ -219,7 +229,8 @@ public class MavenPluginActivator extends Plugin { this.maven.addLocalRepositoryListener(new IndexingTransferListener(indexManager)); this.repositoryRegistry.addRepositoryIndexer(indexManager); this.repositoryRegistry.addRepositoryDiscoverer(new IndexesExtensionReader(indexManager)); - + context.addBundleListener(bundleListener); + // fork repository registry update. must after index manager registered as a listener this.repositoryRegistry.updateRegistry(); } @@ -246,6 +257,8 @@ public class MavenPluginActivator extends Plugin { super.stop(context); this.managerImpl.writeWorkspaceState(); + context.removeBundleListener(bundleListener); + this.mavenBackgroundJob.cancel(); try { this.mavenBackgroundJob.join(); @@ -266,6 +279,7 @@ public class MavenPluginActivator extends Plugin { workspace.removeResourceChangeListener(configurationManager); this.configurationManager = null; + LifecycleMappingFactory.setBundleMetadataSources(null); plugin = null; } 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 874b515c..59f41b8a 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 @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Set; import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -145,6 +144,8 @@ public class LifecycleMappingFactory { private static final String LIFECYCLE_MAPPING_METADATA_CLASSIFIER = "lifecycle-mapping-metadata"; + private static List<LifecycleMappingMetadataSource> bundleMetadataSources = null; + public static LifecycleMappingResult calculateLifecycleMapping(MavenExecutionRequest templateRequest, MavenProjectFacade projectFacade, IProgressMonitor monitor) { long start = System.currentTimeMillis(); @@ -910,32 +911,26 @@ public class LifecycleMappingFactory { /** * Returns lifecycle mapping metadata sources provided by all installed bundles */ - public static List<LifecycleMappingMetadataSource> getBundleMetadataSources() { - // XXX cache! - ArrayList<LifecycleMappingMetadataSource> sources = new ArrayList<LifecycleMappingMetadataSource>(); - - BundleContext ctx = MavenPluginActivator.getDefault().getBundleContext(); - Map<String, Bundle> bundles = new HashMap<String, Bundle>(); - for(Bundle bundle : ctx.getBundles()) { - bundles.put(bundle.getSymbolicName(), bundle); - } - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint configuratorsExtensionPoint = registry - .getExtensionPoint(EXTENSION_LIFECYCLE_MAPPING_METADATA_SOURCE); - if(configuratorsExtensionPoint != null) { - IExtension[] configuratorExtensions = configuratorsExtensionPoint.getExtensions(); - for(IExtension extension : configuratorExtensions) { - RegistryContributor contributor = (RegistryContributor) extension.getContributor(); - Bundle bundle = bundles.get(contributor.getActualName()); - LifecycleMappingMetadataSource source = getMetadataSource(bundle); - if(source != null) { - sources.add(source); + public synchronized static List<LifecycleMappingMetadataSource> getBundleMetadataSources() { + if(bundleMetadataSources == null) { + bundleMetadataSources = new ArrayList<LifecycleMappingMetadataSource>(); + + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint configuratorsExtensionPoint = registry + .getExtensionPoint(EXTENSION_LIFECYCLE_MAPPING_METADATA_SOURCE); + if(configuratorsExtensionPoint != null) { + IExtension[] configuratorExtensions = configuratorsExtensionPoint.getExtensions(); + for(IExtension extension : configuratorExtensions) { + RegistryContributor contributor = (RegistryContributor) extension.getContributor(); + Bundle bundle = Platform.getBundle(contributor.getActualName()); + LifecycleMappingMetadataSource source = getMetadataSource(bundle); + if(source != null) { + bundleMetadataSources.add(source); + } } } } - - return sources; + return bundleMetadataSources; } private static LifecycleMappingMetadataSource getMetadataSource(Bundle bundle) { @@ -1092,4 +1087,11 @@ public class LifecycleMappingFactory { } return false; } + + /** + * @param bundleMetadataSources The bundleMetadataSources to set. + */ + public synchronized static void setBundleMetadataSources(List<LifecycleMappingMetadataSource> bundleMetadataSources) { + LifecycleMappingFactory.bundleMetadataSources = bundleMetadataSources; + } } |