Skip to content

Commit e374516

Browse files
committed
make commit hash part of steve composite version
1 parent f57b085 commit e374516

6 files changed

Lines changed: 44 additions & 1 deletion

File tree

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@
140140
</configuration>
141141
</plugin>
142142

143+
<plugin>
144+
<groupId>pl.project13.maven</groupId>
145+
<artifactId>git-commit-id-plugin</artifactId>
146+
<version>2.2.4</version>
147+
<executions>
148+
<execution>
149+
<phase>initialize</phase>
150+
<goals>
151+
<goal>revision</goal>
152+
</goals>
153+
</execution>
154+
</executions>
155+
<configuration>
156+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
157+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
158+
</configuration>
159+
</plugin>
160+
143161
<!-- Read from main.properties the DB configuration -->
144162
<plugin>
145163
<groupId>org.codehaus.mojo</groupId>

src/main/java/de/rwth/idsg/steve/SteveConfiguration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum SteveConfiguration {
3131

3232
private final String contextPath;
3333
private final String steveVersion;
34+
private final String gitDescribe;
3435
private final ApplicationProfile profile;
3536
private final Ocpp ocpp;
3637
private final Auth auth;
@@ -42,6 +43,7 @@ public enum SteveConfiguration {
4243

4344
contextPath = sanitizeContextPath(p.getOptionalString("context.path"));
4445
steveVersion = p.getString("steve.version");
46+
gitDescribe = useFallbackIfNotSet(p.getOptionalString("git.describe"), null);
4547
profile = ApplicationProfile.fromName(p.getString("profile"));
4648

4749
jetty = Jetty.builder()
@@ -78,6 +80,26 @@ public enum SteveConfiguration {
7880
validate();
7981
}
8082

83+
public String getSteveCompositeVersion() {
84+
if (gitDescribe == null) {
85+
return steveVersion;
86+
} else {
87+
return steveVersion + "-g" + gitDescribe;
88+
}
89+
}
90+
91+
private static String useFallbackIfNotSet(String value, String fallback) {
92+
if (value == null) {
93+
// if the property is optional, value will be null
94+
return fallback;
95+
} else if (value.startsWith("${")) {
96+
// property value variables start with "${" (if maven is not used, the value will not be set)
97+
return fallback;
98+
} else {
99+
return value;
100+
}
101+
}
102+
81103
private String sanitizeContextPath(String s) {
82104
if (s == null || "/".equals(s)) {
83105
return "";

src/main/java/de/rwth/idsg/steve/utils/InternetChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private InternetChecker() { }
2929
);
3030

3131
static {
32-
System.setProperty("http.agent", "SteVe/" + SteveConfiguration.CONFIG.getSteveVersion());
32+
System.setProperty("http.agent", "SteVe/" + SteveConfiguration.CONFIG.getSteveCompositeVersion());
3333
}
3434

3535
/**

src/main/resources/config/dev/main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ auto.register.unknown.stations = false
5252

5353
### DO NOT MODIFY ###
5454
steve.version = ${project.version}
55+
git.describe = ${git.commit.id.describe}
5556
db.sql.logging = true
5657
profile = dev

src/main/resources/config/prod/main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ auto.register.unknown.stations = false
5252

5353
### DO NOT MODIFY ###
5454
steve.version = ${project.version}
55+
git.describe = ${git.commit.id.describe}
5556
db.sql.logging = false
5657
profile = prod

src/main/resources/config/test/main.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ auto.register.unknown.stations = false
5252

5353
### DO NOT MODIFY ###
5454
steve.version = ${project.version}
55+
git.describe = ${git.commit.id.describe}
5556
db.sql.logging = true
5657
profile = test

0 commit comments

Comments
 (0)