Commit 2e32da56 by zhongmh

增加版本 和 项目说明显示

parent f49b8c64
......@@ -6,7 +6,7 @@
<groupId>cn.yunmaozj.tools</groupId>
<artifactId>maven-site-upload-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<description>站点上传插件</description>
<modules>
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>maven-site-upload-parent</artifactId>
<groupId>cn.yunmaozj.tools</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -14,6 +14,8 @@ public class DeveloperEntity {
private String name;
private List<String> roles;
private String project;
private String description;
private String version;
public String getId() {
return id;
......@@ -54,4 +56,20 @@ public class DeveloperEntity {
public void setProject(String project) {
this.project = project;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
}
......@@ -2,9 +2,12 @@ package cn.yunmaozj.configuration;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.security.Developer;
import cn.yunmaozj.security.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.stereotype.Component;
......@@ -17,15 +20,18 @@ import java.util.List;
* @email yunmaozj@163.com
* @create 2019-09-19 23:04
*/
@Component
@Configuration
public class LoadApplicationConfiguration implements ApplicationRunner {
@Autowired
private SystemFile systemFile;
@Bean
public Project project(SystemFile systemFile){
return new Project(systemFile);
}
@Override
public void run(ApplicationArguments args) throws Exception {
}
/**
......@@ -37,7 +43,7 @@ public class LoadApplicationConfiguration implements ApplicationRunner {
if (!file.isDirectory()) {
String fileName = file.getName();
String userId = fileName.substring(0, fileName.indexOf(".xml"));
Developer developer = new Developer(systemFile,userId);
Developer developer = new Developer(systemFile, userId);
}
}
......
......@@ -2,6 +2,7 @@ package cn.yunmaozj.controller;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.security.Developer;
import cn.yunmaozj.security.Project;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -33,6 +34,8 @@ public class IndexController {
private final Logger logger = LoggerFactory.getLogger(IndexController.class);
@Autowired
private SystemFile systemFile;
@Autowired
private Project project;
@RequestMapping(value = {"index.html", "/"})
public void index(HttpServletResponse response) throws IOException {
......@@ -54,6 +57,7 @@ public class IndexController {
html.append("<thead>");
html.append("<tr>");
html.append("<th>Project</th>");
html.append("<th>Version</th>");
html.append("<th>LastModified</th>");
html.append("<th>Description</th>");
if (isRole)
......@@ -63,13 +67,15 @@ public class IndexController {
html.append("<tbody>");
Set<File> fileSet = new TreeSet<>(Arrays.asList(files));
for (File file : fileSet) {
Project.ProjectAttribute projectAttribute = project.getProjectAttribute(file.getName());
if (isRole || developer.exitProject(file.getName())) {
html.append("<tr>");
//项目名字
html.append("<td>").append("<button type=\"button\" class=\"btn btn-link\" url='/").append(file.getName()).append("/index.html'>").append(file.getName()).append("</button>").append("</td>");
html.append("<td>").append(projectAttribute.getVersion()).append("</td>");
//项目时间
html.append("<td>").append(DateFormatUtils.format(file.lastModified(), "yyyy-MM-dd HH:mm:ss")).append("</td>");
html.append("<td></td>");
html.append("<td>").append(projectAttribute.getDescription()).append("</td>");
//是有有删除标记
if (isRole) {
html.append("<td>").append("<button type=\"button\" class=\"btn btn-danger\" url='/del/").append(file.getName()).append("'>删除</button>").append("</td>");
......
......@@ -4,6 +4,7 @@ import cn.yunmaozj.common.DeveloperEntity;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.email.EmailService;
import cn.yunmaozj.security.Developer;
import cn.yunmaozj.security.Project;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -28,6 +29,8 @@ public class UploadController {
@Autowired
private SystemFile systemFile;
@Autowired
private Project project;
@Autowired
private EmailService emailService;
private final Logger logger = LoggerFactory.getLogger(UploadController.class);
......@@ -46,6 +49,7 @@ public class UploadController {
for (DeveloperEntity developerEntity : list) {
Developer developer = new Developer(systemFile, developerEntity.getId());
developer.setName(developerEntity.getName());
project.addProject(developerEntity.getProject(), developerEntity.getDescription(), developerEntity.getVersion());
developer.addProject(developerEntity.getProject());
if (developerEntity.getRoles() != null && developerEntity.getRoles().size() > 0) {
developerEntity.getRoles().forEach(R -> {
......
......@@ -227,7 +227,6 @@ public class Developer {
}
/**
* >>>>>>> master
* 更新密码
*
* @param password
......
package cn.yunmaozj.security;
import cn.yunmaozj.common.SystemFile;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.QName;
import org.dom4j.dom.DOMAttribute;
import org.dom4j.dom.DOMElement;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.dom4j.tree.DefaultDocument;
import java.io.*;
import java.util.Date;
import java.util.List;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2019-10-31 13:32
*/
public class Project {
private static final SAXReader reader = new SAXReader();
private final File projectFile;
private SAXReader saxReader = new SAXReader();
private final static String DEFAULT_CHARSET = "UTF-8";
public final static String ROOT_ROLE_NAME = "root";
private final static OutputFormat outputFormat;
public Project(SystemFile systemFile) {
projectFile = new File(systemFile.getConfigDir(), "project.xml");
if (!projectFile.exists()) {
try {
projectFile.createNewFile();
Document document = new DefaultDocument();
Element element = new DOMElement("projects");
document.add(element);
XMLWriter writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(projectFile), DEFAULT_CHARSET));
writer.write(document);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
static {
outputFormat = OutputFormat.createPrettyPrint();
outputFormat.setEncoding(DEFAULT_CHARSET);
outputFormat.setIndent(true); //设置是否缩进
outputFormat.setIndent(" "); //以四个空格方式实现缩进
outputFormat.setNewlines(true); //设置是否换行
}
public synchronized void addProject(String project, String description, String version) {
Document document = getProjectDocument();
if (document == null) {
return;
}
List<Element> elements = document.getRootElement()
.elements(project);
if (elements == null || elements.size() == 0) {
Element element = new DOMElement(project);
element.add(new DOMAttribute(new QName("description"), description));
element.add(new DOMAttribute(new QName("version"), version));
document.getRootElement().add(element);
write(document);
return;
}
Element element = elements.get(0);
element.addAttribute("description", description);
element.addAttribute("version", version);
write(document);
}
public ProjectAttribute getProjectAttribute(String project) {
Document document = getProjectDocument();
if (document == null) {
return null;
}
List<Element> elements = document.getRootElement()
.elements(project);
if (elements == null || elements.size() == 0) {
return new ProjectAttribute("", "");
}
Element element = elements.get(0);
return new ProjectAttribute(element.attributeValue("description"), element.attributeValue("version"));
}
private Document getProjectDocument() {
try {
Document document = reader.read(projectFile);
return document;
} catch (DocumentException e) {
e.printStackTrace();
}
return null;
}
private synchronized void write(Document document) {
XMLWriter writer = null;
try {
writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(projectFile), DEFAULT_CHARSET), outputFormat);
writer.write(document);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
close(writer);
}
}
private void close(XMLWriter writer) {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static class ProjectAttribute {
String description;
String version;
public ProjectAttribute(String description, String version) {
this.description = description;
this.version = version;
}
public String getDescription() {
return description;
}
public String getVersion() {
return version;
}
}
}
package cn.boliyuan.security;
import cn.boliyuan.ApplicationTest;
import cn.yunmaozj.common.SystemFile;
import cn.yunmaozj.security.Project;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author zhongminghong
* @email zhongmh@yunmaozj.com
* @create 2019-10-31 13:43
*/
public class ProjectTest extends ApplicationTest {
@Autowired
private SystemFile systemFile;
@Test
public void addProject() {
Project project = new Project(systemFile);
project.addProject("test", "测试", "1.0.0");
Project.ProjectAttribute projectAttribute = project.getProjectAttribute("test");
Assert.assertEquals("测试", projectAttribute.getDescription());
Assert.assertEquals("1.0.0", projectAttribute.getVersion());
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>maven-site-upload-parent</artifactId>
<groupId>cn.yunmaozj.tools</groupId>
<version>1.0.5</version>
<version>1.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
......
......@@ -146,6 +146,8 @@ public class SiteUploadMojo extends AbstractMojo {
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");
......
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