Skip to content
Snippets Groups Projects
Commit 0b47751a authored by Johannes Mey's avatar Johannes Mey
Browse files

Merge branch '20-create-script-to-include-commit-in-version-string' into 'master'

Resolve "Create script to include commit in version string"

Closes #20

See merge request !7
parents d01f774d 543f9c59
No related branches found
No related tags found
1 merge request!7Resolve "Create script to include commit in version string"
Pipeline #5106 passed
...@@ -110,6 +110,47 @@ jastadd { ...@@ -110,6 +110,47 @@ jastadd {
jastaddOptions = ["--lineColumnNumbers", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"] jastaddOptions = ["--lineColumnNumbers", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
} }
def versionFile = 'src/main/resources/RelASTVersion.properties'
task updateVersion {
/* version string handling adapted from https://bitbucket.org/extendj/extendj/src/master/build.gradle
written by Jesper Öqvist <jesper.oqvist@cs.lth.se> */
group 'build'
description 'Updates the version file for RelAST'
doLast {
def oldProps = new Properties()
String oldFullVersion, fullVersion
try {
file(versionFile).withInputStream { stream -> oldProps.load(stream) }
oldFullVersion = oldProps['version']
} catch (ignored) {
oldFullVersion = "???"
}
try {
def proc = 'git describe'.execute(null, rootDir)
if (proc.waitFor() == 0) {
fullVersion = proc.text.trim()
if (hasProperty('withNewVersion')) {
// Trim to get latest tag:
version = (fullVersion =~ /-\d+\-g.+$/).replaceAll('')
}
if (oldFullVersion != fullVersion) {
def props = new Properties()
props['version'] = fullVersion
props.store(file(versionFile).newWriter(), null)
}
} else {
logger.warn('No git tags found.')
}
} catch (IOException e) {
logger.warn("Failded to run git describe (${e.getMessage()}).")
}
}
}
processResources.dependsOn updateVersion
task preprocessRelationTest(type: JavaExec, group: 'verification') { task preprocessRelationTest(type: JavaExec, group: 'verification') {
doFirst { doFirst {
......
...@@ -8,14 +8,11 @@ import org.jastadd.relast.parser.RelAstParser; ...@@ -8,14 +8,11 @@ import org.jastadd.relast.parser.RelAstParser;
import org.jastadd.relast.scanner.RelAstScanner; import org.jastadd.relast.scanner.RelAstScanner;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List; import java.util.List;
public class Compiler { public class Compiler {
private static final String VERSION = "0.2.4";
private ArrayList<Option<?>> options; private ArrayList<Option<?>> options;
private FlagOption optionWriteToFile; private FlagOption optionWriteToFile;
private FlagOption optionPrintAST; private FlagOption optionPrintAST;
...@@ -35,7 +32,7 @@ public class Compiler { ...@@ -35,7 +32,7 @@ public class Compiler {
commandLine = new CommandLine(options); commandLine = new CommandLine(options);
commandLine.parse(args); commandLine.parse(args);
printMessage("Running RelAST " + VERSION); printMessage("Running RelAST " + readVersion());
if (commandLine.getArguments().size() < 1) { if (commandLine.getArguments().size() < 1) {
error("specify at least one input file"); error("specify at least one input file");
...@@ -126,6 +123,26 @@ public class Compiler { ...@@ -126,6 +123,26 @@ public class Compiler {
} }
} }
/**
* Reads the version string.
*
* The version string is read from the property file
* src/main/resources/Version.properties. This
* file should be generated during the build process. If it is missing
* then there is some problem in the build script.
*
* @author Jesper Öqvist <jesper.oqvist@cs.lth.se>
* @return the read version string, or <code>version ?</code>
*/
private String readVersion() {
try {
ResourceBundle resources = ResourceBundle.getBundle("Version");
return resources.getString("version");
} catch (MissingResourceException e) {
return "version ?";
}
}
public static void main(String[] args) { public static void main(String[] args) {
try { try {
new Compiler(args); new Compiler(args);
......
RelASTVersion.properties
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment