Skip to content
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

Add default version of export to selfimports #6238

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,13 @@ protected Jar getExtra() throws Exception {
@Override
public void analyze() throws Exception {
super.analyze();
cleanupVersion(getImports(), null, Constants.IMPORT_PACKAGE);
cleanupVersion(getExports(), getVersion(), Constants.EXPORT_PACKAGE);
Packages exports = getExports();
Packages imports = getImports();

cleanupVersion(imports, null, Constants.IMPORT_PACKAGE);
cleanupVersion(exports, getVersion(), Constants.EXPORT_PACKAGE);
addExportVersionToSelfImports(imports, exports);

String version = getProperty(BUNDLE_VERSION);
if (version != null) {
version = cleanupVersion(version);
Expand All @@ -468,6 +473,45 @@ public void analyze() throws Exception {
}
}

/**
* Add version of the export to Selfimports in case the import does not yet
* have a version. This method should be called after exports have been
* processed via {@link #cleanupVersion(Packages, String, String)}
*
* @param imports
* @param exports
* @throws Exception
*/
private void addExportVersionToSelfImports(Packages imports, Packages exports) throws Exception {
Packages selfImports = calcSelfImports(exports, imports);

// augmentImports() does use applyVersionPolicy internally which is the
// main thing we want here
augmentImports(selfImports, exports);
}

/**
* Calculates selfImports which are imports which are also exported by the
* same jar
*
* @param exports
* @param imports
* @return
*/
private Packages calcSelfImports(Packages exports, Packages imports) {
Packages selfImports = new Packages();

imports.entrySet()
.stream()
.filter(e -> exports.containsKey(e.getKey()))
.forEach(e -> {
selfImports.put(e.getKey(), e.getValue());
});

return selfImports;

}

private String doSnapshot(String version) {
String snapshot = getProperty(SNAPSHOT);
if (snapshot == null) {
Expand Down