From c7204a56eee39355e4e03185425d59763acbe77b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 10 Nov 2019 21:13:43 +0100 Subject: [PATCH 1/6] Fix build under Windows --- .../src/test/java/net/sourceforge/pmd/it/PMDExecutor.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java index 05bd0a9755..2ea7115844 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; @@ -36,7 +37,10 @@ public class PMDExecutor { private static ExecutionResult runPMDUnix(Path tempDir, Path reportFile, String ... arguments) throws Exception { String cmd = tempDir.resolve(PMD_BIN_PREFIX + PMDVersion.VERSION + "/bin/run.sh").toAbsolutePath().toString(); - return runPMD(cmd, Arrays.asList(arguments), reportFile); + List args = new ArrayList<>(); + args.add("pmd"); + args.addAll(Arrays.asList(arguments)); + return runPMD(cmd, args, reportFile); } private static ExecutionResult runPMDWindows(Path tempDir, Path reportFile, String ... arguments) throws Exception { @@ -45,7 +49,7 @@ public class PMDExecutor { } private static ExecutionResult runPMD(String cmd, List arguments, Path reportFile) throws Exception { - ProcessBuilder pb = new ProcessBuilder(cmd, "pmd"); + ProcessBuilder pb = new ProcessBuilder(cmd); pb.command().addAll(arguments); pb.redirectErrorStream(false); final Process process = pb.start(); From 60f11fcb7df52e7d16de720796c1e2ba6477138d Mon Sep 17 00:00:00 2001 From: andi Date: Tue, 12 Nov 2019 13:55:53 +0100 Subject: [PATCH 2/6] fix reporting of innerclass classnames --- .../pmd/lang/java/rule/JavaRuleViolation.java | 5 +++++ .../lang/java/rule/JavaRuleViolationTest.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java index 7990caaf39..d544783cd4 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java @@ -101,6 +101,11 @@ public class JavaRuleViolation extends ParametricRuleViolation { private void setClassNameFrom(JavaNode node) { String qualifiedName = null; + + if (node.getScope() instanceof ClassScope) { + qualifiedName = ((ClassScope) node.getScope()).getClassName(); + } + for (AbstractAnyTypeDeclaration parent : node.getParentsOfType(AbstractAnyTypeDeclaration.class)) { String clsName = parent.getScope().getEnclosingScope(ClassScope.class).getClassName(); if (qualifiedName == null) { diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationTest.java index 97a5109611..7c312122a6 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationTest.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.rule; import static org.junit.Assert.assertEquals; import java.io.StringReader; +import java.util.List; import org.junit.Test; @@ -15,6 +16,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersionHandler; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.java.JavaLanguageModule; +import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter; import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; @@ -130,4 +132,20 @@ public class JavaRuleViolationTest { assertEquals("pkg", violation.getPackageName()); assertEquals("Foo", violation.getClassName()); } + + /** + * Test that the name of the inner class is taken correctly. + */ + @Test + public void testInnerClass() { + ASTCompilationUnit ast = parse("class Foo { class Bar { } }"); + List classes = ast.findDescendantsOfType(ASTClassOrInterfaceDeclaration.class); + assertEquals(2, classes.size()); + + JavaRuleViolation fooViolation = new JavaRuleViolation(null, new RuleContext(), classes.get(0), null); + assertEquals("Foo", fooViolation.getClassName()); + + JavaRuleViolation barViolation = new JavaRuleViolation(null, new RuleContext(), classes.get(1), null); + assertEquals("Foo$Bar", barViolation.getClassName()); + } } From 6bf6e2240cb5f362c13e62842315c759397e8126 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 15 Nov 2019 08:51:43 +0100 Subject: [PATCH 3/6] [doc] Update release notes, refs #2106, fixes #2105 --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index ce61258e7f..bea0b9843c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -22,6 +22,7 @@ This is a {{ site.pmd.release_type }} release. * [#2096](https://github.com/pmd/pmd/issues/2096): \[core] Referencing category errorprone.xml produces deprecation warnings for InvalidSlf4jMessageFormat * java * [#1861](https://github.com/pmd/pmd/issues/1861): \[java] Be more lenient with version numbers + * [#2105](https://github.com/pmd/pmd/issues/2105): \[java] Wrong name for inner classes in violations ### API Changes @@ -30,6 +31,7 @@ This is a {{ site.pmd.release_type }} release. * [#2088](https://github.com/pmd/pmd/pull/2088): \[java] Add more version shortcuts for older java - [Henning Schmiedehausen](https://github.com/hgschmie) * [#2089](https://github.com/pmd/pmd/pull/2089): \[core] Minor unrelated improvements to code - [Gonzalo Exequiel Ibars Ingman](https://github.com/gibarsin) * [#2091](https://github.com/pmd/pmd/pull/2091): \[core] Fix pmd warnings (IdenticalCatchCases) - [Gonzalo Exequiel Ibars Ingman](https://github.com/gibarsin) +* [#2106](https://github.com/pmd/pmd/pull/2106): \[java] Wrong name for inner classes - [Andi Pabst](https://github.com/andipabst) {% endtocmaker %} From 20bcda9f735bd0a14b8e69f7ba740f407cb973e5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 16 Nov 2019 21:41:12 +0100 Subject: [PATCH 4/6] Upgrade maven-javadoc-plugin to 3.1.1 This fixes errors like "[ERROR] Error fetching link: /home/travis/build/pmd/pmd/pmd-core/target/apidocs/package-list. Ignored it." during the builds. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3be0f8bc76..7ac567bf10 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a 3.0.0 3.12.0 1.10.1 - 3.0.1 + 3.1.1 4.7 UTF-8 From e0e2010f6fbb0cf944e9a23254aa23d036c90a33 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 16 Nov 2019 22:56:14 +0100 Subject: [PATCH 5/6] javadoc: disable automatic detection of offline links for modules This tries to determine the links to the other reactor projects, e.g. from pmd-java to pmd-core via the url from project.url. Project.url is currently https://pmd.github.io and the constructed url will be https://pmd.github.io/apidocs which doesn't exist. This means, the generated links to classes e.g. from core don't work anyway. Disabling this feature avoids error messages like [ERROR] Error fetching link: /home/travis/build/pmd/pmd/pmd-apex-jorje/target/apidocs. Ignored it. E.g. pmd-apex-jorje does not have own javadoc at all, since it is just a library. The linking between the different pmd modules needs to be revisited with #1769. --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 7ac567bf10..649d971f2e 100644 --- a/pom.xml +++ b/pom.xml @@ -285,6 +285,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a ${ant.version} + false From 5517662381f5303fa8bc257a470c48a9ca318762 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 16 Nov 2019 22:59:44 +0100 Subject: [PATCH 6/6] pmd-dist: fix warning about cross platform compatibility of output directory [WARNING] The assembly descriptor contains a filesystem-root relative reference, which is not cross platform compatible / --- pmd-dist/src/main/resources/assemblies/pmd-src.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-dist/src/main/resources/assemblies/pmd-src.xml b/pmd-dist/src/main/resources/assemblies/pmd-src.xml index a049343e8a..1513da9f56 100644 --- a/pmd-dist/src/main/resources/assemblies/pmd-src.xml +++ b/pmd-dist/src/main/resources/assemblies/pmd-src.xml @@ -13,7 +13,7 @@ false ${project.basedir}/.. - / + .git/** **/target/**