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

com.aliyun.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;

import com.aliyun.bean.DefaultConfigBean;
import com.aliyun.uploader.Uploader;
import com.aliyun.uploader.UploaderFactory;
import com.aliyuncs.DefaultAcsClient;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;

import java.io.File;

public class UploadPackageManager {
    private static final String PUBLIC_OSS_URL_SUFFIX = ".aliyuncs.com";
    private static final String INTERNAL_OSS_URL_SUFFIX = "-internal.aliyuncs.com";
    private Log logger;
    private MavenProject project;

    public UploadPackageManager(MavenProject project, Log logger) {
        this.project = project;
        this.logger = logger;
    }

    public String uploadPackage(DefaultConfigBean config) throws MojoExecutionException {
        File file = project.getArtifact().getFile();
        if (file == null || !file.exists()) {
            String msg = "No artifact is found, please confirm your project's packaging type.";
            throw new MojoExecutionException(msg);
        }

        try {
            Uploader uploader = UploaderFactory.getUploader(config);

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

            return downloadUrl;
        } catch (Exception ex) {
            this.logger.error("upload failed.", ex);
            throw new MojoExecutionException(
                String.format("Upload file failed. [%s/%s]", file.getAbsolutePath(), file.getName()));
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy