From 283d1e1e2150ad6bbc925941fb1b83fcfaa56eeb Mon Sep 17 00:00:00 2001 From: Christian Felde Date: Mon, 1 Nov 2021 12:34:15 +0000 Subject: [PATCH] Remove plugin code and config as moving plugin code to web3j-deployer-plugin repo --- README.md | 67 ++++++++++--------- build.gradle | 26 +------ .../kotlin/org/web3j/deploy/DeployPlugin.kt | 53 --------------- 3 files changed, 38 insertions(+), 108 deletions(-) delete mode 100644 src/main/kotlin/org/web3j/deploy/DeployPlugin.kt diff --git a/README.md b/README.md index 3168dc2..0aa9d7f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ A simple and lightweight library for managing deployments of Ethereum contracts Library is intended used by the Web3j CLI, but may also be used on its own. -Through the use of two annotations, `@Predeploy` and `@Deployable`, developers can define deploy configurations and deployment methods. +Through the use of two annotations, `@Predeploy` and `@Deployable`, developers can define deploy configurations and +deployment methods. Let's start by looking at `@Predeploy` and how this is used to define a Deployer instance for a given network @@ -12,67 +13,73 @@ Let's start by looking at `@Predeploy` and how this is used to define a Deployer package com.example.deployers @Predeploy(profile = "my-deploy-profile") -public Deployer deployMyContract() { - Credentials credentials = ...; +public Deployer deployMyContract(){ + Credentials credentials=...; - Web3j web3j = Web3j.build(...); + Web3j web3j=Web3j.build(...); - return new Deployer(web3j, new FastRawTransactionManager(web3j, credentials), new DefaultGasProvider(), "my-deploy-profile"); -} + return new Deployer(web3j,new FastRawTransactionManager(web3j,credentials),new DefaultGasProvider(),"my-deploy-profile"); + } ``` The profile name can be defined to whatever makes sense to you. Here we use `my-deploy-profile` as an example label. -Assuming you defined this within a package called `com.example.deployers`, you could obtain a reference to this deployer using the `DeployTools`: +Assuming you defined this within a package called `com.example.deployers`, you could obtain a reference to this deployer +using the `DeployTools`: ```java -String profile = "my-deploy-profile"; -String pkgFilter = "com.example" -Deployer deployer = new DeployTools().findDeployer(profile, pkgFilter); +String profile="my-deploy-profile"; + String pkgFilter="com.example" + Deployer deployer=new DeployTools().findDeployer(profile,pkgFilter); ``` -Next you want to define methods that allows you to use the deployer. Often, for complex contract setups, you have multiple steps during a deployment process. Using the `@Deployable` annotation you can define the order you want them to execute, starting low: +Next you want to define methods that allows you to use the deployer. Often, for complex contract setups, you have +multiple steps during a deployment process. Using the `@Deployable` annotation you can define the order you want them to +execute, starting low: ```java package com.example.deploy @Deployable(order = 1) -public void deployA(Deployer deployer) { - ... -} +public void deployA(Deployer deployer){ + ... + } @Deployable(order = 2) -public void deployB(Deployer deployer) { - ... -} +public void deployB(Deployer deployer){ + ... + } @Deployable(order = 3) -public void deployC(Deployer deployer) { - ... -} +public void deployC(Deployer deployer){ + ... + } ``` -When using `runDeployer` from `DeployTools`, it will execute these as `deployA`, `deployB`, and finally `deployC` due to the `order` value on each of the `@Deployable` annotations. Execute them like so: +When using `runDeployer` from `DeployTools`, it will execute these as `deployA`, `deployB`, and finally `deployC` due to +the `order` value on each of the `@Deployable` annotations. Execute them like so: ```java -public static void main(String... args) { - String profile = "my-deploy-profile"; - String pkgFilter = "com.example"; - DeployTools deployTools = new DeployTools() - Deployer deployer = deployTools.findDeployer(network, pkgFilter); - deployTools.runDeployer(deployer, pkgFilter); -} +public static void main(String...args){ + String profile="my-deploy-profile"; + String pkgFilter="com.example"; + DeployTools deployTools=new DeployTools() + Deployer deployer=deployTools.findDeployer(network,pkgFilter); + deployTools.runDeployer(deployer,pkgFilter); + } ``` ## Gradle deploy task -If you include this library in your project, and also include it as a plugin, you can use the deploy task to deploy your contracts like so: +If you include the [web3j-deployer-plugin](https://github.com/web3j/web3j-deployer-plugin) in your project as a plugin, +you can use the deploy task to deploy your contracts like so: ```bash ./gradlew deploy -Pprofile=my-profile -Ppackage=org.testing ``` -To add this as a plugin to your gradle project, in build.gradle include, the below replaing x.y.z with the current version: +To add this as a plugin to your gradle project, in build.gradle include, the below replaing x.y.z with the current +version: ```gradle plugins { diff --git a/build.gradle b/build.gradle index e2a7c58..595a442 100644 --- a/build.gradle +++ b/build.gradle @@ -1,39 +1,15 @@ plugins { - id 'java-gradle-plugin' id 'org.jetbrains.kotlin.jvm' version '1.3.72' id 'de.marcphilipp.nexus-publish' version '0.4.0' id 'io.codearte.nexus-staging' version '0.22.0' - id 'com.gradle.plugin-publish' version '0.12.0' } + apply from: "$rootDir/gradle/publish/build.gradle" apply plugin: 'java' apply plugin: 'idea' - description 'Library for managing deployments of Ethereum contracts and transactions.' - -gradlePlugin { - plugins { - deploy { - id = 'org.web3j.deploy' - implementationClass = 'org.web3j.deploy.DeployPlugin' - } - } -} - - -pluginBundle { - website = 'https://web3j.io/' - vcsUrl = 'https://github.com/web3j/web3j-deployer' - description = 'Gradle plugin for managing deployments of Ethereum contracts and transactions.' - tags = [ - 'ethereum', - 'web3j', - 'deployer' - ] -} - group 'org.web3j' version '4.8.8' diff --git a/src/main/kotlin/org/web3j/deploy/DeployPlugin.kt b/src/main/kotlin/org/web3j/deploy/DeployPlugin.kt deleted file mode 100644 index 42d55d1..0000000 --- a/src/main/kotlin/org/web3j/deploy/DeployPlugin.kt +++ /dev/null @@ -1,53 +0,0 @@ -@file:JvmName("DeployPlugin") - -package org.web3j.deploy - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginConvention -import java.net.URL -import java.net.URLClassLoader - -class DeployPlugin: Plugin { - override fun apply(project: Project) { - val urls : MutableList = mutableListOf() - - // Adding runtime classpath of project - project.afterEvaluate { - val plugin = it.convention.getPlugin(JavaPluginConvention::class.java) - plugin.sourceSets.forEach { sourceSet -> - sourceSet.runtimeClasspath.forEach{path -> - urls.add(path.toURI().toURL()) - } - } - } - - project.tasks.create("deploy") { task -> - val profileName = project.properties.getOrDefault("profile", null)?.toString() - val packageName = project.properties.getOrDefault("package", null)?.toString() - - if (profileName == null || packageName == null) { - println("Missing profile and/or package name parameters") - return@create - } - - task.doLast { - val loader = URLClassLoader(urls.toTypedArray()) - - val deployToolsClass = loader.loadClass(DeployTools::class.java.name) - val deployToolsConstructor = deployToolsClass.getDeclaredConstructor() - val deployTools = deployToolsConstructor.newInstance() - val deploy = deployToolsClass.getDeclaredMethod( - "deploy", - String::class.java, - String::class.java - ) - - deploy.invoke(deployTools, profileName, packageName) - } - - task.group = "web3j" - task.dependsOn("build") - } - } -} \ No newline at end of file