Add git hash (from refs/remotes/origin/master) to error reports.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
e535a88840
commit
c70fcb296f
|
@ -171,6 +171,12 @@ public class ErrorHandler {
|
||||||
if (version != null && !version.equals("${pom.version}")) {
|
if (version != null && !version.equals("${pom.version}")) {
|
||||||
sb.append("**Version:** ");
|
sb.append("**Version:** ");
|
||||||
sb.append(version);
|
sb.append(version);
|
||||||
|
String hash = Utils.getGitHash();
|
||||||
|
if (hash != null) {
|
||||||
|
sb.append(" (");
|
||||||
|
sb.append(hash.substring(0, 12));
|
||||||
|
sb.append(')');
|
||||||
|
}
|
||||||
sb.append('\n');
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
String timestamp = props.getProperty("build.date");
|
String timestamp = props.getProperty("build.date");
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.io.BufferedInputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -576,4 +577,29 @@ public class Utils {
|
||||||
public static boolean parseBoolean(String s) {
|
public static boolean parseBoolean(String s) {
|
||||||
return (Integer.parseInt(s) == 1);
|
return (Integer.parseInt(s) == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the git hash of the remote-tracking branch 'origin/master' from the
|
||||||
|
* most recent update to the working directory (e.g. fetch or successful push).
|
||||||
|
* @return the 40-character SHA-1 hash, or null if it could not be determined
|
||||||
|
*/
|
||||||
|
public static String getGitHash() {
|
||||||
|
if (isJarRunning())
|
||||||
|
return null;
|
||||||
|
File f = new File(".git/refs/remotes/origin/master");
|
||||||
|
if (!f.isFile())
|
||||||
|
return null;
|
||||||
|
try (BufferedReader in = new BufferedReader(new FileReader(f))) {
|
||||||
|
char[] sha = new char[40];
|
||||||
|
if (in.read(sha, 0, sha.length) < sha.length)
|
||||||
|
return null;
|
||||||
|
for (int i = 0; i < sha.length; i++) {
|
||||||
|
if (Character.digit(sha[i], 16) == -1)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return String.valueOf(sha);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user