Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Put version info in separate textfile and read from that #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 16 additions & 35 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,41 +134,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-version-number</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${project.basedir}/src/main/java</basedir>
<includes>
<include>**/JavaApiVersionInfo.java</include>
</includes>
<preserveDir>true</preserveDir>
<replacements>
<replacement>
<token>MAVEN_PROJECT_NAME = ".*"</token>
<value>MAVEN_PROJECT_NAME = "${project.name}"</value>
</replacement>
<replacement>
<token>MAVEN_PROJECT_VERSION = ".*"</token>
<value>MAVEN_PROJECT_VERSION = "${project.version}"</value>
</replacement>
<replacement>
<token>BUILD_NO = ".*"</token>
<value>BUILD_NO = "${travisBuildNumber}"</value>
</replacement>
</replacements>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
Expand Down Expand Up @@ -220,6 +185,22 @@
</dependencies>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/utplsql-api.version</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/utplsql-api.version</exclude>
</excludes>
</resource>
</resources>
</build>

<profiles>
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package org.utplsql.api;

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.
*
Expand All @@ -9,13 +17,23 @@ public class JavaApiVersionInfo {

private JavaApiVersionInfo() { }

private static final String BUILD_NO = "123";

private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
private static final String MAVEN_PROJECT_VERSION = "3.1.2-SNAPSHOT";
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(JavaApiVersionInfo.class.getClassLoader().getResource("utplsql-api.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(); }

}
1 change: 1 addition & 0 deletions src/main/resources/utplsql-api.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${project.version}.${travisBuildNumber}
13 changes: 13 additions & 0 deletions src/test/java/org/utplsql/api/JavaApiVersionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.utplsql.api;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class JavaApiVersionTest {

@Test
void getJavaApiVersion() {
assertTrue(JavaApiVersionInfo.getVersion().startsWith("3.1"));
}
}