Skip to content
Permalink
Browse files
241: Gradle version plugin should allow a version.txt file
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Jan 23, 2020
1 parent 5efaf03 commit 73dda3f098ccf16ab7fadeecbff1a18b21a85703
Showing 1 changed file with 15 additions and 1 deletion.
@@ -27,9 +27,12 @@
import org.gradle.api.Project;
import org.gradle.api.GradleException;

import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
import java.io.IOException;

import static java.util.stream.Collectors.toList;

public class VersionPlugin implements Plugin<Project> {
public void apply(Project project) {
var pb = new ProcessBuilder("git", "rev-parse", "HEAD");
@@ -47,7 +50,18 @@ public void apply(Project project) {
}
project.setProperty("version", desc);
} else {
project.setProperty("version", "unknown");
var root = project.getRootProject().getRootDir().toPath();
var versionTxt = root.resolve("version.txt");
if (Files.exists(versionTxt)) {
var lines = Files.lines(versionTxt).collect(toList());
if (!lines.isEmpty()) {
project.setProperty("version", lines.get(0));
} else {
project.setProperty("version", "unknown");
}
} else {
project.setProperty("version", "unknown");
}
}
} catch (InterruptedException e) {
throw new GradleException("'git rev-parse' was interrupted", e);

0 comments on commit 73dda3f

Please sign in to comment.