plugin_ = new ArrayList<>();
@@ -112,7 +117,6 @@ public class CompileOptions {
return this;
}
-
/**
* Allow using declarations only from the specified version of Kotlin bundled libraries.
*
@@ -251,13 +255,27 @@ public class CompileOptions {
// @argfile
if (!argFile_.isEmpty()) {
- argFile_.forEach(f -> args.add("@" + f.getAbsolutePath()));
- }
-
- // classpath
- if (!classpath_.isEmpty()) {
- args.add("-classpath");
- args.add(classpath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(File.pathSeparator)));
+ argFile_.forEach(f -> {
+ if (f.exists()) {
+ try {
+ try (var reader = Files.newBufferedReader(f.toPath(), Charset.defaultCharset())) {
+ var tokenizer = new AbstractToolProviderOperation.CommandLineTokenizer(reader);
+ String token;
+ while ((token = tokenizer.nextToken()) != null) {
+ args.add(token);
+ }
+ }
+ } catch (IOException e) {
+ if (LOGGER.isLoggable(Level.WARNING)) {
+ LOGGER.log(Level.WARNING, "Could not read: " + f.getAbsolutePath(), e);
+ }
+ }
+ } else {
+ if (LOGGER.isLoggable(Level.WARNING)) {
+ LOGGER.warning("File not found: " + f.getAbsolutePath());
+ }
+ }
+ });
}
// expression
@@ -293,11 +311,6 @@ public class CompileOptions {
args.add("-Xjdk-release=" + jdkRelease_);
}
- // JVM options
- if (!jvmOptions_.isEmpty()) {
- jvmOptions_.forEach(s -> args.add("-J" + s));
- }
-
// kotlin-home
if (kotlinHome_ != null) {
args.add("-kotlin-home");
@@ -375,7 +388,7 @@ public class CompileOptions {
args.add("-verbose");
}
- // Wwrror
+ // Werror
if (wError_) {
args.add("-Werror");
}
@@ -385,9 +398,15 @@ public class CompileOptions {
args.add("-Wextra");
}
- // advanced option (X)
+ // advanced options (X)
if (!advancedOptions_.isEmpty()) {
- advancedOptions_.forEach(it -> args.add("-X" + it));
+ advancedOptions_.forEach(it -> {
+ if (it.startsWith("-X")) {
+ args.add(it);
+ } else {
+ args.add("-X" + it);
+ }
+ });
}
return args;
@@ -678,7 +697,7 @@ public class CompileOptions {
* Limit the API of the JDK in the classpath to the specified Java version. Automatically sets
* {@link #jvmTarget(String) JVM target} version.
*
- * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
+ * Possible values are 1.8, 9, 10, ..., 23. The default value is 1.8.
*
* @param version the target version
* @return this operation instance
@@ -693,8 +712,6 @@ public class CompileOptions {
*
* Limit the API of the JDK in the classpath to the specified Java version. Automatically sets
* {@link #jvmTarget(String) JVM target} version.
- *
- * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
*
* @param version the target version
* @return this operation instance
@@ -704,36 +721,6 @@ public class CompileOptions {
return jdkRelease(String.valueOf(version));
}
- /**
- * Retrieves the Java Virtual Machine options.
- *
- * @return the JVM options
- */
- public Collection jvmOptions() {
- return jvmOptions_;
- }
-
- /**
- * Pass an option directly to Java Virtual Machine
- *
- * @param jvmOptions the JVM options
- * @return this operation instance
- */
- public CompileOptions jvmOptions(Collection jvmOptions) {
- jvmOptions_.addAll(jvmOptions);
- return this;
- }
-
- /**
- * Pass an option directly to JVM
- *
- * @param jvmOptions one or more JVM option
- * @return this operation instance
- */
- public CompileOptions jvmOptions(String... jvmOptions) {
- return jvmOptions(List.of(jvmOptions));
- }
-
/**
* Specify the target version of the generated JVM bytecode.
*
@@ -748,7 +735,7 @@ public class CompileOptions {
/**
* Specify the target version of the generated JVM bytecode.
*
- * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
+ * Possible values are 1.8, 9, 10, ..., 23. The default value is 1.8.
*
* @param target the target version
* @return this operation instance
diff --git a/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java b/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java
index bbf3304..f1fd584 100644
--- a/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java
+++ b/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
package rife.bld.extension.kotlin;
/**
+ * @author Erik C. Thauvin
* Defines the known Kotlin compiler plugin JARs.
*
* @author Erik C. Thauvin
@@ -25,6 +26,8 @@ package rife.bld.extension.kotlin;
public enum CompilerPlugin {
ALL_OPEN("allopen-compiler-plugin.jar"),
ASSIGNMENT("assignment-compiler-plugin.jar"),
+ COMPOSE("compose-compiler-plugin.jar"),
+ KOTLIN_IMPORTS_DUMPER("kotlin-imports-dumper-compiler-plugin.jar"),
KOTLINX_SERIALIZATION("kotlinx-serialization-compiler-plugin.jar"),
KOTLIN_SERIALIZATION("kotlin-serialization-compiler-plugin.jar"),
LOMBOK("lombok-compiler-plugin.jar"),
diff --git a/src/main/java/rife/bld/extension/kotlin/JvmOptions.java b/src/main/java/rife/bld/extension/kotlin/JvmOptions.java
new file mode 100644
index 0000000..7e2ec62
--- /dev/null
+++ b/src/main/java/rife/bld/extension/kotlin/JvmOptions.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rife.bld.extension.kotlin;
+
+import rife.tools.StringUtils;
+
+import java.io.Serial;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * Java Virtual Machine options.
+ *
+ * @author Erik C. Thauvin
+ * @since 1.1.0
+ */
+@SuppressWarnings("PMD.LooseCoupling")
+public class JvmOptions extends ArrayList {
+ /**
+ * Keyword to enable native access for all code on the class path.
+ */
+ public final static String ALL_UNNAMED = "ALL-UNNAMED";
+
+ @Serial
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Modules that are permitted to perform restricted native operations.
+ * The module name can also be {@link #ALL_UNNAMED}.
+ *
+ * @param modules the module names
+ * @return this list of options
+ */
+ public JvmOptions enableNativeAccess(String... modules) {
+ return enableNativeAccess(List.of(modules));
+ }
+
+ /**
+ * Modules that are permitted to perform restricted native operations.
+ * The module name can also be {@link #ALL_UNNAMED}.
+ *
+ * @param modules the module names
+ * @return this list of options
+ */
+ public JvmOptions enableNativeAccess(Collection modules) {
+ add("--enable-native-access=" + StringUtils.join(modules, ","));
+ return this;
+ }
+
+ /**
+ * Controls what action the Java runtime takes when native access is not enabled for a module.
+ *
+ * @param access the access mode
+ * @return this list of options
+ */
+ public JvmOptions illegalNativeAccess(NativeAccess access) {
+ add("--illegal-native-access=" + access.mode);
+ return this;
+ }
+
+ /**
+ * Illegal native access modes.
+ */
+ public enum NativeAccess {
+ ALLOW("allow"),
+ DENY("deny"),
+ WARN("warn");
+
+ public final String mode;
+
+ NativeAccess(String mode) {
+ this.mode = mode;
+ }
+ }
+}
diff --git a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
index efea216..4e0182e 100644
--- a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
+++ b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import rife.bld.BaseProject;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin;
+import rife.bld.extension.kotlin.JvmOptions;
import rife.tools.FileUtils;
import java.io.File;
@@ -30,6 +31,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
import java.util.Objects;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
@@ -86,7 +88,7 @@ class CompileKotlinOperationTest {
@Test
void testCollections() {
var op = new CompileKotlinOperation()
- .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example"))
+ .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example", "Example"))
.kotlinHome("/kotlin_home")
.kotlinc("kotlinc")
.workDir("work_dir")
@@ -103,11 +105,11 @@ class CompileKotlinOperationTest {
.testSourceFiles(List.of(new File("tfile3"), new File("tfile4")))
.testSourceFiles(new File("tfile5"), new File("tfile6"))
.plugins("plugin1", "plugin2")
- .plugins(CompilerPlugin.KOTLIN_SERIALIZATION, CompilerPlugin.ASSIGNMENT)
+ .plugins(CompilerPlugin.KOTLIN_SERIALIZATION, CompilerPlugin.ASSIGNMENT, CompilerPlugin.COMPOSE)
.plugins(new File("lib/compile"), CompilerPlugin.LOMBOK, CompilerPlugin.POWER_ASSERT)
- .plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN)
+ .plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN,
+ CompilerPlugin.KOTLIN_IMPORTS_DUMPER)
.plugins("lib/compile", CompilerPlugin.KOTLINX_SERIALIZATION, CompilerPlugin.SAM_WITH_RECEIVER)
-
.plugins(List.of("plugin3", "plugin4"));
try (var softly = new AutoCloseableSoftAssertions()) {
@@ -131,12 +133,14 @@ class CompileKotlinOperationTest {
new File("tfile1"), new File("tfile2"), new File("tfile3"),
new File("tfile4"), new File("tfile5"), new File("tfile6"));
softly.assertThat(op.plugins()).as("plugins").contains("plugin1", "plugin2", "plugin3", "plugin4",
- "/kotlin_home/lib/kotlin-serialization-compiler-plugin.jar",
- "/kotlin_home/lib/assignment-compiler-plugin.jar",
+ new File("/kotlin_home/lib/kotlin-serialization-compiler-plugin.jar").getAbsolutePath(),
+ new File("/kotlin_home/lib/assignment-compiler-plugin.jar").getAbsolutePath(),
+ new File("/kotlin_home/lib/compose-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "lombok-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "power-assert-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "noarg-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "allopen-compiler-plugin.jar").getAbsolutePath(),
+ new File("lib/compile", "kotlin-imports-dumper-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "kotlinx-serialization-compiler-plugin.jar").getAbsolutePath(),
new File("lib/compile", "sam-with-receiver-compiler-plugin.jar").getAbsolutePath());
}
@@ -167,8 +171,7 @@ class CompileKotlinOperationTest {
}
var op = new CompileKotlinOperation()
- .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
- "Example"))
+ .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example", "Example"))
.buildMainDirectory(mainDir)
.buildTestDirectory(testDir)
.compileMainClasspath(compileJars)
@@ -177,10 +180,16 @@ class CompileKotlinOperationTest {
.compileTestClasspath(mainDir.getAbsolutePath());
op.compileOptions().verbose(true);
- op.compileOptions().jdkRelease("17");
+ op.compileOptions().argFile("src/test/resources/argfile.txt", "src/test/resources/argfile2.txt");
+
+ if (!CompileKotlinOperation.isWindows()) {
+ op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
+ assertThat(op.jvmOptions()).containsExactly("--enable-native-access=ALL-UNNAMED");
+ }
var args = op.compileOptions().args();
- var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
+ var matches = List.of("-Xjdk-release=17", "-no-reflect", "-progressive", "-include-runtime", "-no-stdlib",
+ "-verbose");
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
op.execute();
@@ -205,14 +214,43 @@ class CompileKotlinOperationTest {
}
}
+ @Test
+ void testFindKotlincPath() {
+ assertThat(CompileKotlinOperation.findKotlincPath()).doesNotStartWith("kotlinc");
+ }
+
+ @Test
+ void testFromProject() {
+ var examples = new File("examples");
+ var op = new CompileKotlinOperation().fromProject(
+ new BaseProjectBlueprint(examples, "com.example", "examples", "examples"));
+ assertThat(op.mainSourceDirectories()).containsExactly(new File(examples, "src/main/kotlin"));
+ assertThat(op.testSourceDirectories()).containsExactly(new File(examples, "src/test/kotlin"));
+ }
+
@Test
void testFromProjectNoKotlin() {
var op = new CompileKotlinOperation().fromProject(
- new BaseProjectBlueprint(new File("foo"), "org.example", "foo"));
+ new BaseProjectBlueprint(new File("foo"), "org.example", "foo", "foo"));
assertThat(op.mainSourceDirectories()).isEmpty();
assertThat(op.testSourceDirectories()).isEmpty();
}
+ @Test
+ void testIsOS() {
+ var osName = System.getProperty("os.name");
+ if (osName != null) {
+ var os = osName.toLowerCase(Locale.US);
+ if (os.contains("win")) {
+ assertThat(CompileKotlinOperation.isWindows()).isTrue();
+ } else if (os.contains("linux") || os.contains("unix")) {
+ assertThat(CompileKotlinOperation.isLinux()).isTrue();
+ } else if (os.contains("mac") || os.contains("darwin")) {
+ assertThat(CompileKotlinOperation.isMacOS()).isTrue();
+ }
+ }
+ }
+
@Test
void testKotlinHome() {
var foo = new File("foo");
@@ -314,6 +352,8 @@ class CompileKotlinOperationTest {
.fromProject(new BaseProject())
.plugins(CompilerPlugin.ALL_OPEN,
CompilerPlugin.ASSIGNMENT,
+ CompilerPlugin.COMPOSE,
+ CompilerPlugin.KOTLIN_IMPORTS_DUMPER,
CompilerPlugin.KOTLINX_SERIALIZATION,
CompilerPlugin.KOTLIN_SERIALIZATION,
CompilerPlugin.LOMBOK,
diff --git a/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java b/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
index 3bc9e25..c6e6965 100644
--- a/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
+++ b/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2024 the original author or authors.
+ * Copyright 2023-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package rife.bld.extension.kotlin;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
import java.io.File;
import java.io.IOException;
@@ -45,14 +47,11 @@ class CompileOptionsTest {
.collect(Collectors.joining(File.pathSeparator));
}
-
@Test
@SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
void testArgs() {
var options = new CompileOptions()
.apiVersion("11")
- .argFile(new File("file.txt"), new File("file2.txt"))
- .classpath(new File("path1"), new File("path2"))
.javaParameters(true)
.jvmTarget("11")
.includeRuntime(true)
@@ -76,8 +75,6 @@ class CompileOptionsTest {
var matches = List.of(
"-api-version", "11",
- "@" + localPath("file.txt"), "@" + localPath("file2.txt"),
- "-classpath", localPath("path1", "path2"),
"-java-parameters",
"-jvm-target", "11",
"-include-runtime",
@@ -115,10 +112,9 @@ class CompileOptionsTest {
@Test
void testArgsCollections() {
- var advanceOptions = List.of("Xoption1", "Xoption2");
+ var advanceOptions = List.of("-Xoption1", "option=2");
var argFile = List.of(new File("arg1.txt"), new File("arg2.txt"));
var classpath = List.of(new File("path1"), new File("path2"));
- var jvmOptions = List.of("option1", "option2");
var optIn = List.of("opt1", "opt2");
var options = List.of("-foo", "-bar");
var plugin = List.of("id:name:value", "id2:name2:value2");
@@ -128,7 +124,6 @@ class CompileOptionsTest {
.advancedOptions(advanceOptions)
.argFile(argFile)
.classpath(classpath)
- .jvmOptions(jvmOptions)
.noStdLib(false)
.optIn(optIn)
.options(options)
@@ -146,8 +141,6 @@ class CompileOptionsTest {
.hasSize(argFile.size()).containsAll(argFile);
softly.assertThat(op.classpath()).as("classpath")
.hasSize(classpath.size()).containsAll(classpath);
- softly.assertThat(op.jvmOptions()).as("jvmOptions")
- .hasSize(jvmOptions.size()).containsAll(jvmOptions);
softly.assertThat(op.optIn()).as("optIn")
.hasSize(optIn.size()).containsAll(optIn);
softly.assertThat(op.options()).as("options")
@@ -167,7 +160,7 @@ class CompileOptionsTest {
"-foo", "-bar",
"-script-templates",
"temp1,temp2",
- "-XXoption1", "-XXoption2",
+ "-Xoption1", "-Xoption=2",
"-P", "plugin:id:name:value",
"-P", "plugin:id2:name2:value2");
@@ -192,20 +185,27 @@ class CompileOptionsTest {
var bar = new File("bar.txt");
var options = new CompileOptions();
+ options = options.argFile(foo);
+ assertThat(options.argFile()).contains(foo);
+ options.argFile().clear();
+ assertThat(options.argFile()).isEmpty();
+
options.argFile(foo, bar);
assertThat(options.argFile()).contains(foo, bar);
options.argFile().clear();
+ assertThat(options.argFile()).isEmpty();
options = options.argFile(foo.toPath(), bar.toPath());
assertThat(options.argFile()).contains(foo, bar);
options.argFile().clear();
+ assertThat(options.argFile()).isEmpty();
- options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
+ options = options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
assertThat(options.argFile()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
- options.argFile().clear();
}
@Test
+ @EnabledOnOs(OS.LINUX)
void testCheckAllParams() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "kotlinc-args.txt"));
@@ -214,10 +214,7 @@ class CompileOptionsTest {
var params = new CompileOptions()
.advancedOptions("Xoption")
.apiVersion("11")
- .argFile("file")
- .classpath("classpath")
.expression("expression")
- .jvmOptions("option")
.includeRuntime(true)
.javaParameters(true)
.jdkHome("jdkhome")
@@ -239,6 +236,10 @@ class CompileOptionsTest {
.wError(true)
.wExtra(true);
+ var skipArgs = List.of("-J", "-classpath", "@");
+ assertThat(args).as(skipArgs + " not found.").containsAll(skipArgs);
+ args.removeAll(skipArgs);
+
try (var softly = new AutoCloseableSoftAssertions()) {
for (var p : args) {
var found = false;
@@ -259,31 +260,45 @@ class CompileOptionsTest {
var bar = new File("bar.txt");
var options = new CompileOptions();
+ options = options.classpath(foo);
+ assertThat(options.classpath()).as("File").containsExactly(foo);
+ options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
+
+
options.classpath(foo, bar);
assertThat(options.classpath()).as("File...").containsExactly(foo, bar);
options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
+
options.classpath(List.of(foo, bar));
assertThat(options.classpath()).as("List(File...)").containsExactly(foo, bar);
options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
+
options = options.classpath(foo.toPath(), bar.toPath());
assertThat(options.classpath()).as("Path...").containsExactly(foo, bar);
options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
+
options = options.classpathPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(options.classpath()).as("List(Path...)").containsExactly(foo, bar);
options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
+
options.classpath(foo.getAbsolutePath(), bar.getAbsolutePath());
assertThat(options.classpath()).as("String...")
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
options.classpath().clear();
+ assertThat(options.argFile()).isEmpty();
options.classpathStrings(List.of(foo.getAbsolutePath(), bar.getAbsolutePath()));
assertThat(options.classpath()).as("List(String...)")
.containsExactly(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
- options.classpath().clear();
}
@Test
diff --git a/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java b/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
new file mode 100644
index 0000000..6f8474f
--- /dev/null
+++ b/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2023-2025 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package rife.bld.extension.kotlin;
+
+import org.junit.jupiter.api.Test;
+import rife.bld.extension.CompileKotlinOperation;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+@SuppressWarnings("PMD.AvoidDuplicateLiterals")
+class JvmOptionsTest {
+ @Test
+ void testop() {
+ var op = new CompileKotlinOperation().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
+ assertThat(op.jvmOptions()).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
+
+ op = new CompileKotlinOperation().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
+ assertThat(op.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
+ }
+
+ @Test
+ void testEnableNativeAccess() {
+ var options = new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
+ assertThat(options).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
+
+ options = new JvmOptions().enableNativeAccess("m1");
+ assertThat(options).as("m1").containsExactly("--enable-native-access=m1");
+
+ options = new JvmOptions().enableNativeAccess("m1", "m2");
+ assertThat(options).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
+ }
+
+ @Test
+ void testIllegalNativeAccess() {
+ var options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW);
+ assertThat(options).as("ALLOW").containsExactly("--illegal-native-access=allow");
+
+ options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.DENY);
+ assertThat(options).as("DENY").containsExactly("--illegal-native-access=deny");
+
+ options = new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.WARN);
+ assertThat(options).as("WARN").containsExactly("--illegal-native-access=warn");
+ }
+
+ @Test
+ void testJvmOptions() {
+ var op = new CompileKotlinOperation().jvmOptions("option1", "option2");
+ assertThat(op.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
+
+ op = new CompileKotlinOperation().jvmOptions(List.of("option1", "option2"));
+ assertThat(op.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
+
+ op = op.jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
+ assertThat(op.jvmOptions()).as("List.of(option1,option2,ALL_UNNAMED)")
+ .containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED");
+
+ op = op.jvmOptions(new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW));
+ assertThat(op.jvmOptions()).as("allow")
+ .containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED",
+ "--illegal-native-access=allow");
+ }
+}
diff --git a/src/test/resources/argfile.txt b/src/test/resources/argfile.txt
new file mode 100644
index 0000000..d128d62
--- /dev/null
+++ b/src/test/resources/argfile.txt
@@ -0,0 +1,3 @@
+-Xjdk-release=17 -no-reflect
+
+-progressive
diff --git a/src/test/resources/argfile2.txt b/src/test/resources/argfile2.txt
new file mode 100644
index 0000000..93f9181
--- /dev/null
+++ b/src/test/resources/argfile2.txt
@@ -0,0 +1 @@
+-include-runtime
\ No newline at end of file