├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle ├── src └── main │ ├── java │ └── com │ │ └── webank │ │ └── scaffold │ │ ├── Main.java │ │ ├── artifact │ │ ├── Artifact.java │ │ ├── dir │ │ │ ├── ConfDir.java │ │ │ ├── ContractsDir.java │ │ │ ├── DirectoryArtifact.java │ │ │ ├── GradleDir.java │ │ │ ├── MainDir.java │ │ │ ├── MainJavaDir.java │ │ │ ├── MainResourceDir.java │ │ │ ├── RootDir.java │ │ │ ├── SrcDir.java │ │ │ ├── TestDir.java │ │ │ ├── TestJavaDir.java │ │ │ └── root │ │ │ │ ├── GradleRootDir.java │ │ │ │ ├── MavenRootDir.java │ │ │ │ └── RootDir.java │ │ └── file │ │ │ ├── ApplicationJava.java │ │ │ ├── ApplicationProperties.java │ │ │ ├── BcosConfigJava.java │ │ │ ├── BuildGradle.java │ │ │ ├── CommonResponseJava.java │ │ │ ├── DemosTestJava.java │ │ │ ├── Mvnw.java │ │ │ ├── MvnwCmd.java │ │ │ ├── Pom.java │ │ │ ├── SdkBeanConfigJava.java │ │ │ └── SettingsGradle.java │ │ ├── builder │ │ ├── ConstructorBoFileBuilder.java │ │ ├── ContractConfigBuilder.java │ │ ├── ContractConstantsBuilder.java │ │ ├── FunctionBoFileBuilder.java │ │ ├── JavaFileBuilder.java │ │ ├── ServiceFileBuilder.java │ │ ├── StructsFileBuilder.java │ │ └── SystemConfigBuilder.java │ │ ├── cmd │ │ └── ScaffoldRunner.java │ │ ├── compiler │ │ └── ContractCompiler.java │ │ ├── config │ │ └── UserConfig.java │ │ ├── constants │ │ ├── DirNameConstants.java │ │ ├── FileNameConstants.java │ │ └── ReplaceConstants.java │ │ ├── enums │ │ └── ProjectType.java │ │ ├── exception │ │ └── ScaffoldException.java │ │ ├── factory │ │ └── ProjectFactory.java │ │ ├── handler │ │ ├── ContractHandler.java │ │ ├── ServiceBeanConfigHandler.java │ │ ├── ServicesHandler.java │ │ └── SolidityTypeHandler.java │ │ └── util │ │ ├── ABIUtil.java │ │ └── IOUtil.java │ └── resources │ └── templates │ ├── Application.java.tpl │ ├── BcosConfig.java.tpl │ ├── CommonResponse.java.tpl │ ├── Demos.java.tpl │ ├── SdkBeanConfig.java.tpl │ ├── TestConnection.java.tpl │ ├── build.gradle.tpl │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar.tpl │ │ └── gradle-wrapper.properties.tpl │ ├── mvnw.cmd.tpl │ ├── mvnw.tpl │ ├── pom.xml.tpl │ └── settings.gradle.tpl └── tools ├── config.ini ├── contracts ├── HelloWorld.sol └── KVTable.sol ├── run.bat └── run.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | build/ 3 | .classpath 4 | bin/ 5 | .settings/ 6 | .project 7 | dist/ 8 | tmp/ 9 | /.gradle/ 10 | *.lck 11 | .idea/ 12 | out/ 13 | demo/ 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 3 | GitHub All Releases 4 | 5 | # 组件介绍 6 | 7 | 应用开发脚手架用于一键生成区块链应用开发工程,从而提高应用开发的效率。用户可将智能合约导入脚手架,即可生成对应的区块链应用开发工程,包含了合约函数对应的DAO(Data Access Object)层代码。用户可基于生成的项目补充自己的业务逻辑。 8 | 9 | ## 环境要求 10 | 11 | 在使用本组件前,请确认系统环境已安装相关依赖软件,清单如下: 12 | 13 | | 依赖软件 | 说明 | 备注 | 14 | | ---------- | ------------------------------------------------------------ | ---- | 15 | | Java | \>= JDK[1.8] | | 16 | | Git | 下载安装源码使用Git | | 17 | 18 | 19 | ## 文档 20 | - [**中文**](https://toolkit-doc.readthedocs.io/zh_CN/latest/docs/WeBankBlockchain-SmartDev-Scaffold/index.html) 21 | - [**快速开始**](https://toolkit-doc.readthedocs.io/zh_CN/latest/docs/WeBankBlockchain-SmartDev-Scaffold/quick_start.html) 22 | 23 | 24 | ## 贡献代码 25 | 欢迎参与本项目的社区建设: 26 | - 如项目对您有帮助,欢迎点亮我们的小星星(点击项目左上方Star按钮)。 27 | - 欢迎提交代码(Pull requests)。 28 | - [提问和提交BUG](https://github.com/WeBankBlockchain/SmartDev-Scaffold/issues)。 29 | - 如果发现代码存在安全漏洞,请在[这里](https://security.webank.com)上报。 30 | 31 | 32 | ![](https://media.githubusercontent.com/media/FISCO-BCOS/LargeFiles/master/images/QR_image.png) 33 | 34 | 35 | ## License 36 | ![license](http://img.shields.io/badge/license-Apache%20v2-blue.svg) 37 | 38 | 开源协议为[Apache License 2.0](http://www.apache.org/licenses/). 详情参考[LICENSE](../LICENSE)。 39 | 40 | 41 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.github.johnrengelman.shadow' version '6.1.0' 3 | id 'java' 4 | id 'eclipse' 5 | id 'idea' 6 | id 'application' 7 | } 8 | 9 | group 'com.webank' 10 | version '1.2.0' 11 | 12 | sourceCompatibility = 1.8 13 | targetCompatibility = 1.8 14 | 15 | def solcVersion = rootProject.hasProperty('solcVersion') ? solcVersion : "0.6.10.0" 16 | 17 | repositories { 18 | mavenCentral() 19 | maven { url "https://maven.aliyun.com/nexus/content/groups/public/"} 20 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 21 | maven { url "https://dl.bintray.com/ethereum/maven/" } 22 | mavenLocal() 23 | } 24 | 25 | def log4j_version="2.16.0" 26 | List logger = [ 27 | "org.apache.logging.log4j:log4j-api:$log4j_version", 28 | "org.apache.logging.log4j:log4j-core:$log4j_version", 29 | "org.apache.logging.log4j:log4j-to-slf4j:$log4j_version", 30 | ] 31 | 32 | dependencies { 33 | compile logger 34 | implementation ('com.webank:solc-gradle-plugin:1.0.1') 35 | implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:2.9.1') 36 | implementation group: 'info.picocli', name: 'picocli', version: '4.6.1' 37 | implementation ("org.slf4j:slf4j-api:1.7.30") 38 | implementation "org.fisco-bcos:solcJ:${solcVersion}" 39 | } 40 | 41 | 42 | shadowJar { 43 | mainClassName = 'com.webank.scaffold.Main' 44 | destinationDirectory = file('dist') 45 | archiveFileName = project.name+'.jar' 46 | 47 | exclude '**/*.DSA' 48 | exclude '**/*.RSA' 49 | exclude '**/*.SF' 50 | manifestContentCharset 'utf-8' 51 | metadataCharset 'utf-8' 52 | 53 | from("./"){ 54 | include 'build.gradle' 55 | } 56 | } 57 | 58 | clean { 59 | println "delete ${projectDir}/dist" 60 | delete "${projectDir}/dist" 61 | } 62 | 63 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/SmartDev-Scaffold/1a46d0d8f8bb1698f926918dc72cfcde93c8e33d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'WeBankBlockchain-SmartDev-Scaffold' 2 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/Main.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold; 2 | 3 | import com.webank.scaffold.cmd.ScaffoldRunner; 4 | import com.webank.scaffold.constants.FileNameConstants; 5 | import picocli.CommandLine; 6 | 7 | import java.io.InputStream; 8 | 9 | /** 10 | * @author aaronchu 11 | * @Description 12 | * @data 2021/01/20 13 | */ 14 | public class Main { 15 | 16 | public static void main(String[] args) { 17 | CommandLine cmd = new CommandLine(new ScaffoldRunner()); 18 | cmd.execute(args); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/Artifact.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact; 2 | 3 | import java.io.File; 4 | 5 | public interface Artifact { 6 | 7 | void generate() throws Exception; 8 | 9 | default boolean isDirectory(){ 10 | return false; 11 | } 12 | 13 | default File toFile(){ 14 | return new File(getParentDir(), getName()); 15 | } 16 | 17 | File getParentDir(); 18 | 19 | String getName(); 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/ConfDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.constants.DirNameConstants; 4 | 5 | import java.io.File; 6 | 7 | /** 8 | * @author aaronchu 9 | * @Description 10 | * @data 2021/01/19 11 | */ 12 | public class ConfDir extends DirectoryArtifact { 13 | 14 | public ConfDir(File path) { 15 | super(path); 16 | } 17 | 18 | @Override 19 | protected void doGenerateSubContents() throws Exception { 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return DirNameConstants.CONF_DIR; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/ContractsDir.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.artifact.dir; 17 | 18 | import java.io.File; 19 | 20 | import org.apache.commons.io.FileUtils; 21 | 22 | import com.webank.scaffold.config.UserConfig; 23 | import com.webank.scaffold.constants.DirNameConstants; 24 | import com.webank.scaffold.exception.ScaffoldException; 25 | 26 | /** 27 | * ContractsDir 28 | * 29 | * @Description: 30 | * @Author: grayson 31 | * @Version 1.0 32 | * @Date: 2021-04-07 11:12 33 | **/ 34 | public class ContractsDir extends DirectoryArtifact { 35 | 36 | private UserConfig config; 37 | 38 | public ContractsDir(File parentDir, UserConfig config) { 39 | super(parentDir); 40 | this.config = config; 41 | } 42 | 43 | @Override 44 | protected void doGenerateSubContents() throws Exception { 45 | File file = FileUtils.getFile(config.getSolidityDir()); 46 | if(checkContractsDir(file)){ 47 | FileUtils.copyDirectory(file, this.toFile()); 48 | } 49 | } 50 | 51 | @Override 52 | public String getName() { 53 | return DirNameConstants.SOL_Dir; 54 | } 55 | 56 | private boolean checkContractsDir(File file) throws Exception { 57 | if(!file.isDirectory() || file.listFiles().length == 0){ 58 | throw new ScaffoldException("contracts directory must not be empty : " + file.getName()); 59 | } 60 | for (File solFile : file.listFiles()) { 61 | if(!solFile.getName().endsWith(".sol")){ 62 | throw new ScaffoldException(solFile.getName() + " is not contract file"); 63 | } 64 | } 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/DirectoryArtifact.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.exception.ScaffoldException; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * 10 | * @author aaronchu 11 | * @Description 12 | * @data 2021/01/15 13 | */ 14 | public abstract class DirectoryArtifact implements Artifact { 15 | 16 | protected File parentDir; 17 | 18 | public DirectoryArtifact(File parentDir){ 19 | this.parentDir = parentDir; 20 | } 21 | 22 | @Override 23 | public final void generate() throws Exception { 24 | File f = this.toFile(); 25 | if(!f.mkdirs()){ 26 | throw new ScaffoldException(f.getAbsolutePath() + " directory has exist"); 27 | } 28 | this.doGenerateSubContents(); 29 | } 30 | 31 | protected abstract void doGenerateSubContents() throws Exception; 32 | 33 | @Override 34 | public final boolean isDirectory() { 35 | return true; 36 | } 37 | 38 | @Override 39 | public final File getParentDir(){ 40 | return this.parentDir; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/GradleDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.config.UserConfig; 4 | import com.webank.scaffold.constants.DirNameConstants; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | import org.apache.commons.io.FileUtils; 9 | import org.apache.commons.io.IOUtils; 10 | 11 | import java.io.File; 12 | import java.io.FileOutputStream; 13 | import java.io.InputStream; 14 | import java.io.OutputStream; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | /** 19 | * @author aaronchu 20 | * @Description 21 | * @data 2021/04/06 22 | */ 23 | public class GradleDir extends DirectoryArtifact { 24 | 25 | private UserConfig config; 26 | 27 | public GradleDir(File parentDir, UserConfig config) { 28 | super(parentDir); 29 | this.config = config; 30 | } 31 | 32 | @Override 33 | protected void doGenerateSubContents() throws Exception { 34 | /** 35 | * 1. Create gradle wrapper directory 36 | */ 37 | File wrapperDir = new File(this.toFile(), "wrapper"); 38 | wrapperDir.mkdirs(); 39 | 40 | /** 41 | * 2. Copy gradle wrapper jar 42 | */ 43 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 44 | try(InputStream jarIn = classLoader.getResourceAsStream(FileNameConstants.TEMPLATE_GRADLE_WRAPPER_JAR); 45 | OutputStream jarOut = new FileOutputStream(new File(wrapperDir, FileNameConstants.GRADLE_WRAPPER_JAR)) 46 | ){ 47 | IOUtils.copy(jarIn, jarOut); 48 | } 49 | 50 | /** 51 | * 3. Generate gradle properties file 52 | */ 53 | Map map = new HashMap<>(); 54 | map.put(ReplaceConstants.GRADLE, config.getGradle()); 55 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_GRADLE_WRAPPER_PROPERTIES, map, new File(wrapperDir, FileNameConstants.GRADLE_WRAPPER_PROPERTIES)); 56 | } 57 | 58 | @Override 59 | public String getName() { 60 | return DirNameConstants.GRADLE; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/MainDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.config.UserConfig; 4 | import com.webank.scaffold.constants.DirNameConstants; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @data 2021/01/19 12 | */ 13 | public class MainDir extends DirectoryArtifact { 14 | 15 | private UserConfig config; 16 | 17 | public MainDir(File parentPath, UserConfig config) { 18 | super(parentPath); 19 | this.config = config; 20 | } 21 | 22 | /** 23 | * Generate sub directories: contracts,abi,bin,smbin,java 24 | * @throws Exception 25 | */ 26 | @Override 27 | protected void doGenerateSubContents() throws Exception { 28 | 29 | // process contracts dir 30 | ContractsDir contractsDir = new ContractsDir(this.toFile(), config); 31 | contractsDir.generate(); 32 | 33 | // process resource dir 34 | MainResourceDir resources = new MainResourceDir(this.toFile(), config); 35 | resources.generate(); 36 | 37 | // process java code dir 38 | MainJavaDir javas = new MainJavaDir(this.toFile(), resources.getAbiDir(), this.config); 39 | javas.generate(); 40 | } 41 | 42 | @Override 43 | public String getName() { 44 | return DirNameConstants.MAIN_DIR; 45 | } 46 | 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/MainJavaDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | import com.webank.scaffold.artifact.file.BcosConfigJava; 7 | import com.webank.scaffold.builder.*; 8 | import org.apache.commons.io.FileUtils; 9 | 10 | import com.webank.scaffold.artifact.file.ApplicationJava; 11 | import com.webank.scaffold.artifact.file.CommonResponseJava; 12 | import com.webank.scaffold.artifact.file.SdkBeanConfigJava; 13 | import com.webank.scaffold.config.UserConfig; 14 | import com.webank.scaffold.constants.DirNameConstants; 15 | import com.webank.scaffold.constants.FileNameConstants; 16 | import com.webank.scaffold.util.ABIUtil; 17 | import com.webank.scaffold.util.IOUtil; 18 | 19 | /** 20 | * @author aaronchu 21 | * @author grayson 22 | * @Description 23 | * @data 2021/03/02 24 | */ 25 | public class MainJavaDir extends DirectoryArtifact { 26 | 27 | private File abiDir; 28 | private UserConfig config; 29 | 30 | public MainJavaDir(File parentDir, File abi, UserConfig config) { 31 | super(parentDir); 32 | this.abiDir = abi; 33 | this.config = config; 34 | } 35 | 36 | @Override 37 | protected void doGenerateSubContents() throws Exception { 38 | handleUtil(); 39 | handleSystemConfig(); 40 | handleBcosConfig(); 41 | handleContractConfig(); 42 | handleContractConstants(); 43 | handleBOAndService(); 44 | handleApplication(); 45 | handleSdkBeanConfig(); 46 | handleCommonResponse(); 47 | } 48 | 49 | private void handleContractConstants() throws Exception{ 50 | List contractList = ABIUtil.contracts(abiDir, this.config.getNeed()); 51 | ContractConstantsBuilder constantsBuilder = new ContractConstantsBuilder(this.config, contractList); 52 | File javaDir = this.toFile(); 53 | constantsBuilder.generateJavaFile(FileNameConstants.CONSTANT_PKG_POSTFIX, javaDir); 54 | } 55 | 56 | private void handleApplication() throws Exception{ 57 | String pkg = config.getGroup() + "." + config.getArtifact(); 58 | ApplicationJava applicationJava = new ApplicationJava(IOUtil.convertPackageToFile(this.toFile(),pkg), config); 59 | applicationJava.generate(); 60 | } 61 | 62 | private void handleUtil() throws Exception{ 63 | //hook 64 | } 65 | 66 | private void handleBOAndService() throws Exception{ 67 | File javaDir = this.toFile(); 68 | List contractList = ABIUtil.contracts(abiDir, this.config.getNeed()); 69 | for(String contractName :contractList){ 70 | File abiFile = new File(abiDir, contractName + FileNameConstants.ABI_FILE_POSTFIX); 71 | String abiStr = FileUtils.readFileToString(abiFile); 72 | 73 | // create constructor bo 74 | ConstructorBoFileBuilder cbBuilder = new ConstructorBoFileBuilder(contractName, abiStr, this.config); 75 | cbBuilder.generateJavaFile(FileNameConstants.BO_PKG_POSTFIX, javaDir); 76 | 77 | // create struct bo 78 | StructsFileBuilder structsBuilder = new StructsFileBuilder(abiStr, this.config); 79 | structsBuilder.generateJavaFile(FileNameConstants.BO_PKG_POSTFIX, javaDir); 80 | 81 | // create function bo 82 | FunctionBoFileBuilder fbBuilder = new FunctionBoFileBuilder(contractName, abiStr, this.config); 83 | fbBuilder.generateJavaFile(FileNameConstants.BO_PKG_POSTFIX, javaDir); 84 | 85 | //Build service 86 | ServiceFileBuilder sfBuilder = new ServiceFileBuilder(contractName, abiStr, this.config); 87 | sfBuilder.generateJavaFile(FileNameConstants.SERVICE_PKG_POSTFIX, javaDir); 88 | } 89 | } 90 | 91 | private void handleSystemConfig() throws Exception { 92 | SystemConfigBuilder systemConfigBuilder = new SystemConfigBuilder(config); 93 | systemConfigBuilder.generateJavaFile(FileNameConstants.CONFIG_PKG_POSTFIX, this.toFile()); 94 | } 95 | 96 | private void handleBcosConfig() throws Exception { 97 | String configPackage = config.getGroup() + "." + config.getArtifact() + FileNameConstants.CONFIG_PKG_POSTFIX;; 98 | BcosConfigJava bcosConfigJava = new BcosConfigJava(IOUtil.convertPackageToFile(this.toFile(),configPackage), config); 99 | bcosConfigJava.generate(); 100 | } 101 | 102 | private void handleContractConfig() throws Exception { 103 | List contracts = ABIUtil.contracts(this.abiDir, this.config.getNeed()); 104 | ContractConfigBuilder contractConfigBuilder = new ContractConfigBuilder(config, contracts); 105 | contractConfigBuilder.generateJavaFile(FileNameConstants.CONFIG_PKG_POSTFIX, this.toFile()); 106 | } 107 | 108 | private void handleSdkBeanConfig() throws Exception{ 109 | String configPackage = config.getGroup() + "." + config.getArtifact() + FileNameConstants.CONFIG_PKG_POSTFIX;; 110 | SdkBeanConfigJava sdkBeanConfigJava = new SdkBeanConfigJava(IOUtil.convertPackageToFile(this.toFile(),configPackage), config); 111 | sdkBeanConfigJava.generate(); 112 | } 113 | 114 | private void handleCommonResponse() throws Exception{ 115 | String utilsPackage = config.getGroup() + "." + config.getArtifact() + FileNameConstants.MODEL_FILE_POSTFIX;; 116 | CommonResponseJava commonResponseJava = new CommonResponseJava(IOUtil.convertPackageToFile(this.toFile(),utilsPackage), config); 117 | commonResponseJava.generate(); 118 | } 119 | 120 | @Override 121 | public String getName() { 122 | return DirNameConstants.JAVA_DIR; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/MainResourceDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import java.io.File; 4 | 5 | import com.webank.scaffold.artifact.file.ApplicationProperties; 6 | import com.webank.scaffold.compiler.ContractCompiler; 7 | import com.webank.scaffold.config.UserConfig; 8 | import com.webank.scaffold.constants.DirNameConstants; 9 | import com.webank.scaffold.util.ABIUtil; 10 | 11 | /** 12 | * 13 | * @author aaronchu 14 | * @Description 15 | * @data 2021/03/02 16 | */ 17 | public class MainResourceDir extends DirectoryArtifact { 18 | 19 | private UserConfig config; 20 | private File abiDir; 21 | 22 | public MainResourceDir(File parentDir, UserConfig config) { 23 | super(parentDir); 24 | this.config = config; 25 | this.abiDir = new File(this.toFile(), DirNameConstants.ABI_DIR); 26 | } 27 | 28 | @Override 29 | protected void doGenerateSubContents() throws Exception { 30 | 31 | //1. create Abi And Bin 32 | ContractCompiler compiler = new ContractCompiler(this.toFile(), new File(this.config.getSolidityDir())); 33 | compiler.compile(); 34 | 35 | //2. create conf file 36 | ConfDir confDir = new ConfDir(this.toFile()); 37 | confDir.generate(); 38 | 39 | //3. create Application.properties 40 | ApplicationProperties applicationProperties = new ApplicationProperties( 41 | this.toFile(), 42 | ABIUtil.contracts(new File(this.toFile(), DirNameConstants.ABI_DIR), this.config.getNeed())); 43 | applicationProperties.generate(); 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return DirNameConstants.RESOURCE; 49 | } 50 | 51 | /** 52 | * @return the config 53 | */ 54 | public UserConfig getConfig() { 55 | return config; 56 | } 57 | 58 | /** 59 | * @param config the config to set 60 | */ 61 | public void setConfig(UserConfig config) { 62 | this.config = config; 63 | } 64 | 65 | /** 66 | * @return the abiDir 67 | */ 68 | public File getAbiDir() { 69 | return abiDir; 70 | } 71 | 72 | /** 73 | * @param abiDir the abiDir to set 74 | */ 75 | public void setAbiDir(File abiDir) { 76 | this.abiDir = abiDir; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/RootDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | 8 | import com.webank.scaffold.artifact.file.BuildGradle; 9 | import com.webank.scaffold.artifact.file.SettingsGradle; 10 | import com.webank.scaffold.config.UserConfig; 11 | 12 | /** 13 | * @author aaronchu 14 | * @author grayson 15 | * @Description 16 | * @data 2021/01/19 17 | */ 18 | public class RootDir extends DirectoryArtifact { 19 | 20 | private UserConfig config; 21 | 22 | public RootDir(File basePath, UserConfig config) { 23 | super(basePath); 24 | this.config = config; 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return this.config.getArtifact(); 30 | } 31 | 32 | @Override 33 | public void doGenerateSubContents() throws Exception { 34 | 35 | SrcDir srcDir = new SrcDir(this.toFile(), config); 36 | srcDir.generate(); 37 | 38 | BuildGradle buildGradle = new BuildGradle(this.toFile(), config); 39 | buildGradle.generate(); 40 | 41 | SettingsGradle settingsGradle = new SettingsGradle(this.toFile(), config); 42 | settingsGradle.generate(); 43 | 44 | GradleDir gradle = new GradleDir(this.toFile(), this.config); 45 | gradle.generate(); 46 | } 47 | 48 | public void clean() throws IOException { 49 | FileUtils.forceDelete(this.toFile()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/SrcDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.config.UserConfig; 4 | import com.webank.scaffold.constants.DirNameConstants; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @data 2021/01/19 12 | */ 13 | public class SrcDir extends DirectoryArtifact { 14 | 15 | private UserConfig config; 16 | 17 | public SrcDir(File parentPath, UserConfig config) { 18 | super(parentPath); 19 | this.config = config; 20 | } 21 | 22 | @Override 23 | protected void doGenerateSubContents() throws Exception { 24 | 25 | MainDir mainDir = new MainDir(this.toFile(), config); 26 | mainDir.generate(); 27 | 28 | TestDir testDir = new TestDir(this.toFile(), config); 29 | testDir.generate(); 30 | } 31 | 32 | @Override 33 | public String getName() { 34 | return DirNameConstants.SRC_DIR; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/TestDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.config.UserConfig; 4 | 5 | import java.io.File; 6 | 7 | /** 8 | * @author aaronchu 9 | * @Description 10 | * @data 2021/01/20 11 | */ 12 | public class TestDir extends DirectoryArtifact { 13 | 14 | private UserConfig config; 15 | 16 | public TestDir(File parentDir, UserConfig config) { 17 | super(parentDir); 18 | this.config = config; 19 | } 20 | 21 | @Override 22 | protected void doGenerateSubContents() throws Exception { 23 | TestJavaDir testJavaDir = new TestJavaDir(this.toFile(), this.config); 24 | testJavaDir.generate(); 25 | } 26 | 27 | @Override 28 | public String getName() { 29 | return "test"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/TestJavaDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir; 2 | 3 | import com.webank.scaffold.artifact.file.DemosTestJava; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.util.IOUtil; 6 | 7 | import java.io.File; 8 | 9 | /** 10 | * @author aaronchu 11 | * @Description 12 | * @data 2021/01/20 13 | */ 14 | public class TestJavaDir extends DirectoryArtifact { 15 | 16 | private UserConfig config; 17 | 18 | public TestJavaDir(File parentDir, UserConfig userConfig) { 19 | super(parentDir); 20 | this.config = userConfig; 21 | } 22 | 23 | @Override 24 | protected void doGenerateSubContents() throws Exception { 25 | /** 26 | * 1. Build sub directory due to package name 27 | */ 28 | handleDemos(); 29 | } 30 | 31 | @Override 32 | public String getName() { 33 | return "java"; 34 | } 35 | 36 | private void handleDemos() throws Exception{ 37 | File javaDir = this.toFile(); 38 | String utilsPackage = config.getGroup() + "." + config.getArtifact(); 39 | DemosTestJava demosTestJava = new DemosTestJava(IOUtil.convertPackageToFile(javaDir,utilsPackage), config); 40 | demosTestJava.generate(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/root/GradleRootDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir.root; 2 | 3 | import com.webank.scaffold.artifact.dir.GradleDir; 4 | import com.webank.scaffold.artifact.file.BuildGradle; 5 | import com.webank.scaffold.artifact.file.SettingsGradle; 6 | import com.webank.scaffold.config.UserConfig; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * @author aaronchu 12 | * @Description 13 | * @date 2021/08/10 14 | */ 15 | public class GradleRootDir extends RootDir { 16 | 17 | public GradleRootDir(File basePath, UserConfig config) { 18 | super(basePath, config); 19 | } 20 | 21 | @Override 22 | public void doGenerateSubContents() throws Exception { 23 | super.doGenerateSubContents(); 24 | 25 | BuildGradle buildGradle = new BuildGradle(this.toFile(), config); 26 | buildGradle.generate(); 27 | 28 | SettingsGradle settingsGradle = new SettingsGradle(this.toFile(), config); 29 | settingsGradle.generate(); 30 | 31 | GradleDir gradle = new GradleDir(this.toFile(), this.config); 32 | gradle.generate(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/root/MavenRootDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir.root; 2 | 3 | import com.webank.scaffold.artifact.file.BuildGradle; 4 | import com.webank.scaffold.artifact.file.Mvnw; 5 | import com.webank.scaffold.artifact.file.MvnwCmd; 6 | import com.webank.scaffold.artifact.file.Pom; 7 | import com.webank.scaffold.config.UserConfig; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * @author aaronchu 13 | * @Description 14 | * @date 2021/08/10 15 | */ 16 | public class MavenRootDir extends RootDir { 17 | 18 | public MavenRootDir(File basePath, UserConfig config) { 19 | super(basePath, config); 20 | } 21 | 22 | @Override 23 | public void doGenerateSubContents() throws Exception { 24 | super.doGenerateSubContents(); 25 | 26 | Pom pom = new Pom(this.toFile(), config); 27 | pom.generate(); 28 | 29 | Mvnw mvnw = new Mvnw(this.toFile(), config); 30 | mvnw.generate(); 31 | 32 | MvnwCmd mvnwCmd = new MvnwCmd(this.toFile(), config); 33 | mvnwCmd.generate(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/dir/root/RootDir.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.dir.root; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import com.webank.scaffold.artifact.dir.DirectoryArtifact; 7 | import com.webank.scaffold.artifact.dir.GradleDir; 8 | import com.webank.scaffold.artifact.dir.SrcDir; 9 | import org.apache.commons.io.FileUtils; 10 | 11 | import com.webank.scaffold.artifact.file.BuildGradle; 12 | import com.webank.scaffold.artifact.file.SettingsGradle; 13 | import com.webank.scaffold.config.UserConfig; 14 | 15 | /** 16 | * @author aaronchu 17 | * @author grayson 18 | * @Description 19 | * @data 2021/01/19 20 | */ 21 | public abstract class RootDir extends DirectoryArtifact { 22 | 23 | protected UserConfig config; 24 | 25 | public RootDir(File basePath, UserConfig config) { 26 | super(basePath); 27 | this.config = config; 28 | } 29 | 30 | @Override 31 | public String getName() { 32 | return this.config.getArtifact(); 33 | } 34 | 35 | @Override 36 | public void doGenerateSubContents() throws Exception { 37 | 38 | SrcDir srcDir = new SrcDir(this.toFile(), config); 39 | srcDir.generate(); 40 | } 41 | 42 | public void clean() throws IOException { 43 | FileUtils.forceDelete(this.toFile()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/ApplicationJava.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.ReplaceConstants; 6 | import com.webank.scaffold.constants.FileNameConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Author grayson 16 | * @Description 17 | * @data 2021/03/02 18 | */ 19 | public class ApplicationJava implements Artifact { 20 | 21 | private File parentDir; 22 | private UserConfig config; 23 | 24 | public ApplicationJava(File parent, UserConfig config){ 25 | this.parentDir = parent; 26 | this.config = config; 27 | } 28 | 29 | @Override 30 | public void generate() throws Exception { 31 | this.parentDir.mkdirs(); 32 | String pkg = config.getGroup() + "." + config.getArtifact(); 33 | Map map = new HashMap<>(); 34 | map.put(ReplaceConstants.PACKAGE, pkg); 35 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_APPLICATION, map, this.toFile()); 36 | } 37 | 38 | @Override 39 | public File getParentDir() { 40 | return this.parentDir; 41 | } 42 | 43 | @Override 44 | public String getName() { 45 | return FileNameConstants.APPLICATION_JAVA; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/ApplicationProperties.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.constants.FileNameConstants; 5 | import org.fisco.bcos.sdk.utils.StringUtils; 6 | 7 | import java.io.BufferedWriter; 8 | import java.io.File; 9 | import java.io.FileWriter; 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Description 16 | * @data 2021/03/02 17 | */ 18 | public class ApplicationProperties implements Artifact { 19 | 20 | private File parentDir; 21 | private List contracts; 22 | 23 | public ApplicationProperties(File parentDir, List contracts){ 24 | this.parentDir = parentDir; 25 | this.contracts = contracts; 26 | } 27 | 28 | @Override 29 | public void generate() throws Exception { 30 | try(BufferedWriter writer = new BufferedWriter(new FileWriter(this.toFile()))){ 31 | writeJavaSdkKeys(writer); 32 | writeSystemConfigKeys(writer); 33 | writeContractKeys(writer); 34 | writeSpringBootKeys(writer); 35 | writer.flush(); 36 | } 37 | } 38 | private void writeJavaSdkKeys(BufferedWriter writer) throws IOException { 39 | writer.write("### Java sdk configuration\n"); 40 | writer.write("cryptoMaterial.certPath=conf\n"); 41 | writer.write("network.peers[0]=127.0.0.1:20200\n"); 42 | writer.write("network.peers[1]=127.0.0.1:20201\n"); 43 | writer.newLine(); 44 | } 45 | 46 | private void writeSystemConfigKeys(BufferedWriter writer) throws IOException { 47 | writer.write("### System configuration\n"); 48 | writer.write("system.groupId=1\n"); 49 | writer.write("system.hexPrivateKey=\n"); 50 | writer.newLine(); 51 | } 52 | 53 | private void writeContractKeys(BufferedWriter writer) throws IOException { 54 | writer.write("### Contract configuration\n"); 55 | for(String contractName : contracts){ 56 | contractName = StringUtils.lowercaseFirstLetter(contractName); 57 | writer.write("contract."+contractName+"Address=\n"); 58 | } 59 | writer.newLine(); 60 | } 61 | 62 | private void writeSpringBootKeys(BufferedWriter writer) throws IOException { 63 | writer.write("### Springboot configuration\n"); 64 | writer.write("server.port=8080\n"); 65 | writer.write("server.session.timeout=60\n"); 66 | writer.write("banner.charset=UTF-8\n"); 67 | writer.write("spring.jackson.date-format=yyyy-MM-dd HH:mm:ss\n"); 68 | writer.write("spring.jackson.time-zone=GMT+8\n"); 69 | writer.newLine(); 70 | } 71 | 72 | @Override 73 | public File getParentDir() { 74 | return this.parentDir; 75 | } 76 | 77 | @Override 78 | public String getName() { 79 | return FileNameConstants.APP_PRO; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/BcosConfigJava.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Description 16 | * @data 2021/05/13 17 | */ 18 | public class BcosConfigJava implements Artifact { 19 | 20 | private File parentDir; 21 | private UserConfig config; 22 | 23 | public BcosConfigJava(File parentDir, UserConfig config){ 24 | this.parentDir = parentDir; 25 | this.config = config; 26 | } 27 | @Override 28 | public void generate() throws Exception { 29 | this.parentDir.mkdirs(); 30 | String pkg = config.getGroup() + "." + config.getArtifact()+ ".config"; 31 | Map map = new HashMap<>(); 32 | map.put(ReplaceConstants.PACKAGE, pkg); 33 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_BCOS_CONFIG, map, this.toFile()); 34 | } 35 | 36 | @Override 37 | public File getParentDir() { 38 | return parentDir; 39 | } 40 | 41 | @Override 42 | public String getName() { 43 | return FileNameConstants.BCOS_CONFIG; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/BuildGradle.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.ReplaceConstants; 6 | import com.webank.scaffold.constants.FileNameConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * Generate build.gradle file 15 | * @author aaronchu 16 | * @author grayson 17 | * @Description 18 | * @data 2021/01/15 19 | */ 20 | public class BuildGradle implements Artifact { 21 | 22 | private File parent; 23 | private UserConfig config; 24 | 25 | public BuildGradle(File parent, UserConfig config){ 26 | this.parent = parent; 27 | this.config = config; 28 | } 29 | 30 | @Override 31 | public void generate() throws Exception { 32 | Map map = new HashMap<>(); 33 | map.put(ReplaceConstants.GENERATOR_GROUP, config.getGroup()); 34 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_BUILD_GRADLE, map, this.toFile()); 35 | } 36 | 37 | @Override 38 | public File getParentDir() { 39 | return this.parent; 40 | } 41 | 42 | @Override 43 | public String getName() { 44 | return FileNameConstants.BUILD_GRADLE_FILE; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/CommonResponseJava.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class CommonResponseJava implements Artifact { 14 | 15 | private File parentDir; 16 | private UserConfig config; 17 | 18 | public CommonResponseJava(File parentDir, UserConfig config){ 19 | this.parentDir = parentDir; 20 | this.config = config; 21 | } 22 | 23 | @Override 24 | public void generate() throws Exception { 25 | this.parentDir.mkdirs(); 26 | String pkg = config.getGroup() + "." + config.getArtifact() + ".model"; 27 | Map map = new HashMap<>(); 28 | map.put(ReplaceConstants.PACKAGE, pkg); 29 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_COMMONRESPONSE, map, this.toFile()); 30 | } 31 | 32 | @Override 33 | public File getParentDir() { 34 | return parentDir; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return FileNameConstants.COMMON_RESPONSE_JAVA; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/DemosTestJava.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | public class DemosTestJava implements Artifact { 14 | 15 | private File parentDir; 16 | private UserConfig config; 17 | 18 | public DemosTestJava(File parentDir, UserConfig config){ 19 | this.parentDir = parentDir; 20 | this.config = config; 21 | } 22 | 23 | @Override 24 | public void generate() throws Exception { 25 | this.parentDir.mkdirs(); 26 | String pkg = config.getGroup() + "." + config.getArtifact(); 27 | Map map = new HashMap<>(); 28 | map.put(ReplaceConstants.PACKAGE, pkg); 29 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_DEMOS, map, this.toFile()); 30 | } 31 | 32 | @Override 33 | public File getParentDir() { 34 | return parentDir; 35 | } 36 | 37 | @Override 38 | public String getName() { 39 | return FileNameConstants.DEMOS_JAVA; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/Mvnw.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Description 16 | * @date 2021/08/10 17 | */ 18 | public class Mvnw implements Artifact { 19 | 20 | private File parent; 21 | private UserConfig config; 22 | 23 | public Mvnw(File parent, UserConfig config){ 24 | this.parent = parent; 25 | this.config = config; 26 | } 27 | 28 | @Override 29 | public void generate() throws Exception { 30 | Map map = new HashMap<>(); 31 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_MVNW, map, this.toFile()); 32 | } 33 | 34 | @Override 35 | public File getParentDir() { 36 | return this.parent; 37 | } 38 | 39 | @Override 40 | public String getName() { 41 | return FileNameConstants.MVNW_FILE; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/MvnwCmd.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.util.IOUtil; 7 | 8 | import java.io.File; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author aaronchu 14 | * @Description 15 | * @date 2021/08/10 16 | */ 17 | public class MvnwCmd implements Artifact { 18 | 19 | private File parent; 20 | private UserConfig config; 21 | 22 | public MvnwCmd(File parent, UserConfig config){ 23 | this.parent = parent; 24 | this.config = config; 25 | } 26 | 27 | @Override 28 | public void generate() throws Exception { 29 | Map map = new HashMap<>(); 30 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_MVNW_CMD, map, this.toFile()); 31 | } 32 | 33 | @Override 34 | public File getParentDir() { 35 | return this.parent; 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return FileNameConstants.MVNW_CMD_FILE; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/Pom.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Description 16 | * @date 2021/08/10 17 | */ 18 | public class Pom implements Artifact { 19 | private File parent; 20 | private UserConfig config; 21 | 22 | public Pom(File parent, UserConfig config){ 23 | this.parent = parent; 24 | this.config = config; 25 | } 26 | 27 | @Override 28 | public void generate() throws Exception { 29 | Map map = new HashMap<>(); 30 | map.put(ReplaceConstants.GENERATOR_GROUP, config.getGroup()); 31 | map.put(ReplaceConstants.GENERATOR_ARTIFACT, config.getArtifact()); 32 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_POM, map, this.toFile()); 33 | } 34 | 35 | @Override 36 | public File getParentDir() { 37 | return this.parent; 38 | } 39 | 40 | @Override 41 | public String getName() { 42 | return FileNameConstants.POM_FILE; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/SdkBeanConfigJava.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import com.webank.scaffold.constants.ReplaceConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @Description 16 | * @data 2021/03/03 17 | */ 18 | public class SdkBeanConfigJava implements Artifact { 19 | 20 | private File parentDir; 21 | private UserConfig config; 22 | 23 | public SdkBeanConfigJava(File parentDir, UserConfig config){ 24 | this.parentDir = parentDir; 25 | this.config = config; 26 | } 27 | 28 | @Override 29 | public void generate() throws Exception { 30 | this.parentDir.mkdirs(); 31 | String pkg = config.getGroup() + "." + config.getArtifact() + ".config"; 32 | Map map = new HashMap<>(); 33 | map.put(ReplaceConstants.PACKAGE, pkg); 34 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_SDK_CONFIG, map, this.toFile()); 35 | } 36 | 37 | @Override 38 | public File getParentDir() { 39 | return parentDir; 40 | } 41 | 42 | @Override 43 | public String getName() { 44 | return FileNameConstants.SDK_CONFIG; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/artifact/file/SettingsGradle.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.artifact.file; 2 | 3 | import com.webank.scaffold.artifact.Artifact; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.ReplaceConstants; 6 | import com.webank.scaffold.constants.FileNameConstants; 7 | import com.webank.scaffold.util.IOUtil; 8 | 9 | import java.io.File; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author aaronchu 15 | * @author grayson 16 | * @Description 17 | * @data 2021/02/24 18 | */ 19 | public class SettingsGradle implements Artifact { 20 | 21 | private File parent; 22 | private UserConfig config; 23 | 24 | public SettingsGradle(File parent, UserConfig config){ 25 | this.parent = parent; 26 | this.config = config; 27 | } 28 | 29 | @Override 30 | public void generate() throws Exception { 31 | Map map = new HashMap<>(); 32 | map.put(ReplaceConstants.GENERATOR_ARTIFACT, config.getArtifact()); 33 | IOUtil.replaceAllStr(FileNameConstants.TEMPLATE_SETTING_GRADLE, map, this.toFile()); 34 | } 35 | 36 | @Override 37 | public File getParentDir() { 38 | return this.parent; 39 | } 40 | 41 | @Override 42 | public String getName() { 43 | return FileNameConstants.SETTINGS_GRADLE_FILE; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/ConstructorBoFileBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.builder; 17 | 18 | import com.squareup.javapoet.TypeSpec; 19 | import com.webank.scaffold.config.UserConfig; 20 | import com.webank.scaffold.constants.FileNameConstants; 21 | import com.webank.scaffold.util.ABIUtil; 22 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 23 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinitionFactory; 24 | import org.fisco.bcos.sdk.abi.wrapper.ContractABIDefinition; 25 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 26 | 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | /** 31 | * BoFileHandler 32 | * 33 | * @Description: 34 | * @Author: grayson 35 | * @Version 1.0 36 | * @Date: 2021-04-08 10:47 37 | **/ 38 | public class ConstructorBoFileBuilder implements JavaFileBuilder { 39 | 40 | private String contractName; 41 | private String abiStr; 42 | private UserConfig config; 43 | 44 | public ConstructorBoFileBuilder(String contractName, String abiStr, UserConfig config){ 45 | this.contractName = contractName; 46 | this.abiStr = abiStr; 47 | this.config = config; 48 | } 49 | 50 | @Override 51 | public String getJavaFilePackage(String relativePackage) { 52 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 53 | } 54 | 55 | @Override 56 | public List buildTypeSpec(String fullPkg) { 57 | 58 | // 1.Get Constructor ABIDefinition 59 | ABIDefinitionFactory factory = new ABIDefinitionFactory(new CryptoSuite(0)); 60 | ContractABIDefinition rootAbi = factory.loadABI(abiStr); 61 | ABIDefinition constructorAbi = rootAbi.getConstructor(); 62 | 63 | // 2.Returns null if no constructor defined(this is the common case) 64 | if(constructorAbi == null || constructorAbi.getInputs().isEmpty()) return null; 65 | 66 | // 3.Build TypeSpec 67 | String className = this.contractName + FileNameConstants.CTOR; 68 | return Arrays.asList(ABIUtil.buildBOType(className, constructorAbi.getInputs())); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/ContractConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.builder; 17 | 18 | import com.squareup.javapoet.AnnotationSpec; 19 | import com.squareup.javapoet.ClassName; 20 | import com.squareup.javapoet.TypeSpec; 21 | import com.webank.scaffold.config.UserConfig; 22 | import com.webank.scaffold.constants.FileNameConstants; 23 | import lombok.Data; 24 | import org.fisco.bcos.sdk.utils.StringUtils; 25 | 26 | import javax.lang.model.element.Modifier; 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | /** 31 | * ContractConfigHander 32 | * 33 | * @Description: 34 | * @Author: grayson 35 | * @Version 1.0 36 | * @Date: 2021-04-08 09:33 37 | **/ 38 | public class ContractConfigBuilder implements JavaFileBuilder { 39 | 40 | private List contracts; 41 | private UserConfig config; 42 | 43 | public ContractConfigBuilder(UserConfig config, List contracts){ 44 | this.contracts = contracts; 45 | this.config = config; 46 | } 47 | 48 | @Override 49 | public String getJavaFilePackage(String relativePackage) { 50 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 51 | } 52 | 53 | @Override 54 | public List buildTypeSpec(String fullPkg) { 55 | //1. Basic initializations 56 | ClassName contractConfigClass = ClassName.get(fullPkg, FileNameConstants.CONTRACT_CONFIG); 57 | TypeSpec.Builder contractConfigBuilder = TypeSpec.classBuilder(contractConfigClass) 58 | .addModifiers(Modifier.PUBLIC) 59 | .addAnnotation(Data.class) 60 | .addAnnotation(ClassName.get("org.springframework.context.annotation","Configuration")) 61 | .addAnnotation( 62 | AnnotationSpec 63 | .builder(ClassName.get("org.springframework.boot.context.properties","ConfigurationProperties")) 64 | .addMember("prefix", "\"contract\"") 65 | .build()); 66 | 67 | //2. Populate contract fields 68 | for (String contract : this.contracts) { 69 | String fieldName = StringUtils.lowercaseFirstLetter(contract) +"Address"; 70 | contractConfigBuilder.addField(String.class, fieldName, Modifier.PRIVATE); 71 | } 72 | return Arrays.asList(contractConfigBuilder.build()); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/ContractConstantsBuilder.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.builder; 2 | 3 | import com.squareup.javapoet.*; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.DirNameConstants; 6 | import com.webank.scaffold.constants.FileNameConstants; 7 | 8 | import javax.lang.model.element.Modifier; 9 | import java.util.Arrays; 10 | import java.util.List; 11 | 12 | /** 13 | * @author aaronchu 14 | * @Description 15 | * @data 2021/05/12 16 | */ 17 | public class ContractConstantsBuilder implements JavaFileBuilder { 18 | 19 | private List contracts; 20 | private UserConfig config; 21 | 22 | 23 | public ContractConstantsBuilder(UserConfig config, List contracts){ 24 | this.contracts = contracts; 25 | this.config = config; 26 | } 27 | 28 | @Override 29 | public String getJavaFilePackage(String relativePackage) { 30 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 31 | } 32 | 33 | @Override 34 | public List buildTypeSpec(String fullPkg) { 35 | /** 36 | * 1. Create class header 37 | */ 38 | TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(ClassName.get(fullPkg, FileNameConstants.CONTRACT_CONSTANTS)) 39 | .addModifiers(Modifier.PUBLIC); 40 | 41 | /** 42 | * 2. Create fields 43 | */ 44 | for(String contract:contracts){ 45 | typeBuilder.addField(abiField(contract)); 46 | typeBuilder.addField(binaryField(contract)); 47 | typeBuilder.addField(gmBinaryField(contract)); 48 | } 49 | 50 | /** 51 | * 3. Static blocks for field initializers 52 | */ 53 | CodeBlock.Builder staticBlockBuilder = CodeBlock.builder() 54 | .beginControlFlow("try"); 55 | String readUtilFullName = 56 | "org.apache.commons.io.IOUtils.toString(Thread.currentThread().getContextClassLoader().getResource(\"$L/$L\"))"; 57 | for(String contract:contracts) { 58 | String abiFieldName = contract + FileNameConstants.ABI_POSTFIX; 59 | staticBlockBuilder.addStatement(abiFieldName + " = " + readUtilFullName, DirNameConstants.ABI_DIR, contract + ".abi"); 60 | String binFieldName = contract + FileNameConstants.BINARY_POSTFIX; 61 | staticBlockBuilder.addStatement(binFieldName + " = " + readUtilFullName, DirNameConstants.BIN_DIR, contract + ".bin"); 62 | String gmBinFieldName = contract + FileNameConstants.BINARY_GM_POSTFIX; 63 | staticBlockBuilder.addStatement(gmBinFieldName + " = " + readUtilFullName, DirNameConstants.SMBIN_DIR, contract + ".bin"); 64 | } 65 | 66 | staticBlockBuilder 67 | .nextControlFlow("catch ($T e)", Exception.class) 68 | .addStatement("throw new $T(e)", RuntimeException.class) 69 | .endControlFlow(); 70 | typeBuilder.addStaticBlock(staticBlockBuilder.build()); 71 | 72 | return Arrays.asList(typeBuilder.build()); 73 | } 74 | 75 | private FieldSpec abiField(String contract){ 76 | String fieldName = contract+FileNameConstants.ABI_POSTFIX; 77 | FieldSpec fieldSpec = FieldSpec.builder(String.class, fieldName, Modifier.PUBLIC, Modifier.STATIC).build(); 78 | return fieldSpec; 79 | } 80 | 81 | private FieldSpec binaryField(String contract){ 82 | String fieldName = contract+FileNameConstants.BINARY_POSTFIX; 83 | FieldSpec fieldSpec = FieldSpec.builder(String.class, fieldName, Modifier.PUBLIC, Modifier.STATIC).build(); 84 | return fieldSpec; 85 | } 86 | 87 | private FieldSpec gmBinaryField(String contract){ 88 | String fieldName = contract+FileNameConstants.BINARY_GM_POSTFIX; 89 | FieldSpec fieldSpec = FieldSpec.builder(String.class, fieldName, Modifier.PUBLIC, Modifier.STATIC).build(); 90 | return fieldSpec; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/FunctionBoFileBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.builder; 17 | 18 | import com.squareup.javapoet.TypeSpec; 19 | import com.webank.scaffold.config.UserConfig; 20 | import com.webank.scaffold.util.ABIUtil; 21 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * FunctionBoFileHandler 29 | * 30 | * @Description: 31 | * @Author: grayson 32 | * @Version 1.0 33 | * @Date: 2021-04-08 11:30 34 | **/ 35 | public class FunctionBoFileBuilder implements JavaFileBuilder { 36 | 37 | private String contractName; 38 | private String abiStr; 39 | private UserConfig config; 40 | 41 | public FunctionBoFileBuilder(String contractName, String abiStr, UserConfig config){ 42 | this.contractName = contractName; 43 | this.abiStr = abiStr; 44 | this.config = config; 45 | } 46 | 47 | @Override 48 | public String getJavaFilePackage(String relativePackage) { 49 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 50 | } 51 | 52 | @Override 53 | public List buildTypeSpec(String fullPkg) { 54 | Map result = ABIUtil.buildAbiDefAndTypeSpec(contractName,abiStr); 55 | return result.values().stream().collect(Collectors.toList()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/JavaFileBuilder.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.builder; 2 | 3 | import com.squareup.javapoet.JavaFile; 4 | import com.squareup.javapoet.TypeSpec; 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.List; 8 | 9 | public interface JavaFileBuilder { 10 | 11 | String getJavaFilePackage(String relativePackage); 12 | 13 | List buildTypeSpec(String fullPkg); 14 | 15 | default void generateJavaFile(String relativePackage, File rootFile) throws IOException { 16 | String pkg = getJavaFilePackage(relativePackage); 17 | List typeSpecs = buildTypeSpec(pkg); 18 | if(typeSpecs == null) return; 19 | for (TypeSpec typeSpec: typeSpecs) { 20 | if(typeSpec != null){ 21 | JavaFile file = JavaFile.builder(pkg, typeSpec).build(); 22 | file.writeTo(rootFile); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/ServiceFileBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.builder; 17 | 18 | import com.squareup.javapoet.TypeSpec; 19 | import com.webank.scaffold.config.UserConfig; 20 | import com.webank.scaffold.handler.ServicesHandler; 21 | import com.webank.scaffold.util.ABIUtil; 22 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 23 | 24 | import java.util.Arrays; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * ServiceFileHandler 30 | * 31 | * @Description: 32 | * @Author: grayson 33 | * @Version 1.0 34 | * @Date: 2021-04-08 15:44 35 | **/ 36 | public class ServiceFileBuilder implements JavaFileBuilder { 37 | 38 | private String contractName; 39 | private String abiStr; 40 | private UserConfig config; 41 | 42 | public ServiceFileBuilder(String contractName, String abiStr, UserConfig config){ 43 | this.contractName = contractName; 44 | this.abiStr = abiStr; 45 | this.config = config; 46 | } 47 | 48 | @Override 49 | public String getJavaFilePackage(String relativePackage) { 50 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 51 | } 52 | 53 | @Override 54 | public List buildTypeSpec(String fullPkg) { 55 | Map functions = ABIUtil.buildAbiDefAndTypeSpec(contractName, abiStr); 56 | ServicesHandler servicesHandler = new ServicesHandler(config); 57 | TypeSpec serviceType = servicesHandler.build(contractName, functions); 58 | return Arrays.asList(serviceType); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/StructsFileBuilder.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.builder; 2 | 3 | import com.squareup.javapoet.TypeSpec; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.handler.ContractHandler; 6 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 7 | import org.fisco.bcos.sdk.codegen.CodeGenUtils; 8 | 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Convert struct into bos 14 | * @author yuzhichu 15 | */ 16 | public class StructsFileBuilder implements JavaFileBuilder{ 17 | 18 | private UserConfig config; 19 | private ContractHandler handler; 20 | private List abis; 21 | 22 | public StructsFileBuilder(String abiStr, UserConfig config) throws Exception{ 23 | this.config = config; 24 | this.handler = new ContractHandler(); 25 | this.abis = CodeGenUtils.loadContractAbiDefinition(abiStr); 26 | } 27 | 28 | //private List buildStructTypes(List functionDefinitions) 29 | @Override 30 | public String getJavaFilePackage(String relativePackage) { 31 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 32 | } 33 | 34 | @Override 35 | public List buildTypeSpec(String fullPkg) { 36 | try{ 37 | return handler.buildStructTypes(abis); 38 | } 39 | catch (Exception ex){ 40 | throw new RuntimeException(ex); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/builder/SystemConfigBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.builder; 17 | 18 | import com.squareup.javapoet.*; 19 | import com.webank.scaffold.config.UserConfig; 20 | import com.webank.scaffold.constants.FileNameConstants; 21 | import lombok.Data; 22 | 23 | import javax.lang.model.element.Modifier; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | /** 28 | * SystemConfigBuilder 29 | * 30 | * @Description: 31 | * @Author: grayson 32 | * @Version 1.0 33 | * @Date: 2021-04-08 10:10 34 | **/ 35 | public class SystemConfigBuilder implements JavaFileBuilder { 36 | 37 | private UserConfig config; 38 | 39 | public SystemConfigBuilder(UserConfig config){ 40 | this.config = config; 41 | } 42 | 43 | @Override 44 | public String getJavaFilePackage(String relativePackage) { 45 | return config.getGroup() + "." + config.getArtifact() + relativePackage; 46 | } 47 | 48 | @Override 49 | public List buildTypeSpec(String fullPkg) { 50 | ClassName className = ClassName.get(fullPkg, FileNameConstants.SYSTEM_CONFIG); 51 | TypeSpec systemConfigBuilder = TypeSpec.classBuilder(className) 52 | .addModifiers(Modifier.PUBLIC) 53 | .addAnnotation(Data.class) 54 | .addAnnotation(ClassName.get("org.springframework.context.annotation","Configuration")) 55 | .addAnnotation( 56 | AnnotationSpec 57 | .builder(ClassName.get("org.springframework.boot.context.properties","ConfigurationProperties")) 58 | .addMember("prefix", "\"system\"") 59 | .build()) 60 | .addField( 61 | FieldSpec 62 | .builder( 63 | TypeName.INT, "groupId", Modifier.PRIVATE) 64 | .initializer("1") 65 | .build()) 66 | .addField( 67 | FieldSpec 68 | .builder( 69 | String.class, "hexPrivateKey", Modifier.PRIVATE) 70 | .build()) 71 | .build(); 72 | 73 | return Arrays.asList(systemConfigBuilder); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/cmd/ScaffoldRunner.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.cmd; 2 | 3 | 4 | import com.webank.scaffold.enums.ProjectType; 5 | import com.webank.scaffold.factory.ProjectFactory; 6 | import picocli.CommandLine; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @data 2021/01/20 12 | */ 13 | 14 | @CommandLine.Command(name = "ScaffoldRunner") 15 | public class ScaffoldRunner implements Runnable{ 16 | @CommandLine.Option(names = {"-s", "--sol"}, required = true, description = "Required. Solidity contracts dir.") 17 | private String solidityDir; 18 | 19 | @CommandLine.Option(names = {"-g", "--group"}, required = true,defaultValue = "org.example",description = "Optional. Group name.") 20 | private String group; 21 | 22 | @CommandLine.Option(names = {"-a", "--artifact"}, required = true, defaultValue = "demo",description = "Optional. Artifact name.") 23 | private String artifact; 24 | 25 | @CommandLine.Option(names = {"-o", "--output"},required = true, defaultValue = "artifacts",description = "Optional. Output directory.") 26 | private String output; 27 | 28 | @CommandLine.Option(names = {"-n", "--need"}, required = false,defaultValue = "",description = "Optional. The contracts you need,for example Contract1,Contract2,Contract3") 29 | private String need; 30 | 31 | @CommandLine.Option(names = {"-t", "--type"}, required = false,defaultValue = "gradle",description = "Optional. Project type.") 32 | private String projectType; 33 | 34 | @CommandLine.Option(names = {"-gv", "--gradle"}, required = false,defaultValue = "6.3",description = "Optional. Gradle version.") 35 | private String gradle; 36 | 37 | @Override 38 | public void run() { 39 | ProjectFactory factory = new ProjectFactory(group, artifact, solidityDir, output, need, projectType, gradle); 40 | factory.createProject(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/compiler/ContractCompiler.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.compiler; 2 | 3 | import com.webank.scaffold.constants.DirNameConstants; 4 | import com.webank.solc.plugin.compiler.CompileSolToJava; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * @author aaronchu 10 | * @Description 11 | * @data 2021/01/15 12 | */ 13 | public class ContractCompiler { 14 | 15 | private File output; 16 | private File solDir; 17 | 18 | public ContractCompiler(File output, File solDir){ 19 | this.output = output; 20 | this.solDir = solDir; 21 | } 22 | 23 | /** 24 | * Compile solidity and generates:abi、bin、smbin. 25 | * @throws Exception 26 | */ 27 | public void compile() throws Exception{ 28 | 29 | File abiDir = new File(this.output, DirNameConstants.ABI_DIR); 30 | File binDir = new File(this.output, DirNameConstants.BIN_DIR); 31 | File smBinDir = new File(this.output, DirNameConstants.SMBIN_DIR); 32 | 33 | CompileSolToJava compiler = new CompileSolToJava(); 34 | String solName = "";//Compile everything 35 | 36 | compiler.compileSolToJava( 37 | solName, 38 | null, 39 | solDir, 40 | abiDir, 41 | binDir, 42 | smBinDir, 43 | null 44 | ); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/config/UserConfig.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.config; 2 | 3 | import com.webank.scaffold.enums.ProjectType; 4 | 5 | /** 6 | * Config files for users 7 | * @author aaronchu 8 | * @Description 9 | * @data 2021/01/15 10 | */ 11 | 12 | public class UserConfig{ 13 | 14 | private String group; 15 | private String artifact; 16 | private String solidityDir; 17 | private String outputDir; 18 | private String need; 19 | private String gradle; 20 | private ProjectType projectType; 21 | 22 | public String getGradle() { 23 | return gradle; 24 | } 25 | 26 | private UserConfig(){} 27 | 28 | public static UserConfig getInstance(String group, String artifact, String solidityDir, String outputDir, String need, ProjectType projectType, String gradle){ 29 | 30 | UserConfig config = new UserConfig(); 31 | config.setGroup(group); 32 | config.setArtifact(artifact); 33 | config.setSolidityDir(solidityDir); 34 | config.setOutputDir(outputDir); 35 | config.setNeed(need); 36 | config.setGradle(gradle); 37 | config.setProjectType(projectType); 38 | return config; 39 | } 40 | 41 | private void setGradle(String gradle) { 42 | this.gradle = gradle; 43 | } 44 | 45 | /** 46 | * @return the group 47 | */ 48 | public String getGroup() { 49 | return group; 50 | } 51 | 52 | /** 53 | * @param group the group to set 54 | */ 55 | public void setGroup(String group) { 56 | this.group = group; 57 | } 58 | 59 | /** 60 | * @return the artifact 61 | */ 62 | public String getArtifact() { 63 | return artifact; 64 | } 65 | 66 | /** 67 | * @param artifact the artifact to set 68 | */ 69 | public void setArtifact(String artifact) { 70 | this.artifact = artifact; 71 | } 72 | 73 | /** 74 | * @return the solidityDir 75 | */ 76 | public String getSolidityDir() { 77 | return solidityDir; 78 | } 79 | 80 | /** 81 | * @param solidityDir the solidityDir to set 82 | */ 83 | public void setSolidityDir(String solidityDir) { 84 | this.solidityDir = solidityDir; 85 | } 86 | 87 | /** 88 | * @return the outputDir 89 | */ 90 | public String getOutputDir() { 91 | return outputDir; 92 | } 93 | 94 | /** 95 | * @param outputDir the outputDir to set 96 | */ 97 | public void setOutputDir(String outputDir) { 98 | this.outputDir = outputDir; 99 | } 100 | 101 | /** 102 | * @return the need 103 | */ 104 | public String getNeed() { 105 | return need; 106 | } 107 | 108 | /** 109 | * @param need the need to set 110 | */ 111 | public void setNeed(String need) { 112 | this.need = need; 113 | } 114 | 115 | 116 | public ProjectType getProjectType() { 117 | return projectType; 118 | } 119 | 120 | public void setProjectType(ProjectType projectType) { 121 | this.projectType = projectType; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/constants/DirNameConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.constants; 17 | 18 | /** 19 | * DirNameConstants 20 | * 21 | * @Description: 22 | * @Author: grayson 23 | * @Version 1.0 24 | * @Date: 2021-04-07 14:41 25 | **/ 26 | public class DirNameConstants { 27 | 28 | public static final String ABI_DIR = "abi"; 29 | public static final String BIN_DIR = "bin/ecc"; 30 | public static final String SMBIN_DIR = "bin/sm"; 31 | 32 | public static final String RESOURCE = "resources"; 33 | public static final String GRADLE = "gradle"; 34 | public static final String CONF_DIR = "conf"; 35 | public static final String SOL_Dir = "contracts"; 36 | public static final String MAIN_DIR = "main"; 37 | public static final String SRC_DIR = "src"; 38 | public static final String JAVA_DIR = "java"; 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/constants/FileNameConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.constants; 17 | 18 | /** 19 | * FileNameConstants 20 | * 21 | * @Description: 22 | * @Author: grayson 23 | * @Version 1.0 24 | * @Date: 2021-04-07 15:59 25 | **/ 26 | public class FileNameConstants { 27 | 28 | public static final String TEMPLATE_POSTFIX = ".tpl"; 29 | 30 | //template file name 31 | public static final String TEMPLATE_BUILD_GRADLE = "templates/build.gradle" + TEMPLATE_POSTFIX; 32 | public static final String TEMPLATE_POM = "templates/pom.xml" + TEMPLATE_POSTFIX; 33 | public static final String TEMPLATE_SETTING_GRADLE = "templates/settings.gradle" + TEMPLATE_POSTFIX; 34 | public static final String TEMPLATE_MVNW = "templates/mvnw" + TEMPLATE_POSTFIX; 35 | public static final String TEMPLATE_MVNW_CMD = "templates/mvnw.cmd" + TEMPLATE_POSTFIX; 36 | public static final String TEMPLATE_APPLICATION = "templates/Application.java" + TEMPLATE_POSTFIX; 37 | public static final String TEMPLATE_COMMONRESPONSE = "templates/CommonResponse.java" + TEMPLATE_POSTFIX; 38 | public static final String TEMPLATE_DEMOS = "templates/Demos.java" + TEMPLATE_POSTFIX; 39 | public static final String TEMPLATE_SDK_CONFIG = "templates/SdkBeanConfig.java" + TEMPLATE_POSTFIX; 40 | public static final String TEMPLATE_GRADLE_WRAPPER_JAR = "templates/gradle/wrapper/gradle-wrapper.jar" + TEMPLATE_POSTFIX; 41 | public static final String TEMPLATE_GRADLE_WRAPPER_PROPERTIES = "templates/gradle/wrapper/gradle-wrapper.properties"+TEMPLATE_POSTFIX; 42 | public static final String TEMPLATE_BCOS_CONFIG = "templates/BcosConfig.java"+TEMPLATE_POSTFIX; 43 | 44 | //generated file name 45 | public static final String BUILD_GRADLE_FILE = "build.gradle"; 46 | public static final String POM_FILE = "pom.xml"; 47 | public static final String APP_PRO = "application.properties"; 48 | public static final String SETTINGS_GRADLE_FILE = "settings.gradle"; 49 | public static final String MVNW_FILE = "mvnw"; 50 | public static final String MVNW_CMD_FILE = "mvnw.cmd"; 51 | public static final String APPLICATION_JAVA = "Application.java"; 52 | public static final String COMMON_RESPONSE_JAVA = "CommonResponse.java"; 53 | public static final String DEMOS_JAVA = "Demos.java"; 54 | public static final String SDK_CONFIG = "SdkBeanConfig.java"; 55 | public static final String GRADLE_WRAPPER_JAR = "gradle-wrapper.jar"; 56 | public static final String GRADLE_WRAPPER_PROPERTIES = "gradle-wrapper.properties"; 57 | public static final String BCOS_CONFIG = "BcosConfig.java"; 58 | public static final String SYSTEM_CONFIG = "SystemConfig"; 59 | 60 | public static final String CONTRACT_CONFIG = "ContractConfig"; 61 | public static final String CONTRACT_CONSTANTS = "ContractConstants"; 62 | 63 | //package or file postfix 64 | public static final String CONFIG_PKG_POSTFIX = ".config"; 65 | public static final String UTILS_PKG_POSTFIX = ".utils"; 66 | public static final String ABI_FILE_POSTFIX = ".abi"; 67 | public static final String MODEL_FILE_POSTFIX = ".model"; 68 | public static final String BO_PKG_POSTFIX = ".model.bo"; 69 | public static final String SERVICE_PKG_POSTFIX = ".service"; 70 | public static final String CONSTANT_PKG_POSTFIX = ".constants"; 71 | 72 | public final static String CTOR = "CtorBO"; 73 | public final static String INPUT = "InputBO"; 74 | public final static String ABI_POSTFIX = "Abi"; 75 | public final static String BINARY_POSTFIX = "Binary"; 76 | public final static String BINARY_GM_POSTFIX = "GmBinary"; 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/constants/ReplaceConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.constants; 17 | 18 | /** 19 | * ConfigOptConstants 20 | * 21 | * @Description: 22 | * @Author: grayson 23 | * @Version 1.0 24 | * @Date: 2021-04-06 18:53 25 | **/ 26 | public class ReplaceConstants { 27 | 28 | public static String GENERATOR_ARTIFACT = "generator.artifact"; 29 | public static String GENERATOR_GROUP = "generator.group"; 30 | public static String PACKAGE = "package"; 31 | public static String GRADLE = "gradle"; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/enums/ProjectType.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.enums; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * @author aaronchu 7 | * @Description 8 | * @date 2021/08/10 9 | */ 10 | 11 | public enum ProjectType { 12 | Gradle("gradle"), 13 | 14 | Maven("maven"); 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | 20 | private String name; 21 | 22 | ProjectType(String name){ 23 | this.name = name; 24 | } 25 | 26 | public static ProjectType nameOf(String projectType) { 27 | for(ProjectType projectTypeEnum:ProjectType.values()){ 28 | if(projectTypeEnum.getName().equals(projectType.toLowerCase())){ 29 | return projectTypeEnum; 30 | } 31 | } 32 | return null; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/exception/ScaffoldException.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.exception; 2 | 3 | /** 4 | * @author aaronchu 5 | * @Description 6 | * @data 2021/01/20 7 | */ 8 | public class ScaffoldException extends RuntimeException{ 9 | 10 | /** @Fields serialVersionUID : TODO */ 11 | private static final long serialVersionUID = -4165654620608938012L; 12 | 13 | public ScaffoldException(Exception error){ 14 | super(error); 15 | } 16 | 17 | public ScaffoldException(String message){ 18 | super(message); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/factory/ProjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.factory; 2 | 3 | import com.webank.scaffold.artifact.dir.root.GradleRootDir; 4 | import com.webank.scaffold.artifact.dir.root.MavenRootDir; 5 | import com.webank.scaffold.artifact.dir.root.RootDir; 6 | import com.webank.scaffold.config.UserConfig; 7 | import com.webank.scaffold.enums.ProjectType; 8 | import com.webank.scaffold.exception.ScaffoldException; 9 | import java.io.File; 10 | 11 | /** 12 | * @author aaronchu 13 | * @author grayson 14 | * @Description 15 | * @data 2021/01/20 16 | */ 17 | public class ProjectFactory { 18 | 19 | 20 | private UserConfig config; 21 | 22 | public ProjectFactory(String group, String artifact, String solidityDir, String output, String need, String projectType, String gradle){ 23 | this.config = UserConfig.getInstance(group, artifact, solidityDir, output, need, ProjectType.nameOf(projectType), gradle); 24 | } 25 | 26 | public boolean createProject(){ 27 | //1. build project root object 28 | 29 | RootDir project = determineRootDir(config.getProjectType()); 30 | 31 | //2. create sub content in project 32 | try{ 33 | project.generate(); 34 | System.out.println("Project created:" + project.toFile()); 35 | } 36 | catch (Exception ex){ 37 | ex.printStackTrace(); 38 | 39 | // 3.Delete all project data in case of exception 40 | try{ 41 | project.clean(); 42 | } 43 | catch (Exception e){} 44 | } 45 | return true; 46 | } 47 | 48 | 49 | private RootDir determineRootDir(ProjectType projectType){ 50 | if(ProjectType.Gradle.equals(projectType)){ 51 | return new GradleRootDir(new File(config.getOutputDir()), config); 52 | } 53 | if(ProjectType.Maven.equals(projectType)){ 54 | return new MavenRootDir(new File(config.getOutputDir()), config); 55 | } 56 | throw new IllegalArgumentException("Invalid project type:"+projectType); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/handler/ServiceBeanConfigHandler.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.handler; 2 | 3 | import com.squareup.javapoet.*; 4 | import com.webank.scaffold.config.UserConfig; 5 | import com.webank.scaffold.constants.FileNameConstants; 6 | import lombok.Data; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.fisco.bcos.sdk.client.Client; 9 | import org.fisco.bcos.sdk.utils.StringUtils; 10 | 11 | import javax.lang.model.element.Modifier; 12 | import java.io.File; 13 | import java.util.List; 14 | 15 | /** 16 | * @author aaronchu 17 | * @Description 18 | * @data 2021/03/03 19 | */ 20 | public class ServiceBeanConfigHandler { 21 | private File javaRoot; 22 | private List contracts; 23 | private UserConfig config; 24 | 25 | public ServiceBeanConfigHandler(File javaRoot, List contracts, UserConfig config){ 26 | this.javaRoot = javaRoot; 27 | this.contracts = contracts; 28 | this.config = config; 29 | } 30 | 31 | public void export() throws Exception{ 32 | //1. Initializing 33 | String configPkg = config.getGroup() + "." + config.getArtifact() + ".config"; 34 | TypeSpec.Builder configClassBuilder 35 | = initBuilder(configPkg); 36 | 37 | //2. Contract services beans 38 | String servicePkg = config.getGroup() + "." + config.getArtifact() + ".service"; 39 | for(String contract: contracts){ 40 | addBean(configClassBuilder, servicePkg, contract); 41 | } 42 | 43 | //3. Output 44 | JavaFile javaFile = JavaFile.builder(configPkg, configClassBuilder.build()).build(); 45 | javaFile.writeTo(javaRoot); 46 | } 47 | 48 | private TypeSpec.Builder initBuilder(String configPkg){ 49 | 50 | ClassName className = ClassName.get(configPkg, "ServiceBeanConfig"); 51 | TypeSpec.Builder configClassBuilder 52 | = TypeSpec.classBuilder(className) 53 | .addModifiers(Modifier.PUBLIC) 54 | .addAnnotation(ClassName.get("org.springframework.context.annotation","Configuration")) 55 | .addAnnotation(Data.class) 56 | .addAnnotation(Slf4j.class) 57 | .addField(FieldSpec.builder( 58 | ClassName.get(configPkg, FileNameConstants.SYSTEM_CONFIG), "config", Modifier.PRIVATE) 59 | .addAnnotation(ClassName.get("org.springframework.beans.factory.annotation","Autowired")) 60 | .build()); 61 | return configClassBuilder; 62 | } 63 | 64 | private void addBean(TypeSpec.Builder builder, String servicePackage, String contract){ 65 | String serviceName = contract+"Service"; 66 | ClassName serviceClass = ClassName.get(servicePackage, serviceName); 67 | builder.addMethod( 68 | MethodSpec.methodBuilder(StringUtils.lowercaseFirstLetter(contract)+"Service") 69 | .addModifiers(Modifier.PUBLIC) 70 | .returns(serviceClass) 71 | .addParameter(ParameterSpec.builder(Client.class, "client").build()) 72 | .addException(Exception.class) 73 | .addAnnotation(ClassName.get("import org.springframework.context.annotation","Bean")) 74 | .addStatement("String address = config.getContract().get$LAddress()", contract) 75 | .addStatement("if (address == null) {log.warn(\"$L address not configured, so $L will not inject into spring\");}", contract, serviceName) 76 | .addStatement("return new $L(address, client)",serviceName) 77 | .build() 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/handler/ServicesHandler.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.handler; 2 | 3 | import java.util.Arrays; 4 | import java.util.Map; 5 | 6 | import javax.lang.model.element.Modifier; 7 | 8 | import com.webank.scaffold.builder.ContractConstantsBuilder; 9 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 10 | import org.fisco.bcos.sdk.client.Client; 11 | import org.fisco.bcos.sdk.transaction.manager.AssembleTransactionProcessor; 12 | import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory; 13 | import org.fisco.bcos.sdk.transaction.model.dto.CallResponse; 14 | import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse; 15 | import org.fisco.bcos.sdk.utils.StringUtils; 16 | 17 | import com.squareup.javapoet.AnnotationSpec; 18 | import com.squareup.javapoet.ClassName; 19 | import com.squareup.javapoet.FieldSpec; 20 | import com.squareup.javapoet.MethodSpec; 21 | import com.squareup.javapoet.TypeSpec; 22 | import com.webank.scaffold.config.UserConfig; 23 | import com.webank.scaffold.constants.DirNameConstants; 24 | import com.webank.scaffold.constants.FileNameConstants; 25 | 26 | import lombok.Data; 27 | import lombok.NoArgsConstructor; 28 | 29 | /** 30 | * @author aaronchu 31 | * @Description 32 | * @data 2021/01/27 33 | */ 34 | public class ServicesHandler { 35 | 36 | private UserConfig config; 37 | 38 | public ServicesHandler(UserConfig config) { 39 | this.config = config; 40 | } 41 | 42 | public TypeSpec build(String contract, Map functionWithInputBO) { 43 | 44 | // 1. create service class 45 | ClassName serviceClassName = serviceClassName(contract); 46 | TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(serviceClassName).addModifiers(Modifier.PUBLIC) 47 | .addAnnotation(ClassName.get("org.springframework.stereotype", "Service")) 48 | .addAnnotation(NoArgsConstructor.class).addAnnotation(Data.class); 49 | 50 | // 2. Instance fields: String address|Client client |AssemblyTransactionProcessor processor 51 | typeBuilder = this.populateInstanceFields(contract, typeBuilder); 52 | 53 | // 3. Add post constructor 54 | typeBuilder = this.populateInitializer(contract, typeBuilder); 55 | 56 | // 4. Add method: transaction | call 57 | typeBuilder = this.populateMethods(contract, typeBuilder, functionWithInputBO); 58 | return typeBuilder.build(); 59 | } 60 | 61 | private ClassName serviceClassName(String contract) { 62 | String pkg = config.getGroup() + "." + config.getArtifact(); 63 | String serviceName = contract + "Service"; 64 | return ClassName.get(pkg + ".service", serviceName); 65 | } 66 | 67 | private TypeSpec.Builder populateInstanceFields(String contract, TypeSpec.Builder typeBuilder) { 68 | FieldSpec addressField = FieldSpec.builder(String.class, "address").addModifiers(Modifier.PRIVATE) 69 | .addAnnotation(AnnotationSpec 70 | .builder(ClassName.get("org.springframework.beans.factory.annotation", "Value")) 71 | .addMember("value", "\"$${contract.$LAddress}\"", StringUtils.lowercaseFirstLetter(contract)) 72 | .build()) 73 | .build(); 74 | FieldSpec clientField = FieldSpec.builder(Client.class, "client").addModifiers(Modifier.PRIVATE) 75 | .addAnnotation(ClassName.get("org.springframework.beans.factory.annotation", "Autowired")).build(); 76 | FieldSpec processField = FieldSpec.builder(AssembleTransactionProcessor.class, "txProcessor").build(); 77 | return typeBuilder.addField(addressField).addField(clientField).addField(processField); 78 | } 79 | 80 | private TypeSpec.Builder populateInitializer(String contract, TypeSpec.Builder typeBuilder) { 81 | MethodSpec.Builder txBuilder = MethodSpec.methodBuilder("init"); 82 | txBuilder.addModifiers(Modifier.PUBLIC).addAnnotation(ClassName.get("javax.annotation", "PostConstruct")) 83 | .addException(Exception.class); 84 | txBuilder.addStatement( 85 | "this.txProcessor = $T.createAssembleTransactionProcessor(this.client, this.client.getCryptoSuite().getCryptoKeyPair())", 86 | TransactionProcessorFactory.class); 87 | typeBuilder.addMethod(txBuilder.build()); 88 | return typeBuilder; 89 | } 90 | 91 | private TypeSpec.Builder populateMethods(String contract, TypeSpec.Builder typeBuilder, 92 | Map functionWithInputBO) { 93 | 94 | for (Map.Entry entrySet : functionWithInputBO.entrySet()) { 95 | ABIDefinition function = entrySet.getKey(); 96 | TypeSpec inputBO = entrySet.getValue(); 97 | if (!function.isConstant()) { 98 | typeBuilder.addMethod(getTransactionMethod(contract, function.getName(), inputBO)); 99 | } else { 100 | typeBuilder.addMethod(getCallMethod(contract, function.getName(), inputBO)); 101 | } 102 | } 103 | 104 | return typeBuilder; 105 | } 106 | 107 | private MethodSpec getTransactionMethod(String contract, String function, TypeSpec inputType) { 108 | ClassName constantsClass = constantsClassName(); 109 | String abiField = contract+FileNameConstants.ABI_POSTFIX; 110 | String pkg = config.getGroup() + "." + config.getArtifact() + FileNameConstants.BO_PKG_POSTFIX; 111 | MethodSpec.Builder txBuilder = MethodSpec.methodBuilder(function); 112 | txBuilder.addModifiers(Modifier.PUBLIC).addException(Exception.class).returns(TransactionResponse.class); 113 | if (inputType != null) { 114 | txBuilder.addParameter(ClassName.get(pkg, inputType.name), "input").addStatement( 115 | "return this.txProcessor.sendTransactionAndGetResponse(this.address, $T.$L, \"$L\", input.toArgs())", 116 | constantsClass, abiField,function); 117 | } else { 118 | txBuilder.addStatement( 119 | "return this.txProcessor.sendTransactionAndGetResponse(this.address, $T.$L, \"$L\", $T.asList())", 120 | constantsClass, abiField, function, Arrays.class); 121 | } 122 | return txBuilder.build(); 123 | } 124 | 125 | private MethodSpec getCallMethod(String contract, String function, TypeSpec inputType) { 126 | ClassName constantsClass = constantsClassName(); 127 | String abiField = contract+FileNameConstants.ABI_POSTFIX; 128 | String pkg = config.getGroup() + "." + config.getArtifact() + FileNameConstants.BO_PKG_POSTFIX; 129 | MethodSpec.Builder txBuilder = MethodSpec.methodBuilder(function); 130 | txBuilder.addModifiers(Modifier.PUBLIC).addException(Exception.class).returns(CallResponse.class); 131 | if (inputType != null) { 132 | txBuilder.addParameter(ClassName.get(pkg, inputType.name), "input").addStatement( 133 | "return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, $T.$L, \"$L\", input.toArgs())", 134 | constantsClass, abiField, function); 135 | } else { 136 | txBuilder.addStatement( 137 | "return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, $T.$L, \"$L\", $T.asList())", 138 | constantsClass, abiField, function, Arrays.class); 139 | } 140 | return txBuilder.build(); 141 | } 142 | 143 | 144 | private ClassName constantsClassName() { 145 | String pkg = new ContractConstantsBuilder(config, Arrays.asList()).getJavaFilePackage(FileNameConstants.CONSTANT_PKG_POSTFIX); 146 | String simpleName = "ContractConstants"; 147 | return ClassName.get(pkg , simpleName); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/handler/SolidityTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.handler; 2 | 3 | import com.squareup.javapoet.TypeName; 4 | import com.squareup.javapoet.TypeSpec; 5 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * @author aaronchu 12 | * @Description 13 | * @data 2021/01/26 14 | */ 15 | public class SolidityTypeHandler { 16 | 17 | 18 | /** 19 | * Convert a strong typed solidity type. 20 | * uint256 -> Uint256.class 21 | * uint256[] -> DynamicArray[Uint256].class 22 | * uint256[2] ->StaticArray2[Uint256].class 23 | * uint256[][2] ->DynamicArray[StaticArray2[Uint256]].class 24 | * @param namedType 25 | * @return 26 | */ 27 | public static TypeName convert(ABIDefinition.NamedType namedType){ 28 | ContractHandler handler = new ContractHandler(); 29 | try{ 30 | //如果是结构体,那么返回结构体对应类型的名字,比如xxx.xxx.xxx.Entry 31 | if (!namedType.getComponents().isEmpty()){ 32 | List list = new ArrayList<>(); 33 | list.add(namedType); 34 | TypeName typeName = handler.buildTypeNames(list).get(0); 35 | return typeName; 36 | } 37 | TypeName solType = handler.buildTypeName(namedType.getType()); 38 | TypeName nativeType = handler.getNativeType(solType); 39 | return nativeType; 40 | }catch (Exception ex){ 41 | throw new RuntimeException(ex); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/util/ABIUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.webank.scaffold.util; 17 | 18 | import com.squareup.javapoet.*; 19 | import com.webank.scaffold.constants.FileNameConstants; 20 | import com.webank.scaffold.handler.SolidityTypeHandler; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Data; 23 | import lombok.NoArgsConstructor; 24 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; 25 | import org.fisco.bcos.sdk.abi.wrapper.ABIDefinitionFactory; 26 | import org.fisco.bcos.sdk.abi.wrapper.ContractABIDefinition; 27 | import org.fisco.bcos.sdk.crypto.CryptoSuite; 28 | import org.fisco.bcos.sdk.utils.StringUtils; 29 | 30 | import javax.lang.model.element.Modifier; 31 | import java.io.File; 32 | import java.util.*; 33 | import java.util.stream.Collectors; 34 | 35 | /** 36 | * ABIUtil 37 | * 38 | * @Description: 39 | * @Author: grayson 40 | * @Version 1.0 41 | * @Date: 2021-04-08 15:48 42 | **/ 43 | public class ABIUtil { 44 | 45 | public static TypeSpec buildBOType(String className, List args){ 46 | 47 | // 1.Check: No need to generate BO for functions with no args 48 | if(args.isEmpty()) return null;//No need 49 | 50 | // 2.metadata 51 | TypeSpec.Builder boBuilder = TypeSpec.classBuilder(className) 52 | .addModifiers(Modifier.PUBLIC) 53 | .addAnnotation(Data.class) 54 | .addAnnotation(NoArgsConstructor.class) 55 | .addAnnotation(AllArgsConstructor.class); 56 | 57 | // 3.Fields 58 | int argIndex = 0; 59 | List fixedArgs = new ArrayList<>(); 60 | for(ABIDefinition.NamedType namedType: args){ 61 | String argName = namedType.getName(); 62 | if(argName == null || argName.isEmpty()){ 63 | argName = "arg"+argIndex; 64 | } 65 | TypeName type = SolidityTypeHandler.convert(namedType); 66 | boBuilder.addField(type, argName, Modifier.PRIVATE); 67 | argIndex++; 68 | fixedArgs.add(argName); 69 | } 70 | 71 | // 4.Methods 72 | MethodSpec.Builder toArgsMethodBuilder = MethodSpec.methodBuilder("toArgs") 73 | .addModifiers(Modifier.PUBLIC) 74 | .returns(ListObject.class.getGenericInterfaces()[0]) 75 | .addStatement("$T args = new $T()", List.class, ArrayList.class); 76 | for(String arg: fixedArgs){ 77 | toArgsMethodBuilder.addStatement("args.add($L)", arg); 78 | } 79 | toArgsMethodBuilder.addStatement("return args"); 80 | boBuilder.addMethod(toArgsMethodBuilder.build()); 81 | 82 | TypeSpec boType = boBuilder.build(); 83 | return boType; 84 | } 85 | 86 | public static Map buildAbiDefAndTypeSpec(String contractName, String abiStr) { 87 | 88 | ABIDefinitionFactory factory = new ABIDefinitionFactory(new CryptoSuite(0)); 89 | ContractABIDefinition rootAbi = factory.loadABI(abiStr); 90 | Map> functions = rootAbi.getFunctions(); 91 | 92 | Map result = new HashMap<>(); 93 | for(Map.Entry> e: functions.entrySet()){ 94 | List definitions = e.getValue(); 95 | for(int i=0;i0?Integer.toString(i):""; 99 | String className = contractName 100 | + functionName 101 | + overloadMark 102 | + FileNameConstants.INPUT; 103 | TypeSpec inputType = buildBOType(className, abiDef.getInputs()); 104 | result.put(abiDef, inputType); 105 | } 106 | } 107 | return result; 108 | } 109 | 110 | public static List contracts(File abiDir, String need){ 111 | Set needContracts = Arrays.stream(need.split(",|;")).collect(Collectors.toSet()); 112 | List contractList = Arrays.stream(abiDir.listFiles()) 113 | .map(f->f.getName().split("\\.")[0]) 114 | .filter(c-> (need==null||need.isEmpty()) || needContracts.contains(c)) 115 | .collect(Collectors.toList()); 116 | return contractList; 117 | } 118 | 119 | interface ListObject extends List { 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/com/webank/scaffold/util/IOUtil.java: -------------------------------------------------------------------------------- 1 | package com.webank.scaffold.util; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.Map; 7 | 8 | import org.apache.commons.io.FileUtils; 9 | import org.apache.commons.io.IOUtils; 10 | 11 | /** 12 | * @author aaronchu 13 | * @Description 14 | * @data 2021/01/15 15 | */ 16 | public class IOUtil { 17 | 18 | private IOUtil() { 19 | } 20 | 21 | public static void replaceAllStr(String templateName, Map map, File dest) throws IOException { 22 | ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 23 | try (InputStream is = classLoader.getResourceAsStream(templateName)) { 24 | 25 | // 1.Read template 26 | String template = IOUtils.toString(is); 27 | 28 | // 2.Replace vars in template with users configuration info 29 | for (Map.Entry entry : map.entrySet()) { 30 | template = template.replace("${" + entry.getKey() + "}", entry.getValue()); 31 | } 32 | 33 | // 3.Output 34 | FileUtils.writeStringToFile(dest, template); 35 | } 36 | } 37 | 38 | public static File convertPackageToFile(final File root, String pkg) { 39 | String[] components = pkg.split("\\."); 40 | File dir = root; 41 | for (String component : components) { 42 | dir = new File(dir, component); 43 | } 44 | return dir; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/resources/templates/Application.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class Application { 8 | 9 | public static void main(String[] args){ 10 | SpringApplication.run(Application.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/templates/BcosConfig.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | import org.fisco.bcos.sdk.config.model.AmopTopic; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.context.annotation.PropertySource; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.PostConstruct; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | @Data 16 | @Configuration 17 | @ConfigurationProperties 18 | public class BcosConfig { 19 | private Map cryptoMaterial; 20 | public Map> network; 21 | public List amop; 22 | public Map account; 23 | public Map threadPool; 24 | } 25 | -------------------------------------------------------------------------------- /src/main/resources/templates/CommonResponse.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class CommonResponse { 11 | 12 | public static final String OK = "0"; 13 | 14 | private String code; 15 | private String message; 16 | private Object data; 17 | 18 | public static CommonResponse ok(Object data){ 19 | return new CommonResponse(OK, "",data); 20 | } 21 | 22 | public static CommonResponse fail(String code, Exception ex){ 23 | return new CommonResponse(code, ex.getMessage(), null); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/resources/templates/Demos.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.fisco.bcos.sdk.client.Client; 4 | import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair; 5 | import org.fisco.bcos.sdk.crypto.keypair.ECDSAKeyPair; 6 | import org.fisco.bcos.sdk.crypto.keypair.SM2KeyPair; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | 13 | @SpringBootTest 14 | @RunWith(SpringRunner.class) 15 | public class Demos { 16 | 17 | @Autowired 18 | private Client client; 19 | 20 | @Test 21 | public void keyGeneration() throws Exception { 22 | //ECDSA key generation 23 | CryptoKeyPair ecdsaKeyPair = new ECDSAKeyPair().generateKeyPair(); 24 | System.out.println("ecdsa private key :"+ecdsaKeyPair.getHexPrivateKey()); 25 | System.out.println("ecdsa public key :"+ecdsaKeyPair.getHexPublicKey()); 26 | System.out.println("ecdsa address :"+ecdsaKeyPair.getAddress()); 27 | //SM2 key generation 28 | CryptoKeyPair sm2KeyPair = new SM2KeyPair().generateKeyPair(); 29 | System.out.println("sm2 private key :"+sm2KeyPair.getHexPrivateKey()); 30 | System.out.println("sm2 public key :"+sm2KeyPair.getHexPublicKey()); 31 | System.out.println("sm2 address :"+sm2KeyPair.getAddress()); 32 | } 33 | 34 | @Test 35 | public void deploy() throws Exception { 36 | // AssembleTransactionProcessor txProcessor 37 | // = TransactionProcessorFactory.createAssembleTransactionProcessor(client, client.getCryptoSuite().getCryptoKeyPair()); 38 | // String abi = ContractConstants.HelloWorldAbi; 39 | // String bin = ContractConstants.HelloWorldBinary; 40 | // TransactionReceipt receipt = txProcessor.deployAndGetResponse(abi, bin, Arrays.asList()).getTransactionReceipt(); 41 | // if(receipt.isStatusOK()){ 42 | // System.out.println("Contract Address:"+receipt.getContractAddress()); 43 | // } 44 | // else{ 45 | // System.out.println("Status code:"+receipt.getStatus() + "-"+receipt.getStatusMsg()); 46 | // } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/resources/templates/SdkBeanConfig.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.fisco.bcos.sdk.BcosSDK; 5 | import org.fisco.bcos.sdk.client.Client; 6 | import org.fisco.bcos.sdk.config.ConfigOption; 7 | import org.fisco.bcos.sdk.config.model.ConfigProperty; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.context.annotation.Configuration; 11 | 12 | import java.math.BigInteger; 13 | import java.util.Map; 14 | 15 | @Configuration 16 | @Slf4j 17 | public class SdkBeanConfig { 18 | 19 | @Autowired 20 | private SystemConfig systemConfig; 21 | 22 | @Autowired 23 | private BcosConfig bcosConfig; 24 | 25 | @Bean 26 | public Client client() throws Exception { 27 | ConfigProperty property = new ConfigProperty(); 28 | configNetwork(property); 29 | configCryptoMaterial(property); 30 | 31 | ConfigOption configOption = new ConfigOption(property); 32 | Client client = new BcosSDK(configOption).getClient(systemConfig.getGroupId()); 33 | 34 | BigInteger blockNumber = client.getBlockNumber().getBlockNumber(); 35 | log.info("Chain connect successful. Current block number {}", blockNumber); 36 | 37 | configCryptoKeyPair(client); 38 | log.info("is Gm:{}, address:{}", client.getCryptoSuite().cryptoTypeConfig == 1, client.getCryptoSuite().getCryptoKeyPair().getAddress()); 39 | return client; 40 | } 41 | 42 | public void configNetwork(ConfigProperty configProperty){ 43 | Map peers = bcosConfig.getNetwork(); 44 | configProperty.setNetwork(peers); 45 | } 46 | 47 | public void configCryptoMaterial(ConfigProperty configProperty){ 48 | Map cryptoMaterials = bcosConfig.getCryptoMaterial(); 49 | configProperty.setCryptoMaterial(cryptoMaterials); 50 | } 51 | 52 | public void configCryptoKeyPair(Client client){ 53 | if(systemConfig.getHexPrivateKey() == null || systemConfig.getHexPrivateKey().isEmpty()){ 54 | return; 55 | } 56 | if(systemConfig.getHexPrivateKey().startsWith("0x") || systemConfig.getHexPrivateKey().startsWith("0X")){ 57 | systemConfig.setHexPrivateKey(systemConfig.getHexPrivateKey().substring(2)); 58 | } 59 | client.getCryptoSuite().setCryptoKeyPair(client.getCryptoSuite().createKeyPair(systemConfig.getHexPrivateKey())); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/resources/templates/TestConnection.java.tpl: -------------------------------------------------------------------------------- 1 | package ${package}; 2 | 3 | import org.fisco.bcos.sdk.BcosSDK; 4 | import org.fisco.bcos.sdk.client.Client; 5 | import org.fisco.bcos.sdk.client.protocol.response.BlockNumber; 6 | import org.junit.Test; 7 | 8 | public class TestConnection { 9 | 10 | /** 11 | * 确保连接能够正常进行 12 | */ 13 | @Test 14 | public void connectionTest() throws Exception { 15 | 16 | BcosSDK bcosSDK = BcosSDK.build("conf/config.toml"); 17 | Client client = bcosSDK.getClient(1); 18 | BlockNumber blockNumber = client.getBlockNumber(); 19 | System.out.println("Connection OK, current block number " + blockNumber.getBlockNumber()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/resources/templates/build.gradle.tpl: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/"} 5 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 6 | mavenLocal() 7 | 8 | } 9 | dependencies { 10 | classpath 'com.webank:solc-gradle-plugin:1.0.1' 11 | classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE") 12 | } 13 | } 14 | plugins { 15 | id 'org.springframework.boot' version '2.1.1.RELEASE' 16 | } 17 | apply plugin: 'java' 18 | apply plugin: 'eclipse' 19 | apply plugin: 'idea' 20 | apply plugin: 'maven' 21 | apply plugin: 'solc-gradle-plugin' 22 | apply plugin: 'org.springframework.boot' 23 | apply plugin: 'io.spring.dependency-management' 24 | 25 | sourceCompatibility = 1.8 26 | targetCompatibility = 1.8 27 | group = '${generator.group}' 28 | version = '1.0.0-SNAPSHOT' 29 | 30 | solc{ 31 | output = 'src/main/resources' 32 | onlyAbiBin = true 33 | } 34 | 35 | 36 | repositories { 37 | mavenLocal() 38 | mavenCentral() 39 | maven { url "http://maven.aliyun.com/nexus/content/groups/public/"} 40 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" } 41 | maven { url "https://dl.bintray.com/ethereum/maven/" } 42 | maven { url "https://oss.sonatype.org/service/local/staging/deploy/maven2"} 43 | } 44 | 45 | configurations { 46 | compileOnly { 47 | extendsFrom annotationProcessor 48 | } 49 | all { 50 | } 51 | } 52 | 53 | dependencies { 54 | 55 | compile 'org.springframework.boot:spring-boot-starter-web' 56 | compile 'org.slf4j:slf4j-api:1.7.5' 57 | compileOnly 'org.projectlombok:lombok' 58 | annotationProcessor 'org.projectlombok:lombok' 59 | testCompile('org.springframework.boot:spring-boot-starter-test') { 60 | exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' 61 | } 62 | testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1' 63 | testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.1' 64 | compile ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:2.9.1'){ 65 | exclude group: 'org.slf4j' 66 | } 67 | } 68 | 69 | 70 | sourceSets { 71 | main { 72 | java { 73 | srcDir 'src/main/java' 74 | } 75 | resources { 76 | srcDir 'src/main/resources' 77 | } 78 | } 79 | } 80 | 81 | test { 82 | useJUnitPlatform() 83 | } 84 | 85 | bootJar { 86 | destinationDir file('dist') 87 | archiveName project.name + '-exec.jar' 88 | doLast { 89 | copy { 90 | from file('src/main/resources') 91 | into 'dist' 92 | } 93 | } 94 | } 95 | 96 | clean { 97 | println "delete ${projectDir}/dist" 98 | delete "${projectDir}/dist" 99 | } 100 | -------------------------------------------------------------------------------- /src/main/resources/templates/gradle/wrapper/gradle-wrapper.jar.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WeBankBlockchain/SmartDev-Scaffold/1a46d0d8f8bb1698f926918dc72cfcde93c8e33d/src/main/resources/templates/gradle/wrapper/gradle-wrapper.jar.tpl -------------------------------------------------------------------------------- /src/main/resources/templates/gradle/wrapper/gradle-wrapper.properties.tpl: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-${gradle}-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /src/main/resources/templates/mvnw.cmd.tpl: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /src/main/resources/templates/mvnw.tpl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /src/main/resources/templates/pom.xml.tpl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.1.RELEASE 9 | 10 | 11 | ${generator.group} 12 | ${generator.artifact} 13 | 1.0.0-SNAPSHOT 14 | ${generator.artifact} 15 | Demo project for Spring Boot 16 | 17 | 1.8 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | org.junit.vintage 32 | junit-vintage-engine 33 | 34 | 35 | 36 | 37 | org.projectlombok 38 | lombok 39 | 40 | 41 | org.slf4j 42 | slf4j-api 43 | 1.7.5 44 | 45 | 46 | org.fisco-bcos.java-sdk 47 | fisco-bcos-java-sdk 48 | 2.7.2 49 | 50 | 51 | 52 | 53 | 54 | 55 | org.apache.maven.plugins 56 | maven-resources-plugin 57 | 2.7 58 | 59 | UTF-8 60 | 61 | 62 | 63 | copy-resources 64 | 65 | package 66 | 67 | copy-resources 68 | 69 | 70 | target 71 | 72 | 73 | src/main/resources 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | ${generator.artifact}-exec 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/main/resources/templates/settings.gradle.tpl: -------------------------------------------------------------------------------- 1 | rootProject.name = '${generator.artifact}' 2 | 3 | -------------------------------------------------------------------------------- /tools/config.ini: -------------------------------------------------------------------------------- 1 | [general] 2 | artifact=demo 3 | group=org.example 4 | selector= 5 | # 0.4.25.1 0.5.2.0 0.6.10.0 6 | compiler=0.6.10.0 7 | # or you can set it to maven 8 | type=gradle 9 | gradleVersion=6.3 -------------------------------------------------------------------------------- /tools/contracts/HelloWorld.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.10; 2 | 3 | 4 | contract HelloWorld{ 5 | string name; 6 | 7 | 8 | function set(string memory n) public{ 9 | emit test(n); 10 | name = n; 11 | } 12 | 13 | event test(string a); 14 | 15 | constructor () public{ 16 | name = "Hello, World!"; 17 | } 18 | 19 | function get() public view returns(string memory) { 20 | return name; 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /tools/contracts/KVTable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: Apache-2.0 2 | pragma solidity>=0.6.10 <0.8.20; 3 | pragma experimental ABIEncoderV2; 4 | 5 | struct KVField { 6 | string key; 7 | string value; 8 | } 9 | 10 | struct Entry { 11 | KVField[] fields; 12 | } 13 | 14 | contract KVTable { 15 | function createTable( 16 | string memory tableName, 17 | string memory key, 18 | string memory valueFields 19 | ) public returns (int256) {} 20 | 21 | function get(string memory tableName, string memory key) 22 | public 23 | view 24 | returns (bool, Entry memory entry) 25 | {} 26 | 27 | function set( 28 | string memory tableName, 29 | string memory key, 30 | Entry memory entry 31 | ) public returns (int256) {} 32 | function desc(string memory tableName) public returns(string memory,string memory){} 33 | } 34 | -------------------------------------------------------------------------------- /tools/run.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | set SOL_DIR=%cd%\contracts 5 | if not exist %SOL_DIR% ( 6 | echo %SOL_DIR% directory not exists. Please copy solidity files here 7 | exit /B 0 8 | ) 9 | set TOOLS_DIR=%cd% 10 | for /f "delims=" %%i in ('type "config.ini"^| find /i "="') do set %%i 11 | echo GROUP=%GROUP% 12 | echo ARTIFACT=%ARTIFACT% 13 | echo SOL_DIR=%SOL_DIR% 14 | echo TOOLS_DIR=%TOOLS_DIR% 15 | echo SELECTOR=%SELECTOR% 16 | echo TYPE=%TYPE% 17 | echo COMPILER=%COMPILER% 18 | echo GRADLEVERSION=%GRADLEVERSION% 19 | 20 | if exist %ARTIFACT% ( 21 | echo Artifact "%ARTIFACT%" ALREADY exists. Please remove it if you want to override 22 | exit /B 0 23 | ) 24 | 25 | echo start compiling scaffold... 26 | cd .. 27 | gradlew.bat clean shadowJar -PsolcVersion=%COMPILER% | more 28 | echo end compiling scaffold... 29 | 30 | echo start generating %ARTIFACT%... 31 | 32 | if defined SELECTOR set SELECTOR_OPTION=-n %SELECTOR% 33 | if defined TYPE set TYPE_OPTION=-t %TYPE% 34 | if defined GRADLEVERSION set GRADLEVERSION_OPTION=-gv %GRADLEVERSION% 35 | 36 | java -jar dist/WeBankBlockchain-SmartDev-Scaffold.jar -g %GROUP% -a %ARTIFACT% -s %SOL_DIR% -o %TOOLS_DIR% %SELECTOR_OPTION% %TYPE_OPTION% %GRADLEVERSION_OPTION% 37 | 38 | exit /B 0 39 | 40 | 41 | -------------------------------------------------------------------------------- /tools/run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | LANG=zh_CN.UTF-8 3 | 4 | function LOG_ERROR() 5 | { 6 | local content=${1} 7 | echo -e "\033[31m"${content}"\033[0m" 8 | } 9 | 10 | function check_java(){ 11 | version=$(java -version 2>&1 |grep version |awk '{print $3}') 12 | len=${#version}-2 13 | version=${version:1:len} 14 | 15 | IFS='.' arr=($version) 16 | IFS=' ' 17 | if [ -z ${arr[0]} ];then 18 | echo "At least Java8 is required." 19 | exit 1 20 | fi 21 | if [ ${arr[0]} -eq 1 ];then 22 | if [ ${arr[1]} -lt 8 ];then 23 | echo "At least Java8 is required." 24 | exit 1 25 | fi 26 | elif [ ${arr[0]} -gt 8 ];then 27 | : 28 | else 29 | echo "At least Java8 is required." 30 | exit 1 31 | fi 32 | } 33 | 34 | function check_sol_dir(){ 35 | SOL_DIR="$(pwd)/contracts" 36 | if [ ! -d "$SOL_DIR" ]; then 37 | echo " \" ${SOL_DIR} \" directory not exists. Please copy solidity files here" 38 | exit 0 39 | fi 40 | if [ ! "$(ls -A $SOL_DIR)" ]; then 41 | echo " \" ${SOL_DIR} \" directory is empty. Please copy solidity files here" 42 | exit 0 43 | fi 44 | } 45 | 46 | check_java 47 | check_sol_dir 48 | TOOLS_DIR=$(pwd) 49 | ARTIFACT=$(grep artifact config.ini | cut -d '=' -f 2) 50 | GROUP=$(grep group config.ini | cut -d '=' -f 2) 51 | SELECTOR=$(grep selector config.ini | cut -d '=' -f 2) 52 | COMPILER=$(grep compiler config.ini | cut -d '=' -f 2) 53 | TYPE=$(grep type config.ini | cut -d '=' -f 2) 54 | GRADLEVERSION=$(grep gradleVersion config.ini | cut -d '=' -f 2) 55 | echo "GROUP=$GROUP" 56 | echo "ARTIFACT=$ARTIFACT" 57 | echo "SOL_DIR=$SOL_DIR" 58 | echo "TOOLS_DIR=$TOOLS_DIR" 59 | echo "SELECTOR=$SELECTOR" 60 | echo "COMPILER=$COMPILER" 61 | echo "TYPE=$TYPE" 62 | echo "GRADLEVERSION=$GRADLEVERSION" 63 | ARTIFACT_DIR="$(pwd)/$ARTIFACT" 64 | if [ -d "$ARTIFACT_DIR" ]; then 65 | echo "\"$ARTIFACT_DIR \" directory ALREADY exists. Please remove it if you want to override" 66 | exit 0 67 | fi 68 | 69 | 70 | echo start compiling scaffold... 71 | 72 | 73 | cd .. 74 | ./gradlew clean shadowJar -PsolcVersion=$COMPILER 75 | echo end compiling scaffold... 76 | 77 | echo start generating $ARTIFACT... 78 | 79 | if [ ! -z "$SELECTOR" ]; then 80 | SELECTOR_OPTION="-n $SELECTOR" 81 | fi 82 | 83 | 84 | if [ ! -z "$GRADLEVERSION" ]; then 85 | GRADLEVERSION_OPTION="-gv $GRADLEVERSION" 86 | fi 87 | 88 | 89 | if [ ! -z "$TYPE" ]; then 90 | TYPE_OPTION="-t $TYPE" 91 | fi 92 | 93 | java -jar dist/WeBankBlockchain-SmartDev-Scaffold.jar -g $GROUP -a $ARTIFACT -s $SOL_DIR -o $TOOLS_DIR $SELECTOR_OPTION $TYPE_OPTION $GRADLEVERSION_OPTION 94 | 95 | 96 | --------------------------------------------------------------------------------