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

com.aliyun.manager.UploadPackageManager Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 1.1.9
Show newest version
package com.aliyun.manager;

import com.aliyun.Context;
import com.aliyun.bean.common.OssProfile;
import com.aliyun.bean.common.ToolkitProfile;
import com.aliyun.uploader.Uploader;
import com.aliyun.uploader.UploaderFactory;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;

import java.io.File;

public class UploadPackageManager {
    private Log logger;
    private MavenProject project;

    public UploadPackageManager(MavenProject project) {
        this.project = project;
        this.logger = Context.getLogger();
    }

    public String uploadPackage(
            ToolkitProfile toolkitProfile, OssProfile ossProfile, String appId, String packageVersion) throws Exception {
        return doUpload(toolkitProfile, ossProfile, appId, packageVersion);
    }

    private String doUpload(
            ToolkitProfile toolkitProfile, OssProfile ossProfile,
            String appId, String packageVersion) throws Exception {
        // 优先使用jarPath
        File file;
        if (StringUtils.isNotBlank(toolkitProfile.getJarPath())) {
            Path path = Paths.get(toolkitProfile.getJarPath()).normalize();
            file = path.toFile();
            if (file == null || !file.exists()) {
                throw new Exception("No jar file found with path: " + toolkitProfile.getJarPath());
            }
        } else {
            file = project.getArtifact().getFile();
            if (file == null || !file.exists()) {
                throw new Exception("No artifact is found for: " + project.getArtifactId());
            }
        }

        Uploader uploader = UploaderFactory.getUploader(toolkitProfile, ossProfile, appId, packageVersion);

        this.logger.info(String.format("Start to upload [%s] using [%s].", file.getName(), uploader.getName()));
        long st = System.currentTimeMillis();
        String downloadUrl = uploader.upload(file);
        System.out.print("\n");
        this.logger.info(String
                .format("Upload finished in %s ms, download url: [%s]", System.currentTimeMillis() - st, downloadUrl));

        return downloadUrl;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy