Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<version>${git-commit-id-maven-plugin.version}</version>
<configuration>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/version.properties</generateGitPropertiesFilename>
<generateGitPropertiesFilename>${project.build.outputDirectory}/operator-sdk-version.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.time$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class Utils {
public static final String GENERIC_PARAMETER_TYPE_ERROR_PREFIX =
"Couldn't retrieve generic parameter type from ";

public static final String VERSION_PROPERTIES_FILE_NAME = "operator-sdk-version.properties";

public static final Version VERSION = loadFromProperties();

/**
Expand All @@ -52,7 +54,9 @@ public class Utils {
*/
private static Version loadFromProperties() {
final var is =
Thread.currentThread().getContextClassLoader().getResourceAsStream("version.properties");
Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(VERSION_PROPERTIES_FILE_NAME);

final var properties = new Properties();
if (is != null) {
Expand All @@ -62,7 +66,9 @@ private static Version loadFromProperties() {
log.warn("Couldn't load version information: {}", e.getMessage());
}
} else {
log.warn("Couldn't find version.properties file. Default version information will be used.");
log.warn(
"Couldn't find {} file. Default version information will be used.",
VERSION_PROPERTIES_FILE_NAME);
}

Date builtTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

class VersionTest {

Expand All @@ -28,4 +30,13 @@ void versionShouldReturnTheSameResultFromMavenAndProperties() {

assertEquals(versionFromProperties, versionFromMaven);
}

@Test
void versionShouldBeLoadedFromTheGeneratedPropertiesFile() {
assertNotNull(
Thread.currentThread()
.getContextClassLoader()
.getResource(Utils.VERSION_PROPERTIES_FILE_NAME));
assertNotEquals(Version.UNKNOWN.getCommit(), Utils.VERSION.getCommit());
}
}
Loading