You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2021/08/01 16:43:55 UTC

[incubator-tuweni] branch main updated: Add version printout

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git


The following commit(s) were added to refs/heads/main by this push:
     new df6e0f9  Add version printout
     new a497d54  Merge pull request #331 from atoulme/add_version
df6e0f9 is described below

commit df6e0f91778d15a86fd8d1d72ef5f942a689b14d
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Jul 31 22:22:41 2021 -0700

    Add version printout
---
 {eth-client-app => app-commons}/build.gradle       | 44 ++++++++++++--------
 .../apache/tuweni/app/commons/ApplicationUtils.kt  | 48 ++++++++++++++++++++++
 .../src/main/resources/tuweni.txt                  |  0
 .../tuweni/app/commons/ApplicationUtilsTest.kt     | 28 +++++++++++++
 build.gradle                                       |  2 +-
 eth-client-app/build.gradle                        |  1 +
 .../apache/tuweni/ethclient/EthereumClientApp.kt   | 22 ++++------
 jsonrpc-app/build.gradle                           |  1 +
 .../org/apache/tuweni/jsonrpc/app/JSONRPCApp.kt    | 11 +++++
 jsonrpc/build.gradle                               |  1 +
 settings.gradle                                    |  1 +
 11 files changed, 129 insertions(+), 30 deletions(-)

diff --git a/eth-client-app/build.gradle b/app-commons/build.gradle
similarity index 50%
copy from eth-client-app/build.gradle
copy to app-commons/build.gradle
index 4e8f850..b562ab4 100644
--- a/eth-client-app/build.gradle
+++ b/app-commons/build.gradle
@@ -10,19 +10,38 @@
  * 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.
  */
-plugins { id 'application' }
-
-description = 'Ethereum client App'
+description = 'Apache Tuweni Application Utilities'
 
 dependencies {
-  implementation 'info.picocli:picocli'
-  implementation 'io.vertx:vertx-core'
-  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
-  implementation 'org.bouncycastle:bcprov-jdk15on'
+}
 
-  implementation project(':eth-client')
-  implementation project(':eth-client-ui')
+def copyrightHeader = """
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+"""
+
+processResources {
+  doFirst {
+    def resourcesDir = sourceSets.main.output.resourcesDir
+    resourcesDir.mkdirs()
+    def contents = "copyrightHeader\r\nversion=$rootProject.version"
+    new File(resourcesDir, "project-info.properties").text = contents
+  }
+}
 
