Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java')
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java378
1 files changed, 22 insertions, 356 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
index 4136ba9b..c5d6768f 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/MavenPlugin.java
@@ -11,396 +11,62 @@
package org.eclipse.m2e.core;
-import java.io.File;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Version;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.eclipse.core.resources.IResourceChangeEvent;
-import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
-
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.MutablePlexusContainer;
-import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.classworlds.ClassWorld;
-import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-
-import org.apache.maven.archetype.Archetype;
-import org.apache.maven.archetype.common.ArchetypeArtifactManager;
-import org.apache.maven.archetype.source.ArchetypeDataSource;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.manager.WagonManager;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.resolver.ArtifactCollector;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.index.ArtifactContextProducer;
-import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.updater.IndexUpdater;
-import org.apache.maven.plugin.LegacySupport;
-
-import org.sonatype.aether.RepositorySystem;
-
-import org.eclipse.m2e.core.archetype.ArchetypeCatalogFactory;
-import org.eclipse.m2e.core.archetype.ArchetypeManager;
-import org.eclipse.m2e.core.core.IMavenConstants;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.index.IndexManager;
-import org.eclipse.m2e.core.internal.ExtensionReader;
-import org.eclipse.m2e.core.internal.embedder.MavenEmbeddedRuntime;
-import org.eclipse.m2e.core.internal.embedder.MavenImpl;
-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.markers.IMavenMarkerManager;
-import org.eclipse.m2e.core.internal.markers.MavenMarkerManager;
-import org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl;
-import org.eclipse.m2e.core.internal.project.ProjectConfigurationManager;
-import org.eclipse.m2e.core.internal.project.WorkspaceStateWriter;
-import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager;
-import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob;
-import org.eclipse.m2e.core.internal.repository.RepositoryRegistry;
+import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.MavenProjectManager;
-import org.eclipse.m2e.core.project.MavenUpdateRequest;
import org.eclipse.m2e.core.repository.IRepositoryRegistry;
-/**
- * MavenPlugin main plug-in class.
- */
-public class MavenPlugin extends Plugin {
- private final Logger log = LoggerFactory.getLogger(MavenPlugin.class);
-
- public static final String PREFS_ARCHETYPES = "archetypesInfo.xml"; //$NON-NLS-1$
-
- // The shared instance
- private static MavenPlugin plugin;
-
- /**
- * General purpose plexus container. Contains components from maven embedder and all other bundles visible from this
- * bundle's classloader.
- */
- private MutablePlexusContainer plexus;
-
- private MavenModelManager modelManager;
-
- private NexusIndexManager indexManager;
-
- private BundleContext bundleContext;
-
- private MavenProjectManager projectManager;
+public final class MavenPlugin {
- private MavenRuntimeManager runtimeManager;
+ private static final MavenPlugin INSTANCE = new MavenPlugin();
- private ProjectConfigurationManager configurationManager;
+ private MavenPlugin() {
- private ProjectRegistryRefreshJob mavenBackgroundJob;
-
- private ArchetypeManager archetypeManager;
-
- private ProjectRegistryManager managerImpl;
-
- private IMavenMarkerManager mavenMarkerManager;
-
- private RepositoryRegistry repositoryRegistry;
-
- private String version = "0.0.0"; //$NON-NLS-1$
-
- private String qualifiedVersion = "0.0.0.qualifier"; //$NON-NLS-1$
-
- private IMavenConfiguration mavenConfiguration;
-
- private MavenImpl maven;
-
- public MavenPlugin() {
- plugin = this;
-
- if(Boolean.parseBoolean(Platform.getDebugOption(IMavenConstants.PLUGIN_ID + "/debug/initialization"))) { //$NON-NLS-1$
- System.err.println("### executing constructor " + IMavenConstants.PLUGIN_ID); //$NON-NLS-1$
- new Throwable().printStackTrace();
- }
- }
-
- public IMaven getMaven() {
- return maven;
}
/**
- * This method is called upon plug-in activation
- */
- public void start(final BundleContext context) throws Exception {
- super.start(context);
-
- if(Boolean.parseBoolean(Platform.getDebugOption(IMavenConstants.PLUGIN_ID + "/debug/initialization"))) { //$NON-NLS-1$
- System.err.println("### executing start() " + IMavenConstants.PLUGIN_ID); //$NON-NLS-1$
- new Throwable().printStackTrace();
- }
-
- this.bundleContext = context;
-
- try {
- this.qualifiedVersion = (String) getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
- Version bundleVersion = Version.parseVersion(this.qualifiedVersion);
- this.version = bundleVersion.getMajor() + "." + bundleVersion.getMinor() + "." + bundleVersion.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$
- } catch(IllegalArgumentException e) {
- // ignored
- }
-
- this.mavenConfiguration = new MavenConfigurationImpl();
-
- ClassLoader cl = MavenPlugin.class.getClassLoader();
- ContainerConfiguration cc = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", cl)) //$NON-NLS-1$
- .setName("plexus"); //$NON-NLS-1$
- this.plexus = new DefaultPlexusContainer(cc);
-
- File stateLocationDir = getStateLocation().toFile();
-
- // TODO this is broken, need to make it lazy, otherwise we'll deadlock or timeout... or both
- this.archetypeManager = newArchetypeManager(stateLocationDir);
- try {
- this.archetypeManager.readCatalogs();
- } catch(Exception ex) {
- String msg = "Can't read archetype catalog configuration";
- log.error(msg, ex);
- }
-
- this.mavenMarkerManager = new MavenMarkerManager(mavenConfiguration);
-
- boolean updateProjectsOnStartup = mavenConfiguration.isUpdateProjectsOnStartup();
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
-
- this.maven = new MavenImpl(mavenConfiguration);
-
- // TODO eagerly reads workspace state cache
- this.managerImpl = new ProjectRegistryManager(maven, stateLocationDir, !updateProjectsOnStartup /* readState */,
- mavenMarkerManager);
-
- this.mavenBackgroundJob = new ProjectRegistryRefreshJob(managerImpl, mavenConfiguration);
-
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- workspace.addResourceChangeListener(mavenBackgroundJob, IResourceChangeEvent.POST_CHANGE
- | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE);
-
- this.projectManager = new MavenProjectManager(managerImpl, mavenBackgroundJob, stateLocationDir);
- this.projectManager.addMavenProjectChangedListener(new WorkspaceStateWriter(projectManager));
- if(updateProjectsOnStartup || managerImpl.getProjects().length == 0) {
- this.projectManager.refresh(new MavenUpdateRequest(workspace.getRoot().getProjects(), //
- mavenConfiguration.isOffline() /*offline*/, false /* updateSnapshots */));
- }
-
- this.modelManager = new MavenModelManager(maven, projectManager);
-
- this.runtimeManager = new MavenRuntimeManager();
- this.runtimeManager.setEmbeddedRuntime(new MavenEmbeddedRuntime(getBundleContext()));
- this.runtimeManager.setWorkspaceRuntime(new MavenWorkspaceRuntime(projectManager));
-
- this.configurationManager = new ProjectConfigurationManager(maven, managerImpl, modelManager,
- mavenMarkerManager, mavenConfiguration);
- this.projectManager.addMavenProjectChangedListener(this.configurationManager);
- workspace.addResourceChangeListener(configurationManager, IResourceChangeEvent.PRE_DELETE);
-
- //create repository registry
- this.repositoryRegistry = new RepositoryRegistry(maven, projectManager);
- this.maven.addSettingsChangeListener(repositoryRegistry);
- this.projectManager.addMavenProjectChangedListener(repositoryRegistry);
-
- //create the index manager
- this.indexManager = new NexusIndexManager(projectManager, repositoryRegistry, stateLocationDir);
- this.projectManager.addMavenProjectChangedListener(indexManager);
- this.maven.addLocalRepositoryListener(new IndexingTransferListener(indexManager));
- this.repositoryRegistry.addRepositoryIndexer(indexManager);
- this.repositoryRegistry.addRepositoryDiscoverer(new IndexesExtensionReader(indexManager));
-
- // fork repository registry update. must after index manager registered as a listener
- this.repositoryRegistry.updateRegistry();
- }
-
- private static ArchetypeManager newArchetypeManager(File stateLocationDir) {
- ArchetypeManager archetypeManager = new ArchetypeManager(new File(stateLocationDir, PREFS_ARCHETYPES));
- archetypeManager.addArchetypeCatalogFactory(new ArchetypeCatalogFactory.NexusIndexerCatalogFactory());
- archetypeManager.addArchetypeCatalogFactory(new ArchetypeCatalogFactory.InternalCatalogFactory());
- archetypeManager.addArchetypeCatalogFactory(new ArchetypeCatalogFactory.DefaultLocalCatalogFactory());
- for(ArchetypeCatalogFactory archetypeCatalogFactory : ExtensionReader.readArchetypeExtensions()) {
- archetypeManager.addArchetypeCatalogFactory(archetypeCatalogFactory);
- }
- return archetypeManager;
- }
-
- public PlexusContainer getPlexusContainer() {
- return plexus;
- }
-
- /**
- * This method is called when the plug-in is stopped
- */
- public void stop(BundleContext context) throws Exception {
- super.stop(context);
-
- this.mavenBackgroundJob.cancel();
- try {
- this.mavenBackgroundJob.join();
- } catch(InterruptedException ex) {
- // ignored
- }
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
- workspace.removeResourceChangeListener(this.mavenBackgroundJob);
- this.mavenBackgroundJob = null;
-
- this.projectManager.removeMavenProjectChangedListener(this.configurationManager);
- this.projectManager.removeMavenProjectChangedListener(indexManager);
- this.projectManager.removeMavenProjectChangedListener(repositoryRegistry);
- this.projectManager = null;
-
- this.plexus.dispose();
- this.maven.disposeContainer();
-
- workspace.removeResourceChangeListener(configurationManager);
- this.configurationManager = null;
-
- plugin = null;
- }
-
- /**
- * Returns the shared instance.
+ * @deprecated Use static getCOMPONENT methods instead
*/
public static MavenPlugin getDefault() {
- return plugin;
- }
-
- public MavenModelManager getMavenModelManager() {
- return this.modelManager;
- }
-
- public MavenProjectManager getMavenProjectManager() {
- return this.projectManager;
- }
-
- public ProjectRegistryManager getMavenProjectManagerImpl() {
- return this.managerImpl;
- }
-
- public IndexManager getIndexManager() {
- return this.indexManager;
- }
-
- public MavenRuntimeManager getMavenRuntimeManager() {
- return this.runtimeManager;
- }
-
- public ArchetypeManager getArchetypeManager() {
- return this.archetypeManager;
- }
-
- public IMavenMarkerManager getMavenMarkerManager() {
- return this.mavenMarkerManager;
+ return INSTANCE;
}
- public IMavenConfiguration getMavenConfiguration() {
- return this.mavenConfiguration;
- }
-
- public BundleContext getBundleContext() {
- return this.bundleContext;
- }
-
- public IProjectConfigurationManager getProjectConfigurationManager() {
- return configurationManager;
- }
-
- /** for use by unit tests */
- public ProjectRegistryRefreshJob getProjectManagerRefreshJob() {
- return mavenBackgroundJob;
- }
-
- private <C> C lookup(Class<C> role) {
- try {
- return plexus.lookup(role);
- } catch(ComponentLookupException ex) {
- throw new NoSuchComponentException(ex);
- }
- }
-
- private <T> T lookup(Class<T> role, String roleHint) {
- try {
- return plexus.lookup(role, roleHint);
- } catch(ComponentLookupException ex) {
- throw new NoSuchComponentException(ex);
- }
- }
-
- public static String getVersion() {
- return plugin.version;
- }
-
- public static String getQualifiedVersion() {
- return plugin.qualifiedVersion;
- }
-
- public IRepositoryRegistry getRepositoryRegistry() {
- return repositoryRegistry;
- }
-
- public Archetype getArchetype() {
- return lookup(Archetype.class);
- }
-
- public ArchetypeDataSource getArchetypeDataSource(String hint) {
- return lookup(ArchetypeDataSource.class, hint);
- }
-
- public ArchetypeArtifactManager getArchetypeArtifactManager() {
- return lookup(ArchetypeArtifactManager.class);
- }
-
- public IndexUpdater getIndexUpdater() {
- return lookup(IndexUpdater.class);
+ public IMaven getMaven() {
+ return MavenPluginActivator.getDefault().getMaven();
}
- public WagonManager getWagonManager() {
- return lookup(WagonManager.class);
+ public static MavenProjectManager getMavenProjectManager() {
+ return MavenPluginActivator.getDefault().getMavenProjectManager();
}
- public NexusIndexer getNexusIndexer() {
- return lookup(NexusIndexer.class);
+ public static IProjectConfigurationManager getProjectConfigurationManager() {
+ return MavenPluginActivator.getDefault().getProjectConfigurationManager();
}
- public ArtifactContextProducer getArtifactContextProducer() {
- return lookup(ArtifactContextProducer.class);
+ public static IRepositoryRegistry getRepositoryRegistry() {
+ return MavenPluginActivator.getDefault().getRepositoryRegistry();
}
- public ArtifactFactory getArtifactFactory() {
- return lookup(ArtifactFactory.class);
+ public static IndexManager getIndexManager() {
+ return MavenPluginActivator.getDefault().getIndexManager();
}
- public ArtifactMetadataSource getArtifactMetadataSource() {
- return lookup(ArtifactMetadataSource.class);
+ public static IMavenConfiguration getMavenConfiguration() {
+ return MavenPluginActivator.getDefault().getMavenConfiguration();
}
- public ArtifactCollector getArtifactCollector() {
- return lookup(ArtifactCollector.class);
+ public static MavenRuntimeManager getMavenRuntimeManager() {
+ return MavenPluginActivator.getDefault().getMavenRuntimeManager();
}
- public RepositorySystem getRepositorySystem() {
- return lookup(RepositorySystem.class);
+ public static MavenModelManager getMavenModelManager() {
+ return MavenPluginActivator.getDefault().getMavenModelManager();
}
- public MavenSession setSession(MavenSession session) {
- LegacySupport legacy = lookup(LegacySupport.class);
- MavenSession old = legacy.getSession();
- legacy.setSession(session);
- return old;
- }
}

Back to the top