Compare commits
No commits in common. "f61a4ee188fa29f9d137dc0d2e1abd5367aa525d" and "c8c38b561246dc71d72c0209f6fe2f70efd1e153" have entirely different histories.
f61a4ee188
...
c8c38b5612
9 changed files with 248 additions and 381 deletions
1
.github/workflows/bld.yml
vendored
1
.github/workflows/bld.yml
vendored
|
@ -7,6 +7,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java-version: [ 17, 21, 24 ]
|
java-version: [ 17, 21, 24 ]
|
||||||
|
kotlin-version: [ 1.9.25, 2.0.21, 2.1.20 ]
|
||||||
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
os: [ ubuntu-latest, windows-latest, macos-latest ]
|
||||||
|
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
6
.idea/misc.xml
generated
6
.idea/misc.xml
generated
|
@ -1,10 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
<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" />
|
||||||
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="jacoco" />
|
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="jacoco" />
|
||||||
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="pmd" />
|
<pattern value="rife.bld.extension.CheckstyleOperationBuild" method="pmd" />
|
||||||
|
@ -29,7 +25,7 @@
|
||||||
</option>
|
</option>
|
||||||
<option name="skipTestSources" value="false" />
|
<option name="skipTestSources" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build" />
|
<output url="file://$PROJECT_DIR$/build" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -45,5 +45,5 @@ not provided by the extension. For example:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
repositories = List.of(MAVEN_CENTRAL);
|
repositories = List.of(MAVEN_CENTRAL);
|
||||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)));
|
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)));
|
||||||
```
|
```
|
||||||
|
|
|
@ -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.15
|
bld.extension-checkstyle=com.uwyn.rife2:bld-checkstyle:1.0.14
|
||||||
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.2.1
|
bld.version=2.2.1
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class ExamplesBuild extends BaseProject {
|
||||||
|
|
||||||
repositories = List.of(MAVEN_CENTRAL);
|
repositories = List.of(MAVEN_CENTRAL);
|
||||||
|
|
||||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)));
|
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)));
|
||||||
|
|
||||||
testOperation().mainClass("com.example.ExamplesTest");
|
testOperation().mainClass("com.example.ExamplesTest");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,6 @@ import rife.bld.publish.PublishDeveloper;
|
||||||
import rife.bld.publish.PublishLicense;
|
import rife.bld.publish.PublishLicense;
|
||||||
import rife.bld.publish.PublishScm;
|
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.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -37,7 +34,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, 15);
|
version = version(1, 0, 15, "SNAPSHOT");
|
||||||
|
|
||||||
javaRelease = 17;
|
javaRelease = 17;
|
||||||
|
|
||||||
|
@ -49,7 +46,7 @@ public class CheckstyleOperationBuild extends Project {
|
||||||
scope(compile)
|
scope(compile)
|
||||||
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1)));
|
.include(dependency("com.uwyn.rife2", "bld", version(2, 2, 1)));
|
||||||
scope(test)
|
scope(test)
|
||||||
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 24, 0)))
|
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 23, 1)))
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2)))
|
.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.junit.platform", "junit-platform-console-standalone", version(1, 12, 2)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3)));
|
||||||
|
@ -110,32 +107,6 @@ public class CheckstyleOperationBuild extends Project {
|
||||||
.command("scripts/cliargs.sh")
|
.command("scripts/cliargs.sh")
|
||||||
.execute();
|
.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,25 +314,6 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
return this;
|
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
|
* 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.
|
* every violation, all violations will be caught and single suppressions xml file will be printed out.
|
||||||
|
@ -474,7 +455,6 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
* @see #sourceDir(Collection)
|
* @see #sourceDir(Collection)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
|
||||||
public CheckstyleOperation sourceDir(File... dir) {
|
public CheckstyleOperation sourceDir(File... dir) {
|
||||||
return sourceDir(List.of(dir));
|
return sourceDir(List.of(dir));
|
||||||
}
|
}
|
||||||
|
@ -486,7 +466,6 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
||||||
* @return the checkstyle operation
|
* @return the checkstyle operation
|
||||||
* @see #sourceDirPaths(Collection)
|
* @see #sourceDirPaths(Collection)
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("UnusedReturnValue")
|
|
||||||
public CheckstyleOperation sourceDir(Path... dir) {
|
public CheckstyleOperation sourceDir(Path... dir) {
|
||||||
return sourceDirPaths(List.of(dir));
|
return sourceDirPaths(List.of(dir));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ package rife.bld.extension;
|
||||||
|
|
||||||
import org.assertj.core.api.AutoCloseableSoftAssertions;
|
import org.assertj.core.api.AutoCloseableSoftAssertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
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.Test;
|
||||||
import org.junit.jupiter.api.condition.EnabledOnOs;
|
import org.junit.jupiter.api.condition.EnabledOnOs;
|
||||||
import org.junit.jupiter.api.condition.OS;
|
import org.junit.jupiter.api.condition.OS;
|
||||||
|
@ -43,12 +41,12 @@ 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";
|
||||||
private static final String SRC_MAIN_JAVA = "src/main/java";
|
|
||||||
private static final String SRC_TEST_JAVA = "src/test/java";
|
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void beforeAll() {
|
static void beforeAll() {
|
||||||
|
@ -61,349 +59,272 @@ class CheckstyleOperationTest {
|
||||||
logger.setUseParentHandlers(false);
|
logger.setUseParentHandlers(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CheckstyleOperation newCheckstyleOperation() {
|
|
||||||
return new CheckstyleOperation().fromProject(new Project());
|
@Test
|
||||||
|
void branchMatchingXpath() {
|
||||||
|
var op = new CheckstyleOperation().fromProject(new Project()).branchMatchingXpath(FOO);
|
||||||
|
assertThat(op.options().get("-b")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Test
|
||||||
@DisplayName("Exclude Tests")
|
@EnabledOnOs(OS.LINUX)
|
||||||
class ExcludeTests {
|
void checkAllParameters() throws IOException {
|
||||||
private static final String e = "-e ";
|
var args = Files.readAllLines(Paths.get("src", "test", "resources", "checkstyle-args.txt"));
|
||||||
private static final String x = "-x ";
|
|
||||||
private final File srcMainJavaDir = new File(SRC_MAIN_JAVA);
|
|
||||||
private final File srcTestJavaDir = new File(SRC_TEST_JAVA);
|
|
||||||
|
|
||||||
@Test
|
assertThat(args).isNotEmpty();
|
||||||
void excludeFromFileArray() {
|
|
||||||
var op = newCheckstyleOperation().exclude(srcTestJavaDir, srcMainJavaDir);
|
|
||||||
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
|
|
||||||
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
var params = new CheckstyleOperation()
|
||||||
void excludeFromFileList() {
|
.fromProject(new Project())
|
||||||
var op = newCheckstyleOperation()
|
.branchMatchingXpath("xpath")
|
||||||
.exclude(List.of(srcTestJavaDir, srcMainJavaDir));
|
.debug(true)
|
||||||
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
|
.configurationFile(new File("config"))
|
||||||
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
|
.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
|
try (var softly = new AutoCloseableSoftAssertions()) {
|
||||||
void excludeFromPathArray() {
|
for (var p : args) {
|
||||||
var op = newCheckstyleOperation()
|
var found = false;
|
||||||
.exclude(srcTestJavaDir.toPath(), srcMainJavaDir.toPath());
|
for (var a : params) {
|
||||||
assertThat(String.join(" ", op.executeConstructProcessCommandList()))
|
if (a.startsWith(p)) {
|
||||||
.contains(e + srcTestJavaDir.getAbsolutePath()).contains(e + srcMainJavaDir.getAbsolutePath());
|
found = true;
|
||||||
}
|
break;
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nested
|
|
||||||
@DisplayName("Options Tests")
|
|
||||||
class OptionsTests {
|
|
||||||
@Test
|
|
||||||
void branchMatchingXpath() {
|
|
||||||
var op = newCheckstyleOperation().branchMatchingXpath(FOO);
|
|
||||||
assertThat(op.options().get("-b")).isEqualTo(FOO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@EnabledOnOs(OS.LINUX)
|
|
||||||
void checkAllParameters() throws IOException {
|
|
||||||
var args = Files.readAllLines(Paths.get("src", "test", "resources", "checkstyle-args.txt"));
|
|
||||||
|
|
||||||
assertThat(args).isNotEmpty();
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
softly.assertThat(found).as(p + " not found.").isTrue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void configurationFile() {
|
void configurationFile() {
|
||||||
var op = newCheckstyleOperation().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 = newCheckstyleOperation().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 format() {
|
void exclude() {
|
||||||
var op = newCheckstyleOperation().format(OutputFormat.XML);
|
var foo = new File(SRC_MAIN_JAVA);
|
||||||
assertThat(op.options().get("-f")).isEqualTo("xml");
|
var bar = new File(SRC_TEST_JAVA);
|
||||||
}
|
var e = "-e ";
|
||||||
|
|
||||||
@Test
|
var op = new CheckstyleOperation().fromProject(new Project()).exclude(SRC_MAIN_JAVA, SRC_TEST_JAVA);
|
||||||
void generateChecksAndFileSuppression() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("String...")
|
||||||
var op = newCheckstyleOperation().generateChecksAndFileSuppression(true);
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
assertThat(op.options().containsKey("-G")).as(ADD).isTrue();
|
|
||||||
op = op.generateChecksAndFileSuppression(false);
|
|
||||||
assertThat(op.options().containsKey("-G")).as(REMOVE).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
op = new CheckstyleOperation().fromProject(new Project()).excludeStrings(List.of(SRC_MAIN_JAVA, SRC_TEST_JAVA));
|
||||||
void generateXpathSuppression() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(String...)")
|
||||||
var op = newCheckstyleOperation().generateXpathSuppression(true);
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
assertThat(op.options().containsKey("-g")).as(ADD).isTrue();
|
|
||||||
op = op.generateXpathSuppression(false);
|
|
||||||
assertThat(op.options().containsKey("-g")).as(REMOVE).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo, bar);
|
||||||
void javadocTree() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("File...")
|
||||||
var op = newCheckstyleOperation().javadocTree(true);
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
assertThat(op.options().containsKey("-j")).as(ADD).isTrue();
|
|
||||||
op = op.javadocTree(false);
|
|
||||||
assertThat(op.options().containsKey("-j")).as(REMOVE).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(foo, bar));
|
||||||
void outputPath() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(File...)")
|
||||||
var op = newCheckstyleOperation().outputPath(FOO);
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
assertThat(op.options().get("-o")).isEqualTo(FOO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
op = new CheckstyleOperation().fromProject(new Project()).exclude(foo.toPath(), bar.toPath());
|
||||||
void propertiesFile() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("Path...")
|
||||||
var op = newCheckstyleOperation().propertiesFile(FOO);
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
assertThat(op.options().get("-p")).isEqualTo(FOO);
|
|
||||||
|
|
||||||
var fooPath = Path.of(FOO);
|
op = new CheckstyleOperation().fromProject(new Project()).excludePaths(List.of(foo.toPath(), bar.toPath()));
|
||||||
op = op.propertiesFile(fooPath);
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("List(Path...)")
|
||||||
assertThat(op.options().get("-p")).isEqualTo(fooPath.toFile().getAbsolutePath());
|
.contains(e + foo.getAbsolutePath()).contains(e + bar.getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void suppressionLineColumnNumber() {
|
void excludeRegex() {
|
||||||
var op = newCheckstyleOperation().suppressionLineColumnNumber(FOO + ':' + BAR);
|
var op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(FOO, BAR);
|
||||||
assertThat(op.options().get("-s")).isEqualTo(FOO + ':' + BAR);
|
var x = "-x ";
|
||||||
}
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).contains(x + FOO, x + BAR);
|
||||||
|
|
||||||
@Test
|
op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(List.of(FOO, BAR));
|
||||||
void tabWith() {
|
assertThat(String.join(" ", op.executeConstructProcessCommandList())).as("as list").contains(x + FOO, x + BAR);
|
||||||
var op = newCheckstyleOperation().tabWith(9);
|
}
|
||||||
assertThat(op.options().get("-w")).isEqualTo("9");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void tree() {
|
void execute() throws IOException, ExitStatusException, InterruptedException {
|
||||||
var op = newCheckstyleOperation().tree(true);
|
var tmpFile = File.createTempFile("checkstyle-google", ".txt");
|
||||||
assertThat(op.options().containsKey("-t")).as(ADD).isTrue();
|
tmpFile.deleteOnExit();
|
||||||
op = op.tree(false);
|
var op = new CheckstyleOperation()
|
||||||
assertThat(op.options().containsKey("-t")).as(REMOVE).isFalse();
|
.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
|
@Test
|
||||||
void treeWithComments() {
|
void executeConstructProcessCommandList() {
|
||||||
var op = newCheckstyleOperation().treeWithComments(true);
|
var op = new CheckstyleOperation().fromProject(new BaseProject())
|
||||||
assertThat(op.options().containsKey("-T")).as(ADD).isTrue();
|
.configurationFile("config/checkstyle.xml")
|
||||||
op = op.treeWithComments(false);
|
.branchMatchingXpath("xpath")
|
||||||
assertThat(op.options().containsKey("-T")).as(REMOVE).isFalse();
|
.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
|
@Test
|
||||||
void treeWithJavadoc() {
|
void executeIgnoredModules() {
|
||||||
var op = newCheckstyleOperation().treeWithJavadoc(true);
|
var op = new CheckstyleOperation().fromProject(new Project()).executeIgnoredModules(true);
|
||||||
assertThat(op.options().containsKey("-J")).as(ADD).isTrue();
|
assertThat(op.options().containsKey("-E")).as(ADD).isTrue();
|
||||||
op = op.treeWithJavadoc(false);
|
op = op.executeIgnoredModules(false);
|
||||||
assertThat(op.options().containsKey("-J")).as(REMOVE).isFalse();
|
assertThat(op.options().containsKey("-E")).as(REMOVE).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nested
|
@Test
|
||||||
@DisplayName("Source Dir Tests")
|
void executeNoProject() {
|
||||||
class SourceDirTests {
|
var op = new CheckstyleOperation();
|
||||||
private final File bar = new File(BAR);
|
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||||
private final File foo = new File(FOO);
|
}
|
||||||
private final CheckstyleOperation op = newCheckstyleOperation().sourceDir(FOO, BAR);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDirFromFileArray() {
|
void executeSunChecks() throws IOException {
|
||||||
op.sourceDir(foo, bar);
|
var tmpFile = File.createTempFile("checkstyle-sun", ".txt");
|
||||||
assertThat(op.sourceDir()).as("File...").hasSize(2).contains(foo, bar);
|
tmpFile.deleteOnExit();
|
||||||
op.sourceDir().clear();
|
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
|
@Test
|
||||||
void sourceDirFromFileList() {
|
void format() {
|
||||||
op.sourceDir(List.of(foo, bar));
|
var op = new CheckstyleOperation().fromProject(new Project()).format(OutputFormat.XML);
|
||||||
assertThat(op.sourceDir()).as("List(File...)").hasSize(2).contains(foo, bar);
|
assertThat(op.options().get("-f")).isEqualTo("xml");
|
||||||
op.sourceDir().clear();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDirFromPathArray() {
|
void generateXpathSuppression() {
|
||||||
op.sourceDir(foo.toPath(), bar.toPath());
|
var op = new CheckstyleOperation().fromProject(new Project()).generateXpathSuppression(true);
|
||||||
assertThat(op.sourceDir()).as("Path...").hasSize(2).contains(foo, bar);
|
assertThat(op.options().containsKey("-g")).as(ADD).isTrue();
|
||||||
op.sourceDir().clear();
|
op = op.generateXpathSuppression(false);
|
||||||
}
|
assertThat(op.options().containsKey("-g")).as(REMOVE).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDirFromPathList() {
|
void javadocTree() {
|
||||||
op.sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
|
var op = new CheckstyleOperation().fromProject(new Project()).javadocTree(true);
|
||||||
assertThat(op.sourceDir()).as("List(Path...)").hasSize(2).contains(foo, bar);
|
assertThat(op.options().containsKey("-j")).as(ADD).isTrue();
|
||||||
op.sourceDir().clear();
|
op = op.javadocTree(false);
|
||||||
}
|
assertThat(op.options().containsKey("-j")).as(REMOVE).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDirFromStringArray() {
|
void outputPath() {
|
||||||
op.sourceDir("foo", "bar");
|
var op = new CheckstyleOperation().fromProject(new Project()).outputPath(FOO);
|
||||||
assertThat(op.sourceDir()).as("String...").hasSize(2).contains(foo, bar);
|
assertThat(op.options().get("-o")).isEqualTo(FOO);
|
||||||
op.sourceDir().clear();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sourceDirFromStringList() {
|
void propertiesFile() {
|
||||||
op.sourceDirStrings(List.of(FOO, BAR));
|
var op = new CheckstyleOperation().fromProject(new Project()).propertiesFile(FOO);
|
||||||
assertThat(op.sourceDir()).as("List(String...)").hasSize(2).contains(foo, bar);
|
assertThat(op.options().get("-p")).isEqualTo(FOO);
|
||||||
op.sourceDir().clear();
|
|
||||||
}
|
var fooPath = Path.of(FOO);
|
||||||
}
|
op = op.propertiesFile(fooPath);
|
||||||
|
assertThat(op.options().get("-p")).isEqualTo(fooPath.toFile().getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sourceDir() {
|
||||||
|
var foo = new File(FOO);
|
||||||
|
var bar = new File(BAR);
|
||||||
|
|
||||||
|
var op = new CheckstyleOperation().fromProject(new Project()).sourceDir(FOO, BAR);
|
||||||
|
assertThat(op.sourceDir()).as("String...").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();
|
||||||
|
|
||||||
|
op = op.sourceDir(foo, bar);
|
||||||
|
assertThat(op.sourceDir()).as("File...").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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
-E
|
-E
|
||||||
-f
|
-f
|
||||||
-g
|
-g
|
||||||
-G
|
|
||||||
-j
|
-j
|
||||||
-J
|
-J
|
||||||
-o
|
-o
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue