36 lines
1.4 KiB
Plaintext
36 lines
1.4 KiB
Plaintext
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
|
|
String readFile(File file) throws IOException {
|
|
StringBuilder content = new StringBuilder();
|
|
for (String line : Files.readAllLines(file.toPath(), StandardCharsets.UTF_8)) {
|
|
content.append(line).append(System.lineSeparator());
|
|
}
|
|
return content.toString();
|
|
}
|
|
|
|
File buildLogPath = new File(basedir, "build.log");
|
|
String buildLog = readFile(buildLogPath);
|
|
if (!buildLog.contains("[INFO] CPD Failure: Found 7 lines of duplicated code at locations:")) {
|
|
throw new RuntimeException("No CPD failures detected, did CPD run?");
|
|
}
|
|
if (!buildLog.contains("cpd-for-javascript/src/main/js/globalVariable.js line 1")) {
|
|
throw new RuntimeException("No CPD failures detected, did CPD run?");
|
|
}
|
|
|
|
File cpdXmlReport = new File(basedir, "target/cpd.xml");
|
|
if(!cpdXmlReport.exists())
|
|
{
|
|
throw new FileNotFoundException("Could not find cpd xml report: " + cpdXmlReport);
|
|
}
|
|
String cpdXml = readFile(cpdXmlReport);
|
|
if (!cpdXml.contains("<duplication lines=\"7\" tokens=\"21\">")) {
|
|
throw new RuntimeException("Expected duplication has not been reported");
|
|
}
|
|
if (!cpdXml.contains("cpd-for-javascript/src/main/js/globalVariable.js\"/>")) {
|
|
throw new RuntimeException("Expected duplication has not been reported");
|
|
}
|