Compare commits

...

5 commits

9 changed files with 376 additions and 243 deletions

View file

@ -7,7 +7,6 @@ jobs:
strategy:
matrix:
java-version: [ 17, 21, 24 ]
kotlin-version: [ 1.9.25, 2.0.21, 2.1.20 ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
@ -36,4 +35,4 @@ jobs:
run: ./bld download
- name: Run tests
run: ./bld compile test
run: ./bld compile test

6
.idea/misc.xml generated
View file

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0">
<entry_point TYPE="field" FQNAME="rife.bld.extension.checkstyle.OutputFormat PLAIN" />
<entry_point TYPE="field" FQNAME="rife.bld.extension.checkstyle.OutputFormat SARIF" />
</entry_points>
<pattern value="rife.bld.extension.CheckstyleOperationBuild" />
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="jacoco" />
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="pmd" />
@ -25,7 +29,7 @@
</option>
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>

View file

@ -45,5 +45,5 @@ not provided by the extension. For example:
```java
repositories = List.of(MAVEN_CENTRAL);
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)));
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)));
```

View file

@ -1,7 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.14
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.15
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories=
bld.version=2.2.1

View file

@ -26,7 +26,7 @@ public class ExamplesBuild extends BaseProject {
repositories = List.of(MAVEN_CENTRAL);
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)));
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)));
testOperation().mainClass("com.example.ExamplesTest");
}

View file

@ -22,6 +22,9 @@ import rife.bld.publish.PublishDeveloper;
import rife.bld.publish.PublishLicense;
import rife.bld.publish.PublishScm;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
@ -34,7 +37,7 @@ public class CheckstyleOperationBuild extends Project {
public CheckstyleOperationBuild() {
pkg = "rife.bld.extension";
name = "CheckstyleOperation";
version = version(1, 0, 15, "SNAPSHOT");
version = version(1, 0, 15);
javaRelease = 17;
@ -46,7 +49,7 @@ public class CheckstyleOperationBuild extends Project {
scope(compile)
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1)));
scope(test)
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)))
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 2)))
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3)));
@ -107,6 +110,32 @@ public class CheckstyleOperationBuild extends Project {
.command("scripts/cliargs.sh")
.execute();
}
super.test();
var testResultsDir = "build/test-results/test/";
var op = testOperation().fromProject(this);
op.testToolOptions().reportsDir(new File(testResultsDir));
Exception ex = null;
try {
op.execute();
} catch (Exception e) {
ex = e;
}
var xunitViewer = new File("/usr/bin/xunit-viewer");
if (xunitViewer.exists() && xunitViewer.canExecute()) {
var reportsDir = "build/reports/tests/test/";
Files.createDirectories(Path.of(reportsDir));
new ExecOperation()
.fromProject(this)
.command(xunitViewer.getPath(), "-r", testResultsDir, "-o", reportsDir + "index.html")
.execute();
}
if (ex != null) {
throw ex;
}
}
}

View file

@ -314,6 +314,25 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return this;
}
/**
* Generates to output a suppression xml that will have suppress elements with {@code checks} and {@code files}
* attributes only to use to suppress all violations from user's config. Instead of printing every violation, all
* violations will be catched and single suppressions xml file will be printed out. Used only with the
* {@link #configurationFile(String) configurationFile} option. Output location can be
* specified with the {@link #outputPath(String) output} option.
*
* @param generateChecksAndFileSuppression {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation generateChecksAndFileSuppression(boolean generateChecksAndFileSuppression) {
if (generateChecksAndFileSuppression) {
options_.put("-G", "");
} else {
options_.remove("-G");
}
return this;
}
/**
* Generates to output a suppression xml to use to suppress all violations from user's config. Instead of printing
* every violation, all violations will be caught and single suppressions xml file will be printed out.
@ -455,6 +474,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @return the checkstyle operation
* @see #sourceDir(Collection)
*/
@SuppressWarnings("UnusedReturnValue")
public CheckstyleOperation sourceDir(File... dir) {
return sourceDir(List.of(dir));
}
@ -466,6 +486,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* @return the checkstyle operation
* @see #sourceDirPaths(Collection)
*/
@SuppressWarnings("UnusedReturnValue")
public CheckstyleOperation sourceDir(Path... dir) {
return sourceDirPaths(List.of(dir));
}

View file

