Skip to content

Commit

Permalink
There were test consequences.
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz>

Signed-off-by: Peter Kriens <Peter.Kriens@aQute.biz>
  • Loading branch information
pkriens committed Oct 10, 2023
1 parent a552452 commit e30400f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 26 deletions.
38 changes: 19 additions & 19 deletions biz.aQute.bndlib.tests/test/test/jpms/JPMSModuleInfoPluginTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -395,15 +395,15 @@ 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"));

assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("java.json.bind"))
.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);

Expand Down Expand Up @@ -459,15 +459,15 @@ 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"));

assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("java.json.bind"))
.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);

Expand Down Expand Up @@ -524,15 +524,15 @@ 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"));

assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("java.json.bind"))
.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);

Expand Down Expand Up @@ -588,15 +588,15 @@ 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"));

assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("java.json.bind"))
.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);

Expand Down Expand Up @@ -652,15 +652,15 @@ 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"));

assertThat(moduleAttribute.requires).filteredOn(e -> e.requires.equals("java.management"))
.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);

Expand Down Expand Up @@ -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"));

Expand All @@ -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);

Expand Down Expand Up @@ -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"));

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/JPMSModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions biz.aQute.bndlib/test/aQute/bnd/osgi/JPMSModuleTest.java
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit e30400f

Please sign in to comment.