From 21ed5912f04df6cc6677fc7e7890a668f80e9e39 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 21 Jan 2026 11:37:20 -0800 Subject: [PATCH 1/7] Add support for multiple input types (Collection, Varargs, File, Path) in JavacOptions path-related methods. --- .../rife/bld/operations/JavacOptions.java | 110 +++-- .../rife/bld/operations/TestJavacOptions.java | 401 +++++++++++++++++- 2 files changed, 483 insertions(+), 28 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index b41f693..a67c230 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -12,6 +12,7 @@ import java.io.File; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -562,8 +563,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions moduleSourcePath(File path) { - return moduleSourcePath(path.getAbsolutePath()); + public JavacOptions moduleSourcePath(File... paths) { + return moduleSourcePath(Arrays.stream(paths) + .map(File::getAbsolutePath) + .collect(Collectors.toList())); } /** @@ -572,8 +575,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions moduleSourcePath(Path path) { - return moduleSourcePath(path.toFile()); + public JavacOptions moduleSourcePath(Path... paths) { + return moduleSourcePath(Arrays.stream(paths) + .map(Path::toString) + .collect(Collectors.toList())); } /** @@ -582,9 +587,19 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions moduleSourcePath(String path) { + public JavacOptions moduleSourcePath(String... paths) { + return moduleSourcePath(Arrays.asList(paths)); + } + + /** + * Specify where to find input source files for multiple modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions moduleSourcePath(Collection paths) { add("--module-source-path"); - add(path); + add(String.join(File.pathSeparator, paths)); return this; } @@ -649,7 +664,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions processors(List classnames) { + public JavacOptions processors(Collection classnames) { add("-processor"); add(StringUtils.join(classnames, ",")); return this; @@ -661,8 +676,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions processorModulePath(File path) { - return processorModulePath(path.getAbsolutePath()); + public JavacOptions processorModulePath(File... paths) { + return processorModulePath(Arrays.stream(paths) + .map(File::getAbsolutePath) + .collect(Collectors.toList())); } /** @@ -671,8 +688,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions processorModulePath(Path path) { - return processorModulePath(path.toFile()); + public JavacOptions processorModulePath(Path... paths) { + return processorModulePath(Arrays.stream(paths) + .map(Path::toString) + .collect(Collectors.toList())); } /** @@ -681,9 +700,19 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions processorModulePath(String path) { + public JavacOptions processorModulePath(String... paths) { + return processorModulePath(Arrays.asList(paths)); + } + + /** + * Specify a module path where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorModulePath(Collection paths) { add("--processor-module-path"); - add(path); + add(String.join(File.pathSeparator, paths)); return this; } @@ -693,8 +722,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions processorPath(File path) { - return processorPath(path.getAbsolutePath()); + public JavacOptions processorPath(String... paths) { + return processorPath(Arrays.asList(paths)); } /** @@ -703,8 +732,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions processorPath(Path path) { - return processorPath(path.toFile()); + public JavacOptions processorPath(File... paths) { + return processorPath(Arrays.stream(paths) + .map(File::getAbsolutePath) + .collect(Collectors.toList())); } /** @@ -713,9 +744,21 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions processorPath(String path) { + public JavacOptions processorPath(Path... paths) { + return processorPath(Arrays.stream(paths) + .map(Path::toString) + .collect(Collectors.toList())); + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPath(Collection paths) { add("--processor-path"); - add(path); + add(String.join(File.pathSeparator, paths)); return this; } @@ -784,8 +827,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions upgradeModulePath(File path) { - return upgradeModulePath(path.getAbsolutePath()); + public JavacOptions upgradeModulePath(File... paths) { + return upgradeModulePath(Arrays.stream(paths) + .map(File::getAbsolutePath) + .collect(Collectors.toList())); } /** @@ -794,8 +839,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions upgradeModulePath(Path path) { - return upgradeModulePath(path.toFile()); + public JavacOptions upgradeModulePath(Path... paths) { + return upgradeModulePath(Arrays.stream(paths) + .map(Path::toString) + .collect(Collectors.toList())); } /** @@ -804,9 +851,19 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions upgradeModulePath(String path) { + public JavacOptions upgradeModulePath(String... paths) { + return upgradeModulePath(Arrays.asList(paths)); + } + + /** + * Override location of upgradeable modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions upgradeModulePath(Collection paths) { add("--upgrade-module-path"); - add(path); + add(String.join(File.pathSeparator, paths)); return this; } @@ -861,6 +918,7 @@ public class JavacOptions extends ArrayList { public JavacOptions xLintDisable(XLintKey... keys) { return xLintDisable(Arrays.asList(keys)); } + /** * Warning categories to disable * @@ -871,7 +929,6 @@ public class JavacOptions extends ArrayList { return addXLintOption(keys, "-"); } - private JavacOptions addXLintOption(List keys, String prefix) { if (keys == null || keys.isEmpty()) { return this; @@ -884,5 +941,4 @@ public class JavacOptions extends ArrayList { add(formattedKeys); return this; } - } \ No newline at end of file diff --git a/src/test/java/rife/bld/operations/TestJavacOptions.java b/src/test/java/rife/bld/operations/TestJavacOptions.java index b21aad1..089d661 100644 --- a/src/test/java/rife/bld/operations/TestJavacOptions.java +++ b/src/test/java/rife/bld/operations/TestJavacOptions.java @@ -9,6 +9,8 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import rife.bld.operations.JavacOptions.XLintKey; +import java.io.File; +import java.nio.file.Path; import java.util.Arrays; import java.util.List; @@ -171,7 +173,7 @@ class TestJavacOptions { @Test void testAddReadsWithList() { - List modules = Arrays.asList("mod1=mod2", "mod3=mod4", "mod5=mod6"); + var modules = Arrays.asList("mod1=mod2", "mod3=mod4", "mod5=mod6"); options.addReads(modules); assertEquals(2, options.size()); @@ -960,4 +962,401 @@ class TestJavacOptions { assertEquals(1, options.size()); } } + + @Nested + class ModuleSourcePathTests { + @Test + void testModuleSourcePathMethodChaining() { + options.moduleSourcePath("src/module1", "src/module2") + .parameters() + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("--module-source-path")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testModuleSourcePathMultipleCalls() { + options.moduleSourcePath("src/module1") + .moduleSourcePath("src/module2"); + + assertEquals(4, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals("--module-source-path", options.get(2)); + } + + @Test + void testModuleSourcePathReturnsThis() { + var result = options.moduleSourcePath("src/modules"); + assertSame(options, result); + } + + @Test + void testModuleSourcePathWithCollection() { + var paths = Arrays.asList("src/mod1", "src/mod2", "src/mod3"); + options.moduleSourcePath(paths); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertTrue(options.get(1).contains("src/mod1")); + assertTrue(options.get(1).contains("src/mod2")); + assertTrue(options.get(1).contains("src/mod3")); + } + + @Test + void testModuleSourcePathWithEmptyCollection() { + options.moduleSourcePath(List.of()); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals("", options.get(1)); + } + + @Test + void testModuleSourcePathWithEmptyVarargs() { + options.moduleSourcePath(""); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + } + + @Test + void testModuleSourcePathWithFile() { + options.moduleSourcePath(new File("src/modules")); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertTrue(options.get(1).contains("src")); + assertTrue(options.get(1).contains("modules")); + } + + @Test + void testModuleSourcePathWithPath() { + options.moduleSourcePath(Path.of("src/modules")); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertTrue(options.get(1).contains("src")); + assertTrue(options.get(1).contains("modules")); + } + + @Test + void testModuleSourcePathWithSingleString() { + options.moduleSourcePath("src/modules"); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals("src/modules", options.get(1)); + } + + @Test + void testModuleSourcePathWithVarargs() { + options.moduleSourcePath("src/mod1", "src/mod2", "src/mod3"); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertTrue(options.get(1).contains("src/mod1")); + assertTrue(options.get(1).contains("src/mod2")); + assertTrue(options.get(1).contains("src/mod3")); + } + } + + @Nested + class ProcessorModulePathTests { + @Test + void testProcessorModulePathMethodChaining() { + options.processorModulePath("lib/processors") + .parameters() + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("--processor-module-path")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testProcessorModulePathMultipleCalls() { + options.processorModulePath("lib/proc1") + .processorModulePath("lib/proc2"); + + assertEquals(4, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals("--processor-module-path", options.get(2)); + } + + @Test + void testProcessorModulePathReturnsThis() { + var result = options.processorModulePath("lib/processors"); + assertSame(options, result); + } + + @Test + void testProcessorModulePathWithCollection() { + var paths = Arrays.asList("lib/proc1", "lib/proc2", "lib/proc3"); + options.processorModulePath(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib/proc1")); + assertTrue(options.get(1).contains("lib/proc2")); + assertTrue(options.get(1).contains("lib/proc3")); + } + + @Test + void testProcessorModulePathWithEmptyCollection() { + options.processorModulePath(List.of()); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals("", options.get(1)); + } + + @Test + void testProcessorModulePathWithEmptyVarargs() { + options.processorModulePath(new String[]{}); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + } + + @Test + void testProcessorModulePathWithFile() { + options.processorModulePath(new File("lib/processors")); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("processors")); + } + + @Test + void testProcessorModulePathWithPath() { + options.processorModulePath(Path.of("lib/processors")); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("processors")); + } + + @Test + void testProcessorModulePathWithSingleString() { + options.processorModulePath("lib/processors"); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals("lib/processors", options.get(1)); + } + + @Test + void testProcessorModulePathWithVarargs() { + options.processorModulePath("lib/proc1", "lib/proc2"); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib/proc1")); + assertTrue(options.get(1).contains("lib/proc2")); + } + } + + @Nested + class ProcessorPathTests { + @Test + void testProcessorPathMethodChaining() { + options.processorPath("lib/processors.jar") + .parameters() + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("--processor-path")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testProcessorPathMultipleCalls() { + options.processorPath("lib/proc1.jar") + .processorPath("lib/proc2.jar"); + + assertEquals(4, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("--processor-path", options.get(2)); + } + + @Test + void testProcessorPathReturnsThis() { + var result = options.processorPath("lib/processors.jar"); + assertSame(options, result); + } + + @Test + void testProcessorPathWithCollection() { + var paths = Arrays.asList("lib/proc1.jar", "lib/proc2.jar", "lib/proc3.jar"); + options.processorPath(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains("lib/proc1.jar")); + assertTrue(options.get(1).contains("lib/proc2.jar")); + assertTrue(options.get(1).contains("lib/proc3.jar")); + } + + @Test + void testProcessorPathWithEmptyCollection() { + options.processorPath(List.of()); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("", options.get(1)); + } + + @Test + void testProcessorPathWithEmptyVarargs() { + options.processorPath(new String[]{}); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + } + + @Test + void testProcessorPathWithFile() { + options.processorPath(new File("lib/processors.jar")); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("processors.jar")); + } + + @Test + void testProcessorPathWithPath() { + options.processorPath(Path.of("lib/processors.jar")); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("processors.jar")); + } + + @Test + void testProcessorPathWithSingleString() { + options.processorPath("lib/processors.jar"); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("lib/processors.jar", options.get(1)); + } + + @Test + void testProcessorPathWithVarargs() { + options.processorPath("lib/proc1.jar", "lib/proc2.jar"); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains("lib/proc1.jar")); + assertTrue(options.get(1).contains("lib/proc2.jar")); + } + } + + @Nested + class UpgradeModulePathTests { + @Test + void testUpgradeModulePathMethodChaining() { + options.upgradeModulePath("lib/upgrades") + .parameters() + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("--upgrade-module-path")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testUpgradeModulePathMultipleCalls() { + options.upgradeModulePath("lib/upgrade1") + .upgradeModulePath("lib/upgrade2"); + + assertEquals(4, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals("--upgrade-module-path", options.get(2)); + } + + @Test + void testUpgradeModulePathReturnsThis() { + var result = options.upgradeModulePath("lib/upgrades"); + assertSame(options, result); + } + + @Test + void testUpgradeModulePathWithCollection() { + var paths = Arrays.asList("lib/upg1", "lib/upg2", "lib/upg3"); + options.upgradeModulePath(paths); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib/upg1")); + assertTrue(options.get(1).contains("lib/upg2")); + assertTrue(options.get(1).contains("lib/upg3")); + } + + @Test + void testUpgradeModulePathWithEmptyCollection() { + options.upgradeModulePath(List.of()); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals("", options.get(1)); + } + + @Test + void testUpgradeModulePathWithEmptyVarargs() { + options.upgradeModulePath(new String[]{}); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + } + + @Test + void testUpgradeModulePathWithFile() { + options.upgradeModulePath(new File("lib/upgrades")); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("upgrades")); + } + + @Test + void testUpgradeModulePathWithPath() { + options.upgradeModulePath(Path.of("lib/upgrades")); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib")); + assertTrue(options.get(1).contains("upgrades")); + } + + @Test + void testUpgradeModulePathWithSingleString() { + options.upgradeModulePath("lib/upgrades"); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals("lib/upgrades", options.get(1)); + } + + @Test + void testUpgradeModulePathWithVarargs() { + options.upgradeModulePath("lib/upg1", "lib/upg2"); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertTrue(options.get(1).contains("lib/upg1")); + assertTrue(options.get(1).contains("lib/upg2")); + } + } } From 25c77ed5dfa5f11fe3b7046abfe58342635a28c9 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 21 Jan 2026 15:01:17 -0800 Subject: [PATCH 2/7] Improve method consistency --- .../rife/bld/operations/JavacOptions.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index a67c230..f85165b 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -566,7 +566,7 @@ public class JavacOptions extends ArrayList { public JavacOptions moduleSourcePath(File... paths) { return moduleSourcePath(Arrays.stream(paths) .map(File::getAbsolutePath) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -578,7 +578,7 @@ public class JavacOptions extends ArrayList { public JavacOptions moduleSourcePath(Path... paths) { return moduleSourcePath(Arrays.stream(paths) .map(Path::toString) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -588,7 +588,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions moduleSourcePath(String... paths) { - return moduleSourcePath(Arrays.asList(paths)); + add("--module-source-path"); + add(String.join(File.pathSeparator, paths)); + return this; } /** @@ -598,9 +600,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions moduleSourcePath(Collection paths) { - add("--module-source-path"); - add(String.join(File.pathSeparator, paths)); - return this; + return moduleSourcePath(paths.toArray(new String[0])); } /** @@ -679,7 +679,7 @@ public class JavacOptions extends ArrayList { public JavacOptions processorModulePath(File... paths) { return processorModulePath(Arrays.stream(paths) .map(File::getAbsolutePath) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -691,7 +691,7 @@ public class JavacOptions extends ArrayList { public JavacOptions processorModulePath(Path... paths) { return processorModulePath(Arrays.stream(paths) .map(Path::toString) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -701,7 +701,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions processorModulePath(String... paths) { - return processorModulePath(Arrays.asList(paths)); + add("--processor-module-path"); + add(String.join(File.pathSeparator, paths)); + return this; } /** @@ -711,9 +713,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorModulePath(Collection paths) { - add("--processor-module-path"); - add(String.join(File.pathSeparator, paths)); - return this; + return processorModulePath(paths.toArray(new String[0])); } /** @@ -723,7 +723,9 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processorPath(String... paths) { - return processorPath(Arrays.asList(paths)); + add("--processor-path"); + add(String.join(File.pathSeparator, paths)); + return this; } /** @@ -735,7 +737,7 @@ public class JavacOptions extends ArrayList { public JavacOptions processorPath(File... paths) { return processorPath(Arrays.stream(paths) .map(File::getAbsolutePath) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -747,7 +749,7 @@ public class JavacOptions extends ArrayList { public JavacOptions processorPath(Path... paths) { return processorPath(Arrays.stream(paths) .map(Path::toString) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -757,9 +759,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorPath(Collection paths) { - add("--processor-path"); - add(String.join(File.pathSeparator, paths)); - return this; + return processorPath(paths.toArray(new String[0])); } /** @@ -830,7 +830,7 @@ public class JavacOptions extends ArrayList { public JavacOptions upgradeModulePath(File... paths) { return upgradeModulePath(Arrays.stream(paths) .map(File::getAbsolutePath) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -842,7 +842,7 @@ public class JavacOptions extends ArrayList { public JavacOptions upgradeModulePath(Path... paths) { return upgradeModulePath(Arrays.stream(paths) .map(Path::toString) - .collect(Collectors.toList())); + .toArray(String[]::new)); } /** @@ -852,7 +852,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions upgradeModulePath(String... paths) { - return upgradeModulePath(Arrays.asList(paths)); + add("--upgrade-module-path"); + add(String.join(File.pathSeparator, paths)); + return this; } /** @@ -862,9 +864,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions upgradeModulePath(Collection paths) { - add("--upgrade-module-path"); - add(String.join(File.pathSeparator, paths)); - return this; + return upgradeModulePath(paths.toArray(new String[0])); } /** From b22257ed43846cde847e920849d0ffb160b80d82 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 22 Jan 2026 00:13:15 -0800 Subject: [PATCH 3/7] Refactor javac options to improve consistency and handle null/empty parameters --- .../rife/bld/operations/JavacOptions.java | 411 +++- .../rife/bld/operations/TestJavacOptions.java | 1984 ++++++++++++++--- 2 files changed, 1998 insertions(+), 397 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index f85165b..b079daa 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -5,15 +5,12 @@ package rife.bld.operations; import rife.tools.Convert; -import rife.tools.FileUtils; -import rife.tools.StringUtils; import java.io.File; import java.nio.file.Path; 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.operations.CompileOperation.COMPILE_OPTION_MODULE_PATH; @@ -24,6 +21,7 @@ import static rife.bld.operations.CompileOperation.COMPILE_OPTION_MODULE_PATH; * @author Geert Bevin (gbevin[remove] at uwyn dot com) * @since 1.5.18 */ +@SuppressWarnings("UnusedReturnValue") public class JavacOptions extends ArrayList { public enum DebuggingInfo { ALL, NONE, LINES, VAR, SOURCE @@ -80,6 +78,38 @@ public class JavacOptions extends ArrayList { VARARGS } + // Helper method to check if an array is not empty + private static boolean isNotEmpty(T[] array) { + return array != null && array.length > 0; + } + + // Helper method to check if a collection is not empty + private static boolean isNotEmpty(Collection collection) { + return collection != null && !collection.isEmpty(); + } + + /** + * Helper method to add path-based options + */ + private JavacOptions addPathOption(String option, Collection paths) { + if (isNotEmpty(paths)) { + add(option); + add(String.join(File.pathSeparator, paths)); + } + return this; + } + + /** + * Helper method to add comma-separated options + */ + private JavacOptions addCommaSeparatedOption(String option, Collection values) { + if (isNotEmpty(values)) { + add(option); + add(String.join(",", values)); + } + return this; + } + /** * Option to pass to annotation processors * @@ -100,7 +130,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addExports(String... modules) { - return addExports(Arrays.asList(modules)); + if (isNotEmpty(modules)) { + addExports(Arrays.asList(modules)); + } + return this; } /** @@ -111,10 +144,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions addExports(List modules) { - add("--add-exports"); - add(StringUtils.join(modules, ",")); - return this; + public JavacOptions addExports(Collection modules) { + return addCommaSeparatedOption("--add-exports", modules); } /** @@ -124,7 +155,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addReads(String... modules) { - return addReads(Arrays.asList(modules)); + if (isNotEmpty(modules)) { + addReads(Arrays.asList(modules)); + } + return this; } /** @@ -133,10 +167,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions addReads(List modules) { - add("--add-reads"); - add(StringUtils.join(modules, ",")); - return this; + public JavacOptions addReads(Collection modules) { + return addCommaSeparatedOption("--add-reads", modules); } /** @@ -147,7 +179,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions addModules(String... modules) { - return addModules(Arrays.asList(modules)); + if (isNotEmpty(modules)) { + addModules(Arrays.asList(modules)); + } + return this; } /** @@ -157,10 +192,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions addModules(List modules) { - add("--add-modules"); - add(StringUtils.join(modules, ",")); - return this; + public JavacOptions addModules(Collection modules) { + return addCommaSeparatedOption("--add-modules", modules); } /** @@ -217,7 +250,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions endorsedDirs(File... dirs) { - return endorsedDirs(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + endorsedDirs(Arrays.asList(dirs)); + } + return this; } /** @@ -226,7 +262,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions endorsedDirs(List dirs) { + public JavacOptions endorsedDirs(Collection dirs) { return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); } @@ -237,7 +273,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions endorsedDirs(Path... dirs) { - return endorsedDirsPaths(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + endorsedDirsPaths(Arrays.asList(dirs)); + } + return this; } /** @@ -246,7 +285,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions endorsedDirsPaths(List dirs) { + public JavacOptions endorsedDirsPaths(Collection dirs) { return endorsedDirs(dirs.stream().map(Path::toFile).toList()); } @@ -257,7 +296,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions endorsedDirs(String... dirs) { - return endorsedDirsStrings(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + endorsedDirsStrings(Arrays.asList(dirs)); + } + return this; } /** @@ -266,9 +308,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions endorsedDirsStrings(List dirs) { - add("-endorseddirs"); - add(String.join(",", dirs)); + public JavacOptions endorsedDirsStrings(Collection dirs) { + if (isNotEmpty(dirs)) { + add("-endorseddirs"); + add(String.join(",", dirs)); + } return this; } @@ -279,7 +323,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions extDirs(File... dirs) { - return extDirs(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + extDirs(Arrays.asList(dirs)); + } + return this; } /** @@ -288,7 +335,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions extDirs(List dirs) { + public JavacOptions extDirs(Collection dirs) { return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); } @@ -299,7 +346,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions extDirs(Path... dirs) { - return extDirsPaths(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + extDirsPaths(Arrays.asList(dirs)); + } + return this; } /** @@ -308,7 +358,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions extDirsPaths(List dirs) { + public JavacOptions extDirsPaths(Collection dirs) { return extDirs(dirs.stream().map(Path::toFile).toList()); } @@ -319,7 +369,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions extDirs(String... dirs) { - return extDirsStrings(Arrays.asList(dirs)); + if (isNotEmpty(dirs)) { + extDirsStrings(Arrays.asList(dirs)); + } + return this; } /** @@ -328,9 +381,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions extDirsStrings(List dirs) { - add("-extdirs"); - add(String.join(",", dirs)); + public JavacOptions extDirsStrings(Collection dirs) { + if (isNotEmpty(dirs)) { + add("-extdirs"); + add(String.join(",", dirs)); + } return this; } @@ -458,7 +513,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions limitModules(String... modules) { - return limitModules(Arrays.asList(modules)); + if (isNotEmpty(modules)) { + limitModules(Arrays.asList(modules)); + } + return this; } /** @@ -467,10 +525,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions limitModules(List modules) { - add("--limit-modules"); - add(StringUtils.join(modules, ",")); - return this; + public JavacOptions limitModules(Collection modules) { + return addCommaSeparatedOption("--limit-modules", modules); } /** @@ -480,7 +536,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions module(String... modules) { - return module(Arrays.asList(modules)); + if (isNotEmpty(modules)) { + module(Arrays.asList(modules)); + } + return this; } /** @@ -489,20 +548,22 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions module(List modules) { - add("--module"); - add(StringUtils.join(modules, ",")); - return this; + public JavacOptions module(Collection modules) { + return addCommaSeparatedOption("--module", modules); } /** + * /** * Specify where to find application modules * * @return this list of options * @since 1.5.18 */ public JavacOptions modulePath(File... paths) { - return modulePath(Arrays.asList(paths)); + if (isNotEmpty(paths)) { + modulePath(Arrays.asList(paths)); + } + return this; } /** @@ -511,7 +572,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.6.2 */ - public JavacOptions modulePath(List paths) { + public JavacOptions modulePath(Collection paths) { return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); } @@ -522,7 +583,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions modulePath(Path... paths) { - return modulePathPaths(Arrays.asList(paths)); + if (isNotEmpty(paths)) { + modulePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -531,8 +595,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions modulePathPaths(List paths) { - return modulePath(paths.stream().map(Path::toFile).toList()); + public JavacOptions modulePathPaths(Collection paths) { + return modulePathStrings(paths.stream().map(Path::toString).toList()); } /** @@ -542,7 +606,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions modulePath(String... paths) { - return modulePathStrings(Arrays.asList(paths)); + if (isNotEmpty(paths)) { + modulePathStrings(Arrays.asList(paths)); + } + return this; } /** @@ -551,10 +618,38 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions modulePathStrings(List paths) { - add(COMPILE_OPTION_MODULE_PATH); - add(FileUtils.joinPaths(paths)); - return this; + public JavacOptions modulePathStrings(Collection paths) { + return addPathOption(COMPILE_OPTION_MODULE_PATH, paths); + } + + /** + * Specify where to find input source files for multiple modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions moduleSourcePathStrings(Collection paths) { + return addPathOption("--module-source-path", paths); + } + + /** + * Specify where to find input source files for multiple modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions moduleSourcePathPaths(Collection paths) { + return moduleSourcePathStrings(paths.stream().map(Path::toString).toList()); + } + + /** + * Specify where to find input source files for multiple modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions moduleSourcePath(Collection paths) { + return moduleSourcePathStrings(paths.stream().map(File::getPath).toList()); } /** @@ -564,21 +659,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions moduleSourcePath(File... paths) { - return moduleSourcePath(Arrays.stream(paths) - .map(File::getAbsolutePath) - .toArray(String[]::new)); - } - - /** - * Specify where to find input source files for multiple modules - * - * @return this list of options - * @since 2.1 - */ - public JavacOptions moduleSourcePath(Path... paths) { - return moduleSourcePath(Arrays.stream(paths) - .map(Path::toString) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + moduleSourcePath(Arrays.asList(paths)); + } + return this; } /** @@ -588,8 +672,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions moduleSourcePath(String... paths) { - add("--module-source-path"); - add(String.join(File.pathSeparator, paths)); + if (isNotEmpty(paths)) { + moduleSourcePathStrings(Arrays.asList(paths)); + } return this; } @@ -597,10 +682,13 @@ public class JavacOptions extends ArrayList { * Specify where to find input source files for multiple modules * * @return this list of options - * @since 2.3.1 + * @since 2.1 */ - public JavacOptions moduleSourcePath(Collection paths) { - return moduleSourcePath(paths.toArray(new String[0])); + public JavacOptions moduleSourcePath(Path... paths) { + if (isNotEmpty(paths)) { + moduleSourcePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -655,7 +743,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processors(String... classnames) { - return processors(Arrays.asList(classnames)); + if (isNotEmpty(classnames)) { + processors(Arrays.asList(classnames)); + } + return this; } /** @@ -665,9 +756,7 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processors(Collection classnames) { - add("-processor"); - add(StringUtils.join(classnames, ",")); - return this; + return addCommaSeparatedOption("-processor", classnames); } /** @@ -677,9 +766,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processorModulePath(File... paths) { - return processorModulePath(Arrays.stream(paths) - .map(File::getAbsolutePath) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + processorModulePath(Arrays.asList(paths)); + } + return this; } /** @@ -689,9 +779,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions processorModulePath(Path... paths) { - return processorModulePath(Arrays.stream(paths) - .map(Path::toString) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + processorModulePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -701,8 +792,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions processorModulePath(String... paths) { - add("--processor-module-path"); - add(String.join(File.pathSeparator, paths)); + if (isNotEmpty(paths)) { + processorModulePathStrings(Arrays.asList(paths)); + } return this; } @@ -712,8 +804,28 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions processorModulePath(Collection paths) { - return processorModulePath(paths.toArray(new String[0])); + public JavacOptions processorModulePathPaths(Collection paths) { + return processorModulePathStrings(paths.stream().map(Path::toString).toList()); + } + + /** + * Specify a module path where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorModulePathStrings(Collection paths) { + return addPathOption("--processor-module-path", paths); + } + + /** + * Specify a module path where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorModulePath(Collection paths) { + return processorModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); } /** @@ -723,8 +835,9 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processorPath(String... paths) { - add("--processor-path"); - add(String.join(File.pathSeparator, paths)); + if (isNotEmpty(paths)) { + processorPathStrings(Arrays.asList(paths)); + } return this; } @@ -735,9 +848,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions processorPath(File... paths) { - return processorPath(Arrays.stream(paths) - .map(File::getAbsolutePath) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + processorPath(Arrays.asList(paths)); + } + return this; } /** @@ -747,9 +861,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions processorPath(Path... paths) { - return processorPath(Arrays.stream(paths) - .map(Path::toString) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + processorPathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -758,12 +873,32 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions processorPath(Collection paths) { - return processorPath(paths.toArray(new String[0])); + public JavacOptions processorPathStrings(Collection paths) { + return addPathOption("--processor-path", paths); } /** - * Check that API used is available in the specified profile + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPath(Collection paths) { + return processorPathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPathPaths(Collection paths) { + return processorPathStrings(paths.stream().map(Path::toString).toList()); + } + + /** + * Check that the API used is available in the specified profile * * @return this list of options * @since 1.5.18 @@ -828,9 +963,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions upgradeModulePath(File... paths) { - return upgradeModulePath(Arrays.stream(paths) - .map(File::getAbsolutePath) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + upgradeModulePath(Arrays.asList(paths)); + } + return this; } /** @@ -840,9 +976,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions upgradeModulePath(Path... paths) { - return upgradeModulePath(Arrays.stream(paths) - .map(Path::toString) - .toArray(String[]::new)); + if (isNotEmpty(paths)) { + upgradeModulePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -852,8 +989,9 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions upgradeModulePath(String... paths) { - add("--upgrade-module-path"); - add(String.join(File.pathSeparator, paths)); + if (isNotEmpty(paths)) { + upgradeModulePathStrings(Arrays.asList(paths)); + } return this; } @@ -863,8 +1001,28 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions upgradeModulePath(Collection paths) { - return upgradeModulePath(paths.toArray(new String[0])); + public JavacOptions upgradeModulePathStrings(Collection paths) { + return addPathOption("--upgrade-module-path", paths); + } + + /** + * Override location of upgradeable modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions upgradeModulePath(Collection paths) { + return upgradeModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + + /** + * Override location of upgradeable modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions upgradeModulePathPaths(Collection paths) { + return upgradeModulePathStrings(paths.stream().map(Path::toString).toList()); } /** @@ -896,7 +1054,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions xLint(XLintKey... keys) { - return xLint(Arrays.asList(keys)); + if (isNotEmpty(keys)) { + xLint(Arrays.asList(keys)); + } + return this; } /** @@ -905,7 +1066,7 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions xLint(List keys) { + public JavacOptions xLint(Collection keys) { return addXLintOption(keys, ""); } @@ -916,7 +1077,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions xLintDisable(XLintKey... keys) { - return xLintDisable(Arrays.asList(keys)); + if (isNotEmpty(keys)) { + xLintDisable(Arrays.asList(keys)); + } + return this; } /** @@ -925,20 +1089,21 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions xLintDisable(List keys) { - return addXLintOption(keys, "-"); + public JavacOptions xLintDisable(Collection keys) { + if (isNotEmpty(keys)) { + return addXLintOption(keys, "-"); + } + return this; } - private JavacOptions addXLintOption(List keys, String prefix) { - if (keys == null || keys.isEmpty()) { - return this; + private JavacOptions addXLintOption(Collection keys, String prefix) { + if (isNotEmpty(keys)) { + var keyString = keys.stream() + .map(key -> key.name().replace('_', '-').toLowerCase()) + .collect(Collectors.joining("," + prefix, prefix, "")); + + add("-Xlint:" + keyString); } - - var formattedKeys = keys.stream() - .map(key -> prefix + key.name().replace('_', '-').toLowerCase()) - .collect(Collectors.joining(",", "-Xlint:", "")); - - add(formattedKeys); return this; } } \ No newline at end of file diff --git a/src/test/java/rife/bld/operations/TestJavacOptions.java b/src/test/java/rife/bld/operations/TestJavacOptions.java index 089d661..a5653e7 100644 --- a/src/test/java/rife/bld/operations/TestJavacOptions.java +++ b/src/test/java/rife/bld/operations/TestJavacOptions.java @@ -75,18 +75,14 @@ class TestJavacOptions { void testAddExportsWithEmptyList() { options.addExports(List.of()); - assertEquals(2, options.size()); - assertEquals("--add-exports", options.get(0)); - assertEquals("", options.get(1)); + assertEquals(0, options.size()); } @Test void testAddExportsWithEmptyVarargs() { options.addExports(); - assertEquals(2, options.size()); - assertEquals("--add-exports", options.get(0)); - assertEquals("", options.get(1)); + assertEquals(0, options.size()); } @Test @@ -157,18 +153,14 @@ class TestJavacOptions { void testAddReadsWithEmptyList() { options.addReads(List.of()); - assertEquals(2, options.size()); - assertEquals("--add-reads", options.get(0)); - assertEquals("", options.get(1)); + assertEquals(0, options.size()); } @Test void testAddReadsWithEmptyVarargs() { options.addReads(); - assertEquals(2, options.size()); - assertEquals("--add-reads", options.get(0)); - assertEquals("", options.get(1)); + assertEquals(0, options.size()); } @Test @@ -966,25 +958,95 @@ class TestJavacOptions { @Nested class ModuleSourcePathTests { @Test - void testModuleSourcePathMethodChaining() { - options.moduleSourcePath("src/module1", "src/module2") - .parameters() - .deprecation(); + void testModuleSourcePathWithFile() { + var file = new File("src/modules"); + options.moduleSourcePath(file); - assertEquals(4, options.size()); - assertTrue(options.contains("--module-source-path")); - assertTrue(options.contains("-parameters")); - assertTrue(options.contains("-deprecation")); + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals(file.getPath(), options.get(1)); } @Test - void testModuleSourcePathMultipleCalls() { - options.moduleSourcePath("src/module1") - .moduleSourcePath("src/module2"); + void testModuleSourcePathWithMultipleFiles() { + var file1 = new File("src/module1"); + var file2 = new File("src/module2"); + options.moduleSourcePath(file1, file2); - assertEquals(4, options.size()); + assertEquals(2, options.size()); assertEquals("--module-source-path", options.get(0)); - assertEquals("--module-source-path", options.get(2)); + assertTrue(options.get(1).contains(file1.getPath())); + assertTrue(options.get(1).contains(file2.getPath())); + } + + @Test + void testModuleSourcePathWithFileCollection() { + var files = Arrays.asList( + new File("src/mod1"), + new File("src/mod2"), + new File("src/mod3") + ); + options.moduleSourcePath(files); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testModuleSourcePathWithPath() { + var path = Path.of("src/modules"); + options.moduleSourcePath(path); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals(path.toString(), options.get(1)); + } + + @Test + void testModuleSourcePathWithMultiplePaths() { + var path1 = Path.of("src/module1"); + var path2 = Path.of("src/module2"); + options.moduleSourcePath(path1, path2); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertTrue(options.get(1).contains(path1.toString())); + assertTrue(options.get(1).contains(path2.toString())); + } + + @Test + void testModuleSourcePathPathsCollection() { + var paths = Arrays.asList( + Path.of("src/mod1"), + Path.of("src/mod2"), + Path.of("src/mod3") + ); + options.moduleSourcePathPaths(paths); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testModuleSourcePathStringsCollection() { + var paths = Arrays.asList("src/mod1", "src/mod2", "src/mod3"); + options.moduleSourcePathStrings(paths); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testModuleSourcePathWithEmptyCollection() { + options.moduleSourcePathStrings(List.of()); + + assertEquals(0, options.size()); } @Test @@ -994,97 +1056,141 @@ class TestJavacOptions { } @Test - void testModuleSourcePathWithCollection() { - var paths = Arrays.asList("src/mod1", "src/mod2", "src/mod3"); - options.moduleSourcePath(paths); + void testModuleSourcePathMethodChaining() { + options.moduleSourcePath("src/modules") + .modulePath("lib/modules") + .release(17); - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - assertTrue(options.get(1).contains("src/mod1")); - assertTrue(options.get(1).contains("src/mod2")); - assertTrue(options.get(1).contains("src/mod3")); + assertEquals(6, options.size()); + assertTrue(options.contains("--module-source-path")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); } @Test - void testModuleSourcePathWithEmptyCollection() { - options.moduleSourcePath(List.of()); + void testMultipleModuleSourcePathCalls() { + options.moduleSourcePath("src/mod1") + .moduleSourcePath("src/mod2"); - assertEquals(2, options.size()); + assertEquals(4, options.size()); assertEquals("--module-source-path", options.get(0)); - assertEquals("", options.get(1)); - } - - @Test - void testModuleSourcePathWithEmptyVarargs() { - options.moduleSourcePath(""); - - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - } - - @Test - void testModuleSourcePathWithFile() { - options.moduleSourcePath(new File("src/modules")); - - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - assertTrue(options.get(1).contains("src")); - assertTrue(options.get(1).contains("modules")); - } - - @Test - void testModuleSourcePathWithPath() { - options.moduleSourcePath(Path.of("src/modules")); - - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - assertTrue(options.get(1).contains("src")); - assertTrue(options.get(1).contains("modules")); - } - - @Test - void testModuleSourcePathWithSingleString() { - options.moduleSourcePath("src/modules"); - - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - assertEquals("src/modules", options.get(1)); - } - - @Test - void testModuleSourcePathWithVarargs() { - options.moduleSourcePath("src/mod1", "src/mod2", "src/mod3"); - - assertEquals(2, options.size()); - assertEquals("--module-source-path", options.get(0)); - assertTrue(options.get(1).contains("src/mod1")); - assertTrue(options.get(1).contains("src/mod2")); - assertTrue(options.get(1).contains("src/mod3")); + assertEquals("src/mod1", options.get(1)); + assertEquals("--module-source-path", options.get(2)); + assertEquals("src/mod2", options.get(3)); } } @Nested class ProcessorModulePathTests { @Test - void testProcessorModulePathMethodChaining() { - options.processorModulePath("lib/processors") - .parameters() - .deprecation(); + void testProcessorModulePathWithFile() { + var file = new File("lib/processor-modules"); + options.processorModulePath(file); - assertEquals(4, options.size()); - assertTrue(options.contains("--processor-module-path")); - assertTrue(options.contains("-parameters")); - assertTrue(options.contains("-deprecation")); + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); } @Test - void testProcessorModulePathMultipleCalls() { - options.processorModulePath("lib/proc1") - .processorModulePath("lib/proc2"); + void testProcessorModulePathWithMultipleFiles() { + var file1 = new File("lib/proc1"); + var file2 = new File("lib/proc2"); + options.processorModulePath(file1, file2); - assertEquals(4, options.size()); + assertEquals(2, options.size()); assertEquals("--processor-module-path", options.get(0)); - assertEquals("--processor-module-path", options.get(2)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testProcessorModulePathWithFileCollection() { + var files = Arrays.asList( + new File("lib/proc1"), + new File("lib/proc2"), + new File("lib/proc3") + ); + options.processorModulePath(files); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testProcessorModulePathWithPath() { + var path = Path.of("lib/processor-modules"); + options.processorModulePath(path); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals(path.toString(), options.get(1)); + } + + @Test + void testProcessorModulePathWithMultiplePaths() { + var path1 = Path.of("lib/proc1"); + var path2 = Path.of("lib/proc2"); + options.processorModulePath(path1, path2); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertTrue(options.get(1).contains(path1.toString())); + assertTrue(options.get(1).contains(path2.toString())); + } + + @Test + void testProcessorModulePathPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/proc1"), + Path.of("lib/proc2"), + Path.of("lib/proc3") + ); + options.processorModulePathPaths(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testProcessorModulePathWithString() { + options.processorModulePath("lib/processors"); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals("lib/processors", options.get(1)); + } + + @Test + void testProcessorModulePathWithMultipleStrings() { + options.processorModulePath("lib/proc1", "lib/proc2", "lib/proc3"); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testProcessorModulePathStringsCollection() { + var paths = Arrays.asList("lib/proc1", "lib/proc2", "lib/proc3"); + options.processorModulePathStrings(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testProcessorModulePathWithEmptyCollection() { + options.processorModulePathStrings(List.of()); + + assertEquals(0, options.size()); } @Test @@ -1094,96 +1200,141 @@ class TestJavacOptions { } @Test - void testProcessorModulePathWithCollection() { - var paths = Arrays.asList("lib/proc1", "lib/proc2", "lib/proc3"); - options.processorModulePath(paths); + void testProcessorModulePathMethodChaining() { + options.processorModulePath("lib/proc-modules") + .processors("com.example.Processor") + .deprecation(); - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib/proc1")); - assertTrue(options.get(1).contains("lib/proc2")); - assertTrue(options.get(1).contains("lib/proc3")); + assertEquals(5, options.size()); + assertTrue(options.contains("--processor-module-path")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-deprecation")); } @Test - void testProcessorModulePathWithEmptyCollection() { - options.processorModulePath(List.of()); + void testMultipleProcessorModulePathCalls() { + options.processorModulePath("lib/proc1") + .processorModulePath("lib/proc2"); - assertEquals(2, options.size()); + assertEquals(4, options.size()); assertEquals("--processor-module-path", options.get(0)); - assertEquals("", options.get(1)); - } - - @Test - void testProcessorModulePathWithEmptyVarargs() { - options.processorModulePath(new String[]{}); - - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - } - - @Test - void testProcessorModulePathWithFile() { - options.processorModulePath(new File("lib/processors")); - - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("processors")); - } - - @Test - void testProcessorModulePathWithPath() { - options.processorModulePath(Path.of("lib/processors")); - - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("processors")); - } - - @Test - void testProcessorModulePathWithSingleString() { - options.processorModulePath("lib/processors"); - - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - assertEquals("lib/processors", options.get(1)); - } - - @Test - void testProcessorModulePathWithVarargs() { - options.processorModulePath("lib/proc1", "lib/proc2"); - - assertEquals(2, options.size()); - assertEquals("--processor-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib/proc1")); - assertTrue(options.get(1).contains("lib/proc2")); + assertEquals("lib/proc1", options.get(1)); + assertEquals("--processor-module-path", options.get(2)); + assertEquals("lib/proc2", options.get(3)); } } @Nested class ProcessorPathTests { @Test - void testProcessorPathMethodChaining() { - options.processorPath("lib/processors.jar") - .parameters() - .deprecation(); + void testProcessorPathWithString() { + options.processorPath("lib/processors.jar"); - assertEquals(4, options.size()); - assertTrue(options.contains("--processor-path")); - assertTrue(options.contains("-parameters")); - assertTrue(options.contains("-deprecation")); + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("lib/processors.jar", options.get(1)); } @Test - void testProcessorPathMultipleCalls() { - options.processorPath("lib/proc1.jar") - .processorPath("lib/proc2.jar"); + void testProcessorPathWithMultipleStrings() { + options.processorPath("lib/proc1.jar", "lib/proc2.jar", "lib/proc3.jar"); - assertEquals(4, options.size()); + assertEquals(2, options.size()); assertEquals("--processor-path", options.get(0)); - assertEquals("--processor-path", options.get(2)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testProcessorPathStringsCollection() { + var paths = Arrays.asList("lib/proc1.jar", "lib/proc2.jar", "lib/proc3.jar"); + options.processorPathStrings(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testProcessorPathWithFile() { + var file = new File("lib/processors.jar"); + options.processorPath(file); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testProcessorPathWithMultipleFiles() { + var file1 = new File("lib/proc1.jar"); + var file2 = new File("lib/proc2.jar"); + options.processorPath(file1, file2); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testProcessorPathWithFileCollection() { + var files = Arrays.asList( + new File("lib/proc1.jar"), + new File("lib/proc2.jar"), + new File("lib/proc3.jar") + ); + options.processorPath(files); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testProcessorPathWithPath() { + var path = Path.of("lib/processors.jar"); + options.processorPath(path); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals(path.toString(), options.get(1)); + } + + @Test + void testProcessorPathWithMultiplePaths() { + var path1 = Path.of("lib/proc1.jar"); + var path2 = Path.of("lib/proc2.jar"); + options.processorPath(path1, path2); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertTrue(options.get(1).contains(path1.toString())); + assertTrue(options.get(1).contains(path2.toString())); + } + + @Test + void testProcessorPathPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/proc1.jar"), + Path.of("lib/proc2.jar"), + Path.of("lib/proc3.jar") + ); + options.processorPathPaths(paths); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testProcessorPathWithEmptyCollection() { + options.processorPathStrings(List.of()); + + assertEquals(0, options.size()); } @Test @@ -1193,96 +1344,151 @@ class TestJavacOptions { } @Test - void testProcessorPathWithCollection() { - var paths = Arrays.asList("lib/proc1.jar", "lib/proc2.jar", "lib/proc3.jar"); - options.processorPath(paths); + void testProcessorPathMethodChaining() { + options.processorPath("lib/processors.jar") + .processors("com.example.Processor") + .process(JavacOptions.Processing.ONLY); - assertEquals(2, options.size()); - assertEquals("--processor-path", options.get(0)); - assertTrue(options.get(1).contains("lib/proc1.jar")); - assertTrue(options.get(1).contains("lib/proc2.jar")); - assertTrue(options.get(1).contains("lib/proc3.jar")); + assertEquals(5, options.size()); + assertTrue(options.contains("--processor-path")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-proc:only")); } @Test - void testProcessorPathWithEmptyCollection() { - options.processorPath(List.of()); + void testMultipleProcessorPathCalls() { + options.processorPath("lib/proc1.jar") + .processorPath("lib/proc2.jar"); - assertEquals(2, options.size()); + assertEquals(4, options.size()); assertEquals("--processor-path", options.get(0)); - assertEquals("", options.get(1)); + assertEquals("lib/proc1.jar", options.get(1)); + assertEquals("--processor-path", options.get(2)); + assertEquals("lib/proc2.jar", options.get(3)); } @Test - void testProcessorPathWithEmptyVarargs() { - options.processorPath(new String[]{}); + void testProcessorPathWithDirectoryAndJar() { + options.processorPath("lib/processors", "lib/extra-processors.jar"); assertEquals(2, options.size()); assertEquals("--processor-path", options.get(0)); - } - - @Test - void testProcessorPathWithFile() { - options.processorPath(new File("lib/processors.jar")); - - assertEquals(2, options.size()); - assertEquals("--processor-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("processors.jar")); - } - - @Test - void testProcessorPathWithPath() { - options.processorPath(Path.of("lib/processors.jar")); - - assertEquals(2, options.size()); - assertEquals("--processor-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("processors.jar")); - } - - @Test - void testProcessorPathWithSingleString() { - options.processorPath("lib/processors.jar"); - - assertEquals(2, options.size()); - assertEquals("--processor-path", options.get(0)); - assertEquals("lib/processors.jar", options.get(1)); - } - - @Test - void testProcessorPathWithVarargs() { - options.processorPath("lib/proc1.jar", "lib/proc2.jar"); - - assertEquals(2, options.size()); - assertEquals("--processor-path", options.get(0)); - assertTrue(options.get(1).contains("lib/proc1.jar")); - assertTrue(options.get(1).contains("lib/proc2.jar")); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(2, paths.length); } } @Nested class UpgradeModulePathTests { @Test - void testUpgradeModulePathMethodChaining() { - options.upgradeModulePath("lib/upgrades") - .parameters() - .deprecation(); + void testUpgradeModulePathWithFile() { + var file = new File("lib/upgrades"); + options.upgradeModulePath(file); - assertEquals(4, options.size()); - assertTrue(options.contains("--upgrade-module-path")); - assertTrue(options.contains("-parameters")); - assertTrue(options.contains("-deprecation")); + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); } @Test - void testUpgradeModulePathMultipleCalls() { - options.upgradeModulePath("lib/upgrade1") - .upgradeModulePath("lib/upgrade2"); + void testUpgradeModulePathWithMultipleFiles() { + var file1 = new File("lib/upgrade1"); + var file2 = new File("lib/upgrade2"); + options.upgradeModulePath(file1, file2); - assertEquals(4, options.size()); + assertEquals(2, options.size()); assertEquals("--upgrade-module-path", options.get(0)); - assertEquals("--upgrade-module-path", options.get(2)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testUpgradeModulePathWithFileCollection() { + var files = Arrays.asList( + new File("lib/upgrade1"), + new File("lib/upgrade2"), + new File("lib/upgrade3") + ); + options.upgradeModulePath(files); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testUpgradeModulePathWithPath() { + var path = Path.of("lib/upgrades"); + options.upgradeModulePath(path); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals(path.toString(), options.get(1)); + } + + @Test + void testUpgradeModulePathWithMultiplePaths() { + var path1 = Path.of("lib/upgrade1"); + var path2 = Path.of("lib/upgrade2"); + options.upgradeModulePath(path1, path2); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertTrue(options.get(1).contains(path1.toString())); + assertTrue(options.get(1).contains(path2.toString())); + } + + @Test + void testUpgradeModulePathPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/upgrade1"), + Path.of("lib/upgrade2"), + Path.of("lib/upgrade3") + ); + options.upgradeModulePathPaths(paths); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testUpgradeModulePathWithString() { + options.upgradeModulePath("lib/upgrades"); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals("lib/upgrades", options.get(1)); + } + + @Test + void testUpgradeModulePathWithMultipleStrings() { + options.upgradeModulePath("lib/upgrade1", "lib/upgrade2", "lib/upgrade3"); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testUpgradeModulePathStringsCollection() { + var paths = Arrays.asList("lib/upgrade1", "lib/upgrade2", "lib/upgrade3"); + options.upgradeModulePathStrings(paths); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testUpgradeModulePathWithEmptyCollection() { + options.upgradeModulePathStrings(List.of()); + + assertEquals(0, options.size()); } @Test @@ -1292,71 +1498,1301 @@ class TestJavacOptions { } @Test - void testUpgradeModulePathWithCollection() { - var paths = Arrays.asList("lib/upg1", "lib/upg2", "lib/upg3"); - options.upgradeModulePath(paths); + void testUpgradeModulePathMethodChaining() { + options.upgradeModulePath("lib/upgrades") + .modulePath("lib/modules") + .release(17); - assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib/upg1")); - assertTrue(options.get(1).contains("lib/upg2")); - assertTrue(options.get(1).contains("lib/upg3")); + assertEquals(6, options.size()); + assertTrue(options.contains("--upgrade-module-path")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); } @Test - void testUpgradeModulePathWithEmptyCollection() { - options.upgradeModulePath(List.of()); + void testMultipleUpgradeModulePathCalls() { + options.upgradeModulePath("lib/upgrade1") + .upgradeModulePath("lib/upgrade2"); - assertEquals(2, options.size()); + assertEquals(4, options.size()); assertEquals("--upgrade-module-path", options.get(0)); - assertEquals("", options.get(1)); + assertEquals("lib/upgrade1", options.get(1)); + assertEquals("--upgrade-module-path", options.get(2)); + assertEquals("lib/upgrade2", options.get(3)); } @Test - void testUpgradeModulePathWithEmptyVarargs() { - options.upgradeModulePath(new String[]{}); + void testUpgradeModulePathWithSystem() { + options.upgradeModulePath("lib/upgrades") + .system("none") + .addModules("java.sql"); - assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); + assertEquals(6, options.size()); + assertTrue(options.contains("--upgrade-module-path")); + assertTrue(options.contains("--system")); + assertTrue(options.contains("--add-modules")); + } + } + + @Nested + class AnnotationOptionTests { + @Test + void testAnnotationOptionWithKeyValue() { + options.annotationOption("debug", "true"); + + assertEquals(1, options.size()); + assertEquals("-Adebug=true", options.get(0)); } @Test - void testUpgradeModulePathWithFile() { - options.upgradeModulePath(new File("lib/upgrades")); + void testAnnotationOptionMultipleCalls() { + options.annotationOption("debug", "true") + .annotationOption("verbose", "false"); assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("upgrades")); + assertEquals("-Adebug=true", options.get(0)); + assertEquals("-Averbose=false", options.get(1)); } @Test - void testUpgradeModulePathWithPath() { - options.upgradeModulePath(Path.of("lib/upgrades")); - - assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib")); - assertTrue(options.get(1).contains("upgrades")); + void testAnnotationOptionReturnsThis() { + var result = options.annotationOption("key", "value"); + assertSame(options, result); } @Test - void testUpgradeModulePathWithSingleString() { - options.upgradeModulePath("lib/upgrades"); + void testAnnotationOptionWithComplexValue() { + options.annotationOption("outputDir", "/path/to/output"); - assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); - assertEquals("lib/upgrades", options.get(1)); + assertEquals(1, options.size()); + assertEquals("-AoutputDir=/path/to/output", options.get(0)); } @Test - void testUpgradeModulePathWithVarargs() { - options.upgradeModulePath("lib/upg1", "lib/upg2"); + void testAnnotationOptionMethodChaining() { + options.annotationOption("debug", "true") + .processors("com.example.Processor") + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("-Adebug=true")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-deprecation")); + } + } + + @Nested + class AddModulesTests { + @Test + void testAddModulesWithSingleModule() { + options.addModules("java.sql"); assertEquals(2, options.size()); - assertEquals("--upgrade-module-path", options.get(0)); - assertTrue(options.get(1).contains("lib/upg1")); - assertTrue(options.get(1).contains("lib/upg2")); + assertEquals("--add-modules", options.get(0)); + assertEquals("java.sql", options.get(1)); + } + + @Test + void testAddModulesWithVarargs() { + options.addModules("java.sql", "java.xml", "java.desktop"); + + assertEquals(2, options.size()); + assertEquals("--add-modules", options.get(0)); + assertEquals("java.sql,java.xml,java.desktop", options.get(1)); + } + + @Test + void testAddModulesWithList() { + var modules = Arrays.asList("java.sql", "java.xml", "java.desktop"); + options.addModules(modules); + + assertEquals(2, options.size()); + assertEquals("--add-modules", options.get(0)); + assertEquals("java.sql,java.xml,java.desktop", options.get(1)); + } + + @Test + void testAddModulesWithEmptyVarargs() { + options.addModules(); + + assertEquals(0, options.size()); + } + + @Test + void testAddModulesWithEmptyList() { + options.addModules(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testAddModulesReturnsThis() { + var result = options.addModules("java.sql"); + assertSame(options, result); + } + + @Test + void testAddModulesMethodChaining() { + options.addModules("java.sql") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--add-modules")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + + @Test + void testAddModulesWithAllModulePath() { + options.addModules("ALL-MODULE-PATH"); + + assertEquals(2, options.size()); + assertEquals("--add-modules", options.get(0)); + assertEquals("ALL-MODULE-PATH", options.get(1)); + } + } + + @Nested + class EncodingTests { + @Test + void testEncodingWithUTF8() { + options.encoding("UTF-8"); + + assertEquals(2, options.size()); + assertEquals("-encoding", options.get(0)); + assertEquals("UTF-8", options.get(1)); + } + + @Test + void testEncodingWithISO88591() { + options.encoding("ISO-8859-1"); + + assertEquals(2, options.size()); + assertEquals("-encoding", options.get(0)); + assertEquals("ISO-8859-1", options.get(1)); + } + + @Test + void testEncodingReturnsThis() { + var result = options.encoding("UTF-8"); + assertSame(options, result); + } + + @Test + void testEncodingMethodChaining() { + options.encoding("UTF-8") + .deprecation() + .parameters(); + + assertEquals(4, options.size()); + assertTrue(options.contains("-encoding")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + + @Test + void testMultipleEncodingCalls() { + options.encoding("UTF-8") + .encoding("ISO-8859-1"); + + assertEquals(4, options.size()); + assertEquals("-encoding", options.get(0)); + assertEquals("UTF-8", options.get(1)); + assertEquals("-encoding", options.get(2)); + assertEquals("ISO-8859-1", options.get(3)); + } + } + + @Nested + class DeprecationTests { + @Test + void testDeprecation() { + options.deprecation(); + + assertEquals(1, options.size()); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testDeprecationReturnsThis() { + var result = options.deprecation(); + assertSame(options, result); + } + + @Test + void testDeprecationMethodChaining() { + options.deprecation() + .parameters() + .warningError(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-Werror")); + } + } + + @Nested + class EnablePreviewTests { + @Test + void testEnablePreview() { + options.enablePreview(); + + assertEquals(1, options.size()); + assertTrue(options.contains("--enable-preview")); + } + + @Test + void testEnablePreviewReturnsThis() { + var result = options.enablePreview(); + assertSame(options, result); + } + + @Test + void testEnablePreviewWithRelease() { + options.release(21) + .enablePreview(); + + assertEquals(3, options.size()); + assertTrue(options.containsRelease()); + assertTrue(options.contains("--enable-preview")); + } + } + + @Nested + class EndorsedDirsTests { + @Test + void testEndorsedDirsWithFile() { + var file = new File("lib/endorsed"); + options.endorsedDirs(file); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testEndorsedDirsWithMultipleFiles() { + var file1 = new File("lib/endorsed1"); + var file2 = new File("lib/endorsed2"); + options.endorsedDirs(file1, file2); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testEndorsedDirsWithFileCollection() { + var files = Arrays.asList( + new File("lib/endorsed1"), + new File("lib/endorsed2"), + new File("lib/endorsed3") + ); + options.endorsedDirs(files); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + var paths = options.get(1).split(","); + assertEquals(3, paths.length); + } + + @Test + void testEndorsedDirsWithPath() { + var path = Path.of("lib/endorsed"); + options.endorsedDirs(path); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + } + + @Test + void testEndorsedDirsWithMultiplePaths() { + var path1 = Path.of("lib/endorsed1"); + var path2 = Path.of("lib/endorsed2"); + options.endorsedDirs(path1, path2); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + } + + @Test + void testEndorsedDirsPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/endorsed1"), + Path.of("lib/endorsed2"), + Path.of("lib/endorsed3") + ); + options.endorsedDirsPaths(paths); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + var pathArray = options.get(1).split(","); + assertEquals(3, pathArray.length); + } + + @Test + void testEndorsedDirsWithString() { + options.endorsedDirs("lib/endorsed"); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + assertEquals("lib/endorsed", options.get(1)); + } + + @Test + void testEndorsedDirsWithMultipleStrings() { + options.endorsedDirs("lib/endorsed1", "lib/endorsed2", "lib/endorsed3"); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + var paths = options.get(1).split(","); + assertEquals(3, paths.length); + } + + @Test + void testEndorsedDirsStringsCollection() { + var paths = Arrays.asList("lib/endorsed1", "lib/endorsed2", "lib/endorsed3"); + options.endorsedDirsStrings(paths); + + assertEquals(2, options.size()); + assertEquals("-endorseddirs", options.get(0)); + var pathArray = options.get(1).split(","); + assertEquals(3, pathArray.length); + } + + @Test + void testEndorsedDirsWithEmptyCollection() { + options.endorsedDirsStrings(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testEndorsedDirsReturnsThis() { + var result = options.endorsedDirs("lib/endorsed"); + assertSame(options, result); + } + } + + @Nested + class ExtDirsTests { + @Test + void testExtDirsWithFile() { + var file = new File("lib/ext"); + options.extDirs(file); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testExtDirsWithMultipleFiles() { + var file1 = new File("lib/ext1"); + var file2 = new File("lib/ext2"); + options.extDirs(file1, file2); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testExtDirsWithFileCollection() { + var files = Arrays.asList( + new File("lib/ext1"), + new File("lib/ext2"), + new File("lib/ext3") + ); + options.extDirs(files); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + var paths = options.get(1).split(","); + assertEquals(3, paths.length); + } + + @Test + void testExtDirsWithPath() { + var path = Path.of("lib/ext"); + options.extDirs(path); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + } + + @Test + void testExtDirsWithMultiplePaths() { + var path1 = Path.of("lib/ext1"); + var path2 = Path.of("lib/ext2"); + options.extDirs(path1, path2); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + } + + @Test + void testExtDirsPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/ext1"), + Path.of("lib/ext2"), + Path.of("lib/ext3") + ); + options.extDirsPaths(paths); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + var pathArray = options.get(1).split(","); + assertEquals(3, pathArray.length); + } + + @Test + void testExtDirsWithString() { + options.extDirs("lib/ext"); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + assertEquals("lib/ext", options.get(1)); + } + + @Test + void testExtDirsWithMultipleStrings() { + options.extDirs("lib/ext1", "lib/ext2", "lib/ext3"); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + var paths = options.get(1).split(","); + assertEquals(3, paths.length); + } + + @Test + void testExtDirsStringsCollection() { + var paths = Arrays.asList("lib/ext1", "lib/ext2", "lib/ext3"); + options.extDirsStrings(paths); + + assertEquals(2, options.size()); + assertEquals("-extdirs", options.get(0)); + var pathArray = options.get(1).split(","); + assertEquals(3, pathArray.length); + } + + @Test + void testExtDirsWithEmptyCollection() { + options.extDirsStrings(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testExtDirsReturnsThis() { + var result = options.extDirs("lib/ext"); + assertSame(options, result); + } + } + + @Nested + class DebuggingInfoTests { + @Test + void testDebuggingInfoAll() { + options.debuggingInfo(JavacOptions.DebuggingInfo.ALL); + + assertEquals(1, options.size()); + assertEquals("-g", options.get(0)); + } + + @Test + void testDebuggingInfoNone() { + options.debuggingInfo(JavacOptions.DebuggingInfo.NONE); + + assertEquals(1, options.size()); + assertEquals("-g:none", options.get(0)); + } + + @Test + void testDebuggingInfoLines() { + options.debuggingInfo(JavacOptions.DebuggingInfo.LINES); + + assertEquals(1, options.size()); + assertEquals("-g:lines", options.get(0)); + } + + @Test + void testDebuggingInfoVar() { + options.debuggingInfo(JavacOptions.DebuggingInfo.VAR); + + assertEquals(1, options.size()); + assertEquals("-g:var", options.get(0)); + } + + @Test + void testDebuggingInfoSource() { + options.debuggingInfo(JavacOptions.DebuggingInfo.SOURCE); + + assertEquals(1, options.size()); + assertEquals("-g:source", options.get(0)); + } + + @Test + void testDebuggingInfoReturnsThis() { + var result = options.debuggingInfo(JavacOptions.DebuggingInfo.ALL); + assertSame(options, result); + } + + @Test + void testDebuggingInfoMethodChaining() { + options.debuggingInfo(JavacOptions.DebuggingInfo.LINES) + .deprecation() + .parameters(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-g:lines")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + } + + @Nested + class NativeHeadersTests { + @Test + void testNativeHeadersWithFile() { + var file = new File("build/headers"); + options.nativeHeaders(file); + + assertEquals(2, options.size()); + assertEquals("-h", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testNativeHeadersWithPath() { + var path = Path.of("build/headers"); + options.nativeHeaders(path); + + assertEquals(2, options.size()); + assertEquals("-h", options.get(0)); + assertEquals(path.toFile().getAbsolutePath(), options.get(1)); + } + + @Test + void testNativeHeadersWithString() { + options.nativeHeaders("build/headers"); + + assertEquals(2, options.size()); + assertEquals("-h", options.get(0)); + assertEquals("build/headers", options.get(1)); + } + + @Test + void testNativeHeadersReturnsThis() { + var result = options.nativeHeaders("build/headers"); + assertSame(options, result); + } + + @Test + void testNativeHeadersMethodChaining() { + options.nativeHeaders("build/headers") + .deprecation() + .parameters(); + + assertEquals(4, options.size()); + assertTrue(options.contains("-h")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + } + + @Nested + class ImplicitTests { + @Test + void testImplicitNone() { + options.implicit(JavacOptions.Implicit.NONE); + + assertEquals(1, options.size()); + assertEquals("-implicit:none", options.get(0)); + } + + @Test + void testImplicitClass() { + options.implicit(JavacOptions.Implicit.CLASS); + + assertEquals(1, options.size()); + assertEquals("-implicit:class", options.get(0)); + } + + @Test + void testImplicitReturnsThis() { + var result = options.implicit(JavacOptions.Implicit.NONE); + assertSame(options, result); + } + + @Test + void testImplicitMethodChaining() { + options.implicit(JavacOptions.Implicit.CLASS) + .deprecation() + .parameters(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-implicit:class")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + } + + @Nested + class LimitModulesTests { + @Test + void testLimitModulesWithSingleModule() { + options.limitModules("java.base"); + + assertEquals(2, options.size()); + assertEquals("--limit-modules", options.get(0)); + assertEquals("java.base", options.get(1)); + } + + @Test + void testLimitModulesWithVarargs() { + options.limitModules("java.base", "java.sql", "java.xml"); + + assertEquals(2, options.size()); + assertEquals("--limit-modules", options.get(0)); + assertEquals("java.base,java.sql,java.xml", options.get(1)); + } + + @Test + void testLimitModulesWithList() { + var modules = Arrays.asList("java.base", "java.sql", "java.xml"); + options.limitModules(modules); + + assertEquals(2, options.size()); + assertEquals("--limit-modules", options.get(0)); + assertEquals("java.base,java.sql,java.xml", options.get(1)); + } + + @Test + void testLimitModulesWithEmptyVarargs() { + options.limitModules(); + + assertEquals(0, options.size()); + } + + @Test + void testLimitModulesWithEmptyList() { + options.limitModules(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testLimitModulesReturnsThis() { + var result = options.limitModules("java.base"); + assertSame(options, result); + } + + @Test + void testLimitModulesMethodChaining() { + options.limitModules("java.base") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--limit-modules")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + } + + @Nested + class ModuleTests { + @Test + void testModuleWithSingleModule() { + options.module("com.example.myapp"); + + assertEquals(2, options.size()); + assertEquals("--module", options.get(0)); + assertEquals("com.example.myapp", options.get(1)); + } + + @Test + void testModuleWithVarargs() { + options.module("com.example.module1", "com.example.module2", "com.example.module3"); + + assertEquals(2, options.size()); + assertEquals("--module", options.get(0)); + assertEquals("com.example.module1,com.example.module2,com.example.module3", options.get(1)); + } + + @Test + void testModuleWithList() { + var modules = Arrays.asList("com.example.module1", "com.example.module2", "com.example.module3"); + options.module(modules); + + assertEquals(2, options.size()); + assertEquals("--module", options.get(0)); + assertEquals("com.example.module1,com.example.module2,com.example.module3", options.get(1)); + } + + @Test + void testModuleWithEmptyVarargs() { + options.module(); + + assertEquals(0, options.size()); + } + + @Test + void testModuleWithEmptyList() { + options.module(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testModuleReturnsThis() { + var result = options.module("com.example.myapp"); + assertSame(options, result); + } + + @Test + void testModuleMethodChaining() { + options.module("com.example.myapp") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--module")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + } + + @Nested + class ModulePathTests { + @Test + void testModulePathWithFile() { + var file = new File("lib/modules"); + options.modulePath(file); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testModulePathWithMultipleFiles() { + var file1 = new File("lib/modules1"); + var file2 = new File("lib/modules2"); + options.modulePath(file1, file2); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + assertTrue(options.get(1).contains(file1.getAbsolutePath())); + assertTrue(options.get(1).contains(file2.getAbsolutePath())); + } + + @Test + void testModulePathWithFileCollection() { + var files = Arrays.asList( + new File("lib/modules1"), + new File("lib/modules2"), + new File("lib/modules3") + ); + options.modulePath(files); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testModulePathWithPath() { + var path = Path.of("lib/modules"); + options.modulePath(path); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + assertEquals(path.toString(), options.get(1)); + } + + @Test + void testModulePathWithMultiplePaths() { + var path1 = Path.of("lib/modules1"); + var path2 = Path.of("lib/modules2"); + options.modulePath(path1, path2); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + assertTrue(options.get(1).contains(path1.toString())); + assertTrue(options.get(1).contains(path2.toString())); + } + + @Test + void testModulePathPathsCollection() { + var paths = Arrays.asList( + Path.of("lib/modules1"), + Path.of("lib/modules2"), + Path.of("lib/modules3") + ); + options.modulePathPaths(paths); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testModulePathWithString() { + options.modulePath("lib/modules"); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + assertEquals("lib/modules", options.get(1)); + } + + @Test + void testModulePathWithMultipleStrings() { + options.modulePath("lib/modules1", "lib/modules2", "lib/modules3"); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(3, paths.length); + } + + @Test + void testModulePathStringsCollection() { + var paths = Arrays.asList("lib/modules1", "lib/modules2", "lib/modules3"); + options.modulePathStrings(paths); + + assertEquals(2, options.size()); + assertEquals("--module-path", options.get(0)); + var pathArray = options.get(1).split(File.pathSeparator); + assertEquals(3, pathArray.length); + } + + @Test + void testModulePathWithEmptyCollection() { + options.modulePathStrings(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testModulePathReturnsThis() { + var result = options.modulePath("lib/modules"); + assertSame(options, result); + } + + @Test + void testModulePathMethodChaining() { + options.modulePath("lib/modules") + .addModules("java.sql") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--module-path")); + assertTrue(options.contains("--add-modules")); + assertTrue(options.containsRelease()); + } + } + + @Nested + class ModuleVersionTests { + @Test + void testModuleVersion() { + options.moduleVersion("1.0.0"); + + assertEquals(2, options.size()); + assertEquals("--module-version", options.get(0)); + assertEquals("1.0.0", options.get(1)); + } + + @Test + void testModuleVersionReturnsThis() { + var result = options.moduleVersion("1.0.0"); + assertSame(options, result); + } + + @Test + void testModuleVersionMethodChaining() { + options.moduleVersion("1.0.0") + .module("com.example.myapp") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--module-version")); + assertTrue(options.contains("--module")); + assertTrue(options.containsRelease()); + } + + @Test + void testMultipleModuleVersionCalls() { + options.moduleVersion("1.0.0") + .moduleVersion("2.0.0"); + + assertEquals(4, options.size()); + assertEquals("--module-version", options.get(0)); + assertEquals("1.0.0", options.get(1)); + assertEquals("--module-version", options.get(2)); + assertEquals("2.0.0", options.get(3)); + } + } + + @Nested + class NoWarnTests { + @Test + void testNoWarn() { + options.noWarn(); + + assertEquals(1, options.size()); + assertTrue(options.contains("-nowarn")); + } + + @Test + void testNoWarnReturnsThis() { + var result = options.noWarn(); + assertSame(options, result); + } + + @Test + void testNoWarnMethodChaining() { + options.noWarn() + .parameters() + .deprecation(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-nowarn")); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + } + } + + @Nested + class ParametersTests { + @Test + void testParameters() { + options.parameters(); + + assertEquals(1, options.size()); + assertTrue(options.contains("-parameters")); + } + + @Test + void testParametersReturnsThis() { + var result = options.parameters(); + assertSame(options, result); + } + + @Test + void testParametersMethodChaining() { + options.parameters() + .deprecation() + .warningError(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-parameters")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-Werror")); + } + } + + @Nested + class ProcessTests { + @Test + void testProcessFull() { + options.process(JavacOptions.Processing.FULL); + + assertEquals(1, options.size()); + assertEquals("-proc:full", options.get(0)); + } + + @Test + void testProcessNone() { + options.process(JavacOptions.Processing.NONE); + + assertEquals(1, options.size()); + assertEquals("-proc:none", options.get(0)); + } + + @Test + void testProcessOnly() { + options.process(JavacOptions.Processing.ONLY); + + assertEquals(1, options.size()); + assertEquals("-proc:only", options.get(0)); + } + + @Test + void testProcessReturnsThis() { + var result = options.process(JavacOptions.Processing.ONLY); + assertSame(options, result); + } + + @Test + void testProcessMethodChaining() { + options.process(JavacOptions.Processing.ONLY) + .processors("com.example.Processor") + .deprecation(); + + assertEquals(4, options.size()); + assertTrue(options.contains("-proc:only")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-deprecation")); + } + } + + @Nested + class ProcessorsTests { + @Test + void testProcessorsWithSingleProcessor() { + options.processors("com.example.MyProcessor"); + + assertEquals(2, options.size()); + assertEquals("-processor", options.get(0)); + assertEquals("com.example.MyProcessor", options.get(1)); + } + + @Test + void testProcessorsWithVarargs() { + options.processors("com.example.Processor1", "com.example.Processor2", "com.example.Processor3"); + + assertEquals(2, options.size()); + assertEquals("-processor", options.get(0)); + assertEquals("com.example.Processor1,com.example.Processor2,com.example.Processor3", options.get(1)); + } + + @Test + void testProcessorsWithList() { + var processors = Arrays.asList("com.example.Processor1", "com.example.Processor2", "com.example.Processor3"); + options.processors(processors); + + assertEquals(2, options.size()); + assertEquals("-processor", options.get(0)); + assertEquals("com.example.Processor1,com.example.Processor2,com.example.Processor3", options.get(1)); + } + + @Test + void testProcessorsWithEmptyVarargs() { + options.processors(); + + assertEquals(0, options.size()); + } + + @Test + void testProcessorsWithEmptyList() { + options.processors(List.of()); + + assertEquals(0, options.size()); + } + + @Test + void testProcessorsReturnsThis() { + var result = options.processors("com.example.MyProcessor"); + assertSame(options, result); + } + + @Test + void testProcessorsMethodChaining() { + options.processors("com.example.MyProcessor") + .processorPath("lib/processors.jar") + .deprecation(); + + assertEquals(5, options.size()); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("--processor-path")); + assertTrue(options.contains("-deprecation")); + } + } + + @Nested + class ProfileTests { + @Test + void testProfile() { + options.profile("compact1"); + + assertEquals(2, options.size()); + assertEquals("-profile", options.get(0)); + assertEquals("compact1", options.get(1)); + } + + @Test + void testProfileCompact2() { + options.profile("compact2"); + + assertEquals(2, options.size()); + assertEquals("-profile", options.get(0)); + assertEquals("compact2", options.get(1)); + } + + @Test + void testProfileCompact3() { + options.profile("compact3"); + + assertEquals(2, options.size()); + assertEquals("-profile", options.get(0)); + assertEquals("compact3", options.get(1)); + } + + @Test + void testProfileReturnsThis() { + var result = options.profile("compact1"); + assertSame(options, result); + } + + @Test + void testProfileMethodChaining() { + options.profile("compact1") + .deprecation() + .parameters(); + + assertEquals(4, options.size()); + assertTrue(options.contains("-profile")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + } + + @Nested + class SourceOutputTests { + @Test + void testSourceOutputWithString() { + options.sourceOutput("generated/sources"); + + assertEquals(2, options.size()); + assertEquals("-s", options.get(0)); + assertEquals("generated/sources", options.get(1)); + } + + @Test + void testSourceOutputWithFile() { + var file = new File("generated/sources"); + options.sourceOutput(file); + + assertEquals(2, options.size()); + assertEquals("-s", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testSourceOutputWithPath() { + var path = Path.of("generated/sources"); + options.sourceOutput(path); + + assertEquals(2, options.size()); + assertEquals("-s", options.get(0)); + assertEquals(path.toFile().getAbsolutePath(), options.get(1)); + } + + @Test + void testSourceOutputReturnsThis() { + var result = options.sourceOutput("generated/sources"); + assertSame(options, result); + } + + @Test + void testSourceOutputMethodChaining() { + options.sourceOutput("generated/sources") + .processors("com.example.Processor") + .deprecation(); + + assertEquals(5, options.size()); + assertTrue(options.contains("-s")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-deprecation")); + } + } + + @Nested + class SystemTests { + @Test + void testSystemWithJdk() { + options.system("jdk"); + + assertEquals(2, options.size()); + assertEquals("--system", options.get(0)); + assertEquals("jdk", options.get(1)); + } + + @Test + void testSystemWithNone() { + options.system("none"); + + assertEquals(2, options.size()); + assertEquals("--system", options.get(0)); + assertEquals("none", options.get(1)); + } + + @Test + void testSystemReturnsThis() { + var result = options.system("none"); + assertSame(options, result); + } + + @Test + void testSystemMethodChaining() { + options.system("none") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--system")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + + @Test + void testMultipleSystemCalls() { + options.system("none") + .system("jdk"); + + assertEquals(4, options.size()); + assertEquals("--system", options.get(0)); + assertEquals("none", options.get(1)); + assertEquals("--system", options.get(2)); + assertEquals("jdk", options.get(3)); + } + } + + @Nested + class WarningErrorTests { + @Test + void testWarningError() { + options.warningError(); + + assertEquals(1, options.size()); + assertTrue(options.contains("-Werror")); + } + + @Test + void testWarningErrorReturnsThis() { + var result = options.warningError(); + assertSame(options, result); + } + + @Test + void testWarningErrorMethodChaining() { + options.warningError() + .deprecation() + .parameters(); + + assertEquals(3, options.size()); + assertTrue(options.contains("-Werror")); + assertTrue(options.contains("-deprecation")); + assertTrue(options.contains("-parameters")); + } + + @Test + void testWarningErrorWithXLint() { + options.xLint(UNCHECKED, DEPRECATION) + .warningError(); + + assertEquals(2, options.size()); + assertTrue(options.contains("-Xlint:unchecked,deprecation")); + assertTrue(options.contains("-Werror")); } } } From 3160161299c3b7158f5461973c5750c9fe35bc0f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Thu, 22 Jan 2026 00:19:36 -0800 Subject: [PATCH 4/7] Update copyright --- src/main/java/rife/bld/operations/JavacOptions.java | 2 +- src/test/java/rife/bld/operations/TestJavacOptions.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index b079daa..826024c 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com) + * Copyright 2001-2026 Geert Bevin (gbevin[remove] at uwyn dot com) * Licensed under the Apache License, Version 2.0 (the "License") */ package rife.bld.operations; diff --git a/src/test/java/rife/bld/operations/TestJavacOptions.java b/src/test/java/rife/bld/operations/TestJavacOptions.java index a5653e7..2408e11 100644 --- a/src/test/java/rife/bld/operations/TestJavacOptions.java +++ b/src/test/java/rife/bld/operations/TestJavacOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 Erik C. Thauvin (https://erik.thauvin.net/) + * Copyright 2025-2026 Erik C. Thauvin (https://erik.thauvin.net/) * Licensed under the Apache License, Version 2.0 (the "License") */ package rife.bld.operations; From 44144ce09599ee4c3d9b7362104467ed73b5fc52 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 25 Jan 2026 11:20:24 -0800 Subject: [PATCH 5/7] Add missing null/empty checks --- .../rife/bld/operations/JavacOptions.java | 130 ++++++++++++++---- 1 file changed, 104 insertions(+), 26 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index 826024c..2085a26 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -145,7 +145,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addExports(Collection modules) { - return addCommaSeparatedOption("--add-exports", modules); + if (isNotEmpty(modules)) { + return addCommaSeparatedOption("--add-exports", modules); + } + return this; } /** @@ -168,7 +171,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addReads(Collection modules) { - return addCommaSeparatedOption("--add-reads", modules); + if (isNotEmpty(modules)) { + return addCommaSeparatedOption("--add-reads", modules); + } + return this; } /** @@ -193,7 +199,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions addModules(Collection modules) { - return addCommaSeparatedOption("--add-modules", modules); + if (isNotEmpty(modules)) { + return addCommaSeparatedOption("--add-modules", modules); + } + return this; } /** @@ -263,7 +272,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions endorsedDirs(Collection dirs) { - return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(dirs)) { + return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -286,7 +298,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions endorsedDirsPaths(Collection dirs) { - return endorsedDirs(dirs.stream().map(Path::toFile).toList()); + if (isNotEmpty(dirs)) { + return endorsedDirs(dirs.stream().map(Path::toFile).toList()); + } + return this; } /** @@ -336,7 +351,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions extDirs(Collection dirs) { - return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(dirs)) { + return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -359,7 +377,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions extDirsPaths(Collection dirs) { - return extDirs(dirs.stream().map(Path::toFile).toList()); + if (isNotEmpty(dirs)) { + return extDirs(dirs.stream().map(Path::toFile).toList()); + } + return this; } /** @@ -526,7 +547,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions limitModules(Collection modules) { - return addCommaSeparatedOption("--limit-modules", modules); + if (isNotEmpty(modules)) { + return addCommaSeparatedOption("--limit-modules", modules); + } + return this; } /** @@ -549,7 +573,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions module(Collection modules) { - return addCommaSeparatedOption("--module", modules); + if (isNotEmpty(modules)) { + return addCommaSeparatedOption("--module", modules); + } + return this; } /** @@ -573,7 +600,10 @@ public class JavacOptions extends ArrayList { * @since 1.6.2 */ public JavacOptions modulePath(Collection paths) { - return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(paths)) { + return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -596,7 +626,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions modulePathPaths(Collection paths) { - return modulePathStrings(paths.stream().map(Path::toString).toList()); + if (isNotEmpty(paths)) { + return modulePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -619,7 +652,10 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions modulePathStrings(Collection paths) { - return addPathOption(COMPILE_OPTION_MODULE_PATH, paths); + if (isNotEmpty(paths)) { + return addPathOption(COMPILE_OPTION_MODULE_PATH, paths); + } + return this; } /** @@ -629,7 +665,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions moduleSourcePathStrings(Collection paths) { - return addPathOption("--module-source-path", paths); + if (isNotEmpty(paths)) { + return addPathOption("--module-source-path", paths); + } + return this; } /** @@ -639,7 +678,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions moduleSourcePathPaths(Collection paths) { - return moduleSourcePathStrings(paths.stream().map(Path::toString).toList()); + if (isNotEmpty(paths)) { + return moduleSourcePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -649,7 +691,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions moduleSourcePath(Collection paths) { - return moduleSourcePathStrings(paths.stream().map(File::getPath).toList()); + if (isNotEmpty(paths)) { + return moduleSourcePathStrings(paths.stream().map(File::getPath).toList()); + } + return this; } /** @@ -756,7 +801,10 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processors(Collection classnames) { - return addCommaSeparatedOption("-processor", classnames); + if (isNotEmpty(classnames)) { + return addCommaSeparatedOption("-processor", classnames); + } + return this; } /** @@ -805,7 +853,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorModulePathPaths(Collection paths) { - return processorModulePathStrings(paths.stream().map(Path::toString).toList()); + if (isNotEmpty(paths)) { + return processorModulePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -815,7 +866,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorModulePathStrings(Collection paths) { - return addPathOption("--processor-module-path", paths); + if (isNotEmpty(paths)) { + return addPathOption("--processor-module-path", paths); + } + return this; } /** @@ -825,7 +879,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorModulePath(Collection paths) { - return processorModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(paths)) { + return processorModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -874,7 +931,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorPathStrings(Collection paths) { - return addPathOption("--processor-path", paths); + if (isNotEmpty(paths)) { + return addPathOption("--processor-path", paths); + } + return this; } /** @@ -884,7 +944,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorPath(Collection paths) { - return processorPathStrings(paths.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(paths)) { + return processorPathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -894,7 +957,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorPathPaths(Collection paths) { - return processorPathStrings(paths.stream().map(Path::toString).toList()); + if (isNotEmpty(paths)) { + return processorPathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -1002,7 +1068,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions upgradeModulePathStrings(Collection paths) { - return addPathOption("--upgrade-module-path", paths); + if (isNotEmpty(paths)) { + return addPathOption("--upgrade-module-path", paths); + } + return this; } /** @@ -1012,7 +1081,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions upgradeModulePath(Collection paths) { - return upgradeModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + if (isNotEmpty(paths)) { + return upgradeModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -1022,7 +1094,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions upgradeModulePathPaths(Collection paths) { - return upgradeModulePathStrings(paths.stream().map(Path::toString).toList()); + if (isNotEmpty(paths)) { + return upgradeModulePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -1067,7 +1142,10 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions xLint(Collection keys) { - return addXLintOption(keys, ""); + if (isNotEmpty(keys)) { + return addXLintOption(keys, ""); + } + return this; } /** From 4de8d3c62960013f9fafad40279df50ffc7381ad Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 25 Jan 2026 11:27:14 -0800 Subject: [PATCH 6/7] Handle null values in path and comma-separated options via stream filters --- .../rife/bld/operations/JavacOptions.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index 2085a26..c04f828 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -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 { return collection != null && !collection.isEmpty(); } + /** + * Helper method to add delimited options + */ + private JavacOptions addDelimitedOption(String option, Collection 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 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 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 { * @since 2.1 */ public JavacOptions endorsedDirsStrings(Collection 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 { * @since 2.1 */ public JavacOptions extDirsStrings(Collection dirs) { - if (isNotEmpty(dirs)) { - add("-extdirs"); - add(String.join(",", dirs)); - } - return this; + return addCommaSeparatedOption("-extdirs", dirs); } /** From aa10006ce214ec5966d359f86fc1ba4d8d9e092f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 25 Jan 2026 18:28:39 -0800 Subject: [PATCH 7/7] Remove redundant null/empty checks --- .../rife/bld/operations/JavacOptions.java | 55 ++++--------------- 1 file changed, 11 insertions(+), 44 deletions(-) diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index c04f828..064d4fb 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -154,10 +154,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addExports(Collection modules) { - if (isNotEmpty(modules)) { - return addCommaSeparatedOption("--add-exports", modules); - } - return this; + return addCommaSeparatedOption("--add-exports", modules); } /** @@ -180,10 +177,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions addReads(Collection modules) { - if (isNotEmpty(modules)) { - return addCommaSeparatedOption("--add-reads", modules); - } - return this; + return addCommaSeparatedOption("--add-reads", modules); } /** @@ -208,10 +202,7 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions addModules(Collection modules) { - if (isNotEmpty(modules)) { - return addCommaSeparatedOption("--add-modules", modules); - } - return this; + return addCommaSeparatedOption("--add-modules", modules); } /** @@ -548,10 +539,7 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions limitModules(Collection modules) { - if (isNotEmpty(modules)) { - return addCommaSeparatedOption("--limit-modules", modules); - } - return this; + return addCommaSeparatedOption("--limit-modules", modules); } /** @@ -574,10 +562,7 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions module(Collection modules) { - if (isNotEmpty(modules)) { - return addCommaSeparatedOption("--module", modules); - } - return this; + return addCommaSeparatedOption("--module", modules); } /** @@ -653,10 +638,7 @@ public class JavacOptions extends ArrayList { * @since 2.1 */ public JavacOptions modulePathStrings(Collection paths) { - if (isNotEmpty(paths)) { - return addPathOption(COMPILE_OPTION_MODULE_PATH, paths); - } - return this; + return addPathOption(COMPILE_OPTION_MODULE_PATH, paths); } /** @@ -666,10 +648,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions moduleSourcePathStrings(Collection paths) { - if (isNotEmpty(paths)) { - return addPathOption("--module-source-path", paths); - } - return this; + return addPathOption("--module-source-path", paths); } /** @@ -802,10 +781,7 @@ public class JavacOptions extends ArrayList { * @since 1.5.18 */ public JavacOptions processors(Collection classnames) { - if (isNotEmpty(classnames)) { - return addCommaSeparatedOption("-processor", classnames); - } - return this; + return addCommaSeparatedOption("-processor", classnames); } /** @@ -867,10 +843,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorModulePathStrings(Collection paths) { - if (isNotEmpty(paths)) { - return addPathOption("--processor-module-path", paths); - } - return this; + return addPathOption("--processor-module-path", paths); } /** @@ -932,10 +905,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions processorPathStrings(Collection paths) { - if (isNotEmpty(paths)) { - return addPathOption("--processor-path", paths); - } - return this; + return addPathOption("--processor-path", paths); } /** @@ -1069,10 +1039,7 @@ public class JavacOptions extends ArrayList { * @since 2.3.1 */ public JavacOptions upgradeModulePathStrings(Collection paths) { - if (isNotEmpty(paths)) { - return addPathOption("--upgrade-module-path", paths); - } - return this; + return addPathOption("--upgrade-module-path", paths); } /**