diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt
index c61eafe26c..a43ad74fc2 100644
--- a/pmd/etc/changelog.txt
+++ b/pmd/etc/changelog.txt
@@ -1,5 +1,6 @@
????? ??, 2013 - 5.0.4:
+Fixed bug 1080: net.sourceforge.pmd.cpd.CPDTest test failing
Fixed bug 1081: Regression: CPD skipping all files when using relative paths
Fixed bug 1082: CPD performance issue on larger projects
diff --git a/pmd/pom.xml b/pmd/pom.xml
index 9dac36b152..e7e3ad30e4 100644
--- a/pmd/pom.xml
+++ b/pmd/pom.xml
@@ -616,6 +616,12 @@
1.9.5
test
+
+ org.apache.commons
+ commons-lang3
+ 3.1
+ test
+
diff --git a/pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java b/pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java
index d110fec949..38a219ca38 100644
--- a/pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java
+++ b/pmd/src/test/java/net/sourceforge/pmd/cpd/CPDTest.java
@@ -5,6 +5,7 @@ package net.sourceforge.pmd.cpd;
import java.io.File;
+import org.apache.commons.lang3.SystemUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -14,14 +15,43 @@ import org.junit.Test;
*/
public class CPDTest {
- private static final String BASE_TEST_RESOURCE_PATH = "src/test/resources/net/sourceforge/pmd/cpd/files/";
+ private static final String BASE_TEST_RESOURCE_PATH = "target/test-classes/net/sourceforge/pmd/cpd/files/";
private CPD cpd;
+ private boolean canTestSymLinks = false;
+
@Before
- public void setup() {
+ public void setup() throws Exception {
CPDConfiguration theConfiguration = new CPDConfiguration(new String[] {"--language", "java",
"--minimum-tokens", "10"});
cpd = new CPD(theConfiguration);
+
+ // Symlinks are not well supported under Windows - so the tests are simply not executed here.
+ canTestSymLinks = SystemUtils.IS_OS_UNIX;
+ prepareSymLinks();
+
+ if (!canTestSymLinks) {
+ System.err.println("*** Skipping unit tests with symlinks.");
+ }
+ }
+
+ /**
+ * As java doesn't support symlinks in zip files, maven does not, too.
+ * So, we are creating the symlinks manually here before the test.
+ * @throws Exception any error
+ */
+ private void prepareSymLinks() throws Exception {
+ if (canTestSymLinks) {
+ Runtime runtime = Runtime.getRuntime();
+ if (!new File(BASE_TEST_RESOURCE_PATH, "symlink-for-real-file.txt").exists()) {
+ runtime.exec(new String[] {"ln", "-s", "real-file.txt",
+ BASE_TEST_RESOURCE_PATH + "symlink-for-real-file.txt"}).waitFor();
+ }
+ if (!new File(BASE_TEST_RESOURCE_PATH, "this-is-a-broken-sym-link-for-test").exists()) {
+ runtime.exec(new String[] {"ln", "-s", "broken-sym-link",
+ BASE_TEST_RESOURCE_PATH + "this-is-a-broken-sym-link-for-test"}).waitFor();
+ }
+ }
}
/**
@@ -30,11 +60,13 @@ public class CPDTest {
*/
@Test
public void testFileSectionWithBrokenSymlinks() throws Exception {
- NoFileAssertListener listener = new NoFileAssertListener(0);
- cpd.setCpdListener(listener);
+ if (canTestSymLinks) {
+ NoFileAssertListener listener = new NoFileAssertListener(0);
+ cpd.setCpdListener(listener);
- cpd.add(new File(BASE_TEST_RESOURCE_PATH, "this-is-a-broken-sym-link-for-test"));
- listener.verify();
+ cpd.add(new File(BASE_TEST_RESOURCE_PATH, "this-is-a-broken-sym-link-for-test"));
+ listener.verify();
+ }
}
/**
@@ -43,12 +75,14 @@ public class CPDTest {
*/
@Test
public void testFileAddedAsSymlinkAndReal() throws Exception {
- NoFileAssertListener listener = new NoFileAssertListener(1);
- cpd.setCpdListener(listener);
+ if (canTestSymLinks) {
+ NoFileAssertListener listener = new NoFileAssertListener(1);
+ cpd.setCpdListener(listener);
- cpd.add(new File(BASE_TEST_RESOURCE_PATH, "real-file.txt"));
- cpd.add(new File(BASE_TEST_RESOURCE_PATH, "symlink-for-real-file.txt"));
- listener.verify();
+ cpd.add(new File(BASE_TEST_RESOURCE_PATH, "real-file.txt"));
+ cpd.add(new File(BASE_TEST_RESOURCE_PATH, "symlink-for-real-file.txt"));
+ listener.verify();
+ }
}
/**
diff --git a/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/symlink-for-real-file.txt b/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/symlink-for-real-file.txt
deleted file mode 120000
index cf29a52983..0000000000
--- a/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/symlink-for-real-file.txt
+++ /dev/null
@@ -1 +0,0 @@
-real-file.txt
\ No newline at end of file
diff --git a/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/this-is-a-broken-sym-link-for-test b/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/this-is-a-broken-sym-link-for-test
deleted file mode 120000
index 8d8e4d3769..0000000000
--- a/pmd/src/test/resources/net/sourceforge/pmd/cpd/files/this-is-a-broken-sym-link-for-test
+++ /dev/null
@@ -1 +0,0 @@
-broken-sym-link
\ No newline at end of file