summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorsnjeza2011-04-14 13:31:38 (EDT)
committer Igor Fedorenko2011-04-20 15:12:22 (EDT)
commitcd221a5336069559b6d764282b4a34393a8b2871 (patch)
tree2524a6a57083fe6283103ff6301883b1c7ad55ac
parentb8efa251e9cd9b2c65c9a02d781578b9b96b3d5c (diff)
downloadm2e-core-cd221a5336069559b6d764282b4a34393a8b2871.zip
m2e-core-cd221a5336069559b6d764282b4a34393a8b2871.tar.gz
m2e-core-cd221a5336069559b6d764282b4a34393a8b2871.tar.bz2
M2e Performance - Caching Lifecycle Metadata
Signed-off-by: snjeza <snjezana.peco@redhat.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java16
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java50
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 1187e20..1abff2b 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 874b515..59f41b8 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;
+ }
}