description = "Generates the build.properties file."
doLast {
- // Must fail if there are uncommitted changes
- def status = "git status --short".execute().text.trim()
- if (!status.isEmpty()) {
- throw new GradleException("There are uncomitted changes:\n " + status)
- }
Properties info = new Properties()
+ def status = "git status --short".execute().text.trim()
def revision = "git rev-parse --short HEAD".execute().text.trim()
def userName = ["git", "log", "-1", "--format=%an <%ae>"].execute().text.trim()
def date = "git log -1 --format=%ci".execute().text.trim()
}
@Test
- public void hashMustMatch() {
+ public void hashMustExist() {
InputStream stream = jpf.getClass().getResourceAsStream(".version");
- assertEquals("Should have the same hash", fetchCurrentRevisionFromVCS().trim(), readContentFrom(stream).trim());
- }
-
- private String fetchCurrentRevisionFromVCS() {
- String currentRevision = "";
- try {
- Process process = Runtime.getRuntime().exec("git rev-parse HEAD");
- process.waitFor();
- InputStream output = process.getInputStream();
- currentRevision = readContentFrom(output);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return currentRevision;
+ assertTrue(".version file should be non-empty", !readContentFrom(stream).trim().isEmpty());
}
private String readContentFrom(InputStream stream) {