Compare commits
10 commits
2e3798dd72
...
d7d9cdf98c
Author | SHA1 | Date | |
---|---|---|---|
d7d9cdf98c | |||
b7fb8d9728 | |||
a19e4e8ff3 | |||
c219852e85 | |||
a7674039df | |||
3f0c0ee51b | |||
0c0222800b | |||
5d24b4060a | |||
42dd870408 | |||
da0c2e17d7 |
10 changed files with 165 additions and 79 deletions
2
.idea/copyright/Apache_License.xml
generated
2
.idea/copyright/Apache_License.xml
generated
|
@ -1,6 +1,6 @@
|
|||
<component name="CopyrightManager">
|
||||
<copyright>
|
||||
<option name="notice" value="Copyright 2023-Copyright &#36;today.yearamp;#36;today.year the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
||||
<option name="notice" value="Copyright 2023-&#36;today.year the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." />
|
||||
<option name="myName" value="Apache License" />
|
||||
</copyright>
|
||||
</component>
|
|
@ -37,5 +37,5 @@ not provided by the extension. For example:
|
|||
|
||||
```java
|
||||
repositories = List.of(MAVEN_CENTRAL);
|
||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 15, 0)));
|
||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 16, 0)));
|
||||
```
|
||||
|
|
|
@ -7,6 +7,10 @@ TMPOLD=/tmp/checkcliargs-old
|
|||
java -cp "lib/test/*" $MAIN --help >$TMPNEW
|
||||
java -cp "examples/lib/test/*" $MAIN --help >$TMPOLD
|
||||
|
||||
if [ "$1" == "-v" ]; then
|
||||
code --wait --diff $TMPOLD $TMPNEW
|
||||
else
|
||||
diff $TMPOLD $TMPNEW
|
||||
fi
|
||||
|
||||
rm -rf $TMPNEW $TMPOLD
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.extensions=com.uwyn.rife2:bld-checkstyle:0.9.6
|
||||
bld.extensions=com.uwyn.rife2:bld-checkstyle:1.0.0
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.downloadLocation=
|
||||
bld.sourceDirectories=
|
||||
|
|
|
@ -16,12 +16,14 @@ public class ExamplesBuild extends BaseProject {
|
|||
mainClass = "com.example.ExamplesMain";
|
||||
version = version(0, 1, 0);
|
||||
|
||||
javaRelease = 17;
|
||||
|
||||
autoDownloadPurge = true;
|
||||
downloadSources = true;
|
||||
|
||||
repositories = List.of(MAVEN_CENTRAL);
|
||||
|
||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 15, 0)));
|
||||
scope(test).include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 16, 0)));
|
||||
|
||||
testOperation().mainClass("com.example.ExamplesTest");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.8
|
||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.3
|
||||
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.9
|
||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.5
|
||||
bld.repositories=MAVEN_CENTRAL,MAVEN_LOCAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.downloadLocation=
|
||||
bld.sourceDirectories=
|
||||
|
|
|
@ -35,7 +35,7 @@ public class CheckstyleOperationBuild extends Project {
|
|||
public CheckstyleOperationBuild() {
|
||||
pkg = "rife.bld.extension";
|
||||
name = "CheckstyleOperation";
|
||||
version = version(0, 9, 6);
|
||||
version = version(1, 0, 0);
|
||||
|
||||
javaRelease = 17;
|
||||
downloadSources = true;
|
||||
|
@ -45,7 +45,7 @@ public class CheckstyleOperationBuild extends Project {
|
|||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "bld", version(1, 9, 0)));
|
||||
scope(test)
|
||||
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 15, 0)))
|
||||
.include(dependency("com.puppycrawl.tools", "checkstyle", version(10, 16, 0)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
|
||||
.include(dependency("org.assertj", "assertj-core", version(3, 25, 3)));
|
||||
|
|
32
src/main/java/rife/bld/extension/CheckstyleFormatOption.java
Normal file
32
src/main/java/rife/bld/extension/CheckstyleFormatOption.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2023-2004 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package rife.bld.extension;
|
||||
|
||||
/**
|
||||
* The Checkstyle output format for XML, sarif and default (plaib) logger.
|
||||
*/
|
||||
public enum CheckstyleFormatOption {
|
||||
XML("xml"),
|
||||
SARIF("sarif"),
|
||||
PLAIN("plain");
|
||||
|
||||
public final String label;
|
||||
|
||||
CheckstyleFormatOption(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
}
|
|
@ -32,11 +32,12 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation> {
|
||||
private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName());
|
||||
protected final List<String> exclude = new ArrayList<>();
|
||||
protected final List<String> excludeRegex = new ArrayList<>();
|
||||
/**
|
||||
* The command line options.
|
||||
*/
|
||||
protected final Map<String, String> options = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* The source files(s) or folder(s).
|
||||
*/
|
||||
|
@ -97,7 +98,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
public CheckstyleOperation exclude(String... path) {
|
||||
for (var p : path) {
|
||||
if (isNotBlank(p)) {
|
||||
options.put("-e", p);
|
||||
exclude.add(p);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
|
@ -107,29 +108,50 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
* Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current
|
||||
* path. Multiple excludes are allowed.
|
||||
*
|
||||
* @param paths the list of paths
|
||||
* @param paths the paths
|
||||
* @return the checkstyle operation
|
||||
* @see #exclude(String...)
|
||||
*/
|
||||
public CheckstyleOperation exclude(Collection<String> paths) {
|
||||
for (var p : paths) {
|
||||
if (isNotBlank(p)) {
|
||||
options.put("-e", p);
|
||||
exclude.add(p);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file pattern to exclude from CheckStyle. Multiple excludes are allowed.
|
||||
* Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
|
||||
*
|
||||
* @param pattern the pattern
|
||||
* @param regex the pattern to exclude
|
||||
* @return the checkstyle operation
|
||||
* @see #excludeRegex(Collection)
|
||||
*/
|
||||
public CheckstyleOperation excludedPathPattern(String pattern) {
|
||||
if (isNotBlank(pattern)) {
|
||||
options.put("-x", pattern);
|
||||
public CheckstyleOperation excludeRegex(String... regex) {
|
||||
for (var r : regex) {
|
||||
if (isNotBlank(r)) {
|
||||
excludeRegex.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
|
||||
*
|
||||
* @param regex the patterns to exclude
|
||||
* @return the checkstyle operation
|
||||
* @see #excludeRegex(String...)
|
||||
*/
|
||||
public CheckstyleOperation excludeRegex(Collection<String> regex) {
|
||||
for (var r : regex) {
|
||||
if (isNotBlank(r)) {
|
||||
excludeRegex.add(r);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -162,6 +184,22 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
});
|
||||
|
||||
if (!exclude.isEmpty()) {
|
||||
for (var e : exclude) {
|
||||
if (isNotBlank(e)) {
|
||||
args.add("-e " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!excludeRegex.isEmpty()) {
|
||||
for (var e : excludeRegex) {
|
||||
if (isNotBlank(e)) {
|
||||
args.add("-x " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
args.addAll(sourceDirs);
|
||||
|
||||
return args;
|
||||
|
@ -192,16 +230,17 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Specifies the output format. Valid values: {@code xml}, {@code sarif}, {@code plain} for the XML, sarif and
|
||||
* default logger respectively. Defaults to {@code plain}.
|
||||
* Specifies the output format. Valid values: {@link CheckstyleFormatOption#XML},
|
||||
* {@link CheckstyleFormatOption#SARIF}, {@link CheckstyleFormatOption#PLAIN} for the XML, sarif and default logger
|
||||
* respectively.
|
||||
* <p>
|
||||
* Defaults to {@link CheckstyleFormatOption#PLAIN}.
|
||||
*
|
||||
* @param format the format
|
||||
* @param format the output format
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation format(String format) {
|
||||
if (isNotBlank(format)) {
|
||||
options.put("-f", format);
|
||||
}
|
||||
public CheckstyleOperation format(CheckstyleFormatOption format) {
|
||||
options.put("-f", format.label.toLowerCase());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -209,7 +248,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
* 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.
|
||||
* Used only with the {@link #configurationFile(String) configurationFile} option. Output location can be specified
|
||||
* with the {@link #output(String) output} option.
|
||||
* with the {@link #outputPath(String) output} option.
|
||||
*
|
||||
* @param xPathSuppression {@code true} or {@code false}
|
||||
* @return the checkstyle operation
|
||||
|
@ -231,9 +270,9 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints Parse Tree of the Javadoc comment. The file have to contain <b>only Javadoc comment content</b>
|
||||
* without including '/**' and '*/' at the beginning and at the end respectively. The option cannot
|
||||
* be used other options and requires exactly one file to run on to be specified.
|
||||
* This option is used to print the Parse Tree of the Javadoc comment. The file has to contain only Javadoc comment
|
||||
* content excluding '/**' and '*/' at the beginning and at the end respectively. It can only be used on a
|
||||
* single file and cannot be combined with other options.
|
||||
*
|
||||
* @param isTree {@code true} or {@code false}
|
||||
* @return the checkstyle operation
|
||||
|
@ -248,31 +287,14 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* used with other options and requires exactly one file to run on to be specified.
|
||||
* Sets the output file.
|
||||
* <p>
|
||||
* <b>ATTENTION</b>: generated result will have few queries, joined by pipe(|). Together they will match all AST nodes
|
||||
* on specified line and column. You need to choose only one and recheck that it works. Usage of all of them is also
|
||||
* ok, but might result in undesirable matching and suppress other issues.
|
||||
* Defaults to stdout.
|
||||
*
|
||||
* @param lineColumn the line column
|
||||
* @param file the output file
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation lineColumn(String lineColumn) {
|
||||
if (isNotBlank(lineColumn)) {
|
||||
options.put("-s", lineColumn);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output file. Defaults to stdout.
|
||||
*
|
||||
* @param file the file
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation output(String file) {
|
||||
public CheckstyleOperation outputPath(String file) {
|
||||
if (isNotBlank(file)) {
|
||||
options.put("-o", file);
|
||||
}
|
||||
|
@ -317,7 +339,28 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the tab character. Used only with the {@link #lineColumn(String) lineColum} option.
|
||||
* 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
|
||||
* used with other options and requires exactly one file to run on to be specified.
|
||||
* <p>
|
||||
* Note that the generated result will have few queries, joined by pipe({@code |}). Together they will match all
|
||||
* AST nodes on specified line and column. You need to choose only one and recheck that it works. Usage of all of
|
||||
* them is also ok, but might result in undesirable matching and suppress other issues.
|
||||
*
|
||||
* @param lineColumnNumber the line column number
|
||||
* @return the checkstyle operation
|
||||
*/
|
||||
public CheckstyleOperation suppressionLineColumnNumber(String lineColumnNumber) {
|
||||
if (isNotBlank(lineColumnNumber)) {
|
||||
options.put("-s", lineColumnNumber);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the tab character. Used only with the
|
||||
* {@link #suppressionLineColumnNumber(String) suppressionLineColumnNumber} option.
|
||||
* <p>
|
||||
* Default value is {@code 8}.
|
||||
*
|
||||
* @param length the length
|
||||
|
@ -329,8 +372,8 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints Abstract Syntax Tree(AST) of the checked file. The option cannot be used other options and requires
|
||||
* exactly one file to run on to be specified.
|
||||
* This option is used to display the Abstract Syntax Tree (AST) without any comments of the specified file. It can
|
||||
* only be used on a single file and cannot be combined with other options.
|
||||
*
|
||||
* @param isTree {@code true} or {@code false}
|
||||
* @return the checkstyle operation
|
||||
|
@ -345,8 +388,8 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints Abstract Syntax Tree(AST) with comment nodes of the checked file. The option cannot be used with other
|
||||
* options and requires exactly one file to run on to be specified.
|
||||
* This option is used to display the Abstract Syntax Tree (AST) with comment nodes excluding Javadoc of the
|
||||
* specified file. It can only be used on a single file and cannot be combined with other options.
|
||||
*
|
||||
* @param isTree {@code true} or {@code false}
|
||||
* @return the checkstyle operation
|
||||
|
@ -361,10 +404,8 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
|
|||
}
|
||||
|
||||
/**
|
||||
* Prints Abstract Syntax Tree(AST) with Javadoc nodes and comment nodes of the checked file. Attention that line
|
||||
* number and columns will not be the same as it is a file due to the fact that each javadoc comment is parsed
|
||||
* separately from java file. The option cannot be used with other options and requires exactly one file to run on
|
||||
* to be specified.
|
||||
* This option is used to display the Abstract Syntax Tree (AST) with Javadoc nodes of the specified file. It can
|
||||
* only be used on a single file and cannot be combined with other options.
|
||||
*
|
||||
* @param isTree {@code true} or {@code false}
|
||||
* @return the checkstyle operation
|
||||
|
|
|
@ -58,18 +58,25 @@ class CheckstyleOperationTest {
|
|||
|
||||
@Test
|
||||
void exclude() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO);
|
||||
assertThat(op.options.get("-e")).isEqualTo(FOO);
|
||||
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(FOO));
|
||||
assertThat(op.options.get("-e")).as("as list").isEqualTo(FOO);
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO, BAR);
|
||||
var e = "-e ";
|
||||
assertThat(op.executeConstructProcessCommandList()).contains(e + FOO, e + BAR);
|
||||
|
||||
op = new CheckstyleOperation().fromProject(new Project()).exclude(List.of(FOO, BAR));
|
||||
assertThat(op.executeConstructProcessCommandList()).as("as list").contains(e + FOO, e + BAR);
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludedPathPattern() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).excludedPathPattern(FOO);
|
||||
assertThat(op.options.get("-x")).isEqualTo(FOO);
|
||||
void excludeRegex() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(FOO, BAR);
|
||||
var x = "-x ";
|
||||
assertThat(op.executeConstructProcessCommandList()).contains(x + FOO, x + BAR);
|
||||
|
||||
op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(List.of(FOO, BAR));
|
||||
assertThat(op.executeConstructProcessCommandList()).as("as list").contains(x + FOO, x + BAR);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void execute() throws IOException, ExitStatusException, InterruptedException {
|
||||
var tmpFile = File.createTempFile("checkstyle-google", ".txt");
|
||||
|
@ -78,7 +85,7 @@ class CheckstyleOperationTest {
|
|||
.fromProject(new WebProject())
|
||||
.sourceDir("src/main/java", "src/test/java")
|
||||
.configurationFile("src/test/resources/google_checks.xml")
|
||||
.output(tmpFile.getAbsolutePath());
|
||||
.outputPath(tmpFile.getAbsolutePath());
|
||||
op.execute();
|
||||
assertThat(tmpFile).exists();
|
||||
}
|
||||
|
@ -119,15 +126,15 @@ class CheckstyleOperationTest {
|
|||
.fromProject(new WebProject())
|
||||
.sourceDir(List.of("src/main/java", "src/test/java"))
|
||||
.configurationFile("src/test/resources/sun_checks.xml")
|
||||
.output(tmpFile.getAbsolutePath());
|
||||
.outputPath(tmpFile.getAbsolutePath());
|
||||
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
|
||||
assertThat(tmpFile).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
void format() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).format(FOO);
|
||||
assertThat(op.options.get("-f")).isEqualTo(FOO);
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).format(CheckstyleFormatOption.XML);
|
||||
assertThat(op.options.get("-f")).isEqualTo("xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -147,14 +154,8 @@ class CheckstyleOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void lineColumn() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).lineColumn(FOO);
|
||||
assertThat(op.options.get("-s")).isEqualTo(FOO);
|
||||
}
|
||||
|
||||
@Test
|
||||
void output() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).output(FOO);
|
||||
void outputPath() {
|
||||
var op = new CheckstyleOperation().fromProject(new Project()).outputPath(FOO);
|
||||
assertThat(op.options.get("-o")).isEqualTo(FOO);
|
||||
}
|
||||
|
||||
|
@ -172,6 +173,12 @@ class CheckstyleOperationTest {
|
|||
assertThat(op.sourceDirs).as("foo, bar").hasSize(2).contains(FOO).contains(BAR);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue