Skip to content

Commit 5444476

Browse files
committed
Inject version from version.properties
1 parent 4209b41 commit 5444476

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

gbfs-validator-java-cli/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@
8080
</dependencies>
8181

8282
<build>
83+
<resources>
84+
<resource>
85+
<directory>src/main/resources</directory>
86+
<filtering>true</filtering>
87+
</resource>
88+
</resources>
8389
<plugins>
8490
<!-- Compiler with Picocli annotation processor -->
8591
<plugin>

gbfs-validator-java-cli/src/main/java/org/entur/gbfs/validator/cli/GbfsValidatorCli.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@Command(
2424
name = "gbfs-validator",
2525
mixinStandardHelpOptions = true,
26-
version = "2.0.52-SNAPSHOT", // TODO this needs to be injected
26+
versionProvider = VersionProvider.class,
2727
description = "Validate GBFS feeds against JSON schemas",
2828
headerHeading = "Usage:%n%n",
2929
synopsisHeading = "%n",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.entur.gbfs.validator.cli;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Properties;
6+
import picocli.CommandLine;
7+
8+
public class VersionProvider implements CommandLine.IVersionProvider {
9+
10+
@Override
11+
public String[] getVersion() throws Exception {
12+
Properties properties = new Properties();
13+
try (
14+
InputStream input = getClass()
15+
.getClassLoader()
16+
.getResourceAsStream("version.properties")
17+
) {
18+
if (input == null) {
19+
return new String[] { "Unknown version" };
20+
}
21+
properties.load(input);
22+
String version = properties.getProperty("version", "Unknown version");
23+
return new String[] { version };
24+
} catch (IOException e) {
25+
return new String[] { "Unknown version" };
26+
}
27+
}
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=${project.version}

0 commit comments

Comments
 (0)