From da0c2e17d73be3092b2bcba05b531c554fbb7d29 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:36:23 -0700 Subject: [PATCH 01/10] Bumped PMD extension to version 0.9.8 --- lib/bld/bld-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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= From 42dd8704081db6d509fddb76b765334856038daa Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:39:44 -0700 Subject: [PATCH 02/10] Fixed copyright template --- .idea/copyright/Apache_License.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5d24b4060a24ea288a42246b570e86ba56c25c49 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:46:25 -0700 Subject: [PATCH 03/10] Fixed exclude options to support multiple values --- .../bld/extension/CheckstyleOperation.java | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/rife/bld/extension/CheckstyleOperation.java b/src/main/java/rife/bld/extension/CheckstyleOperation.java index 681e992..ff04d8b 100644 --- a/src/main/java/rife/bld/extension/CheckstyleOperation.java +++ b/src/main/java/rife/bld/extension/CheckstyleOperation.java @@ -32,6 +32,8 @@ 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. */ @@ -97,7 +99,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 +181,20 @@ public class CheckstyleOperation extends AbstractProcessOperation Date: Mon, 29 Apr 2024 03:47:10 -0700 Subject: [PATCH 04/10] Added visual diff argument --- checkcliargs.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From 3f0c0ee51bd5e58a5281fe97ee97fd5459d2883a Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:48:37 -0700 Subject: [PATCH 05/10] Added output format options enum --- .../bld/extension/CheckstyleFormatOption.java | 32 +++++++++++++++++++ .../bld/extension/CheckstyleOperation.java | 15 +++++---- 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 src/main/java/rife/bld/extension/CheckstyleFormatOption.java 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 ff04d8b..4434ec1 100644 --- a/src/main/java/rife/bld/extension/CheckstyleOperation.java +++ b/src/main/java/rife/bld/extension/CheckstyleOperation.java @@ -225,16 +225,17 @@ 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; } From a7674039df6514c20b2c3527e5239010077da52a Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:51:23 -0700 Subject: [PATCH 06/10] Updated methods name/description to better match Checkstyle's help --- .../bld/extension/CheckstyleOperation.java | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/src/main/java/rife/bld/extension/CheckstyleOperation.java b/src/main/java/rife/bld/extension/CheckstyleOperation.java index 4434ec1..7e07690 100644 --- a/src/main/java/rife/bld/extension/CheckstyleOperation.java +++ b/src/main/java/rife/bld/extension/CheckstyleOperation.java @@ -38,7 +38,6 @@ public class CheckstyleOperation extends AbstractProcessOperation options = new ConcurrentHashMap<>(); - /** * The source files(s) or folder(s). */ @@ -133,8 +132,12 @@ 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 @@ -282,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); } @@ -351,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 @@ -363,8 +372,8 @@ public class CheckstyleOperation extends AbstractProcessOperation Date: Mon, 29 Apr 2024 03:54:10 -0700 Subject: [PATCH 07/10] Added/Updated tests --- .../extension/CheckstyleOperationTest.java | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/test/java/rife/bld/extension/CheckstyleOperationTest.java b/src/test/java/rife/bld/extension/CheckstyleOperationTest.java index 6bd2233..9273bcd 100644 --- a/src/test/java/rife/bld/extension/CheckstyleOperationTest.java +++ b/src/test/java/rife/bld/extension/CheckstyleOperationTest.java @@ -58,18 +58,23 @@ 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); + 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); + 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 +83,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 +124,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 +152,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 +171,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); From a19e4e8ff3ce34cb21b146e1d932d9d157e21c9c Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:55:59 -0700 Subject: [PATCH 08/10] Bumped Checkstyle version to 10.16.0 --- README.md | 2 +- examples/src/bld/java/com/example/ExamplesBuild.java | 4 +++- src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) 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/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/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java b/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java index 75dc620..8f45d3e 100644 --- a/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java +++ b/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java @@ -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))); From b7fb8d9728aef41150a805196cb161b54598b8ac Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 03:56:49 -0700 Subject: [PATCH 09/10] Version 1.0.0 --- examples/lib/bld/bld-wrapper.properties | 2 +- src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java b/src/bld/java/rife/bld/extension/CheckstyleOperationBuild.java index 8f45d3e..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; From d7d9cdf98cbb0b55e232bfb3f863f95725fbb43f Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Mon, 29 Apr 2024 04:05:22 -0700 Subject: [PATCH 10/10] Avoid duplicate literals (PMD) --- .../rife/bld/extension/CheckstyleOperationTest.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/test/java/rife/bld/extension/CheckstyleOperationTest.java b/src/test/java/rife/bld/extension/CheckstyleOperationTest.java index 9273bcd..039744a 100644 --- a/src/test/java/rife/bld/extension/CheckstyleOperationTest.java +++ b/src/test/java/rife/bld/extension/CheckstyleOperationTest.java @@ -59,19 +59,21 @@ class CheckstyleOperationTest { @Test void exclude() { var op = new CheckstyleOperation().fromProject(new Project()).exclude(FOO, BAR); - assertThat(op.executeConstructProcessCommandList()).contains("-e " + FOO, "-e " + 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); + assertThat(op.executeConstructProcessCommandList()).as("as list").contains(e + FOO, e + BAR); } @Test void excludeRegex() { var op = new CheckstyleOperation().fromProject(new Project()).excludeRegex(FOO, BAR); - assertThat(op.executeConstructProcessCommandList()).contains("-x " + FOO, "-x " + 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); + assertThat(op.executeConstructProcessCommandList()).as("as list").contains(x + FOO, x + BAR); }