From c720f8116dd7c0b5e242cbc006b09d41a8a846fe Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Wed, 26 Apr 2023 00:16:03 +0200 Subject: [PATCH] Set TranslationGlobals.VERSION_NUMBER automatically during build This will avoid the version number getting outdated again in the future. --- build.gradle | 7 +++++ .../de/tla2b/global/TranslationGlobals.java | 2 +- .../java/de/tla2b/global/VersionHelper.java | 30 +++++++++++++++++++ src/main/resources/de/tla2b/build.properties | 3 ++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/tla2b/global/VersionHelper.java create mode 100644 src/main/resources/de/tla2b/build.properties diff --git a/build.gradle b/build.gradle index 0d32657..bbefbb2 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,13 @@ java { withJavadocJar() } +processResources { + inputs.property("project.version", project.version) + filesMatching("de/tla2b/build.properties") { + expand(version: project.version) + } +} + jacoco { toolVersion = "0.8.9" reportsDirectory = file("$buildDir/customJacocoReportDir") diff --git a/src/main/java/de/tla2b/global/TranslationGlobals.java b/src/main/java/de/tla2b/global/TranslationGlobals.java index 5ac0417..9c5c6d8 100644 --- a/src/main/java/de/tla2b/global/TranslationGlobals.java +++ b/src/main/java/de/tla2b/global/TranslationGlobals.java @@ -6,7 +6,7 @@ import java.util.Arrays; import tla2sany.semantic.FrontEnd; public interface TranslationGlobals { - final String VERSION_NUMBER = "1.1.5-SNAPSHOT"; + final String VERSION_NUMBER = VersionHelper.VERSION; final int TLCValueKind = 100; diff --git a/src/main/java/de/tla2b/global/VersionHelper.java b/src/main/java/de/tla2b/global/VersionHelper.java new file mode 100644 index 0000000..5ff99e4 --- /dev/null +++ b/src/main/java/de/tla2b/global/VersionHelper.java @@ -0,0 +1,30 @@ +package de.tla2b.global; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + +final class VersionHelper { + private VersionHelper() { + throw new AssertionError("Utility class"); + } + + static final String VERSION; + static { + final Properties buildProperties = new Properties(); + final InputStream is = VersionHelper.class.getResourceAsStream("/de/tla2b/build.properties"); + if (is == null) { + throw new AssertionError("Build properties not found, this should never happen!"); + } else { + try (final Reader r = new InputStreamReader(is, StandardCharsets.UTF_8)) { + buildProperties.load(r); + } catch (final IOException e) { + throw new AssertionError("IOException while loading build properties, this should never happen!", e); + } + } + VERSION = buildProperties.getProperty("version"); + } +} diff --git a/src/main/resources/de/tla2b/build.properties b/src/main/resources/de/tla2b/build.properties new file mode 100644 index 0000000..178150d --- /dev/null +++ b/src/main/resources/de/tla2b/build.properties @@ -0,0 +1,3 @@ +# The values for these properties are generated during the build. +# See the configuration of the processResources task in build.gradle. +version=${version} -- GitLab