diff options
author | Gary Wu <gary.i.wu@huawei.com> | 2017-09-01 12:45:12 -0700 |
---|---|---|
committer | Gary Wu <gary.i.wu@huawei.com> | 2017-09-01 12:45:12 -0700 |
commit | 632c23e1bc6772b4471f8de19c761aaca909956a (patch) | |
tree | 97d799da31e87f3a5a9315a6fbe5b519ee71d90f | |
parent | b49dc6b5ba9b8c893dcdbbed296a6633cefbf906 (diff) |
Move version-check into integration repo
Change-Id: Id3d3140ca20500970e470ca9ea32ca7329a5b1b9
Issue-ID: INT-124
Signed-off-by: Gary Wu <gary.i.wu@huawei.com>
-rw-r--r-- | version-manifest/pom.xml | 74 | ||||
-rw-r--r-- | version-manifest/src/main/docker-manifest.csv (renamed from versions/docker-manifest.csv) | 0 | ||||
-rw-r--r-- | version-manifest/src/main/java-manifest.csv (renamed from versions/java-manifest.csv) | 0 | ||||
-rw-r--r-- | version-manifest/src/main/java/org/onap/oparent/versioncheck/VersionCheckMojo.java | 121 | ||||
-rw-r--r-- | version.properties | 14 |
5 files changed, 209 insertions, 0 deletions
diff --git a/version-manifest/pom.xml b/version-manifest/pom.xml new file mode 100644 index 000000000..11318e612 --- /dev/null +++ b/version-manifest/pom.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onap.oparent</groupId> + <artifactId>version</artifactId> + <version>0.1.0</version> + </parent> + <groupId>org.onap.integration</groupId> + <artifactId>version-manifest</artifactId> + <packaging>maven-plugin</packaging> + <name>ONAP Version Manifest and Maven Plugin</name> + <url>https://www.onap.org</url> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <mavenVersion>3.2.3</mavenVersion> + </properties> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>2.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>3.0.8</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${mavenVersion}</version> + </dependency> + <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv --> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-csv</artifactId> + <version>1.4</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>3.2</version> + <configuration> + <goalPrefix>version-check</goalPrefix> + <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> + </configuration> + <executions> + <execution> + <id>mojo-descriptor</id> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + <execution> + <id>help-goal</id> + <goals> + <goal>helpmojo</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/versions/docker-manifest.csv b/version-manifest/src/main/docker-manifest.csv index dba913291..dba913291 100644 --- a/versions/docker-manifest.csv +++ b/version-manifest/src/main/docker-manifest.csv diff --git a/versions/java-manifest.csv b/version-manifest/src/main/java-manifest.csv index 8baa86884..8baa86884 100644 --- a/versions/java-manifest.csv +++ b/version-manifest/src/main/java-manifest.csv diff --git a/version-manifest/src/main/java/org/onap/oparent/versioncheck/VersionCheckMojo.java b/version-manifest/src/main/java/org/onap/oparent/versioncheck/VersionCheckMojo.java new file mode 100644 index 000000000..0bb94f2d6 --- /dev/null +++ b/version-manifest/src/main/java/org/onap/oparent/versioncheck/VersionCheckMojo.java @@ -0,0 +1,121 @@ +/* + * Copyright 2017 Huawei Technologies, Ltd. and others. + * + * 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 an "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.onap.oparent.versioncheck; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +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.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; +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.project.MavenProject; + +@Mojo(name = "version-check", defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class VersionCheckMojo extends AbstractMojo { + + /** + * The Maven Project. + * + * @since 1.0-alpha-1 + */ + @Parameter(defaultValue = "${project}", required = true, readonly = true) + protected MavenProject project; + + /** + * Location of the file. + */ + @Parameter(property = "manifestUri", required = true) + private URI manifestUri; + + public void execute() throws MojoExecutionException { + final Log log = getLog(); + + log.info("Checking version manifest " + manifestUri); + + Map<String, String> expectedVersions = new HashMap<>(); + + try (InputStreamReader in = new InputStreamReader(manifestUri.toURL().openStream(), + StandardCharsets.ISO_8859_1)) { + Iterable<CSVRecord> records = CSVFormat.DEFAULT.withFirstRecordAsHeader().parse(in); + for (CSVRecord record : records) { + String groupId = record.get("groupId"); + String artifactId = record.get("artifactId"); + String version = record.get("version"); + log.debug("Expected version: " + groupId + ":" + artifactId + ":" + version); + expectedVersions.put(groupId + ":" + artifactId, version); + } + } catch (MalformedURLException e) { + log.error(e); + throw new MojoExecutionException(e.getMessage()); + } catch (IOException e) { + log.error(e); + throw new MojoExecutionException(e.getMessage()); + } + + Map<String, String> actualVersions = new HashMap<>(); + MavenProject parent = project.getParent(); + if (parent != null) { + log.debug("Parent: " + parent); + 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()); + } + + Set<String> mismatches = new TreeSet<>(); + for (Entry<String, String> expected : expectedVersions.entrySet()) { + String artifact = expected.getKey(); + String expectedVersion = expectedVersions.get(artifact); + String actualVersion = actualVersions.get(artifact); + if (actualVersion != null && !actualVersion.equals(expectedVersion)) { + mismatches.add(artifact); + } + } + + if (mismatches.isEmpty()) { + log.debug("No version mismatches found"); + } else { + log.warn("The following dependencies should be updated to match the version manifest:"); + 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); + } + } + } + + } +} diff --git a/version.properties b/version.properties new file mode 100644 index 000000000..f841ab77d --- /dev/null +++ b/version.properties @@ -0,0 +1,14 @@ +########################################################### +# Versioning variables +# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... ) +# because they are used in Jenkins, whose plug-in doesn't support + +major_version=0 +minor_version=1 +patch_version=0 + +base_version=${major_version}.${minor_version}.${patch_version} + +# Release must be completed with GIT information # in Jenkins +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT
\ No newline at end of file |