com.aliyun.manager.UploadPackageManager Maven / Gradle / Ivy
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 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 {
File 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