Switched from Lists to Collections
This commit is contained in:
parent
00f40e887f
commit
826a967815
14 changed files with 280 additions and 163 deletions
7
.github/workflows/bld.yml
vendored
7
.github/workflows/bld.yml
vendored
|
@ -22,11 +22,8 @@ jobs:
|
||||||
distribution: "zulu"
|
distribution: "zulu"
|
||||||
java-version: ${{ matrix.java-version }}
|
java-version: ${{ matrix.java-version }}
|
||||||
|
|
||||||
- name: Grant execute permission for bld
|
- name: Download dependencies
|
||||||
run: chmod +x bld
|
|
||||||
|
|
||||||
- name: Download the dependencies
|
|
||||||
run: ./bld download
|
run: ./bld download
|
||||||
|
|
||||||
- name: Run tests with bld
|
- name: Run tests
|
||||||
run: ./bld compile test
|
run: ./bld compile test
|
||||||
|
|
4
.idea/libraries/bld.xml
generated
4
.idea/libraries/bld.xml
generated
|
@ -2,12 +2,12 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -9,7 +9,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.bld/dist/bld-1.9.1.jar",
|
"${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar",
|
||||||
"lib/**/*.jar"
|
"lib/**/*.jar"
|
||||||
],
|
],
|
||||||
"java.compile.nullAnalysis.mode": "automatic"
|
"java.compile.nullAnalysis.mode": "automatic"
|
||||||
|
|
4
examples/.idea/libraries/bld.xml
generated
4
examples/.idea/libraries/bld.xml
generated
|
@ -2,12 +2,12 @@
|
||||||
<library name="bld">
|
<library name="bld">
|
||||||
<CLASSES>
|
<CLASSES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT.jar!/" />
|
||||||
</CLASSES>
|
</CLASSES>
|
||||||
<JAVADOC />
|
<JAVADOC />
|
||||||
<SOURCES>
|
<SOURCES>
|
||||||
<root url="file://$PROJECT_DIR$/lib/bld" />
|
<root url="file://$PROJECT_DIR$/lib/bld" />
|
||||||
<root url="jar://$USER_HOME$/.bld/dist/bld-1.9.1-sources.jar!/" />
|
<root url="jar://$USER_HOME$/.bld/dist/bld-2.0.0-SNAPSHOT-sources.jar!/" />
|
||||||
</SOURCES>
|
</SOURCES>
|
||||||
<excluded>
|
<excluded>
|
||||||
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
|
||||||
|
|
4
examples/.idea/misc.xml
generated
4
examples/.idea/misc.xml
generated
|
@ -1,4 +1,8 @@
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<pattern value="com.example.ExamplesBuild" method="checkstyle" />
|
||||||
|
<pattern value="com.example.ExamplesBuild" />
|
||||||
|
</component>
|
||||||
<component name="PDMPlugin">
|
<component name="PDMPlugin">
|
||||||
<option name="customRuleSets">
|
<option name="customRuleSets">
|
||||||
<list>
|
<list>
|
||||||
|
|
2
examples/.vscode/settings.json
vendored
2
examples/.vscode/settings.json
vendored
|
@ -9,7 +9,7 @@
|
||||||
],
|
],
|
||||||
"java.configuration.updateBuildConfiguration": "automatic",
|
"java.configuration.updateBuildConfiguration": "automatic",
|
||||||
"java.project.referencedLibraries": [
|
"java.project.referencedLibraries": [
|
||||||
"${HOME}/.bld/dist/bld-1.9.1.jar",
|
"${HOME}/.bld/dist/bld-2.0.0-SNAPSHOT.jar",
|
||||||
"lib/**/*.jar"
|
"lib/**/*.jar"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -1,7 +1,7 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.extensions=com.uwyn.rife2:bld-checkstyle:1.0.1
|
|
||||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
|
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.1
|
||||||
|
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
bld.version=1.9.1
|
bld.version=2.0.0-SNAPSHOT
|
||||||
|
|
Binary file not shown.
|
@ -1,9 +1,9 @@
|
||||||
bld.downloadExtensionJavadoc=false
|
bld.downloadExtensionJavadoc=false
|
||||||
bld.downloadExtensionSources=true
|
bld.downloadExtensionSources=true
|
||||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9
|
|
||||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
|
||||||
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.0
|
|
||||||
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
|
||||||
bld.downloadLocation=
|
bld.downloadLocation=
|
||||||
|
bld.extension-exec=com.uwyn.rife2:bld-exec:1.0.1
|
||||||
|
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.6
|
||||||
|
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.1.2
|
||||||
|
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||||
bld.sourceDirectories=
|
bld.sourceDirectories=
|
||||||
bld.version=1.9.1
|
bld.version=2.0.0-SNAPSHOT
|
||||||
|
|
|
@ -25,8 +25,7 @@ import rife.bld.publish.PublishScm;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
import static rife.bld.dependencies.Repository.*;
|
||||||
import static rife.bld.dependencies.Repository.RIFE2_RELEASES;
|
|
||||||
import static rife.bld.dependencies.Scope.compile;
|
import static rife.bld.dependencies.Scope.compile;
|
||||||
import static rife.bld.dependencies.Scope.test;
|
import static rife.bld.dependencies.Scope.test;
|
||||||
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
|
||||||
|
@ -35,20 +34,20 @@ 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, 1);
|
version = version(1, 0, 2, "SNAPSHOT");
|
||||||
|
|
||||||
javaRelease = 17;
|
javaRelease = 17;
|
||||||
downloadSources = true;
|
downloadSources = true;
|
||||||
autoDownloadPurge = true;
|
autoDownloadPurge = true;
|
||||||
repositories = List.of(MAVEN_CENTRAL, RIFE2_RELEASES);
|
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS);
|
||||||
|
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 1)));
|
.include(dependency("com.uwyn.rife2", "bld", version(2, 0, 0, "SNAPSHOT")));
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 17, 0)))
|
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 17, 0)))
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 26, 3)));
|
||||||
javadocOperation()
|
javadocOperation()
|
||||||
.javadocOptions()
|
.javadocOptions()
|
||||||
.author()
|
.author()
|
||||||
|
@ -90,14 +89,14 @@ public class CheckstyleOperationBuild extends Project {
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Generates JaCoCo Reports")
|
@BuildCommand(summary = "Generates JaCoCo Reports")
|
||||||
public void jacoco() throws IOException {
|
public void jacoco() throws Exception {
|
||||||
new JacocoReportOperation()
|
new JacocoReportOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@BuildCommand(summary = "Runs PMD analysis")
|
@BuildCommand(summary = "Runs PMD analysis")
|
||||||
public void pmd() {
|
public void pmd() throws Exception {
|
||||||
new PmdOperation()
|
new PmdOperation()
|
||||||
.fromProject(this)
|
.fromProject(this)
|
||||||
.failOnViolation(true)
|
.failOnViolation(true)
|
||||||
|
|
|
@ -17,11 +17,15 @@
|
||||||
package rife.bld.extension;
|
package rife.bld.extension;
|
||||||
|
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
|
import rife.bld.extension.checkstyle.OutputFormat;
|
||||||
import rife.bld.operations.AbstractProcessOperation;
|
import rife.bld.operations.AbstractProcessOperation;
|
||||||
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
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.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,16 +36,11 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation> {
|
public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation> {
|
||||||
private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName());
|
||||||
protected final List<String> exclude = new ArrayList<>();
|
private final Collection<String> excludeRegex_ = new ArrayList<>();
|
||||||
protected final List<String> excludeRegex = new ArrayList<>();
|
private final Collection<File> exclude_ = new ArrayList<>();
|
||||||
/**
|
private final Map<String, String> options_ = new ConcurrentHashMap<>();
|
||||||
* The command line options.
|
private final Set<File> sourceDir_ = new TreeSet<>();
|
||||||
*/
|
|
||||||
protected final Map<String, String> options = new ConcurrentHashMap<>();
|
|
||||||
/**
|
|
||||||
* The source files(s) or folder(s).
|
|
||||||
*/
|
|
||||||
protected final Set<String> sourceDirs = new TreeSet<>();
|
|
||||||
private BaseProject project_;
|
private BaseProject project_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +51,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation branchMatchingXpath(String xPathQuery) {
|
public CheckstyleOperation branchMatchingXpath(String xPathQuery) {
|
||||||
if (isNotBlank(xPathQuery)) {
|
if (isNotBlank(xPathQuery)) {
|
||||||
options.put("-b", xPathQuery);
|
options_.put("-b", xPathQuery);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -67,11 +66,23 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation configurationFile(String file) {
|
public CheckstyleOperation configurationFile(String file) {
|
||||||
if (isNotBlank(file)) {
|
if (isNotBlank(file)) {
|
||||||
options.put("-c", file);
|
options_.put("-c", file);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(File file) {
|
||||||
|
return configurationFile(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints all debug logging of CheckStyle utility.
|
* Prints all debug logging of CheckStyle utility.
|
||||||
*
|
*
|
||||||
|
@ -80,9 +91,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation debug(boolean isDebug) {
|
public CheckstyleOperation debug(boolean isDebug) {
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
options.put("-d", "");
|
options_.put("-d", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-d");
|
options_.remove("-d");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -96,11 +107,20 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @see #sourceDir(Collection)
|
* @see #sourceDir(Collection)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation exclude(String... path) {
|
public CheckstyleOperation exclude(String... path) {
|
||||||
for (var p : path) {
|
exclude_.addAll(Arrays.stream(path).map(File::new).toList());
|
||||||
if (isNotBlank(p)) {
|
return this;
|
||||||
exclude.add(p);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(File... path) {
|
||||||
|
exclude_.addAll(List.of(path));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,12 +132,8 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
* @see #exclude(String...)
|
* @see #exclude(String...)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation exclude(Collection<String> paths) {
|
public CheckstyleOperation exclude(Collection<File> paths) {
|
||||||
for (var p : paths) {
|
exclude_.addAll(paths);
|
||||||
if (isNotBlank(p)) {
|
|
||||||
exclude.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,12 +145,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @see #excludeRegex(Collection)
|
* @see #excludeRegex(Collection)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation excludeRegex(String... regex) {
|
public CheckstyleOperation excludeRegex(String... regex) {
|
||||||
for (var r : regex) {
|
excludeRegex_.addAll(List.of(regex));
|
||||||
if (isNotBlank(r)) {
|
|
||||||
excludeRegex.add(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,13 +157,20 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @see #excludeRegex(String...)
|
* @see #excludeRegex(String...)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation excludeRegex(Collection<String> regex) {
|
public CheckstyleOperation excludeRegex(Collection<String> regex) {
|
||||||
for (var r : regex) {
|
excludeRegex_.addAll(regex);
|
||||||
if (isNotBlank(r)) {
|
return this;
|
||||||
excludeRegex.add(r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
@Override
|
||||||
|
public void execute() throws IOException, InterruptedException, ExitStatusException {
|
||||||
|
if (project_ == null) {
|
||||||
|
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||||
|
LOGGER.severe("A project must be specified.");
|
||||||
|
}
|
||||||
|
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||||
|
} else {
|
||||||
|
super.execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,46 +179,50 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected List<String> executeConstructProcessCommandList() {
|
protected List<String> executeConstructProcessCommandList() {
|
||||||
if (project_ == null) {
|
|
||||||
LOGGER.severe("A project must be specified.");
|
|
||||||
} else if (sourceDirs.isEmpty()) {
|
|
||||||
sourceDirs.add(project_.srcMainJavaDirectory().getPath());
|
|
||||||
sourceDirs.add(project_.srcTestJavaDirectory().getPath());
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<String> args = new ArrayList<>();
|
final List<String> args = new ArrayList<>();
|
||||||
|
|
||||||
|
if (project_ != null) {
|
||||||
|
if (sourceDir_.isEmpty()) {
|
||||||
|
sourceDir_.add(project_.srcMainJavaDirectory());
|
||||||
|
sourceDir_.add(project_.srcTestJavaDirectory());
|
||||||
|
}
|
||||||
args.add(javaTool());
|
args.add(javaTool());
|
||||||
|
|
||||||
args.add("-cp");
|
args.add("-cp");
|
||||||
args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"),
|
args.add(String.format("%s:%s:%s:%s", new File(project_.libTestDirectory(), "*"),
|
||||||
Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(),
|
new File(project_.libCompileDirectory(), "*"), project_.buildMainDirectory(),
|
||||||
project_.buildTestDirectory()));
|
project_.buildTestDirectory()));
|
||||||
args.add("com.puppycrawl.tools.checkstyle.Main");
|
args.add("com.puppycrawl.tools.checkstyle.Main");
|
||||||
|
|
||||||
options.forEach((k, v) -> {
|
options_.forEach((k, v) -> {
|
||||||
args.add(k);
|
args.add(k);
|
||||||
if (!v.isEmpty()) {
|
if (!v.isEmpty()) {
|
||||||
args.add(v);
|
args.add(v);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!exclude.isEmpty()) {
|
if (!exclude_.isEmpty()) {
|
||||||
for (var e : exclude) {
|
for (var e : exclude_) {
|
||||||
if (isNotBlank(e)) {
|
if (e.exists()) {
|
||||||
args.add("-e " + e);
|
args.add("-e " + e.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!excludeRegex.isEmpty()) {
|
if (!excludeRegex_.isEmpty()) {
|
||||||
for (var e : excludeRegex) {
|
for (var e : excludeRegex_) {
|
||||||
if (isNotBlank(e)) {
|
if (isNotBlank(e)) {
|
||||||
args.add("-x " + e);
|
args.add("-x " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
args.addAll(sourceDirs);
|
args.addAll(sourceDir_.stream().map(File::getAbsolutePath).toList());
|
||||||
|
|
||||||
|
if (LOGGER.isLoggable(Level.FINE)) {
|
||||||
|
LOGGER.log(Level.FINE, String.join(" ", args));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
@ -222,25 +244,25 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules) {
|
public CheckstyleOperation executeIgnoredModules(boolean isAllowIgnoreModules) {
|
||||||
if (isAllowIgnoreModules) {
|
if (isAllowIgnoreModules) {
|
||||||
options.put("-E", "");
|
options_.put("-E", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-E");
|
options_.remove("-E");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the output format. Valid values: {@link CheckstyleFormatOption#XML},
|
* Specifies the output format. Valid values: {@link OutputFormat#XML},
|
||||||
* {@link CheckstyleFormatOption#SARIF}, {@link CheckstyleFormatOption#PLAIN} for the XML, sarif and default logger
|
* {@link OutputFormat#SARIF}, {@link OutputFormat#PLAIN} for the XML, sarif and default logger
|
||||||
* respectively.
|
* respectively.
|
||||||
* <p>
|
* <p>
|
||||||
* Defaults to {@link CheckstyleFormatOption#PLAIN}.
|
* Defaults to {@link OutputFormat#PLAIN}.
|
||||||
*
|
*
|
||||||
* @param format the output format
|
* @param format the output format
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation format(CheckstyleFormatOption format) {
|
public CheckstyleOperation format(OutputFormat format) {
|
||||||
options.put("-f", format.label.toLowerCase());
|
options_.put("-f", format.label.toLowerCase());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,9 +277,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) {
|
public CheckstyleOperation generateXpathSuppression(boolean xPathSuppression) {
|
||||||
if (xPathSuppression) {
|
if (xPathSuppression) {
|
||||||
options.put("-g", "");
|
options_.put("-g", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-g");
|
options_.remove("-g");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -279,13 +301,22 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation javadocTree(boolean isTree) {
|
public CheckstyleOperation javadocTree(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.put("-j", "");
|
options_.put("-j", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-j");
|
options_.remove("-j");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the command line options.
|
||||||
|
*
|
||||||
|
* @return the command line options
|
||||||
|
*/
|
||||||
|
public Map<String, String> options() {
|
||||||
|
return options_;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the output file.
|
* Sets the output file.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -296,11 +327,23 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation outputPath(String file) {
|
public CheckstyleOperation outputPath(String file) {
|
||||||
if (isNotBlank(file)) {
|
if (isNotBlank(file)) {
|
||||||
options.put("-o", file);
|
options_.put("-o", file);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the output file.
|
||||||
|
* <p>
|
||||||
|
* Defaults to stdout.
|
||||||
|
*
|
||||||
|
* @param file the output file
|
||||||
|
* @return the checkstyle operation
|
||||||
|
*/
|
||||||
|
public CheckstyleOperation outputPath(File file) {
|
||||||
|
return outputPath(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the property files to load.
|
* Sets the property files to load.
|
||||||
*
|
*
|
||||||
|
@ -309,11 +352,21 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation propertiesFile(String file) {
|
public CheckstyleOperation propertiesFile(String file) {
|
||||||
if (isNotBlank(file)) {
|
if (isNotBlank(file)) {
|
||||||
options.put("-p", file);
|
options_.put("-p", file);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the property files to load.
|
||||||
|
*
|
||||||
|
* @param file the file
|
||||||
|
* @return the checkstyle operation
|
||||||
|
*/
|
||||||
|
public CheckstyleOperation propertiesFile(File file) {
|
||||||
|
return propertiesFile(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
|
@ -322,7 +375,19 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @see #sourceDir(Collection)
|
* @see #sourceDir(Collection)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation sourceDir(String... dir) {
|
public CheckstyleOperation sourceDir(String... dir) {
|
||||||
sourceDirs.addAll(Arrays.stream(dir).filter(this::isNotBlank).toList());
|
sourceDir_.addAll(Arrays.stream(dir).map(File::new).toList());
|
||||||
|
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 #sourceDir(Collection)
|
||||||
|
*/
|
||||||
|
public CheckstyleOperation sourceDir(File... dir) {
|
||||||
|
sourceDir_.addAll(List.of(dir));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,11 +398,20 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
* @see #sourceDir(String...)
|
* @see #sourceDir(String...)
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation sourceDir(Collection<String> dirs) {
|
public CheckstyleOperation sourceDir(Collection<File> dirs) {
|
||||||
sourceDirs.addAll(dirs.stream().filter(this::isNotBlank).toList());
|
sourceDir_.addAll(dirs);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the file(s) or folders(s) containing the sources files to check
|
||||||
|
*
|
||||||
|
* @return the files or directories
|
||||||
|
*/
|
||||||
|
public Set<File> sourceDir() {
|
||||||
|
return sourceDir_;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
@ -352,7 +426,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber) {
|
public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber) {
|
||||||
if (isNotBlank(lineColumnNumber)) {
|
if (isNotBlank(lineColumnNumber)) {
|
||||||
options.put("-s", lineColumnNumber);
|
options_.put("-s", lineColumnNumber);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -367,7 +441,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation tabWith(int length) {
|
public CheckstyleOperation tabWith(int length) {
|
||||||
options.put("-w", String.valueOf(length));
|
options_.put("-w", String.valueOf(length));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,9 +454,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation tree(boolean isTree) {
|
public CheckstyleOperation tree(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.put("-t", "");
|
options_.put("-t", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-t");
|
options_.remove("-t");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -396,9 +470,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation treeWithComments(boolean isTree) {
|
public CheckstyleOperation treeWithComments(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.put("-T", "");
|
options_.put("-T", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-T");
|
options_.remove("-T");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -412,9 +486,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
*/
|
*/
|
||||||
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
|
public CheckstyleOperation treeWithJavadoc(boolean isTree) {
|
||||||
if (isTree) {
|
if (isTree) {
|
||||||
options.put("-J", "");
|
options_.put("-J", "");
|
||||||
} else {
|
} else {
|
||||||
options.remove("-J");
|
options_.remove("-J");
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023-2004 the original author or authors.
|
* Copyright 2023-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -14,19 +14,19 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package rife.bld.extension;
|
package rife.bld.extension.checkstyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Checkstyle output format for XML, sarif and default (plaib) logger.
|
* The Checkstyle output format for XML, sarif and default (plaib) logger.
|
||||||
*/
|
*/
|
||||||
public enum CheckstyleFormatOption {
|
public enum OutputFormat {
|
||||||
XML("xml"),
|
XML("xml"),
|
||||||
SARIF("sarif"),
|
SARIF("sarif"),
|
||||||
PLAIN("plain");
|
PLAIN("plain");
|
||||||
|
|
||||||
public final String label;
|
public final String label;
|
||||||
|
|
||||||
CheckstyleFormatOption(String label) {
|
OutputFormat(String label) {
|
||||||
this.label = label;
|
this.label = label;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,10 +16,12 @@
|
||||||
|
|
||||||
package rife.bld.extension;
|
package rife.bld.extension;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import rife.bld.BaseProject;
|
import rife.bld.BaseProject;
|
||||||
import rife.bld.Project;
|
import rife.bld.Project;
|
||||||
import rife.bld.WebProject;
|
import rife.bld.WebProject;
|
||||||
|
import rife.bld.extension.checkstyle.OutputFormat;
|
||||||
import rife.bld.operations.exceptions.ExitStatusException;
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -27,21 +29,38 @@ import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
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.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
|
||||||
|
|
||||||
class CheckstyleOperationTest {
|
class CheckstyleOperationTest {
|
||||||
|
public static final String SRC_MAIN_JAVA = "src/main/java";
|
||||||
|
public static final String SRC_TEST_JAVA = "src/test/java";
|
||||||
private static final String ADD = "add";
|
private static final String ADD = "add";
|
||||||
private static final String BAR = "bar";
|
private static final String BAR = "bar";
|
||||||
private static final String FOO = "foo";
|
private static final String FOO = "foo";
|
||||||
private static final String REMOVE = "remove";
|
private static final String REMOVE = "remove";
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void beforeAll() {
|
||||||
|
var level = Level.ALL;
|
||||||
|
var logger = Logger.getLogger("rife.bld.extension");
|
||||||
|
var consoleHandler = new ConsoleHandler();
|
||||||
|
consoleHandler.setLevel(level);
|
||||||
|
logger.addHandler(consoleHandler);
|
||||||
|
logger.setLevel(level);
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void branchMatchingXpath() {
|
void branchMatchingXpath() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
|
||||||
assertThat(op.options.get("-b")).isEqualTo(FOO);
|
assertThat(op.options().get("-b")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,16 +72,16 @@ class CheckstyleOperationTest {
|
||||||
var params = new CheckstyleOperation()
|
var params = new CheckstyleOperation()
|
||||||
.fromProject(new Project())
|
.fromProject(new Project())
|
||||||
.branchMatchingXpath("xpath")
|
.branchMatchingXpath("xpath")
|
||||||
.configurationFile("config")
|
|
||||||
.debug(true)
|
.debug(true)
|
||||||
.exclude("path")
|
.configurationFile(new File("config"))
|
||||||
|
.exclude(SRC_MAIN_JAVA)
|
||||||
.excludeRegex("regex")
|
.excludeRegex("regex")
|
||||||
.executeIgnoredModules(true)
|
.executeIgnoredModules(true)
|
||||||
.format(CheckstyleFormatOption.XML)
|
.format(OutputFormat.XML)
|
||||||
.generateXpathSuppression(true)
|
.generateXpathSuppression(true)
|
||||||
.javadocTree(true)
|
.javadocTree(true)
|
||||||
.outputPath("optionPath")
|
.outputPath(new File("optionPath"))
|
||||||
.propertiesFile("properties")
|
.propertiesFile(new File("properties"))
|
||||||
.suppressionLineColumnNumber("12")
|
.suppressionLineColumnNumber("12")
|
||||||
.tabWith(1)
|
.tabWith(1)
|
||||||
.tree(true)
|
.tree(true)
|
||||||
|
@ -85,25 +104,33 @@ class CheckstyleOperationTest {
|
||||||
@Test
|
@Test
|
||||||
void configurationFile() {
|
void configurationFile() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).configurationFile(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).configurationFile(FOO);
|
||||||
assertThat(op.options.get("-c")).isEqualTo(FOO);
|
assertThat(op.options().get("-c")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void debug() {
|
void debug() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).debug(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).debug(true);
|
||||||
assertThat(op.options.containsKey("-d")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-d")).as(ADD).isTrue();
|
||||||
op = op.debug(false);
|
op = op.debug(false);
|
||||||
assertThat(op.options.containsKey("-d")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-d")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void exclude() {
|
void exclude() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO, BAR);
|
var foo = new File(SRC_MAIN_JAVA);
|
||||||
|
var bar = new File(SRC_TEST_JAVA);
|
||||||
|
var op = new CheckstyleOperation().fromProject(new Project()).exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
|
||||||
var e = "-e ";
|
var e = "-e ";
|
||||||
assertThat(op.executeConstructProcessCommandList()).contains(e + FOO, e + BAR);
|
assertThat(op.executeConstructProcessCommandList()).as("strings")
|
||||||
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
|
|
||||||
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(FOO, BAR));
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo, bar);
|
||||||
assertThat(op.executeConstructProcessCommandList()).as("as list").contains(e + FOO, e + BAR);
|
assertThat(op.executeConstructProcessCommandList()).as("files")
|
||||||
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
|
|
||||||
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
|
||||||
|
assertThat(op.executeConstructProcessCommandList()).as("list")
|
||||||
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -122,13 +149,19 @@ class CheckstyleOperationTest {
|
||||||
tmpFile.deleteOnExit();
|
tmpFile.deleteOnExit();
|
||||||
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("src/test/resources/google_checks.xml")
|
||||||
.outputPath(tmpFile.getAbsolutePath());
|
.outputPath(tmpFile.getAbsolutePath());
|
||||||
op.execute();
|
op.execute();
|
||||||
assertThat(tmpFile).exists();
|
assertThat(tmpFile).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void executeNoProject() {
|
||||||
|
var op = new CheckstyleOperation();
|
||||||
|
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void executeConstructProcessCommandList() {
|
void executeConstructProcessCommandList() {
|
||||||
var op = new CheckstyleOperation().fromProject(new BaseProject())
|
var op = new CheckstyleOperation().fromProject(new BaseProject())
|
||||||
|
@ -137,7 +170,7 @@ class CheckstyleOperationTest {
|
||||||
.propertiesFile("config/checkstyle.properties")
|
.propertiesFile("config/checkstyle.properties")
|
||||||
.debug(true)
|
.debug(true)
|
||||||
.executeIgnoredModules(true)
|
.executeIgnoredModules(true)
|
||||||
.sourceDir("src/main/java", "src/test/java");
|
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA);
|
||||||
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
|
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
|
||||||
.startsWith("java -cp ")
|
.startsWith("java -cp ")
|
||||||
.endsWith(
|
.endsWith(
|
||||||
|
@ -146,15 +179,16 @@ class CheckstyleOperationTest {
|
||||||
"-b xpath " +
|
"-b xpath " +
|
||||||
"-c config/checkstyle.xml " +
|
"-c config/checkstyle.xml " +
|
||||||
"-d -E " +
|
"-d -E " +
|
||||||
"src/main/java src/test/java");
|
new File(SRC_MAIN_JAVA).getAbsolutePath() + " " +
|
||||||
|
new File(SRC_TEST_JAVA).getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void executeIgnoredModules() {
|
void executeIgnoredModules() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
|
||||||
assertThat(op.options.containsKey("-E")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-E")).as(ADD).isTrue();
|
||||||
op = op.executeIgnoredModules(false);
|
op = op.executeIgnoredModules(false);
|
||||||
assertThat(op.options.containsKey("-E")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-E")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -163,7 +197,7 @@ class CheckstyleOperationTest {
|
||||||
tmpFile.deleteOnExit();
|
tmpFile.deleteOnExit();
|
||||||
var op = new CheckstyleOperation()
|
var op = new CheckstyleOperation()
|
||||||
.fromProject(new WebProject())
|
.fromProject(new WebProject())
|
||||||
.sourceDir(List.of("src/main/java", "src/test/java"))
|
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
|
||||||
.configurationFile("src/test/resources/sun_checks.xml")
|
.configurationFile("src/test/resources/sun_checks.xml")
|
||||||
.outputPath(tmpFile.getAbsolutePath());
|
.outputPath(tmpFile.getAbsolutePath());
|
||||||
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||||
|
@ -172,79 +206,88 @@ class CheckstyleOperationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void format() {
|
void format() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).format(CheckstyleFormatOption.XML);
|
var op = new CheckstyleOperation().fromProject(new Project()).format(OutputFormat.XML);
|
||||||
assertThat(op.options.get("-f")).isEqualTo("xml");
|
assertThat(op.options().get("-f")).isEqualTo("xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateXpathSuppression() {
|
void generateXpathSuppression() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
|
||||||
assertThat(op.options.containsKey("-g")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-g")).as(ADD).isTrue();
|
||||||
op = op.generateXpathSuppression(false);
|
op = op.generateXpathSuppression(false);
|
||||||
assertThat(op.options.containsKey("-g")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-g")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void javadocTree() {
|
void javadocTree() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
|
||||||
assertThat(op.options.containsKey("-j")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-j")).as(ADD).isTrue();
|
||||||
op = op.javadocTree(false);
|
op = op.javadocTree(false);
|
||||||
assertThat(op.options.containsKey("-j")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-j")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void outputPath() {
|
void outputPath() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).outputPath(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).outputPath(FOO);
|
||||||
assertThat(op.options.get("-o")).isEqualTo(FOO);
|
assertThat(op.options().get("-o")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDir() {
|
void sourceDir() {
|
||||||
|
var foo = new File(FOO);
|
||||||
|
var bar = new File(BAR);
|
||||||
|
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO);
|
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO);
|
||||||
assertThat(op.sourceDirs).contains(FOO);
|
assertThat(op.sourceDir()).contains(foo);
|
||||||
op = op.sourceDir(FOO, BAR);
|
|
||||||
assertThat(op.sourceDirs).as("foo, bar").hasSize(2).contains(FOO).contains(BAR);
|
op = op.sourceDir(foo, bar);
|
||||||
|
assertThat(op.sourceDir()).as("foo, bar").hasSize(2)
|
||||||
|
.contains(foo).contains(bar);
|
||||||
|
|
||||||
|
op = op.sourceDir(List.of(foo, bar));
|
||||||
|
assertThat(op.sourceDir()).as("List.of(foo, bar)").hasSize(2)
|
||||||
|
.contains(foo).contains(bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
assertThat(op.options.get("-s")).isEqualTo(FOO + ':' + BAR);
|
assertThat(op.options().get("-s")).isEqualTo(FOO + ':' + BAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void tabWith() {
|
void tabWith() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).tabWith(9);
|
var op = new CheckstyleOperation().fromProject(new Project()).tabWith(9);
|
||||||
assertThat(op.options.get("-w")).isEqualTo("9");
|
assertThat(op.options().get("-w")).isEqualTo("9");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void tree() {
|
void tree() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).tree(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).tree(true);
|
||||||
assertThat(op.options.containsKey("-t")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-t")).as(ADD).isTrue();
|
||||||
op = op.tree(false);
|
op = op.tree(false);
|
||||||
assertThat(op.options.containsKey("-t")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-t")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void treeWithComments() {
|
void treeWithComments() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).treeWithComments(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).treeWithComments(true);
|
||||||
assertThat(op.options.containsKey("-T")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-T")).as(ADD).isTrue();
|
||||||
op = op.treeWithComments(false);
|
op = op.treeWithComments(false);
|
||||||
assertThat(op.options.containsKey("-T")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-T")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void treeWithJavadoc() {
|
void treeWithJavadoc() {
|
||||||
var op = new CheckstyleOperation().fromProject(new Project()).treeWithJavadoc(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).treeWithJavadoc(true);
|
||||||
assertThat(op.options.containsKey("-J")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-J")).as(ADD).isTrue();
|
||||||
op = op.treeWithJavadoc(false);
|
op = op.treeWithJavadoc(false);
|
||||||
assertThat(op.options.containsKey("-J")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-J")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue