Cleaned up API to match bld operations and options APIs

This commit is contained in:
Erik C. Thauvin 2024-08-27 01:39:34 -07:00
parent d28388bcd4
commit f623921ff3
Signed by: erik
GPG key ID: 776702A6A2DA330E
5 changed files with 146 additions and 21 deletions

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Erik's Code Style" />
</state>
</component>

View file

@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.downloadLocation= 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.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories= bld.sourceDirectories=
bld.version=2.0.1 bld.version=2.0.1

View file

@ -33,7 +33,7 @@ public class CheckstyleOperationBuild extends Project {
public CheckstyleOperationBuild() { public CheckstyleOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "CheckstyleOperation"; name = "CheckstyleOperation";
version = version(1, 0, 3); version = version(1, 0, 4, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
downloadSources = true; downloadSources = true;

View file

@ -23,6 +23,7 @@ import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level; import java.util.logging.Level;
@ -83,6 +84,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return configurationFile(file.getAbsolutePath()); 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. * Prints all debug logging of CheckStyle utility.
* *
@ -107,8 +120,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #sourceDir(Collection) * @see #sourceDir(Collection)
*/ */
public CheckstyleOperation exclude(String... path) { public CheckstyleOperation exclude(String... path) {
exclude_.addAll(Arrays.stream(path).map(File::new).toList()); return excludeStrings(List.of(path));
return this;
} }
/** /**
@ -120,8 +132,19 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #sourceDir(Collection) * @see #sourceDir(Collection)
*/ */
public CheckstyleOperation exclude(File... path) { public CheckstyleOperation exclude(File... path) {
exclude_.addAll(List.of(path)); return exclude(List.of(path));
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 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; 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. * Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
* *
@ -161,6 +196,19 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return this; 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 @Override
public void execute() throws IOException, InterruptedException, ExitStatusException { public void execute() throws IOException, InterruptedException, ExitStatusException {
if (project_ == null) { if (project_ == null) {
@ -284,6 +332,13 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return this; 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 * This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment
* content excluding '&#47;**' and '*&#47;' at the beginning and at the end respectively. It can only be used on a * content excluding '&#47;**' and '*&#47;' 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()); 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. * Sets the property files to load.
* *
@ -360,16 +427,25 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return propertiesFile(file.getAbsolutePath()); 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. * Specified the file(s) or folder(s) containing the source files to check.
* *
* @param dir one or more directories * @param dir one or more directories
* @return the checkstyle operation * @return the checkstyle operation
* @see #sourceDir(Collection) * @see #sourceDirStrings(Collection)
*/ */
public CheckstyleOperation sourceDir(String... dir) { public CheckstyleOperation sourceDir(String... dir) {
sourceDir_.addAll(Arrays.stream(dir).map(File::new).toList()); return sourceDirStrings(List.of(dir));
return this;
} }
/** /**
@ -380,8 +456,18 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @see #sourceDir(Collection) * @see #sourceDir(Collection)
*/ */
public CheckstyleOperation sourceDir(File... dir) { public CheckstyleOperation sourceDir(File... dir) {
sourceDir_.addAll(List.of(dir)); return sourceDir(List.of(dir));
return this; }
/**
* 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 * @param dirs the directories
* @return the checkstyle operation * @return the checkstyle operation
* @see #sourceDir(String...) * @see #sourceDir(File...)
*/ */
public CheckstyleOperation sourceDir(Collection<File> dirs) { public CheckstyleOperation sourceDir(Collection<File> dirs) {
sourceDir_.addAll(dirs); sourceDir_.addAll(dirs);
@ -405,6 +491,29 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return sourceDir_; 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 * 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 * (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; return this;
} }
/*
* Determines if a string is not blank.
*/
private boolean isNotBlank(String s) {
return s != null && !s.isBlank();
}
} }

View file

@ -27,6 +27,7 @@ import rife.bld.operations.exceptions.ExitStatusException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
@ -131,6 +132,10 @@ class CheckstyleOperationTest {
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar)); op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
assertThat(op.executeConstructProcessCommandList()).as("list") assertThat(op.executeConstructProcessCommandList()).as("list")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath()); .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 @Test
@ -150,8 +155,8 @@ class CheckstyleOperationTest {
var op = new CheckstyleOperation() var op = new CheckstyleOperation()
.fromProject(new WebProject()) .fromProject(new WebProject())
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA) .sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
.configurationFile("src/test/resources/google_checks.xml") .configurationFile(Path.of("src/test/resources/google_checks.xml"))
.outputPath(tmpFile.getAbsolutePath()); .outputPath(tmpFile.toPath());
op.execute(); op.execute();
assertThat(tmpFile).exists(); assertThat(tmpFile).exists();
} }
@ -236,6 +241,10 @@ class CheckstyleOperationTest {
void propertiesFile() { void propertiesFile() {
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO); var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
assertThat(op.options().get("-p")).isEqualTo(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 @Test
@ -249,12 +258,21 @@ class CheckstyleOperationTest {
op = op.sourceDir(foo, bar); op = op.sourceDir(foo, bar);
assertThat(op.sourceDir()).as("foo, bar").hasSize(2) assertThat(op.sourceDir()).as("foo, bar").hasSize(2)
.contains(foo).contains(bar); .contains(foo).contains(bar);
op.sourceDir().clear();
op = op.sourceDir(List.of(foo, bar)); op = op.sourceDir(List.of(foo, bar));
assertThat(op.sourceDir()).as("List.of(foo, bar)").hasSize(2) assertThat(op.sourceDir()).as("List.of(foo, bar)").hasSize(2)
.contains(foo).contains(bar); .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 @Test
void suppressionLineColumnNumber() { void suppressionLineColumnNumber() {
var op = new CheckstyleOperation().fromProject(new Project()).suppressionLineColumnNumber(FOO + ':' + BAR); var op = new CheckstyleOperation().fromProject(new Project()).suppressionLineColumnNumber(FOO + ':' + BAR);