summaryrefslogtreecommitdiffstats
path: root/version-manifest
diff options
context:
space:
mode:
Diffstat (limited to 'version-manifest')
-rw-r--r--version-manifest/pom.xml19
-rw-r--r--version-manifest/src/main/java/org/onap/integration/versionmanifest/VersionCheckMojo.java79
-rw-r--r--version-manifest/src/main/resources/java-manifest.csv2
3 files changed, 83 insertions, 17 deletions
diff --git a/version-manifest/pom.xml b/version-manifest/pom.xml
index 5d3f56983..331f357ad 100644
--- a/version-manifest/pom.xml
+++ b/version-manifest/pom.xml
@@ -48,7 +48,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
- <version>3.2</version>
+ <version>3.4</version>
<configuration>
<goalPrefix>version-manifest</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
@@ -68,6 +68,23 @@
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>2.2.3</version>
+ <executions>
+ <execution>
+ <phase>validate</phase>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
+ <generateGitPropertiesFile>true</generateGitPropertiesFile>
+ </configuration>
+ </plugin>
</plugins>
</build>
</project>
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..d6e5d4ca6 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
@@ -17,18 +17,22 @@
package org.onap.integration.versionmanifest;
import java.io.IOException;
+import java.io.InputStream;
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.Properties;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
-import org.apache.maven.model.Dependency;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
@@ -57,9 +61,22 @@ public class VersionCheckMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
final Log log = getLog();
- log.info("Checking version manifest " + manifest);
+ final Properties gitProps = new Properties();
+ try (InputStream in = getClass().getResourceAsStream("/git.properties")) {
+ gitProps.load(in);
+ } catch (IOException e) {
+ log.error(e);
+ throw new MojoExecutionException(e.getMessage());
+ }
+
+ log.info("Manifest version: " + gitProps.getProperty("git.build.time") + " "
+ + gitProps.getProperty("git.commit.id") + " " + gitProps.getProperty("git.remote.origin.url"));
- Map<String, String> expectedVersions = new HashMap<>();
+ log.info("");
+
+ final List<String> groupIdPrefixes = Arrays.asList("org.onap", "org.openecomp", "org.openo");
+
+ final Map<String, String> expectedVersions = new HashMap<>();
try (InputStreamReader in = new InputStreamReader(getClass().getResourceAsStream(manifest),
StandardCharsets.ISO_8859_1)) {
@@ -79,30 +96,49 @@ public class VersionCheckMojo extends AbstractMojo {
throw new MojoExecutionException(e.getMessage());
}
- Map<String, String> actualVersions = new HashMap<>();
- MavenProject parent = project.getParent();
+ final Map<String, String> actualVersions = new HashMap<>();
+ final MavenProject parent = project.getParent();
if (parent != null) {
log.debug("Parent: " + parent);
- actualVersions.put(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion());
+ // don't warn within the same groupId
+ if (!project.getGroupId().equals(parent.getGroupId())) {
+ actualVersions.put(parent.getGroupId() + ":" + parent.getArtifactId(), parent.getVersion());
+ }
} else {
log.debug("No parent");
}
- for (Dependency dep : project.getDependencies()) {
- log.debug("Dependency: " + dep.toString());
- actualVersions.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion());
+ for (Artifact dep : project.getDependencyArtifacts()) {
+ log.debug("DependencyArtifact: " + dep.toString());
+ // don't warn within the same groupId
+ if (!project.getGroupId().equals(dep.getGroupId())) {
+ actualVersions.put(dep.getGroupId() + ":" + dep.getArtifactId(), dep.getVersion());
+ }
}
- Set<String> mismatches = new TreeSet<>();
- for (Entry<String, String> expected : expectedVersions.entrySet()) {
- String artifact = expected.getKey();
+ final Set<String> mismatches = new TreeSet<>();
+ final Set<String> missingArtifacts = new TreeSet<>();
+
+ for (Entry<String, String> actualVersionEntry : actualVersions.entrySet()) {
+ String artifact = actualVersionEntry.getKey();
+ String actualVersion = actualVersionEntry.getValue();
String expectedVersion = expectedVersions.get(artifact);
- String actualVersion = actualVersions.get(artifact);
- if (actualVersion != null && !actualVersion.equals(expectedVersion)) {
+ if (expectedVersion == null) {
+ if (groupIdPrefixes.stream().anyMatch(prefix -> artifact.startsWith(prefix))) {
+ 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,10 +146,23 @@ 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.warn("");
+ }
+
+ if (missingArtifacts.isEmpty()) {
+ log.debug("No artifacts found missing in the version manifest");
+ } else {
+ 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.warn("");
}
}
diff --git a/version-manifest/src/main/resources/java-manifest.csv b/version-manifest/src/main/resources/java-manifest.csv
index 8baa86884..f6bb6ec29 100644
--- a/version-manifest/src/main/resources/java-manifest.csv
+++ b/version-manifest/src/main/resources/java-manifest.csv
@@ -1,2 +1,2 @@
groupId,artifactId,version
-org.onap.oparent,oparent,0.1.0
+org.onap.oparent,oparent,0.1.1