Skip to content

Commit

Permalink
Restoring web3j-cli (#50)
Browse files Browse the repository at this point in the history
* Initial Comit

* Remove Epirus only functionality

* Further refactoring

* Spotless

* Bumped Web3j project Version.
Removed login Token from web3j config

* Made printing more flexible

* Changed Open Api on success text.
Spotless.

* Bumped web3j version for generated projects.
Applied feedback.
Removed docker functionality, it is now in epirus.

* Removed Docker text
Spotless.

* final commit.
  • Loading branch information
AlexandrouR authored Jan 11, 2021
1 parent 686bcfc commit c8aac7d
Show file tree
Hide file tree
Showing 186 changed files with 7,383 additions and 2,600 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Deprecated
**********

The Web3j CLI has been renamed to the Epirus CLI. Please head `here <https://github.com/epirus-io/epirus-cli>`_ for the new repo.
The Web3j CLI has been renamed to the Web3j CLI. Please head `here <https://github.com/web3j/web3j-cli>`_ for the new repo.



Expand Down
131 changes: 112 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
import java.text.SimpleDateFormat

plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id "application"
id "distribution"
id "idea"
id "jacoco"
id "com.github.johnrengelman.shadow" version "5.1.0"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "com.diffplug.gradle.spotless" version "3.25.0"
id "de.undercouch.download" version "4.0.0"
id "de.marcphilipp.nexus-publish" version "0.4.0"
id 'io.codearte.nexus-staging' version '0.21.1'
id "com.jfrog.bintray" version "1.8.4"
}

description 'web3j command line tools'
mainClassName = 'org.web3j.console.Runner'
description 'Web3j command line tools'
mainClassName = 'org.web3j.console.Web3j'
applicationName = 'web3j'

ext {
web3jVersion = project.property('version')
web3jVersion = '4.8.3'
picocli = '4.0.4'
slf4jVersion = "1.7.+"
slf4jVersion = '1.7.30'
junitVersion = '5.+'
mockitoVersion = "3.+"
gsonVersion = "2.8.6"
wireMockVersion = "2.25.1"
mockitoVersion = '3.+'
gsonVersion = '2.8.6'
wireMockVersion = '2.25.1'
kotlinLoggin = '1.7.9'
dockerJavaVersion = '3.2.5'
web3jEpirusVersion = '0.0.7'
jaxbVersion = '2.2.11'
activationVersion = '1.1.1'
log4jVersion = '1.2.17'
semverVersion = '0.9.0'
commonsLangVersion = '3.9'
jcdpVersion = '4.0.1'
}


