diff --git a/.gitmodules b/.gitmodules index d38c67bf7e..98be72d15f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "m2e-core-tests"] path = m2e-core-tests - url = https://github.com/tesla/m2e-core-tests.git - branch = master + url = https://github.com/laeubi/m2e-core-tests.git + branch = Issue_644_adjust diff --git a/org.eclipse.m2e.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.core/META-INF/MANIFEST.MF index 3e88ad05d1..030e8d9516 100644 --- a/org.eclipse.m2e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core/META-INF/MANIFEST.MF @@ -50,4 +50,19 @@ Import-Package: javax.inject;version="1.0.0", org.osgi.service.component.annotations;version="1.3.0", org.slf4j;version="1.6.2" Automatic-Module-Name: org.eclipse.m2e.core -Service-Component: OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectFacadeAdapterFactory.xml +Service-Component: OSGI-INF/org.eclipse.m2e.core.embedder.MavenModelManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.embedder.MavenImpl.xml, + OSGI-INF/org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.launch.MavenRuntimeManagerImpl.xml, + OSGI-INF/org.eclipse.m2e.core.internal.markers.MavenMarkerManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceClassifierResolverManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceStateWriter.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectFacadeAdapterFactory.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryReader.xml, + OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob.xml, + OSGI-INF/org.eclipse.m2e.core.internal.repository.RepositoryRegistry.xml diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.embedder.MavenModelManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.embedder.MavenModelManager.xml new file mode 100644 index 0000000000..b4c25f46eb --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.embedder.MavenModelManager.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.embedder.MavenImpl.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.embedder.MavenImpl.xml new file mode 100644 index 0000000000..5bc5092a10 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.embedder.MavenImpl.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager.xml new file mode 100644 index 0000000000..83b4891f0f --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.launch.MavenRuntimeManagerImpl.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.launch.MavenRuntimeManagerImpl.xml new file mode 100644 index 0000000000..787e915208 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.launch.MavenRuntimeManagerImpl.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.markers.MavenMarkerManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.markers.MavenMarkerManager.xml new file mode 100644 index 0000000000..ab62a60cd1 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.markers.MavenMarkerManager.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl.xml new file mode 100644 index 0000000000..197264fc58 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.preferences.MavenConfigurationImpl.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.xml new file mode 100644 index 0000000000..abeb0ac9be --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceClassifierResolverManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceClassifierResolverManager.xml new file mode 100644 index 0000000000..ca486176d2 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceClassifierResolverManager.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceStateWriter.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceStateWriter.xml new file mode 100644 index 0000000000..c6250e37c6 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.WorkspaceStateWriter.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager.xml new file mode 100644 index 0000000000..591bdf6df1 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.xml new file mode 100644 index 0000000000..e56ddb69d8 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.MavenProjectManager.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.xml new file mode 100644 index 0000000000..bbd995d754 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryReader.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryReader.xml new file mode 100644 index 0000000000..6498368705 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryReader.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob.xml new file mode 100644 index 0000000000..45fe05e70f --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.project.registry.ProjectRegistryRefreshJob.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.repository.RepositoryRegistry.xml b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.repository.RepositoryRegistry.xml new file mode 100644 index 0000000000..fbb3268ac5 --- /dev/null +++ b/org.eclipse.m2e.core/OSGI-INF/org.eclipse.m2e.core.internal.repository.RepositoryRegistry.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java index a40071ae63..d7262ba30a 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java @@ -377,4 +377,11 @@ V execute(boolean offline, boolean forceDependencyUpdate, ICallable calla * @since 1.10 */ T lookup(Class clazz) throws CoreException; + + /** + * @param + * @param clazz + * @return + */ + T lookupComponent(Class clazz); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenModelManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenModelManager.java index 46167210b3..da0f6fbf7a 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenModelManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/MavenModelManager.java @@ -31,6 +31,8 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,17 +83,15 @@ * * @author Eugene Kuleshov XXX fix circular dependency */ +@Component(service = {MavenModelManager.class}) public class MavenModelManager { private static final Logger log = LoggerFactory.getLogger(MavenModelManager.class); - private final IMavenProjectRegistry projectManager; + @Reference + private IMavenProjectRegistry projectManager; - private final IMaven maven; - - public MavenModelManager(IMaven maven, IMavenProjectRegistry projectManager) { - this.maven = maven; - this.projectManager = projectManager; - } + @Reference + private IMaven maven; public org.apache.maven.model.Model readMavenModel(InputStream reader) throws CoreException { return maven.readModel(reader); 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 fb513d6ae4..49b3c69030 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 @@ -15,23 +15,20 @@ import java.io.File; import java.util.Collection; -import java.util.Dictionary; import java.util.HashSet; -import java.util.Hashtable; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleListener; import org.osgi.framework.Constants; import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.Version; import org.osgi.service.url.URLConstants; import org.osgi.service.url.URLStreamHandlerService; import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,12 +37,6 @@ import com.google.inject.Module; import org.eclipse.aether.RepositorySystem; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.ISaveContext; -import org.eclipse.core.resources.ISaveParticipant; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; @@ -63,29 +54,20 @@ import org.apache.maven.project.DefaultProjectBuilder; import org.apache.maven.repository.legacy.WagonManager; +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.internal.archetype.ArchetypeCatalogFactory; import org.eclipse.m2e.core.internal.archetype.ArchetypeManager; -import org.eclipse.m2e.core.internal.embedder.MavenImpl; import org.eclipse.m2e.core.internal.index.filter.ArtifactFilterManager; import org.eclipse.m2e.core.internal.launch.MavenRuntimeManagerImpl; 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; -import org.eclipse.m2e.core.internal.project.ProjectConfigurationManager; -import org.eclipse.m2e.core.internal.project.WorkspaceClassifierResolverManager; -import org.eclipse.m2e.core.internal.project.WorkspaceStateWriter; -import org.eclipse.m2e.core.internal.project.conversion.ProjectConversionManager; -import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; 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.project.IMavenProjectRegistry; import org.eclipse.m2e.core.project.IProjectConfigurationManager; import org.eclipse.m2e.core.project.IWorkspaceClassifierResolverManager; -import org.eclipse.m2e.core.project.MavenUpdateRequest; import org.eclipse.m2e.core.project.conversion.IProjectConversionManager; import org.eclipse.m2e.core.repository.IRepositoryRegistry; @@ -100,65 +82,17 @@ public class MavenPluginActivator extends Plugin { private final Collection toDisposeContainers = new HashSet<>(); - private MavenModelManager modelManager; - private BundleContext bundleContext; - private MavenProjectManager projectManager; - - private MavenRuntimeManagerImpl runtimeManager; - - private ProjectConfigurationManager configurationManager; - - private ProjectRegistryRefreshJob mavenBackgroundJob; - private ArchetypeManager archetypeManager; - private ProjectRegistryManager managerImpl; - - private IMavenMarkerManager mavenMarkerManager; - - private RepositoryRegistry repositoryRegistry; - - private ArtifactFilterManager artifactFilterManager; - private String version = "0.0.0"; //$NON-NLS-1$ - private IMavenConfiguration mavenConfiguration; - private final BundleListener bundleListener = event -> LifecycleMappingFactory.setBundleMetadataSources(null); - private final ISaveParticipant saveParticipant = new ISaveParticipant() { - - @Override - public void saving(ISaveContext context) { - if(managerImpl != null) { - managerImpl.writeWorkspaceState(); - } - } - - @Override - public void rollback(ISaveContext context) { - } - - @Override - public void prepareToSave(ISaveContext context) { - } - - @Override - public void doneSaving(ISaveContext context) { - } - }; - - private MavenImpl maven; - - private IProjectConversionManager projectConversionManager; - - private IWorkspaceClassifierResolverManager workspaceClassifierResolverManager; - private ServiceRegistration protocolHandlerService; - private ServiceTracker workspaceTracker; + private Map, ServiceTracker> trackers = new ConcurrentHashMap<>(); public MavenPluginActivator() { plugin = this; @@ -169,8 +103,24 @@ public MavenPluginActivator() { } } - public MavenImpl getMaven() { - return maven; + public IMaven getMaven() { + return getService(IMaven.class); + } + + /** + * @param class1 + * @return + */ + private T getService(Class service) { + BundleContext context = getBundleContext(); + if(context == null) { + return null; + } + return service.cast(trackers.computeIfAbsent(service, key -> { + ServiceTracker tracker = new ServiceTracker<>(context, key, null); + tracker.open(); + return tracker; + }).getService()); } /** @@ -179,18 +129,10 @@ public MavenImpl getMaven() { @Override 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(); + Thread.dumpStack(); } - // Workaround MNG-6530 - System.setProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, Boolean.toString(true)); - - URLConnectionCaches.disable(); - - this.bundleContext = context; - try { Version bundleVersion = getBundle().getVersion(); this.version = bundleVersion.getMajor() + "." + bundleVersion.getMinor() + "." + bundleVersion.getMicro(); //$NON-NLS-1$ //$NON-NLS-2$ @@ -198,88 +140,11 @@ public void start(final BundleContext context) throws Exception { // ignored } - this.mavenConfiguration = new MavenConfigurationImpl(); - File stateLocationDir = getStateLocation().toFile(); - - 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); - - context.registerService(IResourceChangeListener.class, mavenBackgroundJob, getMaskProperties( - IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE)); - - this.projectManager = new MavenProjectManager(managerImpl, mavenBackgroundJob, stateLocationDir); - this.projectManager.addMavenProjectChangedListener(new WorkspaceStateWriter(projectManager)); - workspaceTracker = new ServiceTracker<>(bundleContext, IWorkspace.class, - new ServiceTrackerCustomizer() { - - @Override - public IWorkspace addingService(ServiceReference reference) { - //TODO there should be a declarative way to do this! - IWorkspace workspace = bundleContext.getService(reference); - if(workspace != null) { - try { - workspace.addSaveParticipant(IMavenConstants.PLUGIN_ID, saveParticipant); - } catch(CoreException ex) { - getLog().log(ex.getStatus()); - } - } - return workspace; - } - - @Override - public void modifiedService(ServiceReference reference, IWorkspace workspace) { - //we don't care about property changes - } - - @Override - public void removedService(ServiceReference reference, IWorkspace workspace) { - workspace.removeSaveParticipant(IMavenConstants.PLUGIN_ID); - } - }); - workspaceTracker.open(); - if(updateProjectsOnStartup || managerImpl.getProjects().length == 0) { - IWorkspace workspace = workspaceTracker.getService(); - if(workspace != null) { - this.projectManager.refresh(new MavenUpdateRequest(workspace.getRoot().getProjects(), // - mavenConfiguration.isOffline() /*offline*/, false /* updateSnapshots */)); - } - } - - this.modelManager = new MavenModelManager(maven, projectManager); - - this.runtimeManager = new MavenRuntimeManagerImpl(); - - this.configurationManager = new ProjectConfigurationManager(maven, managerImpl, modelManager, mavenMarkerManager, - mavenConfiguration); - this.projectManager.addMavenProjectChangedListener(this.configurationManager); - context.registerService(IResourceChangeListener.class, configurationManager, - getMaskProperties(IResourceChangeEvent.PRE_DELETE)); - - //create repository registry - this.repositoryRegistry = new RepositoryRegistry(maven, projectManager); - this.maven.addSettingsChangeListener(repositoryRegistry); - this.projectManager.addMavenProjectChangedListener(repositoryRegistry); - - // - this.artifactFilterManager = new ArtifactFilterManager(); - - // fork repository registry update. must after index manager registered as a listener - this.repositoryRegistry.updateRegistry(); - - this.projectConversionManager = new ProjectConversionManager(); - - this.workspaceClassifierResolverManager = new WorkspaceClassifierResolverManager(); + // Workaround MNG-6530 + System.setProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, Boolean.toString(true)); + URLConnectionCaches.disable(); + // For static access, this also enables any of the services and keep them running forever... + this.bundleContext = context; //register URL handler, we can't use DS here because this triggers loading of m2e too early Map properties = Map.of(URLConstants.URL_HANDLER_PROTOCOL, new String[] {"mvn"}); this.protocolHandlerService = context.registerService(URLStreamHandlerService.class, @@ -288,14 +153,6 @@ public void removedService(ServiceReference reference, IWorkspace wo // Automatically delete now obsolete nexus cache (can be removed again if some time has passed and it is unlikely an old workspace that need to be cleaned up is used). IPath nexusCache = Platform.getStateLocation(context.getBundle()).append("nexus"); FileUtils.deleteDirectory(nexusCache.toFile()); - //register as service to make static method access obsolete... - bundleContext.registerService(IMavenProjectRegistry.class, projectManager, null); - } - - private static Dictionary getMaskProperties(int mask) { - Dictionary properties = new Hashtable<>(); - properties.put("event.mask", mask); - return properties; } private DefaultPlexusContainer newPlexusContainer(ClassLoader cl) throws PlexusContainerException { @@ -323,22 +180,6 @@ private static ArchetypeManager newArchetypeManager(PlexusContainer container, F return archetypeManager; } - /** - * @deprecated provided for backwards compatibility only. all component lookup must go though relevant subsystem -- - * {@link MavenImpl}, {@link NexusIndexManager} or {@link ArchetypeManager}. - *

