Skip to content

Commit

Permalink
Add version of export to selfimports
Browse files Browse the repository at this point in the history
reuse augmentImports() method to add version information from exports to self-imports, after exports have been processed

Signed-off-by: Christoph Rueger <[email protected]>
  • Loading branch information
chrisrueger committed Aug 27, 2024
1 parent dc17dc6 commit c5e66ab
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>maven</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
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

0 comments on commit c5e66ab

Please sign in to comment.