Skip to content

Commit

Permalink
[project-version-maven-plugin] Provide more properties
Browse files Browse the repository at this point in the history
In addition to project.detailedVersion, also provide the parts it's
made up of:

- project.detailedVersion.timestamp
- project.detailedVersion.commit
  • Loading branch information
bertfrees committed Oct 23, 2018
1 parent 5a71309 commit 5b4a489
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,37 @@ public class SetDetailedProjectVersionMojo extends AbstractMojo {
private String projectVersion;

public void execute() throws MojoFailureException {
String detailedVersion; {
String detailedVersion;
String timeStamp;
String gitCommit; {
try {
if (projectVersion.endsWith("-SNAPSHOT")) {
String timeStamp = new SimpleDateFormat("yyyyMMdd.HHmmss").format(new Date());
String gitDescription; {
Process p = Runtime.getRuntime().exec("git describe --tags --always --dirty");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
gitDescription = reader.readLine();
if (gitDescription == null || reader.readLine() != null)
throw new RuntimeException();
}
timeStamp = new SimpleDateFormat("yyyyMMdd.HHmmss").format(new Date());
Process p = Runtime.getRuntime().exec("git describe --tags --always --dirty");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
gitCommit = reader.readLine();
if (gitCommit == null || reader.readLine() != null)
throw new RuntimeException();
detailedVersion = projectVersion.substring(0, projectVersion.length() - 9)
+ "~" + timeStamp
+ "-" + gitDescription
+ "-" + gitCommit
;
} else
} else {
timeStamp = null;
gitCommit = null;
detailedVersion = projectVersion;
}
} catch (Exception e) {
throw new MojoFailureException("Error computing detailed version", e);
}
}
project.getProperties().put("project.detailedVersion", detailedVersion);
if (timeStamp != null) {
project.getProperties().put("project.detailedVersion.timestamp", timeStamp);
}
if (gitCommit != null) {
project.getProperties().put("project.detailedVersion.commit", gitCommit);
}
}
}

0 comments on commit 5b4a489

Please sign in to comment.