Improved code and tests
Bumped Exec extension to 1.0.1 Bumped PMD extension to 1.1.0
This commit is contained in:
parent
c54672a7a0
commit
c901065b3a
7 changed files with 235 additions and 137 deletions
|
@ -39,6 +39,7 @@ public class CompileKotlinOperationBuild extends Project {
|
|||
|
||||
downloadSources = true;
|
||||
autoDownloadPurge = true;
|
||||
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES);
|
||||
|
||||
var kotlin = version(2, 0, 0);
|
||||
|
|
|
@ -25,7 +25,10 @@ import rife.tools.FileUtils;
|
|||
|
||||
import java.io.File;
|
||||
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.Logger;
|
||||
|
||||
|
@ -50,7 +53,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
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 regex the regular expression to match
|
||||
|
@ -131,14 +134,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation compileMainClasspath(String... classpath) {
|
||||
Collections.addAll(compileMainClasspath_, classpath);
|
||||
compileMainClasspath_.addAll(List.of(classpath));
|
||||
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
|
||||
*/
|
||||
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() {
|
||||
return compileMainClasspath_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the list of compilation options for the compiler.
|
||||
* Retrieves the compilation options for the compiler.
|
||||
*
|
||||
* @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
|
||||
* @return this operation instance
|
||||
|
@ -182,14 +185,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation compileTestClasspath(String... classpath) {
|
||||
Collections.addAll(compileTestClasspath_, classpath);
|
||||
compileTestClasspath_.addAll(List.of(classpath));
|
||||
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
|
||||
*/
|
||||
public CompileKotlinOperation compileTestClasspath(Collection<String> classpath) {
|
||||
|
@ -200,7 +203,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
/**
|
||||
* Retrieves the entries for the test compilation classpath.
|
||||
*
|
||||
* @return the list of classpath
|
||||
* @return the classpath entries
|
||||
*/
|
||||
public Collection<String> compileTestClasspath() {
|
||||
return compileTestClasspath_;
|
||||
|
@ -375,7 +378,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceDirectories(File... directories) {
|
||||
Collections.addAll(mainSourceDirectories_, directories);
|
||||
mainSourceDirectories_.addAll(List.of(directories));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -386,16 +389,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceDirectories(String... directories) {
|
||||
Collections.addAll(mainSourceDirectories_, Arrays.stream(directories)
|
||||
.map(File::new)
|
||||
.toArray(File[]::new));
|
||||
mainSourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList());
|
||||
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
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return the list of directories
|
||||
* @return the main source directories
|
||||
*/
|
||||
public Collection<File> 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
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceFiles(File... files) {
|
||||
mainSourceFiles_.addAll(Arrays.asList(files));
|
||||
mainSourceFiles_.addAll(List.of(files));
|
||||
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
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceFiles(String... files) {
|
||||
Collections.addAll(mainSourceFiles_, Arrays.stream(files)
|
||||
.map(File::new)
|
||||
.toArray(File[]::new));
|
||||
mainSourceFiles_.addAll(Arrays.stream(files).map(File::new).toList());
|
||||
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
|
||||
*/
|
||||
public CompileKotlinOperation mainSourceFiles(Collection<File> files) {
|
||||
|
@ -450,7 +449,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
/**
|
||||
* Retrieves the main files that should be compiled.
|
||||
*
|
||||
* @return the list of files
|
||||
* @return the files
|
||||
*/
|
||||
public Collection<File> mainSourceFiles() {
|
||||
return mainSourceFiles_;
|
||||
|
@ -463,14 +462,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this class instance
|
||||
*/
|
||||
public CompileKotlinOperation plugins(String... plugins) {
|
||||
Collections.addAll(plugins_, plugins);
|
||||
plugins_.addAll(List.of(plugins));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the compiler plugins.
|
||||
*
|
||||
* @return the list of plugins
|
||||
* @return the compiler plugins
|
||||
*/
|
||||
public Collection<String> plugins() {
|
||||
return plugins_;
|
||||
|
@ -479,7 +478,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
/**
|
||||
* Provides compiler plugins.
|
||||
*
|
||||
* @param plugins a list of plugins
|
||||
* @param plugins the compiler plugins
|
||||
* @return this class instance
|
||||
*/
|
||||
public CompileKotlinOperation plugins(Collection<String> plugins) {
|
||||
|
@ -517,7 +516,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
/**
|
||||
* Provides compiler plugins.
|
||||
*
|
||||
* @param jars the list of plugin JARs
|
||||
* @param jars the plugins Java archives
|
||||
* @param plugins one or more plugins
|
||||
* @return this class instance
|
||||
*/
|
||||
|
@ -548,7 +547,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation testSourceDirectories(File... directories) {
|
||||
Collections.addAll(testSourceDirectories_, directories);
|
||||
testSourceDirectories_.addAll(List.of(directories));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -559,16 +558,14 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileKotlinOperation testSourceDirectories(String... directories) {
|
||||
Collections.addAll(testSourceDirectories_, Arrays.stream(directories)
|
||||
.map(File::new)
|
||||
.toArray(File[]::new));
|
||||
testSourceDirectories_.addAll(Arrays.stream(directories).map(File::new).toList());
|
||||
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
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @return the list of directories
|
||||
* @return the test source directories
|
||||
*/
|
||||
public Collection<File> 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
|
||||
*/
|
||||
public CompileKotlinOperation testSourceFiles(File... files) {
|
||||
testSourceFiles_.addAll(Arrays.asList(files));
|
||||
testSourceFiles_.addAll(List.of(files));
|
||||
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
|
||||
*/
|
||||
public CompileKotlinOperation testSourceFiles(String... files) {
|
||||
Collections.addAll(testSourceFiles_, Arrays.stream(files)
|
||||
.map(File::new)
|
||||
.toArray(size -> new File[files.length]));
|
||||
testSourceFiles_.addAll(Arrays.stream(files).map(File::new).toList());
|
||||
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
|
||||
*/
|
||||
public CompileKotlinOperation testSourceFiles(Collection<File> files) {
|
||||
|
@ -623,7 +618,7 @@ public class CompileKotlinOperation extends AbstractOperation<CompileKotlinOpera
|
|||
/**
|
||||
* Retrieves the test files that should be compiled.
|
||||
*
|
||||
* @return the list of files
|
||||
* @return the test files
|
||||
*/
|
||||
public Collection<File> testSourceFiles() {
|
||||
return testSourceFiles_;
|
||||
|
|
|
@ -19,7 +19,10 @@ package rife.bld.extension.kotlin;
|
|||
import rife.bld.extension.CompileKotlinOperation;
|
||||
|
||||
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 static rife.bld.extension.CompileKotlinOperation.isNotBlank;
|
||||
|
@ -65,14 +68,14 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions advancedOptions(String... options) {
|
||||
Collections.addAll(advancedOptions_, options);
|
||||
advancedOptions_.addAll(List.of(options));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify advanced compiler options.
|
||||
*
|
||||
* @param options list of compiler options
|
||||
* @param options the compiler options
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions advancedOptions(Collection<String> options) {
|
||||
|
@ -130,9 +133,7 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions argFile(String... files) {
|
||||
Collections.addAll(argFile_, Arrays.stream(files)
|
||||
.map(File::new)
|
||||
.toArray(File[]::new));
|
||||
argFile_.addAll(Arrays.stream(files).map(File::new).toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -155,7 +156,7 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions argFile(File... files) {
|
||||
Collections.addAll(argFile_, files);
|
||||
argFile_.addAll(List.of(files));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -163,7 +164,7 @@ public class CompileOptions {
|
|||
/**
|
||||
* Read the compiler options from the given files.
|
||||
*
|
||||
* @param files the list of files
|
||||
* @param files the compiler options files
|
||||
* @return this operation instance
|
||||
* @see #argFile(String...)
|
||||
*/
|
||||
|
@ -175,7 +176,7 @@ public class CompileOptions {
|
|||
/**
|
||||
* Retrieves the files containing compiler options.
|
||||
*
|
||||
* @return the list of files
|
||||
* @return the compiler options files
|
||||
*/
|
||||
public Collection<File> argFile() {
|
||||
return argFile_;
|
||||
|
@ -343,9 +344,7 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions classpath(String... paths) {
|
||||
Collections.addAll(classpath_, Arrays.stream(paths)
|
||||
.map(File::new)
|
||||
.toArray(File[]::new));
|
||||
classpath_.addAll(Arrays.stream(paths).map(File::new).toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -358,7 +357,7 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions classpath(File... paths) {
|
||||
Collections.addAll(classpath_, paths);
|
||||
classpath_.addAll(List.of(paths));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -367,7 +366,7 @@ public class CompileOptions {
|
|||
* <p>
|
||||
* 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
|
||||
*/
|
||||
public CompileOptions classpath(Collection<File> paths) {
|
||||
|
@ -378,7 +377,7 @@ public class CompileOptions {
|
|||
/**
|
||||
* Retrieves the class files classpath.
|
||||
*
|
||||
* @return the list of classpath
|
||||
* @return the class files classpath
|
||||
*/
|
||||
public Collection<File> classpath() {
|
||||
return classpath_;
|
||||
|
@ -493,23 +492,23 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions jvmOptions(String... jvmOptions) {
|
||||
Collections.addAll(jvmOptions_, jvmOptions);
|
||||
jvmOptions_.addAll(List.of(jvmOptions));
|
||||
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() {
|
||||
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
|
||||
*/
|
||||
public CompileOptions jvmOptions(Collection<String> jvmOptions) {
|
||||
|
@ -638,14 +637,14 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions optIn(String... annotations) {
|
||||
Collections.addAll(optIn_, annotations);
|
||||
optIn_.addAll(List.of(annotations));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the opt-in fully qualified names.
|
||||
*
|
||||
* @return the list of fully qualified names
|
||||
* @return the fully qualified names
|
||||
*/
|
||||
public Collection<String> 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.
|
||||
*
|
||||
* @param annotations list of annotation names
|
||||
* @param annotations the annotation names
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions optIn(Collection<String> annotations) {
|
||||
|
@ -669,14 +668,14 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions options(String... options) {
|
||||
Collections.addAll(options_, options);
|
||||
options_.addAll(List.of(options));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves additional compiler options.
|
||||
*
|
||||
* @return the list of options
|
||||
* @return the compiler options
|
||||
*/
|
||||
public Collection<String> options() {
|
||||
return options_;
|
||||
|
@ -685,7 +684,7 @@ public class CompileOptions {
|
|||
/**
|
||||
* Specify additional compiler options.
|
||||
*
|
||||
* @param options list of compiler options
|
||||
* @param options the compiler options
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions options(Collection<String> options) {
|
||||
|
@ -735,7 +734,7 @@ public class CompileOptions {
|
|||
/**
|
||||
* Retrieves the plugin options.
|
||||
*
|
||||
* @return the list ofoptions.
|
||||
* @return the plugin ofoptions.
|
||||
*/
|
||||
public Collection<String> plugin() {
|
||||
return plugin_;
|
||||
|
@ -761,14 +760,14 @@ public class CompileOptions {
|
|||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions scriptTemplates(String... classNames) {
|
||||
Collections.addAll(scriptTemplates_, classNames);
|
||||
scriptTemplates_.addAll(List.of(classNames));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the script templates.
|
||||
*
|
||||
* @return the list of templates.
|
||||
* @return the script templates.
|
||||
*/
|
||||
public Collection<String> scriptTemplates() {
|
||||
return scriptTemplates_;
|
||||
|
@ -779,7 +778,7 @@ public class CompileOptions {
|
|||
* <p>
|
||||
* Use fully qualified class names.
|
||||
*
|
||||
* @param classNames the list class names
|
||||
* @param classNames the class names
|
||||
* @return this operation instance
|
||||
*/
|
||||
public CompileOptions scriptTemplates(Collection<String> classNames) {
|
||||
|
|
|
@ -18,7 +18,10 @@ package rife.bld.extension;
|
|||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.Project;
|
||||
import rife.bld.blueprints.BaseProjectBlueprint;
|
||||
import rife.bld.extension.kotlin.CompileOptions;
|
||||
import rife.bld.extension.kotlin.CompilerPlugin;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -26,6 +29,7 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
|
@ -46,6 +50,48 @@ class CompileKotlinOperationTest {
|
|||
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
|
||||
void testExecute() throws IOException {
|
||||
var tmpDir = Files.createTempDirectory("bld-kotlin").toFile();
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
package rife.bld.extension.kotlin;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -23,61 +23,39 @@ import java.io.IOException;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
|
||||
class CompileKotlinOptionsTest {
|
||||
@Test
|
||||
void argsCollectionTest() {
|
||||
var args = new CompileKotlinOptions()
|
||||
.advancedOptions(List.of("Xoption1", "Xoption2"))
|
||||
.argFile(List.of("arg1.txt", "arg2.txt"))
|
||||
.classpath(List.of("path1", "path2"))
|
||||
.jvmOptions(List.of("option1", "option2"))
|
||||
.noStdLib(false)
|
||||
.optIn(List.of("opt1", "opt2"))
|
||||
.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();
|
||||
}
|
||||
class CompileOptionsTest {
|
||||
/**
|
||||
* Returns the local path of the given file names.
|
||||
*
|
||||
* @param fileNames The file names
|
||||
* @return the local path
|
||||
*/
|
||||
private String localPath(String... fileNames) {
|
||||
return Arrays.stream(fileNames).map(it -> new File(it).getAbsolutePath())
|
||||
.collect(Collectors.joining(File.pathSeparator));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void argsTest() {
|
||||
var options = new CompileKotlinOptions()
|
||||
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
|
||||
void testArgs() {
|
||||
var options = new CompileOptions()
|
||||
.apiVersion("11")
|
||||
.argFile("file.txt", "file2.txt")
|
||||
.classpath("path1", "path2")
|
||||
.argFile(new File("file.txt"), new File("file2.txt"))
|
||||
.classpath(new File("path1"), new File("path2"))
|
||||
.javaParameters(true)
|
||||
.jvmTarget("11")
|
||||
.includeRuntime(true)
|
||||
.jdkHome("path")
|
||||
.jdkHome(new File("path"))
|
||||
.jdkRelease("11")
|
||||
.kotlinHome("path")
|
||||
.kotlinHome(new File("path"))
|
||||
.languageVersion("1.0")
|
||||
.moduleName("module")
|
||||
.noJdk(true)
|
||||
|
@ -94,14 +72,14 @@ class CompileKotlinOptionsTest {
|
|||
|
||||
var matches = List.of(
|
||||
"-api-version", "11",
|
||||
"@file.txt", "@file2.txt",
|
||||
"-classpath", "path1" + File.pathSeparator + "path2",
|
||||
"@" + localPath("file.txt"), "@" + localPath("file2.txt"),
|
||||
"-classpath", localPath("path1", "path2"),
|
||||
"-java-parameters",
|
||||
"-jvm-target", "11",
|
||||
"-include-runtime",
|
||||
"-jdk-home", "path",
|
||||
"-jdk-home", localPath("path"),
|
||||
"-Xjdk-release=11",
|
||||
"-kotlin-home", "path",
|
||||
"-kotlin-home", localPath("path"),
|
||||
"-language-version", "1.0",
|
||||
"-module-name", "module",
|
||||
"-no-jdk",
|
||||
|
@ -111,7 +89,7 @@ class CompileKotlinOptionsTest {
|
|||
"-opt-in", "opt2",
|
||||
"-foo",
|
||||
"-bar",
|
||||
"-d", "path",
|
||||
"-d", localPath("path"),
|
||||
"-P", "plugin:id:name:value",
|
||||
"-progressive",
|
||||
"-script-templates", "name,name2",
|
||||
|
@ -123,18 +101,86 @@ class CompileKotlinOptionsTest {
|
|||
args.add(options.apiVersion(11).jvmTarget(11).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)));
|
||||
}
|
||||
}
|
||||
|
||||
@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"));
|
||||
|
||||
assertThat(args).isNotEmpty();
|
||||
|
||||
var params = new CompileKotlinOptions()
|
||||
var params = new CompileOptions()
|
||||
.advancedOptions("Xoption")
|
||||
.argFile("file")
|
||||
.classpath("classpath")
|
||||
|
@ -152,7 +198,7 @@ class CompileKotlinOptionsTest {
|
|||
.noWarn(true)
|
||||
.optIn("annotation")
|
||||
.options("option")
|
||||
.path("path")
|
||||
.path(new File("path"))
|
||||
.plugin("id", "option", "value")
|
||||
.progressive(true)
|
||||
.scriptTemplates("template")
|
Loading…
Add table
Add a link
Reference in a new issue