From c70f03095d68afab57f7661dcad0ffaf6ef5fa9d Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 3 May 2023 21:34:28 +0200 Subject: [PATCH 1/2] fix: only load Version from properties once --- .../operator/api/config/BaseConfigurationService.java | 2 +- .../operator/api/config/ConfigurationServiceProvider.java | 2 +- .../java/io/javaoperatorsdk/operator/api/config/Utils.java | 4 ++++ .../io/javaoperatorsdk/operator/api/config/VersionTest.java | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java index 772a16fe71..3575093ebb 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java @@ -53,7 +53,7 @@ public BaseConfigurationService(Version version, Cloner cloner) { } public BaseConfigurationService() { - this(Utils.loadFromProperties()); + this(Utils.VERSION); } @Override diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProvider.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProvider.java index 25bfebe1d1..2ba60d1fca 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProvider.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProvider.java @@ -70,6 +70,6 @@ public synchronized static void reset() { } static ConfigurationService createDefault() { - return new BaseConfigurationService(Utils.loadFromProperties()); + return new BaseConfigurationService(Utils.VERSION); } } diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index ec244f224c..67a3211cfd 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -27,12 +27,16 @@ public class Utils { public static final String GENERIC_PARAMETER_TYPE_ERROR_PREFIX = "Couldn't retrieve generic parameter type from "; + public static final Version VERSION = loadFromProperties(); + /** * Attempts to load version information from a properties file produced at build time, currently * via the {@code git-commit-id-plugin} maven plugin. * * @return a {@link Version} object encapsulating the version information + * @deprecated use {@link #VERSION} instead, as this method will be made internal in a future release */ + @Deprecated public static Version loadFromProperties() { final var is = Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties"); diff --git a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/VersionTest.java b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/VersionTest.java index 5df0738022..f59b619996 100644 --- a/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/VersionTest.java +++ b/operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/VersionTest.java @@ -8,7 +8,7 @@ class VersionTest { @Test void versionShouldReturnTheSameResultFromMavenAndProperties() { - String versionFromProperties = Utils.loadFromProperties().getSdkVersion(); + String versionFromProperties = Utils.VERSION.getSdkVersion(); String versionFromMaven = Version.UNKNOWN.getSdkVersion(); assertEquals(versionFromProperties, versionFromMaven); From 390581ba0d81a60f0651576b1d6fe9bd866f5b04 Mon Sep 17 00:00:00 2001 From: Chris Laprun Date: Wed, 3 May 2023 22:02:19 +0200 Subject: [PATCH 2/2] fix: format --- .../java/io/javaoperatorsdk/operator/api/config/Utils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java index 67a3211cfd..2028d3d5bc 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java @@ -34,7 +34,8 @@ public class Utils { * via the {@code git-commit-id-plugin} maven plugin. * * @return a {@link Version} object encapsulating the version information - * @deprecated use {@link #VERSION} instead, as this method will be made internal in a future release + * @deprecated use {@link #VERSION} instead, as this method will be made internal in a future + * release */ @Deprecated public static Version loadFromProperties() {