Skip to content

[BUG] Fix baseline quick fixes write to correct key and add quick fixes - #7357

Open
peterkir wants to merge 2 commits into
bndtools:masterfrom
peterkir:fea-baseline-quickfixes
Open

[BUG] Fix baseline quick fixes write to correct key and add quick fixes#7357
peterkir wants to merge 2 commits into
bndtools:masterfrom
peterkir:fea-baseline-quickfixes

Conversation

@peterkir

@peterkir peterkir commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

…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

…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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-Package version value (rather than overwriting broader content) and add resolutions for structural-change markers.
  • Update RunRequirementsPart commits to write back to the actual local -runrequires.* key when applicable, supported by new BndEditModel APIs.
  • 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 packageinfo content using the platform default charset (input.getBytes()). Since the code reads files using UTF-8 elsewhere (and this class now explicitly uses StandardCharsets.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

  • updatePackageVersion writes packageinfo using input.getBytes() (platform default charset). This should use UTF-8 explicitly for consistency with IO.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>
@peterkir peterkir changed the title fix: baseline quick fixes write to correct key and add quick fix for … [BUG] Fix baseline quick fixes write to correct key and add quick fixes Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants