Commit 227b4ac5 by zhongmh

增加多版本控制

parent 0b9d3e29
......@@ -58,4 +58,5 @@
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......@@ -12,6 +12,7 @@
<groupId>cn.yunmaozj.tools</groupId>
<artifactId>site-upload-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>${parent.version}${version.suffix}</version>
<properties>
<boliyuan.parent.version>1.1.5</boliyuan.parent.version>
......@@ -102,4 +103,27 @@
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<version.suffix>-SNAPSHOT</version.suffix>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>master</id>
<properties>
<version.suffix>-releases</version.suffix>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<version.suffix>-beta</version.suffix>
</properties>
</profile>
</profiles>
</project>
\ No newline at end of file
......@@ -14,14 +14,16 @@ import java.util.Set;
*/
public class Directories {
@Parameter(property = "fileList", required = true)
private Set<File> directories = new HashSet<>();
@Parameter(property = "directory", required = true)
private Set<Directory> directories = new HashSet<>();
public Set<File> getFileList() {
public Set<Directory> getFileList() {
return directories;
}
public void addDirectory(File file) {
public void addDirectory(Directory file) {
this.directories.add(file);
}
}
package cn.yunmaozj.upload;
/**
* @author zhongminghong
* @email yunmaozj@163.com
* @create 2019-09-11 11:13
*/
import org.apache.maven.plugins.annotations.Parameter;
import java.io.File;
public class Directory {
@Parameter(property = "name")
private String name;
@Parameter(property = "path", required = true)
private File path;
public String getName() {
return name;
}
public File getPath() {
return path;
}
public void setName(String name) {
this.name = name;
}
public void setPath(File path) {
this.path = path;
}
}
......@@ -14,7 +14,6 @@ import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.StringUtils;
import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
......@@ -69,15 +68,17 @@ public class SiteUploadMojo extends AbstractMojo {
getLog().info("the project packaging is pom");
return;
}
for (File inputDirectory : directories.getFileList()) {
for (Directory directory : directories.getFileList()) {
File inputDirectory = directory.getPath();
if (!inputDirectory.exists()) {
getLog().info("资源目录不存在[" + inputDirectory + "]");
return;
}
getLog().info("输入目录:" + inputDirectory);
try {
File outFile = compress(inputDirectory);
uploader(outFile);
String name = StringUtils.isEmpty(directory.getName()) ? project.getArtifactId() : directory.getName();
File outFile = compress(name, inputDirectory);
uploader(name, outFile);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -87,7 +88,7 @@ public class SiteUploadMojo extends AbstractMojo {
/**
* 上传压缩文件的地方
*/
private void uploader(File outFile) throws MojoExecutionException, IOException {
private void uploader(String name, File outFile) throws MojoExecutionException, IOException {
if (!outFile.exists()) {
throw new MojoExecutionException("上传的文件[" + outFile.getPath() + "]不存在");
}
......@@ -98,7 +99,7 @@ public class SiteUploadMojo extends AbstractMojo {
RequestBody fileBody = RequestBody.create(MediaType.parse("application/octet-stream"), outFile);
MultipartBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", project.getName(), fileBody)
.addFormDataPart("file", name, fileBody)
.build();
if (StringUtils.isNotEmpty(siteServerUserName) && StringUtils.isNotEmpty(siteServerPassword)) {
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)))
......@@ -132,13 +133,14 @@ public class SiteUploadMojo extends AbstractMojo {
Request request = new Request.Builder().url(httpUrlBuilder.build())
.post(body).build();
Response response = client.newCall(request).execute();
getLog().info("Uploading file:[" + outFile + "] to [" + request.url() + "]");
getLog().info(response.toString());
}
/**
* 压缩文件
*/
private File compress(File inputDirectory) throws IOException {
private File compress(String name, File inputDirectory) throws IOException {
Stack<File> directoryStack = new Stack<>();
directoryStack.push(inputDirectory);
File currentDirectoryFile = null;
......@@ -163,7 +165,7 @@ public class SiteUploadMojo extends AbstractMojo {
if (!outputDirectory.exists()) {
outputDirectory.mkdirs();
}
File outFile = new File(outputDirectory, project.getName() + ".zip");
File outFile = new File(outputDirectory, name + ".zip");
ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(outFile);
zipArchiveOutputStream.setUseZip64(Zip64Mode.Never);
for (File file : fileList) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment