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

[jpms] Fix calculation of module name with mult-release-jar dependencies #5360

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion biz.aQute.bndlib.tests/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
slf4j.simple;version=latest,\
org.apiguardian:apiguardian-api;version=latest,\
${junit},\
${mockito}
${mockito},\
com.google.gson

-runtrace: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import aQute.bnd.classfile.ClassFile;
import aQute.bnd.classfile.ModuleAttribute;
import aQute.bnd.classfile.ModuleAttribute.Require;
import aQute.bnd.classfile.ModuleMainClassAttribute;
import aQute.bnd.classfile.ModulePackagesAttribute;
import aQute.bnd.osgi.Builder;
Expand Down Expand Up @@ -1377,4 +1378,36 @@ public void simpleModule() throws Exception {
}
}

@Test
public void multiReleaseDependency() throws Exception {
try (Builder b = new Builder()) {
b.setProperty(Constants.JPMS_MODULE_INFO, "foo");
b.setProperty(Constants.BUNDLE_SYMBOLICNAME, "foo");
b.setProperty(Constants.BUNDLE_VERSION, "1.2.7");
b.setProperty(Constants.PRIVATEPACKAGE, "test.jpms.k.*");
b.addClasspath(new File("bin_test"));
// the module name of this is 'com.google.gson' but it is also
// compiled for java 8, so the default module name would be 'gson'
// if multi-release is not handled correctly
b.addClasspath(IO.getFile("testresources/gson-2.9.1.jar"));
Jar jar = b.build();
assertTrue(b.check());
Resource moduleInfo = jar.getResource(Constants.MODULE_INFO_CLASS);
assertNotNull(moduleInfo);

ClassFile module_info = ClassFile.parseClassFile(new DataInputStream(moduleInfo.openInputStream()));

assertThat(module_info.this_class).isEqualTo("module-info");

ModuleAttribute moduleAttribute = Arrays.stream(module_info.attributes)
.filter(ModuleAttribute.class::isInstance)
.map(ModuleAttribute.class::cast)
.findFirst()
.orElse(null);
assertThat(moduleAttribute.requires).hasSize(2)
.anyMatch(e -> e.requires.equals("java.base"))
.anyMatch(e -> e.requires.equals("com.google.gson"));
}
}

}
16 changes: 16 additions & 0 deletions biz.aQute.bndlib.tests/test/test/jpms/k/Foo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package test.jpms.k;

import com.google.gson.Gson;

public class Foo {

public void serialize() {
Gson gson = new Gson();
String json = gson.toJson(new MyObj());
}

public class MyObj {
public String a;
public int b;
}
}
3 changes: 3 additions & 0 deletions biz.aQute.bndlib.tests/test/test/jpms/k/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("1.0.0")
package test.jpms.k;
Binary file not shown.