Improved code and tests

Bumped Exec extension to 1.0.1
Bumped PMD extension to 1.1.0
This commit is contained in:
Erik C. Thauvin 2024-06-19 08:19:34 -07:00
parent c54672a7a0
commit c901065b3a
Signed by: erik
GPG key ID: 776702A6A2DA330E
7 changed files with 235 additions and 137 deletions

11
.idea/misc.xml generated
View file

@ -1,7 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<entry_points version="2.0">
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin ALL_OPEN" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin ASSIGNMENT" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin KOTLIN_SERIALIZATION" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin LOMBOK" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin NOARG" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin POWER_ASSERT" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.kotlin.CompilerPlugin SAM_WITH_RECEIVER" />
</entry_points>
<pattern value="rife.bld.extension.CompileKotlinOperationBuild" method="pmd" /> <pattern value="rife.bld.extension.CompileKotlinOperationBuild" method="pmd" />
<pattern value="rife.bld.extension.kotlin.CompilerPlugin" />
<pattern value="rife.bld.extension.kotlin.CompilerPlugin" method="CompilerPlugin" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= bld.downloadLocation=
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.0 bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.1
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.0.1 bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.0
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_RELEASES bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=1.9.1 bld.version=1.9.1

View file

@ -39,6 +39,7 @@ public class CompileKotlinOperationBuild extends Project {
downloadSources = true; downloadSources = true;
autoDownloadPurge = true; autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES); repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
var kotlin = version(2, 0, 0); var kotlin = version(2, 0, 0);

View file

