Skip to content

Commit dca1ed8

Browse files
authored
fix: only load Version from properties once (#1886)
* fix: only load Version from properties once * fix: format
1 parent 49c87af commit dca1ed8

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public BaseConfigurationService(Version version, Cloner cloner) {
5353
}
5454

5555
public BaseConfigurationService() {
56-
this(Utils.loadFromProperties());
56+
this(Utils.VERSION);
5757
}
5858

5959
@Override

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public synchronized static void reset() {
7070
}
7171

7272
static ConfigurationService createDefault() {
73-
return new BaseConfigurationService(Utils.loadFromProperties());
73+
return new BaseConfigurationService(Utils.VERSION);
7474
}
7575
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Utils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public class Utils {
2727
public static final String GENERIC_PARAMETER_TYPE_ERROR_PREFIX =
2828
"Couldn't retrieve generic parameter type from ";
2929

30+
public static final Version VERSION = loadFromProperties();
31+
3032
/**
3133
* Attempts to load version information from a properties file produced at build time, currently
3234
* via the {@code git-commit-id-plugin} maven plugin.
3335
*
3436
* @return a {@link Version} object encapsulating the version information
37+
* @deprecated use {@link #VERSION} instead, as this method will be made internal in a future
38+
* release
3539
*/
40+
@Deprecated
3641
public static Version loadFromProperties() {
3742
final var is =
3843
Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties");

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/VersionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class VersionTest {
88

99
@Test
1010
void versionShouldReturnTheSameResultFromMavenAndProperties() {
11-
String versionFromProperties = Utils.loadFromProperties().getSdkVersion();
11+
String versionFromProperties = Utils.VERSION.getSdkVersion();
1212
String versionFromMaven = Version.UNKNOWN.getSdkVersion();
1313

1414
assertEquals(versionFromProperties, versionFromMaven);

0 commit comments

Comments
 (0)