Skip to content

Commit

Permalink
Merge pull request #43 from kyonRay/main
Browse files Browse the repository at this point in the history
Release v1.6.0
  • Loading branch information
kyonRay authored Sep 11, 2024
2 parents 035deba + f5ed6aa commit 9e3acb8
Show file tree
Hide file tree
Showing 18 changed files with 1,016 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest]
os: [macos-12]
steps:
- uses: actions/checkout@v2
with:
Expand Down
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ ext {
ossrhPassword = "xxx"
}
// jackson version
jacksonVersion = '2.14.1'
jacksonVersion = '2.17.0'
javapoetVersion = '1.13.0'
picocliVersion = '4.6.1'
picocliVersion = '4.7.6'
junitVersion = '4.13.2'
commonsLang3Version = '3.12.0'
commonsLang3Version = '3.14.0'

javaSDKVersion3 = "3.7.0"
javaSDKVersion3 = "3.8.0"
javaSDKVersion2 = "2.10.0"
slf4jVersion = "1.7.32"
slf4jVersion = "1.7.36"
}

sourceSets {
Expand All @@ -54,7 +54,7 @@ configurations.all {
// integrationTest.mustRunAfter test
allprojects {
group = 'org.fisco-bcos.code-generator'
version = '1.5.0'
version = '1.6.0'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'eclipse'
Expand Down Expand Up @@ -86,7 +86,7 @@ allprojects {
api("org.slf4j:slf4j-api:${slf4jVersion}")
api("org.apache.commons:commons-lang3:${commonsLang3Version}")
testImplementation("junit:junit:${junitVersion}")
testImplementation("org.mockito:mockito-core:4.6.0")
testImplementation('org.mockito:mockito-core:5.11.0')
}

clean.doLast {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/fisco/bcos/codegen/CodeGenMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ static class PicocliRunner implements Runnable {
required = true)
private File smBinFile;

@Option(
names = {"-d", "--devdoc"},
description = "solidity devdoc file generated by NatSpec style comments.")
private File devdocFile;

@Option(
names = {"-o", "--outputDir"},
description = "destination base directory.",
Expand Down Expand Up @@ -134,9 +139,15 @@ public void run() {
if (version.equals(Version.V2)) {
try {
new org.fisco.bcos.codegen.v2.wrapper.SolidityContractGenerator(
binFile, smBinFile, abiFile, destinationFileDir, packageName)
binFile,
smBinFile,
abiFile,
devdocFile,
destinationFileDir,
packageName)
.generateJavaFiles();
} catch (Exception e) {
e.printStackTrace();
org.fisco.bcos.codegen.v2.utils.CodeGenUtils.exitError(e);
}
} else if (version.equals(Version.V3)) {
Expand All @@ -145,6 +156,7 @@ public void run() {
binFile,
smBinFile,
abiFile,
devdocFile,
destinationFileDir,
packageName,
enableAsyncCall,
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/org/fisco/bcos/codegen/v2/utils/Devdoc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.fisco.bcos.codegen.v2.utils;

import java.util.Map;

public class Devdoc {
private String details;
private Map<String, Method> methods;

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}

public Map<String, Method> getMethods() {
return methods;
}

public void setMethods(Map<String, Method> methods) {
this.methods = methods;
}

public static class Method {
private String details;
private Map<String, String> params;
private Map<String, String> returns;

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}

public Map<String, String> getParams() {
return params;
}

public void setParams(Map<String, String> params) {
this.params = params;
}

public Map<String, String> getReturns() {
return returns;
}

public void setReturns(Map<String, String> returns) {
this.returns = returns;
}
}
}
74 changes: 74 additions & 0 deletions src/main/java/org/fisco/bcos/codegen/v2/utils/DocUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.fisco.bcos.codegen.v2.utils;

import com.squareup.javapoet.MethodSpec;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.fisco.bcos.codegen.v2.exceptions.CodeGenException;
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition;
import org.fisco.bcos.sdk.transaction.tools.JsonUtils;
import org.fisco.bcos.sdk.utils.StringUtils;

public class DocUtils {

public static Devdoc.Method getMethod(Devdoc devdoc, ABIDefinition functionDefinition) {
if (devdoc != null && devdoc.getMethods() != null) {
return devdoc.getMethods().get(functionDefinition.getMethodSignatureAsString());
}

return null;
}

public static void addMethodComments(Devdoc.Method method, MethodSpec.Builder methodBuilder) {
if (method == null) {
return;
}

// add comments for method
if (!StringUtils.isEmpty(method.getDetails())) {
methodBuilder.addJavadoc("$L \n", method.getDetails());
}
}

public static void addParamsComments(Devdoc.Method method, MethodSpec.Builder methodBuilder) {
if (method == null) {
return;
}

// add comments for params
Map<String, String> params = method.getParams();
if (params != null) {
for (String p : params.keySet()) {
if (!StringUtils.isEmpty(params.get(p))) {
methodBuilder.addJavadoc("@param $N $L \n", p, params.get(p));
}
}
}
}

public static void addReturnsComments(
String comments, Devdoc.Method method, MethodSpec.Builder methodBuilder) {
if (method == null) {
return;
}

// add comments for returns
Map<String, String> returns = method.getReturns();
if (returns != null) {
for (String r : returns.keySet()) {
if (!StringUtils.isEmpty(returns.get(r))) {
methodBuilder.addJavadoc("$L $N $L \n", comments, r, returns.get(r));
}
}
}
}

public static Devdoc convertDevDoc(File devdocFile) throws CodeGenException, IOException {
if (devdocFile != null && devdocFile.exists()) {
byte[] devdocBytes = CodeGenUtils.readBytes(devdocFile);
return JsonUtils.fromJson(new String(devdocBytes), Devdoc.class);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.IOException;
import org.fisco.bcos.codegen.v2.exceptions.CodeGenException;
import org.fisco.bcos.codegen.v2.utils.CodeGenUtils;
import org.fisco.bcos.codegen.v2.utils.DocUtils;

/** Java wrapper source code generator for Solidity ABI format. */
public class SolidityContractGenerator {
Expand Down Expand Up @@ -46,18 +47,21 @@ public class SolidityContractGenerator {
private final File binFile;
private final File smBinFile;
private final File abiFile;
private final File devdocFile;
private final File destinationDir;
private final String basePackageName;

public SolidityContractGenerator(
File binFile,
File smBinFile,
File abiFile,
File devdocFile,
File destinationDir,
String basePackageName) {
this.binFile = binFile;
this.smBinFile = smBinFile;
this.abiFile = abiFile;
this.devdocFile = devdocFile;
this.destinationDir = destinationDir;
this.basePackageName = basePackageName;
}
Expand All @@ -77,6 +81,7 @@ public void generateJavaFiles() throws IOException, ClassNotFoundException, Code
new String(binary),
new String(smBinary),
new String(abiBytes),
DocUtils.convertDevDoc(devdocFile),
destinationDir.toString(),
basePackageName);
}
Expand Down
Loading

0 comments on commit 9e3acb8

Please sign in to comment.