From 17364a997b1ff135cb48dc412a797286bb0025fe Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 17 Feb 2023 11:39:03 +0100 Subject: [PATCH] [doc] CPD - use non deprecated `--dir` cli option --- docs/pages/pmd/userdocs/cpd/cpd.md | 27 ++++++++++--------- docs/pages/pmd/userdocs/installation.md | 6 ++--- .../pmd/cpd/CPDCommandLineInterface.java | 4 +-- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 6 ++--- .../pmd/it/BinaryDistributionIT.java | 6 ++--- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 16 +++++------ .../pmd/cpd/CPDCommandLineInterfaceTest.java | 4 +-- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/docs/pages/pmd/userdocs/cpd/cpd.md b/docs/pages/pmd/userdocs/cpd/cpd.md index 09b8ba2bdf..bbc21226ab 100644 --- a/docs/pages/pmd/userdocs/cpd/cpd.md +++ b/docs/pages/pmd/userdocs/cpd/cpd.md @@ -63,11 +63,12 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt required="yes" %} {% include custom/cli_option_row.html options="--files,--dir,-d" - description="List of files and directories to process" + description="List of files and directories to process. +

Note: `--files` is deprecated since PMD 6.52.0. Usage of `--dir` is preferred.

" required="yes" %} {% include custom/cli_option_row.html options="--file-list" - description="Path to file containing a comma delimited list of files to analyze. If this is given, then you don't need to provide `--files`." + description="Path to file containing a comma delimited list of files to analyze. If this is given, then you don't need to provide `--dir`." %} {% include custom/cli_option_row.html options="--language" description="Sources code language." @@ -157,49 +158,49 @@ _Note:_ The following example use the Linux start script. For Windows, just repl Minimum required options: Just give it the minimum duplicate size and the source directory: - $ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java + $ ./run.sh cpd --minimum-tokens 100 --dir /usr/local/java/src/java You can also specify the language: - $ ./run.sh cpd --minimum-tokens 100 --files /path/to/c/source --language cpp + $ ./run.sh cpd --minimum-tokens 100 --dir /path/to/c/source --language cpp You may wish to check sources that are stored in different directories: - $ ./run.sh cpd --minimum-tokens 100 --files /path/to/other/source --files /path/to/other/source --files /path/to/other/source --language fortran + $ ./run.sh cpd --minimum-tokens 100 --dir /path/to/other/source --dir /path/to/other/source --dir /path/to/other/source --language fortran -There should be no limit to the number of '--files', you may add... But if you stumble one, please tell us ! +There should be no limit to the number of `--dir`, you may add... But if you stumble one, please tell us ! And if you're checking a C source tree with duplicate files in different architecture directories you can skip those using --skip-duplicate-files: - $ ./run.sh cpd --minimum-tokens 100 --files /path/to/c/source --language cpp --skip-duplicate-files + $ ./run.sh cpd --minimum-tokens 100 --dir /path/to/c/source --language cpp --skip-duplicate-files You can also specify the encoding to use when parsing files: - $ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java --encoding utf-16le + $ ./run.sh cpd --minimum-tokens 100 --dir /usr/local/java/src/java --encoding utf-16le You can also specify a report format - here we're using the XML report: - $ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java --format xml + $ ./run.sh cpd --minimum-tokens 100 --dir /usr/local/java/src/java --format xml The default format is a text report, and there's also a `csv` report. Note that CPD is pretty memory-hungry; you may need to give Java more memory to run it, like this: $ export PMD_JAVA_OPTS=-Xmx512m - $ ./run.sh cpd --minimum-tokens 100 --files /usr/local/java/src/java + $ ./run.sh cpd --minimum-tokens 100 --dir /usr/local/java/src/java In order to change the heap size under Windows, you'll need to edit the batch file `cpd.bat` or set the environment variable `PMD_JAVA_OPTS` prior to starting CPD: C:\ > cd C:\pmd-bin-{{site.pmd.version}}\bin C:\...\bin > set PMD_JAVA_OPTS=-Xmx512m - C:\...\bin > .\cpd.bat --minimum-tokens 100 --files c:\temp\src + C:\...\bin > .\cpd.bat --minimum-tokens 100 --dir c:\temp\src If you specify a source directory but don't want to scan the sub-directories, you can use the non-recursive option: - $ ./run.sh cpd --minimum-tokens 100 --non-recursive --files /usr/local/java/src/java + $ ./run.sh cpd --minimum-tokens 100 --non-recursive --dir /usr/local/java/src/java ### Exit status @@ -209,7 +210,7 @@ This behavior has been introduced to ease CPD integration into scripts or hooks, - +
0Everything is fine, no code duplications found
1Couldn't understand command line parameters or CPD exited with an exception
4At least one code duplication has been detected unless '--fail-on-violation false' is used.
4At least one code duplication has been detected unless `--fail-on-violation false` is used.
diff --git a/docs/pages/pmd/userdocs/installation.md b/docs/pages/pmd/userdocs/installation.md index 2a31ba3f8b..38f015faa4 100644 --- a/docs/pages/pmd/userdocs/installation.md +++ b/docs/pages/pmd/userdocs/installation.md @@ -116,7 +116,7 @@ Additionally, the following options, are specified most of the time even though Like for PMD, CPD is started on Unix by `run.sh cpd` and on Windows by `cpd.bat`. There are two required parameters: -* `--files `: path to the sources to analyse. This can be a file name, a +* `--dir `: path to the sources to analyse. This can be a file name, a directory or a jar or zip file containing the sources. * `--minimum-tokens `: the minimum token length which should be reported as a duplicate. @@ -138,7 +138,7 @@ There are two required parameters:
~ $ cd ~/bin/pmd-bin-{{site.pmd.version}}/bin
-~/.../bin $ ./run.sh cpd --minimum-tokens 100 --files /home/me/src
+~/.../bin $ ./run.sh cpd --minimum-tokens 100 --dir /home/me/src
 
   Found a 7 line (110 tokens) duplication in the following files:
   Starting at line 579 of /home/me/src/test/java/foo/FooTypeTest.java
@@ -154,7 +154,7 @@ There are two required parameters:
     
C:\ > cd C:\pmd-bin-{{site.pmd.version}}\bin
-C:\...\bin > .\cpd.bat --minimum-tokens 100 --files c:\temp\src
+C:\...\bin > .\cpd.bat --minimum-tokens 100 --dir c:\temp\src
 
   Found a 7 line (110 tokens) duplication in the following files:
   Starting at line 579 of c:\temp\src\test\java\foo\FooTypeTest.java
diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java
index 990defedad..ab7c4143c6 100644
--- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java
+++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java
@@ -214,12 +214,12 @@ public final class CPDCommandLineInterface {
         String helpText = " For example on Windows:" + PMD.EOL;
 
         helpText += " C:\\>" + "pmd-bin-" + PMDVersion.VERSION + "\\bin\\cpd.bat"
-                + " --minimum-tokens 100 --files c:\\jdk18\\src\\java" + PMD.EOL;
+                + " --minimum-tokens 100 --dir c:\\jdk18\\src\\java" + PMD.EOL;
         helpText += PMD.EOL;
 
         helpText += " For example on *nix:" + PMD.EOL;
         helpText += " $ " + "pmd-bin-" + PMDVersion.VERSION + "/bin/run.sh cpd"
-                + " --minimum-tokens 100 --files /path/to/java/code" + PMD.EOL;
+                + " --minimum-tokens 100 --dir /path/to/java/code" + PMD.EOL;
         helpText += PMD.EOL;
 
         helpText += " Supported languages: " + Arrays.toString(LanguageFactory.supportedLanguages) + PMD.EOL;
diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
index a01b355b7d..8ec8c41d61 100644
--- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
+++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
@@ -70,7 +70,7 @@ public class CPDCommandLineInterfaceTest {
 
     @Test
     public void testEmptyResultRendering() {
-        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--files",
+        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--dir",
                 SRC_DIR, "--format", "xml");
         final String expectedFilesXml = getExpectedFileEntriesXml(NUMBER_OF_TOKENS.keySet());
         assertEquals(CPD.StatusCode.OK, statusCode);
@@ -99,7 +99,7 @@ public class CPDCommandLineInterfaceTest {
 
     @Test
     public void testDebugLogging() {
-        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--files",
+        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--dir",
                 SRC_DIR, "--debug");
         assertEquals(CPD.StatusCode.OK, statusCode);
         assertThat(errLog.getLog(), containsString("Tokenizing ")); // this is a debug logging
@@ -108,7 +108,7 @@ public class CPDCommandLineInterfaceTest {
     @Test
     public void testNormalLogging() {
         loggingRule.clear();
-        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--files",
+        CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--dir",
                 SRC_DIR);
         assertEquals(CPD.StatusCode.OK, statusCode);
         assertThat(errLog.getLog(), not(containsString("Tokenizing "))); // this is a debug logging
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 36cf4f1b2e..ef0368c1b6 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
@@ -141,17 +141,17 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest {
         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-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
index a43be3d6d9..87fea5e67d 100644
--- a/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
+++ b/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
@@ -22,7 +22,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
      */
     @Test
     public void testIgnoreIdentifiers() {
-        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers");
         Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication"));
     }
@@ -32,7 +32,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
      */
     @Test
     public void testIgnoreIdentifiersFailOnViolationFalse() throws Exception {
-        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--failOnViolation",
                 "false");
         Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication"));
@@ -43,7 +43,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
      */
     @Test
     public void testIgnoreIdentifiersFailOnViolationFalseLongOption() throws Exception {
-        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--fail-on-violation",
                 "false");
         Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication"));
@@ -54,7 +54,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
      */
     @Test
     public void testExcludes() throws Exception {
-        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--ignore-identifiers", "--files",
+        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--ignore-identifiers", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--exclude",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/File2.java");
         Assert.assertFalse(out.contains("Found a 7 line (34 tokens) duplication"));
@@ -70,7 +70,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
         // set the default encoding under Windows
         System.setProperty("file.encoding", "Cp1252");
 
-        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--format", "xml",
                 // request UTF-8 for CPD
                 "--encoding", "UTF-8");
@@ -89,7 +89,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
      */
     @Test
     public void testBrokenAndValidFile() throws IOException {
-        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/badandgood/", "--format", "text", "--skip-lexical-errors");
         Assert.assertTrue(
                 Pattern.compile("Skipping .*?BadFile\\.java\\. Reason: Lexical error in file").matcher(out).find());
@@ -98,14 +98,14 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
 
     @Test
     public void testFormatXmlWithoutEncoding() throws Exception {
-        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--files",
+        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--format", "xml");
         Assert.assertTrue(out.contains(""));
     }
 
     @Test
     public void testCSVFormat() throws Exception {
-        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "100", "--files", "src/test/resources/net/sourceforge/pmd/cpd/badandgood/",
+        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "100", "--dir", "src/test/resources/net/sourceforge/pmd/cpd/badandgood/",
                 "--language", "c", "--format", "csv");
         Assert.assertFalse(out.contains("Couldn't instantiate renderer"));
     }
diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
index c6b4df8f27..cb05b5deaa 100644
--- a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
+++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java
@@ -15,7 +15,7 @@ import net.sourceforge.pmd.cli.BaseCPDCLITest;
 public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
     @Test
     public void shouldFindDuplicatesWithDifferentFileExtensions() {
-        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "5", "--language", "js", "--files",
+        String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "5", "--language", "js", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/ts/File1.ts",
                 "src/test/resources/net/sourceforge/pmd/cpd/ts/File2.ts");
 
@@ -24,7 +24,7 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest {
 
     @Test
     public void shouldFindNoDuplicatesWithDifferentFileExtensions() {
-        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "5", "--language", "js", "--files",
+        String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "5", "--language", "js", "--dir",
                 "src/test/resources/net/sourceforge/pmd/cpd/ts/");
 
         assertThat(out.trim(), emptyString());