Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

241: Gradle version plugin should allow a version.txt file #375

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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);