diff --git a/.gitignore b/.gitignore index 1a3632e..a33e683 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ deployconfig.json +publishconf.json .DS_Store /build/ /testinput/ \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6d2d23e..135e774 100755 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { id 'signing' } group "org.bdware.bdcontract" -version "0.7.1" +version "0.7.2" sourceCompatibility = 1.8 repositories { mavenCentral() @@ -20,6 +20,8 @@ dependencies { implementation 'org.bouncycastle:bcprov-jdk15on:1.69' implementation 'org.apache.httpcomponents:httpclient:4.5.13' implementation 'org.apache.httpcomponents:httpmime:4.5.13' + implementation 'org.bdware.doip:bdosclient:0.0.2' + // implementation 'org.bdware.doip:doip-audit-tool:1.2.4' testImplementation 'junit:junit:4.13.2' } diff --git a/publishconf.json b/publishconf.json new file mode 100644 index 0000000..b74d56c --- /dev/null +++ b/publishconf.json @@ -0,0 +1,7 @@ +{ + "routerURI": "tcp://127.0.0.1:21041", + "codeRepoId": "bdtest/CodeRepository", + "ypkPath": "/Users/huaqiancai/BDWare/bdware-address/node-storage/build/node-storage-0.0.1.ypk", + "publicKey": "04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610", + "privateKey": "1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b" +} \ No newline at end of file diff --git a/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java b/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java new file mode 100644 index 0000000..4f1f8bf --- /dev/null +++ b/src/main/java/org/bdware/ypkdeploy/CodeRepoTool.java @@ -0,0 +1,54 @@ +package org.bdware.ypkdeploy; + +import com.google.gson.JsonObject; +import org.bdware.bdosclient.CodeRepoClient; +import org.bdware.doip.audit.EndpointConfig; +import org.bdware.doip.audit.client.AuditIrpClient; +import org.bdware.doip.audit.config.FileStorage; +import org.bdware.doip.codec.doipMessage.DoipMessage; +import org.zz.gmhelper.SM2KeyPair; + +import java.util.concurrent.atomic.AtomicInteger; + +public class CodeRepoTool { + static class Config { + + } + + public static void publish(String publishConfig) throws Exception { + FileStorage storage = new FileStorage(publishConfig); + EndpointConfig endpointConfig = storage.loadAsEndpointConfig(); + AuditIrpClient irpClient = new AuditIrpClient(endpointConfig); + JsonObject arg = storage.load(); + CodeRepoClient client = new CodeRepoClient(arg.get("codeRepoId").getAsString(), irpClient, SM2KeyPair.fromJson(arg.toString())); + String ypkPath = arg.get("ypkPath").getAsString(); + AtomicInteger result = new AtomicInteger(0); + client.createAndUpload(ypkPath, new CodeRepoClient.ProgressCallback() { + @Override + public void onStart(String doId) { + System.out.println("[CodeRepoTool] onStart:" + doId); + } + + @Override + public void onProgress(String doId, int currentChunk, int totalChunk) { + System.out.println("[CodeRepoTool] " + doId + " progress: " + currentChunk + "/" + totalChunk); + } + + @Override + public void onFinish(String doId) { + System.out.println("[CodeRepoTool] onFinish:" + doId); + result.incrementAndGet(); + } + + @Override + public void onError(String message, DoipMessage msg) { + System.out.println("[CodeRepoTool] error:" + message); + System.out.println("[CodeRepoTool] doipMsg:" + msg.body.getDataAsJsonString()); + result.incrementAndGet(); + } + }); + for (; result.get() == 0; ) { + Thread.yield(); + } + } +} diff --git a/src/test/java/CodeRepoToolTest.java b/src/test/java/CodeRepoToolTest.java new file mode 100644 index 0000000..ed1019e --- /dev/null +++ b/src/test/java/CodeRepoToolTest.java @@ -0,0 +1,9 @@ +import org.bdware.ypkdeploy.CodeRepoTool; +import org.junit.Test; + +public class CodeRepoToolTest { + @Test + public void run() throws Exception { + CodeRepoTool.publish("./publishconf.json"); + } +}