paths) {
- return classpath(paths.stream().map(File::new).toList());
- }
-
- /**
- * Retrieves the string to evaluate as a Kotlin script.
- *
- * @return the expression
- */
- public String expression() {
- return expression_;
- }
-
/**
* Evaluate the given string as a Kotlin script.
*
@@ -509,69 +415,6 @@ public class CompileOptions {
return this;
}
- /**
- * Indicates whether the {@link #includeRuntime(boolean)} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isIncludeRuntime() {
- return includeRuntime_;
- }
-
- /**
- * Indicates whether {@link #javaParameters(boolean)} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isJavaParameters() {
- return javaParameters_;
- }
-
- /**
- * Indicates whether {@link #noJdk(boolean) noJdk} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isNoJdk() {
- return noJdk_;
- }
-
- /**
- * Indicates whether {@link #noReflect(boolean) noRflect} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isNoReflect() {
- return noReflect_;
- }
-
- /**
- * Indicates whether {@link #noStdLib(boolean) noStdLib} +was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isNoStdLib() {
- return noStdLib_;
- }
-
- /**
- * Indicates whether {@link #noWarn(boolean) noWarn} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isNoWarn() {
- return noWarn_;
- }
-
- /**
- * Indicates whether {@link #progressive(boolean) progressive} was set.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isProgressive() {
- return progressive_;
- }
-
/**
* Indicates whether {@link #verbose(boolean)} was set.
*
@@ -581,15 +424,6 @@ public class CompileOptions {
return verbose_;
}
- /**
- * Indicates whether warnings are turned into a compilation error.
- *
- * @return {@code true} or {@code false}
- */
- public boolean isWError() {
- return wError_;
- }
-
/**
* Generate metadata for Java 1.8 reflection on method parameters.
*
@@ -607,8 +441,8 @@ public class CompileOptions {
* @param jdkHome the JDK home path
* @return this operation instance
*/
- public CompileOptions jdkHome(File jdkHome) {
- jdkHome_ = jdkHome;
+ public CompileOptions jdkHome(String jdkHome) {
+ jdkHome_ = new File(jdkHome);
return this;
}
@@ -618,45 +452,18 @@ public class CompileOptions {
* @param jdkHome the JDK home path
* @return this operation instance
*/
- public CompileOptions jdkHome(String jdkHome) {
- return jdkHome(new File(jdkHome));
+ public CompileOptions jdkHome(File jdkHome) {
+ jdkHome_ = jdkHome;
+ return this;
}
/**
- * Use a custom JDK home directory to include into the classpath if it differs from the default {@code JAVA_HOME}.
- *
- * @param jdkHome the JDK home path
- * @return this operation instance
- */
- public CompileOptions jdkHome(Path jdkHome) {
- return jdkHome(jdkHome.toFile());
- }
-
- /**
- * Retrieves the custom JDK home directory.
- *
- * @return the JDK home path.
- */
- public File jdkHome() {
- return jdkHome_;
- }
-
- /**
- * Return the specified JDK API version.
- *
- * @return the API version
- */
- public String jdkRelease() {
- return jdkRelease_;
- }
-
- /**
- * Compile against the specified JDK API version.
+ * Specify the target version of the generated JVM bytecode.
*
* 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, ..., 21. The default value is 1.8.
*
* @param version the target version
* @return this operation instance
@@ -667,12 +474,7 @@ public class CompileOptions {
}
/**
- * Compile against the specified JDK API version.
- *
- * 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.
+ * Specify the target version of the generated JVM bytecode.
*
* @param version the target version
* @return this operation instance
@@ -683,6 +485,17 @@ public class CompileOptions {
return this;
}
+ /**
+ * Pass an option directly to JVM
+ *
+ * @param jvmOptions one or more JVM option
+ * @return this operation instance
+ */
+ public CompileOptions jvmOptions(String... jvmOptions) {
+ jvmOptions_.addAll(List.of(jvmOptions));
+ return this;
+ }
+
/**
* Retrieves the Java Virtual Machine options.
*
@@ -704,13 +517,16 @@ public class CompileOptions {
}
/**
- * Pass an option directly to JVM
+ * Specify the target version of the generated JVM bytecode.
+ *
+ * Possible values are 1.8, 9, 10, ..., 21. The default value is 1.8.
*
- * @param jvmOptions one or more JVM option
+ * @param target the target version
* @return this operation instance
*/
- public CompileOptions jvmOptions(String... jvmOptions) {
- return jvmOptions(List.of(jvmOptions));
+ public CompileOptions jvmTarget(String target) {
+ jvmTarget_ = target;
+ return this;
}
/**
@@ -725,28 +541,6 @@ public class CompileOptions {
return this;
}
- /**
- * Specify the target version of the generated JVM bytecode.
- *
- * Possible values are 1.8, 9, 10, ..., 22. The default value is 1.8.
- *
- * @param target the target version
- * @return this operation instance
- */
- public CompileOptions jvmTarget(String target) {
- jvmTarget_ = target;
- return this;
- }
-
- /**
- * Retrieves the target version of the generated JVM bytecode.
- *
- * @return the target version
- */
- public String jvmTarget() {
- return jvmTarget_;
- }
-
/**
* Specify a custom path to the Kotlin compiler used for the discovery of runtime libraries.
*
@@ -758,25 +552,6 @@ public class CompileOptions {
return this;
}
- /**
- * Retrieves the custom path of the Kotlin compiler.
- *
- * @return the Kotlin home path
- */
- public File kotlinHome() {
- return kotlinHome_;
- }
-
- /**
- * Specify a custom path to the Kotlin compiler used for the discovery of runtime libraries.
- *
- * @param path the Kotlin home path
- * @return this operation instance
- */
- public CompileOptions kotlinHome(Path path) {
- return kotlinHome(path.toFile());
- }
-
/**
* Specify a custom path to the Kotlin compiler used for the discovery of runtime libraries.
*
@@ -784,7 +559,8 @@ public class CompileOptions {
* @return this operation instance
*/
public CompileOptions kotlinHome(String path) {
- return kotlinHome(new File(path));
+ kotlinHome_ = new File(path);
+ return this;
}
/**
@@ -798,15 +574,6 @@ public class CompileOptions {
return this;
}
- /**
- * Retrieves the {@link #languageVersion(String) language version}.
- *
- * @return the language version
- */
- public String languageVersion() {
- return languageVersion_;
- }
-
/**
* Set a custom name for the generated {@code .kotlin_module} file.
*
@@ -818,15 +585,6 @@ public class CompileOptions {
return this;
}
- /**
- * Retrieves the {@link #moduleName(String) module name}.
- *
- * @return the module name
- */
- public String moduleName() {
- return moduleName_;
- }
-
/**
* Don't automatically include the Java runtime into the classpath.
*
@@ -947,27 +705,6 @@ public class CompileOptions {
return this;
}
- /**
- * Retrieves the location to place generated class files into.
- *
- * @return the location path.
- */
- public File path() {
- return path_;
- }
-
- /**
- * Place the generated class files into the specified location.
- *
- * The location can be a directory, a ZIP, or a JAR file.
- *
- * @param path the location path
- * @return this operation instance
- */
- public CompileOptions path(Path path) {
- return path(path.toFile());
- }
-
/**
* Place the generated class files into the specified location.
*
@@ -977,7 +714,8 @@ public class CompileOptions {
* @return this operation instance
*/
public CompileOptions path(String path) {
- return path(new File(path));
+ path_ = new File(path);
+ return this;
}
/**
@@ -996,7 +734,7 @@ public class CompileOptions {
/**
* Retrieves the plugin options.
*
- * @return the plugin options.
+ * @return the plugin ofoptions.
*/
public Collection plugin() {
return plugin_;
diff --git a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
index e2e6bd5..231ff1e 100644
--- a/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
+++ b/src/test/java/rife/bld/extension/CompileKotlinOperationTest.java
@@ -108,8 +108,8 @@ class CompileKotlinOperationTest {
var mainDir = new File(buildDir, "main");
var testDir = new File(buildDir, "test");
- assertThat(mainDir.mkdirs()).as("make mainDir").isTrue();
- assertThat(testDir.mkdirs()).as("make testDir").isTrue();
+ assertThat(mainDir.mkdirs()).isTrue();
+ assertThat(testDir.mkdirs()).isTrue();
var compileJars = new ArrayList();
for (var f : Objects.requireNonNull(new File("examples/lib/compile").listFiles())) {
@@ -136,20 +136,20 @@ class CompileKotlinOperationTest {
var args = op.compileOptions().args();
var matches = List.of("-Xjdk-release=17", "-no-stdlib", "-verbose");
- assertThat(args).as(args + " == " + matches).isEqualTo(matches);
+ assertThat(args).isEqualTo(matches);
op.execute();
- assertThat(tmpDir).as("tmpDir").isNotEmptyDirectory();
- assertThat(mainDir).as("mainDir").isNotEmptyDirectory();
- assertThat(testDir).as("testDir").isNotEmptyDirectory();
+ assertThat(tmpDir).isNotEmptyDirectory();
+ assertThat(mainDir).isNotEmptyDirectory();
+ assertThat(testDir).isNotEmptyDirectory();
var mainOut = Path.of(mainDir.getAbsolutePath(), "com", "example").toFile();
- assertThat(new File(mainOut, "Example.class")).as("Example.class").exists();
- assertThat(new File(mainOut, "Example$Companion.class")).as("ExampleCompanion.class").exists();
+ assertThat(new File(mainOut, "Example.class")).exists();
+ assertThat(new File(mainOut, "Example$Companion.class")).exists();
var testOut = Path.of(testDir.getAbsolutePath(), "com", "example").toFile();
- assertThat(new File(testOut, "ExampleTest.class")).as("ExampleTest.class").exists();
+ assertThat(new File(testOut, "ExampleTest.class")).exists();
} finally {
FileUtils.deleteDirectory(tmpDir);
}
diff --git a/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java b/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
index b628a3c..25df90b 100644
--- a/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
+++ b/src/test/java/rife/bld/extension/kotlin/CompileOptionsTest.java
@@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
@@ -44,7 +43,6 @@ class CompileOptionsTest {
.collect(Collectors.joining(File.pathSeparator));
}
-
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
void testArgs() {
@@ -103,8 +101,7 @@ class CompileOptionsTest {
args.add(options.apiVersion(11).jvmTarget(11).args());
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)));
+ IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i)).isEqualTo(matches.get(i)));
}
}
@@ -173,29 +170,10 @@ class CompileOptionsTest {
break;
}
}
- assertThat(found).as(arg + " not found.").isTrue();
+ assertThat(found).as(arg).isTrue();
}
}
- @Test
- void testArgsFile() {
- var foo = new File("foo.txt");
- var bar = new File("bar.txt");
- var options = new CompileOptions();
-
- options.argFile(foo, bar);
- assertThat(options.argFile()).contains(foo, bar);
- options.argFile().clear();
-
- options = options.argFile(foo.toPath(), bar.toPath());
- assertThat(options.argFile()).contains(foo, bar);
- options.argFile().clear();
-
- options.argFile(foo.getAbsolutePath(), bar.getAbsolutePath());
- assertThat(options.argFile()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
- options.argFile().clear();
- }
-
@Test
void testCheckAllParams() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "kotlinc-args.txt"));
@@ -204,7 +182,6 @@ class CompileOptionsTest {
var params = new CompileOptions()
.advancedOptions("Xoption")
- .apiVersion("11")
.argFile("file")
.classpath("classpath")
.expression("expression")
@@ -214,7 +191,6 @@ class CompileOptionsTest {
.jdkHome("jdkhome")
.jvmTarget(12)
.kotlinHome("kotlin")
- .languageVersion("1.0")
.moduleName("moduleName")
.noJdk(true)
.noReflect(true)
@@ -240,109 +216,4 @@ class CompileOptionsTest {
assertThat(found).as(p + " not found.").isTrue();
}
}
-
- @Test
- void testClasspath() {
- var foo = new File("foo.txt");
- var bar = new File("bar.txt");
- var options = new CompileOptions();
-
- options.classpath(foo, bar);
- assertThat(options.classpath()).contains(foo, bar);
- options.classpath().clear();
-
- options = options.classpath(foo.toPath(), bar.toPath());
- assertThat(options.classpath()).contains(foo, bar);
- options.classpath().clear();
-
- options.classpath(foo.getAbsolutePath(), bar.getAbsolutePath());
- assertThat(options.classpath()).contains(new File(foo.getAbsolutePath()), new File(bar.getAbsolutePath()));
- options.classpath().clear();
- }
-
- @Test
- void testJdkHome() {
- var foo = new File("foo.txt");
- var options = new CompileOptions();
-
- options.jdkHome(foo);
- assertThat(options.jdkHome()).isEqualTo(foo);
-
- options = options.jdkHome(foo.toPath());
- assertThat(options.jdkHome()).isEqualTo(foo);
-
- options.jdkHome(foo.getAbsolutePath());
- assertThat(options.jdkHome().getAbsolutePath()).isEqualTo(foo.getAbsolutePath());
- }
-
- @Test
- void testKotlinHome() {
- var foo = new File("foo.txt");
- var options = new CompileOptions();
-
- options.kotlinHome(foo);
- assertThat(options.kotlinHome()).isEqualTo(foo);
-
- options = options.kotlinHome(foo.toPath());
- assertThat(options.kotlinHome()).isEqualTo(foo);
-
- options.kotlinHome(foo.getAbsolutePath());
- assertThat(options.kotlinHome().getAbsolutePath()).isEqualTo(foo.getAbsolutePath());
- }
-
- @Test
- void testOptions() {
- var options = new CompileOptions()
- .advancedOptions("xopt1", "xopt2")
- .apiVersion("11")
- .argFile(Path.of("args.txt"))
- .classpath("classpath")
- .expression("expression")
- .includeRuntime(true)
- .javaParameters(true)
- .jdkHome("jdk-home")
- .jdkRelease("22")
- .jvmTarget("9")
- .kotlinHome("kotlin-home")
- .languageVersion("1.0")
- .moduleName("module")
- .noJdk(true)
- .noReflect(true)
- .noStdLib(true)
- .noWarn(true)
- .optIn("opt1", "opt2")
- .options("-foo", "-bar")
- .path(Path.of("path"))
- .plugin("id", "name", "value")
- .progressive(true)
- .scriptTemplates("name", "name2")
- .verbose(true)
- .wError(true);
-
- 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/resources/kotlinc-args.txt b/src/test/resources/kotlinc-args.txt
index b3c7f27..1f49a77 100644
--- a/src/test/resources/kotlinc-args.txt
+++ b/src/test/resources/kotlinc-args.txt
@@ -1,5 +1,4 @@
@
--api-version
-classpath
-d
-expression
@@ -9,7 +8,6 @@
-jdk-home
-jvm-target
-kotlin-home
--language-version
-module-name
-no-jdk
-no-reflect