From 13f7675b67401ade55f7be87741c8173632e5c04 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2016 11:27:22 +0200 Subject: [PATCH 1/3] Fixes #1481 no problems found results in blank file instead of empty xml --- .../pmd/cpd/CPDCommandLineInterface.java | 2 +- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 33 +++++++++++++++++++ src/site/markdown/overview/changelog.md | 2 ++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.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 3f33269854..b5ce0c9c6d 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 @@ -86,8 +86,8 @@ public class CPDCommandLineInterface { } cpd.go(); + System.out.println(arguments.getRenderer().render(cpd.getMatches())); if (cpd.getMatches().hasNext()) { - System.out.println(arguments.getRenderer().render(cpd.getMatches())); setStatusCodeOrExit(DUPLICATE_CODE_FOUND); } } 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 new file mode 100644 index 0000000000..513cf8c1ea --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java @@ -0,0 +1,33 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.cpd; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.LogMode; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; +import org.junit.contrib.java.lang.system.StandardOutputStreamLog; +import org.junit.rules.TestRule; + +public class CPDCommandLineInterfaceTest { + @Rule + public final TestRule restoreSystemProperties = new RestoreSystemProperties(); + @Rule + public final StandardOutputStreamLog log = new StandardOutputStreamLog(LogMode.LOG_ONLY); + + @Test + public void testEmptyResultRendering() { + System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true"); + CPDCommandLineInterface.main(new String[] { + "--minimum-tokens", "340", + "--language", "java", + "--files", "src/test/resources/net/sourceforge/pmd/cpd/files/", + "--format", "xml" + }); + Assert.assertEquals("\n\n", log.getLog()); + } + +} diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 7f9ad192cb..83e12d43f5 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -16,6 +16,8 @@ * java-unusedcode/UnusedLocalVariable * [#1484](https://sourceforge.net/p/pmd/bugs/1484/): UnusedLocalVariable - false positive - parenthesis +* General + * [#1481](https://sourceforge.net/p/pmd/bugs/1481/): no problems found results in blank file instead of empty xml **API Changes:** From e71324e08c7582be54e71c24d2c5b8af460d3dfb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2016 11:36:35 +0200 Subject: [PATCH 2/3] Fix unit test for #1481 --- .../net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a36f167686..6a2ad260d6 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 @@ -23,6 +23,6 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { runCPD("--minimum-tokens", "5", "--language", "js", "--files", "src/test/resources/net/sourceforge/pmd/cpd/ts/"); String out = getOutput(); - Assert.assertTrue(out.isEmpty()); + Assert.assertTrue(out.trim().isEmpty()); } } From 379b0de1867599d79cc35a1c9d6f5dc0ab454a92 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2016 11:36:41 +0200 Subject: [PATCH 3/3] Update changelog --- src/site/markdown/overview/changelog.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 83e12d43f5..9ae5c29031 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -24,4 +24,5 @@ * New command line parameter for PMD: `-norulesetcompatibility` - this disables the ruleset factory compatibility filter and fails, if e.g. an old rule name is used in the ruleset. See also [#1360](https://sourceforge.net/p/pmd/bugs/1360/). - This option is also available for the ant task: `true`. \ No newline at end of file + This option is also available for the ant task: `true`. +* CPD: If no problems found, an empty report will be output instead of nothing. See also [#1481](https://sourceforge.net/p/pmd/bugs/1481/) \ No newline at end of file