diff --git a/src/main/java/rife/bld/operations/JavacOptions.java b/src/main/java/rife/bld/operations/JavacOptions.java index b41f693..064d4fb 100644 --- a/src/main/java/rife/bld/operations/JavacOptions.java +++ b/src/main/java/rife/bld/operations/JavacOptions.java @@ -1,18 +1,17 @@ /* - * 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; 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.List; +import java.util.Collection; +import java.util.Objects; import java.util.stream.Collectors; import static rife.bld.operations.CompileOperation.COMPILE_OPTION_MODULE_PATH; @@ -23,6 +22,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 @@ -79,6 +79,46 @@ 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 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) { + return addDelimitedOption(option, paths, File.pathSeparator); + } + + /** + * Helper method to add comma-separated options + */ + private JavacOptions addCommaSeparatedOption(String option, Collection values) { + return addDelimitedOption(option, values, ","); + } + /** * Option to pass to annotation processors * @@ -99,7 +139,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; } /** @@ -110,10 +153,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); } /** @@ -123,7 +164,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; } /** @@ -132,10 +176,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); } /** @@ -146,7 +188,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; } /** @@ -156,10 +201,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); } /** @@ -216,7 +259,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; } /** @@ -225,8 +271,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions endorsedDirs(List dirs) { - return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + public JavacOptions endorsedDirs(Collection dirs) { + if (isNotEmpty(dirs)) { + return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -236,7 +285,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; } /** @@ -245,8 +297,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions endorsedDirsPaths(List dirs) { - return endorsedDirs(dirs.stream().map(Path::toFile).toList()); + public JavacOptions endorsedDirsPaths(Collection dirs) { + if (isNotEmpty(dirs)) { + return endorsedDirs(dirs.stream().map(Path::toFile).toList()); + } + return this; } /** @@ -256,7 +311,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; } /** @@ -265,10 +323,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions endorsedDirsStrings(List dirs) { - add("-endorseddirs"); - add(String.join(",", dirs)); - return this; + public JavacOptions endorsedDirsStrings(Collection dirs) { + return addCommaSeparatedOption("-endorseddirs", dirs); } /** @@ -278,7 +334,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; } /** @@ -287,8 +346,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions extDirs(List dirs) { - return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + public JavacOptions extDirs(Collection dirs) { + if (isNotEmpty(dirs)) { + return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -298,7 +360,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; } /** @@ -307,8 +372,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions extDirsPaths(List dirs) { - return extDirs(dirs.stream().map(Path::toFile).toList()); + public JavacOptions extDirsPaths(Collection dirs) { + if (isNotEmpty(dirs)) { + return extDirs(dirs.stream().map(Path::toFile).toList()); + } + return this; } /** @@ -318,7 +386,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; } /** @@ -327,10 +398,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions extDirsStrings(List dirs) { - add("-extdirs"); - add(String.join(",", dirs)); - return this; + public JavacOptions extDirsStrings(Collection dirs) { + return addCommaSeparatedOption("-extdirs", dirs); } /** @@ -457,7 +526,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; } /** @@ -466,10 +538,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); } /** @@ -479,7 +549,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; } /** @@ -488,20 +561,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; } /** @@ -510,8 +585,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.6.2 */ - public JavacOptions modulePath(List paths) { - return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + public JavacOptions modulePath(Collection paths) { + if (isNotEmpty(paths)) { + return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; } /** @@ -521,7 +599,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; } /** @@ -530,8 +611,11 @@ 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) { + if (isNotEmpty(paths)) { + return modulePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; } /** @@ -541,7 +625,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; } /** @@ -550,9 +637,43 @@ 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)); + 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) { + if (isNotEmpty(paths)) { + return moduleSourcePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; + } + + /** + * Specify where to find input source files for multiple modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions moduleSourcePath(Collection paths) { + if (isNotEmpty(paths)) { + return moduleSourcePathStrings(paths.stream().map(File::getPath).toList()); + } return this; } @@ -562,8 +683,11 @@ 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) { + if (isNotEmpty(paths)) { + moduleSourcePath(Arrays.asList(paths)); + } + return this; } /** @@ -572,8 +696,11 @@ 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(String... paths) { + if (isNotEmpty(paths)) { + moduleSourcePathStrings(Arrays.asList(paths)); + } + return this; } /** @@ -582,9 +709,10 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions moduleSourcePath(String path) { - add("--module-source-path"); - add(path); + public JavacOptions moduleSourcePath(Path... paths) { + if (isNotEmpty(paths)) { + moduleSourcePathPaths(Arrays.asList(paths)); + } return this; } @@ -640,7 +768,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; } /** @@ -649,10 +780,8 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions processors(List classnames) { - add("-processor"); - add(StringUtils.join(classnames, ",")); - return this; + public JavacOptions processors(Collection classnames) { + return addCommaSeparatedOption("-processor", classnames); } /** @@ -661,8 +790,11 @@ 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) { + if (isNotEmpty(paths)) { + processorModulePath(Arrays.asList(paths)); + } + return this; } /** @@ -671,8 +803,11 @@ 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) { + if (isNotEmpty(paths)) { + processorModulePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -681,9 +816,46 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions processorModulePath(String path) { - add("--processor-module-path"); - add(path); + public JavacOptions processorModulePath(String... paths) { + if (isNotEmpty(paths)) { + processorModulePathStrings(Arrays.asList(paths)); + } + return this; + } + + /** + * Specify a module path where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorModulePathPaths(Collection paths) { + if (isNotEmpty(paths)) { + return processorModulePathStrings(paths.stream().map(Path::toString).toList()); + } + return this; + } + + /** + * 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) { + if (isNotEmpty(paths)) { + return processorModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } return this; } @@ -693,34 +865,77 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 1.5.18 */ - public JavacOptions processorPath(File path) { - return processorPath(path.getAbsolutePath()); - } - - /** - * Specify where to find annotation processors - * - * @return this list of options - * @since 2.1 - */ - public JavacOptions processorPath(Path path) { - return processorPath(path.toFile()); - } - - /** - * Specify where to find annotation processors - * - * @return this list of options - * @since 2.1 - */ - public JavacOptions processorPath(String path) { - add("--processor-path"); - add(path); + public JavacOptions processorPath(String... paths) { + if (isNotEmpty(paths)) { + processorPathStrings(Arrays.asList(paths)); + } return this; } /** - * Check that API used is available in the specified profile + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.1 + */ + public JavacOptions processorPath(File... paths) { + if (isNotEmpty(paths)) { + processorPath(Arrays.asList(paths)); + } + return this; + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.1 + */ + public JavacOptions processorPath(Path... paths) { + if (isNotEmpty(paths)) { + processorPathPaths(Arrays.asList(paths)); + } + return this; + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPathStrings(Collection paths) { + return addPathOption("--processor-path", paths); + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPath(Collection paths) { + if (isNotEmpty(paths)) { + return processorPathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; + } + + /** + * Specify where to find annotation processors + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions processorPathPaths(Collection paths) { + if (isNotEmpty(paths)) { + return processorPathStrings(paths.stream().map(Path::toString).toList()); + } + return this; + } + + /** + * Check that the API used is available in the specified profile * * @return this list of options * @since 1.5.18 @@ -784,8 +999,11 @@ 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) { + if (isNotEmpty(paths)) { + upgradeModulePath(Arrays.asList(paths)); + } + return this; } /** @@ -794,8 +1012,11 @@ 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) { + if (isNotEmpty(paths)) { + upgradeModulePathPaths(Arrays.asList(paths)); + } + return this; } /** @@ -804,9 +1025,46 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.1 */ - public JavacOptions upgradeModulePath(String path) { - add("--upgrade-module-path"); - add(path); + public JavacOptions upgradeModulePath(String... paths) { + if (isNotEmpty(paths)) { + upgradeModulePathStrings(Arrays.asList(paths)); + } + return this; + } + + /** + * Override location of upgradeable modules + * + * @return this list of options + * @since 2.3.1 + */ + 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) { + if (isNotEmpty(paths)) { + return upgradeModulePathStrings(paths.stream().map(File::getAbsolutePath).toList()); + } + return this; + } + + /** + * Override location of upgradeable modules + * + * @return this list of options + * @since 2.3.1 + */ + public JavacOptions upgradeModulePathPaths(Collection paths) { + if (isNotEmpty(paths)) { + return upgradeModulePathStrings(paths.stream().map(Path::toString).toList()); + } return this; } @@ -839,7 +1097,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; } /** @@ -848,8 +1109,11 @@ public class JavacOptions extends ArrayList { * @return this list of options * @since 2.3.1 */ - public JavacOptions xLint(List keys) { - return addXLintOption(keys, ""); + public JavacOptions xLint(Collection keys) { + if (isNotEmpty(keys)) { + return addXLintOption(keys, ""); + } + return this; } /** @@ -859,30 +1123,33 @@ 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; } + /** * Warning categories to disable * * @return this list of options * @since 2.3.1 */ - public JavacOptions xLintDisable(List keys) { - return addXLintOption(keys, "-"); - } - - - private JavacOptions addXLintOption(List keys, String prefix) { - if (keys == null || keys.isEmpty()) { - return this; + public JavacOptions xLintDisable(Collection keys) { + if (isNotEmpty(keys)) { + return addXLintOption(keys, "-"); } - - var formattedKeys = keys.stream() - .map(key -> prefix + key.name().replace('_', '-').toLowerCase()) - .collect(Collectors.joining(",", "-Xlint:", "")); - - add(formattedKeys); 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); + } + 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..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; @@ -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; @@ -73,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 @@ -155,23 +153,19 @@ 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 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 +954,1845 @@ class TestJavacOptions { assertEquals(1, options.size()); } } + + @Nested + class ModuleSourcePathTests { + @Test + void testModuleSourcePathWithFile() { + var file = new File("src/modules"); + options.moduleSourcePath(file); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals(file.getPath(), options.get(1)); + } + + @Test + void testModuleSourcePathWithMultipleFiles() { + var file1 = new File("src/module1"); + var file2 = new File("src/module2"); + options.moduleSourcePath(file1, file2); + + assertEquals(2, options.size()); + assertEquals("--module-source-path", options.get(0)); + 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 + void testModuleSourcePathReturnsThis() { + var result = options.moduleSourcePath("src/modules"); + assertSame(options, result); + } + + @Test + void testModuleSourcePathMethodChaining() { + options.moduleSourcePath("src/modules") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--module-source-path")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + + @Test + void testMultipleModuleSourcePathCalls() { + options.moduleSourcePath("src/mod1") + .moduleSourcePath("src/mod2"); + + assertEquals(4, options.size()); + assertEquals("--module-source-path", options.get(0)); + assertEquals("src/mod1", options.get(1)); + assertEquals("--module-source-path", options.get(2)); + assertEquals("src/mod2", options.get(3)); + } + } + + @Nested + class ProcessorModulePathTests { + @Test + void testProcessorModulePathWithFile() { + var file = new File("lib/processor-modules"); + options.processorModulePath(file); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testProcessorModulePathWithMultipleFiles() { + var file1 = new File("lib/proc1"); + var file2 = new File("lib/proc2"); + options.processorModulePath(file1, file2); + + assertEquals(2, options.size()); + assertEquals("--processor-module-path", options.get(0)); + 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 + void testProcessorModulePathReturnsThis() { + var result = options.processorModulePath("lib/processors"); + assertSame(options, result); + } + + @Test + void testProcessorModulePathMethodChaining() { + options.processorModulePath("lib/proc-modules") + .processors("com.example.Processor") + .deprecation(); + + assertEquals(5, options.size()); + assertTrue(options.contains("--processor-module-path")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-deprecation")); + } + + @Test + void testMultipleProcessorModulePathCalls() { + options.processorModulePath("lib/proc1") + .processorModulePath("lib/proc2"); + + assertEquals(4, options.size()); + assertEquals("--processor-module-path", options.get(0)); + assertEquals("lib/proc1", options.get(1)); + assertEquals("--processor-module-path", options.get(2)); + assertEquals("lib/proc2", options.get(3)); + } + } + + @Nested + class ProcessorPathTests { + @Test + void testProcessorPathWithString() { + options.processorPath("lib/processors.jar"); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("lib/processors.jar", options.get(1)); + } + + @Test + void testProcessorPathWithMultipleStrings() { + options.processorPath("lib/proc1.jar", "lib/proc2.jar", "lib/proc3.jar"); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + 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 + void testProcessorPathReturnsThis() { + var result = options.processorPath("lib/processors.jar"); + assertSame(options, result); + } + + @Test + void testProcessorPathMethodChaining() { + options.processorPath("lib/processors.jar") + .processors("com.example.Processor") + .process(JavacOptions.Processing.ONLY); + + assertEquals(5, options.size()); + assertTrue(options.contains("--processor-path")); + assertTrue(options.contains("-processor")); + assertTrue(options.contains("-proc:only")); + } + + @Test + void testMultipleProcessorPathCalls() { + options.processorPath("lib/proc1.jar") + .processorPath("lib/proc2.jar"); + + assertEquals(4, options.size()); + assertEquals("--processor-path", options.get(0)); + assertEquals("lib/proc1.jar", options.get(1)); + assertEquals("--processor-path", options.get(2)); + assertEquals("lib/proc2.jar", options.get(3)); + } + + @Test + void testProcessorPathWithDirectoryAndJar() { + options.processorPath("lib/processors", "lib/extra-processors.jar"); + + assertEquals(2, options.size()); + assertEquals("--processor-path", options.get(0)); + var paths = options.get(1).split(File.pathSeparator); + assertEquals(2, paths.length); + } + } + + @Nested + class UpgradeModulePathTests { + @Test + void testUpgradeModulePathWithFile() { + var file = new File("lib/upgrades"); + options.upgradeModulePath(file); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals(file.getAbsolutePath(), options.get(1)); + } + + @Test + void testUpgradeModulePathWithMultipleFiles() { + var file1 = new File("lib/upgrade1"); + var file2 = new File("lib/upgrade2"); + options.upgradeModulePath(file1, file2); + + assertEquals(2, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + 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 + void testUpgradeModulePathReturnsThis() { + var result = options.upgradeModulePath("lib/upgrades"); + assertSame(options, result); + } + + @Test + void testUpgradeModulePathMethodChaining() { + options.upgradeModulePath("lib/upgrades") + .modulePath("lib/modules") + .release(17); + + assertEquals(6, options.size()); + assertTrue(options.contains("--upgrade-module-path")); + assertTrue(options.contains("--module-path")); + assertTrue(options.containsRelease()); + } + + @Test + void testMultipleUpgradeModulePathCalls() { + options.upgradeModulePath("lib/upgrade1") + .upgradeModulePath("lib/upgrade2"); + + assertEquals(4, options.size()); + assertEquals("--upgrade-module-path", options.get(0)); + assertEquals("lib/upgrade1", options.get(1)); + assertEquals("--upgrade-module-path", options.get(2)); + assertEquals("lib/upgrade2", options.get(3)); + } + + @Test + void testUpgradeModulePathWithSystem() { + options.upgradeModulePath("lib/upgrades") + .system("none") + .addModules("java.sql"); + + 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 testAnnotationOptionMultipleCalls() { + options.annotationOption("debug", "true") + .annotationOption("verbose", "false"); + + assertEquals(2, options.size()); + assertEquals("-Adebug=true", options.get(0)); + assertEquals("-Averbose=false", options.get(1)); + } + + @Test + void testAnnotationOptionReturnsThis() { + var result = options.annotationOption("key", "value"); + assertSame(options, result); + } + + @Test + void testAnnotationOptionWithComplexValue() { + options.annotationOption("outputDir", "/path/to/output"); + + assertEquals(1, options.size()); + assertEquals("-AoutputDir=/path/to/output", options.get(0)); + } + + @Test + 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("--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")); + } + } }