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

Commit

Permalink
Update Client Version to be ethstats friendly (#258)
Browse files Browse the repository at this point in the history
Update value returned by web3_clientVersion to be ethstats friendly

* Version part starts with a v
* SNAPSHOT builds report 32 bits of the git hash
* OS and architecture are sniffed out and reported
* JVM version and branding are sniffed out and reported

Example values (not all real):
pantheon/v0.9.0-dev-f800a0b1/osx-x86_64/oracle-java-1.8
pantheon/v0.9.0-dev-27960b57/osx-x86_64/zulu-java-11
pantheon/v0.9.0/linux-arm64/openjdk-java-12
  • Loading branch information
shemnon committed Nov 14, 2018
1 parent 21bc640 commit 002d9ce
Show file tree
Hide file tree
Showing 23 changed files with 411 additions and 46 deletions.
27 changes: 27 additions & 0 deletions build.gradle
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
33 changes: 27 additions & 6 deletions buildSrc/src/main/groovy/ProjectPropertiesFile.groovy
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,13 +130,27 @@ ${String.join("\n", methodDeclarations)}
}

String variableDeclaration() {
return " private static final ${type} ${name} = \"${value}\";"
def constantName = name.replaceAll("([a-z])([A-Z]+)", '$1_$2').toUpperCase()
def constantValue = value.replaceAll("([a-z])([A-Z]+)", '$1_$2').toUpperCase()
switch (type) {
case PropertyType.STRING:
return " private static final ${type} ${constantName} = \"${value}\";"
case PropertyType.VERSION:
return " private static final ${type} ${constantName} =\n" +
" ${constantValue}\n" +
" + \"/v\"\n" +
" + ${filename}.class.getPackage().getImplementationVersion()\n" +
" + \"/\"\n" +
" + PlatformDetector.getOS()\n" +
" + \"/\"\n" +
" + PlatformDetector.getVM();"
}
}

String methodDeclaration() {
return """
public static ${type} ${name}() {
return ${name};
return ${name.replaceAll("([a-z])([A-Z]+)", '$1_$2').toUpperCase()};
}"""
}
}
Expand Down
8 changes: 6 additions & 2 deletions config/build.gradle
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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)
20 changes: 17 additions & 3 deletions pantheon/src/main/java/tech/pegasys/pantheon/PantheonInfo.java
@@ -1,12 +1,26 @@
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 CLIENT_IDENTITY = "pantheon";
private static final String VERSION =
CLIENT_IDENTITY
+ "/v"
+ PantheonInfo.class.getPackage().getImplementationVersion()
+ "/"
+ PlatformDetector.getOS()
+ "/"
+ PlatformDetector.getVM();

private PantheonInfo() {}

public static String clientIdentity() {
return CLIENT_IDENTITY;
}

public static String version() {
return version;
return VERSION;
}
}

0 comments on commit 002d9ce

Please sign in to comment.