Cleaned up API to match bld operations and options APIs
This commit is contained in:
parent
d28388bcd4
commit
f623921ff3
5 changed files with 146 additions and 21 deletions
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
|
@ -0,0 +1,5 @@
|
|||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Erik's Code Style" />
|
||||
</state>
|
||||
</component>
|
|
@ -1,7 +1,7 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.downloadLocation=
|
||||
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.3
|
||||
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.4-SNAPSHOT
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.sourceDirectories=
|
||||
bld.version=2.0.1
|
||||
|
|
|
@ -33,7 +33,7 @@ public class CheckstyleOperationBuild extends Project {
|
|||
public CheckstyleOperationBuild() {
|
||||
pkg = "rife.bld.extension";
|
||||
name = "CheckstyleOperation";
|
||||
version = version(1, 0, 3);
|
||||
version = version(1, 0, 4, "SNAPSHOT");
|
||||
|
||||
javaRelease = 17;
|
||||
downloadSources = true;
|
||||
|
|
|
@ -23,6 +23,7 @@ import rife.bld.operations.exceptions.ExitStatusException;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
@ -83,6 +84,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return configurationFile(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the location of the file that defines the configuration modules. The location can either be a
|
||||
* filesystem location, or a name passed to the {@link ClassLoader#getResource(String) ClassLoader.getResource() }
|
||||
* method. A configuration file is required.
|
||||
*
|
||||
* @param file the file
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation configurationFile(Path file) {
|
||||
return configurationFile(file.toFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all debug logging of CheckStyle utility.
|
||||
*
|
||||
|
@ -107,8 +120,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
* @see #sourceDir(Collection)
|
||||
*/
|
||||
public CheckstyleOperation exclude(String... path) {
|
||||
exclude_.addAll(Arrays.stream(path).map(File::new).toList());
|
||||
return this;
|
||||
return excludeStrings(List.of(path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -120,8 +132,19 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
* @see #sourceDir(Collection)
|
||||
*/
|
||||
public CheckstyleOperation exclude(File... path) {
|
||||
exclude_.addAll(List.of(path));
|
||||
return this;
|
||||
return exclude(List.of(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current
|
||||
* path. Multiple excludes are allowed.
|
||||
*
|
||||
* @param path one or more paths
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDir(Collection)
|
||||
*/
|
||||
public CheckstyleOperation exclude(Path... path) {
|
||||
return excludePaths(List.of(path));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,6 +160,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current
|
||||
* path. Multiple excludes are allowed.
|
||||
*
|
||||
* @param paths the paths
|
||||
* @return the checkstyle operation
|
||||
* @see #exclude(String...)
|
||||
*/
|
||||
public CheckstyleOperation excludePaths(Collection<Path> paths) {
|
||||
return exclude(paths.stream().map(Path::toFile).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
|
||||
*
|
||||
|
@ -161,6 +196,19 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current
|
||||
* path. Multiple excludes are allowed.
|
||||
*
|
||||
* @param paths the paths
|
||||
* @return the checkstyle operation
|
||||
* @see #exclude(String...)
|
||||
*/
|
||||
public CheckstyleOperation excludeStrings(Collection<String> paths) {
|
||||
exclude_.addAll(paths.stream().map(File::new).toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws IOException, InterruptedException, ExitStatusException {
|
||||
if (project_ == null) {
|
||||
|
@ -284,6 +332,13 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines if a string is not blank.
|
||||
*/
|
||||
private boolean isNotBlank(String s) {
|
||||
return s != null && !s.isBlank();
|
||||
}
|
||||
|
||||
/**
|
||||
* This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment
|
||||
* content excluding '/**' and '*/' at the beginning and at the end respectively. It can only be used on a
|
||||
|
@ -337,6 +392,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return outputPath(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file.
|
||||
* <p>
|
||||
* Defaults to stdout.
|
||||
*
|
||||
* @param file the output file
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation outputPath(Path file) {
|
||||
return outputPath(file.toFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property files to load.
|
||||
*
|
||||
|
@ -360,16 +427,25 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return propertiesFile(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the property files to load.
|
||||
*
|
||||
* @param file the file
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation propertiesFile(Path file) {
|
||||
return propertiesFile(file.toFile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Specified the file(s) or folder(s) containing the source files to check.
|
||||
*
|
||||
* @param dir one or more directories
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDir(Collection)
|
||||
* @see #sourceDirStrings(Collection)
|
||||
*/
|
||||
public CheckstyleOperation sourceDir(String... dir) {
|
||||
sourceDir_.addAll(Arrays.stream(dir).map(File::new).toList());
|
||||
return this;
|
||||
return sourceDirStrings(List.of(dir));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -380,8 +456,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
* @see #sourceDir(Collection)
|
||||
*/
|
||||
public CheckstyleOperation sourceDir(File... dir) {
|
||||
sourceDir_.addAll(List.of(dir));
|
||||
return this;
|
||||
return sourceDir(List.of(dir));
|
||||
}
|
||||
|
||||
/**
|
||||
* Specified the file(s) or folder(s) containing the source files to check.
|
||||
*
|
||||
* @param dir one or more directories
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDirPaths(Collection)
|
||||
*/
|
||||
public CheckstyleOperation sourceDir(Path... dir) {
|
||||
return sourceDirPaths(List.of(dir));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -389,7 +475,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
*
|
||||
* @param dirs the directories
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDir(String...)
|
||||
* @see #sourceDir(File...)
|
||||
*/
|
||||
public CheckstyleOperation sourceDir(Collection<File> dirs) {
|
||||
sourceDir_.addAll(dirs);
|
||||
|
@ -405,6 +491,29 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
return sourceDir_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specified the file(s) or folder(s) containing the source files to check.
|
||||
*
|
||||
* @param dirs the directories
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDir(Path...)
|
||||
*/
|
||||
public CheckstyleOperation sourceDirPaths(Collection<Path> dirs) {
|
||||
return sourceDir(dirs.stream().map(Path::toFile).toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Specified the file(s) or folder(s) containing the source files to check.
|
||||
*
|
||||
* @param dirs the directories
|
||||
* @return the checkstyle operation
|
||||
* @see #sourceDir(String...)
|
||||
*/
|
||||
public CheckstyleOperation sourceDirStrings(Collection<String> dirs) {
|
||||
sourceDir_.addAll(dirs.stream().map(File::new).toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints xpath suppressions at the file's line and column position. Argument is the line and column number
|
||||
* (separated by a {@code :} ) in the file that the suppression should be generated for. The option cannot be
|
||||
|
@ -485,11 +594,4 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determines if a string is not blank.
|
||||
*/
|
||||
private boolean isNotBlank(String s) {
|
||||
return s != null && !s.isBlank();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import rife.bld.operations.exceptions.ExitStatusException;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
|
@ -131,6 +132,10 @@ class CheckstyleOperationTest {
|
|||
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
|
||||
assertThat(op.executeConstructProcessCommandList()).as("list")
|
||||
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||
|
||||
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo.toPath(), bar.toPath());
|
||||
assertThat(op.executeConstructProcessCommandList()).as("list")
|
||||
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -150,8 +155,8 @@ class CheckstyleOperationTest {
|
|||
var op = new CheckstyleOperation()
|
||||
.fromProject(new WebProject())
|
||||
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
|
||||
.configurationFile("src/test/resources/google_checks.xml")
|
||||
.outputPath(tmpFile.getAbsolutePath());
|
||||
.configurationFile(Path.of("src/test/resources/google_checks.xml"))
|
||||
.outputPath(tmpFile.toPath());
|
||||
op.execute();
|
||||
assertThat(tmpFile).exists();
|
||||
}
|
||||
|
@ -236,6 +241,10 @@ class CheckstyleOperationTest {
|
|||
void propertiesFile() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
|
||||
assertThat(op.options().get("-p")).isEqualTo(FOO);
|
||||
|
||||
var fooPath = Path.of(FOO);
|
||||
op = op.propertiesFile(fooPath);
|
||||
assertThat(op.options().get("-p")).isEqualTo(fooPath.toFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -249,12 +258,21 @@ class CheckstyleOperationTest {
|
|||
op = op.sourceDir(foo, bar);
|
||||
assertThat(op.sourceDir()).as("foo, bar").hasSize(2)
|
||||
.contains(foo).contains(bar);
|
||||
op.sourceDir().clear();
|
||||
|
||||
op = op.sourceDir(List.of(foo, bar));
|
||||
assertThat(op.sourceDir()).as("List.of(foo, bar)").hasSize(2)
|
||||
.contains(foo).contains(bar);
|
||||
op.sourceDir().clear();
|
||||
|
||||
op = op.sourceDir(foo.toPath(), bar.toPath());
|
||||
assertThat(op.sourceDir()).as("foo.toPath(), bar.toPath()").hasSize(2)
|
||||
.contains(foo).contains(bar);
|
||||
op.sourceDir().clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void suppressionLineColumnNumber() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).suppressionLineColumnNumber(FOO + ':' + BAR);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue