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

View file

@ -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_;

View file

@ -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) {