From 71253717bf427a8a84d4c47e257959f4527aa75e Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 31 Jan 2025 14:00:22 -0800 Subject: [PATCH 1/5] Bumped artifact and pages actions to the latest versions --- .github/workflows/pages.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index bf43624..508f6a5 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -47,11 +47,11 @@ jobs: uses: actions/configure-pages@v3 - name: Upload artifact - uses: actions/upload-pages-artifact@v1 + uses: actions/upload-pages-artifact@v3 with: # Upload generated Javadocs repository path: "build/javadoc/" - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 + uses: actions/deploy-pages@v4 From bc60dcbcf856ac73eb18848323a11795055578f8 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 31 Jan 2025 14:00:57 -0800 Subject: [PATCH 2/5] Bumped AssertJ to version 3.27.3 --- src/bld/java/rife/bld/extension/PmdOperationBuild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld/java/rife/bld/extension/PmdOperationBuild.java b/src/bld/java/rife/bld/extension/PmdOperationBuild.java index eb43550..d7c18ec 100644 --- a/src/bld/java/rife/bld/extension/PmdOperationBuild.java +++ b/src/bld/java/rife/bld/extension/PmdOperationBuild.java @@ -49,7 +49,7 @@ public class PmdOperationBuild extends Project { scope(test) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 4))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 4))) - .include(dependency("org.assertj", "assertj-core", version(3, 27, 2))); + .include(dependency("org.assertj", "assertj-core", version(3, 27, 3))); javadocOperation() .javadocOptions() From a1d0b30968ce16caae100f4c67300e08adbff1f8 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 31 Jan 2025 14:03:39 -0800 Subject: [PATCH 3/5] Added missing prepend classpath and excludes options --- .../java/rife/bld/extension/PmdOperation.java | 127 +++++++++++++++--- .../rife/bld/extension/PmdOperationTest.java | 24 ++++ 2 files changed, 136 insertions(+), 15 deletions(-) diff --git a/src/main/java/rife/bld/extension/PmdOperation.java b/src/main/java/rife/bld/extension/PmdOperation.java index 0e5ef6f..aa0a61d 100644 --- a/src/main/java/rife/bld/extension/PmdOperation.java +++ b/src/main/java/rife/bld/extension/PmdOperation.java @@ -49,6 +49,10 @@ public class PmdOperation extends AbstractOperation { public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml"; private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName()); private static final String PMD_DIR = "pmd"; + /** + * The list of paths to exclude. + */ + private final List excludes_ = new ArrayList<>(); /** * The input paths (source) list. */ @@ -101,6 +105,10 @@ public class PmdOperation extends AbstractOperation { * The default language version(s). */ private Collection languageVersions_ = new ArrayList<>(); + /** + * The classpath to prepend. + */ + private String prependClasspath_; /** * The project reference. */ @@ -272,7 +280,6 @@ public class PmdOperation extends AbstractOperation { return cache(Path.of(cache)); } - /** * Sets the default language version to be used for all input files. * @@ -314,6 +321,37 @@ public class PmdOperation extends AbstractOperation { return this; } + /** + * Adds paths to exclude from the analysis. + * + * @param excludes one or more paths to exclude + * @return this operation + */ + public PmdOperation excludes(Path... excludes) { + excludes_.addAll(List.of(excludes)); + return this; + } + + /** + * Adds paths to exclude from the analysis. + * + * @param excludes paths to exclude + * @return this operation + */ + public PmdOperation excludes(Collection excludes) { + excludes_.addAll(excludes); + return this; + } + + /** + * Returns the paths to exclude from the analysis. + * + * @return the exclude paths + */ + public List excludes() { + return excludes_; + } + /** * Performs the PMD code analysis operation. */ @@ -456,8 +494,17 @@ public class PmdOperation extends AbstractOperation { * @return this operation */ public PMDConfiguration initConfiguration(String commandName) { - PMDConfiguration config = new PMDConfiguration(); + var config = new PMDConfiguration(); + // addRelativizeRoots + config.addRelativizeRoots(relativizeRoots_.stream().toList()); + + // prependAuxClasspath + if (prependClasspath_ != null) { + config.prependAuxClasspath(prependClasspath_); + } + + // setAnalysisCacheLocation if (cache_ == null && project_ != null && incrementalAnalysis_) { config.setAnalysisCacheLocation( Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath()); @@ -465,38 +512,50 @@ public class PmdOperation extends AbstractOperation { config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath()); } - config.setFailOnError(failOnError_); - config.setFailOnViolation(failOnViolation_); - + // setDefaultLanguageVersions if (languageVersions_ != null) { config.setDefaultLanguageVersions(languageVersions_.stream().toList()); } + // setExcludes + if (!excludes_.isEmpty()) { + config.setExcludes(excludes_); + } + + // setFailOnError + config.setFailOnError(failOnError_); + // setFailOnViolation + config.setFailOnViolation(failOnViolation_); + + // setForceLanguageVersion if (forcedLanguageVersion_ != null) { config.setForceLanguageVersion(forcedLanguageVersion_); } + // setIgnoreFilePath if (ignoreFile_ != null) { config.setIgnoreFilePath(ignoreFile_); } + // setIgnoreIncrementalAnalysis config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_); + // setInputPathList if (inputPaths_.isEmpty()) { throw new IllegalArgumentException(commandName + ": InputPaths required."); } else { config.setInputPathList(inputPaths_.stream().toList()); } - if (reportProperties_ != null) { - config.setReportProperties(reportProperties_); - } + // setInputUri if (inputUri_ != null) { config.setInputUri(inputUri_); } + // setMinimumPriority config.setMinimumPriority(rulePriority_); + // setReportFile if (project_ != null) { config.setReportFile(Objects.requireNonNullElseGet(reportFile_, () -> Paths.get(project_.buildDirectory().getPath(), @@ -505,12 +564,25 @@ public class PmdOperation extends AbstractOperation { config.setReportFile(reportFile_); } - config.addRelativizeRoots(relativizeRoots_.stream().toList()); + // setReportFormat config.setReportFormat(reportFormat_); + + // setReportProperties + if (reportProperties_ != null) { + config.setReportProperties(reportProperties_); + } + + // setRuleSets config.setRuleSets(ruleSets_.stream().toList()); + + // setShowSuppressedViolations config.setShowSuppressedViolations(showSuppressed_); + // setSourceEncoding config.setSourceEncoding(encoding_); + // setSuppressMarker config.setSuppressMarker(suppressedMarker_); + + // setThreads config.setThreads(threads_); return config; @@ -710,11 +782,36 @@ public class PmdOperation extends AbstractOperation { return numViolations; } + /** + * Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader + * is currently configured, the ClassLoader used to load the PMDConfiguration class will be used as the parent + * ClassLoader of the created ClassLoader. + *