+dependencies {
   testImplementation project(':junit')
   testImplementation 'org.junit.jupiter:junit-jupiter-api'
   testImplementation 'org.junit.jupiter:junit-jupiter-params'
@@ -30,11 +49,4 @@ dependencies {
   testImplementation 'org.mockito:mockito-junit-jupiter'
 
   testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
-
-  runtimeOnly 'ch.qos.logback:logback-classic'
-}
-
-application {
-  mainClassName = 'org.apache.tuweni.ethclient.EthereumClientAppKt'
-  applicationName = 'tuweni'
 }
diff --git a/app-commons/src/main/kotlin/org/apache/tuweni/app/commons/ApplicationUtils.kt b/app-commons/src/main/kotlin/org/apache/tuweni/app/commons/ApplicationUtils.kt
new file mode 100644
index 0000000..2aa2b0c
--- /dev/null
+++ b/app-commons/src/main/kotlin/org/apache/tuweni/app/commons/ApplicationUtils.kt
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.tuweni.app.commons
+
+import java.nio.charset.StandardCharsets
+import java.util.Properties
+
+/**
+ * Utilities to display versions and banners in programs.
+ */
+object ApplicationUtils {
+
+  val version: String
+  init {
+    val infoProperties = Properties()
+    infoProperties.load(ApplicationUtils::class.java.classLoader.getResourceAsStream("project-info.properties"))
+    version = infoProperties["version"].toString()
+  }
+
+  fun renderBanner(message: String) {
+    val asciiart =
+      ApplicationUtils::class.java.getResourceAsStream("/tuweni.txt").readAllBytes().toString(StandardCharsets.UTF_8)
+    if (System.console() != null) {
+      asciiart.split("\n").forEachIndexed { lineNo, line ->
+        if (lineNo % 2 == 0) {
+          println("\u001b[5;37m$line\u001b[0m")
+        } else {
+          println(line)
+        }
+      }
+    }
+    println(message)
+  }
+}
diff --git a/eth-client-app/src/main/resources/tuweni.txt b/app-commons/src/main/resources/tuweni.txt
similarity index 100%
rename from eth-client-app/src/main/resources/tuweni.txt
rename to app-commons/src/main/resources/tuweni.txt
diff --git a/app-commons/src/test/kotlin/org/apache/tuweni/app/commons/ApplicationUtilsTest.kt b/app-commons/src/test/kotlin/org/apache/tuweni/app/commons/ApplicationUtilsTest.kt
new file mode 100644
index 0000000..a527052
--- /dev/null
+++ b/app-commons/src/test/kotlin/org/apache/tuweni/app/commons/ApplicationUtilsTest.kt
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.tuweni.app.commons
+
+import org.junit.jupiter.api.Assertions.assertFalse
+import org.junit.jupiter.api.Test
+
+class ApplicationUtilsTest {
+
+  @Test
+  fun testVersion() {
+    assertFalse(ApplicationUtils.version.isBlank())
+  }
+}
diff --git a/build.gradle b/build.gradle
index 92b3df5..170b5e3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -123,7 +123,7 @@ if (file('.git').exists()) {
         'eth/src/test/resources/missing-nonce.json',
         'eth/src/test/resources/valid-genesis.json',
         'eth/src/test/resources/besu-dev.json',
-        'eth-client-app/src/main/resources/tuweni.txt',
+        'app-commons/src/main/resources/tuweni.txt',
         'evm/src/test/resources/**',
         'tuweni.png',
         'eth-crawler/src/main/resources/webapp/bootstrap-nightfall.css',
diff --git a/eth-client-app/build.gradle b/eth-client-app/build.gradle
index 4e8f850..20068de 100644
--- a/eth-client-app/build.gradle
+++ b/eth-client-app/build.gradle
@@ -20,6 +20,7 @@ dependencies {
   implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
   implementation 'org.bouncycastle:bcprov-jdk15on'
 
+  implementation project(':app-commons')
   implementation project(':eth-client')
   implementation project(':eth-client-ui')
 
diff --git a/eth-client-app/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientApp.kt b/eth-client-app/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientApp.kt
index 7a5f4c5..c43f8ff 100644
--- a/eth-client-app/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientApp.kt
+++ b/eth-client-app/src/main/kotlin/org/apache/tuweni/ethclient/EthereumClientApp.kt
@@ -18,27 +18,16 @@ package org.apache.tuweni.ethclient
 
 import io.vertx.core.Vertx
 import kotlinx.coroutines.runBlocking
+import org.apache.tuweni.app.commons.ApplicationUtils
 import org.apache.tuweni.ethclientui.UI
 import org.bouncycastle.jce.provider.BouncyCastleProvider
 import picocli.CommandLine
-import java.nio.charset.StandardCharsets
 import java.nio.file.Path
 import java.security.Security
 import kotlin.system.exitProcess
 
 fun main(args: Array<String>) = runBlocking {
-  val asciiart =
-    AppOptions::class.java.getResourceAsStream("/tuweni.txt").readAllBytes().toString(StandardCharsets.UTF_8)
-  if (System.console() != null) {
-    asciiart.split("\n").forEachIndexed { lineNo, line ->
-      if (lineNo % 2 == 0) {
-        println("\u001b[5;37m$line\u001b[0m")
-      } else {
-        println(line)
-      }
-    }
-    println("Apache Tuweni client loading")
-  }
+  ApplicationUtils.renderBanner("Apache Tuweni client loading")
   Security.addProvider(BouncyCastleProvider())
   val opts = CommandLine.populateCommand(AppOptions(), *args)
 
@@ -46,6 +35,10 @@ fun main(args: Array<String>) = runBlocking {
     CommandLine(opts).usage(System.out)
     exitProcess(0)
   }
+  if (opts.version) {
+    println("Apache Tuweni #{ApplicationUtils.version}")
+    exitProcess(0)
+  }
 
   val config = EthereumClientConfig.fromFile(opts.configPath)
   val ethClient = EthereumClient(Vertx.vertx(), config)
@@ -64,6 +57,9 @@ class AppOptions {
   @CommandLine.Option(names = ["-h", "--help"], description = ["Prints usage prompt"])
   var help: Boolean = false
 
+  @CommandLine.Option(names = ["-v", "--version"], description = ["Prints version"])
+  var version: Boolean = false
+
   @CommandLine.Option(names = ["-w", "--web"], description = ["Web console host:port"], defaultValue = "127.0.0.1:8080")
   var web: String? = null
 }
diff --git a/jsonrpc-app/build.gradle b/jsonrpc-app/build.gradle
index 61441fd..70e7ac7 100644
--- a/jsonrpc-app/build.gradle
+++ b/jsonrpc-app/build.gradle
@@ -15,6 +15,7 @@ plugins { id 'application' }
 description = 'Ethereum JSON-RPC client application'
 
 dependencies {
+  implementation project(':app-commons')
   implementation project(':bytes')
   implementation project(':config')
   implementation project(':crypto')
diff --git a/jsonrpc-app/src/main/kotlin/org/apache/tuweni/jsonrpc/app/JSONRPCApp.kt b/jsonrpc-app/src/main/kotlin/org/apache/tuweni/jsonrpc/app/JSONRPCApp.kt
index 3d10d92..90f448d 100644
--- a/jsonrpc-app/src/main/kotlin/org/apache/tuweni/jsonrpc/app/JSONRPCApp.kt
+++ b/jsonrpc-app/src/main/kotlin/org/apache/tuweni/jsonrpc/app/JSONRPCApp.kt
@@ -22,6 +22,7 @@ import io.vertx.core.VertxOptions
 import io.vertx.tracing.opentelemetry.OpenTelemetryOptions
 import kotlinx.coroutines.asCoroutineDispatcher
 import kotlinx.coroutines.runBlocking
+import org.apache.tuweni.app.commons.ApplicationUtils
 import org.apache.tuweni.eth.internalError
 import org.apache.tuweni.bytes.Bytes
 import org.apache.tuweni.eth.JSONRPCResponse
@@ -50,6 +51,7 @@ import org.slf4j.LoggerFactory
 import java.nio.file.Paths
 import java.security.Security
 import java.util.concurrent.Executors
+import kotlin.system.exitProcess
 
 val logger = LoggerFactory.getLogger(JSONRPCApp::class.java)
 
@@ -60,6 +62,15 @@ object JSONRPCApp {
 
   @JvmStatic
   fun main(args: Array<String>) {
+    if (args.contains("--version")) {
+      println("Apache Tuweni JSON-RPC proxy ${ApplicationUtils.version}")
+      exitProcess(0)
+    }
+    if (args.contains("--help") || args.contains("-h")) {
+      println("USAGE: jsonrpc <config file>")
+      exitProcess(0)
+    }
+    ApplicationUtils.renderBanner("Loading JSON-RPC proxy")
     val configFile = Paths.get(if (args.isNotEmpty()) args[0] else "config.toml")
     Security.addProvider(BouncyCastleProvider())
 
diff --git a/jsonrpc/build.gradle b/jsonrpc/build.gradle
index e56512f..46d874e 100644
--- a/jsonrpc/build.gradle
+++ b/jsonrpc/build.gradle
@@ -26,6 +26,7 @@ dependencies {
   implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core'
   implementation 'io.vertx:vertx-lang-kotlin-coroutines'
   implementation 'io.vertx:vertx-lang-kotlin'
+  implementation project(':app-commons')
   implementation project(':bytes')
   implementation project(':crypto')
   implementation project(':concurrent')
diff --git a/settings.gradle b/settings.gradle
index 2f738d2..3949e41 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -11,6 +11,7 @@
  * specific language governing permissions and limitations under the License.
  */
 rootProject.name='tuweni'
+include 'app-commons'
 include 'bytes'
 include 'concurrent'
 include 'concurrent-coroutines'

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org