From 347b676b76e2af0464bd607f431cee06570b3a2c Mon Sep 17 00:00:00 2001 From: Michael Christen Date: Mon, 3 Oct 2022 10:12:47 +0200 Subject: [PATCH] changed system to load build properties --- .gitignore | 2 +- build.xml | 4 +- defaults/yacyBuild.properties.template | 3 ++ .../peers/operation/yacyBuildProperties.java | 40 +++++++++++++++++ .../yacyBuildProperties.java.template | 43 ------------------- 5 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 defaults/yacyBuild.properties.template create mode 100644 source/net/yacy/peers/operation/yacyBuildProperties.java delete mode 100644 source/net/yacy/peers/operation/yacyBuildProperties.java.template diff --git a/.gitignore b/.gitignore index e80a0dfaa..be15e091e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ yacy.log /test/DATA/ /javadoc/ /build/ -source/net/yacy/peers/operation/yacyBuildProperties.java +/defaults/yacyBuild.properties /.idea/ .idea/ *.iws diff --git a/build.xml b/build.xml index 16b358107..781b54e58 100644 --- a/build.xml +++ b/build.xml @@ -105,8 +105,8 @@ - - + + diff --git a/defaults/yacyBuild.properties.template b/defaults/yacyBuild.properties.template new file mode 100644 index 000000000..e3b0017f6 --- /dev/null +++ b/defaults/yacyBuild.properties.template @@ -0,0 +1,3 @@ +SVNRevision = @REPL_REVISION_NR@ +Version = @REPL_VERSION@ + diff --git a/source/net/yacy/peers/operation/yacyBuildProperties.java b/source/net/yacy/peers/operation/yacyBuildProperties.java new file mode 100644 index 000000000..a4b21cec9 --- /dev/null +++ b/source/net/yacy/peers/operation/yacyBuildProperties.java @@ -0,0 +1,40 @@ +package net.yacy.peers.operation; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Locale; +import java.util.Properties; +import java.util.regex.Pattern; + + +public final class yacyBuildProperties { + + private static Properties props = new Properties(); + + static { + try { + props.load(new FileInputStream("defaults/yacyBuild.properties")); + } catch (IOException e) { + e.printStackTrace(); + props = null; + } + } + + public static String getSVNRevision() { + if (props == null) return "0"; + final String revision = props.getProperty("SVNRevision"); + return revision.contains("@") || revision.contains("$") ? "0" : revision; + } + + public static String getVersion() { + if (props == null) return "0.1"; + final String version = props.getProperty("Version"); + return version.contains("@") ? "0.1" : version; + } + + public static final Pattern versionMatcher = Pattern.compile("\\A(\\d+\\.\\d{1,3})(\\d{0,5})\\z"); + + public static String getLongVersion() { + return String.format(Locale.US, "%.3f%05d", Float.valueOf(getVersion()), Integer.valueOf(getSVNRevision())); + } +} diff --git a/source/net/yacy/peers/operation/yacyBuildProperties.java.template b/source/net/yacy/peers/operation/yacyBuildProperties.java.template deleted file mode 100644 index 0304159d9..000000000 --- a/source/net/yacy/peers/operation/yacyBuildProperties.java.template +++ /dev/null @@ -1,43 +0,0 @@ -package net.yacy.peers.operation; - -import java.util.Locale; -import java.util.regex.Pattern; - - -/** - * Properties set when compiling this release/version - */ -public final class yacyBuildProperties { - private yacyBuildProperties() { - } - - /** - * returns the SVN-Revision Number as a String - */ - public static String getSVNRevision() { - final String revision = "@REPL_REVISION_NR@"; - if (revision.contains("@") || revision.contains("$")) { - return "0"; - } - return revision; - } - - /** - * returns the version String (e. g. 0.9) - */ - public static String getVersion() { - if ("@REPL_VERSION@".contains("@") ) { - return "0.1"; - } - return "@REPL_VERSION@"; - } - - public static final Pattern versionMatcher = Pattern.compile("\\A(\\d+\\.\\d{1,3})(\\d{0,5})\\z"); - - /** - * returns the long version String (e. g. 0.9106712) - */ - public static String getLongVersion() { - return String.format(Locale.US, "%.3f%05d", Float.valueOf(getVersion()), Integer.valueOf(getSVNRevision())); - } -}