Skip to content

Commit

Permalink
Merge pull request bndtools#718 from bjhargrave/next
Browse files Browse the repository at this point in the history
bndtools#708 Package not imported when a sub-package is contained in the bundle
  • Loading branch information
bjhargrave committed Dec 2, 2014
2 parents 1171b89 + e7383fb commit 2855e10
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
45 changes: 43 additions & 2 deletions biz.aQute.bndlib.tests/src/test/BuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,45 @@
@SuppressWarnings("resource")
public class BuilderTest extends BndTestCase {

/**
* #708 if a bundle has a.b.c but imports a.b then bnd cannot find the version of
* a.b because the scanning of a.b.c already has set the information for a.b
* to "nothing". The learnPackage() method must be adapted so that "empty"
* package do not occupy a position This was diagnosed by Balázs Zsoldos
* balazs.zsoldos@everit.biz
* @throws Exception
*/

public void testOverlappingPackageMissesImportVersions() throws Exception {
Builder exporter = new Builder();
exporter.setExportPackage("test._708.a.b");
exporter.addClasspath(new File("bin"));
exporter.build();
assertTrue( exporter.check());

//
// We need to build a temp entry because if we include 'bin'
// on the final build then we see the a.b package there, and
// there it has information
//

Builder temp = new Builder();
temp.setPrivatePackage("test._708.a.b.c");
temp.addClasspath(new File("bin"));
temp.build();
assertTrue( temp.check());

Builder importer = new Builder();
importer.setPrivatePackage("test._708.a.b.c");
importer.addClasspath(temp.getJar());
importer.addClasspath(exporter.getJar());
importer.build();
assertTrue( importer.check());

assertEquals( "test._708.a.b;version=\"1.2.3\"", exporter.getJar().getManifest().getMainAttributes().getValue("Export-Package"));
assertEquals( "test._708.a.b;version=\"[1.2,2)\"", importer.getJar().getManifest().getMainAttributes().getValue("Import-Package"));

}
/**
* Test if the Manifest gets the last modified date
*/
Expand All @@ -42,7 +81,7 @@ public void testLastModifiedForManifest() throws Exception {
Date date = new Date(t);
System.out.println(date + " " + t);
// TODO we need to adapt the timestamp handling
assertTrue(date + " " + t, t ==1142555622000L);
assertTrue(date + " " + t, t == 1142555622000L);
}
finally {
ajr.close();
Expand Down Expand Up @@ -245,7 +284,9 @@ public void testVeryOldPackageInfo() throws Exception {
b.addClasspath(IO.getFile("jar/osgi-3.0.0.jar"));
b.setExportPackage("org.osgi.util.measurement;version=100, org.osgi.util.tracker;version=100, *");
Jar build = b.build();
assertTrue(b.check("Version for package org.osgi.util.measurement is set to different values in the source ", "Version for package org.osgi.util.tracker is set to different values in the source"));
assertTrue(b.check(
"Version for package org.osgi.util.measurement is set to different values in the source ",
"Version for package org.osgi.util.tracker is set to different values in the source"));
}
finally {
b.close();
Expand Down
5 changes: 5 additions & 0 deletions biz.aQute.bndlib.tests/src/test/_708/a/b/ReferredTo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test._708.a.b;

public class ReferredTo {

}
7 changes: 7 additions & 0 deletions biz.aQute.bndlib.tests/src/test/_708/a/b/c/Refererrer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test._708.a.b.c;

import test._708.a.b.*;

public class Refererrer {
ReferredTo r = new ReferredTo();
}
1 change: 1 addition & 0 deletions biz.aQute.bndlib.tests/src/test/_708/a/b/packageinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version 1.2.3
9 changes: 9 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ private void learnPackage(Jar jar, PackageRef packageRef, Packages map) throws E
if (packageRef.isMetaData() || packageRef.isJava() || packageRef.isPrimitivePackage())
return;

//
// We should ignore empty directories/packages. Empty packages should
// not take the package slot. See #708
//

Map<String,Resource> dir = jar.getDirectories().get(packageRef.getBinary());
if ( dir == null || dir.size() == 0)
return;

//
// Make sure we only do this once for each package
// in cp order (which is the calling order)
Expand Down

0 comments on commit 2855e10

Please sign in to comment.