summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/pmd-helper-plugin/src/main
diff options
context:
space:
mode:
authorGautam Shah <gautams@amdocs.com>2018-06-01 08:38:32 +0530
committerGAUTAMS <gautams@amdocs.com>2018-06-04 13:53:51 +0530
commit03205dad582ffa5db54187f451b9a29d3d0af386 (patch)
tree21e67f2a40764fe1b1904e58cd775c0041528352 /openecomp-be/tools/pmd-helper-plugin/src/main
parent06b1f35479a40194c6d84c38cc1215ae76b81ba6 (diff)
Fixing Merge Build issue and Sonar issues.
fixing build issue and Sonar issues. Change-Id: I4209b79ab2a3646839df50be4b58f8f230b6d710 Issue-ID: SDC-1189 Signed-off-by: GAUTAMS <gautams@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/pmd-helper-plugin/src/main')
-rw-r--r--openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java92
1 files changed, 60 insertions, 32 deletions
diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java
index 87c9ca5f1f..c80951ff50 100644
--- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java
+++ b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java
@@ -17,9 +17,9 @@
package org.openecomp.sdc.onboarding.pmd;
import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.getStateFile;
+import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.isReportEmpty;
import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.readCurrentPMDState;
import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.writeCurrentPMDState;
-import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.isReportEmpty;
import java.io.File;
import java.io.IOException;
@@ -28,7 +28,6 @@ import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -78,28 +77,19 @@ public class VerifyHelperMojo extends AbstractMojo {
if (project.getPackaging().equals(excludePackaging)) {
return;
}
- if (moduleCoordinates.equals(persistingModuleCoordinates)) {
- if (pmdStateFile.exists()) {
- pmdStateFile.delete();
- }
- }
- if (pmdCurrentStateFile == null) {
- pmdCurrentStateFile =
- getStateFile(pmdCurrentStateFilePath.substring(0, pmdCurrentStateFilePath.indexOf('/')), project,
- pmdCurrentStateFilePath);
- pmdCurrentStateFile.getParentFile().mkdirs();
- pmdReportFile.getParentFile().mkdirs();
- }
- if (PMDState.getHistoricState() != null && PMDState.getHistoricState().isEmpty()) {
- getLog().error("PMD Check is skipped. problem while loading data.");
- }
- if (Boolean.FALSE.equals(Boolean.valueOf(project.getProperties().getProperty(SKIP_PMD))) && !isReportEmpty(pmdReportFile)) {
+ init();
+ warnDataIssuesIfAny();
+
+ if (Boolean.FALSE.equals(Boolean.valueOf(project.getProperties().getProperty(SKIP_PMD))) && !isReportEmpty(
+ pmdReportFile)) {
Map<String, List<Violation>> data = readCurrentPMDState(pmdCurrentStateFile);
Map<String, List<Violation>> cv = readCurrentModulePMDReport();
data.putAll(cv);
+ boolean error = false;
if (!PMDState.getHistoricState().isEmpty() && !PMDHelperUtils
.evaluateCodeQuality(PMDState.getHistoricState(), cv,
pmdFailureReportLocation, getLog())) {
+ error = true;
if (validatePMDReport) {
throw new MojoFailureException(
"PMD Failures encountered. Build halted. For details refer " + pmdFailureReportLocation
@@ -111,39 +101,63 @@ public class VerifyHelperMojo extends AbstractMojo {
+ " and address them before committing this code in Version Control System. \u001B[0m");
}
}
+ String moduleChecksum = project.getProperties().getProperty("mainChecksum") + ":" + project.getProperties()
+ .getProperty(
+ "testChecksum");
+ data = reinitializeIfNeeded(!error, data);
+
Map<String, Object> checksumStore = HashMap.class.cast(data);
- checksumStore.put(moduleCoordinates,
- project.getProperties().getProperty("mainChecksum") + ":" + project.getProperties()
- .getProperty("testChecksum"));
- writeCurrentPMDState(pmdCurrentStateFile, data);
+ if (!moduleChecksum.equals(checksumStore.get(moduleCoordinates))) {
+ checksumStore.put(moduleCoordinates, moduleChecksum);
+ writeCurrentPMDState(pmdCurrentStateFile, data);
+ }
}
if (Boolean.FALSE.equals(Boolean.valueOf(project.getProperties().getProperty(SKIP_PMD)))) {
- if (isReportEmpty(pmdReportFile)){
+ if (isReportEmpty(pmdReportFile)) {
HashMap data = HashMap.class.cast(readCurrentPMDState(pmdCurrentStateFile));
data.put(moduleCoordinates,
- project.getProperties().getProperty("mainChecksum") + ":" + project.getProperties()
- .getProperty("testChecksum"));
+ project.getProperties().getProperty("mainChecksum") + ":" + project.getProperties().getProperty(
+ "testChecksum"));
writeCurrentPMDState(pmdCurrentStateFile, data);
}
pmdReportFile.delete();
}
+ removeProcessFiles();
+
+ }
+
+ private void removeProcessFiles() {
+ if (moduleCoordinates.equals(persistingModuleCoordinates) && pmdStateFile.exists()) {
+ pmdStateFile.delete();
+ }
if (pmdTargetLocation.exists()) {
pmdTargetLocation.delete();
}
+ }
+
+ private void init() {
+ if (pmdCurrentStateFile == null) {
+ setPmdCurrentStateFile(
+ getStateFile(pmdCurrentStateFilePath.substring(0, pmdCurrentStateFilePath.indexOf('/')), project,
+ pmdCurrentStateFilePath));
+
+ pmdReportFile.getParentFile().mkdirs();
+ }
+ }
+ private static void setPmdCurrentStateFile(File file) {
+ pmdCurrentStateFile = file;
+ pmdCurrentStateFile.getParentFile().mkdirs();
}
private Map<String, List<Violation>> readCurrentModulePMDReport() {
try {
PMDState.reset(compiledFilesList, compiledTestFilesList, moduleCoordinates);
if (pmdReportFile.exists()) {
- boolean isFirst = true;
- for (String line : Files.lines(pmdReportFile.toPath()).collect(Collectors.toList())) {
- if (isFirst) {
- isFirst = false;
- } else {
- PMDState.addViolation(line, moduleCoordinates);
- }
+ List<String> lines = Files.readAllLines(pmdReportFile.toPath());
+ lines.remove(0);
+ for (String line : lines) {
+ PMDState.addViolation(line, moduleCoordinates);
}
}
} catch (IOException ioe) {
@@ -152,4 +166,18 @@ public class VerifyHelperMojo extends AbstractMojo {
return PMDState.getState();
}
+ private void warnDataIssuesIfAny() {
+ if (PMDState.getHistoricState() != null && PMDState.getHistoricState().isEmpty()) {
+ getLog().error("PMD Check is skipped. problem while loading data.");
+ }
+ }
+
+ private Map<String, List<Violation>> reinitializeIfNeeded(boolean required, Map<String, List<Violation>> orig) {
+ if (required) {
+ return readCurrentPMDState(pmdCurrentStateFile);
+ } else {
+ return orig;
+ }
+ }
+
}