mirror of
https://github.com/rife2/bld
synced 2026-02-04 01:03:42 +01:00
Handle null values in path and comma-separated options via stream filters
This commit is contained in:
parent
44144ce095
commit
4de8d3c629
|
|
@ -11,6 +11,7 @@ import java.nio.file.Path;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static rife.bld.operations.CompileOperation.COMPILE_OPTION_MODULE_PATH;
|
||||
|
|
@ -88,26 +89,34 @@ public class JavacOptions extends ArrayList<String> {
|
|||
return collection != null && !collection.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to add delimited options
|
||||
*/
|
||||
private JavacOptions addDelimitedOption(String option, Collection<String> values, String separator) {
|
||||
if (isNotEmpty(values)) {
|
||||
var joined = values.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(separator));
|
||||
if (!joined.isEmpty()) {
|
||||
add(option);
|
||||
add(joined);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to add path-based options
|
||||
*/
|
||||
private JavacOptions addPathOption(String option, Collection<String> paths) {
|
||||
if (isNotEmpty(paths)) {
|
||||
add(option);
|
||||
add(String.join(File.pathSeparator, paths));
|
||||
}
|
||||
return this;
|
||||
return addDelimitedOption(option, paths, File.pathSeparator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to add comma-separated options
|
||||
*/
|
||||
private JavacOptions addCommaSeparatedOption(String option, Collection<String> values) {
|
||||
if (isNotEmpty(values)) {
|
||||
add(option);
|
||||
add(String.join(",", values));
|
||||
}
|
||||
return this;
|
||||
return addDelimitedOption(option, values, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -324,11 +333,7 @@ public class JavacOptions extends ArrayList<String> {
|
|||
* @since 2.1
|
||||
*/
|
||||
public JavacOptions endorsedDirsStrings(Collection<String> dirs) {
|
||||
if (isNotEmpty(dirs)) {
|
||||
add("-endorseddirs");
|
||||
add(String.join(",", dirs));
|
||||
}
|
||||
return this;
|
||||
return addCommaSeparatedOption("-endorseddirs", dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -403,11 +408,7 @@ public class JavacOptions extends ArrayList<String> {
|
|||
* @since 2.1
|
||||
*/
|
||||
public JavacOptions extDirsStrings(Collection<String> dirs) {
|
||||
if (isNotEmpty(dirs)) {
|
||||
add("-extdirs");
|
||||
add(String.join(",", dirs));
|
||||
}
|
||||
return this;
|
||||
return addCommaSeparatedOption("-extdirs", dirs);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue