Skip to content

Commit

Permalink
Better error handling and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Jun 28, 2018
1 parent e595cdc commit caf851a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/main/java/com/widen/versioning/VersionGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public static String gitDescribe(Settings settings, File projectDir) {

process.waitFor();
if (process.exitValue() != 0 || output.isEmpty()) {
return null;
throw new RuntimeException("Git returned status code " + process.exitValue() + ": " + output);
}

return output;
} catch (Exception e) {
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand Down
28 changes: 19 additions & 9 deletions src/main/java/com/widen/versioning/VersioningPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@ public void apply(final Project project) {
task.doLast(t -> System.out.println(project.getVersion()));

// Defer setting the version until after the build script is evaluated.
project.afterEvaluate(p -> {
String version = VersionGenerator.generateFromGit(settings, p.getRootProject().getProjectDir());
if (version != null) {
p.setVersion(version);
}
else if ("unspecified".equals(p.getVersion())) {
p.setVersion(settings.initialVersion);
}
});
project.afterEvaluate(p -> applyVersion(project, settings));
}

private void applyVersion(final Project project, final Settings settings) {
String version = null;
try {
version = VersionGenerator.generateFromGit(settings, project.getRootProject().getProjectDir());
}
catch (Exception e) {
project.getLogger().warn("Error trying to determine project version", e);
}

if (version != null) {
project.setVersion(version);
}
else if ("unspecified".equals(project.getVersion())) {
project.getLogger().debug("No version specified, using initial version");
project.setVersion(settings.initialVersion);
}
}
}

0 comments on commit caf851a

Please sign in to comment.