Skip to content

Commit

Permalink
Merge pull request #418 from jonesbusy/feature/build-date
Browse files Browse the repository at this point in the history
Include build date on version
  • Loading branch information
jonesbusy authored Dec 8, 2024
2 parents efbd722 + 498364c commit 6265a52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ public class PomVersionProvider implements CommandLine.IVersionProvider {

@Override
public String[] getVersion() throws Exception {
return new String[] {getVersionFromProperties()};
return new String[] {
"plugin modernizer %s (%s)".formatted(getValue("project.version"), getValue("build.timestamp")),
};
}

private String getVersionFromProperties() throws IOException {
/**
* Get a value from the pom.properties file
* @param property the property to get
* @return the value of the property
* @throws IOException if the file is not found
*/
private String getValue(String property) throws IOException {
Properties properties = new Properties();
try (InputStream input = getClass().getClassLoader().getResourceAsStream("pom.properties")) {
if (input == null) {
Expand All @@ -22,11 +30,11 @@ private String getVersionFromProperties() throws IOException {
properties.load(input);
}

String version = properties.getProperty("project.version");
if (version == null || version.isEmpty()) {
throw new ModernizerException("Version not found in pom.properties");
String value = properties.getProperty(property);
if (value == null || value.isEmpty()) {
throw new ModernizerException("%s not found in pom.properties".formatted(property));
}

return version;
return value;
}
}
1 change: 1 addition & 0 deletions plugin-modernizer-cli/src/main/resources/pom.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
project.version = ${project.version}
build.timestamp = ${maven.build.timestamp}
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

<properties>

<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>

<!-- Reproducible builds -->
<project.build.outputTimestamp>2024-01-01T00:00:00Z</project.build.outputTimestamp>

Expand Down

0 comments on commit 6265a52

Please sign in to comment.