Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include build date on version #418

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading