Skip to content

Commit

Permalink
Include Quarkus version in version endpoint and fix native (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwalluck authored Sep 24, 2024
1 parent b5b5d56 commit 0264737
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
41 changes: 20 additions & 21 deletions src/main/java/org/jboss/pnc/ppitegrator/rest/VersionResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ public class VersionResource implements VersionService {
public static final String UNKNOWN_VERSION = "unknown";

public static final Pattern VERSION_PATTERN = Pattern.compile(
"^(\\d+\\.\\d+\\.\\d+(-SNAPSHOT)? \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}([+-]\\d{2}:\\d{2}|Z)? [0-9a-f]{7}|"
"^(\\d+\\.\\d+\\.\\d+(-SNAPSHOT)? \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}([+-]\\d{2}:\\d{2}|Z)? [0-9a-f]{7} \\d+\\.\\d+\\.\\d+(-SNAPSHOT)?|"
+ UNKNOWN_VERSION + ")$");

private static final String GIT_PROPERTIES = "git.properties";
private static final String APPLICATION_PROPERTIES = "application.properties";

private static final int NUM_PROPERTIES = 4;

private static final String GIT_BUILD_VERSION = "git.build.version";

private static final String GIT_BUILD_TIME = "git.build.time";

private static final String GIT_COMMIT_ID_ABBREV = "git.commit.id.abbrev";

private static final String VERSION_IO_QUARKUS = "version.io.quarkus";

private static String version;

@Override
Expand All @@ -48,27 +52,22 @@ public String getVersion() {
}

try {
var resources = VersionResource.class.getClassLoader().getResources(GIT_PROPERTIES);
var props = new Properties();

while (resources.hasMoreElements()) {
var url = resources.nextElement();
Log.debugf("Loaded GIT information from %s", url);

try (var in = url.openStream()) {
props.load(in);
var gitBuildVersion = props.getProperty(GIT_BUILD_VERSION);
Objects.requireNonNull(gitBuildVersion);
var gitBuildTime = props.getProperty(GIT_BUILD_TIME);
Objects.requireNonNull(gitBuildTime);
var buildTime = OffsetDateTime.parse(gitBuildTime).toString();
var gitCommitIdAbbrev = props.getProperty(GIT_COMMIT_ID_ABBREV);
Objects.requireNonNull(gitCommitIdAbbrev);
version = String.join(" ", gitBuildVersion, buildTime, gitCommitIdAbbrev).stripLeading();
}
try (var in = VersionService.class.getResourceAsStream(APPLICATION_PROPERTIES)) {
var props = new Properties(NUM_PROPERTIES);
props.load(in);
var gitBuildVersion = props.getProperty(GIT_BUILD_VERSION);
Objects.requireNonNull(gitBuildVersion);
var gitBuildTime = props.getProperty(GIT_BUILD_TIME);
Objects.requireNonNull(gitBuildTime);
var buildTime = OffsetDateTime.parse(gitBuildTime).toString();
var gitCommitIdAbbrev = props.getProperty(GIT_COMMIT_ID_ABBREV);
Objects.requireNonNull(gitCommitIdAbbrev);
var versionIoQuarkus = props.getProperty(VERSION_IO_QUARKUS);
version = String.join(" ", gitBuildVersion, buildTime, gitCommitIdAbbrev, versionIoQuarkus)
.stripLeading();
}
} catch (Exception e) {
Log.errorf("Error reading GIT information from %s", GIT_PROPERTIES, e);
Log.errorf("Error reading properties from %s", APPLICATION_PROPERTIES, e);
version = UNKNOWN_VERSION;
}

Expand Down
17 changes: 12 additions & 5 deletions src/main/resources/META-INF/resources/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@
<script>
/*<![CDATA[*/
$(function() {
const dropdown = $('#product-dropdown');
$.get('/api/version')
.done(function(data) {
version.html('Version: ' + data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
const errorMessage = JSON.parse(jqXHR.responseText);
const msg = 'Error ' + errorMessage.code + ': ' + errorMessage.message;
version.html('Version: ' + msg);
});

const dropdown = $('#product-dropdown');
dropdown.empty();
dropdown.append('<option disabled="disabled" selected="selected">Select a Product<\/option>');

const dropdown2 = $('#release-dropdown');

dropdown2.empty();
dropdown2.append('<option disabled="disabled" selected="selected">Select a Release<\/option>');

Expand All @@ -69,6 +77,7 @@

const product_phase = $('#product-phase');
const release_phase = $('#release-phase');
const version = $('#version');
const productErrorAlert = $('#productErrorAlert');
const productErrorAlertMessage = $('#productErrorAlertMessage');
const releaseErrorAlert = $('#releaseErrorAlert');
Expand Down Expand Up @@ -136,9 +145,7 @@
<div class="container">
<div class="page-header">
<h1 style="text-align: center">Product Pages Integrator</h1>
<h2 style="text-align: center">${git.build.version}</h2>
<h3 style="text-align: center">${git.build.time}</h3>
<h4 style="text-align: center">${git.commit.id.abbrev}</h4>
<p style="text-align: center"><span id="version" class="label label-primary"></span></p>
</div>
<div class="form-container">
<form class="form-horizontal">
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ quarkus.package.output-name=pp-integrator
quarkus.shutdown.timeout = 30
# FIXME
quarkus.tls.trust-all=true

git.build.version=${git.build.version}
git.build.time=${git.build.time}
git.commit.id.abbrev=${git.commit.id.abbrev}
version.io.quarkus=${version.io.quarkus}
20 changes: 11 additions & 9 deletions src/test/java/org/jboss/pnc/ppitegrator/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
import static org.jboss.resteasy.reactive.RestResponse.StatusCode.OK;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.Objects;
import java.util.Set;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.pnc.ppitegrator.pp.model.Phase;
import org.jboss.pnc.ppitegrator.rest.ErrorMessage;
import org.junit.jupiter.api.Test;
Expand All @@ -43,12 +43,6 @@

@QuarkusTest
class AppTest {
@ConfigProperty(name = "test.product_shortname")
String productShortname;

@ConfigProperty(name = "test.release_shortname")
String releaseShortname;

private static final String MISSING_SHORTNAME = "XXX";

private static final String INVALID_SHORTNAME = "000";
Expand All @@ -74,6 +68,10 @@ private static void verifyBadRequest(String errorMessage) {

@Test
void testPhaseProductEndpoint() {
var productShortname = System.getProperty("test.product_shortname");
Objects.requireNonNull(
productShortname,
"Product shortname cannot be null. Use \"-Dtest.product_shortname=jbossfoo\"");
var name = given().log()
.all()
.accept(TEXT_PLAIN)
Expand Down Expand Up @@ -133,6 +131,10 @@ void testInvalidPhaseProductEndpoint() {

@Test
void testPhaseReleaseEndpoint() {
var releaseShortname = System.getProperty("test.release_shortname");
Objects.requireNonNull(
releaseShortname,
"Release shortname cannot be null. Use \"-Dtest.release_shortname=jbossfoo-1-0.0\"");
var name = given().log()
.all()
.accept(TEXT_PLAIN)
Expand Down Expand Up @@ -234,8 +236,8 @@ void testReleasesEndpoint() {

@Test
void testVersionRegex() {
assertThat("1.0.0-SNAPSHOT 2024-08-26T11:36:27-04:00 a2bbb6a", matchesRegex(VERSION_PATTERN));
assertThat("1.0.0-SNAPSHOT 2024-08-26T15:29:09Z f6dfbe7", matchesRegex(VERSION_PATTERN));
assertThat("1.0.0-SNAPSHOT 2024-08-26T11:36:27-04:00 a2bbb6a 3.15.0", matchesRegex(VERSION_PATTERN));
assertThat("1.0.0-SNAPSHOT 2024-08-26T15:29:09Z f6dfbe7 3.15.0", matchesRegex(VERSION_PATTERN));
assertThat(UNKNOWN_VERSION, matchesRegex(VERSION_PATTERN));
}

Expand Down

0 comments on commit 0264737

Please sign in to comment.