Skip to content

Commit

Permalink
Merge pull request #113 from hyperledger/removeEpirus
Browse files Browse the repository at this point in the history
updated to gradle 8.7 and removed Epirus
  • Loading branch information
NickSneo authored Oct 7, 2024
2 parents a41613a + 724c7fa commit 4fb9791
Show file tree
Hide file tree
Showing 87 changed files with 853 additions and 534 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,3 @@ docs/build
**/.project
**/.settings
**/bin

gradle/bintray
gradle/jacoco
gradle/java
gradle/javadoc
gradle/publish
gradle/repositories
gradle/spotless
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [4.11.3]() (Upcoming)
# [4.12.3]() (Upcoming)

### Bug Fixes

*

### Features

* updated to gradle 8.7 and removed Epirus [#113](https://github.com/hyperledger/web3j-openapi/pull/113)
* Bump snapshot version to 4.11.3 [#109](https://github.com/hyperledger/web3j-openapi/pull/109)

### BREAKING CHANGES
Expand Down
25 changes: 10 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Web3j Open API
[![Build Status](https://travis-ci.org/web3j/web3j-openapi.svg?branch=master)](https://travis-ci.org/web3j/web3j-openapi)

Web3j-OpenAPI is a [OpenAPI](https://swagger.io/specification/) client and server generator from
[Solidity](https://solidity.readthedocs.io/) smart contracts. it provides a way to interact with the Ethereum blockchain via simple and intuitive HTTP requests, abstracting the coding layer. These interactions can be done using :
[Solidity](https://solidity.readthedocs.io/) smart contracts. it provides a way to interact with the Ethereum blockchain via simple and intuitive
HTTP requests, abstracting the coding layer. These interactions can be done using :
- Plain HTTP requests
- Via the `Swagger-UI`, which is generated with every project
- A client application using the [`webj3-openapi-client`](/client) implementation
Expand All @@ -16,31 +17,25 @@ The workflow can be summed in the following steps:
- Sending HTTP requests using `Swagger-UI`, client application or `Curl` request.

# Getting started with Web3j-OpenAPI
To generate an OpenAPI project using the [Web3j-OpenAPI](https://github.com/web3j/web3j-openapi) generator, you need to have the [Epirus-CLI](https://docs.epirus.io/quickstart) installed on your machine (Note - the Epirus CLI has replaced the Web3j CLI).
It’s easy to do (for Windows instructions head [here](https://docs.epirus.io/quickstart/#installation)):
To generate an OpenAPI project using the [Web3j-OpenAPI](https://github.com/hyperledger/web3j-openapi) generator,
you need to have the [Web3j-CLI](https://docs.web3j.io/latest/command_line_tools/) installed on your machine.
It’s easy to do (for Windows instructions head [here](https://github.com/hyperledger/web3j-cli/)):

```ssh
$ curl -L get.epirus.io | sh
$ curl -L get.web3j.io | sh
```

### Create a Hello World project
To create a base OpenAPI project using a `Hello World` contract, run the following :

```ssh
$ epirus openapi new
$ web3j openapi new
```

You can also generate a `Web3j-OpenAPI` project using the [Web3j-OpenAPI-gradle-plugin](https://github.com/web3j/web3j-openapi-gradle-plugin).

### Configure the project
After having the generated project, you can use the [Epirus-CLI](https://docs.epirus.io) to run it using the following command (Note: You will need to create an [Epirus](https://www.web3labs.com/epirus) Account).

```ssh
$ epirus login
$ epirus run rinkeby|ropsten
```

Alternatively, you can configure your application with the following environment variables:
After having the generated project, you can configure your application with the following environment variables:

```ssh
$ export WEB3J_ENDPOINT=<link_to_your_Ethereum_node>
Expand All @@ -50,7 +45,7 @@ $ export WEB3J_OPENAPI_PORT=9090
```

### Run the project
If you aren't using the [Epirus-CLI](https://docs.epirus.io/quickstart/#deployment), you may run the project using the following Gradle target:
If you aren't using the Web3j-CLI you may run the project using the following Gradle target:

```ssh
$ cd <project_folder>
Expand All @@ -70,7 +65,7 @@ The easiest way to interact with the generated project is via the generated `Swa
Also, you can use our client implementation via adding the following dependency to your project:
```groovy
dependencies {
implementation "org.web3j.openapi:web3j-openapi-client:4.7.1"
implementation "org.web3j.openapi:web3j-openapi-client:4.12.2"
}
```

Expand Down
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:4.0.0'
classpath 'org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:4.1.0'
}
}

plugins {
id 'de.undercouch.download' version '4.1.1'
id 'com.diffplug.gradle.spotless' version '4.5.1'
id 'io.codearte.nexus-staging' version '0.22.0'
id 'de.undercouch.download' version '4.1.2'
id 'com.diffplug.spotless' version '6.25.0'
id 'io.codearte.nexus-staging' version '0.30.0'
id 'de.marcphilipp.nexus-publish' version '0.4.0'
}

Expand All @@ -34,7 +33,6 @@ subprojects {

apply {
[
'bintray',
'publish',
'jacoco',
'java',
Expand Down Expand Up @@ -113,4 +111,8 @@ subprojects {
}

sourceCompatibility = 17

tasks.named("spotlessJava") {
dependsOn(tasks.named("spotlessGroovyGradle"))
}
}
11 changes: 9 additions & 2 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ dependencies {
implementation "com.fasterxml.jackson.module:jackson-module-kotlin:${versions.jackson}"
}

// To publish in mavenLocal()
// tasks.withType(Sign)*.enabled = false
tasks.named("spotlessJava") {
dependsOn(tasks.named("spotlessGroovyGradle"))
dependsOn(tasks.named("compileKotlin"))
}

tasks.named("spotlessKotlin") {
dependsOn(tasks.named("spotlessGroovyGradle"))
dependsOn(tasks.named("spotlessJava"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import javax.ws.rs.core.MediaType
* Client API exception containing error data.
*/
class ClientException internal constructor(
val error: ErrorResponse?
val error: ErrorResponse?,
) : RuntimeException(error?.title) {
companion object {

Expand All @@ -34,8 +34,8 @@ class ClientException internal constructor(
ErrorResponse(
title = exception.response.statusInfo.reasonPhrase,
requestUrl = exception.response.location?.toString(),
responseStatus = exception.response.status
)
responseStatus = exception.response.status,
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import javax.ws.rs.sse.SseEventSource
*/
internal class ClientInvocationHandler(
private val target: WebTarget,
private val client: Any
private val client: Any,
) : InvocationHandler {

override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): Any? {
Expand Down Expand Up @@ -71,7 +71,7 @@ internal class ClientInvocationHandler(
Proxy.newProxyInstance(
method.returnType.classLoader,
arrayOf(method.returnType),
ClientInvocationHandler(target, it)
ClientInvocationHandler(target, it),
)
} else {
it
Expand All @@ -91,7 +91,7 @@ internal class ClientInvocationHandler(
} else {
logger.error {
"Unexpected exception while invoking method $method: " +
(error.message ?: error::class.java.canonicalName)
(error.message ?: error::class.java.canonicalName)
}
error.targetException
}
Expand All @@ -101,7 +101,7 @@ internal class ClientInvocationHandler(
private fun handleClientError(error: ClientErrorException, method: Method): RuntimeException {
logger.error {
"Client exception while invoking method $method: " +
(error.message ?: error.response.statusInfo.reasonPhrase)
(error.message ?: error.response.statusInfo.reasonPhrase)
}
return ClientException.of(error)
}
Expand All @@ -115,9 +115,9 @@ internal class ClientInvocationHandler(
}

private fun Method.isEvent() = name == "onEvent" &&
parameterTypes.size == 1 &&
parameterTypes[0] == Consumer::class.java &&
returnType == CompletableFuture::class.java
parameterTypes.size == 1 &&
parameterTypes[0] == Consumer::class.java &&
returnType == CompletableFuture::class.java

private val Any.typeArguments: List<Class<*>>
get() {
Expand All @@ -128,13 +128,13 @@ internal class ClientInvocationHandler(
private class SseEventSourceResult<T>(
private val source: SseEventSource,
onEvent: Consumer<T>,
eventType: Class<T>
eventType: Class<T>,
) : CompletableFuture<Void>() {
init {
source.register(
{ onEvent.accept(it.readData(eventType)) },
{ completeExceptionally(it) },
{ complete(null) }
{ complete(null) },
)
whenComplete { _, _ ->
// Close the source gracefully by client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import java.util.logging.Logger
import javax.ws.rs.client.Client
import javax.ws.rs.client.ClientBuilder

class ClientService @JvmOverloads constructor (
class ClientService @JvmOverloads constructor(
val uri: String,
readTimeout: Int = DEFAULT_READ_TIMEOUT,
connectTimeout: Int = DEFAULT_CONNECT_TIMEOUT
connectTimeout: Int = DEFAULT_CONNECT_TIMEOUT,
) : AutoCloseable {

private val mapper = jacksonObjectMapper()
Expand Down
16 changes: 14 additions & 2 deletions codegen/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,17 @@ task copyIntegrationTestResources(type: Copy) {

integrationTest.dependsOn copyIntegrationTestResources, publishToMavenLocal

// To publish in mavenLocal()
// tasks.withType(Sign)*.enabled = false
tasks.named("spotlessKotlin") {
dependsOn(tasks.named("spotlessGroovyGradle"))
dependsOn(tasks.named("spotlessJava"))
dependsOn(tasks.named("test"))
}

tasks.named("spotlessJava") {
dependsOn(tasks.named("spotlessGroovyGradle"))
dependsOn(tasks.named("compileKotlin"))
dependsOn(tasks.named("compileTestKotlin"))
dependsOn(tasks.named("processResources"))
dependsOn(tasks.named("processTestResources"))
dependsOn(tasks.named("test"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ class GenerationTest {
"src",
"test",
"resources",
"contracts").toFile()
"contracts",
).toFile()

val generatorConfiguration = GeneratorConfiguration(
projectName = "testProject",
packageName = "com.test",
outputDir = tempFolder.canonicalPath,
contracts = loadContractConfigurations(listOf(contractsFolder)),
contextPath = "test"
contextPath = "test",
)
assertDoesNotThrow {
OpenApiGenerator(generatorConfiguration).generate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package org.web3j.openapi.codegen
import org.web3j.openapi.codegen.config.GeneratorConfiguration

abstract class AbstractGenerator(
val configuration: GeneratorConfiguration
val configuration: GeneratorConfiguration,
) {
protected val packageDir = configuration.packageName.split(".").joinToString("/")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.web3j.openapi.codegen.coregen.CoreGenerator
import org.web3j.openapi.codegen.servergen.ServerGenerator

class OpenApiGenerator(
private val configuration: GeneratorConfiguration
private val configuration: GeneratorConfiguration,
) {
fun generate() {
println("Generating Web3j-OpenAPI project ... Files written to ${configuration.outputDir}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ package org.web3j.openapi.codegen.common

class ContractResources(
val functionResources: List<FunctionResource>,
val eventResources: List<EventResource>
val eventResources: List<EventResource>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ data class EventResource(
val returnType: String = "",
val path: String = "",
val capitalizedName: String,
val decapitalizedName: String = capitalizedName.decapitalize()
val decapitalizedName: String = capitalizedName.decapitalize(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ data class FunctionResource(
val returnType: String,
val mediaType: String = "",
val path: String = "",
val operationTag: String = ""
val operationTag: String = "",
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ package org.web3j.openapi.codegen.common

data class ParameterDefinition(
val name: String,
val type: String
val type: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ package org.web3j.openapi.codegen.common
data class Tag(
val name: String,
val description: String,
var lastCharacter: String = ","
var lastCharacter: String = ",",
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ import java.io.File

data class ContractConfiguration(
val abiFile: File,
val contractDetails: ContractDetails
val contractDetails: ContractDetails,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.web3j.protocol.core.methods.response.AbiDefinition

data class ContractDetails(
val contractName: String,
var abiDefinitions: List<AbiDefinition>
var abiDefinitions: List<AbiDefinition>,
) {
init {
abiDefinitions.filter { it.isPayable }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class GeneratorConfiguration @JvmOverloads constructor(
val contextPath: String,
val version: String = VersionProvider.versionName,
val sanitizedProjectName: String = sanitizeName(projectName),
val withImplementations: Boolean = true
val withImplementations: Boolean = true,
) {
val rootProjectName = sanitizedProjectName.toLowerCase().replace(' ', '-')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object VersionProvider {
fun getVersion(): Array<String> {
return arrayOf(
"Version: $versionName",
"Build timestamp: ${buildTimestamp.let { timeFormatter.format(it) }}"
"Build timestamp: ${buildTimestamp.let { timeFormatter.format(it) }}",
)
}
}
Loading

0 comments on commit 4fb9791

Please sign in to comment.