Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[m2e] Remove references to internal packages and avoid static methods
The latest m2e updates have moved methods in internal packages. This breaks m2e support in Bndtools where we were going around the official API. This is primarily an attempt to remove the usage of internal types in an effort to remain compatible between versions. Furthermore we need to coexist in scenarios where: * A maven project change listener whiteboard is built in to M2E 2+ and replaces the one we created * Services are used for M2E objects such as IMaven - access these in a consistent way * Public lookup methods now exist, but we must still use reflection while 1.x is supported A good deal of cleanup will be possible once we have a base of 2.0, but for now this is a good next step. Known issues: The bndrun "Browse Repos" section populates, but then disappears again after about a second. Resolving is possible. Signed-off-by: Tim Ward <timothyjward@apache.org>
- Loading branch information
1 parent
6e6d57f
commit 2f264b7
Showing
16 changed files
with
286 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,59 @@ | ||
package bndtools.m2e; | ||
|
||
import org.eclipse.m2e.core.internal.MavenPluginActivator; | ||
import org.eclipse.m2e.core.internal.project.registry.MavenProjectManager; | ||
import org.eclipse.m2e.core.MavenPlugin; | ||
import org.eclipse.m2e.core.embedder.IMaven; | ||
import org.eclipse.m2e.core.project.IMavenProjectRegistry; | ||
import org.osgi.annotation.bundle.Header; | ||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.BundleActivator; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.FrameworkUtil; | ||
|
||
import aQute.bnd.osgi.Constants; | ||
|
||
@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}") | ||
public class Activator implements BundleActivator { | ||
|
||
/** | ||
* M2E version 2 has implicit support for whiteboard listeners and registers | ||
* services. This activator helps us to work in both situations. | ||
*/ | ||
private boolean isM2E_v2; | ||
|
||
private MavenProjectChangedListenersTracker projectChangedListenersTracker; | ||
|
||
@Override | ||
public void start(BundleContext context) throws Exception { | ||
projectChangedListenersTracker = new MavenProjectChangedListenersTracker(); | ||
MavenProjectManager projectManager = MavenPluginActivator.getDefault() | ||
.getMavenProjectManager(); | ||
projectManager.addMavenProjectChangedListener(projectChangedListenersTracker); | ||
Bundle bundle = FrameworkUtil.getBundle(MavenPlugin.class); | ||
isM2E_v2 = bundle.getVersion() | ||
.getMajor() == 2; | ||
|
||
if (!isM2E_v2) { | ||
projectChangedListenersTracker = new MavenProjectChangedListenersTracker(); | ||
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); | ||
projectManager.addMavenProjectChangedListener(projectChangedListenersTracker); | ||
|
||
registerM2EServices(context); | ||
} | ||
} | ||
|
||
/** | ||
* These services should only be registered if running on M2E 1.x | ||
* | ||
* @param context | ||
*/ | ||
private void registerM2EServices(BundleContext context) { | ||
context.registerService(IMaven.class, MavenPlugin.getMaven(), null); | ||
context.registerService(IMavenProjectRegistry.class, MavenPlugin.getMavenProjectRegistry(), null); | ||
} | ||
|
||
@Override | ||
public void stop(BundleContext context) throws Exception { | ||
MavenProjectManager projectManager = MavenPluginActivator.getDefault() | ||
.getMavenProjectManager(); | ||
projectManager.removeMavenProjectChangedListener(projectChangedListenersTracker); | ||
projectChangedListenersTracker.close(); | ||
if (!isM2E_v2) { | ||
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); | ||
projectManager.removeMavenProjectChangedListener(projectChangedListenersTracker); | ||
projectChangedListenersTracker.close(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package bndtools.m2e; | ||
|
||
import org.osgi.service.component.annotations.Component; | ||
|
||
@Component(service = M2ETypeAccess.class) | ||
public class M2ETypeAccess { | ||
|
||
} |
Oops, something went wrong.