forked from phoedos/pmd
Merge branch 'master' into pmd/7.0.x
This commit is contained in:
@@ -80,9 +80,9 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>failsafe-default</id>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
@@ -198,11 +198,6 @@
|
||||
<artifactId>pmd-ruby</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-scala_2.13</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-swift</artifactId>
|
||||
@@ -259,6 +254,11 @@
|
||||
<artifactId>pmd-apex</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-scala_2.13</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-ui</artifactId>
|
||||
@@ -266,5 +266,36 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jdk7-compat-it</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>java7.home</name>
|
||||
</property>
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>jdk7-compat-it</id>
|
||||
<goals>
|
||||
<goal>integration-test</goal>
|
||||
<goal>verify</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<environmentVariables>
|
||||
<JAVA_HOME>${java7.home}</JAVA_HOME>
|
||||
<PATH>${java7.home}/bin:${env.PATH}</PATH>
|
||||
</environmentVariables>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
@@ -21,6 +21,11 @@ public class AllRulesIT extends AbstractBinaryDistributionTest {
|
||||
|
||||
@Parameters
|
||||
public static Iterable<String> languagesToTest() {
|
||||
if (PMDExecutor.isJava7Test()) {
|
||||
// note: apex and scala require java8
|
||||
return Arrays.asList("java", "javascript", "jsp", "modelica",
|
||||
"plsql", "pom", "visualforce", "velocitytemplate", "xml", "xsl");
|
||||
}
|
||||
// note: scala and wsdl have no rules
|
||||
return Arrays.asList("java", "apex", "javascript", "jsp", "modelica",
|
||||
"plsql", "pom", "visualforce", "velocitytemplate", "xml", "xsl");
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
@@ -21,7 +21,19 @@ import net.sourceforge.pmd.PMDVersion;
|
||||
|
||||
public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
|
||||
private static final String SUPPORTED_LANGUAGES = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, vf, xml]";
|
||||
private static final String SUPPORTED_LANGUAGES_CPD;
|
||||
private static final String SUPPORTED_LANGUAGES_PMD;
|
||||
|
||||
static {
|
||||
// note: apex and scala require java8
|
||||
if (PMDExecutor.isJava7Test()) {
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [cpp, cs, dart, ecmascript, fortran, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, swift, vf, xml]";
|
||||
SUPPORTED_LANGUAGES_PMD = "ecmascript, java, jsp, modelica, plsql, pom, vf, vm, wsdl, xml, xsl";
|
||||
} else {
|
||||
SUPPORTED_LANGUAGES_CPD = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, vf, xml]";
|
||||
SUPPORTED_LANGUAGES_PMD = "apex, ecmascript, java, jsp, modelica, plsql, pom, scala, swift, vf, vm, wsdl, xml, xsl";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileExistence() {
|
||||
@@ -66,12 +78,20 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
|
||||
ExecutionResult result;
|
||||
|
||||
result = PMDExecutor.runPMD(tempDir); // without any argument, display usage help and error
|
||||
result.assertExecutionResult(1, SUPPORTED_LANGUAGES_PMD);
|
||||
|
||||
result = PMDExecutor.runPMD(tempDir, "-h");
|
||||
result.assertExecutionResult(0, "apex, ecmascript, java, jsp, modelica, plsql, pom, scala, swift, vf, vm, wsdl, xml, xsl");
|
||||
result.assertExecutionResult(0, SUPPORTED_LANGUAGES_PMD);
|
||||
|
||||
result = PMDExecutor.runPMDRules(tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml");
|
||||
result.assertExecutionResult(4, "", "JumbledIncrementer.java:8:");
|
||||
|
||||
// also test XML format
|
||||
result = PMDExecutor.runPMDRules(tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml");
|
||||
result.assertExecutionResult(4, "", "JumbledIncrementer.java\">");
|
||||
result.assertExecutionResult(4, "", "<violation beginline=\"8\" endline=\"10\" begincolumn=\"13\" endcolumn=\"13\" rule=\"JumbledIncrementer\"");
|
||||
|
||||
result = PMDExecutor.runPMDRules(tempDir, srcDir, "rulesets/java/quickstart.xml");
|
||||
result.assertExecutionResult(4, "");
|
||||
}
|
||||
@@ -82,15 +102,23 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
|
||||
|
||||
ExecutionResult result;
|
||||
|
||||
result = CpdExecutor.runCpd(tempDir); // without any argument, display usage help and error
|
||||
result.assertExecutionResult(1, SUPPORTED_LANGUAGES_CPD);
|
||||
|
||||
result = CpdExecutor.runCpd(tempDir, "-h");
|
||||
result.assertExecutionResult(0, SUPPORTED_LANGUAGES);
|
||||
result.assertExecutionResult(0, SUPPORTED_LANGUAGES_CPD);
|
||||
|
||||
result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "10", "--format", "text", "--files", srcDir);
|
||||
result.assertExecutionResult(4, "Found a 10 line (55 tokens) duplication in the following files:");
|
||||
result.assertExecutionResult(4, "Class1.java");
|
||||
result.assertExecutionResult(4, "Class2.java");
|
||||
|
||||
result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "10", "--format", "xml", "--files", srcDir);
|
||||
result.assertExecutionResult(4, "<duplication lines=\"10\" tokens=\"55\">");
|
||||
result.assertExecutionResult(4, "Class1.java\"/>");
|
||||
result.assertExecutionResult(4, "Class2.java\"/>");
|
||||
|
||||
result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "1000", "--format", "text", "--files", srcDir);
|
||||
result.assertExecutionResult(0, "");
|
||||
result.assertExecutionResult(0);
|
||||
}
|
||||
}
|
||||
|
@@ -42,6 +42,15 @@ public class ExecutionResult {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the command exited with the expected exit code. Any output is ignored.
|
||||
*
|
||||
* @param expectedExitCode the exit code, e.g. 0 if no rule violations are expected, or 4 if violations are found
|
||||
*/
|
||||
public void assertExecutionResult(int expectedExitCode) {
|
||||
assertExecutionResult(expectedExitCode, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the command exited with the expected exit code and that the given expected
|
||||
* output is contained in the actual command output.
|
||||
@@ -69,7 +78,7 @@ public class ExecutionResult {
|
||||
if (!output.contains(expectedOutput)) {
|
||||
fail("Expected output '" + expectedOutput + "' not present.\nComplete result:\n\n" + this);
|
||||
}
|
||||
} else {
|
||||
} else if (expectedOutput != null && expectedOutput.isEmpty()) {
|
||||
assertTrue("The output should have been empty.\nComplete result:\n\n" + this, output.isEmpty());
|
||||
}
|
||||
if (expectedReport != null && !expectedReport.isEmpty()) {
|
||||
|
@@ -14,6 +14,7 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
import net.sourceforge.pmd.PMDVersion;
|
||||
@@ -103,15 +104,19 @@ public class PMDExecutor {
|
||||
* @throws Exception if the execution fails for any reason (executable not found, ...)
|
||||
*/
|
||||
public static ExecutionResult runPMDRules(Path tempDir, String sourceDirectory, String ruleset) throws Exception {
|
||||
return runPMDRules(tempDir, sourceDirectory, ruleset, FORMATTER);
|
||||
}
|
||||
|
||||
public static ExecutionResult runPMDRules(Path tempDir, String sourceDirectory, String ruleset, String formatter) throws Exception {
|
||||
Path reportFile = Files.createTempFile("pmd-it-report", "txt");
|
||||
reportFile.toFile().deleteOnExit();
|
||||
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
return runPMDWindows(tempDir, reportFile, SOURCE_DIRECTORY_FLAG, sourceDirectory, RULESET_FLAG, ruleset,
|
||||
FORMAT_FLAG, FORMATTER, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString());
|
||||
FORMAT_FLAG, formatter, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString());
|
||||
} else {
|
||||
return runPMDUnix(tempDir, reportFile, SOURCE_DIRECTORY_FLAG, sourceDirectory, RULESET_FLAG, ruleset,
|
||||
FORMAT_FLAG, FORMATTER, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString());
|
||||
FORMAT_FLAG, formatter, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +134,8 @@ public class PMDExecutor {
|
||||
return runPMDUnix(tempDir, null, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isJava7Test() {
|
||||
return StringUtils.equals(System.getenv("JAVA_HOME"), System.getProperty("java7.home"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user