Move jvmOptions to main compile operation
This commit is contained in:
parent
3a012bf012
commit
125e9f7327
6 changed files with 65 additions and 72 deletions
|
@ -60,14 +60,17 @@ public class ExampleBuild extends Project {
|
||||||
@BuildCommand(summary = "Compiles the Kotlin project")
|
@BuildCommand(summary = "Compiles the Kotlin project")
|
||||||
@Override
|
@Override
|
||||||
public void compile() throws Exception {
|
public void compile() throws Exception {
|
||||||
var options = new CompileOptions().verbose(true);
|
|
||||||
options.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
|
||||||
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
|
// The source code located in src/main/kotlin and src/test/kotlin will be compiled
|
||||||
new CompileKotlinOperation()
|
var op = new CompileKotlinOperation()
|
||||||
// .kotlinHome("path/to/kotlin")
|
// .kotlinHome("path/to/kotlin")
|
||||||
// .kotlinc("path/to/kotlinc")
|
// .kotlinc("path/to/kotlinc")
|
||||||
.compileOptions(options)
|
.compileOptions(new CompileOptions().verbose(true))
|
||||||
.fromProject(this)
|
.fromProject(this);
|
||||||
.execute();
|
|
||||||
|
if (!CompileKotlinOperation.isWindows()) {
|
||||||
|
op.jvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED);
|
||||||
|
}
|
||||||
|
|
||||||
|
op.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package rife.bld.extension;
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
import rife.bld.extension.kotlin.CompileOptions;
|
import rife.bld.extension.kotlin.CompileOptions;
|
||||||
import rife.bld.extension.kotlin.CompilerPlugin;
|
import rife.bld.extension.kotlin.CompilerPlugin;
|
||||||
|
import rife.bld.extension.kotlin.JvmOptions;
|
||||||
import rife.bld.operations.AbstractOperation;
|
import rife.bld.operations.AbstractOperation;
|
||||||
import rife.bld.operations.exceptions.ExitStatusException;
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
import rife.tools.FileUtils;
|
import rife.tools.FileUtils;
|
||||||
|
@ -43,6 +44,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
private static final String KOTLINC_EXECUTABLE = "kotlinc" + (isWindows() ? ".bat" : "");
|
private static final String KOTLINC_EXECUTABLE = "kotlinc" + (isWindows() ? ".bat" : "");
|
||||||
private final Collection<String> compileMainClasspath_ = new ArrayList<>();
|
private final Collection<String> compileMainClasspath_ = new ArrayList<>();
|
||||||
private final Collection<String> compileTestClasspath_ = new ArrayList<>();
|
private final Collection<String> compileTestClasspath_ = new ArrayList<>();
|
||||||
|
private final JvmOptions jvmOptions_ = new JvmOptions();
|
||||||
private final Collection<File> mainSourceDirectories_ = new ArrayList<>();
|
private final Collection<File> mainSourceDirectories_ = new ArrayList<>();
|
||||||
private final Collection<File> mainSourceFiles_ = new ArrayList<>();
|
private final Collection<File> mainSourceFiles_ = new ArrayList<>();
|
||||||
private final Collection<String> plugins_ = new ArrayList<>();
|
private final Collection<String> plugins_ = new ArrayList<>();
|
||||||
|
@ -479,6 +481,10 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
} else {
|
} else {
|
||||||
args.add(findKotlincPath(silent()));
|
args.add(findKotlincPath(silent()));
|
||||||
}
|
}
|
||||||
|
// JVM options
|
||||||
|
if (!jvmOptions_.isEmpty()) {
|
||||||
|
jvmOptions_.forEach(s -> command.add("-J" + s));
|
||||||
|
}
|
||||||
|
|
||||||
// classpath
|
// classpath
|
||||||
if (classpath != null && !classpath.isEmpty()) {
|
if (classpath != null && !classpath.isEmpty()) {
|
||||||
|
@ -607,6 +613,36 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
||||||
return op;
|
return op;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the Java Virtual Machine options.
|
||||||
|
*
|
||||||
|
* @return the JVM options
|
||||||
|
*/
|
||||||
|
public JvmOptions jvmOptions() {
|
||||||
|
return jvmOptions_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass an option directly to the Java Virtual Machine
|
||||||
|
*
|
||||||
|
* @param jvmOptions the JVM options
|
||||||
|
* @return this operation instance
|
||||||
|
*/
|
||||||
|
public CompileKotlinOperation jvmOptions(Collection<String> jvmOptions) {
|
||||||
|
jvmOptions_.addAll(jvmOptions);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pass an option directly to the Java Virtual Machine
|
||||||
|
*
|
||||||
|
* @param jvmOptions one or more JVM option
|
||||||
|
* @return this operation instance
|
||||||
|
*/
|
||||||
|
public CompileKotlinOperation jvmOptions(String... jvmOptions) {
|
||||||
|
return jvmOptions(List.of(jvmOptions));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Kotlin home directory, if it differs from the default {@code KOTLIN_HOME}.
|
* Provides the Kotlin home directory, if it differs from the default {@code KOTLIN_HOME}.
|
||||||
*
|
*
|
||||||
|
|
|
@ -37,7 +37,6 @@ public class CompileOptions {
|
||||||
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
private final Collection<String> advancedOptions_ = new ArrayList<>();
|
||||||
private final Collection<File> argFile_ = new ArrayList<>();
|
private final Collection<File> argFile_ = new ArrayList<>();
|
||||||
private final Collection<File> classpath_ = new ArrayList<>();
|
private final Collection<File> classpath_ = new ArrayList<>();
|
||||||
private final JvmOptions jvmOptions_ = new JvmOptions();
|
|
||||||
private final Collection<String> optIn_ = new ArrayList<>();
|
private final Collection<String> optIn_ = new ArrayList<>();
|
||||||
private final Collection<String> options_ = new ArrayList<>();
|
private final Collection<String> options_ = new ArrayList<>();
|
||||||
private final Collection<String> plugin_ = new ArrayList<>();
|
private final Collection<String> plugin_ = new ArrayList<>();
|
||||||
|
@ -293,11 +292,6 @@ public class CompileOptions {
|
||||||
args.add("-Xjdk-release=" + jdkRelease_);
|
args.add("-Xjdk-release=" + jdkRelease_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// JVM options
|
|
||||||
if (!jvmOptions_.isEmpty()) {
|
|
||||||
jvmOptions_.forEach(s -> args.add("-J" + s));
|
|
||||||
}
|
|
||||||
|
|
||||||
// kotlin-home
|
// kotlin-home
|
||||||
if (kotlinHome_ != null) {
|
if (kotlinHome_ != null) {
|
||||||
args.add("-kotlin-home");
|
args.add("-kotlin-home");
|
||||||
|
@ -704,36 +698,6 @@ public class CompileOptions {
|
||||||
return jdkRelease(String.valueOf(version));
|
return jdkRelease(String.valueOf(version));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves the Java Virtual Machine options.
|
|
||||||
*
|
|
||||||
* @return the JVM options
|
|
||||||
*/
|
|
||||||
public JvmOptions jvmOptions() {
|
|
||||||
return jvmOptions_;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pass an option directly to the Java Virtual Machine
|
|
||||||
*
|
|
||||||
* @param jvmOptions the JVM options
|
|
||||||
* @return this operation instance
|
|
||||||
*/
|
|
||||||
public CompileOptions jvmOptions(Collection<String> jvmOptions) {
|
|
||||||
jvmOptions_.addAll(jvmOptions);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pass an option directly to the Java Virtual Machine
|
|
||||||
*
|
|
||||||
* @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.
|
* Specify the target version of the generated JVM bytecode.
|
||||||
*
|
*
|
||||||
|
|
|
@ -182,10 +182,14 @@ class CompileKotlinOperationTest {
|
||||||
|
|
||||||
op.compileOptions().verbose(true);
|
op.compileOptions().verbose(true);
|
||||||
op.compileOptions().jdkRelease("17");
|
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 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);
|
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
|
||||||
|
|
||||||
op.execute();
|
op.execute();
|
||||||
|
|
|
@ -117,7 +117,6 @@ class CompileOptionsTest {
|
||||||
var advanceOptions = List.of("Xoption1", "Xoption2");
|
var advanceOptions = List.of("Xoption1", "Xoption2");
|
||||||
var argFile = List.of(new File("arg1.txt"), new File("arg2.txt"));
|
var argFile = List.of(new File("arg1.txt"), new File("arg2.txt"));
|
||||||
var classpath = List.of(new File("path1"), new File("path2"));
|
var classpath = List.of(new File("path1"), new File("path2"));
|
||||||
var jvmOptions = List.of("option1", "option2");
|
|
||||||
var optIn = List.of("opt1", "opt2");
|
var optIn = List.of("opt1", "opt2");
|
||||||
var options = List.of("-foo", "-bar");
|
var options = List.of("-foo", "-bar");
|
||||||
var plugin = List.of("id:name:value", "id2:name2:value2");
|
var plugin = List.of("id:name:value", "id2:name2:value2");
|
||||||
|
@ -127,7 +126,6 @@ class CompileOptionsTest {
|
||||||
.advancedOptions(advanceOptions)
|
.advancedOptions(advanceOptions)
|
||||||
.argFile(argFile)
|
.argFile(argFile)
|
||||||
.classpath(classpath)
|
.classpath(classpath)
|
||||||
.jvmOptions(jvmOptions)
|
|
||||||
.noStdLib(false)
|
.noStdLib(false)
|
||||||
.optIn(optIn)
|
.optIn(optIn)
|
||||||
.options(options)
|
.options(options)
|
||||||
|
@ -145,8 +143,6 @@ class CompileOptionsTest {
|
||||||
.hasSize(argFile.size()).containsAll(argFile);
|
.hasSize(argFile.size()).containsAll(argFile);
|
||||||
softly.assertThat(op.classpath()).as("classpath")
|
softly.assertThat(op.classpath()).as("classpath")
|
||||||
.hasSize(classpath.size()).containsAll(classpath);
|
.hasSize(classpath.size()).containsAll(classpath);
|
||||||
softly.assertThat(op.jvmOptions()).as("jvmOptions")
|
|
||||||
.hasSize(jvmOptions.size()).containsAll(jvmOptions);
|
|
||||||
softly.assertThat(op.optIn()).as("optIn")
|
softly.assertThat(op.optIn()).as("optIn")
|
||||||
.hasSize(optIn.size()).containsAll(optIn);
|
.hasSize(optIn.size()).containsAll(optIn);
|
||||||
softly.assertThat(op.options()).as("options")
|
softly.assertThat(op.options()).as("options")
|
||||||
|
@ -216,7 +212,6 @@ class CompileOptionsTest {
|
||||||
.argFile("file")
|
.argFile("file")
|
||||||
.classpath("classpath")
|
.classpath("classpath")
|
||||||
.expression("expression")
|
.expression("expression")
|
||||||
.jvmOptions("option")
|
|
||||||
.includeRuntime(true)
|
.includeRuntime(true)
|
||||||
.javaParameters(true)
|
.javaParameters(true)
|
||||||
.jdkHome("jdkhome")
|
.jdkHome("jdkhome")
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package rife.bld.extension.kotlin;
|
package rife.bld.extension.kotlin;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import rife.bld.extension.CompileKotlinOperation;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -25,15 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||||
class JvmOptionsTest {
|
class JvmOptionsTest {
|
||||||
@Test
|
@Test
|
||||||
void testCompileOptions() {
|
void testop() {
|
||||||
var compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
var op = new CompileKotlinOperation().jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
||||||
assertThat(compileOptions.jvmOptions()).as(JvmOptions.ALL_UNNAMED)
|
assertThat(op.jvmOptions()).as(JvmOptions.ALL_UNNAMED).containsExactly("--enable-native-access=ALL-UNNAMED");
|
||||||
.containsExactly("--enable-native-access=ALL-UNNAMED");
|
|
||||||
assertThat(compileOptions.args()).as("args()").containsExactly("-J--enable-native-access=ALL-UNNAMED");
|
|
||||||
|
|
||||||
compileOptions = new CompileOptions().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
|
op = new CompileKotlinOperation().jvmOptions(new JvmOptions().enableNativeAccess("m1", "m2"));
|
||||||
assertThat(compileOptions.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
assertThat(op.jvmOptions()).as("m1,m2").containsExactly("--enable-native-access=m1,m2");
|
||||||
assertThat(compileOptions.args()).as("args(m1,m2)").containsExactly("-J--enable-native-access=m1,m2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -62,26 +60,19 @@ class JvmOptionsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testJvmOptions() {
|
void testJvmOptions() {
|
||||||
var compileOptions = new CompileOptions().jvmOptions("option1", "option2");
|
var op = new CompileKotlinOperation().jvmOptions("option1", "option2");
|
||||||
assertThat(compileOptions.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
|
assertThat(op.jvmOptions()).as("option1,option2").containsExactly("option1", "option2");
|
||||||
assertThat(compileOptions.args()).as("args()").containsExactly("-Joption1", "-Joption2");
|
|
||||||
|
|
||||||
compileOptions = new CompileOptions().jvmOptions(List.of("option1", "option2"));
|
op = new CompileKotlinOperation().jvmOptions(List.of("option1", "option2"));
|
||||||
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
|
assertThat(op.jvmOptions()).as("List.of(option1,option2)").containsExactly("option1", "option2");
|
||||||
assertThat(compileOptions.args()).as("args(list)").containsExactly("-Joption1", "-Joption2");
|
|
||||||
|
|
||||||
compileOptions = compileOptions.jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
op = op.jvmOptions(new JvmOptions().enableNativeAccess(JvmOptions.ALL_UNNAMED));
|
||||||
assertThat(compileOptions.jvmOptions()).as("List.of(option1,option2,ALL_UNNAMED)")
|
assertThat(op.jvmOptions()).as("List.of(option1,option2,ALL_UNNAMED)")
|
||||||
.containsExactly("option1", "option2", "--enable-native-access=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));
|
op = op.jvmOptions(new JvmOptions().illegalNativeAccess(JvmOptions.NativeAccess.ALLOW));
|
||||||
assertThat(compileOptions.jvmOptions()).as("allow")
|
assertThat(op.jvmOptions()).as("allow")
|
||||||
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED",
|
.containsExactly("option1", "option2", "--enable-native-access=ALL-UNNAMED",
|
||||||
"--illegal-native-access=allow");
|
"--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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue