-
Notifications
You must be signed in to change notification settings - Fork 83
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
Strip micro-version and add upper bound when adding package imports #1007
Conversation
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.
Hi @alshamams thank you for working on this.
While this fixes the linked issue in its most basic form I think this is a good opportunity to fix a few other flaws in this quick-fix.
In general it would be good to also specify the upper bound of the import version range and to move the logic to a more general place, i.e. to ImportPackageObject.getVersion()
.
You can get such String using the following to assemble a suitable VersionRange from a org.osgi.framework.Version
:
new VersionRange("[" + version.getMajor() + "." + version.getMinor() + "," + (version.getMajor() + 1) + "]").toString()
With that the version of the ImportPackageObject
does not have to be set explicitly anymore.
Besides that, the quick-fix currently only adds a version if the Import-Package header already exists. This could be fixed by replacing.
if (header == null) {
bundle.setHeader(Constants.IMPORT_PACKAGE, pkgId);
} else if (header instanceof ImportPackageHeader ipHeader) {
by
if (header == null) {
header = bundle.getModel().getFactory().createHeader(Constants.IMPORT_PACKAGE, pkgId);
}
if (header instanceof ImportPackageHeader ipHeader) {
Thanks @HannesWell for the quick review.
Thanks, this looks clean and elegant. However, modifying the getVersion API will have implications in regular import package flow. (Not the quick fix one, but while adding import packages from Dependencies tab). Is this what you intend ? Just wanted to make sure you are aware of this change before I push.
I was aware of it, and was planning to do it in a follow-up PR, given that it is unrelated to the issue at hand. I think that I will make the change here itself. |
I have not yet checked every caller path of the code, but yes in general it is good practice to specifiy an upper bound if one specifies a lower to follow semantic versioning. If one really wants to have no upper-bound, it can still be removed later. But from my experience I currently add an upper bound in 90% of the time I use the quick-fix.
Yes that's fine from my POV, this change is small enough at the moment and it is related enough to mix it. |
cd950ea
to
814f84b
Compare
Hi @HannesWell , |
814f84b
to
4300d25
Compare
ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/bundle/ImportPackageObject.java
Outdated
Show resolved
Hide resolved
...rg.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java
Outdated
Show resolved
Hide resolved
4300d25
to
d34e795
Compare
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.
@alshamams I just applied the suggestions locally and also added handling for the default empty version (0.0.0
) in ImportPackageObject
so that in that case not a version range like [0.0.0,1.0.0)
is added. This case
The great thing about specifying the upper bound in ImportPackageObject.getVersion()
is, that it is now also added if one select and adds a package via the Editor directly or through the add dependencies
link in the Automated Management of Dependencies
section.
This is IMHO a great improvement for PDE respectively its users.
The current state looks very good to me and is for me ready for submission.
Are you fine with this as well?
This commit resets the micro-version to '0' while importing packages as part of quick fix, as it is not relevant. Additionally it specifies the next major version as exclusive upper bound to support semantic versioning. Fixes eclipse-pde#401 Co-authored-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
d34e795
to
147e200
Compare
I'm merging this now. |
This was done wrong in eclipse-pde#1007
This was done wrong in eclipse-pde#1007 And fix wrong version ranges in PDE introduced by that bug.
This was done wrong in eclipse-pde#1007 And fix wrong version ranges in PDE introduced by that bug.
This was done wrong in #1007 And fix wrong version ranges in PDE introduced by that bug.
This commit resets the micro-version to ‘0’ while importing packages as part of quick fix, as it is not relevant.
Fixes: #401