diff --git a/.gitignore b/.gitignore index bff1c774..4955999c 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ docs/build .project .classpath bin +logs \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 71fac4ad..460161c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,36 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [1.6.0](https://github.com/web3j/web3j-cli/releases/tag/v1.6.0) (2024-05-27) + +### Bug Fixes + +* + +### Features + +* Updated web3j to latest version 4.12.0 [#111](https://github.com/hyperledger/web3j-cli/pull/111) + +### BREAKING CHANGES + +* Upgrade gradle to 8.7 [#111](https://github.com/hyperledger/web3j-cli/pull/111) + +# [1.5.3](https://github.com/web3j/web3j-cli/releases/tag/v1.5.3) (2024-03-28) + +### Bug Fixes + +* Removed JCDP (failing in windows 11) and updated with Jansi [#105](https://github.com/web3j/web3j-cli/pull/105) + +### Features + +* Updated web3j to latest version 4.11.2 [#106](https://github.com/web3j/web3j-cli/pull/106) +* Migrate to hyperledger repo structure [#102](https://github.com/web3j/web3j-cli/pull/102) +* Added support for creating ERC-721 project [#101](https://github.com/web3j/web3j-cli/pull/101) + +### BREAKING CHANGES + +* NIL + # [1.5.2](https://github.com/web3j/web3j-cli/releases/tag/v1.5.2) (2024-02-24) ### Bug Fixes diff --git a/build.gradle b/build.gradle index 4d27a7b4..b72964db 100644 --- a/build.gradle +++ b/build.gradle @@ -1,16 +1,16 @@ import java.text.SimpleDateFormat plugins { - id 'org.jetbrains.kotlin.jvm' version '1.6.21' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id "application" id "distribution" id "idea" id "jacoco" - 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 "com.github.johnrengelman.shadow" version "8.1.1" + id "com.diffplug.spotless" version "6.25.0" + id "de.undercouch.download" version "4.1.2" id "de.marcphilipp.nexus-publish" version "0.4.0" - id 'io.codearte.nexus-staging' version '0.21.1' + id 'io.codearte.nexus-staging' version '0.30.0' id "com.jfrog.bintray" version "1.8.4" } @@ -19,21 +19,20 @@ mainClassName = 'org.web3j.console.Web3j' applicationName = 'web3j' ext { - web3jVersion = '4.11.0' - picocli = '4.6.0' - slf4jVersion = '1.7.30' - junitVersion = '5.8.2' - mockitoVersion = '4.1.0' - gsonVersion = '2.8.6' - wireMockVersion = '2.25.1' - kotlinLoggin = '1.7.9' - dockerJavaVersion = '3.2.5' + web3jVersion = '4.12.0' + picocli = '4.7.6' + slf4jVersion = '2.0.13' + junitVersion = '5.9.3' + mockitoVersion = '5.12.0' + mockitoInline = '5.2.0' + gsonVersion = '2.11.0' + wireMockVersion = '3.6.0' + kotlinLoggin = '3.0.5' + dockerJavaVersion = '3.3.6' web3jEpirusVersion = '0.0.7' - jaxbVersion = '2.2.11' - activationVersion = '1.1.1' - log4jVersion = '2.15.0' - semverVersion = '0.9.0' - commonsLangVersion = '3.9' + log4jVersion = '2.23.1' + semverVersion = '0.10.2' + commonsLangVersion = '3.14.0' jansiVersion = '2.4.1' } @@ -75,11 +74,11 @@ test { } distZip { - archiveName "web3j-${project.version}.zip" + archiveFileName.set("web3j-${project.version}.zip") } distTar { - archiveName "web3j-${project.version}.tar" + archiveFileName.set("web3j-${project.version}.tar") } dependencies { @@ -93,10 +92,6 @@ dependencies { "io.epirus:epirus-web3j:$web3jEpirusVersion", "info.picocli:picocli:$picocli", files('libs/smartcheck.jar'), - "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", "org.apache.commons:commons-lang3:$commonsLangVersion", "com.github.zafarkhaja:java-semver:$semverVersion", @@ -110,8 +105,8 @@ dependencies { testImplementation "org.junit.jupiter:junit-jupiter:$junitVersion", "org.mockito:mockito-core:$mockitoVersion", - "org.mockito:mockito-inline:$mockitoVersion", - "com.github.tomakehurst:wiremock-jre8:$wireMockVersion" + "org.mockito:mockito-inline:$mockitoInline", + "org.wiremock:wiremock:$wireMockVersion" } @@ -136,9 +131,9 @@ def getTimestamp() { classes { dependsOn createProperties } task shadowBugWorkaround(type: Jar) { - archiveBaseName = 'nested-gradle-jar' + archiveBaseName.set('nested-gradle-jar') from files(file("${rootDir}/gradle/wrapper/gradle-wrapper.jar")) - destinationDir file('build/shadow-bug-workaround') + destinationDirectory.set(file('build/shadow-bug-workaround')) } shadowJar { diff --git a/gradle.properties b/gradle.properties index 47643479..ae55de7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=1.5.2 +version=1.6.0 group=org.web3j.console diff --git a/gradle/jacoco/build.gradle b/gradle/jacoco/build.gradle index fb9fb7d1..4ef78502 100644 --- a/gradle/jacoco/build.gradle +++ b/gradle/jacoco/build.gradle @@ -6,7 +6,9 @@ task jacocoRootTestReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { getAdditionalSourceDirs().from(subprojects.sourceSets.main.allSource.srcDirs) getClassDirectories().from(subprojects.sourceSets.main.output) getExecutionData().from(subprojects.jacocoTestReport.executionData) - reports { xml.enabled = true } + reports { + xml.required.set(true) + } doFirst { getExecutionData().from(executionData.findAll { it.exists() }) diff --git a/gradle/repositories/build.gradle b/gradle/repositories/build.gradle index 5a360a6e..e7581f69 100644 --- a/gradle/repositories/build.gradle +++ b/gradle/repositories/build.gradle @@ -4,5 +4,4 @@ repositories { jcenter() maven { url 'https://oss.sonatype.org/content/repositories/releases/' } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } - maven { url "https://artifacts.consensys.net/public/maven/maven/" } } diff --git a/gradle/spotless/build.gradle b/gradle/spotless/build.gradle index 9dd2d472..359ae01a 100644 --- a/gradle/spotless/build.gradle +++ b/gradle/spotless/build.gradle @@ -1,5 +1,5 @@ -apply plugin: 'com.diffplug.gradle.spotless' +apply plugin: 'com.diffplug.spotless' apply plugin: "de.undercouch.download" task downloadJavaLicense(type: Download) { @@ -26,7 +26,7 @@ spotless { exclude '**/build/install/**' } removeUnusedImports() - googleJavaFormat("1.7").aosp() + googleJavaFormat("1.17.0").aosp() importOrder 'java', '', 'org.web3j', '\\#' trimTrailingWhitespace() endWithNewline() @@ -39,7 +39,7 @@ spotless { exclude '**/.gradle/**' exclude '**/build/install/**' } - ktlint('0.31.0') + ktlint('0.49.1') trimTrailingWhitespace() endWithNewline() licenseHeaderFile "$rootDir/gradle/spotless/java.license" @@ -52,4 +52,20 @@ spotless { } } -spotlessCheck.dependsOn('downloadJavaLicense', 'downloadFormatterProperties') +tasks.named('spotlessJava') { + dependsOn downloadJavaLicense, downloadFormatterProperties + dependsOn tasks.named('compileJava'), tasks.named('compileTestJava'), tasks.named('processResources'), tasks.named('processTestResources'), tasks.named('startScripts'), tasks.named('startShadowScripts') + mustRunAfter tasks.named('spotlessGroovyGradle'), tasks.named('test'), tasks.named('jacocoTestReport') +} + +tasks.named('spotlessKotlin') { + dependsOn downloadJavaLicense, downloadFormatterProperties + dependsOn tasks.named('compileJava'), tasks.named('compileTestJava'), tasks.named('processResources'), tasks.named('processTestResources'), tasks.named('spotlessJava'), tasks.named('startScripts'), tasks.named('startShadowScripts') + mustRunAfter tasks.named('spotlessGroovyGradle'), tasks.named('test'), tasks.named('jacocoTestReport') +} + +tasks.named('spotlessCheck') { + dependsOn downloadJavaLicense, downloadFormatterProperties, tasks.named('spotlessJava'), tasks.named('spotlessKotlin'), tasks.named('spotlessGroovyGradle') + mustRunAfter tasks.named('jacocoTestReport'), tasks.named('test') +} + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 5c2d1cf0..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 06c09673..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Tue Nov 19 11:45:38 GMT 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip diff --git a/gradlew b/gradlew index 83f2acfd..1aa94a42 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,111 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,92 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a14..7101f8e4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,14 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -51,48 +55,36 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/org/web3j/console/project/Project.java b/src/main/java/org/web3j/console/project/Project.java index 3da31f98..42816de6 100644 --- a/src/main/java/org/web3j/console/project/Project.java +++ b/src/main/java/org/web3j/console/project/Project.java @@ -22,8 +22,12 @@ public interface Project { void createProject() - throws IOException, InterruptedException, NoSuchAlgorithmException, - NoSuchProviderException, InvalidAlgorithmParameterException, CipherException; + throws IOException, + InterruptedException, + NoSuchAlgorithmException, + NoSuchProviderException, + InvalidAlgorithmParameterException, + CipherException; ProjectWallet getProjectWallet(); } diff --git a/src/main/java/org/web3j/console/project/wallet/ProjectWallet.java b/src/main/java/org/web3j/console/project/wallet/ProjectWallet.java index 7d427cf8..ac4d025c 100644 --- a/src/main/java/org/web3j/console/project/wallet/ProjectWallet.java +++ b/src/main/java/org/web3j/console/project/wallet/ProjectWallet.java @@ -30,8 +30,11 @@ public class ProjectWallet { private final String walletAddress; public ProjectWallet(String walletPassword, String walletPath) - throws NoSuchAlgorithmException, NoSuchProviderException, - InvalidAlgorithmParameterException, CipherException, IOException { + throws NoSuchAlgorithmException, + NoSuchProviderException, + InvalidAlgorithmParameterException, + CipherException, + IOException { this.walletPassword = walletPassword; this.walletPath = walletPath; File walletFile = new File(walletPath); diff --git a/src/main/java/org/web3j/console/wrapper/subcommand/TruffleGenerateCommand.java b/src/main/java/org/web3j/console/wrapper/subcommand/TruffleGenerateCommand.java index b843aafb..e8acd9f3 100644 --- a/src/main/java/org/web3j/console/wrapper/subcommand/TruffleGenerateCommand.java +++ b/src/main/java/org/web3j/console/wrapper/subcommand/TruffleGenerateCommand.java @@ -79,7 +79,8 @@ public void run() { jsonFileLocation.getAbsolutePath(), destinationDirLocation.getAbsolutePath(), basePackageName, - useJavaNativeTypes) + useJavaNativeTypes, + true) .generate(); } catch (Exception e) { Console.exitError(e); diff --git a/src/main/kotlin/org/web3j/console/openapi/OpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/OpenApiCommand.kt index 173ca943..9137588e 100644 --- a/src/main/kotlin/org/web3j/console/openapi/OpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/OpenApiCommand.kt @@ -12,12 +12,12 @@ */ package org.web3j.console.openapi +import org.web3j.console.SubCommand +import org.web3j.console.Web3jVersionProvider import org.web3j.console.openapi.subcommands.GenerateOpenApiCommand import org.web3j.console.openapi.subcommands.ImportOpenApiCommand import org.web3j.console.openapi.subcommands.JarOpenApiCommand import org.web3j.console.openapi.subcommands.NewOpenApiCommand -import org.web3j.console.SubCommand -import org.web3j.console.Web3jVersionProvider import picocli.CommandLine import picocli.CommandLine.Command @@ -29,7 +29,8 @@ import picocli.CommandLine.Command CommandLine.HelpCommand::class, ImportOpenApiCommand::class, JarOpenApiCommand::class, - NewOpenApiCommand::class], + NewOpenApiCommand::class, + ], showDefaultValues = true, abbreviateSynopsis = true, mixinStandardHelpOptions = true, @@ -38,6 +39,6 @@ import picocli.CommandLine.Command descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", - footer = ["Web3j CLI is licensed under the Apache License 2.0"] + footer = ["Web3j CLI is licensed under the Apache License 2.0"], ) class OpenApiCommand : SubCommand() diff --git a/src/main/kotlin/org/web3j/console/openapi/options/OpenApiProjectOptions.kt b/src/main/kotlin/org/web3j/console/openapi/options/OpenApiProjectOptions.kt index bb8cd9b8..cfb49e38 100644 --- a/src/main/kotlin/org/web3j/console/openapi/options/OpenApiProjectOptions.kt +++ b/src/main/kotlin/org/web3j/console/openapi/options/OpenApiProjectOptions.kt @@ -20,14 +20,14 @@ class OpenApiProjectOptions : BaseProjectOptions() { @Option( names = ["--context-path"], - description = ["Set the API context path (Default: project name)."] + description = ["Set the API context path (Default: project name)."], ) var contextPath: String? = null @Option( names = ["--address-length"], description = ["Specify the address length."], - showDefaultValue = CommandLine.Help.Visibility.ALWAYS + showDefaultValue = CommandLine.Help.Visibility.ALWAYS, ) var addressLength = 20 } diff --git a/src/main/kotlin/org/web3j/console/openapi/options/PreCompiledContractOptions.kt b/src/main/kotlin/org/web3j/console/openapi/options/PreCompiledContractOptions.kt index d251307f..b2ddb29b 100644 --- a/src/main/kotlin/org/web3j/console/openapi/options/PreCompiledContractOptions.kt +++ b/src/main/kotlin/org/web3j/console/openapi/options/PreCompiledContractOptions.kt @@ -19,14 +19,14 @@ class PreCompiledContractOptions { @Option( names = ["-a", "--abi"], description = ["Input ABI files and folders."], - arity = "1..*" + arity = "1..*", ) var abis: MutableList = mutableListOf() @Option( names = ["-b", "--bin"], description = ["Input BIN files and folders."], - arity = "1..*" + arity = "1..*", ) var bins: MutableList = mutableListOf() } diff --git a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectCreationUtils.kt b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectCreationUtils.kt index 5f2b7e37..a42c7c6d 100644 --- a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectCreationUtils.kt +++ b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectCreationUtils.kt @@ -32,7 +32,7 @@ internal object OpenApiProjectCreationUtils { return OpenApiProjectStructure( outputDir, openApiTemplateProvider.packageName, - openApiTemplateProvider.projectName + openApiTemplateProvider.projectName, ).apply { ProjectCreationUtils.generateTopLevelDirectories(this) openApiTemplateProvider.generateFiles(this) diff --git a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectGradleCommands.kt b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectGradleCommands.kt index 0b06c1b0..cd1a2aa8 100644 --- a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectGradleCommands.kt +++ b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectGradleCommands.kt @@ -24,11 +24,15 @@ internal object OpenApiProjectGradleCommands { if (!isWindows()) { setExecutable(pathToDirectory, "gradlew") executeBuild( - File(pathToDirectory!!), arrayOf("bash", "-c", "./gradlew generateWeb3jOpenApi")) + File(pathToDirectory!!), + arrayOf("bash", "-c", "./gradlew generateWeb3jOpenApi"), + ) } else { setExecutable(pathToDirectory, "gradlew.bat") executeBuild( - File(pathToDirectory!!), arrayOf("cmd", "/c", ".\\gradlew.bat generateWeb3jOpenApi")) + File(pathToDirectory!!), + arrayOf("cmd", "/c", ".\\gradlew.bat generateWeb3jOpenApi"), + ) } } @@ -37,11 +41,15 @@ internal object OpenApiProjectGradleCommands { if (!isWindows()) { setExecutable(pathToDirectory, "gradlew") executeBuild( - File(pathToDirectory!!), arrayOf("bash", "-c", "./gradlew generateWeb3jSwaggerUI")) + File(pathToDirectory!!), + arrayOf("bash", "-c", "./gradlew generateWeb3jSwaggerUI"), + ) } else { setExecutable(pathToDirectory, "gradlew.bat") executeBuild( - File(pathToDirectory!!), arrayOf("cmd", "/c", ".\\gradlew.bat generateWeb3jSwaggerUI")) + File(pathToDirectory!!), + arrayOf("cmd", "/c", ".\\gradlew.bat generateWeb3jSwaggerUI"), + ) } } @@ -50,11 +58,15 @@ internal object OpenApiProjectGradleCommands { if (!isWindows()) { setExecutable(pathToDirectory, "gradlew") executeBuild( - File(pathToDirectory!!), arrayOf("bash", "-c", "./gradlew clean")) + File(pathToDirectory!!), + arrayOf("bash", "-c", "./gradlew clean"), + ) } else { setExecutable(pathToDirectory, "gradlew.bat") executeBuild( - File(pathToDirectory!!), arrayOf("cmd", "/c", ".\\gradlew.bat clean")) + File(pathToDirectory!!), + arrayOf("cmd", "/c", ".\\gradlew.bat clean"), + ) } } @@ -63,11 +75,15 @@ internal object OpenApiProjectGradleCommands { if (!isWindows()) { setExecutable(pathToDirectory, "gradlew") executeBuild( - File(pathToDirectory!!), arrayOf("bash", "-c", "./gradlew shadowJar")) + File(pathToDirectory!!), + arrayOf("bash", "-c", "./gradlew shadowJar"), + ) } else { setExecutable(pathToDirectory, "gradlew.bat") executeBuild( - File(pathToDirectory!!), arrayOf("cmd", "/c", ".\\gradlew.bat shadowJar")) + File(pathToDirectory!!), + arrayOf("cmd", "/c", ".\\gradlew.bat shadowJar"), + ) } } } diff --git a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectStructure.kt b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectStructure.kt index 9a1e10e7..0c2ab8cb 100644 --- a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectStructure.kt +++ b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiProjectStructure.kt @@ -17,10 +17,10 @@ import org.web3j.console.project.ProjectStructure class OpenApiProjectStructure( rootDir: String, packageName: String, - projectName: String + projectName: String, ) : ProjectStructure( rootDir, packageName, projectName, - "kotlin" + "kotlin", ) diff --git a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiTemplateProvider.kt b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiTemplateProvider.kt index 769ed0c7..9581a1dd 100644 --- a/src/main/kotlin/org/web3j/console/openapi/project/OpenApiTemplateProvider.kt +++ b/src/main/kotlin/org/web3j/console/openapi/project/OpenApiTemplateProvider.kt @@ -32,7 +32,7 @@ class OpenApiTemplateProvider @JvmOverloads constructor( private val gradlewWrapperSettings: String = "project/gradlew-wrapper.properties.template", private val gradlewBatScript: String = "project/gradlew.bat.template", private val gradlewScript: String = "project/gradlew.template", - private val gradlewJar: String = "gradle-wrapper.jar" + private val gradlewJar: String = "gradle-wrapper.jar", ) : TemplateProvider { private fun loadGradleBuild(): String { return TemplateReader.readFile(gradleBuild) @@ -66,32 +66,55 @@ class OpenApiTemplateProvider @JvmOverloads constructor( override fun generateFiles(projectStructure: ProjectStructure) { ProjectWriter.writeResourceFile( - loadGradleBuild(), "build.gradle", projectStructure.projectRoot) + loadGradleBuild(), + "build.gradle", + projectStructure.projectRoot, + ) ProjectWriter.writeResourceFile( - loadGradleSettings(), "settings.gradle", projectStructure.projectRoot) - if (solidityContract.isNotEmpty()) ProjectWriter.writeResourceFile( - loadSolidityContract(), "HelloWorld.sol", projectStructure.solidityPath) + loadGradleSettings(), + "settings.gradle", + projectStructure.projectRoot, + ) + if (solidityContract.isNotEmpty()) { + ProjectWriter.writeResourceFile( + loadSolidityContract(), + "HelloWorld.sol", + projectStructure.solidityPath, + ) + } if (pathToSolidityFolder.isNotEmpty()) { ProjectWriter.importSolidityProject( - File(pathToSolidityFolder), projectStructure.solidityPath) + File(pathToSolidityFolder), + projectStructure.solidityPath, + ) } ProjectWriter.writeResourceFile( TemplateReader.readFile("project/Dockerfile.template"), "Dockerfile", - projectStructure.projectRoot) + projectStructure.projectRoot, + ) ProjectWriter.writeResourceFile( loadGradlewWrapperSettings(), "gradle-wrapper.properties", - projectStructure.wrapperPath) + projectStructure.wrapperPath, + ) ProjectWriter.writeResourceFile( - loadGradlewScript(), "gradlew", projectStructure.projectRoot) + loadGradlewScript(), + "gradlew", + projectStructure.projectRoot, + ) ProjectWriter.writeResourceFile( - loadGradlewBatScript(), "gradlew.bat", projectStructure.projectRoot) + loadGradlewBatScript(), + "gradlew.bat", + projectStructure.projectRoot, + ) ProjectWriter.copyResourceFile( gradlewJar, - projectStructure.wrapperPath + "gradle-wrapper.jar") + projectStructure.wrapperPath + "gradle-wrapper.jar", + ) ProjectWriter.copyResourceFile( readme, - projectStructure.projectRoot + File.separator + "README.md") + projectStructure.projectRoot + File.separator + "README.md", + ) } } diff --git a/src/main/kotlin/org/web3j/console/openapi/project/erc777/CopyUtils.kt b/src/main/kotlin/org/web3j/console/openapi/project/erc777/CopyUtils.kt index 6abeb3e3..f7fc0ba4 100644 --- a/src/main/kotlin/org/web3j/console/openapi/project/erc777/CopyUtils.kt +++ b/src/main/kotlin/org/web3j/console/openapi/project/erc777/CopyUtils.kt @@ -30,7 +30,7 @@ internal object CopyUtils { ProjectWriter.writeResourceFile( TemplateReader.readFile(inputPath), File(inputPath).name, - outputPath + outputPath, ) } } diff --git a/src/main/kotlin/org/web3j/console/openapi/subcommands/AbstractOpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/subcommands/AbstractOpenApiCommand.kt index 74293935..df6cb02e 100644 --- a/src/main/kotlin/org/web3j/console/openapi/subcommands/AbstractOpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/subcommands/AbstractOpenApiCommand.kt @@ -12,16 +12,15 @@ */ package org.web3j.console.openapi.subcommands +import org.apache.commons.lang3.StringUtils import org.web3j.console.openapi.options.OpenApiProjectOptions import org.web3j.console.openapi.utils.PrettyPrinter import org.web3j.console.openapi.utils.SimpleFileLogger - -import org.apache.commons.lang.StringUtils import org.web3j.console.project.InteractiveOptions import org.web3j.console.project.utils.InputVerifier -import picocli.CommandLine.Model.CommandSpec import picocli.CommandLine.ExitCode import picocli.CommandLine.Mixin +import picocli.CommandLine.Model.CommandSpec import picocli.CommandLine.Spec import java.io.File import java.nio.file.Paths @@ -51,12 +50,13 @@ abstract class AbstractOpenApiCommand : Callable { } override fun call(): Int { - if (inputIsNotValid(projectOptions.packageName, projectOptions.projectName)) + if (inputIsNotValid(projectOptions.packageName, projectOptions.projectName)) { exitProcess(1) + } val projectFolder = Paths.get( projectOptions.outputDir, - projectOptions.projectName + projectOptions.projectName, ).toFile().apply { if (exists() || File("${projectOptions.projectName}$JAR_SUFFIX").exists()) { if (projectOptions.overwrite || interactiveOptions.overrideExistingProject()) { @@ -82,8 +82,10 @@ abstract class AbstractOpenApiCommand : Callable { abstract fun generate(projectFolder: File) private fun inputIsNotValid(vararg requiredArgs: String): Boolean { - return !(inputVerifier.requiredArgsAreNotEmpty(*requiredArgs) && - inputVerifier.classNameIsValid(projectOptions.projectName) && - inputVerifier.packageNameIsValid(projectOptions.packageName)) + return !( + inputVerifier.requiredArgsAreNotEmpty(*requiredArgs) && + inputVerifier.classNameIsValid(projectOptions.projectName) && + inputVerifier.packageNameIsValid(projectOptions.packageName) + ) } } diff --git a/src/main/kotlin/org/web3j/console/openapi/subcommands/GenerateOpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/subcommands/GenerateOpenApiCommand.kt index c0ac39ec..06c16a2b 100644 --- a/src/main/kotlin/org/web3j/console/openapi/subcommands/GenerateOpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/subcommands/GenerateOpenApiCommand.kt @@ -12,47 +12,47 @@ */ package org.web3j.console.openapi.subcommands +import org.apache.commons.io.FileUtils +import org.web3j.console.Web3jVersionProvider import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.buildProject import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.createProjectStructure import org.web3j.console.openapi.project.OpenApiTemplateProvider import org.web3j.console.openapi.utils.PrettyPrinter - -import org.apache.commons.io.FileUtils -import org.web3j.console.Web3jVersionProvider import org.web3j.console.project.utils.ProgressCounter import org.web3j.console.project.utils.ProjectUtils.deleteFolder import org.web3j.console.project.utils.ProjectUtils.exitIfNoContractFound -import picocli.CommandLine.Option import picocli.CommandLine.Command import picocli.CommandLine.Help.Visibility.ALWAYS +import picocli.CommandLine.Option import java.io.File import java.nio.file.Files import java.nio.file.Paths @Command( - name = "generate", - description = ["Generate REST endpoints from existing Solidity contracts."], - showDefaultValues = true, - abbreviateSynopsis = true, - mixinStandardHelpOptions = true, - versionProvider = Web3jVersionProvider::class, - synopsisHeading = "%n", - descriptionHeading = "%nDescription:%n%n", - optionListHeading = "%nOptions:%n", - footerHeading = "%n", - footer = ["Web3j CLI is licensed under the Apache License 2.0"]) + name = "generate", + description = ["Generate REST endpoints from existing Solidity contracts."], + showDefaultValues = true, + abbreviateSynopsis = true, + mixinStandardHelpOptions = true, + versionProvider = Web3jVersionProvider::class, + synopsisHeading = "%n", + descriptionHeading = "%nDescription:%n%n", + optionListHeading = "%nOptions:%n", + footerHeading = "%n", + footer = ["Web3j CLI is licensed under the Apache License 2.0"], +) class GenerateOpenApiCommand : AbstractOpenApiCommand() { @Option( names = ["-s", "--solidity-path"], - description = ["Path to Solidity file/folder"] + description = ["Path to Solidity file/folder"], ) var solidityImportPath: String? = null @Option( names = ["--with-implementations"], description = ["Generate the interfaces implementations."], - showDefaultValue = ALWAYS + showDefaultValue = ALWAYS, ) var withImplementations: Boolean = false @@ -77,17 +77,22 @@ class GenerateOpenApiCommand : AbstractOpenApiCommand() { projectName = projectOptions.projectName, contextPath = contextPath, addressLength = (projectOptions.addressLength * 8).toString(), - generateServer = withImplementations.toString() - ), outputDir = tempFolder.toAbsolutePath().toString()) + generateServer = withImplementations.toString(), + ), + outputDir = tempFolder.toAbsolutePath().toString(), + ) buildProject( projectStructure.projectRoot, withOpenApi = true, withSwaggerUi = false, - withShadowJar = false) + withShadowJar = false, + ) - FileUtils.copyDirectory(Paths.get(tempFolder.toString(), projectOptions.projectName, "build", "generated", "sources", "web3j", "main").toFile(), - Paths.get(projectOptions.outputDir, projectOptions.projectName).toFile()) + FileUtils.copyDirectory( + Paths.get(tempFolder.toString(), projectOptions.projectName, "build", "generated", "sources", "web3j", "main").toFile(), + Paths.get(projectOptions.outputDir, projectOptions.projectName).toFile(), + ) deleteFolder(tempFolder) progressCounter.setLoading(false) diff --git a/src/main/kotlin/org/web3j/console/openapi/subcommands/ImportOpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/subcommands/ImportOpenApiCommand.kt index 79dca361..f78172af 100644 --- a/src/main/kotlin/org/web3j/console/openapi/subcommands/ImportOpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/subcommands/ImportOpenApiCommand.kt @@ -12,14 +12,13 @@ */ package org.web3j.console.openapi.subcommands +import org.web3j.console.Web3jVersionProvider import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.buildProject import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.createProjectStructure import org.web3j.console.openapi.project.OpenApiTemplateProvider import org.web3j.console.openapi.utils.PrettyPrinter -import org.web3j.console.Web3jVersionProvider import org.web3j.console.project.utils.ProgressCounter import org.web3j.console.project.utils.ProjectUtils.exitIfNoContractFound - import picocli.CommandLine.Command import picocli.CommandLine.Option import java.io.File @@ -35,13 +34,13 @@ import java.io.File descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", - footer = ["Web3j CLI is licensed under the Apache License 2.0"] + footer = ["Web3j CLI is licensed under the Apache License 2.0"], ) class ImportOpenApiCommand : AbstractOpenApiCommand() { @Option( names = ["-s", "--solidity-path"], - description = ["Path to Solidity file/folder"] + description = ["Path to Solidity file/folder"], ) var solidityImportPath: String? = null @@ -62,8 +61,10 @@ class ImportOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectOptions.outputDir) + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectOptions.outputDir, + ) buildProject(projectStructure.projectRoot, withSwaggerUi = false) diff --git a/src/main/kotlin/org/web3j/console/openapi/subcommands/JarOpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/subcommands/JarOpenApiCommand.kt index 5fe0dc1c..25be680f 100644 --- a/src/main/kotlin/org/web3j/console/openapi/subcommands/JarOpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/subcommands/JarOpenApiCommand.kt @@ -12,15 +12,14 @@ */ package org.web3j.console.openapi.subcommands +import org.web3j.console.Web3jVersionProvider import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.buildProject import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.createProjectStructure import org.web3j.console.openapi.project.OpenApiTemplateProvider import org.web3j.console.openapi.utils.PrettyPrinter -import org.web3j.console.Web3jVersionProvider import org.web3j.console.project.utils.ProgressCounter import org.web3j.console.project.utils.ProjectUtils.exitIfNoContractFound import org.web3j.console.project.utils.ProjectUtils.findSolidityContracts - import picocli.CommandLine.Command import picocli.CommandLine.Option import java.io.File @@ -40,13 +39,13 @@ import java.nio.file.StandardCopyOption descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", - footer = ["Web3j CLI is licensed under the Apache License 2.0"] + footer = ["Web3j CLI is licensed under the Apache License 2.0"], ) class JarOpenApiCommand : AbstractOpenApiCommand() { @Option( names = ["-s", "--solidity-path"], - description = ["Path to Solidity file/folder"] + description = ["Path to Solidity file/folder"], ) var solidityImportPath: String? = null @@ -77,19 +76,22 @@ class JarOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectDirectoryPath.toString()) + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectDirectoryPath.toString(), + ) } buildProject( Paths.get(projectDirectoryPath.toString(), projectOptions.projectName).toString(), withOpenApi = false, withSwaggerUi = false, - withShadowJar = true) + withShadowJar = true, + ) Files.copy( getJarFile(projectDirectoryPath), File(projectOptions.outputDir, "${projectOptions.projectName}$JAR_SUFFIX").toPath(), - StandardCopyOption.REPLACE_EXISTING + StandardCopyOption.REPLACE_EXISTING, ) progressCounter.setLoading(false) @@ -103,11 +105,12 @@ class JarOpenApiCommand : AbstractOpenApiCommand() { * @return Path to the Jar */ private fun getJarFile(outputProjectFolder: Path): Path { - return File(outputProjectFolder + return File( + outputProjectFolder .resolve(projectOptions.projectName) .resolve("build") .resolve("libs") - .toString() + .toString(), ).listFiles()!!.first { it.name.endsWith("-all.jar") }.toPath() } diff --git a/src/main/kotlin/org/web3j/console/openapi/subcommands/NewOpenApiCommand.kt b/src/main/kotlin/org/web3j/console/openapi/subcommands/NewOpenApiCommand.kt index b0bad5c2..3f0c9bf7 100644 --- a/src/main/kotlin/org/web3j/console/openapi/subcommands/NewOpenApiCommand.kt +++ b/src/main/kotlin/org/web3j/console/openapi/subcommands/NewOpenApiCommand.kt @@ -12,13 +12,12 @@ */ package org.web3j.console.openapi.subcommands +import org.web3j.console.Web3jVersionProvider import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.buildProject import org.web3j.console.openapi.project.OpenApiProjectCreationUtils.createProjectStructure import org.web3j.console.openapi.project.OpenApiTemplateProvider import org.web3j.console.openapi.project.erc777.CopyUtils import org.web3j.console.openapi.utils.PrettyPrinter - -import org.web3j.console.Web3jVersionProvider import org.web3j.console.project.TemplateType import org.web3j.console.project.utils.ProgressCounter import picocli.CommandLine.Command @@ -36,7 +35,7 @@ import java.io.File descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", - footer = ["Web3j CLI is licensed under the Apache License 2.0"] + footer = ["Web3j CLI is licensed under the Apache License 2.0"], ) class NewOpenApiCommand : AbstractOpenApiCommand() { @@ -57,8 +56,9 @@ class NewOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectOptions.outputDir + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectOptions.outputDir, ) buildProject(projectStructure.projectRoot, withSwaggerUi = false) } @@ -72,12 +72,14 @@ class NewOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectOptions.outputDir + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectOptions.outputDir, ) CopyUtils.copyFromResources( "contracts/ERC777Token.sol", - projectStructure.solidityPath) + projectStructure.solidityPath, + ) buildProject(projectStructure.projectRoot, withSwaggerUi = false) } @@ -90,12 +92,14 @@ class NewOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectOptions.outputDir + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectOptions.outputDir, ) CopyUtils.copyFromResources( "contracts/ERC20Token.sol", - projectStructure.solidityPath) + projectStructure.solidityPath, + ) buildProject(projectStructure.projectRoot, withSwaggerUi = false) } @@ -108,12 +112,14 @@ class NewOpenApiCommand : AbstractOpenApiCommand() { packageName = projectOptions.packageName, projectName = projectOptions.projectName, contextPath = contextPath, - addressLength = (projectOptions.addressLength * 8).toString() - ), outputDir = projectOptions.outputDir + addressLength = (projectOptions.addressLength * 8).toString(), + ), + outputDir = projectOptions.outputDir, ) CopyUtils.copyFromResources( "contracts/ERC721Token.sol", - projectStructure.solidityPath) + projectStructure.solidityPath, + ) buildProject(projectStructure.projectRoot, withSwaggerUi = false) } } diff --git a/src/main/kotlin/org/web3j/console/openapi/utils/PrettyPrinter.kt b/src/main/kotlin/org/web3j/console/openapi/utils/PrettyPrinter.kt index 27f98b46..fb55a3ad 100644 --- a/src/main/kotlin/org/web3j/console/openapi/utils/PrettyPrinter.kt +++ b/src/main/kotlin/org/web3j/console/openapi/utils/PrettyPrinter.kt @@ -12,9 +12,8 @@ */ package org.web3j.console.openapi.utils -import org.web3j.console.project.utils.InstructionsPrinter - import org.fusesource.jansi.Ansi +import org.web3j.console.project.utils.InstructionsPrinter object PrettyPrinter { diff --git a/src/main/resources/gradle-wrapper.jar b/src/main/resources/gradle-wrapper.jar index 0d4a9516..e6441136 100644 Binary files a/src/main/resources/gradle-wrapper.jar and b/src/main/resources/gradle-wrapper.jar differ diff --git a/src/main/resources/project/build.gradle.template b/src/main/resources/project/build.gradle.template index 94a638f3..8c787d82 100644 --- a/src/main/resources/project/build.gradle.template +++ b/src/main/resources/project/build.gradle.template @@ -1,9 +1,9 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.10' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id 'application' - id "com.github.johnrengelman.shadow" version "5.2.0" - id 'org.web3j' version '4.11.0' + id "com.github.johnrengelman.shadow" version "8.1.1" + id 'org.web3j' version '4.12.0' } @@ -30,9 +30,9 @@ node { } ext { - web3jVersion = '4.11.0' - logbackVersion = '1.4.14' - klaxonVersion = '5.5' + web3jVersion = '4.12.0' + logbackVersion = '1.5.6' + klaxonVersion = '5.6' besuPluginVersion = '24.1.1' besuInternalVersion = '24.1.1' besuInternalCryptoVersion = '23.1.3' @@ -47,8 +47,8 @@ dependencies { implementation "org.web3j:web3j-unit:$web3jVersion" implementation "org.web3j:web3j-evm:$web3jVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' implementation "org.hyperledger.besu:plugin-api:$besuPluginVersion" implementation "org.hyperledger.besu.internal:besu:$besuInternalVersion" diff --git a/src/main/resources/project/build.gradleGenerateOpenApi.template b/src/main/resources/project/build.gradleGenerateOpenApi.template index 2bd693a3..479f7739 100644 --- a/src/main/resources/project/build.gradleGenerateOpenApi.template +++ b/src/main/resources/project/build.gradleGenerateOpenApi.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/build.gradleImport.template b/src/main/resources/project/build.gradleImport.template index 8298e747..fbfbed36 100644 --- a/src/main/resources/project/build.gradleImport.template +++ b/src/main/resources/project/build.gradleImport.template @@ -1,9 +1,9 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.10' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id 'application' - id "com.github.johnrengelman.shadow" version "5.2.0" - id 'org.web3j' version '4.11.0' + id "com.github.johnrengelman.shadow" version "8.1.1" + id 'org.web3j' version '4.12.0' } @@ -33,9 +33,9 @@ ext { besuPluginVersion = '24.1.1' besuInternalVersion = '24.1.1' besuInternalCryptoVersion = '23.1.3' - web3jVersion = '4.11.0' - logbackVersion = '1.4.14' - klaxonVersion = '5.5' + web3jVersion = '4.12.0' + logbackVersion = '1.5.6' + klaxonVersion = '5.6' besuCryptoDepVersion = '0.8.3' } @@ -47,8 +47,8 @@ dependencies { implementation "org.web3j:web3j-unit:$web3jVersion" implementation "org.web3j:web3j-evm:$web3jVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' implementation "org.hyperledger.besu:plugin-api:$besuPluginVersion" implementation "org.hyperledger.besu.internal:besu:$besuInternalVersion" diff --git a/src/main/resources/project/build.gradleImportOpenApi.template b/src/main/resources/project/build.gradleImportOpenApi.template index 57c06166..5db600a2 100644 --- a/src/main/resources/project/build.gradleImportOpenApi.template +++ b/src/main/resources/project/build.gradleImportOpenApi.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/build.gradleJarOpenApi.template b/src/main/resources/project/build.gradleJarOpenApi.template index 8e957c5d..8496bd1b 100644 --- a/src/main/resources/project/build.gradleJarOpenApi.template +++ b/src/main/resources/project/build.gradleJarOpenApi.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" id "com.github.johnrengelman.shadow" version "5.2.0" } diff --git a/src/main/resources/project/build.gradleOpenApi.template b/src/main/resources/project/build.gradleOpenApi.template index 381df5a7..2f51154a 100644 --- a/src/main/resources/project/build.gradleOpenApi.template +++ b/src/main/resources/project/build.gradleOpenApi.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/erc20/build.gradleErc20.template b/src/main/resources/project/erc20/build.gradleErc20.template index 6f6f40f1..8c87e5f2 100644 --- a/src/main/resources/project/erc20/build.gradleErc20.template +++ b/src/main/resources/project/erc20/build.gradleErc20.template @@ -1,9 +1,9 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.10' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id 'application' - id "com.github.johnrengelman.shadow" version "5.2.0" - id 'org.web3j' version '4.11.0' + id "com.github.johnrengelman.shadow" version "8.1.1" + id 'org.web3j' version '4.12.0' } group '' @@ -29,9 +29,9 @@ node { } ext { - web3jVersion = '4.11.0' - logbackVersion = '1.4.14' - klaxonVersion = '5.5' + web3jVersion = '4.12.0' + logbackVersion = '1.5.6' + klaxonVersion = '5.6' besuPluginVersion = '24.1.1' besuInternalVersion = '24.1.1' besuInternalCryptoVersion = '23.1.3' @@ -46,8 +46,8 @@ dependencies { implementation "org.web3j:web3j-unit:$web3jVersion" implementation "org.web3j:web3j-evm:$web3jVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' implementation "org.hyperledger.besu:plugin-api:$besuPluginVersion" implementation "org.hyperledger.besu.internal:besu:$besuInternalVersion" diff --git a/src/main/resources/project/erc20/build.gradleOpenApiErc20.template b/src/main/resources/project/erc20/build.gradleOpenApiErc20.template index eeac2bd8..c35cf138 100644 --- a/src/main/resources/project/erc20/build.gradleOpenApiErc20.template +++ b/src/main/resources/project/erc20/build.gradleOpenApiErc20.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/erc721/build.gradleErc721.template b/src/main/resources/project/erc721/build.gradleErc721.template index b1010ea2..2727d227 100644 --- a/src/main/resources/project/erc721/build.gradleErc721.template +++ b/src/main/resources/project/erc721/build.gradleErc721.template @@ -1,9 +1,9 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.10' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id 'application' - id "com.github.johnrengelman.shadow" version "5.2.0" - id 'org.web3j' version '4.11.0' + id "com.github.johnrengelman.shadow" version "8.1.1" + id 'org.web3j' version '4.12.0' } group '' @@ -29,9 +29,9 @@ node { } ext { - web3jVersion = '4.11.0' - logbackVersion = '1.4.14' - klaxonVersion = '5.5' + web3jVersion = '4.12.0' + logbackVersion = '1.5.6' + klaxonVersion = '5.6' besuPluginVersion = '24.1.1' besuInternalVersion = '24.1.1' besuInternalCryptoVersion = '23.1.3' @@ -46,8 +46,8 @@ dependencies { implementation "org.web3j:web3j-unit:$web3jVersion" implementation "org.web3j:web3j-evm:$web3jVersion" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' implementation "org.hyperledger.besu:plugin-api:$besuPluginVersion" implementation "org.hyperledger.besu.internal:besu:$besuInternalVersion" diff --git a/src/main/resources/project/erc721/build.gradleOpenApiErc721.template b/src/main/resources/project/erc721/build.gradleOpenApiErc721.template index 5bf78e63..b582b200 100644 --- a/src/main/resources/project/erc721/build.gradleOpenApiErc721.template +++ b/src/main/resources/project/erc721/build.gradleOpenApiErc721.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/erc777/build.gradleErc777.template b/src/main/resources/project/erc777/build.gradleErc777.template index 50429cb3..3e83ef10 100644 --- a/src/main/resources/project/erc777/build.gradleErc777.template +++ b/src/main/resources/project/erc777/build.gradleErc777.template @@ -1,9 +1,9 @@ plugins { id 'java' - id 'org.jetbrains.kotlin.jvm' version '1.8.10' + id 'org.jetbrains.kotlin.jvm' version '1.9.24' id 'application' - id "com.github.johnrengelman.shadow" version "5.2.0" - id 'org.web3j' version '4.11.0' + id "com.github.johnrengelman.shadow" version "8.1.1" + id 'org.web3j' version '4.12.0' } group '' @@ -30,9 +30,9 @@ node { } ext { - web3jVersion = '4.11.0' - logbackVersion = '1.4.14' - klaxonVersion = '5.5' + web3jVersion = '4.12.0' + logbackVersion = '1.5.6' + klaxonVersion = '5.6' } dependencies { diff --git a/src/main/resources/project/erc777/build.gradleOpenApiErc777.template b/src/main/resources/project/erc777/build.gradleOpenApiErc777.template index 4da3b422..fe5be486 100644 --- a/src/main/resources/project/erc777/build.gradleOpenApiErc777.template +++ b/src/main/resources/project/erc777/build.gradleOpenApiErc777.template @@ -1,5 +1,5 @@ plugins { - id "org.web3j.openapi" version "4.11.0" + id "org.web3j.openapi" version "4.11.2" } group '' diff --git a/src/main/resources/project/gradlew-wrapper.properties.template b/src/main/resources/project/gradlew-wrapper.properties.template index 070cb702..b82aa23a 100644 --- a/src/main/resources/project/gradlew-wrapper.properties.template +++ b/src/main/resources/project/gradlew-wrapper.properties.template @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/resources/project/gradlew.bat.template b/src/main/resources/project/gradlew.bat.template index f9553162..25da30db 100644 --- a/src/main/resources/project/gradlew.bat.template +++ b/src/main/resources/project/gradlew.bat.template @@ -1,4 +1,20 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -9,25 +25,29 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,48 +55,36 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/resources/project/gradlew.template b/src/main/resources/project/gradlew.template index f48d5d06..1aa94a42 100644 --- a/src/main/resources/project/gradlew.template +++ b/src/main/resources/project/gradlew.template @@ -1,170 +1,249 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# 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 +# +# https://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. +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=$((i+1)) + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" fi +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + exec "$JAVACMD" "$@" diff --git a/src/main/resources/project/settings.gradle.template b/src/main/resources/project/settings.gradle.template index 9c9932e0..c5f002fa 100644 --- a/src/main/resources/project/settings.gradle.template +++ b/src/main/resources/project/settings.gradle.template @@ -3,7 +3,6 @@ pluginManagement { mavenLocal() gradlePluginPortal() maven { url "https://hyperledger.jfrog.io/hyperledger/besu-maven" } - maven { url "https://artifacts.consensys.net/public/maven/maven/" } maven { url "https://splunk.jfrog.io/splunk/ext-releases-local" } } } diff --git a/src/test/java/org/web3j/console/ProjectTest.java b/src/test/java/org/web3j/console/ProjectTest.java index 0631da90..a133dabf 100644 --- a/src/test/java/org/web3j/console/ProjectTest.java +++ b/src/test/java/org/web3j/console/ProjectTest.java @@ -32,8 +32,11 @@ public class ProjectTest extends ClassExecutor { @BeforeEach public void createWeb3jProject() - throws IOException, NoSuchAlgorithmException, NoSuchProviderException, - InvalidAlgorithmParameterException, CipherException { + throws IOException, + NoSuchAlgorithmException, + NoSuchProviderException, + InvalidAlgorithmParameterException, + CipherException { ConfigManager.setDevelopment(); final File testWalletDirectory = new File(workingDirectory.getPath() + File.separator + "keystore"); diff --git a/src/test/kotlin/org/web3j/console/openapi/OpenApiProjectTest.kt b/src/test/kotlin/org/web3j/console/openapi/OpenApiProjectTest.kt index d736fd37..f89b01ae 100644 --- a/src/test/kotlin/org/web3j/console/openapi/OpenApiProjectTest.kt +++ b/src/test/kotlin/org/web3j/console/openapi/OpenApiProjectTest.kt @@ -12,19 +12,19 @@ */ package org.web3j.console.openapi +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test import org.web3j.console.openapi.subcommands.GenerateOpenApiCommand import org.web3j.console.openapi.subcommands.ImportOpenApiCommand import org.web3j.console.openapi.subcommands.JarOpenApiCommand import org.web3j.console.openapi.subcommands.NewOpenApiCommand -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Test import org.web3j.console.project.utils.Folders import picocli.CommandLine import java.io.File import java.io.PrintWriter import java.nio.file.Paths -import org.junit.jupiter.api.Disabled @Disabled class OpenApiProjectTest {