Skip to content

Generate a Versions file to be consumed at runtime #1667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
13 changes: 13 additions & 0 deletions operator-framework-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fill in the information that is available in Maven.

<artifactId>templating-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>filtering-java-templates</id>
<goals>
<goal>filter-sources</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.javaoperatorsdk.operator.api.config;

public final class Versions {

private Versions() {}

protected static final String JOSDK = "${project.version}";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you pls enlighten me how this supposed to work? Where are those placeholders filled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is filled by the Maven Plugin as it is in java-templates folder as opposed to java.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to write a unit test for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here: 52643d3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, thx!

protected static final String KUBERNETES_CLIENT = "${fabric8-client.version}";

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
/** A class encapsulating the version information associated with this SDK instance. */
public class Version {

public static final Version UNKNOWN = new Version("unknown", "unknown", Date.from(Instant.EPOCH));
public static final Version UNKNOWN =
new Version(Versions.JOSDK, "unknown", Date.from(Instant.EPOCH));
public static final Version KUBENETES_CLIENT =
new Version(Versions.KUBERNETES_CLIENT, "unknown", Date.from(Instant.EPOCH));

private final String sdk;
private final String commit;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.javaoperatorsdk.operator.api.config;

import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

public class VersionTest {

@Test
void versionShouldReturnTheSameResultFromMavenAndProperties() {
String versionFromProperties = Utils.loadFromProperties().getSdkVersion();
String versionFromMaven = Version.UNKNOWN.getSdkVersion();

assertEquals(versionFromProperties, versionFromMaven);
}

}