Skip to content

Commit f2746dc

Browse files
authored
Merge pull request #66 from utPLSQL/feature/outsource_version_info_to_file
Put version info in separate textfile and read from that
2 parents e4ca168 + ff6ec1b commit f2746dc

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

pom.xml

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -134,41 +134,6 @@
134134
</execution>
135135
</executions>
136136
</plugin>
137-
<plugin>
138-
<groupId>com.google.code.maven-replacer-plugin</groupId>
139-
<artifactId>replacer</artifactId>
140-
<version>1.5.3</version>
141-
<executions>
142-
<execution>
143-
<id>replace-version-number</id>
144-
<phase>generate-sources</phase>
145-
<goals>
146-
<goal>replace</goal>
147-
</goals>
148-
</execution>
149-
</executions>
150-
<configuration>
151-
<basedir>${project.basedir}/src/main/java</basedir>
152-
<includes>
153-
<include>**/JavaApiVersionInfo.java</include>
154-
</includes>
155-
<preserveDir>true</preserveDir>
156-
<replacements>
157-
<replacement>
158-
<token>MAVEN_PROJECT_NAME = ".*"</token>
159-
<value>MAVEN_PROJECT_NAME = "${project.name}"</value>
160-
</replacement>
161-
<replacement>
162-
<token>MAVEN_PROJECT_VERSION = ".*"</token>
163-
<value>MAVEN_PROJECT_VERSION = "${project.version}"</value>
164-
</replacement>
165-
<replacement>
166-
<token>BUILD_NO = ".*"</token>
167-
<value>BUILD_NO = "${travisBuildNumber}"</value>
168-
</replacement>
169-
</replacements>
170-
</configuration>
171-
</plugin>
172137
<plugin>
173138
<artifactId>maven-resources-plugin</artifactId>
174139
<version>2.6</version>
@@ -220,6 +185,22 @@
220185
</dependencies>
221186
</plugin>
222187
</plugins>
188+
<resources>
189+
<resource>
190+
<directory>src/main/resources</directory>
191+
<filtering>true</filtering>
192+
<includes>
193+
<include>**/utplsql-api.version</include>
194+
</includes>
195+
</resource>
196+
<resource>
197+
<directory>src/main/resources</directory>
198+
<filtering>false</filtering>
199+
<excludes>
200+
<exclude>**/utplsql-api.version</exclude>
201+
</excludes>
202+
</resource>
203+
</resources>
223204
</build>
224205

225206
<profiles>
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package org.utplsql.api;
22

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.InputStreamReader;
6+
import java.net.URISyntaxException;
7+
import java.nio.charset.Charset;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
10+
311
/** This class is getting updated automatically by the build process.
412
* Please do not update its constants manually cause they will be overwritten.
513
*
@@ -9,13 +17,23 @@ public class JavaApiVersionInfo {
917

1018
private JavaApiVersionInfo() { }
1119

12-
private static final String BUILD_NO = "123";
20+
1321
private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
14-
private static final String MAVEN_PROJECT_VERSION = "3.1.2-SNAPSHOT";
22+
private static String MAVEN_PROJECT_VERSION = "unknown";
1523

16-
public static String getVersion() {
17-
return MAVEN_PROJECT_VERSION + "." + BUILD_NO;
24+
static {
25+
try {
26+
MAVEN_PROJECT_VERSION = Files.readAllLines(
27+
Paths.get(JavaApiVersionInfo.class.getClassLoader().getResource("utplsql-api.version").toURI())
28+
, Charset.defaultCharset())
29+
.get(0);
30+
}
31+
catch ( IOException | URISyntaxException e ) {
32+
System.out.println("WARNING: Could not get Version information!");
33+
}
1834
}
35+
36+
public static String getVersion() { return MAVEN_PROJECT_VERSION; }
1937
public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }
2038

2139
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${project.version}.${travisBuildNumber}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.utplsql.api;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
public class JavaApiVersionTest {
8+
9+
@Test
10+
void getJavaApiVersion() {
11+
assertTrue(JavaApiVersionInfo.getVersion().startsWith("3.1"));
12+
}
13+
}

0 commit comments

Comments
 (0)