From 21ed5912f04df6cc6677fc7e7890a668f80e9e39 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 21 Jan 2026 11:37:20 -0800 Subject: [PATCH] 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")); + } + } }