Skip to content
Snippets Groups Projects
Commit f87d7556 authored by René Schöne's avatar René Schöne
Browse files

Use correct file in Compiler. Always retrieve version from git describe.

- project property "withNewVersion" applies this version to current task(s) like jar or publish
- project property "asSnapshot" appends "-SNAPSHOT" to the version
parent 50eacf43
No related branches found
No related tags found
1 merge request!10Resolve "Fix versioning and prepare publishing"
This commit is part of merge request !10. Comments created here will be created in the context of that merge request.
...@@ -10,3 +10,4 @@ src/test/jastadd/*/*.ast ...@@ -10,3 +10,4 @@ src/test/jastadd/*/*.ast
src/test/jastadd/*/*.jadd src/test/jastadd/*/*.jadd
src/test/jastadd/*/*ResolverStubs.jrag src/test/jastadd/*/*ResolverStubs.jrag
!src/test/jastadd/*/MyRefResolver.jadd !src/test/jastadd/*/MyRefResolver.jadd
/gradle.properties
...@@ -14,6 +14,9 @@ repositories { ...@@ -14,6 +14,9 @@ repositories {
jcenter() jcenter()
} }
group = 'org.jastadd'
apply plugin: 'maven-publish'
buildscript { buildscript {
repositories.jcenter() repositories.jcenter()
dependencies { dependencies {
...@@ -43,6 +46,44 @@ sourceSets { ...@@ -43,6 +46,44 @@ sourceSets {
} }
} }
/* version string handling adapted from https://bitbucket.org/extendj/extendj/src/master/build.gradle
written by Jesper Öqvist <jesper.oqvist@cs.lth.se> */
def versionFile = 'src/main/resources/RelASTVersion.properties'
def oldProps = new Properties()
String oldFullVersion, fullVersion
try {
file(versionFile).withInputStream { stream -> oldProps.load(stream) }
oldFullVersion = oldProps['version']
} catch (ignored) {
// this happens, if either the properties file is not present, or cannot be read from
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 (hasProperty('asSnapshot')) {
version += '-SNAPSHOT'
}
println("Using version " + version)
}
if (oldFullVersion != fullVersion) {
def props = new Properties()
props['version'] = fullVersion
props.store(file(versionFile).newWriter(), null)
}
} else {
logger.warn('No git tags found to retrieve version.')
}
} catch (IOException e) {
logger.warn("Failded to run git describe (${e.getMessage()}) to retrieve version.")
}
jar { jar {
manifest { manifest {
attributes "Main-Class": 'org.jastadd.relast.compiler.Compiler' attributes "Main-Class": 'org.jastadd.relast.compiler.Compiler'
...@@ -110,46 +151,27 @@ jastadd { ...@@ -110,46 +151,27 @@ 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' publishing {
task updateVersion { publications {
/* version string handling adapted from https://bitbucket.org/extendj/extendj/src/master/build.gradle maven(MavenPublication) {
written by Jesper Öqvist <jesper.oqvist@cs.lth.se> */ artifact("build/libs/relast-${version}.jar") {
group 'build' extension 'jar'
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 { repositories {
logger.warn('No git tags found.') maven {
name 'nexus'
url "http://172.22.1.152:8081/repository/" + (project.hasProperty('asSnapshot') ? "maven-snapshots" : "maven-releases/")
credentials {
username project.repoUser
password project.repoPassword
} }
} catch (IOException e) {
logger.warn("Failded to run git describe (${e.getMessage()}).")
} }
} }
} }
processResources.dependsOn updateVersion publish.dependsOn jar
task preprocessRelationTest(type: JavaExec, group: 'verification') { task preprocessRelationTest(type: JavaExec, group: 'verification') {
......
...@@ -136,7 +136,7 @@ public class Compiler { ...@@ -136,7 +136,7 @@ public class Compiler {
*/ */
private String readVersion() { private String readVersion() {
try { try {
ResourceBundle resources = ResourceBundle.getBundle("Version"); ResourceBundle resources = ResourceBundle.getBundle("RelASTVersion");
return resources.getString("version"); return resources.getString("version");
} catch (MissingResourceException e) { } catch (MissingResourceException e) {
return "version ?"; return "version ?";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment