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

fix #279 determine module name of annotated module #281

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/main/groovy/org/beryx/jlink/util/Util.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ class Util {

private static final String IMPORT_DECLARATION = 'import' + IGNORE + '(static' + IGNORE + ')?' + QUALIFIED_NAME + '(\\.\\*' + ')?' + IGNORE + ';'
private static final String IMPORT_DECLARATIONS = '(' + IMPORT_DECLARATION + IGNORE + ')*'
private static final String MODULE_DECLARATION = '(?s)' + IGNORE + IMPORT_DECLARATIONS + '(open' + IGNORE + ')?' + 'module' + IGNORE + '(?<MODULE>' + QUALIFIED_NAME + ').*?'

private static final String ANNOTATION = '(@' + IGNORE + QUALIFIED_NAME + '((' + IGNORE + ')(\\([^)]*\\)))?)'
private static final String MODULE_ANNOTATIONS = '(' + ANNOTATION + IGNORE + ')*'

private static final String MODULE_DECLARATION = '(?s)' + IGNORE + IMPORT_DECLARATIONS + MODULE_ANNOTATIONS + '(open' + IGNORE + ')?' + 'module' + IGNORE + '(?<MODULE>' + QUALIFIED_NAME + ').*?'

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

Expand Down
15 changes: 15 additions & 0 deletions src/test/groovy/org/beryx/jlink/JlinkPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ class JlinkPluginSpec extends Specification {
checkOutput(result, 'helloBom', '{"from":"Alice","to":"Bob","greeting":"Hello"}')
}

def "should create runtime image of project with annotations on module declaration"() {
when:
File buildFile = setUpBuild('hello-annotated-module')
BuildResult result = GradleRunner.create()
.withDebug(true)
.withGradleVersion('7.6')
.withProjectDir(testProjectDir.toFile())
.withPluginClasspath()
.withArguments(JlinkPlugin.TASK_NAME_JLINK, "-is")
.build();

then:
checkOutput(result, 'helloAnnotatedModule', 'Hello annotated module!')
}

def "should create image of project with multiple launchers"() {
when:

Expand Down
18 changes: 11 additions & 7 deletions src/test/groovy/org/beryx/jlink/UtilSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ class UtilSpec extends Specification {
Util.getModuleNameFrom(text) == moduleName

where:
text | moduleName
'module a.b.c\n{' | 'a.b.c'
'open module a.b.c{}' | 'a.b.c'
' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c'
'/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c'
'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c'
'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
text | moduleName
'module a.b.c\n{' | 'a.b.c'
'open module a.b.c{}' | 'a.b.c'
' \t open\t \tmodule \ta.b.c\t { ' | 'a.b.c'
'/*my module*/\nmodule /*---*/ a.b.c // declaration\n{\n exports a.b.c;\n}' | 'a.b.c'
'import x.y.Z;//comment\nimport x.y.W;\nmodule /*---*/ a.b.c' | 'a.b.c'
'import x.y.z.*;\nimport x.y/*WW*/./*ZZ*/w.*;\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
'import x.y.z.*;\n@Annotation\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
'import x.y.z.*;\n@Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
'import x.y.z.*;\n@ Annotation("text")\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
'import x.y.z.*;\n@Annotation\n(\n var = "text"\n)\nmodule //x.y.z\n/*-->*/a.b.c' | 'a.b.c'
}

@Unroll
Expand Down
31 changes: 31 additions & 0 deletions src/test/resources/hello-annotated-module/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id 'org.beryx.jlink'
id 'org.javamodularity.moduleplugin' version '1.8.12'
}

repositories {
mavenCentral()
}

sourceCompatibility = 17
targetCompatibility = 17

dependencies {
implementation 'org.jspecify:jspecify:1.0.0'
}

application {
mainClass = 'org.beryx.modular.annotatedmodule.HelloAnnotatedModule'
}
jar {
manifest {
attributes 'Implementation-Title': 'helloAnnotatedModule',
'Main-Class': application.mainClass
}
}

jlink {
launcher {
name = 'helloAnnotatedModule'
}
}
1 change: 1 addition & 0 deletions src/test/resources/hello-annotated-module/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'helloAnnotatedModule'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.jspecify.annotations.NullMarked;

@NullMarked
module org.beryx.modular.annotatedmodule {
requires org.jspecify;
opens org.beryx.modular.annotatedmodule;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.beryx.modular.annotatedmodule;

import java.io.StringReader;

public class HelloAnnotatedModule {
public static void main(String[] args) throws Exception {
System.out.println("Hello annotated module!");
}
}
4 changes: 2 additions & 2 deletions src/test/resources/hello-toolchain/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ application {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(23)
vendor = JvmVendorSpec.ADOPTIUM
languageVersion = JavaLanguageVersion.of(24)
//vendor = JvmVendorSpec.ADOPTIUM
}
}

Expand Down
Loading