Skip to content

Commit

Permalink
Remove versionModifier from version.properties, detecting the modifie…
Browse files Browse the repository at this point in the history
…r based on the current Git branch: master = 'RELEASE', other = 'SNAPSHOT'
  • Loading branch information
Nashatyrev committed Apr 15, 2016
1 parent 1402230 commit b3794fc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 19 deletions.
11 changes: 7 additions & 4 deletions build.gradle
Expand Up @@ -10,18 +10,21 @@ allprojects {
}
}

def gitCurBranch() {
def process = "git rev-parse --abbrev-ref HEAD".execute()
return process.text.trim()
}

subprojects {
apply plugin: 'java'

def config = new ConfigSlurper().parse(new File("$projectDir/src/main/resources/version.properties").toURI().toURL())

group = 'org.ethereum'

if (config.modifier?.trim())
version = config.versionNumber + "-" + config.modifier
else
version = config.versionNumber
version = config.versionNumber + ("master" == gitCurBranch() ? "-RELEASE" : "-SNAPSHOT")

println("Building version: " + version)

compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << '-XDignore.symbol.file'
Expand Down
9 changes: 7 additions & 2 deletions ethereumj-core/build.gradle
Expand Up @@ -250,7 +250,7 @@ tasks.processResources.doLast(){
println 'This will be printed after the build task even if something else calls the build task'

File versionfile = file(new File('build/resources/main/build-info.properties'))
versionfile.text = 'build.hash=' + gitCommitHash() + 'build.time=' + buildTime()
versionfile.text = 'build.hash=' + gitCommitHash() + '\n' + 'build.time=' + buildTime() + '\n' + 'build.branch=' + gitCurBranch() + '\n'
}

task publish {
Expand Down Expand Up @@ -312,7 +312,7 @@ def customizePom(pom, gradleProject) {

def gitCommitHash() {
def process = "git rev-parse --short HEAD".execute()
return process.text
return process.text.trim()
}

def buildTime() {
Expand All @@ -321,3 +321,8 @@ def buildTime() {
return '[GMT]-' + df.format(new Date())
}

def gitCurBranch() {
def process = "git rev-parse --abbrev-ref HEAD".execute()
return process.text.trim()
}

Expand Up @@ -14,6 +14,7 @@
import org.ethereum.net.p2p.P2pHandler;
import org.ethereum.net.rlpx.MessageCodec;
import org.ethereum.net.rlpx.Node;
import org.ethereum.util.BuildInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
Expand Down Expand Up @@ -144,8 +145,7 @@ public SystemProperties(Config apiConfig) {

if (this.projectVersion == null) this.projectVersion = "-.-.-";

this.projectVersionModifier = props.getProperty("modifier");
this.projectVersionModifier = this.projectVersionModifier.replaceAll("\"", "");
this.projectVersionModifier = "master".equals(BuildInfo.buildBranch) ? "RELEASE" : "SNAPSHOT";

} catch (Exception e) {
logger.error("Can't read config.", e);
Expand Down
23 changes: 14 additions & 9 deletions ethereumj-core/src/main/java/org/ethereum/util/BuildInfo.java
Expand Up @@ -11,22 +11,27 @@ public class BuildInfo {

private static final Logger logger = LoggerFactory.getLogger("general");

public static String buildHash;
public static String buildTime;
public static String buildBranch;

public static void printInfo(){
static {
try {
Properties props = new Properties();
InputStream is = BuildInfo.class.getResourceAsStream("/build-info.properties");

if (is != null) {
props.load(is);

String hash = props.getProperty("build.hash");
String time = props.getProperty("build.time");
buildHash = props.getProperty("build.hash");
buildTime = props.getProperty("build.time");
buildBranch = props.getProperty("build.branch");
} catch (IOException e) {
logger.error("Error reading /build-info.properties", e);
}
}

logger.info("git.hash: [{}]", hash);
logger.info("build.time: {}", time);
logger.info("");
}
} catch (IOException e) {}
public static void printInfo(){
logger.info("git.hash: [{}]", buildHash);
logger.info("build.time: {}", buildTime);
}
}
3 changes: 1 addition & 2 deletions ethereumj-core/src/main/resources/version.properties
@@ -1,2 +1 @@
versionNumber='1.2.1'
modifier="RELEASE"
versionNumber='1.2.1'

0 comments on commit b3794fc

Please sign in to comment.