Skip to content

Commit

Permalink
HBX-2951: Backport automated releases to branch 6.6
Browse files Browse the repository at this point in the history
  - Use maven-injection-plugin to set the version string in the org.hibernate.tool.api.version.Version
  • Loading branch information
marko-bekhta authored and koentsje committed Jan 15, 2025
1 parent 48a180b commit 2ca6bc6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
22 changes: 22 additions & 0 deletions orm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,26 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-injection-plugin</artifactId>
<configuration>
<bytecodeInjections>
<bytecodeInjection>
<expression>${project.version}</expression>
<targetMembers>
<methodBodyReturn>
<className>org.hibernate.tool.api.version.Version</className>
<methodName>versionString</methodName>
</methodBodyReturn>
</targetMembers>
</bytecodeInjection>
</bytecodeInjections>
</configuration>
</plugin>
</plugins>
</build>

</project>
13 changes: 11 additions & 2 deletions orm/src/main/java/org/hibernate/tool/api/version/Version.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package org.hibernate.tool.api.version;

public interface Version {

final static String CURRENT_VERSION = "6.6.3-SNAPSHOT";

/**
* @deprecated Use {@link #versionString()} instead.
*/
@Deprecated
final static String CURRENT_VERSION = versionString();

static String versionString() {
// This implementation is replaced during the build with another one that returns the correct value.
return "UNKNOWN";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void processString(String template, Writer output) {
}

public void setupContext() {
getContext().put("version", Version.CURRENT_VERSION);
getContext().put("version", Version.versionString());
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.
getContext().put("templates", new Templates());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TestCase {
@Test
public void testVersion() throws Exception {
assertEquals(
org.hibernate.tool.api.version.Version.CURRENT_VERSION,
org.hibernate.tool.api.version.Version.versionString(),
extractVersion(getPomXml()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void testSingleFileGeneration() {
null,
FileUtil.findFirstString("$", new File(outputDir, "artifacts.txt")));
assertEquals(
"File for artifacts in " + Version.CURRENT_VERSION,
"File for artifacts in " + Version.versionString(),
FileUtil.findFirstString("artifacts", new File( outputDir, "artifacts.txt")));
}

Expand Down

0 comments on commit 2ca6bc6

Please sign in to comment.