[BUG] Fix baseline quick fixes write to correct key and add quick fixes - #7357
Open
peterkir wants to merge 2 commits into
Open
[BUG] Fix baseline quick fixes write to correct key and add quick fixes#7357peterkir wants to merge 2 commits into
peterkir wants to merge 2 commits into
Conversation
…structural change markers - BaselineErrorHandler.getResolutions: fix bnd.bnd markers to update the Export-Package version value instead of overwriting the entire file - BaselineErrorHandler.getProposals: fix bnd.bnd quick assist to replace the version value in Export-Package rather than the package name - BaselineErrorHandler: add quick fixes for 'method added/removed' structural change markers by deriving package name and suggested version from baselineInfo - RunRequirementsPart.doCommitToModel: write to the actual local key (e.g. -runrequires.shared) instead of always creating a new -runrequires entry - BndEditModel: add getLocalMergePropertyKey and setRunRequiresAtKey to support the above - Add BaselineErrorHandlerTest and extend BndEditModelTest to cover the new behaviour Signed-off-by: Peter Kirschner <peter@klib.io>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Bndtools baseline/structural-change quick fixes and run requirement persistence, ensuring edits are applied to the correct underlying model keys and that baseline version updates modify only the intended value.
Changes:
- Fix baseline quick-fix / quick-assist behavior to update only the
Export-Packageversion value (rather than overwriting broader content) and add resolutions for structural-change markers. - Update
RunRequirementsPartcommits to write back to the actual local-runrequires.*key when applicable, supported by newBndEditModelAPIs. - Add/extend tests covering the new behaviors.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| bndtools.core/src/bndtools/editor/project/RunRequirementsPart.java | Commit run requirements to the correct local merge key instead of always -runrequires. |
| biz.aQute.bndlib/src/aQute/bnd/build/model/BndEditModel.java | Add APIs to discover the local merge key and set run requirements at a specific key. |
| biz.aQute.bndlib.tests/test/test/BndEditModelTest.java | Add unit tests for the new BndEditModel behaviors. |
| bndtools.builder/src/org/bndtools/builder/handlers/baseline/BaselineErrorHandler.java | Refine baseline resolutions/proposals and add structural-change quick fixes. |
| bndtools.builder/test/org/bndtools/builder/handlers/baseline/BaselineErrorHandlerTest.java | Add unit tests for Export-Package version replacement logic. |
| biz.aQute.bndlib/bnd.bnd | Update Export-Package entry to include an explicit version for aQute.bnd.build.model. |
Suppressed comments (2)
bndtools.builder/src/org/bndtools/builder/handlers/baseline/BaselineErrorHandler.java:376
- This quick-fix writes
packageinfocontent using the platform default charset (input.getBytes()). Since the code reads files using UTF-8 elsewhere (and this class now explicitly usesStandardCharsets.UTF_8), the write should be explicit too to avoid corrupting non-ASCII content on non-UTF-8 platforms.
This issue also appears on line 488 of the same file.
String input = "version " + suggestedVersion;
ByteArrayInputStream stream = new ByteArrayInputStream(input.getBytes());
file.setContents(stream, false, true, monitor);
bndtools.builder/src/org/bndtools/builder/handlers/baseline/BaselineErrorHandler.java:491
updatePackageVersionwritespackageinfousinginput.getBytes()(platform default charset). This should use UTF-8 explicitly for consistency withIO.collect(...)(UTF-8) and the other writes in this class.
String input = "version " + suggestedVersion;
pkgInfoFile.getWorkspace()
.run(monitor -> pkgInfoFile.setContents(new ByteArrayInputStream(input.getBytes()),
false, true, monitor), null);
Comment on lines
+443
to
+452
| static String replaceVersionInExportPackage(String content, int searchFrom, String suggestedVersion) { | ||
| int searchEnd = Math.min(searchFrom + 300, content.length()); | ||
| Pattern versionPattern = Pattern.compile(";\\s*version\\s*=\\s*\"([^\"]*)\""); | ||
| Matcher m = versionPattern.matcher(content); | ||
| m.region(searchFrom, searchEnd); | ||
| if (m.find()) { | ||
| return content.substring(0, m.start(1)) + suggestedVersion + content.substring(m.end(1)); | ||
| } | ||
| return null; | ||
| } |
Comment on lines
+1208
to
+1216
| public Optional<String> getLocalMergePropertyKey(String stem) { | ||
| if (documentProperties.containsKey(stem)) | ||
| return Optional.of(stem); | ||
| String prefix = stem + "."; | ||
| return documentProperties.stringPropertyNames() | ||
| .stream() | ||
| .filter(k -> k.startsWith(prefix)) | ||
| .findFirst(); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Peter Kirschner <peter@kirschners.de>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…structural change markers