Skip to content

Commit 0b4a0ea

Browse files
committed
HBX-2936 Use maven-injection-plugin to set the version string in the org.hibernate.tool.api.version.Version
1 parent 0584bc4 commit 0b4a0ea

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

orm/pom.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,26 @@
8787
</dependency>
8888
</dependencies>
8989

90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.jboss.maven.plugins</groupId>
94+
<artifactId>maven-injection-plugin</artifactId>
95+
<configuration>
96+
<bytecodeInjections>
97+
<bytecodeInjection>
98+
<expression>${project.version}</expression>
99+
<targetMembers>
100+
<methodBodyReturn>
101+
<className>org.hibernate.tool.api.version.Version</className>
102+
<methodName>versionString</methodName>
103+
</methodBodyReturn>
104+
</targetMembers>
105+
</bytecodeInjection>
106+
</bytecodeInjections>
107+
</configuration>
108+
</plugin>
109+
</plugins>
110+
</build>
111+
90112
</project>
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package org.hibernate.tool.api.version;
22

33
public interface Version {
4-
5-
final static String CURRENT_VERSION = "7.0.0-SNAPSHOT";
64

5+
/**
6+
* @deprecated Use {@link #versionString()} instead.
7+
*/
8+
@Deprecated
9+
final static String CURRENT_VERSION = versionString();
10+
11+
static String versionString() {
12+
// This implementation is replaced during the build with another one that returns the correct value.
13+
return "UNKNOWN";
14+
}
715
}

orm/src/main/java/org/hibernate/tool/internal/export/common/TemplateHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void processString(String template, Writer output) {
177177
}
178178

179179
public void setupContext() {
180-
getContext().put("version", Version.CURRENT_VERSION);
180+
getContext().put("version", Version.versionString());
181181
getContext().put("ctx", getContext() ); //TODO: I would like to remove this, but don't know another way to actually get the list possible "root" keys for debugging.
182182
getContext().put("templates", new Templates());
183183

test/nodb/src/test/java/org/hibernate/tool/VersionTest/TestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class TestCase {
4545
@Test
4646
public void testVersion() throws Exception {
4747
assertEquals(
48-
org.hibernate.tool.api.version.Version.CURRENT_VERSION,
48+
org.hibernate.tool.api.version.Version.versionString(),
4949
extractVersion(getPomXml()));
5050
}
5151

test/nodb/src/test/java/org/hibernate/tool/hbm2x/GenericExporterTest/TestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void testSingleFileGeneration() {
9090
null,
9191
FileUtil.findFirstString("$", new File(outputDir, "artifacts.txt")));
9292
assertEquals(
93-
"File for artifacts in " + Version.CURRENT_VERSION,
93+
"File for artifacts in " + Version.versionString(),
9494
FileUtil.findFirstString("artifacts", new File( outputDir, "artifacts.txt")));
9595
}
9696

0 commit comments

Comments
 (0)