@ -18,6 +18,8 @@ package rife.bld.extension;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
@ -41,12 +43,12 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
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 BAR = "bar";
private static final String FOO = "foo";
private static final String REMOVE = "remove";
private static final String SRC_MAIN_JAVA = "src/main/java";
private static final String SRC_TEST_JAVA = "src/test/java";
@BeforeAll
static void beforeAll() {
@ -59,272 +61,349 @@ class CheckstyleOperationTest {
logger.setUseParentHandlers(false);
}
@Test
void branchMatchingXpath() {
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
assertThat(op.options().get("-b")).isEqualTo(FOO);
private CheckstyleOperation newCheckstyleOperation() {
return new CheckstyleOperation().fromProject(new Project());
}
@Test
@EnabledOnOs(OS.LINUX)
void checkAllParameters() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "checkstyle-args.txt"));
@Nested
@DisplayName("Exclude Tests")
class ExcludeTests {
private static final String e = "-e ";
private static final String x = "-x ";
private final File srcMainJavaDir = new File(SRC_MAIN_JAVA);
private final File srcTestJavaDir = new File(SRC_TEST_JAVA);
assertThat(args).isNotEmpty();
@Test
void excludeFromFileArray() {
var op = newCheckstyleOperation().exclude(srcTestJavaDir, srcMainJavaDir);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
}
var params = new CheckstyleOperation()
.fromProject(new Project())
.branchMatchingXpath("xpath")
.debug(true)
.configurationFile(new File("config"))
.exclude(SRC_MAIN_JAVA)
.excludeRegex("regex")
.executeIgnoredModules(true)
.format(OutputFormat.XML)
.generateXpathSuppression(true)
.javadocTree(true)
.outputPath(new File("optionPath"))
.propertiesFile(new File("properties"))
.suppressionLineColumnNumber("12")
.tabWith(1)
.tree(true)
.treeWithComments(true)
.treeWithJavadoc(true)
.executeConstructProcessCommandList();
@Test
void excludeFromFileList() {
var op = newCheckstyleOperation()
.exclude(List.of(srcTestJavaDir, srcMainJavaDir));
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
}
try (var softly = new AutoCloseableSoftAssertions()) {
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
softly.assertThat(found).as(p + " not found.").isTrue();
}
@Test
void excludeFromPathArray() {
var op = newCheckstyleOperation()
.exclude(srcTestJavaDir.toPath(), srcMainJavaDir.toPath());
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
}
@Test
void excludeFromPathList() {
var op = newCheckstyleOperation()
.excludePaths(List.of(srcTestJavaDir.toPath(), srcMainJavaDir.toPath()));
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
}
@Test
void excludeFromStringArray() {
var op = newCheckstyleOperation().exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
}
@Test
void excludeFromStringList() {
var op = newCheckstyleOperation()
.excludeStrings(List.of(SRC_MAIN_JAVA, SRC_TEST_JAVA));
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.contains(e + srcMainJavaDir.getAbsolutePath()).contains(e + srcTestJavaDir.getAbsolutePath());
}
@Test
void excludeNonExistingPath() {
var op = newCheckstyleOperation().exclude(FOO);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.doesNotContain(e + FOO);
}
@Test
void excludeNonExistingPaths() {
var op = newCheckstyleOperation().exclude(FOO, BAR);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.doesNotContain(e + FOO).doesNotContain(e + BAR);
}
@Test
void excludeRegex() {
var op = newCheckstyleOperation().excludeRegex(FOO, BAR);
assertThat(String.join(" ", op.executeConstructProcessCommandList())).contains(x + FOO, x + BAR);
}
@Test
void excludeRegexFromList() {
var op = newCheckstyleOperation().excludeRegex(List.of(FOO, BAR));
assertThat(String.join(" ", op.executeConstructProcessCommandList())).contains(x + FOO, x + BAR);
}
}
@Test
void configurationFile() {
var op = new CheckstyleOperation().fromProject(new Project()).configurationFile(FOO);
assertThat(op.options().get("-c")).isEqualTo(FOO);
@Nested
@DisplayName("Execute Tests")
class ExecuteTests {
@Test
void execute() throws IOException, ExitStatusException, InterruptedException {
var tmpFile = File.createTempFile("checkstyle-google", ".txt");
tmpFile.deleteOnExit();
var op = new CheckstyleOperation()
.fromProject(new WebProject())
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
.configurationFile(Path.of("src/test/resources/google_checks.xml"))
.outputPath(tmpFile.toPath());
op.execute();
assertThat(tmpFile).as("tmp file should exist").exists();
}
@Test
void executeConstructProcessCommandList() {
var op = new CheckstyleOperation().fromProject(new BaseProject())
.configurationFile("config/checkstyle.xml")
.branchMatchingXpath("xpath")
.propertiesFile("config/checkstyle.properties")
.debug(true)
.executeIgnoredModules(true)
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.startsWith("java -cp ")
.endsWith(
"com.puppycrawl.tools.checkstyle.Main " +
"-p config/checkstyle.properties " +
"-b xpath " +
"-c config/checkstyle.xml " +
"-d -E " +
new File(SRC_MAIN_JAVA).getAbsolutePath() + " " +
new File(SRC_TEST_JAVA).getAbsolutePath());
}
@Test
void executeIgnoredModules() {
var op = newCheckstyleOperation().executeIgnoredModules(true);
assertThat(op.options().containsKey("-E")).as(ADD).isTrue();
op = op.executeIgnoredModules(false);
assertThat(op.options().containsKey("-E")).as(REMOVE).isFalse();
}
@Test
void executeNoProject() {
var op = new CheckstyleOperation();
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
}
@Test
void executeSunChecks() throws IOException {
var tmpFile = File.createTempFile("checkstyle-sun", ".txt");
tmpFile.deleteOnExit();
var op = newCheckstyleOperation()
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
.configurationFile("src/test/resources/sun_checks.xml")
.outputPath(tmpFile.getAbsolutePath());
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
assertThat(tmpFile).as("tmp file should exist").exists();
}
}
@Test
void debug() {
var op = new CheckstyleOperation().fromProject(new Project()).debug(true);
assertThat(op.options().containsKey("-d")).as(ADD).isTrue();
op = op.debug(false);
assertThat(op.options().containsKey("-d")).as(REMOVE).isFalse();
}
@Nested
@DisplayName("Options Tests")
class OptionsTests {
@Test
void branchMatchingXpath() {
var op = newCheckstyleOperation().branchMatchingXpath(FOO);
assertThat(op.options().get("-b")).isEqualTo(FOO);
}
@Test
void exclude() {
var foo = new File(SRC_MAIN_JAVA);
var bar = new File(SRC_TEST_JAVA);
var e = "-e ";
@Test
@EnabledOnOs(OS.LINUX)
void checkAllParameters() throws IOException {
var args = Files.readAllLines(Paths.get("src", "test", "resources", "checkstyle-args.txt"));
var op = new CheckstyleOperation().fromProject(new Project()).exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("String...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
assertThat(args).isNotEmpty();
op = new CheckstyleOperation().fromProject(new Project()).excludeStrings(List.of(SRC_MAIN_JAVA, SRC_TEST_JAVA));
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(String...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
var params = newCheckstyleOperation()
.branchMatchingXpath("xpath")
.debug(true)
.configurationFile(new File("config"))
.exclude(SRC_MAIN_JAVA)
.excludeRegex("regex")
.executeIgnoredModules(true)
.format(OutputFormat.XML)
.generateXpathSuppression(true)
.generateChecksAndFileSuppression(true)
.javadocTree(true)
.outputPath(new File("optionPath"))
.propertiesFile(new File("properties"))
.suppressionLineColumnNumber("12")
.tabWith(1)
.tree(true)
.treeWithComments(true)
.treeWithJavadoc(true)
.executeConstructProcessCommandList();
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo, bar);
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("File...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
try (var softly = new AutoCloseableSoftAssertions()) {
for (var p : args) {
var found = false;
for (var a : params) {
if (a.startsWith(p)) {
found = true;
break;
}
}
softly.assertThat(found).as("%s not found.", p).isTrue();
}
}
}
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(File...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
@Test
void configurationFile() {
var op = newCheckstyleOperation().configurationFile(FOO);
assertThat(op.options().get("-c")).isEqualTo(FOO);
}
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo.toPath(), bar.toPath());
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("Path...")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
@Test
void debug() {
var op = newCheckstyleOperation().debug(true);
assertThat(op.options().containsKey("-d")).as(ADD).isTrue();
op = op.debug(false);
assertThat(op.options().containsKey("-d")).as(REMOVE).isFalse();
}
op = new CheckstyleOperation().fromProject(new Project()).excludePaths(List.of(foo.toPath(), bar.toPath()));
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(Path...)")
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
}
@Test
void format() {
var op = newCheckstyleOperation().format(OutputFormat.XML);
assertThat(op.options().get("-f")).isEqualTo("xml");
}
@Test
void excludeRegex() {
var op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(FOO, BAR);
var x = "-x ";
assertThat(String.join(" ", op.executeConstructProcessCommandList())).contains(x + FOO, x + BAR);
@Test
void generateChecksAndFileSuppression() {
var op = newCheckstyleOperation().generateChecksAndFileSuppression(true);
assertThat(op.options().containsKey("-G")).as(ADD).isTrue();
op = op.generateChecksAndFileSuppression(false);
assertThat(op.options().containsKey("-G")).as(REMOVE).isFalse();
}
op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(List.of(FOO, BAR));
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("as list").contains(x + FOO, x + BAR);
}
@Test
void generateXpathSuppression() {
var op = newCheckstyleOperation().generateXpathSuppression(true);
assertThat(op.options().containsKey("-g")).as(ADD).isTrue();
op = op.generateXpathSuppression(false);
assertThat(op.options().containsKey("-g")).as(REMOVE).isFalse();
}
@Test
void execute() throws IOException, ExitStatusException, InterruptedException {
var tmpFile = File.createTempFile("checkstyle-google", ".txt");
tmpFile.deleteOnExit();
var op = new CheckstyleOperation()
.fromProject(new WebProject())
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
.configurationFile(Path.of("src/test/resources/google_checks.xml"))
.outputPath(tmpFile.toPath());
op.execute();
assertThat(tmpFile).exists();
}
@Test
void javadocTree() {
var op = newCheckstyleOperation().javadocTree(true);
assertThat(op.options().containsKey("-j")).as(ADD).isTrue();
op = op.javadocTree(false);
assertThat(op.options().containsKey("-j")).as(REMOVE).isFalse();
}
@Test
void executeConstructProcessCommandList() {
var op = new CheckstyleOperation().fromProject(new BaseProject())
.configurationFile("config/checkstyle.xml")
.branchMatchingXpath("xpath")
.propertiesFile("config/checkstyle.properties")
.debug(true)
.executeIgnoredModules(true)
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA);
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
.startsWith("java -cp ")
.endsWith(
"com.puppycrawl.tools.checkstyle.Main " +
"-p config/checkstyle.properties " +
"-b xpath " +
"-c config/checkstyle.xml " +
"-d -E " +
new File(SRC_MAIN_JAVA).getAbsolutePath() + " " +
new File(SRC_TEST_JAVA).getAbsolutePath());
}
@Test
void outputPath() {
var op = newCheckstyleOperation().outputPath(FOO);
assertThat(op.options().get("-o")).isEqualTo(FOO);
}
@Test
void executeIgnoredModules() {
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
assertThat(op.options().containsKey("-E")).as(ADD).isTrue();
op = op.executeIgnoredModules(false);
assertThat(op.options().containsKey("-E")).as(REMOVE).isFalse();
}
@Test
void propertiesFile() {
var op = newCheckstyleOperation().propertiesFile(FOO);
assertThat(op.options().get("-p")).isEqualTo(FOO);
@Test
void executeNoProject() {
var op = new CheckstyleOperation();
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
}
var fooPath = Path.of(FOO);
op = op.propertiesFile(fooPath);
assertThat(op.options().get("-p")).isEqualTo(fooPath.toFile().getAbsolutePath());
}
@Test
void executeSunChecks() throws IOException {
var tmpFile = File.createTempFile("checkstyle-sun", ".txt");
tmpFile.deleteOnExit();
var op = new CheckstyleOperation()
.fromProject(new WebProject())
.sourceDir(SRC_MAIN_JAVA, SRC_TEST_JAVA)
.configurationFile("src/test/resources/sun_checks.xml")
.outputPath(tmpFile.getAbsolutePath());
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
assertThat(tmpFile).exists();
}
@Test
void suppressionLineColumnNumber() {
var op = newCheckstyleOperation().suppressionLineColumnNumber(FOO + ':' + BAR);
assertThat(op.options().get("-s")).isEqualTo(FOO + ':' + BAR);
}
@Test
void format() {
var op = new CheckstyleOperation().fromProject(new Project()).format(OutputFormat.XML);
assertThat(op.options().get("-f")).isEqualTo("xml");
}
@Test
void tabWith() {
var op = newCheckstyleOperation().tabWith(9);
assertThat(op.options().get("-w")).isEqualTo("9");
}
@Test
void generateXpathSuppression() {
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
assertThat(op.options().containsKey("-g")).as(ADD).isTrue();
op = op.generateXpathSuppression(false);
assertThat(op.options().containsKey("-g")).as(REMOVE).isFalse();
}
@Test
void tree() {
var op = newCheckstyleOperation().tree(true);
assertThat(op.options().containsKey("-t")).as(ADD).isTrue();
op = op.tree(false);
assertThat(op.options().containsKey("-t")).as(REMOVE).isFalse();
}
@Test
void javadocTree() {
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
assertThat(op.options().containsKey("-j")).as(ADD).isTrue();
op = op.javadocTree(false);
assertThat(op.options().containsKey("-j")).as(REMOVE).isFalse();
}
@Test
void treeWithComments() {
var op = newCheckstyleOperation().treeWithComments(true);
assertThat(op.options().containsKey("-T")).as(ADD).isTrue();
op = op.treeWithComments(false);
assertThat(op.options().containsKey("-T")).as(REMOVE).isFalse();
}
@Test
void outputPath() {
var op = new CheckstyleOperation().fromProject(new Project()).outputPath(FOO);
assertThat(op.options().get("-o")).isEqualTo(FOO);
}
@Test
void treeWithJavadoc() {
var op = newCheckstyleOperation().treeWithJavadoc(true);
assertThat(op.options().containsKey("-J")).as(ADD).isTrue();
op = op.treeWithJavadoc(false);
assertThat(op.options().containsKey("-J")).as(REMOVE).isFalse();
}
@Test
void propertiesFile() {
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
assertThat(op.options().get("-p")).isEqualTo(FOO);
@Nested
@DisplayName("Source Dir Tests")
class SourceDirTests {
private final File bar = new File(BAR);
private final File foo = new File(FOO);
private final CheckstyleOperation op = newCheckstyleOperation().sourceDir(FOO, BAR);
var fooPath = Path.of(FOO);
op = op.propertiesFile(fooPath);
assertThat(op.options().get("-p")).isEqualTo(fooPath.toFile().getAbsolutePath());
}
@Test
void sourceDirFromFileArray() {
op.sourceDir(foo, bar);
assertThat(op.sourceDir()).as("File...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
@Test
void sourceDir() {
var foo = new File(FOO);
var bar = new File(BAR);
@Test
void sourceDirFromFileList() {
op.sourceDir(List.of(foo, bar));
assertThat(op.sourceDir()).as("List(File...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO, BAR);
assertThat(op.sourceDir()).as("String...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
@Test
void sourceDirFromPathArray() {
op.sourceDir(foo.toPath(), bar.toPath());
assertThat(op.sourceDir()).as("Path...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
op = op.sourceDirStrings(List.of(FOO, BAR));
assertThat(op.sourceDir()).as("List(String...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
@Test
void sourceDirFromPathList() {
op.sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.sourceDir()).as("List(Path...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
op = op.sourceDir(foo, bar);
assertThat(op.sourceDir()).as("File...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
@Test
void sourceDirFromStringArray() {
op.sourceDir("foo", "bar");
assertThat(op.sourceDir()).as("String...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
op = op.sourceDir(List.of(foo, bar));
assertThat(op.sourceDir()).as("List(File...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDir(foo.toPath(), bar.toPath());
assertThat(op.sourceDir()).as("Path...").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
op = op.sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.sourceDir()).as("List(Path...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
@Test
void suppressionLineColumnNumber() {
var op = new CheckstyleOperation().fromProject(new Project()).suppressionLineColumnNumber(FOO + ':' + BAR);
assertThat(op.options().get("-s")).isEqualTo(FOO + ':' + BAR);
}
@Test
void tabWith() {
var op = new CheckstyleOperation().fromProject(new Project()).tabWith(9);
assertThat(op.options().get("-w")).isEqualTo("9");
}
@Test
void tree() {
var op = new CheckstyleOperation().fromProject(new Project()).tree(true);
assertThat(op.options().containsKey("-t")).as(ADD).isTrue();
op = op.tree(false);
assertThat(op.options().containsKey("-t")).as(REMOVE).isFalse();
}
@Test
void treeWithComments() {
var op = new CheckstyleOperation().fromProject(new Project()).treeWithComments(true);
assertThat(op.options().containsKey("-T")).as(ADD).isTrue();
op = op.treeWithComments(false);
assertThat(op.options().containsKey("-T")).as(REMOVE).isFalse();
}
@Test
void treeWithJavadoc() {
var op = new CheckstyleOperation().fromProject(new Project()).treeWithJavadoc(true);
assertThat(op.options().containsKey("-J")).as(ADD).isTrue();
op = op.treeWithJavadoc(false);
assertThat(op.options().containsKey("-J")).as(REMOVE).isFalse();
@Test
void sourceDirFromStringList() {
op.sourceDirStrings(List.of(FOO, BAR));
assertThat(op.sourceDir()).as("List(String...)").hasSize(2).contains(foo, bar);
op.sourceDir().clear();
}
}
}
}

View file

@ -5,6 +5,7 @@
-E
-f
-g
-G
-j
-J
-o