New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[m2e] Remove references to internal packages and avoid static methods #5422
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
for some level of future proofing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did wonder, but the boolean would need to be renamed too.
The whole codebase needs a refactor, and fundamentally this class will be removed completely once we have 2.x as a base. I therefore leaned towards “make it work for now”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s also worth noting that the ceiling for the import is capped at
3.0.0)
in the bnd file, so> 2
can’t occur without changing that.