Move jvmOptions to main compile operation

This commit is contained in:
Erik C. Thauvin 2025-03-23 02:18:31 -07:00
parent 3a012bf012
commit 125e9f7327
Signed by: erik
GPG key ID: 776702A6A2DA330E
6 changed files with 65 additions and 72 deletions

View file

@ -182,10 +182,14 @@ class CompileKotlinOperationTest {
op.compileOptions().verbose(true);
op.compileOptions().jdkRelease("17");
op.compileOptions().jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
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", "-J--enable-native-access=ALL-UNNAMED", "-no-stdlib", "-verbose");
var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
op.execute();

View file

@ -117,7 +117,6 @@ class CompileOptionsTest {
var advanceOptions = List.of("Xoption1", "Xoption2");
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");
@ -127,7 +126,6 @@ class CompileOptionsTest {
.advancedOptions(advanceOptions)
.argFile(argFile)
.classpath(classpath)
.jvmOptions(jvmOptions)
.noStdLib(false)
.optIn(optIn)
.options(options)
@ -145,8 +143,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")
@ -216,7 +212,6 @@ class CompileOptionsTest {
.argFile("file")
.classpath("classpath")
.expression("expression")
.jvmOptions("option")
.includeRuntime(true)
.javaParameters(true)
.jdkHome("jdkhome")

View file

@ -17,6 +17,7 @@
package rife.bld.extension.kotlin;
import org.junit.jupiter.api.Test;
import rife.bld.extension.CompileKotlinOperation;
import java.util.List;
@ -25,15 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class JvmOptionsTest {
@Test
void testCompileOptions() {
var compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
assertThat(compileOptions.jvmOptions()).as(JvmOptions.ALL_UNNAMED)
.containsExactly("--enable-native-access=ALL-UNNAMED");
assertThat(compileOptions.args()).as("args()").containsExactly("-J--enable-native-access=ALL-UNNAMED");
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");
compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
assertThat(compileOptions.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
assertThat(compileOptions.args()).as("args(m1,m2)").containsExactly("-J--enable-native-access=m1,m2");
op = new CompileKotlinOperation().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
assertThat(op.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
}
@Test
@ -62,26 +60,19 @@ class JvmOptionsTest {
@Test
void testJvmOptions() {
var compileOptions = new CompileOptions().jvmOptions("option1", "option2");
assertThat(compileOptions.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
assertThat(compileOptions.args()).as("args()").containsExactly("-Joption1", "-Joption2");
var op = new CompileKotlinOperation().jvmOptions("option1", "option2");
assertThat(op.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
compileOptions = new CompileOptions().jvmOptions(List.of("option1", "option2"));
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
assertThat(compileOptions.args()).as("args(list)").containsExactly("-Joption1", "-Joption2");
op = new CompileKotlinOperation().jvmOptions(List.of("option1", "option2"));
assertThat(op.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
compileOptions = compileOptions.jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2,ALL_UNNAMED)")
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");
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED)")
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED");
compileOptions = compileOptions.jvmOptions(new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW));
assertThat(compileOptions.jvmOptions()).as("allow")
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");
assertThat(compileOptions.args()).as("args(option1,option2,ALL_UNNAMED,allow)")
.containsExactly("-Joption1", "-Joption2", "-J--enable-native-access=ALL-UNNAMED",
"-J--illegal-native-access=allow");
}
}