Merge branch 'bug-1481'

This commit is contained in:
Andreas Dangel
2016-05-28 11:46:33 +02:00
4 changed files with 37 additions and 2 deletions

View File

@ -86,8 +86,8 @@ public class CPDCommandLineInterface {
}
cpd.go();
if (cpd.getMatches().hasNext()) {
System.out.println(arguments.getRenderer().render(cpd.getMatches()));
if (cpd.getMatches().hasNext()) {
if (arguments.isFailOnViolation()) {
setStatusCodeOrExit(DUPLICATE_CODE_FOUND);
} else {

View File

@ -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("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<pmd-cpd/>\n", log.getLog());
}
}

View File

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

View File

@ -144,6 +144,7 @@ you'll need a java8 runtime environment.
* [#1470](https://sourceforge.net/p/pmd/bugs/1470/): Error with type-bound lambda
* [#1478](https://sourceforge.net/p/pmd/bugs/1478/): PMD CLI - Use first language as default if Java is not available
* [#1485](https://sourceforge.net/p/pmd/bugs/1485/): Analysis of some apex classes cause a stackoverflow error
* [#1481](https://sourceforge.net/p/pmd/bugs/1481/): no problems found results in blank file instead of empty xml
**API Changes:**
@ -152,6 +153,7 @@ you'll need a java8 runtime environment.
* CPD: If a complete filename is specified, the language dependent filename filter is not applied. This allows
to scan files, that are not using the standard file extension. If a directory is specified, the filename filter
is still applied and only those files with the correct file extension of the language are scanned.
* CPD: If no problems found, an empty report will be output instead of nothing. See also [#1481](https://sourceforge.net/p/pmd/bugs/1481/)
* 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/).