- * In most case, use MavenPlugin.getMaven().lookup(...) instead. - */ - @Deprecated - public PlexusContainer getPlexusContainer() { - try { - return getMaven().getPlexusContainer(); - } catch(CoreException ex) { - getLog().log(ex.getStatus()); - return null; - } - } - /** * This method is called when the plug-in is stopped */ @@ -350,27 +191,10 @@ public void stop(BundleContext context) throws Exception { } context.removeBundleListener(bundleListener); - this.mavenBackgroundJob.cancel(); - try { - this.mavenBackgroundJob.join(); - } catch(InterruptedException ex) { - // ignored - } - workspaceTracker.close(); - this.mavenBackgroundJob = null; - - this.projectManager.removeMavenProjectChangedListener(this.configurationManager); - this.projectManager.removeMavenProjectChangedListener(repositoryRegistry); - this.projectManager = null; - toDisposeContainers.forEach(PlexusContainer::dispose); - this.maven.disposeContainer(); - this.configurationManager = null; LifecycleMappingFactory.setBundleMetadataSources(null); - this.projectConversionManager = null; - plugin = null; } @@ -382,19 +206,19 @@ public static MavenPluginActivator getDefault() { } public MavenModelManager getMavenModelManager() { - return this.modelManager; + return getService(MavenModelManager.class); } - public MavenProjectManager getMavenProjectManager() { - return this.projectManager; + public IMavenProjectRegistry getMavenProjectManager() { + return getService(IMavenProjectRegistry.class); } public ProjectRegistryManager getMavenProjectManagerImpl() { - return this.managerImpl; + return getService(ProjectRegistryManager.class); } public MavenRuntimeManagerImpl getMavenRuntimeManager() { - return this.runtimeManager; + return getService(MavenRuntimeManagerImpl.class); } public ArchetypeManager getArchetypeManager() { @@ -419,11 +243,11 @@ public ArchetypeManager getArchetypeManager() { } public IMavenMarkerManager getMavenMarkerManager() { - return this.mavenMarkerManager; + return getService(IMavenMarkerManager.class); } public IMavenConfiguration getMavenConfiguration() { - return this.mavenConfiguration; + return getService(IMavenConfiguration.class); } public BundleContext getBundleContext() { @@ -431,12 +255,12 @@ public BundleContext getBundleContext() { } public IProjectConfigurationManager getProjectConfigurationManager() { - return configurationManager; + return getService(IProjectConfigurationManager.class); } /** for use by unit tests */ public ProjectRegistryRefreshJob getProjectManagerRefreshJob() { - return mavenBackgroundJob; + return getService(ProjectRegistryRefreshJob.class); } public static String getVersion() { @@ -452,30 +276,30 @@ public static String getUserAgent() { } public IRepositoryRegistry getRepositoryRegistry() { - return repositoryRegistry; + return getService(IRepositoryRegistry.class); } public WagonManager getWagonManager() { - return maven.lookupComponent(WagonManager.class); + return getMaven().lookupComponent(WagonManager.class); } public RepositorySystem getRepositorySystem() { - return maven.lookupComponent(RepositorySystem.class); + return getMaven().lookupComponent(RepositorySystem.class); } public ArtifactFilterManager getArifactFilterManager() { - return artifactFilterManager; + return getService(ArtifactFilterManager.class); } /** * @return */ public IProjectConversionManager getProjectConversionManager() { - return projectConversionManager; + return getService(IProjectConversionManager.class); } public IWorkspaceClassifierResolverManager getWorkspaceClassifierResolverManager() { - return workspaceClassifierResolverManager; + return getService(IWorkspaceClassifierResolverManager.class); } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MvnProtocolHandlerService.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MvnProtocolHandlerService.java index c528308936..f4fc76ff64 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MvnProtocolHandlerService.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MvnProtocolHandlerService.java @@ -47,6 +47,7 @@ import org.eclipse.m2e.core.embedder.IMavenExecutionContext; +//@Component(service = URLStreamHandlerService.class, property = URLConstants.URL_HANDLER_PROTOCOL + "=mvn", immediate = true) public class MvnProtocolHandlerService extends AbstractURLStreamHandlerService { public MvnProtocolHandlerService() { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java index 578d5ca340..bfc510e175 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilder.java @@ -40,7 +40,6 @@ import org.eclipse.m2e.core.internal.IMavenConstants; import org.eclipse.m2e.core.internal.M2EUtils; import org.eclipse.m2e.core.internal.MavenPluginActivator; -import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext; import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager; import org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager; import org.eclipse.m2e.core.project.IMavenProjectFacade; @@ -83,7 +82,7 @@ public final T execute(final int kind, final Map args, IProgress return null; } - final MavenExecutionContext context = projectManager.createExecutionContext(pomResource, resolverConfiguration); + final IMavenExecutionContext context = projectManager.createExecutionContext(pomResource, resolverConfiguration); return context.execute((context2, monitor2) -> { final IMavenProjectFacade projectFacade = getProjectFacade(project, monitor2); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java index 04a4cb2169..335a410275 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenImpl.java @@ -37,6 +37,9 @@ import java.util.Properties; import java.util.Set; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -172,6 +175,7 @@ import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants; +@Component(service = {IMaven.class, IMavenConfigurationChangeListener.class}) public class MavenImpl implements IMaven, IMavenConfigurationChangeListener { private static final Logger log = LoggerFactory.getLogger(MavenImpl.class); @@ -182,7 +186,8 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener { private DefaultPlexusContainer plexus; - private final IMavenConfiguration mavenConfiguration; + @Reference + private IMavenConfiguration mavenConfiguration; private final ConverterLookup converterLookup = new DefaultConverterLookup(); @@ -201,11 +206,6 @@ public class MavenImpl implements IMaven, IMavenConfigurationChangeListener { /** Last modified timestamp of cached user settings */ private long settings_timestamp; - public MavenImpl(IMavenConfiguration mavenConfiguration) { - this.mavenConfiguration = mavenConfiguration; - mavenConfiguration.addConfigurationChangeListener(this); - } - @Override @SuppressWarnings("deprecation") @Deprecated @@ -1336,6 +1336,7 @@ public T lookup(Class clazz) throws CoreException { /** * @since 1.5 */ + @Override public T lookupComponent(Class clazz) { try { return getPlexusContainer0().lookup(clazz); @@ -1379,6 +1380,7 @@ protected void configure() { return new DefaultPlexusContainer(mavenCoreCC, logginModule, new ExtensionModule(), coreExportsModule); } + @Deactivate public synchronized void disposeContainer() { if(plexus != null) { plexus.dispose(); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java index 9d5dbf8261..bdd58f1f9b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/filter/ArtifactFilterManager.java @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.List; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +39,7 @@ * * @author igor */ +@Component(service = {ArtifactFilterManager.class}) public class ArtifactFilterManager { private static final Logger log = LoggerFactory.getLogger(ArtifactFilterManager.class); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenRuntimeManagerImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenRuntimeManagerImpl.java index de635fb6f3..11d1cff32b 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenRuntimeManagerImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenRuntimeManagerImpl.java @@ -20,10 +20,11 @@ import java.util.Map; import java.util.Set; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.osgi.service.prefs.BackingStoreException; import org.osgi.service.prefs.Preferences; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IPreferencesService; @@ -36,6 +37,7 @@ /** * @since 1.5 */ +@Component(service = MavenRuntimeManagerImpl.class) public class MavenRuntimeManagerImpl { public static final String DEFAULT = "DEFAULT"; //$NON-NLS-1$ @@ -47,10 +49,10 @@ public class MavenRuntimeManagerImpl { private final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; - private final IPreferencesService preferenceStore; + @Reference + private IPreferencesService preferenceStore; public MavenRuntimeManagerImpl() { - this.preferenceStore = Platform.getPreferencesService(); this.preferencesLookup[0] = InstanceScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); this.preferencesLookup[1] = DefaultScope.INSTANCE.getNode(IMavenConstants.PLUGIN_ID); } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java index f5b8804911..cf6c9eb7d1 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/markers/MavenMarkerManager.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.Set; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,15 +49,14 @@ import org.eclipse.m2e.core.internal.Messages; +@Component(service = {IMavenMarkerManager.class}) public class MavenMarkerManager implements IMavenMarkerManager { private static Logger log = LoggerFactory.getLogger(MavenMarkerManager.class); - private final IMavenConfiguration mavenConfiguration; + @Reference + private IMavenConfiguration mavenConfiguration; - public MavenMarkerManager(IMavenConfiguration mavenConfiguration) { - this.mavenConfiguration = mavenConfiguration; - } @Override public void addMarkers(IResource pomResource, String type, MavenExecutionResult result) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java index 2ce60d26d7..26f658f0ac 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/preferences/MavenConfigurationImpl.java @@ -15,6 +15,11 @@ import java.util.Map; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; import org.osgi.service.prefs.BackingStoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +28,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.ListenerList; -import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.INodeChangeListener; @@ -45,21 +49,17 @@ import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; +@Component(service = {IMavenConfiguration.class}) public class MavenConfigurationImpl implements IMavenConfiguration, IPreferenceChangeListener, INodeChangeListener { private static final Logger log = LoggerFactory.getLogger(MavenConfigurationImpl.class); private final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2]; - private final IPreferencesService preferenceStore; + @Reference + private IPreferencesService preferenceStore; private final ListenerList listeners = new ListenerList<>(ListenerList.IDENTITY); - public MavenConfigurationImpl() { - preferenceStore = Platform.getPreferencesService(); - - init(); - } - private boolean exists(IEclipsePreferences preferenceNode) { if(preferenceNode == null) { return false; @@ -72,7 +72,8 @@ private boolean exists(IEclipsePreferences preferenceNode) { } } - private void init() { + @Activate + void init() { if(exists(preferencesLookup[0])) { ((IEclipsePreferences) preferencesLookup[0].parent()).removeNodeChangeListener(this); preferencesLookup[0].removePreferenceChangeListener(this); @@ -189,11 +190,16 @@ public boolean isUpdateIndexesOnStartup() { .parseBoolean(preferenceStore.get(MavenPreferenceConstants.P_UPDATE_INDEXES, null, preferencesLookup)); } + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) @Override public synchronized void addConfigurationChangeListener(IMavenConfigurationChangeListener listener) { this.listeners.add(listener); } + public synchronized void removeConfigurationChangeListener(IMavenConfigurationChangeListener listener) { + this.listeners.remove(listener); + } + @Override public void preferenceChange(PreferenceChangeEvent event) { MavenConfigurationChangeEvent mavenEvent = new MavenConfigurationChangeEvent(event.getKey(), event.getNewValue(), diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java index 1eb158f337..dd0bdd6745 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java @@ -31,6 +31,8 @@ import java.util.Properties; import java.util.Set; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,7 +82,6 @@ import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.internal.Messages; import org.eclipse.m2e.core.internal.embedder.AbstractRunnable; -import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; import org.eclipse.m2e.core.internal.markers.IMavenMarkerManager; import org.eclipse.m2e.core.internal.preferences.ProblemSeverity; @@ -107,29 +108,26 @@ * * @author igor */ +@Component(service = {IProjectConfigurationManager.class, IMavenProjectChangedListener.class, + IResourceChangeListener.class}, property = "event.mask:Integer=" + IResourceChangeEvent.PRE_DELETE) public class ProjectConfigurationManager implements IProjectConfigurationManager, IMavenProjectChangedListener, IResourceChangeListener { /*package*/static final Logger log = LoggerFactory.getLogger(ProjectConfigurationManager.class); - final ProjectRegistryManager projectManager; + @Reference + ProjectRegistryManager projectManager; - final MavenModelManager mavenModelManager; + @Reference + MavenModelManager mavenModelManager; - final IMavenMarkerManager mavenMarkerManager; + @Reference + IMavenMarkerManager mavenMarkerManager; - final IMaven maven; + @Reference + IMaven maven; - final IMavenConfiguration mavenConfiguration; - - public ProjectConfigurationManager(IMaven maven, ProjectRegistryManager projectManager, - MavenModelManager mavenModelManager, IMavenMarkerManager mavenMarkerManager, - IMavenConfiguration mavenConfiguration) { - this.projectManager = projectManager; - this.mavenModelManager = mavenModelManager; - this.mavenMarkerManager = mavenMarkerManager; - this.maven = maven; - this.mavenConfiguration = mavenConfiguration; - } + @Reference + IMavenConfiguration mavenConfiguration; @Override public List importProjects(Collection projectInfos, @@ -503,7 +501,7 @@ private void updateProjectConfiguration(final ProjectConfigurationRequest reques log.debug("Setting encoding for project {}: {}", project.getName(), sourceEncoding); //$NON-NLS-1$ project.setDefaultCharset(sourceEncoding, monitor); - MavenExecutionContext executionContext = projectManager.createExecutionContext(mavenProjectFacade.getPom(), + IMavenExecutionContext executionContext = projectManager.createExecutionContext(mavenProjectFacade.getPom(), mavenProjectFacade.getResolverConfiguration()); executionContext.execute(mavenProject, (context, monitor1) -> { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceClassifierResolverManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceClassifierResolverManager.java index 591fe50f65..1c634ef026 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceClassifierResolverManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceClassifierResolverManager.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,6 +36,7 @@ * @author atanasenko * @since 1.9 */ +@Component(service = IWorkspaceClassifierResolverManager.class) public class WorkspaceClassifierResolverManager implements IWorkspaceClassifierResolverManager { protected static final Logger log = LoggerFactory.getLogger(WorkspaceClassifierResolverManager.class); diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java index e1e94127a1..b718c75d33 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/WorkspaceStateWriter.java @@ -16,14 +16,16 @@ import java.io.File; import java.io.IOException; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; @@ -42,23 +44,26 @@ /** * Maintains map file of maven artifacts present in workspace. */ + +@Component(service = {IMavenProjectChangedListener.class}) public class WorkspaceStateWriter implements IMavenProjectChangedListener { private static QualifiedName PPROP_EXTENSION = new QualifiedName(WorkspaceStateWriter.class.getName(), "extension"); //$NON-NLS-1$ private static final Logger log = LoggerFactory.getLogger(WorkspaceStateWriter.class); - private final MavenProjectManager projectManager; + @Reference + private MavenProjectManager projectManager; + + @Reference + private IWorkspace workspace; - public WorkspaceStateWriter(MavenProjectManager projectManager) { - this.projectManager = projectManager; - } @Override public void mavenProjectChanged(MavenProjectChangedEvent[] events, IProgressMonitor monitor) { try { MutableWorkspaceState state = new MutableWorkspaceState(); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IWorkspaceRoot root = workspace.getRoot(); for(IMavenProjectFacade projectFacade : projectManager.getProjects()) { IProject project = projectFacade.getProject(); if(!project.isAccessible()) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java index 55aaf554da..3f29368c92 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/conversion/ProjectConversionManager.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,6 +56,7 @@ * @author Fred Bricon * @since 1.1 */ +@Component(service = IProjectConversionManager.class) public class ProjectConversionManager implements IProjectConversionManager { private static final String CONVERSION_PARTICIPANTS_EXTENSION_POINT = "org.eclipse.m2e.core.projectConversionParticipants"; diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectManager.java index ec86f57513..95c1be99a9 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectManager.java @@ -16,20 +16,28 @@ import java.io.File; import java.util.Collection; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; - -import org.apache.maven.execution.MavenExecutionRequest; +import org.eclipse.core.runtime.Platform; import org.eclipse.m2e.core.embedder.ICallable; -import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; +import org.eclipse.m2e.core.embedder.IMavenExecutionContext; import org.eclipse.m2e.core.project.IMavenProjectChangedListener; import org.eclipse.m2e.core.project.IMavenProjectFacade; import org.eclipse.m2e.core.project.IMavenProjectRegistry; import org.eclipse.m2e.core.project.MavenUpdateRequest; -import org.eclipse.m2e.core.project.ResolverConfiguration; /** @@ -37,20 +45,34 @@ * dependency between ProjectRegistryRefreshJob and ProjectRegistryManager. Otherwise, all requests are forwarded to * ProjectRegistryManager as is. */ +@Component(service = {IMavenProjectRegistry.class}) public class MavenProjectManager implements IMavenProjectRegistry { public static final String STATE_FILENAME = "workspacestate.properties"; //$NON-NLS-1$ - private final ProjectRegistryManager manager; + @Reference + private ProjectRegistryManager manager; + + @Reference + private ProjectRegistryRefreshJob mavenBackgroundJob; + + @Reference + private IMavenConfiguration configuration; - private final ProjectRegistryRefreshJob mavenBackgroundJob; + @Reference + private IWorkspace workspace; - private final File workspaceStateFile; + private File workspaceStateFile; - public MavenProjectManager(ProjectRegistryManager manager, ProjectRegistryRefreshJob mavenBackgroundJob, - File stateLocation) { - this.manager = manager; - this.mavenBackgroundJob = mavenBackgroundJob; - this.workspaceStateFile = new File(stateLocation, STATE_FILENAME); + @Activate + void init(BundleContext bundleContext) { + IPath result = Platform.getStateLocation(bundleContext.getBundle()); + File bundleStateLocation = result.toFile(); + this.workspaceStateFile = new File(bundleStateLocation, STATE_FILENAME); + boolean updateProjectsOnStartup = configuration.isUpdateProjectsOnStartup(); + if(updateProjectsOnStartup || manager.getProjects().length == 0) { + refresh(new MavenUpdateRequest(workspace.getRoot().getProjects(), // + configuration.isOffline() /*offline*/, false /* updateSnapshots */)); + } } // Maven projects @@ -60,18 +82,12 @@ public void refresh(MavenUpdateRequest request) { mavenBackgroundJob.refresh(request); } - @Override - @SuppressWarnings("deprecation") - @Deprecated - public void refresh(MavenUpdateRequest request, IProgressMonitor monitor) throws CoreException { - manager.refresh(request, monitor); - } - @Override public void refresh(Collection pomFiles, IProgressMonitor monitor) throws CoreException { manager.refresh(pomFiles, monitor); } + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) @Override public void addMavenProjectChangedListener(IMavenProjectChangedListener listener) { manager.addMavenProjectChangedListener(listener); @@ -110,29 +126,15 @@ public IMavenProjectFacade getMavenProject(String groupId, String artifactId, St } public File getWorkspaceStateFile() { + //FIXME this is more a property of the WorkspaceStateWriter! return workspaceStateFile; } - @Override - @SuppressWarnings("deprecation") - @Deprecated - public MavenExecutionRequest createExecutionRequest(IFile pom, ResolverConfiguration resolverConfiguration, - IProgressMonitor monitor) throws CoreException { - return manager.createExecutionRequest(pom, resolverConfiguration, monitor); - } - - @Override - @SuppressWarnings("deprecation") - @Deprecated - public MavenExecutionRequest createExecutionRequest(IMavenProjectFacade project, IProgressMonitor monitor) - throws CoreException { - return createExecutionRequest(project.getPom(), project.getResolverConfiguration(), monitor); - } - @Override public V execute(final IMavenProjectFacade facade, final ICallable callable, IProgressMonitor monitor) throws CoreException { - MavenExecutionContext context = manager.createExecutionContext(facade.getPom(), facade.getResolverConfiguration()); - return context.execute((context1, monitor1) -> context1.execute(facade.getMavenProject(monitor1), callable, monitor1), monitor); + IMavenExecutionContext context = manager.createExecutionContext(facade.getPom(), facade.getResolverConfiguration()); + return context.execute( + (context1, monitor1) -> context1.execute(facade.getMavenProject(monitor1), callable, monitor1), monitor); } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java index a284c878c9..a05569bfef 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryManager.java @@ -36,6 +36,11 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.component.annotations.ReferenceCardinality; +import org.osgi.service.component.annotations.ReferencePolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +48,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ISaveContext; +import org.eclipse.core.resources.ISaveParticipant; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -56,8 +64,6 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.osgi.util.NLS; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - import org.apache.maven.artifact.repository.MavenArtifactRepository; import org.apache.maven.execution.DefaultMavenExecutionResult; import org.apache.maven.execution.MavenExecutionRequest; @@ -82,6 +88,7 @@ import org.eclipse.m2e.core.embedder.ICallable; import org.eclipse.m2e.core.embedder.ILocalRepositoryListener; import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.embedder.IMavenConfiguration; import org.eclipse.m2e.core.embedder.IMavenExecutionContext; import org.eclipse.m2e.core.internal.ExtensionReader; import org.eclipse.m2e.core.internal.IMavenConstants; @@ -89,7 +96,6 @@ import org.eclipse.m2e.core.internal.URLConnectionCaches; import org.eclipse.m2e.core.internal.builder.MavenBuilder; import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext; -import org.eclipse.m2e.core.internal.embedder.MavenImpl; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory; import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingResult; import org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata; @@ -112,7 +118,8 @@ * This class keeps track of all maven projects present in the workspace and provides mapping between Maven and the * workspace. */ -public class ProjectRegistryManager { +@Component(service = ProjectRegistryManager.class) +public class ProjectRegistryManager implements ISaveParticipant { static final Logger log = LoggerFactory.getLogger(ProjectRegistryManager.class); static final String ARTIFACT_TYPE_POM = "pom"; //$NON-NLS-1$ @@ -139,13 +146,19 @@ public class ProjectRegistryManager { private static final String CTX_MAVENPROJECTS = ProjectRegistryManager.class.getName() + "/mavenProjects"; - private final ProjectRegistry projectRegistry; + private ProjectRegistry projectRegistry; + + @Reference + /*package*/ IMaven maven; - /*package*/final MavenImpl maven; + @Reference + /*package*/IMavenMarkerManager markerManager; - /*package*/final IMavenMarkerManager markerManager; + @Reference + private IMavenConfiguration configuration; - private final ProjectRegistryReader stateReader; + @Reference + private ProjectRegistryReader stateReader; private final Set projectChangeListeners = new LinkedHashSet<>(); @@ -163,17 +176,21 @@ public class ProjectRegistryManager { */ Consumer> addContextProjectListener; - public ProjectRegistryManager(MavenImpl maven, File stateLocationDir, boolean readState, - IMavenMarkerManager mavenMarkerManager) { - this.markerManager = mavenMarkerManager; - this.maven = maven; - - this.stateReader = new ProjectRegistryReader(stateLocationDir); + public ProjectRegistryManager() { + this.mavenProjectCache = createProjectCache(); + } - ProjectRegistry state = readState && stateReader != null ? stateReader.readWorkspaceState(this) : null; + @Activate + void init() { + //TODO this should really happen in the background! + ProjectRegistry state; + if(configuration.isUpdateProjectsOnStartup()) { + state = null; + } else { + state = stateReader.readWorkspaceState(this); + } this.projectRegistry = (state != null && state.isValid()) ? state : new ProjectRegistry(); - this.mavenProjectCache = createProjectCache(); } /** @@ -284,7 +301,7 @@ public void refresh(final MavenUpdateRequest request, final IProgressMonitor mon } private boolean isForceDependencyUpdate() throws CoreException { - MavenExecutionContext context = maven.getExecutionContext(); + IMavenExecutionContext context = maven.getExecutionContext(); return context != null && context.getExecutionRequest().isUpdateSnapshots(); } @@ -779,6 +796,7 @@ private Set refreshWorkspaceModules(MutableProjectRegistry state, IFile p return state.removeWorkspaceModules(pom, mavenProject); } + @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) public void addMavenProjectChangedListener(IMavenProjectChangedListener listener) { synchronized(projectChangeListeners) { projectChangeListeners.add(listener); @@ -1009,14 +1027,14 @@ private V execute(final IProjectRegistry state, final IFile pom, return createExecutionContext(state, pom, resolverConfiguration).execute(callable, monitor); } - private MavenExecutionContext createExecutionContext(final IProjectRegistry state, final IFile pom, + private IMavenExecutionContext createExecutionContext(final IProjectRegistry state, final IFile pom, final ResolverConfiguration resolverConfiguration) throws CoreException { - MavenExecutionContext context = maven.createExecutionContext(); + IMavenExecutionContext context = maven.createExecutionContext(); configureExecutionRequest(context.getExecutionRequest(), state, pom, resolverConfiguration); return context; } - public MavenExecutionContext createExecutionContext(final IFile pom, + public IMavenExecutionContext createExecutionContext(final IFile pom, final ResolverConfiguration resolverConfiguration) throws CoreException { return createExecutionContext(projectRegistry, pom, resolverConfiguration); } @@ -1162,10 +1180,8 @@ private Set flushMavenCaches(File pom, ArtifactKey key, boolean force) { private Set flushMavenCache(Class clazz, File pom, ArtifactKey key, boolean force) { try { - IManagedCache cache = (IManagedCache) maven.getPlexusContainer().lookup(clazz); + IManagedCache cache = (IManagedCache) maven.lookup(clazz); return cache.removeProject(pom, key, force); - } catch(ComponentLookupException ex) { - // can't really happen } catch(CoreException ex) { // can't really happen } @@ -1190,4 +1206,34 @@ private static File getRemoteFile(IFile file) { return null; } } + + @Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL) + void setWorkspace(IWorkspace workspace) throws CoreException { + //TODO better be declarative see https://github.com/eclipse-platform/eclipse.platform.resources/issues/55 + workspace.addSaveParticipant(IMavenConstants.PLUGIN_ID, this); + } + + void unsetWorkspace(IWorkspace workspace) { + workspace.removeSaveParticipant(IMavenConstants.PLUGIN_ID); + } + + @Override + public void doneSaving(ISaveContext context) { + + } + + @Override + public void prepareToSave(ISaveContext context) { + + } + + @Override + public void rollback(ISaveContext context) { + + } + + @Override + public void saving(ISaveContext context) { + writeWorkspaceState(); + } } diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java index c4d9221eb1..994c3ad261 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryReader.java @@ -24,9 +24,12 @@ import java.io.Serializable; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.Version; import org.osgi.framework.VersionRange; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,15 +46,23 @@ * * @author Eugene Kuleshov */ +@Component(service = {ProjectRegistryReader.class}) public class ProjectRegistryReader { private static final Logger log = LoggerFactory.getLogger(ProjectRegistryReader.class); private static final String WORKSPACE_STATE = "workspaceState.ser"; //$NON-NLS-1$ - private final File stateFile; + private File stateFile; - public ProjectRegistryReader(File stateLocationDir) { - this.stateFile = new File(stateLocationDir, WORKSPACE_STATE); + @Activate + void init(BundleContext bundleContext) { + IPath result = Platform.getStateLocation(bundleContext.getBundle()); + File bundleStateLocation = result.toFile(); + setStateLocation(bundleStateLocation); + } + + public void setStateLocation(File bundleStateLocation) { + this.stateFile = new File(bundleStateLocation, WORKSPACE_STATE); } public ProjectRegistry readWorkspaceState(final ProjectRegistryManager managerImpl) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java index eb2ddb7b5f..238a6f03dd 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/ProjectRegistryRefreshJob.java @@ -19,6 +19,9 @@ import java.util.LinkedHashSet; import java.util.Set; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +48,8 @@ import org.eclipse.m2e.core.project.MavenUpdateRequest; +@Component(service = {ProjectRegistryRefreshJob.class, IResourceChangeListener.class}, property = "event.mask:Integer=" + + (IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE)) public class ProjectRegistryRefreshJob extends Job implements IResourceChangeListener, IPreferenceChangeListener, IBackgroundProcessingQueue { private static final Logger log = LoggerFactory.getLogger(ProjectRegistryRefreshJob.class); @@ -53,14 +58,14 @@ public class ProjectRegistryRefreshJob extends Job implements IResourceChangeLis private final Set queue = new LinkedHashSet<>(); - /*package*/final ProjectRegistryManager manager; + @Reference + /*package*/ ProjectRegistryManager manager; - private final IMavenConfiguration mavenConfiguration; + @Reference + private IMavenConfiguration mavenConfiguration; - public ProjectRegistryRefreshJob(ProjectRegistryManager manager, IMavenConfiguration mavenConfiguration) { + public ProjectRegistryRefreshJob() { super(Messages.ProjectRegistryRefreshJob_title); - this.manager = manager; - this.mavenConfiguration = mavenConfiguration; } public void refresh(MavenUpdateRequest updateRequest) { @@ -68,6 +73,17 @@ public void refresh(MavenUpdateRequest updateRequest) { schedule(SCHEDULE_DELAY); } + @Deactivate + void shutdown() { + cancel(); + try { + //TODO do we really need/want to block until cancel? + join(); + } catch(InterruptedException ex) { + // ignored + } + } + // Job @Override diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/repository/RepositoryRegistry.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/repository/RepositoryRegistry.java index 887f352b19..352b1c55c8 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/repository/RepositoryRegistry.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/repository/RepositoryRegistry.java @@ -22,6 +22,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,12 +53,15 @@ * * @author igor */ +@Component(service = {IRepositoryRegistry.class, IMavenProjectChangedListener.class, ISettingsChangeListener.class}) public class RepositoryRegistry implements IRepositoryRegistry, IMavenProjectChangedListener, ISettingsChangeListener { private static final Logger log = LoggerFactory.getLogger(RepositoryRegistry.class); - private final IMaven maven; + @Reference + private IMaven maven; - private final IMavenProjectRegistry projectManager; + @Reference + private IMavenProjectRegistry projectManager; /** * Maps repositoryUrl to IndexInfo of repository index @@ -80,10 +86,7 @@ public class RepositoryRegistry implements IRepositoryRegistry, IMavenProjectCha private final RepositoryRegistryUpdateJob job = new RepositoryRegistryUpdateJob(this); - public RepositoryRegistry(IMaven maven, IMavenProjectRegistry projectManager) { - this.maven = maven; - this.projectManager = projectManager; - + public RepositoryRegistry() { this.workspaceRepository = new RepositoryInfo(null/*id*/, "workspace://"/*url*/, null/*basedir*/, SCOPE_WORKSPACE, null/*auth*/); //$NON-NLS-1$ } @@ -293,12 +296,14 @@ public List getRepositories(int scope) { return result; } + @Activate public void updateRegistry() { job.updateRegistry(); } public void addRepositoryIndexer(IRepositoryIndexer indexer) { this.indexers.add(indexer); + updateRegistry(); } public void addRepositoryDiscoverer(IRepositoryDiscoverer discoverer) { diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectRegistry.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectRegistry.java index 50d11183f7..0ed17bb2ad 100644 --- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectRegistry.java +++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/project/IMavenProjectRegistry.java @@ -20,10 +20,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.apache.maven.execution.MavenExecutionRequest; - import org.eclipse.m2e.core.embedder.ICallable; -import org.eclipse.m2e.core.embedder.IMavenExecutionContext; /** @@ -48,16 +45,6 @@ public interface IMavenProjectRegistry { */ void refresh(MavenUpdateRequest request); - /** - * Performs requested Maven project update synchronously. In other words, this method does not return until all - * affected projects have been updated and corresponding MavenProjectChangeEvent's broadcast. This method acquires a - * lock on the workspace's root. - * - * @deprecated this method does not properly join {@link IMavenExecutionContext}, use - * {@link #refresh(Collection, IProgressMonitor)} instead. - */ - @Deprecated void refresh(MavenUpdateRequest request, IProgressMonitor monitor) throws CoreException; - /** * Performs requested Maven project update synchronously. In other words, this method does not return until all * affected projects have been updated and corresponding MavenProjectChangeEvent's broadcast. This method acquires a @@ -87,18 +74,6 @@ public interface IMavenProjectRegistry { */ IMavenProjectFacade getMavenProject(String groupId, String artifactId, String version); - /** - * @deprecated This method does not properly join {@link IMavenExecutionContext} - */ - @Deprecated MavenExecutionRequest createExecutionRequest(IFile pom, ResolverConfiguration resolverConfiguration, - IProgressMonitor monitor) throws CoreException; - - /** - * @deprecated This method does not properly join {@link IMavenExecutionContext} - */ - @Deprecated MavenExecutionRequest createExecutionRequest(IMavenProjectFacade project, IProgressMonitor monitor) - throws CoreException; - /** * @since 1.4 */ diff --git a/org.eclipse.m2e.editor/META-INF/MANIFEST.MF b/org.eclipse.m2e.editor/META-INF/MANIFEST.MF index ebe7a60779..b328ec11f7 100644 --- a/org.eclipse.m2e.editor/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.editor/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.m2e.editor;singleton:=true -Bundle-Version: 1.18.4.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.m2e.editor.MavenEditorPlugin Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java index 28328bdb6a..1b56ff18f1 100644 --- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java +++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java @@ -97,6 +97,7 @@ import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants; import org.eclipse.m2e.core.project.IMavenProjectChangedListener; import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; import org.eclipse.m2e.core.project.MavenProjectChangedEvent; import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; import org.eclipse.m2e.core.ui.internal.actions.SelectionUtil; @@ -783,7 +784,8 @@ public void init(IEditorSite site, IEditorInput editorInput) throws PartInitExce } reloadMavenProjectCache(); - MavenPluginActivator.getDefault().getMavenProjectManager().addMavenProjectChangedListener(this); + IMavenProjectRegistry projectRegistry = MavenPluginActivator.getDefault().getMavenProjectManager(); + projectRegistry.addMavenProjectChangedListener(this); activationListener = new MavenPomActivationListener(site.getWorkbenchWindow().getPartService()); } diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java index 9bee830384..8e0445bb51 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/MavenJdtPlugin.java @@ -52,8 +52,8 @@ import org.eclipse.m2e.core.embedder.MavenConfigurationChangeEvent; import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.internal.jobs.IBackgroundProcessingQueue; -import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; import org.eclipse.m2e.core.project.IMavenProjectFacade; +import org.eclipse.m2e.core.project.IMavenProjectRegistry; import org.eclipse.m2e.jdt.internal.BuildPathManager; import org.eclipse.m2e.jdt.internal.MavenClassifierManager; import org.eclipse.m2e.jdt.internal.Messages; @@ -113,7 +113,7 @@ public void start(BundleContext bundleContext) throws Exception { IWorkspace workspace = ResourcesPlugin.getWorkspace(); - MavenProjectManager projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); + IMavenProjectRegistry projectManager = MavenPluginActivator.getDefault().getMavenProjectManager(); IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration(); File stateLocationDir = getStateLocation().toFile(); @@ -184,7 +184,7 @@ public void stop(BundleContext context) throws Exception { workspaceSourceDownloadJob = null; MavenPluginActivator mplugin = MavenPluginActivator.getDefault(); if(mplugin != null) { - MavenProjectManager projectManager = mplugin.getMavenProjectManager(); + IMavenProjectRegistry projectManager = mplugin.getMavenProjectManager(); projectManager.removeMavenProjectChangedListener(buildpathManager); projectManager.removeMavenProjectChangedListener(launchConfigurationListener); } diff --git a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java index 07945d77b2..4c3bc8acf5 100644 --- a/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java +++ b/org.eclipse.m2e.launching/src/org/eclipse/m2e/internal/launch/MavenRuntimeLaunchSupport.java @@ -44,6 +44,7 @@ import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.internal.launch.AbstractMavenRuntime; +import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; import org.eclipse.m2e.workspace.WorkspaceState; @@ -281,7 +282,9 @@ public void applyMavenRuntime(VMArguments properties) { } public static void applyWorkspaceArtifacts(VMArguments properties) { - File state = MavenPluginActivator.getDefault().getMavenProjectManager().getWorkspaceStateFile(); + //FIXME + File state = ((MavenProjectManager) MavenPluginActivator.getDefault().getMavenProjectManager()) + .getWorkspaceStateFile(); properties.appendProperty(WorkspaceState.SYSPROP_STATEFILE_LOCATION, quote(state.getAbsolutePath())); } diff --git a/org.eclipse.m2e.profiles.core/META-INF/MANIFEST.MF b/org.eclipse.m2e.profiles.core/META-INF/MANIFEST.MF index fb23502da9..e67b2d49f7 100644 --- a/org.eclipse.m2e.profiles.core/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.profiles.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: M2E Maven Profiles Management Bundle-SymbolicName: org.eclipse.m2e.profiles.core;singleton:=true -Bundle-Version: 1.17.4.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.m2e.profiles.core.internal.MavenProfilesCoreActivator Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0", org.eclipse.core.resources;bundle-version="3.6.0", diff --git a/org.eclipse.m2e.profiles.core/src/org/eclipse/m2e/profiles/core/internal/management/ProfileManager.java b/org.eclipse.m2e.profiles.core/src/org/eclipse/m2e/profiles/core/internal/management/ProfileManager.java index ad76d8b8de..b3ab3b5e5b 100644 --- a/org.eclipse.m2e.profiles.core/src/org/eclipse/m2e/profiles/core/internal/management/ProfileManager.java +++ b/org.eclipse.m2e.profiles.core/src/org/eclipse/m2e/profiles/core/internal/management/ProfileManager.java @@ -341,7 +341,8 @@ private List getProjectRepositories(Model projectModel) { private RepositorySystem getRepositorySystem() { try { //TODO find an alternative way to get the Maven RepositorySystem, or use Aether directly to resolve models?? - return MavenPluginActivator.getDefault().getMaven().lookup(RepositorySystem.class); + IMaven maven = MavenPluginActivator.getDefault().getMaven(); + return maven.lookup(RepositorySystem.class); } catch(CoreException e) { if(e.getStatus().getException() instanceof ComponentLookupException) { throw new NoSuchComponentException((ComponentLookupException) e.getStatus().getException());