From 3c0c467177bf44d28b469c3411ccf56cffe4d50c Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 14 Dec 2018 00:06:37 +0100 Subject: [PATCH 1/2] Put version info into utplsql-cli.version file and read it instead of compiling it into code. --- pom.xml | 51 ++++++------------- .../java/org/utplsql/cli/CliVersionInfo.java | 27 ++++++++-- src/main/resources/utplsql-cli.version | 1 + .../org/utplsql/cli/CliVersionInfoTest.java | 14 +++++ 4 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 src/main/resources/utplsql-cli.version create mode 100644 src/test/java/org/utplsql/cli/CliVersionInfoTest.java diff --git a/pom.xml b/pom.xml index bbdfe39..edf96a2 100644 --- a/pom.xml +++ b/pom.xml @@ -89,41 +89,6 @@ - - com.google.code.maven-replacer-plugin - replacer - 1.5.3 - - - replace-version-number - generate-sources - - replace - - - - - ${project.basedir}/src/main/java - - **/CliVersionInfo.java - - true - - - MAVEN_PROJECT_NAME = ".*" - MAVEN_PROJECT_NAME = "${project.name}" - - - MAVEN_PROJECT_VERSION = ".*" - MAVEN_PROJECT_VERSION = "${project.version}" - - - BUILD_NO = ".*" - BUILD_NO = "${travisBuildNumber}" - - - - org.apache.maven.plugins maven-surefire-plugin @@ -162,6 +127,22 @@ + + + src/main/resources + true + + **/utplsql-cli.version + + + + src/main/resources + false + + **/utplsql-cli.version + + + diff --git a/src/main/java/org/utplsql/cli/CliVersionInfo.java b/src/main/java/org/utplsql/cli/CliVersionInfo.java index 96fbc4c..920da1c 100644 --- a/src/main/java/org/utplsql/cli/CliVersionInfo.java +++ b/src/main/java/org/utplsql/cli/CliVersionInfo.java @@ -1,5 +1,13 @@ package org.utplsql.cli; +import org.utplsql.api.JavaApiVersionInfo; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; + /** This class is getting updated automatically by the build process. * Please do not update its constants manually cause they will be overwritten. * @@ -7,14 +15,23 @@ */ public class CliVersionInfo { - private static final String BUILD_NO = "local"; - private static final String MAVEN_PROJECT_NAME = "cli"; - private static final String MAVEN_PROJECT_VERSION = "3.1.1-SNAPSHOT"; + private static final String MAVEN_PROJECT_NAME = "utPLSL-cli"; + private static String MAVEN_PROJECT_VERSION = "unknown"; - public static String getVersion() { - return MAVEN_PROJECT_VERSION + "." + BUILD_NO; + static { + try { + MAVEN_PROJECT_VERSION = Files.readAllLines( + Paths.get(CliVersionInfo.class.getClassLoader().getResource("utplsql-cli.version").toURI()) + , Charset.defaultCharset()) + .get(0); + } + catch ( IOException | URISyntaxException e ) { + System.out.println("WARNING: Could not get Version information!"); + } } + public static String getVersion() { return MAVEN_PROJECT_VERSION; } public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); } + } diff --git a/src/main/resources/utplsql-cli.version b/src/main/resources/utplsql-cli.version new file mode 100644 index 0000000..3fb16e7 --- /dev/null +++ b/src/main/resources/utplsql-cli.version @@ -0,0 +1 @@ +${project.version}.${travisBuildNumber} \ No newline at end of file diff --git a/src/test/java/org/utplsql/cli/CliVersionInfoTest.java b/src/test/java/org/utplsql/cli/CliVersionInfoTest.java new file mode 100644 index 0000000..fc1957b --- /dev/null +++ b/src/test/java/org/utplsql/cli/CliVersionInfoTest.java @@ -0,0 +1,14 @@ +package org.utplsql.cli; + +import org.junit.jupiter.api.Test; +import org.utplsql.api.JavaApiVersionInfo; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CliVersionInfoTest { + + @Test + void getCliVersionInfo() { + assertTrue(CliVersionInfo.getVersion().startsWith("3.1")); + } +} From 6f8f2cbf56b945b0fe2013336effaf550990c67d Mon Sep 17 00:00:00 2001 From: pesse Date: Fri, 14 Dec 2018 00:22:38 +0100 Subject: [PATCH 2/2] Read the info from stream instead of NIO --- .../java/org/utplsql/cli/CliVersionInfo.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/utplsql/cli/CliVersionInfo.java b/src/main/java/org/utplsql/cli/CliVersionInfo.java index 920da1c..c7ab283 100644 --- a/src/main/java/org/utplsql/cli/CliVersionInfo.java +++ b/src/main/java/org/utplsql/cli/CliVersionInfo.java @@ -2,11 +2,11 @@ import org.utplsql.api.JavaApiVersionInfo; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URISyntaxException; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Paths; /** This class is getting updated automatically by the build process. * Please do not update its constants manually cause they will be overwritten. @@ -20,12 +20,14 @@ public class CliVersionInfo { static { try { - MAVEN_PROJECT_VERSION = Files.readAllLines( - Paths.get(CliVersionInfo.class.getClassLoader().getResource("utplsql-cli.version").toURI()) - , Charset.defaultCharset()) - .get(0); + try ( InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-cli.version")) { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + MAVEN_PROJECT_VERSION = reader.readLine(); + + reader.close(); + } } - catch ( IOException | URISyntaxException e ) { + catch ( IOException e ) { System.out.println("WARNING: Could not get Version information!"); } }