From 1929d75c6856e212979c3a9c7950dfd717d3bb98 Mon Sep 17 00:00:00 2001 From: vempo Date: Sun, 12 Aug 2018 14:17:59 +0300 Subject: Removed execution of PMD from build Change-Id: I52d55e2585c56118c685745c00e52c2838b76d04 Issue-ID: SDC-1065 Signed-off-by: vempo --- openecomp-be/pom.xml | 88 -------- openecomp-be/tools/artifact-copy-plugin/pom.xml | 3 +- openecomp-be/tools/build-data-installer/pom.xml | 28 +-- openecomp-be/tools/pmd-helper-plugin/pom.xml | 46 ---- .../onboarding/pmd/InitializationHelperMojo.java | 111 ---------- .../sdc/onboarding/pmd/PMDHelperUtils.java | 243 --------------------- .../org/openecomp/sdc/onboarding/pmd/PMDState.java | 74 ------- .../org/openecomp/sdc/onboarding/pmd/Table.java | 107 --------- .../sdc/onboarding/pmd/VerifyHelperMojo.java | 185 ---------------- .../openecomp/sdc/onboarding/pmd/Violation.java | 56 ----- .../src/main/resources/pmd-empty.xml | 6 - 11 files changed, 2 insertions(+), 945 deletions(-) delete mode 100644 openecomp-be/tools/pmd-helper-plugin/pom.xml delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/InitializationHelperMojo.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDHelperUtils.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDState.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Table.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Violation.java delete mode 100644 openecomp-be/tools/pmd-helper-plugin/src/main/resources/pmd-empty.xml (limited to 'openecomp-be') diff --git a/openecomp-be/pom.xml b/openecomp-be/pom.xml index b603499d5e..6cfc23a7a8 100644 --- a/openecomp-be/pom.xml +++ b/openecomp-be/pom.xml @@ -87,13 +87,6 @@ org.openecomp.sdc.onboarding compile-helper-plugin ${project.version} - - - org.openecomp.sdc.onboarding - pmd-helper-plugin - ${project.version} - - @@ -116,87 +109,6 @@ - - org.apache.maven.plugins - maven-pmd-plugin - ${maven.pmd.plugin.version} - - - org.openecomp.sdc - build-tools - ${build.tools.version} - - - net.sourceforge.pmd - pmd-core - ${pmd.core.version} - - - net.sourceforge.pmd - pmd-java - ${pmd.java.version} - - - - ${skipPMD} - false - false - ${project.build.directory}/pmd/pmd.cache - false - false - csv - ${project.build.directory}/pmd - true - false - false - - /category/java/bestpractices.xml - /category/java/codestyle.xml - /category/java/design.xml - /category/java/errorprone.xml - /category/java/multithreading.xml - /category/java/performance.xml - /category/java/security.xml - - - - - - check - - integration-test - - - - - org.openecomp.sdc.onboarding - pmd-helper-plugin - ${project.version} - - - - init-pmd-helper - post-verify-helper - - - - - pom - ${project.build.directory}/pmd/pmd.xml - ${project.build.directory}/pmd.txt - ${project.build.directory}/pmd/pmd.csv - org.openecomp.sdc:build-data-installer - org.openecomp.sdc:sdc-onboarding/target/build-data/pmdState.dat - - ${project.build.outputDirectory}/pmd.dat - - ${project.build.directory}/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst - - - ${project.build.directory}/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst - - - org.apache.maven.plugins maven-jar-plugin diff --git a/openecomp-be/tools/artifact-copy-plugin/pom.xml b/openecomp-be/tools/artifact-copy-plugin/pom.xml index b06b4a9e58..7eb7d4c6fc 100644 --- a/openecomp-be/tools/artifact-copy-plugin/pom.xml +++ b/openecomp-be/tools/artifact-copy-plugin/pom.xml @@ -11,10 +11,9 @@ sdc-onboarding org.openecomp.sdc 1.3.0-SNAPSHOT - ../../../onboarding + ../../../onboarding/pom.xml - true classes/**/*.class maven-status/** true diff --git a/openecomp-be/tools/build-data-installer/pom.xml b/openecomp-be/tools/build-data-installer/pom.xml index 2d79e472e9..74890ad55d 100644 --- a/openecomp-be/tools/build-data-installer/pom.xml +++ b/openecomp-be/tools/build-data-installer/pom.xml @@ -4,42 +4,16 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.openecomp.sdc build-data-installer sdc-onboarding org.openecomp.sdc 1.3.0-SNAPSHOT - ../../../onboarding + ../../../onboarding/pom.xml - - true - - - org.openecomp.sdc.onboarding - pmd-helper-plugin - ${project.version} - - - - init-pmd-helper - post-verify-helper - - - - - pom - ${project.build.directory}/pmd/pmd.xml - ${project.build.directory}/pmd/pmd.csv - ${project.build.directory}/pmd.txt - org.openecomp.sdc:build-data-installer - org.openecomp.sdc:sdc-onboarding/target/build-data/pmdState.dat - ${project.build.outputDirectory}/pmd.dat - - org.openecomp.sdc.onboarding artifact-copy-plugin diff --git a/openecomp-be/tools/pmd-helper-plugin/pom.xml b/openecomp-be/tools/pmd-helper-plugin/pom.xml deleted file mode 100644 index 2442ae5401..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - 4.0.0 - - org.openecomp.sdc.onboarding - pmd-helper-plugin - maven-plugin - - - sdc-onboarding - org.openecomp.sdc - 1.3.0-SNAPSHOT - ../../../onboarding - - - true - classes/**/*.class - maven-status/** - - - - - org.apache.maven - maven-core - ${maven-core.version} - - - org.apache.maven.plugin-tools - maven-plugin-annotations - ${maven-plugin-annotations.version} - - - - - - - org.apache.maven.plugins - maven-plugin-plugin - ${maven-plugin-plugin.version} - - - - - \ No newline at end of file diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/InitializationHelperMojo.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/InitializationHelperMojo.java deleted file mode 100644 index 5b4d5fd131..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/InitializationHelperMojo.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2018 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on a "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openecomp.sdc.onboarding.pmd; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.List; -import java.util.Map; - -import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.*; - -@Mojo(name = "init-pmd-helper", threadSafe = true, defaultPhase = LifecyclePhase.PREPARE_PACKAGE, - requiresDependencyResolution = ResolutionScope.NONE) -public class InitializationHelperMojo extends AbstractMojo { - - private static final String SKIP_PMD = "skipPMD"; - - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}") - private String moduleCoordinates; - @Parameter - private File pmdTargetLocation; - @Parameter - private File pmdReportFile; - @Parameter - private String persistingModuleCoordinates; - @Parameter - private File pmdStateFile; - @Parameter - private String pmdCurrentStateFilePath; - @Parameter - private String excludePackaging; - - static { - PMDState.setHistoricState(readCurrentPMDState("pmd.dat")); - } - - public void execute() throws MojoExecutionException, MojoFailureException { - if (project.getPackaging().equals(excludePackaging)) { - return; - } - if (moduleCoordinates.equals(persistingModuleCoordinates)) { - pmdStateFile.getParentFile().mkdirs(); - try (OutputStream os = new FileOutputStream(pmdStateFile); - ObjectOutputStream oos = new ObjectOutputStream(os)) { - File f = getStateFile(pmdCurrentStateFilePath.substring(0, pmdCurrentStateFilePath.indexOf('/')), - project, pmdCurrentStateFilePath); - Map> data = readCurrentPMDState(f); - if (PMDState.getHistoricState() != null) { - PMDState.getHistoricState().putAll(data); - oos.writeObject(PMDState.getHistoricState()); - } else { - oos.writeObject(data); - } - if (Paths.get(f.getParentFile().getAbsolutePath(), "compileState.dat").toFile().exists()) { - Files.copy(Paths.get(f.getParentFile().getAbsolutePath(), "compileState.dat"), - Paths.get(pmdStateFile.getParentFile().getAbsolutePath(), "compile.dat"), - StandardCopyOption.REPLACE_EXISTING); - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } - return; - } - if (project.getProperties().containsKey(SKIP_PMD) && Boolean.TRUE.equals(Boolean.valueOf( - project.getProperties().getProperty(SKIP_PMD)))) { - return; - } - pmdTargetLocation.getParentFile().mkdirs(); - try (InputStream is = this.getClass().getResourceAsStream("/pmd-empty.xml"); - OutputStream os = new FileOutputStream(pmdTargetLocation)) { - String text = readInputStream(is); - os.write(text.getBytes()); - } catch (IOException ioe) { - throw new UncheckedIOException(ioe); - } - } - -} diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDHelperUtils.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDHelperUtils.java deleted file mode 100644 index 55f6175184..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDHelperUtils.java +++ /dev/null @@ -1,243 +0,0 @@ -package org.openecomp.sdc.onboarding.pmd; - -import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.OutputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class PMDHelperUtils { - - private PMDHelperUtils() { - // default constructor. donot remove. - } - - private static Map pmdLink = new HashMap<>(); - - static { - pmdLink.put("one", "errorprone"); - pmdLink.put("ign", "design"); - pmdLink.put("ing", "multithreading"); - pmdLink.put("nce", "performance"); - pmdLink.put("ity", "security"); - pmdLink.put("yle", "codestyle"); - pmdLink.put("ces", "bestpractices"); - } - - static String readInputStream(InputStream is) { - try (Scanner s = new Scanner(is).useDelimiter("\\A")) { - return s.hasNext() ? s.next() : ""; - } - } - - static File getStateFile(String moduleCoordinate, MavenProject proj, String filePath) { - return new File(getTopParentProject(moduleCoordinate, proj).getBasedir(), - filePath.substring(filePath.indexOf('/') + 1)); - } - - private static MavenProject getTopParentProject(String moduleCoordinate, MavenProject proj) { - if (getModuleCoordinate(proj).equals(moduleCoordinate) || proj.getParent() == null) { - return proj; - } else { - return getTopParentProject(moduleCoordinate, proj.getParent()); - } - } - - private static String getModuleCoordinate(MavenProject project) { - return project.getGroupId() + ":" + project.getArtifactId(); - } - - private static T readState(String fileName, Class clazz) { - try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); - ObjectInputStream ois = new ObjectInputStream(is)) { - return clazz.cast(ois.readObject()); - } catch (Exception ioe) { - return null; - } - } - - static T readState(File file, Class clazz) { - try (InputStream is = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(is)) { - return clazz.cast(ois.readObject()); - } catch (Exception ioe) { - return null; - } - } - - static boolean evaluateCodeQuality(Map> stats, Map> current, - File file, Log logger) { - boolean qualityCheckPassed = true; - Map table = new HashMap<>(); - Set classes = current.keySet(); - int counter = 0; - for (String clazz : classes) { - List orgViolation = stats.get(clazz) == null ? new ArrayList<>() : stats.get(clazz); - List currViolation = current.get(clazz) == null ? new ArrayList<>() : current.get(clazz); - if (diffViolation(orgViolation, currViolation) > 0) { - Map lDetails = diffCategory(orgViolation, currViolation); - for (String cat : lDetails.keySet()) { - String lineNo = getLineNumbers(currViolation, cat); - table.put(++counter + clazz, cat + ":" + lDetails.get(cat) + ":" + lineNo); - } - } - } - if (!table.isEmpty()) { - qualityCheckPassed = false; - try { - Files.write(file.toPath(), - new Table(getTableHeaders(true), getContents(table, true)).drawTable().getBytes(), - StandardOpenOption.CREATE); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - logger.error(new Table(getTableHeaders(false), getContents(table, false)).drawTable()); - } - return qualityCheckPassed; - } - - private static ArrayList getTableHeaders(boolean addLink) { - ArrayList list = new ArrayList<>(); - list.add("Class Name"); - list.add("Rule Category"); - list.add("Rule Name"); - list.add("Fix"); - list.add("Source Line No"); - if (addLink) { - list.add("Help Link"); - } - return list; - } - - private static ArrayList> getContents(Map data, boolean addLink) { - ArrayList> list = new ArrayList<>(); - Pattern p = Pattern.compile("(.*):(.*):(.*):(.*)"); - for (String s : data.keySet()) { - ArrayList l = new ArrayList<>(); - l.add(s.substring(s.indexOf("::") + 2)); - Matcher m = p.matcher(data.get(s)); - if (m.find()) { - l.add(m.group(1)); - l.add(m.group(2)); - l.add(m.group(3) + " at least"); - l.add(m.group(4)); - if (addLink) { - l.add("http://pmd.sourceforge.net/snapshot/pmd_rules_java_" + getLinkCategory(m.group(1)) + ".html#" - + m.group(2).toLowerCase()); - } - } - list.add(l); - } - return list; - } - - private static String getLinkCategory(String cat) { - for (String category : pmdLink.keySet()) { - if (cat.contains(category)) { - return pmdLink.get(category); - } - } - return "ERROR"; - } - - private static int diffViolation(List org, List curr) { - int diff = 0; - if (org == null || org.isEmpty()) { - if (curr != null && !curr.isEmpty()) { - diff = curr.size(); - } - } else { - if (curr != null && !curr.isEmpty()) { - diff = curr.size() - org.size(); - } - } - return diff; - } - - private static Map diffCategory(List org, List curr) { - Map currData = new HashMap<>(); - Map orgData = new HashMap<>(); - countViolations(curr, currData); - countViolations(org, orgData); - Map val = new HashMap<>(); - for (String cat : currData.keySet()) { - if (orgData.get(cat) == null) { - val.put(cat, currData.get(cat).intValue()); - } else if (currData.get(cat).intValue() > orgData.get(cat).intValue()) { - val.put(cat, currData.get(cat).intValue() - orgData.get(cat).intValue()); - } - } - return val; - } - - private static void countViolations(List violations, Map store){ - for (Violation v : violations) { - if (store.get(v.getCategory() + ":" + v.getRule()) == null) { - store.put(v.getCategory() + ":" + v.getRule(), new AtomicInteger(1)); - } else { - store.get(v.getCategory() + ":" + v.getRule()).incrementAndGet(); - } - } - } - - private static void processOriginalViolations(List org){ - - } - private static String getLineNumbers(List vList, String category) { - String val = ""; - boolean firstOver = false; - for (Violation v : vList) { - if (category.equals(v.getCategory() + ":" + v.getRule())) { - if (firstOver) { - val += ","; - } - val += v.getLine(); - firstOver = true; - } - } - return val; - } - - static Map> readCurrentPMDState(String fileName) { - Map> val = readState(fileName, HashMap.class); - return val == null ? new HashMap<>() : val; - } - - static Map> readCurrentPMDState(File file) { - Map> val = readState(file, HashMap.class); - return val == null ? new HashMap<>() : val; - } - - static void writeCurrentPMDState(File file, Map> data) { - try (OutputStream os = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(os)) { - oos.writeObject(data); - } catch (IOException ioe) { - throw new UncheckedIOException(ioe); - } - } - - static boolean isReportEmpty(File reportFile){ - try { - return !reportFile.exists() || Files.readAllLines(reportFile.toPath()).size()<=1; - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } -} diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDState.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDState.java deleted file mode 100644 index 2602fff2c6..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/PMDState.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.openecomp.sdc.onboarding.pmd; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class PMDState { - - private static Map> data = new HashMap<>(); - private static Map> historicState = null; - private static Pattern p = - Pattern.compile("\"(.*)\",\"(.*)\",\"(.*)\",\"(.*)\",\"(.*)\",\"(.*)\",\"(.*)\",\"(.*)\""); - - public static boolean addViolation(String line, String fileLocation) { - Matcher m = p.matcher(line); - if (m.find()) { - if (m.group(3).indexOf("generated-sources") != -1) { - return true; - } - String mainOrTest = - m.group(3).indexOf(File.separator + "test" + File.separator) == -1 ? "[MAIN] " : "[TEST] "; - List list = data.get(fileLocation + "::" + mainOrTest + m.group(2) + "." + m.group(3).substring( - m.group(3).lastIndexOf(File.separatorChar) + 1)); - if (list == null) { - list = new LinkedList<>(); - data.put(fileLocation + "::" + mainOrTest + m.group(2) + "." + m.group(3).substring( - m.group(3).lastIndexOf(File.separatorChar) + 1), list); - } - - list.add(new Violation(m.group(7), m.group(8), m.group(6), Integer.parseInt(m.group(4)), - Integer.parseInt(m.group(5)))); - return true; - } - return false; - } - - public static void reset(File mainFile, File testFile, String moduleCoordinates) throws IOException { - data.clear(); - init(mainFile, moduleCoordinates, "[MAIN] "); - init(testFile, moduleCoordinates, "[TEST] "); - } - - private static void init(File file, String moduleCoordinates, String maiOrTest) throws IOException { - if (file.exists()) { - List coll = Files.readAllLines(file.toPath()); - for (String line : coll) { - if (line.indexOf("$") == -1) { - data.put(moduleCoordinates + "::" + maiOrTest + line.substring(0, line.indexOf('.')) - .replace(File.separator, ".") + ".java", - new LinkedList<>()); - } - } - } - } - - public static Map> getState() { - return data; - } - - public static void setHistoricState(Map> data) { - historicState = data; - } - - public static Map> getHistoricState() { - return historicState; - } - -} diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Table.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Table.java deleted file mode 100644 index 68eafd0117..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Table.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2018 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on a "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openecomp.sdc.onboarding.pmd; - -import java.util.ArrayList; -import java.util.List; - -public class Table { - - private final int TABLEPADDING = 1; - private final char SEPERATOR_CHAR = '-'; - - private ArrayList headers; - private ArrayList> table; - private ArrayList maxLength; - - public Table(ArrayList headersIn, ArrayList> content) { - this.headers = headersIn; - this.maxLength = new ArrayList(); - for (int i = 0; i < headers.size(); i++) { - maxLength.add(headers.get(i).length()); - } - this.table = content; - calcMaxLengthAll(); - } - - public String drawTable() { - StringBuilder sb = new StringBuilder(); - StringBuilder sbRowSep = new StringBuilder(); - StringBuffer padder = new StringBuffer(); - String rowSeperator = ""; - - for (int i = 0; i < TABLEPADDING; i++) { - padder.append(" "); - } - - for (int i = 0; i < maxLength.size(); i++) { - sbRowSep.append("|"); - for (int j = 0; j < maxLength.get(i) + (TABLEPADDING * 2); j++) { - sbRowSep.append(SEPERATOR_CHAR); - } - } - sbRowSep.append("|"); - rowSeperator = sbRowSep.toString(); - - sb.append(rowSeperator); - sb.append("\n"); - sb.append("|"); - for (int i = 0; i < headers.size(); i++) { - sb.append(padder); - sb.append(headers.get(i)); - for (int k = 0; k < (maxLength.get(i) - headers.get(i).length()); k++) { - sb.append(" "); - } - sb.append(padder); - sb.append("|"); - } - sb.append("\n"); - sb.append(rowSeperator); - sb.append("\n"); - - for (int i = 0; i < table.size(); i++) { - ArrayList tempRow = table.get(i); - sb.append("|"); - for (int j = 0; j < tempRow.size(); j++) { - sb.append(padder); - sb.append(tempRow.get(j)); - for (int k = 0; k < (maxLength.get(j) - tempRow.get(j).length()); k++) { - sb.append(" "); - } - sb.append(padder); - sb.append("|"); - } - sb.append("\n"); - sb.append(rowSeperator); - sb.append("\n"); - } - return sb.toString(); - } - - private void calcMaxLengthAll() { - for (int i = 0; i < table.size(); i++) { - List temp = table.get(i); - for (int j = 0; j < temp.size(); j++) { - if (temp.get(j).length() > maxLength.get(j)) { - maxLength.set(j, temp.get(j).length()); - } - } - } - } - -} - 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 deleted file mode 100644 index 0785696ca0..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/VerifyHelperMojo.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright © 2018 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on a "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openecomp.sdc.onboarding.pmd; - -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; -import org.apache.maven.project.MavenProject; - -import java.io.File; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.openecomp.sdc.onboarding.pmd.PMDHelperUtils.*; - -@Mojo(name = "post-verify-helper", threadSafe = true, defaultPhase = LifecyclePhase.VERIFY, - requiresDependencyResolution = ResolutionScope.NONE) -public class VerifyHelperMojo extends AbstractMojo { - - private static final String SKIP_PMD = "skipPMD"; - - @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; - @Parameter(defaultValue = "${project.artifact.groupId}:${project.artifact.artifactId}") - private String moduleCoordinates; - @Parameter(defaultValue = "${session}") - private MavenSession session; - @Parameter - private File pmdTargetLocation; - @Parameter - private File pmdReportFile; - @Parameter - private File pmdStateFile; - @Parameter - private String pmdCurrentStateFilePath; - @Parameter - private String excludePackaging; - @Parameter - private Boolean validatePMDReport = Boolean.FALSE; - @Parameter - private String persistingModuleCoordinates; - @Parameter - private File pmdFailureReportLocation; - @Parameter - private File compiledFilesList; - @Parameter - private File compiledTestFilesList; - - private static File pmdCurrentStateFile; - - public void execute() throws MojoExecutionException, MojoFailureException { - if (project.getPackaging().equals(excludePackaging)) { - return; - } - init(); - warnDataIssuesIfAny(); - - if (Boolean.FALSE.equals(Boolean.valueOf(project.getProperties().getProperty(SKIP_PMD))) && !isReportEmpty( - pmdReportFile)) { - Map> data = readCurrentPMDState(pmdCurrentStateFile); - Map> 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 - .getAbsolutePath()); - } else { - getLog().error( - "\u001B[31m\u001B[1m Code Quality concerns raised by Quality Management System. For details refer " - + pmdFailureReportLocation.getAbsolutePath() - + " 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 checksumStore = HashMap.class.cast(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)) { - HashMap data = HashMap.class.cast(readCurrentPMDState(pmdCurrentStateFile)); - data.put(moduleCoordinates, - project.getProperties().getProperty("mainChecksum") + ":" + project.getProperties().getProperty( - "testChecksum")); - writeCurrentPMDState(pmdCurrentStateFile, data); - } - pmdReportFile.delete(); - } - removeProcessFiles(); - - } - - private void removeProcessFiles() { - if (moduleCoordinates.equals(persistingModuleCoordinates) && pmdStateFile.exists()) { - for (File file : pmdStateFile.getParentFile().listFiles()) { - if (file.isFile()) { - file.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> readCurrentModulePMDReport() { - try { - PMDState.reset(compiledFilesList, compiledTestFilesList, moduleCoordinates); - if (pmdReportFile.exists()) { - List lines = Files.readAllLines(pmdReportFile.toPath()); - lines.remove(0); - for (String line : lines) { - PMDState.addViolation(line, moduleCoordinates); - } - } - } catch (IOException ioe) { - throw new UncheckedIOException(ioe); - } - 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> reinitializeIfNeeded(boolean required, Map> orig) { - if (required) { - return readCurrentPMDState(pmdCurrentStateFile); - } else { - return orig; - } - } - -} diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Violation.java b/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Violation.java deleted file mode 100644 index b0cafc474f..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/java/org/openecomp/sdc/onboarding/pmd/Violation.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2018 European Support Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on a "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openecomp.sdc.onboarding.pmd; - -import java.io.Serializable; - -public class Violation implements Serializable { - - private final String category; - private final String rule; - private final String description; - private final int priority; - private final int line; - - public String getCategory() { - return category; - } - - public String getRule() { - return rule; - } - - public int getPriority() { - return priority; - } - - public int getLine() { - return line; - } - - public Violation(String category, String rule, String description, int priority, int line) { - this.category = category; - this.rule = rule; - this.description = description; - this.priority = priority; - this.line = line; - } - - public String toString() { - return category + ":" + rule + ":" + getPriority() + description + ":" + line; - } -} diff --git a/openecomp-be/tools/pmd-helper-plugin/src/main/resources/pmd-empty.xml b/openecomp-be/tools/pmd-helper-plugin/src/main/resources/pmd-empty.xml deleted file mode 100644 index c23b533c81..0000000000 --- a/openecomp-be/tools/pmd-helper-plugin/src/main/resources/pmd-empty.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - -- cgit 1.2.3-korg