@ -25,7 +25,10 @@ import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -50,7 +53,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
private BaseProject project_; private BaseProject project_;
/** /**
* Returns the list of JARs contained in a given directory. * Returns the list of Java archives contained in a given directory.
* *
* @param directory the directory * @param directory the directory
* @param regex the regular expression to match * @param regex the regular expression to match
@ -131,14 +134,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation compileMainClasspath(String... classpath) { public CompileKotlinOperation compileMainClasspath(String... classpath) {
Collections.addAll(compileMainClasspath_, classpath); compileMainClasspath_.addAll(List.of(classpath));
return this; return this;
} }
/** /**
* Provides a list of entries for the main compilation classpath. * Provides the entries for the main compilation classpath.
* *
* @param classpath a list of classpath entries * @param classpath the classpath entries
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation compileMainClasspath(Collection<String> classpath) { public CompileKotlinOperation compileMainClasspath(Collection<String> classpath) {
@ -147,16 +150,16 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
} }
/** /**
* Retrieves the list of entries for the main compilation classpath. * Retrieves the entries for the main compilation classpath.
* *
* @return the list of classpath * @return the classpath entries
*/ */
public Collection<String> compileMainClasspath() { public Collection<String> compileMainClasspath() {
return compileMainClasspath_; return compileMainClasspath_;
} }
/** /**
* Retrieves the list of compilation options for the compiler. * Retrieves the compilation options for the compiler.
* *
* @return the compilation options * @return the compilation options
*/ */
@ -165,7 +168,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
} }
/** /**
* Provides a list of compilation options to pass to the Kotlin compiler. * Provides the compilation options to pass to the Kotlin compiler.
* *
* @param options the compiler options * @param options the compiler options
* @return this operation instance * @return this operation instance
@ -182,14 +185,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation compileTestClasspath(String... classpath) { public CompileKotlinOperation compileTestClasspath(String... classpath) {
Collections.addAll(compileTestClasspath_, classpath); compileTestClasspath_.addAll(List.of(classpath));
return this; return this;
} }
/** /**
* Provides a list of entries for the test compilation classpath. * Provides the entries for the test compilation classpath.
* *
* @param classpath a list of classpath entries * @param classpath the classpath entries
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation compileTestClasspath(Collection<String> classpath) { public CompileKotlinOperation compileTestClasspath(Collection<String> classpath) {
@ -200,7 +203,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Retrieves the entries for the test compilation classpath. * Retrieves the entries for the test compilation classpath.
* *
* @return the list of classpath * @return the classpath entries
*/ */
public Collection<String> compileTestClasspath() { public Collection<String> compileTestClasspath() {
return compileTestClasspath_; return compileTestClasspath_;
@ -375,7 +378,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceDirectories(File... directories) { public CompileKotlinOperation mainSourceDirectories(File... directories) {
Collections.addAll(mainSourceDirectories_, directories); mainSourceDirectories_.addAll(List.of(directories));
return this; return this;
} }
@ -386,16 +389,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceDirectories(String... directories) { public CompileKotlinOperation mainSourceDirectories(String... directories) {
Collections.addAll(mainSourceDirectories_, Arrays.stream(directories) mainSourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
/** /**
* Provides a list of main source directories that should be compiled. * Provides the main source directories that should be compiled.
* *
* @param directories a list of main source directories * @param directories the main source directories
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceDirectories(Collection<File> directories) { public CompileKotlinOperation mainSourceDirectories(Collection<File> directories) {
@ -406,40 +407,38 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Retrieves the main source directories that should be compiled. * Retrieves the main source directories that should be compiled.
* *
* @return the list of directories * @return the main source directories
*/ */
public Collection<File> mainSourceDirectories() { public Collection<File> mainSourceDirectories() {
return mainSourceDirectories_; return mainSourceDirectories_;
} }
/** /**
* Provides main files that should be compiled. * Provides main source files that should be compiled.
* *
* @param files one or more main files * @param files one or more main source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceFiles(File... files) { public CompileKotlinOperation mainSourceFiles(File... files) {
mainSourceFiles_.addAll(Arrays.asList(files)); mainSourceFiles_.addAll(List.of(files));
return this; return this;
} }
/** /**
* Provides main files that should be compiled. * Provides main source files that should be compiled.
* *
* @param files one or more main files * @param files one or more main source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceFiles(String... files) { public CompileKotlinOperation mainSourceFiles(String... files) {
Collections.addAll(mainSourceFiles_, Arrays.stream(files) mainSourceFiles_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
/** /**
* Provides a list of main files that should be compiled. * Provides the main source files that should be compiled.
* *
* @param files a list of main files * @param files the main source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation mainSourceFiles(Collection<File> files) { public CompileKotlinOperation mainSourceFiles(Collection<File> files) {
@ -450,7 +449,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Retrieves the main files that should be compiled. * Retrieves the main files that should be compiled.
* *
* @return the list of files * @return the files
*/ */
public Collection<File> mainSourceFiles() { public Collection<File> mainSourceFiles() {
return mainSourceFiles_; return mainSourceFiles_;
@ -463,14 +462,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this class instance * @return this class instance
*/ */
public CompileKotlinOperation plugins(String... plugins) { public CompileKotlinOperation plugins(String... plugins) {
Collections.addAll(plugins_, plugins); plugins_.addAll(List.of(plugins));
return this; return this;
} }
/** /**
* Retrieves the compiler plugins. * Retrieves the compiler plugins.
* *
* @return the list of plugins * @return the compiler plugins
*/ */
public Collection<String> plugins() { public Collection<String> plugins() {
return plugins_; return plugins_;
@ -479,7 +478,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Provides compiler plugins. * Provides compiler plugins.
* *
* @param plugins a list of plugins * @param plugins the compiler plugins
* @return this class instance * @return this class instance
*/ */
public CompileKotlinOperation plugins(Collection<String> plugins) { public CompileKotlinOperation plugins(Collection<String> plugins) {
@ -517,7 +516,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Provides compiler plugins. * Provides compiler plugins.
* *
* @param jars the list of plugin JARs * @param jars the plugins Java archives
* @param plugins one or more plugins * @param plugins one or more plugins
* @return this class instance * @return this class instance
*/ */
@ -548,7 +547,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceDirectories(File... directories) { public CompileKotlinOperation testSourceDirectories(File... directories) {
Collections.addAll(testSourceDirectories_, directories); testSourceDirectories_.addAll(List.of(directories));
return this; return this;
} }
@ -559,16 +558,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceDirectories(String... directories) { public CompileKotlinOperation testSourceDirectories(String... directories) {
Collections.addAll(testSourceDirectories_, Arrays.stream(directories) testSourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
/** /**
* Provides a list of test source directories that should be compiled. * Provides the test source directories that should be compiled.
* *
* @param directories a list of test source directories * @param directories the test source directories
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceDirectories(Collection<File> directories) { public CompileKotlinOperation testSourceDirectories(Collection<File> directories) {
@ -579,40 +576,38 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Retrieves the test source directories that should be compiled. * Retrieves the test source directories that should be compiled.
* *
* @return the list of directories * @return the test source directories
*/ */
public Collection<File> testSourceDirectories() { public Collection<File> testSourceDirectories() {
return testSourceDirectories_; return testSourceDirectories_;
} }
/** /**
* Provides test files that should be compiled. * Provides test source files that should be compiled.
* *
* @param files one or more test files * @param files one or more test source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceFiles(File... files) { public CompileKotlinOperation testSourceFiles(File... files) {
testSourceFiles_.addAll(Arrays.asList(files)); testSourceFiles_.addAll(List.of(files));
return this; return this;
} }
/** /**
* Provides test files that should be compiled. * Provides the test sources files that should be compiled.
* *
* @param files one or more test files * @param files one or more test source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceFiles(String... files) { public CompileKotlinOperation testSourceFiles(String... files) {
Collections.addAll(testSourceFiles_, Arrays.stream(files) testSourceFiles_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(size -> new File[files.length]));
return this; return this;
} }
/** /**
* Provides a list of test files that should be compiled. * Provides the test source files that should be compiled.
* *
* @param files a list of test files * @param files the test source files
* @return this operation instance * @return this operation instance
*/ */
public CompileKotlinOperation testSourceFiles(Collection<File> files) { public CompileKotlinOperation testSourceFiles(Collection<File> files) {
@ -623,7 +618,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
/** /**
* Retrieves the test files that should be compiled. * Retrieves the test files that should be compiled.
* *
* @return the list of files * @return the test files
*/ */
public Collection<File> testSourceFiles() { public Collection<File> testSourceFiles() {
return testSourceFiles_; return testSourceFiles_;

View file

@ -19,7 +19,10 @@ package rife.bld.extension.kotlin;
import rife.bld.extension.CompileKotlinOperation; import rife.bld.extension.CompileKotlinOperation;
import java.io.File; import java.io.File;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static rife.bld.extension.CompileKotlinOperation.isNotBlank; import static rife.bld.extension.CompileKotlinOperation.isNotBlank;
@ -65,14 +68,14 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions advancedOptions(String... options) { public CompileOptions advancedOptions(String... options) {
Collections.addAll(advancedOptions_, options); advancedOptions_.addAll(List.of(options));
return this; return this;
} }
/** /**
* Specify advanced compiler options. * Specify advanced compiler options.
* *
* @param options list of compiler options * @param options the compiler options
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions advancedOptions(Collection<String> options) { public CompileOptions advancedOptions(Collection<String> options) {
@ -130,9 +133,7 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions argFile(String... files) { public CompileOptions argFile(String... files) {
Collections.addAll(argFile_, Arrays.stream(files) argFile_.addAll(Arrays.stream(files).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -155,7 +156,7 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions argFile(File... files) { public CompileOptions argFile(File... files) {
Collections.addAll(argFile_, files); argFile_.addAll(List.of(files));
return this; return this;
} }
@ -163,7 +164,7 @@ public class CompileOptions {
/** /**
* Read the compiler options from the given files. * Read the compiler options from the given files.
* *
* @param files the list of files * @param files the compiler options files
* @return this operation instance * @return this operation instance
* @see #argFile(String...) * @see #argFile(String...)
*/ */
@ -175,7 +176,7 @@ public class CompileOptions {
/** /**
* Retrieves the files containing compiler options. * Retrieves the files containing compiler options.
* *
* @return the list of files * @return the compiler options files
*/ */
public Collection<File> argFile() { public Collection<File> argFile() {
return argFile_; return argFile_;
@ -343,9 +344,7 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions classpath(String... paths) { public CompileOptions classpath(String... paths) {
Collections.addAll(classpath_, Arrays.stream(paths) classpath_.addAll(Arrays.stream(paths).map(File::new).toList());
.map(File::new)
.toArray(File[]::new));
return this; return this;
} }
@ -358,7 +357,7 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions classpath(File... paths) { public CompileOptions classpath(File... paths) {
Collections.addAll(classpath_, paths); classpath_.addAll(List.of(paths));
return this; return this;
} }
@ -367,7 +366,7 @@ public class CompileOptions {
* <p> * <p>
* The classpath can contain file and directory paths, ZIP, or JAR files. * The classpath can contain file and directory paths, ZIP, or JAR files.
* *
* @param paths the list of paths * @param paths the search paths
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions classpath(Collection<File> paths) { public CompileOptions classpath(Collection<File> paths) {
@ -378,7 +377,7 @@ public class CompileOptions {
/** /**
* Retrieves the class files classpath. * Retrieves the class files classpath.
* *
* @return the list of classpath * @return the class files classpath
*/ */
public Collection<File> classpath() { public Collection<File> classpath() {
return classpath_; return classpath_;
@ -493,23 +492,23 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions jvmOptions(String... jvmOptions) { public CompileOptions jvmOptions(String... jvmOptions) {
Collections.addAll(jvmOptions_, jvmOptions); jvmOptions_.addAll(List.of(jvmOptions));
return this; return this;
} }
/** /**
* Retrieves the JVM options. * Retrieves the Java Virtual Machine options.
* *
* @return the list of options * @return the JVM options
*/ */
public Collection<String> jvmOptions() { public Collection<String> jvmOptions() {
return jvmOptions_; return jvmOptions_;
} }
/** /**
* Pass an option directly to JVM * Pass an option directly to Java Virtual Machine
* *
* @param jvmOptions the list JVM options * @param jvmOptions the JVM options
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions jvmOptions(Collection<String> jvmOptions) { public CompileOptions jvmOptions(Collection<String> jvmOptions) {
@ -638,14 +637,14 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions optIn(String... annotations) { public CompileOptions optIn(String... annotations) {
Collections.addAll(optIn_, annotations); optIn_.addAll(List.of(annotations));
return this; return this;
} }
/** /**
* Retrieves the opt-in fully qualified names. * Retrieves the opt-in fully qualified names.
* *
* @return the list of fully qualified names * @return the fully qualified names
*/ */
public Collection<String> optIn() { public Collection<String> optIn() {
return optIn_; return optIn_;
@ -654,7 +653,7 @@ public class CompileOptions {
/** /**
* Enable usages of API that requires opt-in with a requirement annotation with the given fully qualified name. * Enable usages of API that requires opt-in with a requirement annotation with the given fully qualified name.
* *
* @param annotations list of annotation names * @param annotations the annotation names
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions optIn(Collection<String> annotations) { public CompileOptions optIn(Collection<String> annotations) {
@ -669,14 +668,14 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions options(String... options) { public CompileOptions options(String... options) {
Collections.addAll(options_, options); options_.addAll(List.of(options));
return this; return this;
} }
/** /**
* Retrieves additional compiler options. * Retrieves additional compiler options.
* *
* @return the list of options * @return the compiler options
*/ */
public Collection<String> options() { public Collection<String> options() {
return options_; return options_;
@ -685,7 +684,7 @@ public class CompileOptions {
/** /**
* Specify additional compiler options. * Specify additional compiler options.
* *
* @param options list of compiler options * @param options the compiler options
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions options(Collection<String> options) { public CompileOptions options(Collection<String> options) {
@ -735,7 +734,7 @@ public class CompileOptions {
/** /**
* Retrieves the plugin options. * Retrieves the plugin options.
* *
* @return the list ofoptions. * @return the plugin ofoptions.
*/ */
public Collection<String> plugin() { public Collection<String> plugin() {
return plugin_; return plugin_;
@ -761,14 +760,14 @@ public class CompileOptions {
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions scriptTemplates(String... classNames) { public CompileOptions scriptTemplates(String... classNames) {
Collections.addAll(scriptTemplates_, classNames); scriptTemplates_.addAll(List.of(classNames));
return this; return this;
} }
/** /**
* Retrieves the script templates. * Retrieves the script templates.
* *
* @return the list of templates. * @return the script templates.
*/ */
public Collection<String> scriptTemplates() { public Collection<String> scriptTemplates() {
return scriptTemplates_; return scriptTemplates_;
@ -779,7 +778,7 @@ public class CompileOptions {
* <p> * <p>
* Use fully qualified class names. * Use fully qualified class names.
* *
* @param classNames the list class names * @param classNames the class names
* @return this operation instance * @return this operation instance
*/ */
public CompileOptions scriptTemplates(Collection<String> classNames) { public CompileOptions scriptTemplates(Collection<String> classNames) {

View file

@ -18,7 +18,10 @@ package rife.bld.extension;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.Project;
import rife.bld.blueprints.BaseProjectBlueprint; import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.extension.kotlin.CompileOptions;
import rife.bld.extension.kotlin.CompilerPlugin;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import java.io.File; import java.io.File;
@ -26,6 +29,7 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
@ -46,6 +50,48 @@ class CompileKotlinOperationTest {
logger.setUseParentHandlers(false); logger.setUseParentHandlers(false);
} }
@Test
void testCollections() {
var op = new CompileKotlinOperation()
.fromProject(new Project())
.compileMainClasspath("path1", "path2")
.compileOptions(new CompileOptions().jdkRelease("17").verbose(true))
.mainSourceDirectories("dir1", "dir2")
.mainSourceDirectories(List.of(new File("dir3"), new File("dir4")))
.mainSourceFiles("file1", "file2")
.mainSourceFiles(List.of(new File("file3"), new File("file4")))
.mainSourceFiles(new File("file5"), new File("file6"))
.testSourceDirectories("tdir1", "tdir2")
.testSourceDirectories(List.of(new File("tdir3"), new File("tdir4")))
.testSourceFiles("tfile1", "tfile2")
.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(new File("lib/compile"), CompilerPlugin.LOMBOK, CompilerPlugin.POWER_ASSERT)
.plugins(List.of("plugin3", "plugin4"))
.plugins(Arrays.stream(Objects.requireNonNull(new File("lib/compile").listFiles())).toList(),
CompilerPlugin.ALL_OPEN, CompilerPlugin.SAM_WITH_RECEIVER);
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()).hasSize(10);
}
@Test @Test
void testExecute() throws IOException { void testExecute() throws IOException {
var tmpDir = Files.createTempDirectory("bld-kotlin").toFile(); var tmpDir = Files.createTempDirectory("bld-kotlin").toFile();

View file

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package rife.bld.extension; package rife.bld.extension.kotlin;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -23,61 +23,39 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressWarnings("PMD.AvoidDuplicateLiterals")
class CompileKotlinOptionsTest { class CompileOptionsTest {
@Test /**
void argsCollectionTest() { * Returns the local path of the given file names.
var args = new CompileKotlinOptions() *
.advancedOptions(List.of("Xoption1", "Xoption2")) * @param fileNames The file names
.argFile(List.of("arg1.txt", "arg2.txt")) * @return the local path
.classpath(List.of("path1", "path2")) */
.jvmOptions(List.of("option1", "option2")) private String localPath(String... fileNames) {
.noStdLib(false) return Arrays.stream(fileNames).map(it -> new File(it).getAbsolutePath())
.optIn(List.of("opt1", "opt2")) .collect(Collectors.joining(File.pathSeparator));
.options(List.of("-foo", "-bar"))
.scriptTemplates(List.of("temp1", "temp2"))
.args();
var matches = List.of(
"@arg1.txt", "@arg2.txt",
"-classpath", "path1:path2",
"-Joption1", "-Joption2",
"-opt-in", "opt1",
"-opt-in", "opt2",
"-foo", "-bar",
"-script-templates",
"temp1,temp2",
"-XXoption1", "-XXoption2");
for (var arg : args) {
var found = false;
for (var match : matches) {
if (match.equals(arg)) {
found = true;
break;
}
}
assertThat(found).as(arg).isTrue();
}
} }
@Test @Test
void argsTest() { @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
var options = new CompileKotlinOptions() void testArgs() {
var options = new CompileOptions()
.apiVersion("11") .apiVersion("11")
.argFile("file.txt", "file2.txt") .argFile(new File("file.txt"), new File("file2.txt"))
.classpath("path1", "path2") .classpath(new File("path1"), new File("path2"))
.javaParameters(true) .javaParameters(true)
.jvmTarget("11") .jvmTarget("11")
.includeRuntime(true) .includeRuntime(true)
.jdkHome("path") .jdkHome(new File("path"))
.jdkRelease("11") .jdkRelease("11")
.kotlinHome("path") .kotlinHome(new File("path"))
.languageVersion("1.0") .languageVersion("1.0")
.moduleName("module") .moduleName("module")
.noJdk(true) .noJdk(true)
@ -94,14 +72,14 @@ class CompileKotlinOptionsTest {
var matches = List.of( var matches = List.of(
"-api-version", "11", "-api-version", "11",
"@file.txt", "@file2.txt", "@" + localPath("file.txt"), "@" + localPath("file2.txt"),
"-classpath", "path1" + File.pathSeparator + "path2", "-classpath", localPath("path1", "path2"),
"-java-parameters", "-java-parameters",
"-jvm-target", "11", "-jvm-target", "11",
"-include-runtime", "-include-runtime",
"-jdk-home", "path", "-jdk-home", localPath("path"),
"-Xjdk-release=11", "-Xjdk-release=11",
"-kotlin-home", "path", "-kotlin-home", localPath("path"),
"-language-version", "1.0", "-language-version", "1.0",
"-module-name", "module", "-module-name", "module",
"-no-jdk", "-no-jdk",
@ -111,7 +89,7 @@ class CompileKotlinOptionsTest {
"-opt-in", "opt2", "-opt-in", "opt2",
"-foo", "-foo",
"-bar", "-bar",
"-d", "path", "-d", localPath("path"),
"-P", "plugin:id:name:value", "-P", "plugin:id:name:value",
"-progressive", "-progressive",
"-script-templates", "name,name2", "-script-templates", "name,name2",
@ -123,18 +101,86 @@ class CompileKotlinOptionsTest {
args.add(options.apiVersion(11).jvmTarget(11).args()); args.add(options.apiVersion(11).jvmTarget(11).args());
for (var a : args) { for (var a : args) {
assertThat(a).hasSize(matches.size());
IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i)).isEqualTo(matches.get(i))); IntStream.range(0, a.size()).forEach(i -> assertThat(a.get(i)).isEqualTo(matches.get(i)));
} }
} }
@Test @Test
void checkAllParamsTest() throws IOException { void testArgsCollections() {
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");
var scriptTemplates = List.of("temp1", "temp2");
var op = new CompileOptions()
.advancedOptions(advanceOptions)
.argFile(argFile)
.classpath(classpath)
.jvmOptions(jvmOptions)
.noStdLib(false)
.optIn(optIn)
.options(options)
.scriptTemplates(scriptTemplates);
plugin.forEach(it -> {
var p = it.split(":");
op.plugin(p[0], p[1], p[2]);
});
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"),
"-classpath", localPath("path1", "path2"),
"-Joption1", "-Joption2",
"-opt-in", "opt1",
"-opt-in", "opt2",
"-foo", "-bar",
"-script-templates",
"temp1,temp2",
"-XXoption1", "-XXoption2",
"-P", "plugin:id:name:value",
"-P", "plugin:id2:name2:value2");
var args = op.args();
for (var arg : args) {
var found = false;
for (var match : matches) {
if (match.equals(arg)) {
found = true;
break;
}
}
assertThat(found).as(arg).isTrue();
}
}
@Test
void testCheckAllParams() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "kotlinc-args.txt")); var args = Files.readAllLines(Paths.get("src", "test", "resources", "kotlinc-args.txt"));
assertThat(args).isNotEmpty(); assertThat(args).isNotEmpty();
var params = new CompileKotlinOptions() var params = new CompileOptions()
.advancedOptions("Xoption") .advancedOptions("Xoption")
.argFile("file") .argFile("file")
.classpath("classpath") .classpath("classpath")
@ -152,7 +198,7 @@ class CompileKotlinOptionsTest {
.noWarn(true) .noWarn(true)
.optIn("annotation") .optIn("annotation")
.options("option") .options("option")
.path("path") .path(new File("path"))
.plugin("id", "option", "value") .plugin("id", "option", "value")
.progressive(true) .progressive(true)
.scriptTemplates("template") .scriptTemplates("template")