Skip to content

Commit

Permalink
Merge pull request #2 from ethauvin/main
Browse files Browse the repository at this point in the history
Added File argument alternatives with Path and String.
  • Loading branch information
gbevin authored Aug 29, 2024
2 parents 2bc3319 + f37a626 commit ad69a06
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bld/java/rife/bld/extension/Antlr4Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public Antlr4Build() {
.include(dependency("com.uwyn.rife2", "bld", version(2,0,1)))
.include(dependency("org.antlr", "antlr4", version(4,11,1)));
scope(test)
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,10,3)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,10,3)));
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5,11,0)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1,11,0)));

javadocOperation()
.javadocOptions()
Expand Down
156 changes: 151 additions & 5 deletions src/main/java/rife/bld/extension/Antlr4Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
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.
Expand Down Expand Up @@ -115,7 +117,7 @@ public void execute()
* @since 1.0
*/
public Antlr4Operation arguments(String... arguments) {
arguments_.addAll(Arrays.asList(arguments));
arguments_.addAll(List.of(arguments));
return this;
}

Expand All @@ -138,47 +140,147 @@ public Antlr4Operation arguments(List<String> arguments) {
*
* @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));
}

/**
* Provides the source directories that will be used for the antlr operation.
*
* @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<File> directories) {
sourceDirectories_.addAll(directories);
return this;
}

/**
* Provides the source directories that will be used for the antlr operation.
*
* @param directories the source directories
* @return this operation instance
* @see #sourceDirectories(Path...)
* @since 1.0
*/
public Antlr4Operation sourceDirectoriesPaths(List<Path> 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<String> directories) {
return sourceDirectories(directories.stream().map(File::new).toList());
}

/**
* Provides the source files that will be used for the antlr operation.
*
* @param files the source files
* @return this operation instance
* @see #sourceFiles(List)
* @since 1.0
*/
public Antlr4Operation sourceFiles(File... files) {
return sourceFiles(Arrays.asList(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<File> files) {
sourceFiles_.addAll(files);
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<Path> 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<String> files) {
return sourceFiles(files.stream().map(File::new).toList());
}

/**
* Provides the output directory where all output is generated.
*
Expand All @@ -191,6 +293,28 @@ public Antlr4Operation outputDirectory(File directory) {
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.
*
Expand All @@ -203,6 +327,28 @@ public Antlr4Operation libDirectory(File directory) {
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.
*
Expand Down Expand Up @@ -365,4 +511,4 @@ public File outputDirectory() {
public File libDirectory() {
return libDirectory_;
}
}
}

0 comments on commit ad69a06

Please sign in to comment.