Quick fix to add available matching version for Imported packages#1962
Conversation
|
@HannesWell Corrected: |
cf7ab4f to
6e79a47
Compare
de3e456 to
971407a
Compare
f6a6a98 to
adb0579
Compare
| exportedPackage.getVersion().toString(), NameVersionDescriptor.TYPE_PACKAGE); | ||
| exportedPackage.getExporter().getBundle(); | ||
|
|
||
| if (("java".equals(name) || name.startsWith("java."))) { //$NON-NLS-1$ //$NON-NLS-2$ |
There was a problem hiding this comment.
can this check be moved to the beginning of the loop, as soon as name is available?
adb0579 to
7089fa0
Compare
7089fa0 to
7687e6f
Compare
|
This pull request changes some projects for the first time in this development cycle. An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch. Git patchFurther information are available in Common Build Issues - Missing version increments. |
HannesWell
left a comment
There was a problem hiding this comment.
Just one point from me at the moment, I'll try to do a full review this evening.
| public static String computeInitialRequirementVersionRange(String version) { | ||
| if (version != null && VersionUtil.validateVersion(version).isOK()) { | ||
| Version pvi = Version.parseVersion(version); | ||
| return new VersionRange( | ||
| "[" + pvi.getMajor() + "." + pvi.getMinor() + "," + (pvi.getMajor() + 1) + ")") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ | ||
| .toString(); | ||
| } | ||
| return ""; //$NON-NLS-1$ | ||
| } |
There was a problem hiding this comment.
Recently I added a method that does this to ManifestUtils:
Admittedly this method would probably better be moved to this class and probably be used instead of the existing method. That would hopefully add proper version ranges in more places.
I can try to have a look at unifying these as soon as possible. Or if you want to have a look at it, it would be more than welcome.
There was a problem hiding this comment.
@HannesWell
I have moved your method createConsumerRequirementRange to VersionUtil class and updated the corresponding callers(found 2 classes - JavaResolutionFactory and ImportPackageObject).
Kindly check the changes.
35827e3 to
cc2fb8c
Compare
|
@HannesWell |
d0529e8 to
a045060
Compare
6d5c079 to
eb69bb5
Compare
eb69bb5 to
2c25e5b
Compare
|
this is ready to land, but would like another quick look from you, @HannesWell ! |
Yes I will do it soon. |
2c25e5b to
b23030f
Compare
|
@HannesWell
|
4030b60 to
33e07d7
Compare
|
@HannesWell |
33e07d7 to
40bbadd
Compare
noopur2507
left a comment
There was a problem hiding this comment.
Thanks, Neha. The overall approach looks good and aligns well with the existing Require-Bundle quick fix. I’ve added a few comments to improve the correctness.
Also, please add tests if applicable for PDE quick fixes.
@HannesWell / @gireeshpunathil – please take a look and suggest if anything else should be adjusted.
Once the above comments are addressed, this should be in good shape for merging.
| // $NON-NLS-2$ | ||
| continue; | ||
| } | ||
| if (name.equalsIgnoreCase(inputElement.toString())) { |
There was a problem hiding this comment.
Package names in OSGi are case-sensitive, so this can lead to incorrect matches.
| continue; | ||
| } | ||
| if (name.equalsIgnoreCase(inputElement.toString())) { | ||
| return exportedPackage.getVersion(); |
There was a problem hiding this comment.
This returns the first matching exported package. This may produce incorrect results when multiple bundles export the same package. IMO, the fix should select the highest available version instead.
| super(type, marker); | ||
| } | ||
|
|
||
| public Version getVersion(Object inputElement) { |
There was a problem hiding this comment.
Can this parameter be of type String instead of Object?
There was a problem hiding this comment.
versionRange is calculated based on version object(in line 79). If we change the type to string, we will have to change the type again there.
| ImportPackageHeader header = (ImportPackageHeader) bundle.getManifestHeader(Constants.IMPORT_PACKAGE); | ||
| if (header != null) { | ||
| for (ImportPackageObject importPackage : header.getPackages()) { | ||
| if (bundleId.equals(importPackage.getName())) { |
There was a problem hiding this comment.
"bundleId" is misleading here as the value represents a package name. Please update it across all usages of "bundleId" in the PR.
| for (ImportPackageObject importPackage : header.getPackages()) { | ||
| if (bundleId.equals(importPackage.getName())) { | ||
| Version version = getVersion(bundleId); | ||
| if (version != null) { |
There was a problem hiding this comment.
Currently, if no matching exported package is found i.e. if version is null, the quick fix will silently fail. So, the quick fix will appear but will have no effect. Better to avoid offering it if no version is available.
| AddMatchingVersion = Require latest available version | ||
| AddMatchingVersionDescription = Add a version range aligned with the latest compatible available version |
There was a problem hiding this comment.
Please review both strings to reflect the intended change for the latest version / version range as these are now used by both Require-Bundle and Import-Package quick fixes.
There was a problem hiding this comment.
@noopur2507
I have updated the msg. Attached the screenshot in the PR description
|
@nburnwal09, I still see old changes in the PR. Can you please update it? |
40bbadd to
c3b57fe
Compare
c3b57fe to
df3c116
Compare
Yeah sorry about that. That pushed got rejected in my local and I didn't notice. Have updated just now |

This is to provide a quick fix for adding the available matching version for Imported packages in MANIFEST.MF warning.
Similar to the fix: #1623 and as suggested in here
Attaching screenshot for the quick fix:
After applying: