Skip to content

Commit 583e25f

Browse files
authored
Merge pull request #281 from beryx/fix/279-annotated-module-info
fix #279 determine module name of annotated module
2 parents b299ea3 + 4434636 commit 583e25f

File tree

8 files changed

+81
-10
lines changed

8 files changed

+81
-10
lines changed

src/main/groovy/org/beryx/jlink/util/Util.groovy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ class Util {
6767

6868
private static final String IMPORT_DECLARATION = 'import' + IGNORE + '(static' + IGNORE + ')?' + QUALIFIED_NAME + '(\\.\\*' + ')?' + IGNORE + ';'
6969
private static final String IMPORT_DECLARATIONS = '(' + IMPORT_DECLARATION + IGNORE + ')*'
70-
private static final String MODULE_DECLARATION = '(?s)' + IGNORE + IMPORT_DECLARATIONS + '(open' + IGNORE + ')?' + 'module' + IGNORE + '(?<MODULE>' + QUALIFIED_NAME + ').*?'
70+
71+
private static final String ANNOTATION = '(@' + IGNORE + QUALIFIED_NAME + '((' + IGNORE + ')(\\([^)]*\\)))?)'
72+
private static final String MODULE_ANNOTATIONS = '(' + ANNOTATION + IGNORE + ')*'
73+
74+
private static final String MODULE_DECLARATION = '(?s)' + IGNORE + IMPORT_DECLARATIONS + MODULE_ANNOTATIONS + '(open' + IGNORE + ')?' + 'module' + IGNORE + '(?<MODULE>' + QUALIFIED_NAME + ').*?'
7175

7276
private static final Pattern PATTERN = Pattern.compile(MODULE_DECLARATION)
7377

src/test/groovy/org/beryx/jlink/JlinkPluginSpec.groovy

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ class JlinkPluginSpec extends Specification {
205205
checkOutput(result, 'helloBom', '{"from":"Alice","to":"Bob","greeting":"Hello"}')
206206
}
207207

208+
def "should create runtime image of project with annotations on module declaration"() {
209+
when:
210+
File buildFile = setUpBuild('hello-annotated-module')
211+
BuildResult result = GradleRunner.create()
212+
.withDebug(true)
213+
.withGradleVersion('7.6')
214+
.withProjectDir(testProjectDir.toFile())
215+
.withPluginClasspath()
216+
.withArguments(JlinkPlugin.TASK_NAME_JLINK, "-is")
217+
.build();
218+
219+
then:
220+
checkOutput(result, 'helloAnnotatedModule', 'Hello annotated module!')
221+
}
222+
208223
def "should create image of project with multiple launchers"() {
209224
when:
210225

src/test/groovy/org/beryx/jlink/UtilSpec.groovy

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ class UtilSpec extends Specification {
4444
Util.getModuleNameFrom(text) == moduleName
4545

4646
where:
47-
text | moduleName
48-
'module a.b.c\n{' | 'a.b.c'
49-
'open module a.b.c{}' | 'a.b.c'
50-
' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c'
51-
'/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c'
52-
'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c'
53-
'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
47+
text | moduleName
48+
'module a.b.c\n{' | 'a.b.c'
49+
'open module a.b.c{}' | 'a.b.c'
50+
' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c'
51+
'/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c'
52+
'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c'
53+
'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
54+
'import x.y.z.*;\n@Annotation\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
55+
'import x.y.z.*;\n@Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
56+
'import x.y.z.*;\n@ Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
57+
'import x.y.z.*;\n@Annotation\n(\n var = "text"\n)\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
5458
}
5559

5660
@Unroll
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id 'org.beryx.jlink'
3+
id 'org.javamodularity.moduleplugin' version '1.8.12'
4+
}
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
sourceCompatibility = 17
11+
targetCompatibility = 17
12+
13+
dependencies {
14+
implementation 'org.jspecify:jspecify:1.0.0'
15+
}
16+
17+
application {
18+
mainClass = 'org.beryx.modular.annotatedmodule.HelloAnnotatedModule'
19+
}
20+
jar {
21+
manifest {
22+
attributes 'Implementation-Title': 'helloAnnotatedModule',
23+
'Main-Class': application.mainClass
24+
}
25+
}
26+
27+
jlink {
28+
launcher {
29+
name = 'helloAnnotatedModule'
30+
}
31+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'helloAnnotatedModule'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import org.jspecify.annotations.NullMarked;
2+
3+
@NullMarked
4+
module org.beryx.modular.annotatedmodule {
5+
requires org.jspecify;
6+
opens org.beryx.modular.annotatedmodule;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.beryx.modular.annotatedmodule;
2+
3+
import java.io.StringReader;
4+
5+
public class HelloAnnotatedModule {
6+
public static void main(String[] args) throws Exception {
7+
System.out.println("Hello annotated module!");
8+
}
9+
}

src/test/resources/hello-toolchain/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ application {
2121

2222
java {
2323
toolchain {
24-
languageVersion = JavaLanguageVersion.of(23)
25-
vendor = JvmVendorSpec.ADOPTIUM
24+
languageVersion = JavaLanguageVersion.of(24)
25+
//vendor = JvmVendorSpec.ADOPTIUM
2626
}
2727
}
2828

0 commit comments

Comments
 (0)