+ * If the classpath String looks like a URL to a file (i.e. starts with {@code file://}) the file will be read with + * each line representing an entry on the classpath. + * + * @param classpath one or more classpath + * @return this operation + */ + public PmdOperation prependAuxClasspath(String... classpath) { + prependClasspath_ = String.join(File.pathSeparator, classpath); + return this; + } + + /** + * Returns the prepended classpath. + * + * @return the classpath + */ + public String prependAuxClasspath() { + return prependClasspath_; + } + /** * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot one or more relative root paths - * @return this operations + * @return this operation * @see #relativizeRoots(Collection) */ public PmdOperation relativizeRoots(Path... relativeRoot) { @@ -725,7 +822,7 @@ public class PmdOperation extends AbstractOperation { * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot one or more relative root paths - * @return this operations + * @return this operation * @see #relativizeRootsFiles(Collection) */ public PmdOperation relativizeRoots(File... relativeRoot) { @@ -736,7 +833,7 @@ public class PmdOperation extends AbstractOperation { * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot one or more relative root paths - * @return this operations + * @return this operation * @see #relativizeRootsStrings(Collection) */ public PmdOperation relativizeRoots(String... relativeRoot) { @@ -747,7 +844,7 @@ public class PmdOperation extends AbstractOperation { * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot a collection of relative root paths - * @return this operations + * @return this operation * @see #relativizeRoots(Path...) */ public PmdOperation relativizeRoots(Collection relativeRoot) { @@ -768,7 +865,7 @@ public class PmdOperation extends AbstractOperation { * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot a collection of relative root paths - * @return this operations + * @return this operation * @see #relativizeRoots(File...) */ public PmdOperation relativizeRootsFiles(Collection relativeRoot) { @@ -779,7 +876,7 @@ public class PmdOperation extends AbstractOperation { * Adds several paths to shorten paths that are output in the report. * * @param relativeRoot a collection of relative root paths - * @return this operations + * @return this operation * @see #relativizeRoots(String...) */ public PmdOperation relativizeRootsStrings(Collection relativeRoot) { diff --git a/src/test/java/rife/bld/extension/PmdOperationTest.java b/src/test/java/rife/bld/extension/PmdOperationTest.java index 08df70f..48545e5 100644 --- a/src/test/java/rife/bld/extension/PmdOperationTest.java +++ b/src/test/java/rife/bld/extension/PmdOperationTest.java @@ -166,6 +166,24 @@ class PmdOperationTest { assertThat(config.getSourceEncoding()).as("ISO_8859").isEqualTo(StandardCharsets.ISO_8859_1); } + @Test + void testExcludes() { + var foo = Path.of("foo/bar"); + var bar = Path.of("bar/foo"); + var foz = Path.of("foz/baz"); + var baz = Path.of("baz/foz"); + + var excludes = List.of(foo, bar); + var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(excludes); + var config = pmd.initConfiguration(COMMAND_NAME); + assertThat(config.getExcludes()).containsExactly(excludes.toArray(new Path[0])); + + pmd = pmd.excludes(baz, foz); + assertThat(pmd.excludes()).hasSize(4); + config = pmd.initConfiguration(COMMAND_NAME); + assertThat(config.getExcludes()).hasSize(4).contains(bar, foz); + } + @Test void testExecute() throws ExitStatusException { var pmd = new PmdOperation().fromProject(new BaseProject()); @@ -368,6 +386,12 @@ class PmdOperationTest { assertThat(pmd).isEqualTo(0); } + @Test + void testPrependAuxClasspath() { + var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).prependAuxClasspath("foo", "bar"); + assertThat(pmd.prependAuxClasspath()).isEqualTo("foo" + File.pathSeparator + "bar"); + } + @Test void testPriority() throws ExitStatusException { var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH); From e7fac3130b78dbb7d1a710bda9c103678a9f142c Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 31 Jan 2025 14:04:08 -0800 Subject: [PATCH 4/5] Bumped PMD to version 7.10.0 --- src/bld/java/rife/bld/extension/PmdOperationBuild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld/java/rife/bld/extension/PmdOperationBuild.java b/src/bld/java/rife/bld/extension/PmdOperationBuild.java index d7c18ec..bb7319c 100644 --- a/src/bld/java/rife/bld/extension/PmdOperationBuild.java +++ b/src/bld/java/rife/bld/extension/PmdOperationBuild.java @@ -40,7 +40,7 @@ public class PmdOperationBuild extends Project { repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, RIFE2_RELEASES, RIFE2_SNAPSHOTS); - var pmd = version(7, 9, 0); + var pmd = version(7, 10, 0); scope(compile) .include(dependency("com.uwyn.rife2", "bld", version(2, 2, 0))) .include(dependency("net.sourceforge.pmd", "pmd-java", pmd)); From 25bce33323f205f7ab6030ca1931f995c9f4f0b5 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 31 Jan 2025 14:07:34 -0800 Subject: [PATCH 5/5] Version 1.1.11 --- src/bld/java/rife/bld/extension/PmdOperationBuild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bld/java/rife/bld/extension/PmdOperationBuild.java b/src/bld/java/rife/bld/extension/PmdOperationBuild.java index bb7319c..616d5d5 100644 --- a/src/bld/java/rife/bld/extension/PmdOperationBuild.java +++ b/src/bld/java/rife/bld/extension/PmdOperationBuild.java @@ -31,7 +31,7 @@ public class PmdOperationBuild extends Project { public PmdOperationBuild() { pkg = "rife.bld.extension"; name = "bld-pmd"; - version = version(1, 1, 10); + version = version(1, 1, 11); javaRelease = 17;