From d4f2a50324eb8ad9a79a54f6bfb7f7089e056db9 Mon Sep 17 00:00:00 2001 From: Gal Rogozinski Date: Wed, 13 Mar 2019 09:09:38 +0100 Subject: [PATCH] Change: Prepare IRI to have its version injected by CI (#1359) * Parse version from jar manifest * Parse version from pom when running directly from IDE * update pom version * add commit hash to version * get correct version wiht travis * delete unneccessary comment * change travis.yml to release properly * add doc and delete unused imports --- .travis.yml | 10 +++--- DOCKER.md | 6 ++-- pom.xml | 33 ++++++++++++++++++- src/main/java/com/iota/iri/IRI.java | 5 +-- .../com/iota/iri/conf/BaseIotaConfig.java | 2 +- src/main/java/com/iota/iri/service/API.java | 5 +-- .../java/com/iota/iri/utils/IotaUtils.java | 29 ++++++++++++++++ 7 files changed, 77 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 057c21907e..a5ef1a5bef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,12 @@ script: - git checkout -f $TRAVIS_BRANCH - git checkout $build_head - git merge $TRAVIS_BRANCH - - mvn integration-test -Dlogging-level=INFO - #run jar sanity tests - - VERSION=$(mvn help:evaluate -Dexpression=project.version | grep -E '^[0-9.]+') + - VERSION=$(mvn git-commit-id:revision help:evaluate -Dexpression=project.version | grep -E '^[0-9.]+') + - VERSION=${VERSION/DEV*/RELEASE} - echo $VERSION + - mvn versions:set -DnewVersion=$VERSION + #run jar sanity tests + - mvn integration-test -Dlogging-level=INFO #jacoco prep (appends to mvn run) - JACOCO_V=$(mvn help:evaluate -Dexpression=jacoco.version | grep -E '^[0-9.]+') - export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:$HOME/.m2/repository/org/jacoco/org.jacoco.agent/$JACOCO_V/org.jacoco.agent-$JACOCO_V-runtime.jar=destfile=$PWD/target/jacoco.exec,output=file,append=true,dumponexit=true" @@ -61,7 +63,7 @@ deploy: api_key: secure: "j+KolvRrsinh6OTqjli1y5I4gdPdD5MT6RFahVRrznxtcb2t7y6x41PknkI/8BksxLJKKQ1f40L307Aquzih9FmLesWcrYrCOS/B40dlCc3uV8DEZKhZF+QWqvsDpZ0EfiluGFljqGpxwngb/miNObqQzQvzpdUXBpZcuzxgqziynJD6jt3TYbNn544m/i4cWbb++b1h2Bm+jwELzJcf6/CZ1TxUh49vdM4S6yTpvnKwg4NLeH6g8s9oYEN1iwYtQokGKlH/emBZDsqDtF4KH7kXPpEKTcho4nH504XWJpanVAQ02Pha4SAnyVu4rKiLH4e6v99xZOBLVTH/qkvlwzvkNYr2xS5q9T9G7DZBRE+oc2MIbcnuSkhHwrUcmf2Hc0zCIP4RLCXAUuVlNEmIQUKgTezVzaqaEQLsa+EFIoosS+8pT/kVnaLbwxrITUmgM246+gvzMcVg8SmyPvVj6iRxfR6spTd7V2M0ePdqWlCL8P9RY4YrtxR2yJ6/3C0XNf29t+s/r1jat8fwWp8Gf7GiCaJEYG9VO24Chhi+MZCKBJnmx5G/98zvLw3f6a1FsEGZrw9RhF2vJKK6sD3rIvNkUsYmf0OhM7bf0NceFMGTJ/mFzM/JX0OHMtIyAvUfyyPVbQkIHNcGBgQMZasx07K3fjcn2lqv4FbHVi3HbdM=" file_glob: true - file: target/*.jar* + file: target/*RELEASE.jar* skip_cleanup: true before_deploy: openssl aes-256-cbc -K $encrypted_5a15fa813cca_key -iv $encrypted_5a15fa813cca_iv -in codesigning.asc.enc -out codesigning.asc -d && gpg --fast-import codesigning.asc deploy: mvn package -P build-extras -Dlogging-level=INFO diff --git a/DOCKER.md b/DOCKER.md index 14e92f860b..be0b0b8198 100644 --- a/DOCKER.md +++ b/DOCKER.md @@ -2,13 +2,13 @@ Run the official iotaledger/iri container, passing the mandatory -p option: -```docker run iotaledger/iri:v1.6.1-RELEASE -p 14265``` +```docker run iotaledger/iri:vX.X.X-RELEASE -p 14265``` This will get your a running IRI with its API listening on port 14265, no neighbours and an empty database. The IRI Docker container by default expects data at /iri/data. Use the `-v` option of the `docker run` command to mount volumes so to have persistent data. You can also pass more command line options to the docker run command and those will be passed to IRI. If you want to use a iri.ini file with the docker container, supposing it's stored under /path/to/conf/iri.ini on your docker host, then pass `-v /path/to/conf:/iri/conf` and add -c /iri/conf/iri.ini as docker run arguments. So for example the `docker run` command above would become: -```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:v1.6.1-RELEASE -p 14265 -c /iri/conf/iri.ini``` +```docker run -v /path/to/conf:/iri/conf -v /path/to/data:/iri/data iotaledger/iri:vX.X.X-RELEASE -p 14265 -c /iri/conf/iri.ini``` Please refer to the IRI documentation for further command line options and iri.ini options. @@ -61,7 +61,7 @@ ExecStart=/usr/bin/docker run \ -p 14265:14265 \ -p 15600:15600 \ -p 14600:14600/udp \ -iotaledger/iri:v1.6.1-RELEASE \ +iotaledger/iri:vX.X.X-RELEASE \ -p 14265 \ --zmq-enabled \ --testnet diff --git a/pom.xml b/pom.xml index 18995e36c7..b89a416d51 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.iota iri - 1.6.1-RELEASE + 1.6.1-DEV-${version.number} IRI IOTA Reference Implementation @@ -22,6 +22,7 @@ 3.0.0 1.4.26.Final 0.7.9 + ${git.commit.id.abbrev} @@ -218,6 +219,36 @@ false + + pl.project13.maven + git-commit-id-plugin + 2.2.4 + + + validate + + revision + + + + + ${project.basedir}/.git + false + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.1 + + + + true + + + + diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java index bd84b60d52..27d9d88786 100644 --- a/src/main/java/com/iota/iri/IRI.java +++ b/src/main/java/com/iota/iri/IRI.java @@ -5,6 +5,7 @@ import com.iota.iri.conf.ConfigFactory; import com.iota.iri.conf.IotaConfig; import com.iota.iri.service.API; +import com.iota.iri.utils.IotaUtils; import java.io.File; import java.io.IOException; @@ -42,7 +43,6 @@ public class IRI { public static final String MAINNET_NAME = "IRI"; public static final String TESTNET_NAME = "IRI Testnet"; - public static final String VERSION = "1.6.1-RELEASE"; /** * The entry point of IRI. @@ -114,7 +114,8 @@ private static class IRILauncher { */ public static void main(String [] args) throws Exception { IotaConfig config = createConfiguration(args); - log.info("Welcome to {} {}", config.isTestnet() ? TESTNET_NAME : MAINNET_NAME, VERSION); + String version = IotaUtils.getIriVersion(); + log.info("Welcome to {} {}", config.isTestnet() ? TESTNET_NAME : MAINNET_NAME, version); iota = new Iota(config); ixi = new IXI(iota); diff --git a/src/main/java/com/iota/iri/conf/BaseIotaConfig.java b/src/main/java/com/iota/iri/conf/BaseIotaConfig.java index 40841628dc..3756f622a8 100644 --- a/src/main/java/com/iota/iri/conf/BaseIotaConfig.java +++ b/src/main/java/com/iota/iri/conf/BaseIotaConfig.java @@ -123,7 +123,7 @@ public JCommander parseConfigFromArgs(String[] args) throws ParameterException { .acceptUnknownOptions(true) .allowParameterOverwriting(true) //This is the first line of JCommander Usage - .programName("java -jar iri-" + IRI.VERSION + ".jar") + .programName("java -jar iri-" + IotaUtils.getIriVersion() + ".jar") .build(); if (ArrayUtils.isNotEmpty(args)) { jCommander.parse(args); diff --git a/src/main/java/com/iota/iri/service/API.java b/src/main/java/com/iota/iri/service/API.java index 618b6f5972..9f345899ae 100644 --- a/src/main/java/com/iota/iri/service/API.java +++ b/src/main/java/com/iota/iri/service/API.java @@ -22,6 +22,7 @@ import com.iota.iri.service.tipselection.impl.WalkValidatorImpl; import com.iota.iri.utils.Converter; import com.iota.iri.utils.IotaIOUtils; +import com.iota.iri.utils.IotaUtils; import com.iota.iri.utils.MapIdentityManager; import io.undertow.Undertow; import io.undertow.security.api.AuthenticationMechanism; @@ -884,8 +885,8 @@ private AbstractResponse getNodeInfoStatement() throws Exception{ MilestoneViewModel milestone = MilestoneViewModel.first(instance.tangle); return GetNodeInfoResponse.create( - name, - IRI.VERSION, + name, + IotaUtils.getIriVersion(), Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().freeMemory(), System.getProperty("java.version"), diff --git a/src/main/java/com/iota/iri/utils/IotaUtils.java b/src/main/java/com/iota/iri/utils/IotaUtils.java index 7a751e4d65..56b6fcf4c1 100644 --- a/src/main/java/com/iota/iri/utils/IotaUtils.java +++ b/src/main/java/com/iota/iri/utils/IotaUtils.java @@ -1,9 +1,15 @@ package com.iota.iri.utils; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.iota.iri.IRI; import com.iota.iri.model.Hash; +import java.io.FileReader; import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -17,6 +23,29 @@ public class IotaUtils { + private static final Logger log = LoggerFactory.getLogger(IotaUtils.class); + + /** + * Returns the current version IRI is running by reading the Jar manifest. + * If we run not from a jar or the manifest is missing we read straight from the pom + * + * @return the implementation version of IRI + */ + public static String getIriVersion() { + String implementationVersion = IRI.class.getPackage().getImplementationVersion(); + //If not in manifest (can happen when running from IDE) + if (implementationVersion == null) { + MavenXpp3Reader reader = new MavenXpp3Reader(); + try { + Model model = reader.read(new FileReader("pom.xml")); + implementationVersion = model.getVersion(); + } catch (Exception e) { + log.error("Failed to parse version from pom", e); + } + } + return implementationVersion; + } + public static List splitStringToImmutableList(String string, String regexSplit) { return Arrays.stream(string.split(regexSplit)) .filter(StringUtils::isNoneBlank)