diff options
Diffstat (limited to 'openecomp-be/tools/pmd-helper-plugin/src')
-rw-r--r-- | openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java | 92 |
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; + } + } + } |