forked from phoedos/pmd
pmd: fixed #1068 CPD fails on broken symbolic links
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
????? ??, 2013 - 5.0.3:
|
||||
|
||||
Fixed bug 1068: CPD fails on broken symbolic links
|
||||
|
||||
|
||||
|
||||
February 3, 2013 - 5.0.2:
|
||||
|
||||
Fixed bug 878: False positive: UnusedFormalParameter for abstract methods
|
||||
|
@ -93,11 +93,16 @@ public class CPD {
|
||||
current.add(signature);
|
||||
}
|
||||
|
||||
if (!file.getCanonicalPath().equals(new File(file.getAbsolutePath()).getCanonicalPath())) {
|
||||
if (!file.getCanonicalPath().equals(file.getAbsolutePath())) {
|
||||
System.err.println("Skipping " + file + " since it appears to be a symlink");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
System.err.println("Skipping " + file + " since it doesn't exist (broken symlink?)");
|
||||
return;
|
||||
}
|
||||
|
||||
listener.addedFile(fileCount, file);
|
||||
SourceCode sourceCode = configuration.sourceCodeFor(file);
|
||||
configuration.tokenizer().tokenize(sourceCode, tokens);
|
||||
|
71
pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java
Normal file
71
pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link CPD}
|
||||
*/
|
||||
public class CPDTest {
|
||||
|
||||
private static final String BASE_TEST_RESOURCE_PATH = "src/test/resources/net/sourceforge/pmd/cpd/files/";
|
||||
|
||||
private CPD cpd;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
CPDConfiguration theConfiguration = new CPDConfiguration(new String[] {"--language", "java",
|
||||
"--minimum-tokens", "10"});
|
||||
cpd = new CPD(theConfiguration);
|
||||
}
|
||||
|
||||
/**
|
||||
* A broken symlink (which is basically a not existing file), should be skipped.
|
||||
* @throws Exception any error
|
||||
*/
|
||||
@Test
|
||||
public void testFileSectionWithBrokenSymlinks() throws Exception {
|
||||
cpd.setCpdListener(new NoFileAssertListener(0));
|
||||
|
||||
cpd.add(new File(BASE_TEST_RESOURCE_PATH, "this-is-a-broken-sym-link-for-test"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A file should be added only once - even if it was found twice, because of a sym link.
|
||||
* @throws Exception any error
|
||||
*/
|
||||
@Test
|
||||
public void testFileAddedAsSymlinkAndReal() throws Exception {
|
||||
cpd.setCpdListener(new NoFileAssertListener(1));
|
||||
|
||||
cpd.add(new File(BASE_TEST_RESOURCE_PATH, "real-file.txt"));
|
||||
cpd.add(new File(BASE_TEST_RESOURCE_PATH, "symlink-for-real-file.txt"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple listener that fails, if to many files were added and not skipped.
|
||||
*/
|
||||
private static class NoFileAssertListener implements CPDListener {
|
||||
private int maximumFilesAllowed;
|
||||
private int files;
|
||||
public NoFileAssertListener(int maximumFilesAllowed) {
|
||||
this.maximumFilesAllowed = maximumFilesAllowed;
|
||||
this.files = 0;
|
||||
}
|
||||
public void addedFile(int fileCount, File file) {
|
||||
files++;
|
||||
if (files > maximumFilesAllowed) {
|
||||
Assert.fail("File was added! - " + file);
|
||||
}
|
||||
}
|
||||
public void phaseUpdate(int phase) {
|
||||
// not needed for this test
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
real-file.txt
|
@ -0,0 +1 @@
|
||||
broken-sym-link
|
Reference in New Issue
Block a user