Skip to content

Commit c88695a

Browse files
committed
Add better determination of Convex version
1 parent 02e0b87 commit c88695a

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

convex-core/pom.xml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<artifactId>convex</artifactId>
77
<version>0.8.1-SNAPSHOT</version>
88
</parent>
9-
9+
1010
<properties>
11-
<antlr.version>4.13.2</antlr.version>
12-
<bc.version>1.79</bc.version>
13-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<antlr.version>4.13.2</antlr.version>
12+
<bc.version>1.79</bc.version>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
</properties>
1515

1616
<modelVersion>4.0.0</modelVersion>
@@ -51,40 +51,44 @@
5151
</execution>
5252
</executions>
5353
<configuration>
54-
<basedir>${project.build.directory}/generated-sources/antlr4/convex/core/lang/reader/antlr</basedir>
54+
<basedir>
55+
${project.build.directory}/generated-sources/antlr4/convex/core/lang/reader/antlr</basedir>
5556
<includes>
5657
<include>*.java</include>
5758
</includes>
5859
<replacements>
5960
<replacement>
6061
<token>// Generated from convex.+</token>
61-
<value>// Generated file. This header modified in convex-core/pom.xml to ensure repeatable builds.</value>
62+
<value>// Generated file. This header modified in
63+
convex-core/pom.xml to ensure repeatable builds.</value>
6264
</replacement>
6365
</replacements>
6466
<regex>true</regex>
6567
</configuration>
6668
</plugin>
6769
<plugin>
68-
<groupId>org.codehaus.mojo</groupId>
69-
<artifactId>build-helper-maven-plugin</artifactId>
70-
<version>3.6.0</version>
71-
<executions>
72-
<execution>
73-
<id>add-source</id>
74-
<phase>generate-sources</phase>
75-
<goals>
76-
<goal>add-source</goal>
77-
</goals>
78-
<configuration>
79-
<sources>
80-
<source>${project.build.directory}/generated-sources/antlr4/</source>
81-
</sources>
82-
</configuration>
83-
</execution>
84-
</executions>
85-
</plugin>
86-
87-
<!-- This plugin ensures we get a test-jar which is used as a dependency for some other tests. Not needed any more?
70+
<groupId>org.codehaus.mojo</groupId>
71+
<artifactId>build-helper-maven-plugin</artifactId>
72+
<version>3.6.0</version>
73+
<executions>
74+
<execution>
75+
<id>add-source</id>
76+
<phase>generate-sources</phase>
77+
<goals>
78+
<goal>add-source</goal>
79+
</goals>
80+
<configuration>
81+
<sources>
82+
<source>
83+
${project.build.directory}/generated-sources/antlr4/</source>
84+
</sources>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
90+
<!-- This plugin ensures we get a test-jar which is used as a
91+
dependency for some other tests. Not needed any more?
8892
<plugin>
8993
<groupId>org.apache.maven.plugins</groupId>
9094
<artifactId>maven-jar-plugin</artifactId>
@@ -105,7 +109,10 @@
105109
<resource>
106110
<directory>src/main/antlr4</directory>
107111
</resource>
108-
112+
<resource>
113+
<directory>src/main/resources-filtered</directory>
114+
<filtering>true</filtering>
115+
</resource>
109116
</resources>
110117
<testResources>
111118
<testResource>

convex-core/src/main/java/convex/core/util/Utils.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Comparator;
2222
import java.util.HashMap;
2323
import java.util.List;
24+
import java.util.Properties;
2425
import java.util.Random;
2526
import java.util.function.Function;
2627
import java.util.function.Supplier;
@@ -1403,10 +1404,25 @@ public static long longByteAt(long value,long i) {
14031404
return 0xFF&(value >> ((ALongBlob.LENGTH - i - 1) * 8));
14041405
}
14051406

1407+
static String version=null;
14061408
public static String getVersion() {
1407-
String v= Utils.class.getPackage().getImplementationVersion();
1408-
if (v==null) v="Unlabelled SNAPSHOT";
1409-
return v;
1409+
version = Utils.class.getPackage().getImplementationVersion();
1410+
1411+
if (version==null) try {
1412+
Properties properties = new Properties();
1413+
InputStream stream = getResourceAsStream("/convex/core/build.properties");
1414+
if (stream!=null) {
1415+
properties.load(stream);
1416+
version=properties.getProperty("convex.core.version");
1417+
}
1418+
} catch (IOException e) {
1419+
e.printStackTrace();
1420+
}
1421+
1422+
if (version==null) {
1423+
return "SNAPSHOT";
1424+
}
1425+
return version;
14101426
}
14111427

14121428
public static String timeString() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
convex.core.version=${project.version}

convex-core/src/test/java/convex/util/UtilsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
55
import static org.junit.jupiter.api.Assertions.assertEquals;
66
import static org.junit.jupiter.api.Assertions.assertFalse;
7+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
78
import static org.junit.jupiter.api.Assertions.assertNull;
89
import static org.junit.jupiter.api.Assertions.assertThrows;
910
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -433,5 +434,9 @@ public void testStatesAsOfRange() throws BadSignatureException {
433434
assertNull(q.poll());
434435
assertTrue(q.isEmpty());
435436
}
437+
438+
@Test public void testVersion() {
439+
assertNotEquals("SNAPSHOT",Utils.getVersion());
440+
}
436441

437442
}

0 commit comments

Comments
 (0)