Skip to content

Commit 5462cb1

Browse files
committed
Inject version from build properties
1 parent 437c2bd commit 5462cb1

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

gbfs-validator-java-api/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
<execution>
204204
<goals>
205205
<goal>repackage</goal>
206+
<goal>build-info</goal>
206207
</goals>
207208
</execution>
208209
</executions>

gbfs-validator-java-api/src/main/java/org/entur/gbfs/validator/api/handler/ValidateApiDelegateHandler.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ public class ValidateApiDelegateHandler implements ValidateApiDelegate {
6666
private static final Logger logger = LoggerFactory.getLogger(ValidateApiDelegateHandler.class);
6767

6868
private final Loader loader;
69+
private final VersionProvider versionProvider;
6970

7071
/**
7172
* Creates a new validation handler.
7273
*
7374
* @param loader the GBFS file loader to use
75+
* @param versionProvider provides access to application version information
7476
*/
75-
public ValidateApiDelegateHandler(Loader loader) {
77+
public ValidateApiDelegateHandler(Loader loader, VersionProvider versionProvider) {
7678
this.loader = loader;
79+
this.versionProvider = versionProvider;
7780
}
7881

7982
/**
@@ -170,7 +173,7 @@ private org.entur.gbfs.validator.api.model.ValidationResult mergeValidationResul
170173
if (results.isEmpty()) {
171174
org.entur.gbfs.validator.api.model.ValidationResult emptyApiResult = new org.entur.gbfs.validator.api.model.ValidationResult();
172175
ValidationResultSummary emptySummary = new ValidationResultSummary();
173-
emptySummary.setValidatorVersion("2.0.30-SNAPSHOT");
176+
emptySummary.setValidatorVersion(versionProvider.getVersion());
174177
emptySummary.setFiles(new ArrayList<>());
175178
emptyApiResult.setSummary(emptySummary);
176179
return emptyApiResult;
@@ -199,7 +202,7 @@ private org.entur.gbfs.validator.api.model.ValidationResult mapValidationResult(
199202
String language
200203
) {
201204
ValidationResultSummary validationResultSummary = new ValidationResultSummary();
202-
validationResultSummary.setValidatorVersion("2.0.30-SNAPSHOT");
205+
validationResultSummary.setValidatorVersion(versionProvider.getVersion());
203206

204207
validationResultSummary.setFiles(
205208
mapFiles(loadedFilesForLanguage, internalValidationResult.files(), language)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
*
3+
* *
4+
* *
5+
* * * Licensed under the EUPL, Version 1.2 or – as soon they will be approved by
6+
* * * the European Commission - subsequent versions of the EUPL (the "Licence");
7+
* * * You may not use this work except in compliance with the Licence.
8+
* * * You may obtain a copy of the Licence at:
9+
* * *
10+
* * * https://joinup.ec.europa.eu/software/page/eupl
11+
* * *
12+
* * * Unless required by applicable law or agreed to in writing, software
13+
* * * distributed under the Licence is distributed on an "AS IS" basis,
14+
* * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* * * See the Licence for the specific language governing permissions and
16+
* * * limitations under the Licence.
17+
* *
18+
*
19+
*/
20+
21+
package org.entur.gbfs.validator.api.handler;
22+
23+
import org.springframework.boot.info.BuildProperties;
24+
import org.springframework.stereotype.Component;
25+
26+
/**
27+
* Provides access to application build information including version.
28+
* Wraps Spring Boot's BuildProperties for easier access.
29+
*/
30+
@Component
31+
public class VersionProvider {
32+
33+
private final BuildProperties buildProperties;
34+
35+
public VersionProvider(BuildProperties buildProperties) {
36+
this.buildProperties = buildProperties;
37+
}
38+
39+
public String getVersion() {
40+
return buildProperties.getVersion();
41+
}
42+
}

0 commit comments

Comments
 (0)