From 2ca6bc66f7820a763e518d991c07736d129da976 Mon Sep 17 00:00:00 2001 From: marko-bekhta Date: Mon, 2 Dec 2024 11:59:52 +0100 Subject: [PATCH] HBX-2951: Backport automated releases to branch 6.6 - Use maven-injection-plugin to set the version string in the org.hibernate.tool.api.version.Version --- orm/pom.xml | 22 +++++++++++++++++++ .../hibernate/tool/api/version/Version.java | 13 +++++++++-- .../export/common/TemplateHelper.java | 2 +- .../hibernate/tool/VersionTest/TestCase.java | 2 +- .../hbm2x/GenericExporterTest/TestCase.java | 2 +- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/orm/pom.xml b/orm/pom.xml index c599d299cd..d6e078bca3 100644 --- a/orm/pom.xml +++ b/orm/pom.xml @@ -82,4 +82,26 @@ + + + + org.jboss.maven.plugins + maven-injection-plugin + + + + ${project.version} + + + org.hibernate.tool.api.version.Version + versionString + + + + + + + + + diff --git a/orm/src/main/java/org/hibernate/tool/api/version/Version.java b/orm/src/main/java/org/hibernate/tool/api/version/Version.java index 52d641fb94..da4f560172 100644 --- a/orm/src/main/java/org/hibernate/tool/api/version/Version.java +++ b/orm/src/main/java/org/hibernate/tool/api/version/Version.java @@ -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"; + } + } diff --git a/orm/src/main/java/org/hibernate/tool/internal/export/common/TemplateHelper.java b/orm/src/main/java/org/hibernate/tool/internal/export/common/TemplateHelper.java index 3a8152feef..33722b7ce5 100644 --- a/orm/src/main/java/org/hibernate/tool/internal/export/common/TemplateHelper.java +++ b/orm/src/main/java/org/hibernate/tool/internal/export/common/TemplateHelper.java @@ -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()); diff --git a/test/nodb/src/test/java/org/hibernate/tool/VersionTest/TestCase.java b/test/nodb/src/test/java/org/hibernate/tool/VersionTest/TestCase.java index 3447393a51..cbd52f1357 100644 --- a/test/nodb/src/test/java/org/hibernate/tool/VersionTest/TestCase.java +++ b/test/nodb/src/test/java/org/hibernate/tool/VersionTest/TestCase.java @@ -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())); } diff --git a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/GenericExporterTest/TestCase.java b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/GenericExporterTest/TestCase.java index 3d51e38372..54fc9e3ceb 100644 --- a/test/nodb/src/test/java/org/hibernate/tool/hbm2x/GenericExporterTest/TestCase.java +++ b/test/nodb/src/test/java/org/hibernate/tool/hbm2x/GenericExporterTest/TestCase.java @@ -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"))); }