diff --git a/.idea/copyright/Apache_License.xml b/.idea/copyright/Apache_License.xml index ade80da..4446c15 100644 --- a/.idea/copyright/Apache_License.xml +++ b/.idea/copyright/Apache_License.xml @@ -1,6 +1,6 @@ - - + \ No newline at end of file diff --git a/README.md b/README.md index c223a6e..49b1a8b 100644 --- a/README.md +++ b/README.md @@ -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))); ``` diff --git a/checkcliargs.sh b/checkcliargs.sh index 1e271db..867c768 100755 --- a/checkcliargs.sh +++ b/checkcliargs.sh @@ -7,6 +7,10 @@ TMPOLD=/tmp/checkcliargs-old java -cp "lib/test/*" $MAIN --help >$TMPNEW java -cp "examples/lib/test/*" $MAIN --help >$TMPOLD -diff $TMPOLD $TMPNEW +if [ "$1" == "-v" ]; then + code --wait --diff $TMPOLD $TMPNEW +else + diff $TMPOLD $TMPNEW +fi rm -rf $TMPNEW $TMPOLD diff --git a/examples/lib/bld/bld-wrapper.properties b/examples/lib/bld/bld-wrapper.properties index b3d6546..eede168 100644 --- a/examples/lib/bld/bld-wrapper.properties +++ b/examples/lib/bld/bld-wrapper.properties @@ -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= diff --git a/examples/src/bld/java/com/example/ExamplesBuild.java b/examples/src/bld/java/com/example/ExamplesBuild.java index 8900bce..52a2409 100644 --- a/examples/src/bld/java/com/example/ExamplesBuild.java +++ b/examples/src/bld/java/com/example/ExamplesBuild.java @@ -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"); } diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index 294731d..13d377b 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -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= diff --git a/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java b/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java index 75dc620..9b7c7d6 100644 --- a/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java +++ b/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java @@ -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))); diff --git a/src/main/java/rife/bld/extension/CheckstyleFormatOption.java b/src/main/java/rife/bld/extension/CheckstyleFormatOption.java new file mode 100644 index 0000000..09ad8ac --- /dev/null +++ b/src/main/java/rife/bld/extension/CheckstyleFormatOption.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/rife/bld/extension/CheckstyleOperation.java b/src/main/java/rife/bld/extension/CheckstyleOperation.java index 681e992..7e07690 100644 --- a/src/main/java/rife/bld/extension/CheckstyleOperation.java +++ b/src/main/java/rife/bld/extension/CheckstyleOperation.java @@ -32,11 +32,12 @@ import java.util.logging.Logger; */ public class CheckstyleOperation extends AbstractProcessOperation { private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName()); + protected final List exclude = new ArrayList<>(); + protected final List excludeRegex = new ArrayList<>(); /** * The command line options. */ protected final Map options = new ConcurrentHashMap<>(); - /** * The source files(s) or folder(s). */ @@ -97,7 +98,7 @@ public class CheckstyleOperation extends AbstractProcessOperation 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 regex) { + for (var r : regex) { + if (isNotBlank(r)) { + excludeRegex.add(r); + } + } + return this; } @@ -162,6 +184,22 @@ public class CheckstyleOperation extends AbstractProcessOperation + * 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 AbstractProcessOperationonly Javadoc comment content - * 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 - * ATTENTION: 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 + * 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. + *

* Default value is {@code 8}. * * @param length the length @@ -329,8 +372,8 @@ public class CheckstyleOperation extends AbstractProcessOperation