Commit 779160ac by 钟明宏

Merge branch 'dev'

parents 3068f490 e7286579
### 1.0.1
1. 增加过期文档删除功能
\ No newline at end of file
1. 增加过期文档删除功能
### 1.0.6
1. 修改显示的文档样式
2. 增加项目信息保存
3. 优化过期文档删除功能
### 1.0.7
1. 重构上传规则,一次性上传所有信息
\ No newline at end of file
......@@ -3,15 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-site-upload-parent</artifactId>
<artifactId>maven-document-upload-parent</artifactId>
<groupId>cn.yunmaozj.tools</groupId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>cn.yunmaozj.tools</groupId>
<artifactId>site-server</artifactId>
<artifactId>document-server</artifactId>
<properties>
<docker.registry>127.0.0.1:5000</docker.registry>
......@@ -36,11 +36,6 @@
<version>1.2.60</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
......
......@@ -18,7 +18,7 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@EnableScheduling
@EnableWebMvc
@SpringBootApplication
public class SiteServer implements ApplicationRunner {
public class DocumentServer implements ApplicationRunner {
@Autowired
private SystemFile systemFile;
......@@ -29,7 +29,7 @@ public class SiteServer implements ApplicationRunner {
}
public static void main(String[] args) {
SpringApplication.run(SiteServer.class, args);
SpringApplication.run(DocumentServer.class, args);
}
@Override
......
......@@ -29,7 +29,7 @@ public class FileCleanTask {
public void cleanFile() {
File[] files = systemFile.getWwwDir().listFiles();
for (File file : files) {
if (System.currentTimeMillis() - file.lastModified() > month) {
if ((System.currentTimeMillis() - file.lastModified()) > month) {
logger.warn("开始清理过期文件[{}] 创建时间[{}]",file,DateFormatUtils.format(new Date(file.lastModified()),"yyyy-MM-dd HH:mm:ss"));
systemFile.cleanFile(file.getName());
}
......
......@@ -77,12 +77,12 @@ public class SystemFile {
}
/**
* 解压文件
* 解压文件到www目录下面
*
* @param filename
* @param inputStream
*/
public void unzip(String filename, InputStream inputStream) throws IOException {
public void unzipToWww(String filename, InputStream inputStream) throws IOException {
// ArchiveEntry archiveEntry = null;
File unzipFile = new File(getWwwDir(), filename);//临时解压目录
logger.info("解压目录:{}", unzipFile);
......
......@@ -30,14 +30,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private SystemFile systemFile;
/*@Bean
public UserDetailsService userDetailsService() {
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
//manager.createUser(User.withDefaultPasswordEncoder().username("user").password("99boliyuan").roles("root").build());
//logger.info("创建用户:user 密码:99boliyuan");
return manager;
}*/
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().mvcMatchers("/site-upload", "/update-developer")
......
......@@ -4,16 +4,20 @@ import cn.yunmaozj.common.DeveloperEntity;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.email.EmailService;
import cn.yunmaozj.security.Developer;
import cn.yunmaozj.security.InfoXmlResolver;
import cn.yunmaozj.security.Project;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.List;
......@@ -32,16 +36,23 @@ public class UploadController {
private Project project;
@Autowired
private EmailService emailService;
@Autowired
private InfoXmlResolver resolver;
private final Logger logger = LoggerFactory.getLogger(UploadController.class);
@PostMapping("/site-upload")
public void siteUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
systemFile.unzip(multipartFile.getResource().getFilename(), multipartFile.getInputStream());
public synchronized void siteUpload(@RequestParam("file") MultipartFile multipartFile) throws IOException, DocumentException {
systemFile.unzipToWww(multipartFile.getResource().getFilename(), multipartFile.getInputStream());
resolver.resolver(multipartFile.getResource().getFilename());
}
/**
* 未来将会废弃
* 更新开发人员
*/
@Deprecated
@PostMapping("/update-developer")
public synchronized void updateDeveloper(String entities) throws IOException {
logger.info("接收到开发人员信息:{}", entities);
......
......@@ -30,8 +30,6 @@ public class Developer {
private final Logger logger = LoggerFactory.getLogger(Developer.class);
private final SAXReader reader = new SAXReader();
private SystemFile systemFile;
private SAXReader saxReader = new SAXReader();
private final File userFile;
......@@ -366,4 +364,13 @@ public class Developer {
return roles().contains(ROOT_ROLE_NAME);
}
/**
* 通过解析info.xml获取信息
*
* @param infoXml
*/
public void resolver(File infoXml) {
}
}
package cn.yunmaozj.security;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.email.EmailService;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2019-11-09 11:35
*/
@Component
public class InfoXmlResolver {
private final Logger logger;
private final SystemFile systemFile;
private final Project project;
private SAXReader saxReader;
private final EmailService emailService;
public InfoXmlResolver(SystemFile systemFile, Project project, EmailService emailService) {
this.systemFile = systemFile;
this.project = project;
this.emailService = emailService;
this.saxReader = new SAXReader();
this.logger = LoggerFactory.getLogger(InfoXmlResolver.class);
}
/**
* 项目资源名字
*
* @param resourceFileName
*/
public void resolver(String resourceFileName) throws DocumentException, IOException {
File projectFileName = new File(systemFile.getWwwDir(), resourceFileName);
File infoXml = new File(projectFileName, "info.xml");
if (!infoXml.exists()) {
return;
}
Document document = saxReader.read(infoXml);
Element artifactId = document.getRootElement().element("artifactId");
Element version = document.getRootElement().element("version");
Element description = document.getRootElement().element("description");
updateProject(artifactId.getText(), version.getText(), description.getText());
Element developers = document.getRootElement().element("developers");
if (developers != null) {
List<Element> developerList = developers.elements("developer");
for (Element developer : developerList) {
String id = developer.attributeValue("id");
String email = developer.attributeValue("email");
String name = developer.attributeValue("name");
Developer developerEntity = new Developer(systemFile, id);
if (StringUtils.isNotEmpty(name))
developerEntity.setName(name);
developerEntity.addProject(artifactId.getText());
if (developer.element("roles") != null) {
List<Element> roleList = developer.element("roles").elements("role");
if (roleList != null && roleList.size() > 0) {
roleList.forEach(E -> {
if (!Developer.ROOT_ROLE_NAME.equals(E.getText())) {
developerEntity.addRole(E.getText());
}
});
}
}
developerEntity.setEmail(email);
if (StringUtils.isEmpty(developerEntity.getPassword())) {
//生成随机密码
String password = RandomStringUtils.randomAlphanumeric(6);
developerEntity.setPassword(password);
emailService.sendLog("docs.yunmaozj.com", "你当前登录网站的密码是:" + password, developerEntity.getEmail());
}
}
}
}
private void updateProject(String projectName, String version, String description) {
project.addProject(projectName, description, version);
}
}
package cn.boliyuan;
import cn.yunmaozj.SiteServer;
import cn.yunmaozj.DocumentServer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @create 2019-09-17 17:39
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = SiteServer.class)
@SpringBootTest(classes = DocumentServer.class)
public class ApplicationTest {
@Test
......
......@@ -3,25 +3,25 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-site-upload-parent</artifactId>
<artifactId>maven-document-upload-parent</artifactId>
<groupId>cn.yunmaozj.tools</groupId>
<version>1.0.6</version>
<version>1.0.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>cn.yunmaozj.tools</groupId>
<artifactId>site-upload-maven-plugin</artifactId>
<artifactId>document-upload-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>${parent.version}${version.suffix}</version>
<description>
文档上传工具
</description>
<description>文档上传工具</description>
<properties>
<boliyuan.parent.version>1.1.5</boliyuan.parent.version>
</properties>
<inceptionYear>2019</inceptionYear>
<developers>
<developer>
<id>zhongmh</id>
......@@ -142,13 +142,13 @@
<profile>
<id>master</id>
<properties>
<version.suffix>-releases</version.suffix>
<version.suffix>-RELEASE</version.suffix>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<version.suffix>-beta</version.suffix>
<version.suffix>-BETA</version.suffix>
</properties>
</profile>
</profiles>
......
package cn.yunmaozj.upload;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import jdk.nashorn.api.scripting.JSObject;
import jdk.nashorn.internal.ir.debug.JSONWriter;
import okhttp3.*;
import org.apache.commons.compress.archivers.zip.Zip64Mode;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
......@@ -18,14 +13,19 @@ import org.apache.maven.plugins.annotations.*;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;
import org.codehaus.plexus.util.StringUtils;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultDocument;
import org.dom4j.tree.DefaultElement;
import org.dom4j.tree.DefaultText;
import java.io.*;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Consumer;
/**
......@@ -34,7 +34,7 @@ import java.util.function.Consumer;
* @create 2019-09-10 11:30
*/
@Mojo(name = "upload", threadSafe = true)
public class SiteUploadMojo extends AbstractMojo {
public class DocumentUploadMojo extends AbstractMojo {
@Parameter(property = "skip", defaultValue = "false")
private boolean skip;
......@@ -81,12 +81,10 @@ public class SiteUploadMojo extends AbstractMojo {
getLog().info("输入目录:" + inputDirectory);
String name = StringUtils.isEmpty(directory.getName()) ? project.getArtifactId() : directory.getName();
try {
writeProjectInfo(name, inputDirectory);
//上传压缩文件
File outFile = compress(name, inputDirectory);
uploader(name, outFile);
//上传开发人员信息
List<Developer> developers = project.getDevelopers();
uploadDeveloper(developers, name);
transport(name, outFile);
} catch (IOException e) {
e.printStackTrace();
}
......@@ -97,7 +95,7 @@ public class SiteUploadMojo extends AbstractMojo {
/**
* 上传压缩文件的地方
*/
private void uploader(String name, File outFile) throws MojoExecutionException, IOException {
private void transport(String name, File outFile) throws MojoExecutionException, IOException {
if (!outFile.exists()) {
throw new MojoExecutionException("上传的文件[" + outFile.getPath() + "]不存在");
}
......@@ -129,54 +127,6 @@ public class SiteUploadMojo extends AbstractMojo {
getLog().info(response.toString());
}
public void uploadDeveloper(List<Developer> developers, String name) throws IOException {
if (developers == null || developers.size() == 0) {
getLog().debug("developer.size == 0");
return;
}
JsonArray developerArray = new JsonArray();
for (Developer developer : developers) {
JsonObject developerObject = new JsonObject();
if (StringUtils.isEmpty(developer.getEmail())) {
throw new NullPointerException("开发人员必须设置email属性");
}
if (StringUtils.isEmpty(developer.getName())) {
throw new NullPointerException("开发人员必须设置name属性");
}
developerObject.addProperty("id", developer.getId());
developerObject.addProperty("email", developer.getEmail());
developerObject.addProperty("name", developer.getName());
developerObject.addProperty("description", project.getDescription());
developerObject.addProperty("version", project.getVersion());
JsonArray roleArray = new JsonArray();
if (developer.getRoles() == null || developer.getRoles().size() == 0) {
roleArray.add("developer");
} else {
developer.getRoles().forEach(R -> roleArray.add(R));
}
developerObject.add("roles", roleArray);
developerObject.addProperty("project", name);
developerArray.add(developerObject);
}
RequestBody body = new FormBody.Builder()
.add("entities", developerArray.toString()).build();
HttpUrl.Builder httpUrlBuilder = new HttpUrl.Builder();
if (ssl) {
httpUrlBuilder.scheme("https");
} else {
httpUrlBuilder.scheme("http");
}
httpUrlBuilder.host(siteServerHost).port(siteServerPort);
if (StringUtils.isNotEmpty(siteServerUserName) && StringUtils.isNotEmpty(siteServerPassword)) {
httpUrlBuilder.username(siteServerUserName).password(siteServerPassword);
}
httpUrlBuilder.addPathSegment("update-developer");
Request request = new Request.Builder().url(httpUrlBuilder.build())
.post(body).build();
Response response = getClient().newCall(request).execute();
getLog().info("upload developer info [" + response.toString() + "]");
}
/**
* 压缩文件
*/
......@@ -253,4 +203,65 @@ public class SiteUploadMojo extends AbstractMojo {
}
/**
* 写入项目信息,
*
* @param inputDirectory
*/
public void writeProjectInfo(String projectName, File inputDirectory) throws IOException {
File infoXml = new File(inputDirectory, "info.xml");
OutputFormat outputFormat = OutputFormat.createPrettyPrint();
outputFormat.setEncoding("UTF-8");
outputFormat.setIndent(true); //设置是否缩进
outputFormat.setIndent(" "); //以四个空格方式实现缩进
outputFormat.setNewlines(true); //设置是否换行
DefaultDocument document = new DefaultDocument("project");
Element projectElement = new DefaultElement("project");
projectElement.addAttribute("date", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
projectElement.addAttribute("javaVersion", System.getProperty("java.version"));
projectElement.addAttribute("osName", System.getProperty("os.name"));
projectElement.addAttribute("hostName", InetAddress.getLocalHost().getHostName());
//添加项目信息
Element artifactId = new DefaultElement("artifactId");
artifactId.setText(projectName);
//版本
Element version = new DefaultElement("version");
version.setText(project.getVersion());
//简介
Element description = new DefaultElement("description");
description.setText(project.getDescription());
//添加开人员
Element developers = new DefaultElement("developers");
for (Developer developer : project.getDevelopers()) {
Element developerElement = new DefaultElement("developer");
developerElement.addAttribute("name", developer.getName());
developerElement.addAttribute("email", developer.getEmail());
developerElement.addAttribute("id", developer.getId());
Element roles = new DefaultElement("roles");
if (developer.getRoles() != null && developer.getRoles().size() > 0) {
for (String roleString : developer.getRoles()) {
Element role = new DefaultElement("role");
role.add(new DefaultText(roleString));
roles.add(role);
}
} else {
Element role = new DefaultElement("role");
role.add(new DefaultText("developer"));
roles.add(role);
}
developerElement.add(roles);
developers.add(developerElement);
}
projectElement.add(artifactId);
projectElement.add(version);
projectElement.add(description);
projectElement.add(developers);
document.add(projectElement);
XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(infoXml), "UTF-8"));
writer.write(document);
writer.close();
}
}
......@@ -5,14 +5,16 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cn.yunmaozj.tools</groupId>
<artifactId>maven-site-upload-parent</artifactId>
<version>1.0.6</version>
<artifactId>maven-document-upload-parent</artifactId>
<version>1.0.7</version>
<description>站点上传插件</description>
<modules>
<module>site-upload-maven-plugin</module>
<module>site-server</module>
<module>document-upload-maven-plugin</module>
<module>document-server</module>
</modules>
<packaging>pom</packaging>
<url>http://git.cqwzxt.com/opensource/site-upload-maven-plugin</url>
<properties>
......@@ -47,11 +49,19 @@
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.2</version>
</dependency>
</dependencies>
<build>
......@@ -59,7 +69,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.76.96</version>
<version>3.1.0-RELEASE</version>
</plugin>
</plugins>
</build>
......
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