Merge branch 'master' into 7.0.x

This commit is contained in:
Clément Fournier
2019-11-19 03:36:57 +01:00
6 changed files with 34 additions and 4 deletions

View File

@ -27,6 +27,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
@ -35,6 +36,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 %}

View File

@ -13,7 +13,7 @@
<fileSet>
<useDefaultExcludes>false</useDefaultExcludes>
<directory>${project.basedir}/..</directory>
<outputDirectory>/</outputDirectory>
<outputDirectory></outputDirectory>
<excludes>
<exclude>.git/**</exclude>
<exclude>**/target/**</exclude>

View File

@ -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<String> 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<String> 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();

View File

@ -101,6 +101,11 @@ public class JavaRuleViolation extends ParametricRuleViolation<JavaNode> {
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) {

View File

@ -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<ASTClassOrInterfaceDeclaration> 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());
}
}

View File

@ -95,7 +95,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
<checkstyle.version>3.0.0</checkstyle.version>
<pmd.plugin.version>3.12.0</pmd.plugin.version>
<ant.version>1.10.1</ant.version>
<javadoc.plugin.version>3.0.1</javadoc.plugin.version>
<javadoc.plugin.version>3.1.1</javadoc.plugin.version>
<antlr.version>4.7</antlr.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -287,6 +287,7 @@ Objective-C, Perl, PHP, PLSQL, Python, Ruby, Salesforce.com Apex, Scala, Swift a
<version>${ant.version}</version>
</additionalDependency>
</additionalDependencies>
<detectOfflineLinks>false</detectOfflineLinks>
</configuration>
</plugin>
<plugin>