diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 2114dc4697..451cb53031 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -18,7 +18,6 @@ import java.util.zip.ZipFile; import org.junit.Test; import net.sourceforge.pmd.PMDVersion; -import net.sourceforge.pmd.internal.LogMessages; public class BinaryDistributionIT extends AbstractBinaryDistributionTest { @@ -26,8 +25,24 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { private static final String SUPPORTED_LANGUAGES_PMD; static { - SUPPORTED_LANGUAGES_CPD = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, gherkin, go, groovy, html, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, vf, xml]"; - SUPPORTED_LANGUAGES_PMD = "apex, ecmascript, html, java, jsp, kotlin, modelica, plsql, pom, scala, swift, vf, vm, wsdl, xml, xsl"; + SUPPORTED_LANGUAGES_CPD = "Valid values: apex, cpp, cs, dart, ecmascript,\n" + + " fortran, gherkin, go, groovy, html, java, jsp,\n" + + " kotlin, lua, matlab, modelica, objectivec, perl,\n" + + " php, plsql, python, ruby, scala, swift, vf, xml"; + SUPPORTED_LANGUAGES_PMD = "Valid values: apex, apex-54, apex-latest,\n" + + " ecmascript, ecmascript-ES6, ecmascript-latest,\n" + + " html, html-latest, java, java-1.3, java-1.4,\n" + + " java-1.5, java-1.6, java-1.7, java-1.8, java-10,\n" + + " java-11, java-12, java-13, java-14, java-15,\n" + + " java-16, java-17, java-18, java-18-preview,\n" + + " java-19, java-19-preview, java-9, java-latest,\n" + + " jsp, jsp-latest, kotlin, kotlin-1.6-rfc+0.1,\n" + + " kotlin-latest, modelica, modelica-latest, plsql,\n" + + " plsql-latest, pom, pom-latest, scala, scala-2.10,\n" + + " scala-2.11, scala-2.12, scala-2.13, scala-latest,\n" + + " swift, swift-latest, vf, vf-latest, vm,\n" + + " vm-latest, wsdl, wsdl-latest, xml, xml-latest,\n" + + " xsl, xsl-latest"; } private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); @@ -42,10 +57,9 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { String basedir = "pmd-bin-" + PMDVersion.VERSION + "/"; result.add(basedir); result.add(basedir + "LICENSE"); - result.add(basedir + "bin/run.sh"); + result.add(basedir + "bin/pmd"); result.add(basedir + "bin/pmd.bat"); - result.add(basedir + "bin/cpd.bat"); - result.add(basedir + "bin/ast-dump.bat"); + result.add(basedir + "conf/simplelogger.properties"); result.add(basedir + "lib/pmd-core-" + PMDVersion.VERSION + ".jar"); result.add(basedir + "lib/pmd-java-" + PMDVersion.VERSION + ".jar"); return result; @@ -98,7 +112,7 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { @Test public void testPmdNoArgs() throws Exception { ExecutionResult result = PMDExecutor.runPMD(tempDir); // without any argument, display usage help and error - result.assertExecutionResultErrOutput(1, LogMessages.runWithHelpFlagMessage()); + result.assertExecutionResultErrOutput(2, "Usage: pmd analyze "); } @Test @@ -110,14 +124,14 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { result = PMDExecutor.runPMD(tempDir, "-d", srcDir, "-R", "src/test/resources/rulesets/sample-ruleset.xml", "-r", folder.newFile().toString()); result.assertExecutionResult(4); - result.assertErrorOutputContains("[main] INFO net.sourceforge.pmd.PMD - Log level is at INFO"); + result.assertErrorOutputContains("[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at INFO"); // now with debug result = PMDExecutor.runPMD(tempDir, "-d", srcDir, "-R", "src/test/resources/rulesets/sample-ruleset.xml", "-r", folder.newFile().toString(), "--debug"); result.assertExecutionResult(4); - result.assertErrorOutputContains("[main] INFO net.sourceforge.pmd.PMD - Log level is at TRACE"); + result.assertErrorOutputContains("[main] INFO net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand - Log level is at TRACE"); } @Test @@ -135,22 +149,22 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { ExecutionResult result; result = CpdExecutor.runCpd(tempDir); // without any argument, display usage help and error - result.assertExecutionResultErrOutput(1, LogMessages.runWithHelpFlagMessage()); + result.assertExecutionResultErrOutput(2, "Usage: pmd cpd "); result = CpdExecutor.runCpd(tempDir, "-h"); result.assertExecutionResult(0, SUPPORTED_LANGUAGES_CPD); - result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "10", "--format", "text", "--files", srcDir); + result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "10", "--format", "text", "--dir", 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 = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "10", "--format", "xml", "--dir", srcDir); result.assertExecutionResult(4, ""); result.assertExecutionResult(4, "Class1.java\"/>"); result.assertExecutionResult(4, "Class2.java\"/>"); - result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "1000", "--format", "text", "--files", srcDir); + result = CpdExecutor.runCpd(tempDir, "--minimum-tokens", "1000", "--format", "text", "--dir", srcDir); result.assertExecutionResult(0); } } diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/CpdExecutor.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/CpdExecutor.java index 8dc812c278..0948d9ff28 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/CpdExecutor.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/CpdExecutor.java @@ -7,7 +7,6 @@ package net.sourceforge.pmd.it; import static net.sourceforge.pmd.util.CollectionUtil.listOf; import java.nio.file.Path; -import java.util.Arrays; import java.util.List; import org.apache.commons.lang3.SystemUtils; @@ -37,12 +36,11 @@ public class CpdExecutor { String cmd; List args; if (SystemUtils.IS_OS_WINDOWS) { - cmd = "/bin/cpd.bat"; - args = Arrays.asList(arguments); + cmd = "/bin/pmd.bat"; } else { - cmd = "/bin/run.sh"; - args = listOf("cpd", arguments); + cmd = "/bin/pmd"; } + args = listOf("cpd", arguments); cmd = tempDir.resolve(PMD_BIN_PREFIX + PMDVersion.VERSION + cmd).toAbsolutePath().toString(); return PMDExecutor.runCommand(cmd, args, null); } 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 b61e94d7a7..6e87ce3a13 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 @@ -37,16 +37,19 @@ public class PMDExecutor { } private static ExecutionResult runPMDUnix(Path tempDir, Path reportFile, String... arguments) throws Exception { - String cmd = tempDir.resolve(AbstractBinaryDistributionTest.PMD_BIN_PREFIX + PMDVersion.VERSION + "/bin/run.sh").toAbsolutePath().toString(); + String cmd = tempDir.resolve(AbstractBinaryDistributionTest.PMD_BIN_PREFIX + PMDVersion.VERSION + "/bin/pmd").toAbsolutePath().toString(); List args = new ArrayList<>(); - args.add("pmd"); + args.add("run"); args.addAll(Arrays.asList(arguments)); return runCommand(cmd, args, reportFile); } private static ExecutionResult runPMDWindows(Path tempDir, Path reportFile, String... arguments) throws Exception { String cmd = tempDir.resolve(AbstractBinaryDistributionTest.PMD_BIN_PREFIX + PMDVersion.VERSION + "/bin/pmd.bat").toAbsolutePath().toString(); - return runCommand(cmd, Arrays.asList(arguments), reportFile); + List args = new ArrayList<>(); + args.add("run"); + args.addAll(Arrays.asList(arguments)); + return runCommand(cmd, args, reportFile); } static ExecutionResult runCommand(String cmd, List arguments, Path reportFile) throws Exception { @@ -116,7 +119,7 @@ public class PMDExecutor { FORMAT_FLAG, formatter, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString(), NO_PROGRESSBAR_FLAG); } else { return runPMDUnix(tempDir, reportFile, SOURCE_DIRECTORY_FLAG, sourceDirectory, RULESET_FLAG, ruleset, - FORMAT_FLAG, formatter, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString(), NO_PROGRESSBAR_FLAG); + FORMAT_FLAG, formatter, REPORTFILE_FLAG, reportFile.toAbsolutePath().toString(), NO_PROGRESSBAR_FLAG, "--verbose"); } }