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