From cbcbe40ead944b3e5e6f1e0260b5f283ef11af84 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Wed, 28 Aug 2024 17:42:46 -0700 Subject: [PATCH] Added File argument alternatives with Path and String. --- .../rife/bld/extension/Antlr4Operation.java | 162 +++++++++++++++++- 1 file changed, 154 insertions(+), 8 deletions(-) diff --git a/src/main/java/rife/bld/extension/Antlr4Operation.java b/src/main/java/rife/bld/extension/Antlr4Operation.java index b9119e3..8c786ad 100644 --- a/src/main/java/rife/bld/extension/Antlr4Operation.java +++ b/src/main/java/rife/bld/extension/Antlr4Operation.java @@ -9,7 +9,9 @@ import rife.bld.operations.AbstractOperation; import rife.bld.operations.exceptions.ExitStatusException; import java.io.File; -import java.util.*; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; /** * Generates Java sources from ANTLR grammars. @@ -115,7 +117,7 @@ public class Antlr4Operation extends AbstractOperation { * @since 1.0 */ public Antlr4Operation arguments(String... arguments) { - arguments_.addAll(Arrays.asList(arguments)); + arguments_.addAll(List.of(arguments)); return this; } @@ -138,10 +140,11 @@ public class Antlr4Operation extends AbstractOperation { * * @param directories the source directories * @return this operation instance + * @see #sourceDirectories(List) * @since 1.0 */ public Antlr4Operation sourceDirectories(File... directories) { - return sourceDirectories(Arrays.asList(directories)); + return sourceDirectories(List.of(directories)); } /** @@ -149,6 +152,31 @@ public class Antlr4Operation extends AbstractOperation { * * @param directories the source directories * @return this operation instance + * @see #sourceDirectoriesPaths(List) + * @since 1.4 + */ + public Antlr4Operation sourceDirectories(Path... directories) { + return sourceDirectoriesPaths(List.of(directories)); + } + + /** + * Provides the source directories that will be used for the antlr operation. + * + * @param directories the source directories + * @return this operation instance + * @see #sourceDirectoriesStrings(List) + * @since 1.4 + */ + public Antlr4Operation sourceDirectories(String... directories) { + return sourceDirectoriesStrings(List.of(directories)); + } + + /** + * Provides the source directories that will be used for the antlr operation. + * + * @param directories the source directories + * @return this operation instance + * @see #sourceDirectories(File...) * @since 1.0 */ public Antlr4Operation sourceDirectories(List directories) { @@ -157,14 +185,27 @@ public class Antlr4Operation extends AbstractOperation { } /** - * Provides the source files that will be used for the antlr operation. + * Provides the source directories that will be used for the antlr operation. * - * @param files the source files + * @param directories the source directories * @return this operation instance + * @see #sourceDirectories(Path...) * @since 1.0 */ - public Antlr4Operation sourceFiles(File... files) { - return sourceFiles(Arrays.asList(files)); + public Antlr4Operation sourceDirectoriesPaths(List directories) { + return sourceDirectories(directories.stream().map(Path::toFile).toList()); + } + + /** + * Provides the source directories that will be used for the antlr operation. + * + * @param directories the source directories + * @return this operation instance + * @see #sourceDirectories(File...) + * @since 1.0 + */ + public Antlr4Operation sourceDirectoriesStrings(List directories) { + return sourceDirectories(directories.stream().map(File::new).toList()); } /** @@ -172,6 +213,43 @@ public class Antlr4Operation extends AbstractOperation { * * @param files the source files * @return this operation instance + * @see #sourceFiles(List) + * @since 1.0 + */ + public Antlr4Operation sourceFiles(File... files) { + return sourceFiles(List.of(files)); + } + + /** + * Provides the source files that will be used for the antlr operation. + * + * @param files the source files + * @return this operation instance + * @see #sourceFilesPaths(List) + * @since 1.4 + */ + public Antlr4Operation sourceFiles(Path... files) { + return sourceFilesPaths(List.of(files)); + } + + /** + * Provides the source files that will be used for the antlr operation. + * + * @param files the source files + * @return this operation instance + * @see #sourceFilesStrings(List) + * @since 1.4 + */ + public Antlr4Operation sourceFiles(String... files) { + return sourceFilesStrings(List.of(files)); + } + + /** + * Provides the source files that will be used for the antlr operation. + * + * @param files the source files + * @return this operation instance + * @see #sourceFiles(File...) * @since 1.0 */ public Antlr4Operation sourceFiles(List files) { @@ -179,6 +257,30 @@ public class Antlr4Operation extends AbstractOperation { return this; } + /** + * Provides the source files that will be used for the antlr operation. + * + * @param files the source files + * @return this operation instance + * @see #sourceFiles(Path...) + * @since 1.4 + */ + public Antlr4Operation sourceFilesPaths(List files) { + return sourceFiles(files.stream().map(Path::toFile).toList()); + } + + /** + * Provides the source files that will be used for the antlr operation. + * + * @param files the source files + * @return this operation instance + * @see #sourceFiles(String...) + * @since 1.4 + */ + public Antlr4Operation sourceFilesStrings(List files) { + return sourceFiles(files.stream().map(File::new).toList()); + } + /** * Provides the output directory where all output is generated. * @@ -191,6 +293,28 @@ public class Antlr4Operation extends AbstractOperation { return this; } + /** + * Provides the output directory where all output is generated. + * + * @param directory the output directory + * @return this operation instance + * @since 1.4 + */ + public Antlr4Operation outputDirectory(Path directory) { + return outputDirectory(directory.toFile()); + } + + /** + * Provides the output directory where all output is generated. + * + * @param directory the output directory + * @return this operation instance + * @since 1.4 + */ + public Antlr4Operation outputDirectory(String directory) { + return outputDirectory(new File(directory)); + } + /** * Provides the location of grammars and tokens files. * @@ -203,6 +327,28 @@ public class Antlr4Operation extends AbstractOperation { return this; } + /** + * Provides the location of grammars and tokens files. + * + * @param directory the lib directory + * @return this operation instance + * @since 1.4 + */ + public Antlr4Operation libDirectory(Path directory) { + return libDirectory(directory.toFile()); + } + + /** + * Provides the location of grammars and tokens files. + * + * @param directory the lib directory + * @return this operation instance + * @since 1.4 + */ + public Antlr4Operation libDirectory(String directory) { + return libDirectory(new File(directory)); + } + /** * Provides grammar file encoding; e.g., euc-jp. * @@ -365,4 +511,4 @@ public class Antlr4Operation extends AbstractOperation { public File libDirectory() { return libDirectory_; } -} \ No newline at end of file +}