From 3462f3060541f0d3e156010899ad4b128f77e755 Mon Sep 17 00:00:00 2001 From: Gary Wu Date: Tue, 5 Sep 2017 16:59:20 -0700 Subject: Warn of dependencies missing in version manifest Change-Id: I5816e4de483d7c063c6316babc83c3dad75295ef Issue-ID: INT-124 Signed-off-by: Gary Wu --- version-manifest/pom.xml | 2 +- .../versionmanifest/VersionCheckMojo.java | 46 +++++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/version-manifest/pom.xml b/version-manifest/pom.xml index 5d3f56983..884199e6f 100644 --- a/version-manifest/pom.xml +++ b/version-manifest/pom.xml @@ -48,7 +48,7 @@ org.apache.maven.plugins maven-plugin-plugin - 3.2 + 3.4 version-manifest true diff --git a/version-manifest/src/main/java/org/onap/integration/versionmanifest/VersionCheckMojo.java b/version-manifest/src/main/java/org/onap/integration/versionmanifest/VersionCheckMojo.java index b26c1cdac..5d4e9a8fa 100644 --- a/version-manifest/src/main/java/org/onap/integration/versionmanifest/VersionCheckMojo.java +++ b/version-manifest/src/main/java/org/onap/integration/versionmanifest/VersionCheckMojo.java @@ -20,7 +20,9 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -58,8 +60,11 @@ public class VersionCheckMojo extends AbstractMojo { final Log log = getLog(); log.info("Checking version manifest " + manifest); + log.info(""); - Map expectedVersions = new HashMap<>(); + final List groupIdPrefixes = Arrays.asList("org.onap", "org.openecomp", "org.openo"); + + final Map expectedVersions = new HashMap<>(); try (InputStreamReader in = new InputStreamReader(getClass().getResourceAsStream(manifest), StandardCharsets.ISO_8859_1)) { @@ -79,8 +84,8 @@ public class VersionCheckMojo extends AbstractMojo { throw new MojoExecutionException(e.getMessage()); } - Map actualVersions = new HashMap<>(); - MavenProject parent = project.getParent(); + final Map actualVersions = new HashMap<>(); + final MavenProject parent = project.getParent(); if (parent != null) { log.debug("Parent: " + parent); actualVersions.put(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion()); @@ -93,16 +98,28 @@ public class VersionCheckMojo extends AbstractMojo { actualVersions.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion()); } - Set mismatches = new TreeSet<>(); - for (Entry expected : expectedVersions.entrySet()) { - String artifact = expected.getKey(); + final Set mismatches = new TreeSet<>(); + final Set missingArtifacts = new TreeSet<>(); + + for (Entry actualVersion : actualVersions.entrySet()) { + String artifact = actualVersion.getKey(); String expectedVersion = expectedVersions.get(artifact); - String actualVersion = actualVersions.get(artifact); - if (actualVersion != null && !actualVersion.equals(expectedVersion)) { + if (expectedVersion == null) { + if (artifact.startsWith("org.onap") || artifact.startsWith("org.openecomp")) { + missingArtifacts.add(artifact); + } + } else if (!expectedVersion.equals(actualVersion)) { mismatches.add(artifact); } } + // used for formatting + int[] columnWidths = new int[10]; + columnWidths[0] = actualVersions.keySet().stream().mapToInt(String::length).max().orElse(1); + columnWidths[1] = actualVersions.values().stream().mapToInt(String::length).max().orElse(1); + columnWidths[2] = expectedVersions.values().stream().mapToInt(String::length).max().orElse(1); + String format = " %-" + columnWidths[0] + "s" + " %" + columnWidths[1] + "s -> %" + columnWidths[2] + "s"; + if (mismatches.isEmpty()) { log.debug("No version mismatches found"); } else { @@ -110,11 +127,22 @@ public class VersionCheckMojo extends AbstractMojo { for (String artifact : mismatches) { String expectedVersion = expectedVersions.get(artifact); String actualVersion = actualVersions.get(artifact); + if (actualVersion != null && !actualVersion.equals(expectedVersion)) { - log.warn(" " + artifact + " " + actualVersion + " -> " + expectedVersion); + log.warn(String.format(format, artifact, actualVersion, expectedVersion)); } } } + log.info(""); + + if (!missingArtifacts.isEmpty()) { + log.warn("The following dependencies are missing in the version manifest:"); + for (String artifact : missingArtifacts) { + String actualVersion = actualVersions.get(artifact); + log.warn(String.format(format, artifact, actualVersion, "?")); + } + } + log.info(""); } } -- cgit 1.2.3-korg