Expand All @@ -29,12 +44,13 @@ apply {
'java',
'javadoc',
'repositories',
'publish',
'spotless'
].each { buildScript ->
download {
src "https://raw.githubusercontent.com/web3j/build-tools/master/gradle/$buildScript/build.gradle"
dest "$rootDir/gradle/$buildScript/build.gradle"
overwrite true
overwrite false
quiet true
onlyIfModified true
}
Expand All @@ -43,8 +59,11 @@ apply {
}

repositories {

jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/ethereum/maven/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}

test {
Expand All @@ -63,26 +82,100 @@ distTar {
}

dependencies {
api "org.web3j:abi:$web3jVersion"

implementation "org.web3j:codegen:$web3jVersion",
"org.web3j:contracts:$web3jVersion",
"org.web3j:core:$web3jVersion",
"org.web3j:crypto:$web3jVersion",
"org.web3j:hosted-providers:$web3jVersion",
"io.epirus:epirus-web3j:$web3jEpirusVersion",
"info.picocli:picocli:$picocli",
files('libs/smartcheck.jar'),
"javax.xml.bind:jaxb-api:2.2.11",
"com.sun.xml.bind:jaxb-core:2.2.11",
"com.sun.xml.bind:jaxb-impl:2.2.11",
"javax.activation:activation:1.1.1",
"org.web3j:hosted-providers:$web3jVersion",
"javax.xml.bind:jaxb-api:$jaxbVersion",
"com.sun.xml.bind:jaxb-core:$jaxbVersion",
"com.sun.xml.bind:jaxb-impl:$jaxbVersion",
"javax.activation:activation:$activationVersion",
"com.google.code.gson:gson:$gsonVersion",
"javax.activation:activation:1.1.1",
"org.apache.commons:commons-lang3:3.9"
"org.apache.commons:commons-lang3:$commonsLangVersion",
"com.github.zafarkhaja:java-semver:$semverVersion",
"log4j:log4j:$log4jVersion",
"io.github.microutils:kotlin-logging:$kotlinLoggin",
"com.github.docker-java:docker-java:$dockerJavaVersion",
"com.diogonunes:JCDP:$jcdpVersion"

runtime "org.slf4j:slf4j-nop:$slf4jVersion"
runtimeOnly "org.slf4j:slf4j-nop:$slf4jVersion"

testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion",
"org.mockito:mockito-core:$mockitoVersion",
"org.mockito:mockito-inline:$mockitoVersion",
"com.github.tomakehurst:wiremock-jre8:$wireMockVersion"
testImplementation 'org.mockito:mockito-inline:3.3.0'
}


task createProperties(dependsOn: processResources) doLast {
// if resources dir is empty we need to create this ourselves
new File("$buildDir/resources/main/").mkdirs()

new File("$buildDir/resources/main/web3j-version.properties").withWriter { w ->
Properties p = new Properties()
p['version'] = project.version.toString()
p['timestamp'] = getTimestamp()
p.store w, null
}
}

def getTimestamp() {
Date today = new Date()
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z")
df.setTimeZone(TimeZone.getTimeZone("UTC"))
return df.format(today)
}
classes { dependsOn createProperties }

task shadowBugWorkaround(type: Jar) {
archiveBaseName = 'nested-gradle-jar'
from files(file("${rootDir}/gradle/wrapper/gradle-wrapper.jar"))
destinationDir file('build/shadow-bug-workaround')
}

shadowJar {
dependsOn shadowBugWorkaround
zip64 = true
// Shadow plugin bug: explodes the nested jar.
// Workaround: double-nest the jar.
// Refer https://github.com/johnrengelman/shadow/issues/111
from shadowBugWorkaround
}

sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
}

compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

sourceCompatibility = 1.8

def generatedResources = "$buildDir/generated-resources/main"

sourceSets {
main {
// Register an output folder on the main source set:
output.dir(generatedResources, builtBy: 'generateVersionProperties')
}
}

task generateVersionProperties {
description 'Creates a version.properties file with build info that is added to the root of the JAR'
doLast {
new File(generatedResources).mkdirs()
def generated = new File(generatedResources, "version.properties")
generated.write("version=$rootProject.version\n")
generated.append("timestamp=${System.currentTimeMillis()}\n")
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version=4.6.0-SNAPSHOT
version=4.8.2-SNAPSHOT
group=org.web3j.console
91 changes: 91 additions & 0 deletions gradle/publish/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: "de.marcphilipp.nexus-publish"

task javadocsJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}

task testsJar(type: Jar) {
archiveClassifier = 'tests'
from sourceSets.test.output
}

javadoc { options.encoding = 'UTF-8' }

artifacts { archives sourcesJar, javadocsJar, testsJar }

publishing {
publications {
maven(MavenPublication) {
from components.java

artifact sourcesJar
artifact javadocsJar
artifact testsJar

pom {
name = project.name
description.set(project.provider({ project.description }))
url = 'https://web3j.io'

licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

scm {
def slug = rootProject.name
if (project.hasProperty('rootProjectOverride')) {
slug = project.rootProjectOverride
}

url = "https://github.com/web3j/$slug"
connection = "scm:https://github.com/web3j/${slug}.git"
developerConnection = "scm:git://github.com/web3j/${slug}.git"
}

developers {
developer {
id = 'conor10'
name = 'Conor Svensson'
email = '[email protected]'
}
}
}
}
}
}

nexusPublishing {
repositories {
sonatype {
username = System.getenv('OSSRH_USERNAME')
password = System.getenv('OSSRH_PASSWORD')
}
}
}


nexusStaging {
username System.getenv('OSSRH_USERNAME')
password System.getenv('OSSRH_PASSWORD')
packageGroup = rootProject.group
}


signing {
sign publishing.publications.maven
def signingKey = new File("$rootDir/web3j.asc")
if (signingKey.exists()) {
useInMemoryPgpKeys(signingKey.getText('UTF-8'), System.getenv('GPG_PASSPHRASE'))
}
}
3 changes: 2 additions & 1 deletion gradle/spotless/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spotless {
include '**/src/*/java/**/*.java'
exclude '**/.gradle/**'
exclude '**/generated/**'
exclude '**/build/install/**'
}
removeUnusedImports()
googleJavaFormat("1.7").aosp()
Expand All @@ -36,6 +37,7 @@ spotless {
target fileTree('.') {
include '**/*.kt'
exclude '**/.gradle/**'
exclude '**/build/install/**'
}
ktlint('0.31.0')
trimTrailingWhitespace()
Expand All @@ -47,7 +49,6 @@ spotless {
greclipse().configFile("$rootDir/gradle/spotless/formatter.properties")
endWithNewline()
indentWithSpaces(4)
paddedCell()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2020 Web3 Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.web3j.console;

import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Stream;

import picocli.CommandLine.IDefaultValueProvider;
import picocli.CommandLine.Model.ArgSpec;
import picocli.CommandLine.Model.OptionSpec;

import static org.web3j.console.EnvironmentVariablesProperties.*;

public class EnvironmentVariableDefaultProvider implements IDefaultValueProvider {
private final Map<String, String> environment;

public EnvironmentVariableDefaultProvider(final Map<String, String> environment) {
this.environment = environment;
}

@Override
public String defaultValue(final ArgSpec argSpec) {
if (!argSpec.isOption()) {
return null;
}
return envVarNames((OptionSpec) argSpec)
.map(environment::get)
.filter(Objects::nonNull)
.findFirst()
.orElse(null);
}

private Stream<String> envVarNames(final OptionSpec spec) {
return Arrays.stream(spec.names())
.filter(name -> name.startsWith("--")) // Only long options are allowed
.map(this::fullEnvVarName);
}

private String fullEnvVarName(final String name) {
String suffix = nameToEnvVarSuffix(name);
String prefix;
if (Arrays.asList(WEB3J_CLI_SPECIFIC_VARIABLES).contains(suffix)) {
prefix = WEB3J_CLI_VAR_PREFIX;
} else if (Arrays.asList(OPENAPI_SPECIFIC_VARIABLES).contains(suffix)) {
prefix = WEB3J_OPENAPI_VAR_PREFIX;
} else {
prefix = WEB3J_VAR_PREFIX;
}
return prefix + suffix;
}

private String nameToEnvVarSuffix(final String name) {
return name.substring("--".length()).replace('-', '_').toUpperCase(Locale.US);
}
}
Loading

0 comments on commit c8aac7d

Please sign in to comment.