Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Update Client Version to be ethstats friendly #258

Merged
merged 9 commits into from
Nov 14, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,33 @@ configure(subprojects.findAll {it.name != 'errorprone-checks'}) {
}
}

// Takes the version, and if -SNAPSHOT is part of it replaces SNAPSHOT
// with the git commit version.
def calculateVersion() {
String version = rootProject.version
if (version.endsWith("-SNAPSHOT")) {
version = version.replace("-SNAPSHOT", "-dev-" + getCheckedOutGitCommitHash())
}
return version
}

def getCheckedOutGitCommitHash() {
def gitFolder = "$projectDir/.git/"
def takeFromHash = 8
/*
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
*/
def head = new File(gitFolder + "HEAD").text.split(":") // .git/HEAD
def isCommit = head.length == 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd

if(isCommit) return head[0].trim().take(takeFromHash) // e5a7c79edabb

def refHead = new File(gitFolder + head[1].trim()) // .git/refs/heads/master
refHead.text.trim().take takeFromHash
}

apply plugin: 'net.researchgate.release'

task releaseIntegrationTest(type: Test){
Expand Down
29 changes: 24 additions & 5 deletions buildSrc/src/main/groovy/ProjectPropertiesFile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class ProjectPropertiesFile extends DefaultTask {
properties.add(new Property(name, value, PropertyType.STRING))
}

void addVersion(String name, String value) {
properties.add(new Property(name, value, PropertyType.VERSION))
}

@Nested
List<Property> getProperties() {
return properties
Expand All @@ -73,9 +77,11 @@ class ProjectPropertiesFile extends DefaultTask {
String[] methodDeclarations = properties.stream().map({p -> p.methodDeclaration()}).toArray()
return """package ${destPackage};

import tech.pegasys.pantheon.util.PlatformDetector;

// This file is generated via a gradle task and should not be edited directly.
public class ${filename} {
${String.join("\n ", varDeclarations)}
public final class ${filename} {
${String.join("\n", varDeclarations)}

private ${filename}() {}
${String.join("\n", methodDeclarations)}
Expand All @@ -84,7 +90,8 @@ ${String.join("\n", methodDeclarations)}
}

private enum PropertyType {
STRING("String")
STRING("String"),
VERSION("String");

private final String strVal
PropertyType(String strVal) {
Expand All @@ -96,7 +103,7 @@ ${String.join("\n", methodDeclarations)}
}
}

private static class Property {
private class Property {
private final String name
private final String value
private final PropertyType type
Expand All @@ -123,7 +130,19 @@ ${String.join("\n", methodDeclarations)}
}

String variableDeclaration() {
return " private static final ${type} ${name} = \"${value}\";"
switch (type) {
case PropertyType.STRING:
return " private static final ${type} ${name} = \"${value}\";"
case PropertyType.VERSION:
return " private static final ${type} ${name} =\n" +
" ${value}\n" +
" + \"/v\"\n" +
" + ${filename}.class.getPackage().getImplementationVersion()\n" +
" + \"/\"\n" +
" + PlatformDetector.getOS()\n" +
" + \"/\"\n" +
" + PlatformDetector.getVM();"
}
}

String methodDeclaration() {
Expand Down
8 changes: 6 additions & 2 deletions config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-config'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions consensus/clique/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ plugins { id 'java' }
jar {
baseName 'pantheon-clique'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions consensus/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-consensus-common'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-ibft'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions consensus/ibftlegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-ibftlegacy'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-crypto'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/blockcreation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-blockcreation'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-core'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/eth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-eth'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/jsonrpc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-json-rpc'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/mock-p2p/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-mock-p2p'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/p2p/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-p2p'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/rlp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-ethereum-rlp'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
8 changes: 6 additions & 2 deletions ethereum/trie/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon-trie'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down
11 changes: 8 additions & 3 deletions pantheon/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ apply plugin: 'java-library'
jar {
baseName 'pantheon'
manifest {
attributes('Implementation-Title': baseName,
'Implementation-Version': project.version)
attributes(
'Specification-Title': baseName,
'Specification-Version': project.version,
'Implementation-Title': baseName,
'Implementation-Version': calculateVersion()
)
}
}

Expand Down Expand Up @@ -58,7 +62,8 @@ dependencies {

task writeInfoFile(type: ProjectPropertiesFile) {
destPackage = "tech.pegasys.pantheon"
addString("version", "$rootProject.name/$rootProject.version")
addString("clientIdentity", rootProject.name)
addVersion("version", "clientIdentity")
}

compileJava.dependsOn(writeInfoFile)
18 changes: 16 additions & 2 deletions pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package tech.pegasys.pantheon;

import tech.pegasys.pantheon.util.PlatformDetector;

// This file is generated via a gradle task and should not be edited directly.
public class PantheonInfo {
private static final String version = "pantheon/0.9.0-SNAPSHOT";
public final class PantheonInfo {
private static final String clientIdentity = "pantheon";
private static final String version =
shemnon marked this conversation as resolved.
Show resolved Hide resolved
clientIdentity
+ "/v"
+ PantheonInfo.class.getPackage().getImplementationVersion()
+ "/"
+ PlatformDetector.getOS()
+ "/"
+ PlatformDetector.getVM();

private PantheonInfo() {}

public static String clientIdentity() {
return clientIdentity;
}

public static String version() {
return version;
}
Expand Down
Loading