Skip to content

Commit 873a4b7

Browse files
committed
Fix module-info parsing: consider "open module" notation
1 parent 4f06080 commit 873a4b7

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/main/java/org/gradlex/javamodule/testing/internal/ModuleInfoParser.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ static String moduleName(String moduleInfoFileContent) {
6767
List<String> tokens = Arrays.asList(cleanedLine.split("\\s+"));
6868
if (moduleKeywordFound && !tokens.isEmpty()) {
6969
return tokens.get(0);
70-
} else if (tokens.indexOf("module") == 0) {
71-
moduleKeywordFound = true;
7270
}
73-
if (tokens.size() > 1) {
74-
return tokens.get(1);
71+
72+
int moduleKeywordIndex = tokens.indexOf("module");
73+
if (moduleKeywordIndex == 0 || moduleKeywordIndex == 1) {
74+
if (tokens.size() > moduleKeywordIndex) {
75+
return tokens.get(moduleKeywordIndex + 1);
76+
}
77+
moduleKeywordFound = true;
7578
}
7679
}
7780
return null;

src/test/groovy/org/gradlex/javamodule/testing/internal/ModuleInfoParseTest.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,20 @@ class ModuleInfoParseTest extends Specification {
5959
expect:
6060
nameFromFile == 'some.thing'
6161
}
62+
63+
def "finds module name when open keyword is used"() {
64+
given:
65+
def nameFromFile = ModuleInfoParser.moduleName('''
66+
open module /*module some.other*/ some.thing { /* module
67+
odd comment*/ requires transitive foo.bar.la;
68+
requires/* weird comment*/ static foo.bar.lo;
69+
requires /*something to say*/foo.bar.li; /*
70+
requires only.a.comment
71+
*/
72+
}
73+
''')
74+
75+
expect:
76+
nameFromFile == 'some.thing'
77+
}
6278
}

0 commit comments

Comments
 (0)