plugin_ = new ArrayList<>();
@@ -65,7 +60,6 @@ public class CompileOptions {
private boolean progressive_;
private boolean verbose_;
private boolean wError_;
- private boolean wExtra_;
/**
* Specify advanced compiler options.
@@ -117,6 +111,7 @@ public class CompileOptions {
return this;
}
+
/**
* Allow using declarations only from the specified version of Kotlin bundled libraries.
*
@@ -255,27 +250,13 @@ public class CompileOptions {
// @argfile
if (!argFile_.isEmpty()) {
- 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());
- }
- }
- });
+ 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)));
}
// expression
@@ -311,6 +292,11 @@ 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");
@@ -393,20 +379,9 @@ public class CompileOptions {
args.add("-Werror");
}
- // Wextra
- if (wExtra_) {
- args.add("-Wextra");
- }
-
- // advanced options (X)
+ // advanced option (X)
if (!advancedOptions_.isEmpty()) {
- advancedOptions_.forEach(it -> {
- if (it.startsWith("-X")) {
- args.add(it);
- } else {
- args.add("-X" + it);
- }
- });
+ advancedOptions_.forEach(it -> args.add("-X" + it));
}
return args;
@@ -622,15 +597,6 @@ public class CompileOptions {
return wError_;
}
- /**
- * Indicates whether additional declaration, expression, and type compiler checks emit warnings.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isWExtra() {
- return wExtra_;
- }
-
/**
* Generate metadata for Java 1.8 reflection on method parameters.
*
@@ -697,7 +663,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, ..., 23. The default value is 1.8.
+ * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
*
* @param version the target version
* @return this operation instance
@@ -712,6 +678,8 @@ 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
@@ -721,6 +689,36 @@ 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.
*
@@ -735,7 +733,7 @@ public class CompileOptions {
/**
* Specify the target version of the generated JVM bytecode.
*
- * Possible values are 1.8, 9, 10, ..., 23. The default value is 1.8.
+ * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
*
* @param target the target version
* @return this operation instance
@@ -1073,15 +1071,4 @@ public class CompileOptions {
wError_ = wError;
return this;
}
-
- /**
- * Enable additional declaration, expression, and type compiler checks that emit warnings if {@code true}.
- *
- * @param wExtra {@code true} or {@code false}
- * @return this operation instance
- */
- public CompileOptions wExtra(boolean wExtra) {
- wExtra_ = wExtra;
- return this;
- }
}
diff --git a/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java b/src/main/java/rife/bld/extension/kotlin/CompilerPlugin.java
index f1fd584..bbf3304 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-2025 the original author or authors.
+ * Copyright 2023-2024 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,7 +17,6 @@
package rife.bld.extension.kotlin;
/**
- * @author Erik C. Thauvin
* Defines the known Kotlin compiler plugin JARs.
*
* @author Erik C. Thauvin
@@ -26,8 +25,6 @@ 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
deleted file mode 100644
index 7e2ec62..0000000
--- a/src/main/java/rife/bld/extension/kotlin/JvmOptions.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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 4e0182e..85c8cff 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-2025 the original author or authors.
+ * Copyright 2023-2024 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.
@@ -16,14 +16,13 @@
package rife.bld.extension;
-import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import rife.bld.BaseProject;
+import rife.bld.Project;
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;
@@ -31,7 +30,6 @@ 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;
@@ -88,7 +86,7 @@ class CompileKotlinOperationTest {
@Test
void testCollections() {
var op = new CompileKotlinOperation()
- .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example", "Example"))
+ .fromProject(new Project())
.kotlinHome("/kotlin_home")
.kotlinc("kotlinc")
.workDir("work_dir")
@@ -105,45 +103,42 @@ 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, CompilerPlugin.COMPOSE)
+ .plugins(CompilerPlugin.KOTLIN_SERIALIZATION, CompilerPlugin.ASSIGNMENT)
.plugins(new File("lib/compile"), CompilerPlugin.LOMBOK, CompilerPlugin.POWER_ASSERT)
- .plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN,
- CompilerPlugin.KOTLIN_IMPORTS_DUMPER)
+ .plugins(Path.of("lib/compile"), CompilerPlugin.NOARG, CompilerPlugin.ALL_OPEN)
.plugins("lib/compile", CompilerPlugin.KOTLINX_SERIALIZATION, CompilerPlugin.SAM_WITH_RECEIVER)
+
.plugins(List.of("plugin3", "plugin4"));
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(op.kotlinHome().getName()).as("kotlin_home").isEqualTo("kotlin_home");
- softly.assertThat(op.kotlinc().getName()).as("kotlinc").isEqualTo("kotlinc");
- softly.assertThat(op.workDir().getName()).as("work_dir").isEqualTo("work_dir");
- softly.assertThat(op.compileMainClasspath()).as("compileMainClassPath")
- .containsAll(List.of("path1", "path2"));
- softly.assertThat(op.compileOptions().hasRelease()).as("hasRelease").isTrue();
- softly.assertThat(op.compileOptions().isVerbose()).as("isVerbose").isTrue();
- softly.assertThat(op.mainSourceDirectories()).as("mainSourceDirectories").containsExactly(
- Path.of("examples", "src", "main", "kotlin").toFile(), new File("dir1"),
- new File("dir2"), new File("dir3"), new File("dir4"));
- softly.assertThat(op.testSourceDirectories()).as("testSourceDirectories").containsOnly(
- Path.of("examples", "src", "test", "kotlin").toFile(), new File("tdir1"),
- new File("tdir2"), new File("tdir3"), new File("tdir4"));
- softly.assertThat(op.mainSourceFiles()).as("mainSourceFiles").containsOnly(
- new File("file1"), new File("file2"), new File("file3"),
- new File("file4"), new File("file5"), new File("file6"));
- softly.assertThat(op.testSourceFiles()).as("testSourceFiles").containsOnly(
- 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",
- 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());
- }
+ assertThat(op.kotlinHome().getName()).as("kotlin_home").isEqualTo("kotlin_home");
+ assertThat(op.kotlinc().getName()).as("kotlinc").isEqualTo("kotlinc");
+ assertThat(op.workDir().getName()).as("work_dir").isEqualTo("work_dir");
+
+ assertThat(op.compileMainClasspath()).as("compileMainClassPath")
+ .containsAll(List.of("path1", "path2"));
+ assertThat(op.compileOptions().hasRelease()).as("hasRelease").isTrue();
+ assertThat(op.compileOptions().isVerbose()).as("isVerbose").isTrue();
+ assertThat(op.mainSourceDirectories()).as("mainSourceDirectories").containsExactly(
+ Path.of("src", "main", "kotlin").toFile().getAbsoluteFile(), new File("dir1"),
+ new File("dir2"), new File("dir3"), new File("dir4"));
+ assertThat(op.testSourceDirectories()).as("testSourceDirectories").containsOnly(
+ Path.of("src", "test", "kotlin").toFile().getAbsoluteFile(), new File("tdir1"),
+ new File("tdir2"), new File("tdir3"), new File("tdir4"));
+ assertThat(op.mainSourceFiles()).as("mainSourceFiles").containsOnly(
+ new File("file1"), new File("file2"), new File("file3"),
+ new File("file4"), new File("file5"), new File("file6"));
+ assertThat(op.testSourceFiles()).as("testSourceFiles").containsOnly(
+ new File("tfile1"), new File("tfile2"), new File("tfile3"),
+ new File("tfile4"), new File("tfile5"), new File("tfile6"));
+ 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("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", "kotlinx-serialization-compiler-plugin.jar").getAbsolutePath(),
+ new File("lib/compile", "sam-with-receiver-compiler-plugin.jar").getAbsolutePath());
}
@Test
@@ -155,10 +150,8 @@ class CompileKotlinOperationTest {
var mainDir = new File(buildDir, "main");
var testDir = new File(buildDir, "test");
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(mainDir.mkdirs()).as("make mainDir").isTrue();
- softly.assertThat(testDir.mkdirs()).as("make testDir").isTrue();
- }
+ assertThat(mainDir.mkdirs()).as("make mainDir").isTrue();
+ assertThat(testDir.mkdirs()).as("make testDir").isTrue();
var compileJars = new ArrayList();
for (var f : Objects.requireNonNull(new File("examples/lib/compile").listFiles())) {
@@ -171,7 +164,8 @@ class CompileKotlinOperationTest {
}
var op = new CompileKotlinOperation()
- .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example", "Example", "Example"))
+ .fromProject(new BaseProjectBlueprint(new File("examples"), "com.example",
+ "Example"))
.buildMainDirectory(mainDir)
.buildTestDirectory(testDir)
.compileMainClasspath(compileJars)
@@ -180,32 +174,21 @@ class CompileKotlinOperationTest {
.compileTestClasspath(mainDir.getAbsolutePath());
op.compileOptions().verbose(true);
- 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");
- }
+ op.compileOptions().jdkRelease("17");
var args = op.compileOptions().args();
- var matches = List.of("-Xjdk-release=17", "-no-reflect", "-progressive", "-include-runtime", "-no-stdlib",
- "-verbose");
+ var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
assertThat(args).as(args + " == " + matches).isEqualTo(matches);
op.execute();
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(tmpDir).as("tmpDir").isNotEmptyDirectory();
- softly.assertThat(mainDir).as("mainDir").isNotEmptyDirectory();
- softly.assertThat(testDir).as("testDir").isNotEmptyDirectory();
- }
+ assertThat(tmpDir).as("tmpDir").isNotEmptyDirectory();
+ assertThat(mainDir).as("mainDir").isNotEmptyDirectory();
+ assertThat(testDir).as("testDir").isNotEmptyDirectory();
var mainOut = Path.of(mainDir.getAbsolutePath(), "com", "example").toFile();
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(new File(mainOut, "Example.class")).as("Example.class").exists();
- softly.assertThat(new File(mainOut, "Example$Companion.class"))
- .as("ExampleCompanion.class").exists();
- }
+ assertThat(new File(mainOut, "Example.class")).as("Example.class").exists();
+ assertThat(new File(mainOut, "Example$Companion.class")).as("ExampleCompanion.class").exists();
var testOut = Path.of(testDir.getAbsolutePath(), "com", "example").toFile();
assertThat(new File(testOut, "ExampleTest.class")).as("ExampleTest.class").exists();
@@ -214,43 +197,6 @@ 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", "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");
@@ -304,13 +250,11 @@ class CompileKotlinOperationTest {
op.mainSourceDirectories().clear();
op.mainSourceDirectoriesPaths(List.of(new File(FILE_1).toPath(), new File(FILE_2).toPath()));
- assertThat(op.mainSourceDirectories()).as("List(Path...)")
- .containsExactly(new File(FILE_1), new File(FILE_2));
+ assertThat(op.mainSourceDirectories()).as("List(Path...)").containsExactly(new File(FILE_1), new File(FILE_2));
op.mainSourceDirectories().clear();
op.mainSourceDirectoriesStrings(List.of(FILE_1, FILE_2));
- assertThat(op.mainSourceDirectories()).as("List(String...)")
- .containsExactly(new File(FILE_1), new File(FILE_2));
+ assertThat(op.mainSourceDirectories()).as("List(String...)").containsExactly(new File(FILE_1), new File(FILE_2));
op.mainSourceDirectories().clear();
}
@@ -352,8 +296,6 @@ 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,
@@ -361,10 +303,8 @@ class CompileKotlinOperationTest {
CompilerPlugin.POWER_ASSERT,
CompilerPlugin.SAM_WITH_RECEIVER);
- try (var softly = new AutoCloseableSoftAssertions()) {
- for (var p : op.plugins()) {
- softly.assertThat(new File(p)).as(p).exists();
- }
+ for (var p : op.plugins()) {
+ assertThat(new File(p)).as(p).exists();
}
}
diff --git a/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java b/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
index c6e6965..91ad563 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-2025 the original author or authors.
+ * Copyright 2023-2024 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.
@@ -16,10 +16,7 @@
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;
@@ -47,11 +44,14 @@ class CompileOptionsTest {
.collect(Collectors.joining(File.pathSeparator));
}
+
@Test
- @SuppressWarnings("PMD.UnitTestShouldIncludeAssert")
+ @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
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)
@@ -70,11 +70,12 @@ class CompileOptionsTest {
.progressive(true)
.scriptTemplates("name", "name2")
.verbose(true)
- .wError(true)
- .wExtra(true);
+ .wError(true);
var matches = List.of(
"-api-version", "11",
+ "@" + localPath("file.txt"), "@" + localPath("file2.txt"),
+ "-classpath", localPath("path1", "path2"),
"-java-parameters",
"-jvm-target", "11",
"-include-runtime",
@@ -95,26 +96,24 @@ class CompileOptionsTest {
"-progressive",
"-script-templates", "name,name2",
"-verbose",
- "-Werror",
- "-Wextra");
+ "-Werror");
var args = new ArrayList>();
args.add(options.args());
args.add(options.apiVersion(11).jvmTarget(11).args());
- try (var softly = new AutoCloseableSoftAssertions()) {
- for (var a : args) {
- IntStream.range(0, a.size()).forEach(i -> softly.assertThat(a.get(i))
- .as(a.get(i) + " == " + matches.get(i)).isEqualTo(matches.get(i)));
- }
+ for (var a : args) {
+ IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i))
+ .as(a.get(i) + " == " + matches.get(i)).isEqualTo(matches.get(i)));
}
}
@Test
void testArgsCollections() {
- var advanceOptions = List.of("-Xoption1", "option=2");
+ 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");
@@ -124,6 +123,7 @@ class CompileOptionsTest {
.advancedOptions(advanceOptions)
.argFile(argFile)
.classpath(classpath)
+ .jvmOptions(jvmOptions)
.noStdLib(false)
.optIn(optIn)
.options(options)
@@ -134,22 +134,22 @@ class CompileOptionsTest {
op.plugin(p[0], p[1], p[2]);
});
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(op.advancedOptions()).as("advancedOptions")
- .hasSize(advanceOptions.size()).containsAll(advanceOptions);
- softly.assertThat(op.argFile()).as("argFile")
- .hasSize(argFile.size()).containsAll(argFile);
- softly.assertThat(op.classpath()).as("classpath")
- .hasSize(classpath.size()).containsAll(classpath);
- softly.assertThat(op.optIn()).as("optIn")
- .hasSize(optIn.size()).containsAll(optIn);
- softly.assertThat(op.options()).as("options")
- .hasSize(options.size()).containsAll(options);
- softly.assertThat(op.plugin()).as("plugin")
- .hasSize(plugin.size()).containsAll(plugin);
- softly.assertThat(op.scriptTemplates()).as("scriptTemplates")
- .hasSize(scriptTemplates.size()).containsAll(scriptTemplates);
- }
+ assertThat(op.advancedOptions()).as("advancedOptions")
+ .hasSize(advanceOptions.size()).containsAll(advanceOptions);
+ assertThat(op.argFile()).as("argFile")
+ .hasSize(argFile.size()).containsAll(argFile);
+ assertThat(op.classpath()).as("classpath")
+ .hasSize(classpath.size()).containsAll(classpath);
+ assertThat(op.jvmOptions()).as("jvmOptions")
+ .hasSize(jvmOptions.size()).containsAll(jvmOptions);
+ assertThat(op.optIn()).as("optIn")
+ .hasSize(optIn.size()).containsAll(optIn);
+ assertThat(op.options()).as("options")
+ .hasSize(options.size()).containsAll(options);
+ assertThat(op.plugin()).as("plugin")
+ .hasSize(plugin.size()).containsAll(plugin);
+ assertThat(op.scriptTemplates()).as("scriptTemplates")
+ .hasSize(scriptTemplates.size()).containsAll(scriptTemplates);
var matches = List.of(
'@' + localPath("arg1.txt"), '@' + localPath("arg2.txt"),
@@ -160,22 +160,20 @@ class CompileOptionsTest {
"-foo", "-bar",
"-script-templates",
"temp1,temp2",
- "-Xoption1", "-Xoption=2",
+ "-XXoption1", "-XXoption2",
"-P", "plugin:id:name:value",
"-P", "plugin:id2:name2:value2");
- try (var softly = new AutoCloseableSoftAssertions()) {
- var args = op.args();
- for (var arg : args) {
- var found = false;
- for (var match : matches) {
- if (match.equals(arg)) {
- found = true;
- break;
- }
+ var args = op.args();
+ for (var arg : args) {
+ var found = false;
+ for (var match : matches) {
+ if (match.equals(arg)) {
+ found = true;
+ break;
}
- softly.assertThat(found).as(arg + " not found.").isTrue();
}
+ assertThat(found).as(arg + " not found.").isTrue();
}
}
@@ -185,27 +183,20 @@ 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 = options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
+ 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,7 +205,10 @@ class CompileOptionsTest {
var params = new CompileOptions()
.advancedOptions("Xoption")
.apiVersion("11")
+ .argFile("file")
+ .classpath("classpath")
.expression("expression")
+ .jvmOptions("option")
.includeRuntime(true)
.javaParameters(true)
.jdkHome("jdkhome")
@@ -233,24 +227,17 @@ class CompileOptionsTest {
.progressive(true)
.scriptTemplates("template")
.verbose(true)
- .wError(true)
- .wExtra(true);
+ .wError(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;
- for (var a : params.args()) {
- if (a.startsWith(p)) {
- found = true;
- break;
- }
+ for (var p : args) {
+ var found = false;
+ for (var a : params.args()) {
+ if (a.startsWith(p)) {
+ found = true;
+ break;
}
- softly.assertThat(found).as(p + " not found.").isTrue();
}
+ assertThat(found).as(p + " not found.").isTrue();
}
}
@@ -260,45 +247,31 @@ 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
@@ -358,36 +331,32 @@ class CompileOptionsTest {
.progressive(true)
.scriptTemplates("name", "name2")
.verbose(true)
- .wError(true)
- .wExtra(true);
+ .wError(true);
- try (var softly = new AutoCloseableSoftAssertions()) {
- softly.assertThat(options.advancedOptions()).containsExactly("xopt1", "xopt2");
- softly.assertThat(options.apiVersion()).isEqualTo("11");
- softly.assertThat(options.argFile()).containsExactly(new File("args.txt"));
- softly.assertThat(options.classpath()).containsExactly(new File("classpath"));
- softly.assertThat(options.expression()).isEqualTo("expression");
- softly.assertThat(options.isIncludeRuntime()).isTrue();
- softly.assertThat(options.isJavaParameters()).isTrue();
- softly.assertThat(options.isNoJdk()).isTrue();
- softly.assertThat(options.isNoReflect()).isTrue();
- softly.assertThat(options.isNoStdLib()).isTrue();
- softly.assertThat(options.isNoWarn()).isTrue();
- softly.assertThat(options.isProgressive()).isTrue();
- softly.assertThat(options.isVerbose()).isTrue();
- softly.assertThat(options.jdkHome()).isEqualTo(new File("jdk-home"));
- softly.assertThat(options.jdkRelease()).isEqualTo("22");
- softly.assertThat(options.jvmTarget()).isEqualTo("9");
- softly.assertThat(options.kotlinHome()).isEqualTo(new File("kotlin-home"));
- softly.assertThat(options.languageVersion()).isEqualTo("1.0");
- softly.assertThat(options.moduleName()).isEqualTo("module");
- softly.assertThat(options.optIn()).containsExactly("opt1", "opt2");
- softly.assertThat(options.options()).containsExactly("-foo", "-bar");
- softly.assertThat(options.path()).isEqualTo(new File("path"));
- softly.assertThat(options.plugin()).containsExactly("id:name:value");
- softly.assertThat(options.scriptTemplates()).containsExactly("name", "name2");
- softly.assertThat(options.isWError()).isTrue();
- softly.assertThat(options.isWExtra()).isTrue();
- }
+ assertThat(options.advancedOptions()).containsExactly("xopt1", "xopt2");
+ assertThat(options.apiVersion()).isEqualTo("11");
+ assertThat(options.argFile()).containsExactly(new File("args.txt"));
+ assertThat(options.classpath()).containsExactly(new File("classpath"));
+ assertThat(options.expression()).isEqualTo("expression");
+ assertThat(options.isIncludeRuntime()).isTrue();
+ assertThat(options.isJavaParameters()).isTrue();
+ assertThat(options.isNoJdk()).isTrue();
+ assertThat(options.isNoReflect()).isTrue();
+ assertThat(options.isNoStdLib()).isTrue();
+ assertThat(options.isNoWarn()).isTrue();
+ assertThat(options.isProgressive()).isTrue();
+ assertThat(options.isVerbose()).isTrue();
+ assertThat(options.jdkHome()).isEqualTo(new File("jdk-home"));
+ assertThat(options.jdkRelease()).isEqualTo("22");
+ assertThat(options.jvmTarget()).isEqualTo("9");
+ assertThat(options.kotlinHome()).isEqualTo(new File("kotlin-home"));
+ assertThat(options.languageVersion()).isEqualTo("1.0");
+ assertThat(options.moduleName()).isEqualTo("module");
+ assertThat(options.optIn()).containsExactly("opt1", "opt2");
+ assertThat(options.options()).containsExactly("-foo", "-bar");
+ assertThat(options.path()).isEqualTo(new File("path"));
+ assertThat(options.plugin()).containsExactly("id:name:value");
+ assertThat(options.scriptTemplates()).containsExactly("name", "name2");
+ assertThat(options.isWError()).isTrue();
}
}
diff --git a/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java b/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
deleted file mode 100644
index 6f8474f..0000000
--- a/src/test/java/rife/bld/extension/kotlin/JvmOptionsTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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
deleted file mode 100644
index d128d62..0000000
--- a/src/test/resources/argfile.txt
+++ /dev/null
@@ -1,3 +0,0 @@
--Xjdk-release=17 -no-reflect
-
--progressive
diff --git a/src/test/resources/argfile2.txt b/src/test/resources/argfile2.txt
deleted file mode 100644
index 93f9181..0000000
--- a/src/test/resources/argfile2.txt
+++ /dev/null
@@ -1 +0,0 @@
--include-runtime
\ No newline at end of file
diff --git a/src/test/resources/kotlinc-args.txt b/src/test/resources/kotlinc-args.txt
index e764231..b3c7f27 100644
--- a/src/test/resources/kotlinc-args.txt
+++ b/src/test/resources/kotlinc-args.txt
@@ -22,5 +22,4 @@
-script-templates
-verbose
-Werror
--Wextra
-X