diff --git a/biz.aQute.bndlib.tests/test/test/jpms/JPMSModuleInfoPluginTest.java b/biz.aQute.bndlib.tests/test/test/jpms/JPMSModuleInfoPluginTest.java index d5ab43ea08..7e9ac2184a 100644 --- a/biz.aQute.bndlib.tests/test/test/jpms/JPMSModuleInfoPluginTest.java +++ b/biz.aQute.bndlib.tests/test/test/jpms/JPMSModuleInfoPluginTest.java @@ -157,7 +157,7 @@ public void moduleWithOptionsIgnore() throws Exception { assertThat(moduleAttribute.requires).hasSize(3) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")); ModulePackagesAttribute modulePackagesAttribute = Arrays.stream(module_info.attributes) @@ -212,7 +212,7 @@ public void moduleWithOptionsStatic() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -395,7 +395,7 @@ public void moduleWithAllDynamicImportsOrOptionalIsStatic() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -403,7 +403,7 @@ public void moduleWithAllDynamicImportsOrOptionalIsStatic() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_STATIC_PHASE); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -459,7 +459,7 @@ public void moduleWithAllDynamicImportsIsStatic_2() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -467,7 +467,7 @@ public void moduleWithAllDynamicImportsIsStatic_2() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_STATIC_PHASE); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -524,7 +524,7 @@ public void moduleWithAllDynamicImportsIsStatic() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -532,7 +532,7 @@ public void moduleWithAllDynamicImportsIsStatic() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_STATIC_PHASE); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -588,7 +588,7 @@ public void moduleWithAllResolutionOptionalImportsIsStatic() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -596,7 +596,7 @@ public void moduleWithAllResolutionOptionalImportsIsStatic() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_STATIC_PHASE); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -652,7 +652,7 @@ public void moduleWithNoImportsIsStatic() throws Exception { assertThat(moduleAttribute.requires).hasSize(5) .anyMatch(e -> e.requires.equals("java.base")) .anyMatch(e -> e.requires.equals("java.management")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -660,7 +660,7 @@ public void moduleWithNoImportsIsStatic() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_STATIC_PHASE); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -716,7 +716,7 @@ public void moduleManualConfiguration() throws Exception { assertThat(moduleAttribute.requires).hasSize(5) .anyMatch(e -> e.requires.equals("bar")) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -728,7 +728,7 @@ public void moduleManualConfiguration() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(0); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -793,7 +793,7 @@ public void moduleRequiresModuleB() throws Exception { assertThat(moduleAttribute.requires).hasSize(4) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")) .anyMatch(e -> e.requires.equals("java.json.bind")); @@ -805,7 +805,7 @@ public void moduleRequiresModuleB() throws Exception { .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(0); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); @@ -869,7 +869,7 @@ public void moduleRequiresModuleA() throws Exception { assertThat(moduleAttribute.requires).hasSize(3) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .anyMatch(e -> e.requires.equals("java.json")); assertThat(moduleAttribute.uses).hasSize(0); @@ -931,9 +931,9 @@ public void moduleRequiresA() throws Exception { assertThat(moduleAttribute.requires).hasSize(2) .anyMatch(e -> e.requires.equals("java.base")) - .anyMatch(e -> e.requires.equals("geronimo-jcdi_2.0_spec")); + .anyMatch(e -> e.requires.equals("geronimo.jcdi.2.0.spec")); - assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo-jcdi_2.0_spec")) + assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("geronimo.jcdi.2.0.spec")) .flatExtracting(e -> Arrays.asList(e.requires_flags)) .containsExactlyInAnyOrder(ModuleAttribute.Require.ACC_TRANSITIVE); diff --git a/biz.aQute.bndlib/src/aQute/bnd/osgi/JPMSModule.java b/biz.aQute.bndlib/src/aQute/bnd/osgi/JPMSModule.java index b0f9628d66..5a4a601cd6 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/osgi/JPMSModule.java +++ b/biz.aQute.bndlib/src/aQute/bnd/osgi/JPMSModule.java @@ -502,6 +502,14 @@ public int getNextRelease(int release) { public static String cleanupName(String bsn) { if (bsn == null) return null; + if ( bsn.endsWith(".jar")) + bsn= bsn.substring(0, bsn.length()-4); + + Pattern STRIP_SUFFIX_P = Pattern.compile("-\\d+\\..*$"); + Matcher m = STRIP_SUFFIX_P.matcher(bsn); + if (m.find()) { + bsn = bsn.substring(0, m.start()); + } String[] split = bsn.split("[^A-Za-z0-9]+"); return Stream.of(split) diff --git a/biz.aQute.bndlib/src/aQute/bnd/plugin/jpms/JPMSModuleInfoPlugin.java b/biz.aQute.bndlib/src/aQute/bnd/plugin/jpms/JPMSModuleInfoPlugin.java index 795749838e..adf4413abd 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/plugin/jpms/JPMSModuleInfoPlugin.java +++ b/biz.aQute.bndlib/src/aQute/bnd/plugin/jpms/JPMSModuleInfoPlugin.java @@ -51,7 +51,6 @@ import java.util.Set; import java.util.function.Supplier; import java.util.jar.Manifest; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.slf4j.Logger; @@ -227,14 +226,12 @@ private String getModuleName(Analyzer analyzer, JPMSModule m, Parameters moduleI return null; } - moduleName = jar.getName(); - Matcher matcher = mangledModuleName.matcher(moduleName); - if (matcher.matches()) { - moduleName = matcher.group(1); - } + moduleName = JPMSModule.cleanupName(jar.getName()); final String name = moduleName; moduleName = moduleInfoOptions.stream() - .filterValue(attrs -> name.equals(attrs.get(SUBSTITUTE_ATTRIBUTE))) + .mapValue(attrs -> attrs.get(SUBSTITUTE_ATTRIBUTE)) + .mapValue(JPMSModule::cleanupName) + .filterValue(s -> name.equals(s)) .keys() .findFirst() .orElse(moduleName); diff --git a/biz.aQute.bndlib/test/aQute/bnd/osgi/JPMSModuleTest.java b/biz.aQute.bndlib/test/aQute/bnd/osgi/JPMSModuleTest.java new file mode 100644 index 0000000000..4d0c7ff770 --- /dev/null +++ b/biz.aQute.bndlib/test/aQute/bnd/osgi/JPMSModuleTest.java @@ -0,0 +1,29 @@ +package aQute.bnd.osgi; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.jupiter.api.Test; + +class JPMSModuleTest { + + @Test + void cleanupTest() { + assertThat(JPMSModule.cleanupName("foo-1.0.jar")).isEqualTo("foo"); + assertThat(JPMSModule.cleanupName("bar-foo.jar")).isEqualTo("bar.foo"); + assertThat(JPMSModule.cleanupName("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) + .isEqualTo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); + assertThat(JPMSModule.cleanupName("foo.jar")).isEqualTo("foo"); + assertThat(JPMSModule.cleanupName("foo")).isEqualTo("foo"); + assertThat(JPMSModule.cleanupName("foo.bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("-foo.bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("-foo.bar-")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("-foo......................bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("foo.--.bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("-------------------------foo.--.bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("-------------------------foo.-🙂-.bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("foo🙂bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName("\n\nfoo🙂bar")).isEqualTo("foo.bar"); + assertThat(JPMSModule.cleanupName(null)).isNull(); + } + +}