Skip to content

Commit b3eed2b

Browse files
committed
Java Imports & Empty header
- The java imports are now always done except when the used framework is < 1.9 (before R7). The EE version is now ignored. - The version used to come from the _imports_. However, that does not make sense, so I've changed it to the classpathExports version of the framework package. This is in almost all cases the floor of the import range. By using the export, we can make the decision that we use an old framework in any bundle that has the framework package on the class path and not only in bundles that import the framework. (Surprised this was not a problem?) - The MRJ will now set the Input-Package to Require-Capability to an empty string since the spec is rather strange imho. The RFC is a tiny bit clearer but this case should be made more explicit. --- Signed-off-by: Peter Kriens <[email protected]> Signed-off-by: Peter Kriens <[email protected]>
1 parent 24aef24 commit b3eed2b

File tree

12 files changed

+72
-34
lines changed

12 files changed

+72
-34
lines changed

biz.aQute.bndlib.tests/test/test/AnalyzerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@ public void testBundleActivatorNotImported() throws Exception {
828828
Builder a = new Builder();
829829
try {
830830
Properties p = new Properties();
831+
p.put("-noimportjava", "true");
831832
p.put("Import-Package", "!org.osgi.framework,*");
832833
p.put("Private-Package", "org.objectweb.*");
833834
p.put("Bundle-Activator", "org.osgi.framework.BundleActivator");

biz.aQute.bndlib.tests/test/test/ImportJavaTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import aQute.bnd.osgi.Builder;
1616
import aQute.bnd.osgi.Domain;
1717
import aQute.bnd.osgi.Jar;
18+
import aQute.lib.io.IO;
1819

1920
public class ImportJavaTest {
2021
private Builder builder;
@@ -95,6 +96,7 @@ public void import_java_old_framework() throws Exception {
9596
builder.setProperty("-classpath", "compilerversions/compilerversions.jar");
9697
builder.setProperty("-includepackage", "sun_1_8");
9798
builder.setProperty("-noimportjava", "false");
99+
builder.addClasspath(IO.getFile("jar/osgi.core-4.3.0.jar"));
98100
Jar jar = builder.build();
99101
assertTrue(builder.check());
100102
Manifest manifest = jar.getManifest();

biz.aQute.bndlib.tests/test/test/MultiReleaseTest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ public void testBuild() throws Exception {
3838

3939
Project main = ws.getProject("multirelease.main");
4040
Project v9 = ws.getProject("multirelease.v9");
41+
Project v12 = ws.getProject("multirelease.v12");
4142
Project v17 = ws.getProject("multirelease.v17");
4243

4344
v17.compile(false);
4445
v17.build();
46+
v12.compile(false);
47+
v12.build();
4548
v9.compile(false);
4649
v9.build();
4750
main.setProperty(Constants.JPMS_MODULE_INFO, "");
@@ -73,15 +76,23 @@ public void testBuild() throws Exception {
7376
assertThat(manifest9.getMainAttributes()
7477
.getValue(Constants.IMPORT_PACKAGE))
7578
.isEqualTo(
76-
"org.osgi.service.condpermadmin;version=\"[1.1,2)\",org.osgi.service.url;version=\"[1.0,2)\"");
79+
"");
7780
assertThat(manifest9.getMainAttributes()
7881
.getValue(Constants.REQUIRE_CAPABILITY)).isEqualTo("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=9))\"");
7982

83+
Manifest manifest12 = jpms.getManifest(12);
84+
assertThat(manifest12).isNotNull();
85+
assertThat(manifest12.getMainAttributes()
86+
.getValue(Constants.IMPORT_PACKAGE)).isEqualTo(
87+
"org.osgi.service.url;version=\"[1.0,2)\"");
88+
assertThat(manifest12.getMainAttributes()
89+
.getValue(Constants.REQUIRE_CAPABILITY)).isEqualTo("osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=12))\"");
90+
8091
Manifest manifest17 = jpms.getManifest(17);
8192
assertThat(manifest17).isNotNull();
8293
assertThat(manifest17.getMainAttributes()
8394
.getValue(Constants.IMPORT_PACKAGE)).isEqualTo(
84-
"java.io,java.lang,org.osgi.service.startlevel;version=\"[1.1,2)\",org.osgi.service.url;version=\"[1.0,2)\"");
95+
"org.osgi.service.startlevel;version=\"[1.1,2)\",org.osgi.service.url;version=\"[1.0,2)\"");
8596
assertThat(manifest17.getMainAttributes()
8697
.getValue(Constants.REQUIRE_CAPABILITY)).isEqualTo(
8798
"fake;filter:=\"(&(fake=fake)(version>=1.2.3)(!(version>=2.0.0)))\",osgi.ee;filter:=\"(&(osgi.ee=JavaSE)(version=17))\"");
@@ -100,11 +111,16 @@ public void testBuild() throws Exception {
100111
assertThat(IO.collect(somefile.get()
101112
.openInputStream())).isEqualTo("17");
102113

103-
somefile = jpms.findResource("somefile", 15);
114+
somefile = jpms.findResource("somefile", 11);
104115
assertThat(somefile).isPresent();
105116
assertThat(IO.collect(somefile.get()
106117
.openInputStream())).isEqualTo("9");
107118

119+
somefile = jpms.findResource("somefile", 13);
120+
assertThat(somefile).isPresent();
121+
assertThat(IO.collect(somefile.get()
122+
.openInputStream())).isEqualTo("12");
123+
108124
assertThat(jpms.getModuleName()).isPresent()
109125
.get()
110126
.isEqualTo("foo.bar");

biz.aQute.bndlib.tests/test/test/ProjectTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public void testSubBuilders() throws Exception {
599599

600600
assertEquals(12, project.getExports()
601601
.size());
602-
assertEquals(18, project.getImports()
602+
assertEquals(33, project.getImports()
603603
.size());
604604
assertEquals(12, project.getContained()
605605
.size());

biz.aQute.bndlib.tests/testresources/ws-multirelease/multirelease.main/bnd.bnd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Main-Class hello.App
99

1010
-includeresource \
1111
META-INF/versions/9=@${repo;multirelease.v9}, \
12+
META-INF/versions/12=@${repo;multirelease.v12}, \
1213
META-INF/versions/17=@${repo;multirelease.v17}
1314

1415

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
javac.source=12
2+
javac.target=12
3+
4+
src=src
5+
target=generated
6+
bin=generated/bin
7+
8+
-buildpath osgi.core, org.osgi.annotation.bundle
9+
-includeresource somefile
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package hello;
2+
3+
4+
public class Hello {
5+
6+
Private local = new Private();
7+
8+
public static void main(String args[]) {
9+
System.out.println("Hello from java 12");
10+
}
11+
}

biz.aQute.bndlib.tests/testresources/ws-multirelease/multirelease.v9/src/hello/Hello.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
44

55
public class Hello {
6-
ConditionalPermissionAdmin cpa;
7-
Private local = new Private();
86
public static void main(String args[]) {
97
System.out.println("Hello from java 9");
108
}

0 commit comments

Comments
 (0)