All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.ypkdeploy.CodeRepoTool Maven / Gradle / Ivy

The newest version!
package org.bdware.ypkdeploy;

import com.google.gson.Gson;
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 {

    public static void publish(String publishConfig, String ypkPath) throws Exception {
        FileStorage storage = new FileStorage(publishConfig);
        EndpointConfig endpointConfig = storage.loadAsEndpointConfig();
        AuditIrpClient irpClient = new AuditIrpClient(endpointConfig);
        CodeRepoConfig bdosConfig = new Gson().fromJson(storage.load(), CodeRepoConfig.class);
        JsonObject arg = storage.load();
        if (bdosConfig.codeRepoId == null) {
            System.out.println("[CodeRepoTool] error: missing codeRepoId");
            return;
        }
        CodeRepoClient client = new CodeRepoClient(bdosConfig.codeRepoId, irpClient,
                SM2KeyPair.fromJson(arg.toString()));
        if (ypkPath == null)
            ypkPath = bdosConfig.ypkPath;
        if (ypkPath == null) {
            System.out.println("[CodeRepoTool] error: missing ypkPath");
            return;
        }
        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();
        }
    }

    public static void publish(String publishConfig) throws Exception {
        publish(publishConfig, null);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy