提交 5e4ba9a8 authored 作者: zhangshuang's avatar zhangshuang

合并分支 'zs' 到 'master'

Zs 查看合并请求 ty_wyl/adaptation-master1!35
......@@ -90,6 +90,11 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
......
......@@ -27,8 +27,8 @@ public class WebSocketServer {
public void onOpen(Session session,@PathParam("uuid")String uuid){
this.session = session;
this.uuid = uuid;
System.out.println(this.uuid + "\t" + this.session);
//session.getOpenSessions().
//System.out.println("第一个" + uuid);
logger.info("uuid:"+uuid);
map.put(uuid,this);
try {
......@@ -70,6 +70,7 @@ public class WebSocketServer {
public static void sendInfo(String sessionId,String msg,String action,String state,String projectName){
try {
//System.out.println(sessionId);
map.get(sessionId).sendMessage(LocalDateTime.now()+"\t"+projectName+"\t"+action+"\t"+state+"\t"+msg);
} catch (IOException e) {
e.printStackTrace();
......
......@@ -34,6 +34,10 @@ public class Project {
private String codeUrl;//当前源码源码路径
private String des;//描述
private String stage;//阶段(源代码、替换后、编译后)
private Integer status = 1;//状态(0:删除 1:未删除)
@Temporal(TemporalType.TIMESTAMP)
......
......@@ -37,6 +37,6 @@ public class Report {
MYSQL,ORACLE,SQLSERVER,POSTGRE
}
public enum Language{
JAVA,PYTHON,CPP
JAVA,PYTHON,CPP,JSP,ONLYVIEW
}
}
package com.zjty.adaptationmaster.adaptor.repository;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface ReportDao extends JpaRepository<Report, Integer>, JpaSpecificationExecutor {
}
......@@ -8,6 +8,7 @@ import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.adaptor.service.AdaptationService;
import com.zjty.adaptationmaster.utils.ApusicDeployer;
import com.zjty.adaptationmaster.utils.FileUtil;
import com.zjty.adaptationmaster.utils.FileZip;
import com.zjty.adaptationmaster.utils.MavenCompiler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -60,11 +61,12 @@ public class AdaptationServiceImpl implements AdaptationService {
@Transactional
@Override
public ServerResponse unZipProject(String path, Project project) {
project = projectDao.getOne(project.getId());
FileUtil fileUtil = new FileUtil();
project.setCodeUrl(Const.UPLOAD_LOCATION+File.separator+project.getProjectName());
Project project1 = projectDao.getOne(project.getId());
//FileUtil fileUtil = new FileUtil();
project1.setCodeUrl(Const.UPLOAD_LOCATION+File.separator+project.getProjectName());
try {
fileUtil.unZip(new File(path),project.getCodeUrl());
FileZip.unzip(new File(path),project.getCodeUrl());
project.setStage(project.getStage());
} catch (Exception e) {
e.printStackTrace();
}
......
......@@ -36,7 +36,7 @@ public class DBMigrateServiceImpl implements DBMigrateService {
private DBRecordDao dbRecordDao;
//线程池数量,合适的线程数量能让程序更快
private static final int poolSize = 2;
private static final int poolSize = 4;
@Value("${highgo.driver}")
private String highgoDriver;
......
package com.zjty.adaptationmaster.adaptor.service.Impl;
import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
import com.zjty.adaptationmaster.adaptor.repository.ReportDao;
import com.zjty.adaptationmaster.adaptor.service.InspectService;
import com.zjty.adaptationmaster.base.response.ServerResponse;
import com.zjty.adaptationmaster.utils.Inspector;
......@@ -11,16 +13,30 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@Service
public class InspectServiceImpl implements InspectService {
@Autowired
private ProjectDao projectDao;
@Autowired
private ReportDao reportDao;
@Transactional
@Override
public ServerResponse inspect(Project project) {
//Project project = projectDao.getOne(projectId);
return ServerResponse.success(new Inspector(project,new HashMap<>(),new HashMap<>()/*,new ArrayList<>()*/).inspect());
Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java",Report.Language.JAVA);
suffixLanguageMapping.put("cpp",Report.Language.CPP);
suffixLanguageMapping.put("py",Report.Language.PYTHON);
suffixLanguageMapping.put("jsp",Report.Language.JSP);
//suffixLanguageMapping.put("html",Report.Language.ONLYVIEW);
Report report = new Inspector(project, suffixLanguageMapping).inspect();
reportDao.save(report);
Project one = projectDao.getOne(project.getId());
one.setReport(report);
return ServerResponse.success(report);
}
}
......@@ -40,7 +40,7 @@ public class Const {
public static Map<String,Long> transferCountMap = new ConcurrentHashMap<>();
public static final String MAVENHOME = "D:\\apache-maven-3.5.4";
public static final String CTLPATH = "/home/user/Desktop/AAS-V9.0/bin/appctl";
public static final String MAVENHOME = "D:\\Program Files\\apache-maven-3.5.4-bin\\apache-maven-3.5.4";
public static final String CTLPATH = "/home/user/AAS-V9.0/bin/appctl.cmd";
public static final String CTLPWD = "Qwert123!@#";
}
......@@ -3,12 +3,14 @@ package com.zjty.adaptationmaster.utils;
import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.base.entity.ProjectStatueFromMiddleware;
import com.zjty.adaptationmaster.base.enums.Const;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
......@@ -18,7 +20,9 @@ public class ApusicDeployer {
private String ctlPath;
private String ctlPwd;
public void deploy(Project project,String webSocketName){
String command = ctlPath+" -p '"+ctlPwd+"' install "+project.getProjectName()+" "+project.getReport().getPackagePath();
//String command = ctlPath+" -p "+ Const.CTLPWD +" install "+project.getProjectName()+" "+project.getReport().getPackagePath();
String command = ctlPath +" install "+project.getProjectName()+" "+project.getReport().getPackagePath();
System.out.println(command);
appctl(command,webSocketName,project.getProjectName());
}
public List<ProjectStatueFromMiddleware> list(){
......@@ -43,22 +47,27 @@ public class ApusicDeployer {
return result;
}
public boolean start(String projectName,String webSocketName){
String command = ctlPath+" -p '"+ctlPwd+"' start "+projectName;
String command = ctlPath+" start "+projectName;
appctl(command,webSocketName,projectName);
return true;
}
public boolean stop(String projectName,String webSocketName){
String command = ctlPath+" -p '"+ctlPwd+"' stop "+projectName;
String command = ctlPath+" stop "+projectName;
appctl(command,webSocketName,projectName);
return true;
}
private void appctl(String command,String webSocketName,String projectName){
try {
Process exec = Runtime.getRuntime().exec(command);
String password = "Qwert123!@#";
OutputStream outputStream = exec.getOutputStream();
outputStream.write(password.getBytes());
outputStream.flush();
outputStream.close();
BufferedReader reader = new BufferedReader(new InputStreamReader(exec.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
WebSocketServer.sendInfo(line, webSocketName, "部署", "running", projectName);
WebSocketServer.sendInfo(webSocketName, line, "部署", "running", projectName);
}
} catch (IOException e) {
e.printStackTrace();
......
package com.zjty.adaptationmaster.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.FileUtils;
import java.io.*;
import java.nio.charset.Charset;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@Slf4j
public class FileZip {
public static void unZipFiles(File zipFile, String descDir)throws IOException
{
File pathFile = new File(descDir);
if(!pathFile.exists())
{
pathFile.mkdirs();
}
//解决zip文件中有中文目录或者中文文件
ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK"));
for(Enumeration entries = zip.entries(); entries.hasMoreElements();)
{
ZipEntry entry = (ZipEntry)entries.nextElement();
String zipEntryName = entry.getName();
InputStream in = zip.getInputStream(entry);
String outPath = (descDir+zipEntryName).replaceAll("\\*", "/");;
//判断路径是否存在,不存在则创建文件路径
File file = new File(outPath.substring(0, outPath.lastIndexOf('/')));
if(!file.exists())
{
file.mkdirs();
public static void unzip(File zipFile, String descDir) {
try (ZipArchiveInputStream inputStream = getZipFile(zipFile)) {
File pathFile = new File(descDir);
if (!pathFile.exists()) {
pathFile.mkdirs();
}
//判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压
if(new File(outPath).isDirectory())
{
continue;
ZipArchiveEntry entry = null;
while ((entry = inputStream.getNextZipEntry()) != null) {
if (entry.isDirectory()) {
File directory = new File(descDir, entry.getName());
directory.mkdirs();
} else {
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(new File(descDir, entry.getName())));
//输出文件路径信息
log.info("解压文件的当前路径为:{}", descDir + entry.getName());
IOUtils.copy(inputStream, os);
} finally {
IOUtils.closeQuietly(os);
}
}
}
//输出文件路径信息
System.out.println(outPath);
OutputStream out = new FileOutputStream(outPath);
byte[] buf1 = new byte[1024];
int len;
while((len=in.read(buf1))>0)
{
out.write(buf1,0,len);
final File[] files = pathFile.listFiles();
if (files != null && files.length == 1 && files[0].isDirectory()) {
// 说明只有一个文件夹
FileUtils.copyDirectory(files[0], pathFile);
//免得删除错误, 删除的文件必须在/data/demand/目录下。
boolean isValid = files[0].getPath().contains("/data/www/");
if (isValid) {
FileUtils.forceDelete(files[0]);
}
}
in.close();
out.close();
log.info("******************解压完毕********************");
} catch (Exception e) {
log.error("[unzip] 解压zip文件出错", e);
}
zip.close(); //**原博忘记关了,所以我在做完这些操作后想要删除文件时,一直已占用,必须关掉服务器才可以**
System.out.println("******************解压完毕********************");
}
private static ZipArchiveInputStream getZipFile(File zipFile) throws Exception {
return new ZipArchiveInputStream(new BufferedInputStream(new FileInputStream(zipFile)));
}
public static void main(String[] args) throws Exception{
String path = "D:\\sqlFile\\uploads\\8599bc6b-e140-493e-8ea6-07eba392adad.zip";
unzip(new File(path), "D:\\sqlFile\\uploads\\test123456789");
}
}
......@@ -4,7 +4,7 @@ import com.zjty.adaptationmaster.adaptor.entity.Project;
import com.zjty.adaptationmaster.adaptor.entity.Report;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.File;
......@@ -13,7 +13,6 @@ import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*;
import java.util.regex.Matcher;
/**
* 项目体检,根据既定特征值,
......@@ -25,47 +24,45 @@ public class Inspector {
public static void main(String[] args) {
Project project = new Project();
project.setCodeUrl("");
Map<String,Report.Language> suffixLanguageMapping = new HashMap<>();
Map<String, Report.Separate> suffixSeparateMapping = new HashMap<>();
List<String> configFileSuffixList = new ArrayList<>();
Inspector inspector = new Inspector(project,suffixLanguageMapping,suffixSeparateMapping/*,configFileSuffixList*/);
inspector.inspect();
project.setCodeUrl("C:\\home\\project\\rsc\\hrmbclient");
Map<String, Report.Language> suffixLanguageMapping = new HashMap<>();
suffixLanguageMapping.put("java",Report.Language.JAVA);
suffixLanguageMapping.put("cpp",Report.Language.CPP);
suffixLanguageMapping.put("py",Report.Language.PYTHON);
suffixLanguageMapping.put("jsp",Report.Language.JSP);
Inspector inspector = new Inspector(project,suffixLanguageMapping);
System.out.println(inspector.inspect());
}
private Project project;
private Report report;
private Map<String, Counter> languageMatchMap;
private Map<String, Counter> separateMatchMap;
private Map<String, Report.Language> suffixLanguageMapping;
private Map<String, Report.Separate> suffixSeparateMapping;
private Map<String,List<Path>> configFileTypePathsMapping;
public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping,Map<String, Report.Separate> suffixSeparateMapping/*,List<String> configFileSuffixList*/){
public Inspector(Project project,Map<String,Report.Language> suffixLanguageMapping){
this.project = project;
this.suffixLanguageMapping = suffixLanguageMapping;
this.suffixSeparateMapping = suffixSeparateMapping;
this.languageMatchMap = new HashMap<>();
for(String s:suffixLanguageMapping.keySet()){
languageMatchMap.put(s,new Counter());
}
this.separateMatchMap = new HashMap<>();
for(String s:suffixSeparateMapping.keySet()){
separateMatchMap.put(s,new Counter());
}
/**
* 如果存在html文件,不一定是前端代码,
* 如果只存在html文件,不存在其他类型文件,大概率是前端代码
* 策略:
* 先检测是否存在html文件,如果存在,假定为前端项目
* 然后检测其他条件,如果符合,将假定冲掉
*/
languageMatchMap.put("html",new Counter());
this.configFileTypePathsMapping = new HashMap<>();
// for(String s:configFileSuffixList){
// configFileTypePathsMapping.put(s,new ArrayList<>());
// }
configFileTypePathsMapping.put("xml",new ArrayList<>());
configFileTypePathsMapping.put("properties",new ArrayList<>());
configFileTypePathsMapping.put("yml",new ArrayList<>());
this.report = new Report();
}
private List<Path> propertiesConfigPaths = new ArrayList<>();
private List<Path> ymlConfigPaths = new ArrayList<>();
private List<Path> xmlConfigPaths = new ArrayList<>();
/**
* FileVisitResult.CONTINUE 继续遍历
* FileVisitResult.TERMINATE 中止访问
......@@ -79,11 +76,6 @@ public class Inspector {
for(String s:suffixLanguageMapping.keySet()){
languageSuffixMatcherMapping.put(s,aDefault.getPathMatcher("glob:**/*."+s));
}
Map<String,PathMatcher> separateSuffixMatcherMapping = new HashMap<>();
for(String s:suffixLanguageMapping.keySet()){
separateSuffixMatcherMapping.put(s,aDefault.getPathMatcher("glob:**/*."+s));
}
Map<PathMatcher,String> configFileMatcherSuffixMapping = new HashMap<>();
for(String s:configFileTypePathsMapping.keySet()){
configFileMatcherSuffixMapping.put(aDefault.getPathMatcher("glob:**/*."+s),s);
......@@ -99,26 +91,26 @@ public class Inspector {
*/
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
for(Map.Entry<String,PathMatcher> entry:languageSuffixMatcherMapping.entrySet()){
if(entry.getValue().matches(dir)){
languageMatchMap.get(entry.getKey()).plus();
}
}
for(Map.Entry<String,PathMatcher> entry:separateSuffixMatcherMapping.entrySet()){
if(entry.getValue().matches(dir)){
separateMatchMap.get(entry.getKey()).plus();
}
}
/**
* 这里是对于路径(文件夹)的过滤,在这里读不到文件
* 如果能判断,可以返回FileVisitResult.SKIP_SUBTREE 不访问子目录
*/
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
for(Map.Entry<String,PathMatcher> entry:languageSuffixMatcherMapping.entrySet()){
if(entry.getValue().matches(file)){
languageMatchMap.get(entry.getKey()).plus();
}
}
for(Map.Entry<PathMatcher,String> entry:configFileMatcherSuffixMapping.entrySet()){
if(entry.getKey().matches(file)){
configFileTypePathsMapping.get(entry.getValue()).add(file);
}
}
//System.out.println(file);
return FileVisitResult.CONTINUE;
}
......@@ -139,21 +131,32 @@ public class Inspector {
}
public Report analysis(){
report.setLanguage(Report.Language.ONLYVIEW);
for(Map.Entry<String,Counter> entry:languageMatchMap.entrySet()){
if(entry.getValue().getNumber()>0){
report.setLanguage(suffixLanguageMapping.get(entry.getKey()));
}
}
for(Map.Entry<String,Counter> entry:separateMatchMap.entrySet()){
if(entry.getValue().getNumber()>0){
report.setIsSeparate(suffixSeparateMapping.get(entry.getKey()));
if(!entry.getKey().equals("html")){
report.setLanguage(suffixLanguageMapping.get(entry.getKey()));
}
}
}
/**
* 对于具体的配置文件对应的处理方法
* 增加要处理的文件类型需要在这里增加相应的处理方法
*/
for(Map.Entry<String,List<Path>> entry:configFileTypePathsMapping.entrySet()){
//System.out.println(entry.getKey());
switch (entry.getKey()){
case ".xml":
/**
* 配置文件的一个类型,xml文件
*/
case "xml":
System.out.println(entry.getValue().size());
for(Path path:entry.getValue()){
if(path.getFileName().equals("pom.xml")){
/**
* 对于maven工程,可以在maven配置文件中得到一这些信息
* 编译方式打包方式和打好的包的路径
*/
if(path.getFileName().endsWith("pom.xml")){
report.setDependenceManagement(Report.DependenceManagement.MAVEN);
report.setCompileFilePath(path.toString());
......@@ -164,50 +167,61 @@ public class Inspector {
} catch (DocumentException e) {
e.printStackTrace();
}
//Node dependences = document.selectSingleNode("dependencies");
//report.setPackagePath();
Element elementProject = document.getRootElement();
String projectMavenName = elementProject.elementText("artifactId");
String projectMavenVersion = elementProject.elementText("version");
report.setPackagePath(path.getParent()+"/target/"+projectMavenName+"-"+projectMavenVersion+".war");
}
//PathMatcher matcher = FileSystems.getDefault().getPathMatcher("");
if(path.getFileName().toString().equals("application.properties")){
}
break;
/**
* 配置文件的一个类型,properties文件
*
*/
case "properties":
for(Path path:entry.getValue()) {
/**
* springboot项目的配置文件一般是application.properties或application.yml
*/
if (path.getFileName().endsWith("application.properties")) {
Properties properties = new Properties();
try {
properties.load(new FileInputStream(path.toFile()));
} catch (IOException e) {
e.printStackTrace();
}
String datasourceDriver = properties.getProperty("spring.datasource.driver-class-name");
String active = properties.getProperty("spring.profiles.active");
System.out.println(path.getParent());
File file = new File(path.getParent().toString()+"/application-"+active+".properties");
if(file.exists()){
File file = new File(path.getParent().toString() + "/application-" + active + ".properties");
if (file.exists()) {
Properties properties1 = new Properties();
try {
properties1.load(new FileInputStream(file));
String driver = properties1.getProperty("spring.datasource.driver-class-name");
if(driver!=null)datasourceDriver = driver;
if (driver != null) datasourceDriver = driver;
} catch (IOException e) {
e.printStackTrace();
}
}else {
} else {
System.out.println("没有找到active配置文件");
}
if(datasourceDriver!=null){
if(datasourceDriver.contains(Report.DatabaseType.MYSQL.name().toLowerCase())){
if (datasourceDriver != null) {
if (datasourceDriver.contains(Report.DatabaseType.MYSQL.name().toLowerCase())) {
report.setDatabaseType(Report.DatabaseType.MYSQL);
} else if(datasourceDriver.contains(Report.DatabaseType.POSTGRE.name().toLowerCase())){
} else if (datasourceDriver.contains(Report.DatabaseType.POSTGRE.name().toLowerCase())) {
report.setDatabaseType(Report.DatabaseType.POSTGRE);
} else if(datasourceDriver.contains(Report.DatabaseType.ORACLE.name().toLowerCase())){
} else if (datasourceDriver.contains(Report.DatabaseType.ORACLE.name().toLowerCase())) {
report.setDatabaseType(Report.DatabaseType.ORACLE);
} else if(datasourceDriver.contains(Report.DatabaseType.SQLSERVER.name().toLowerCase())){
} else if (datasourceDriver.contains(Report.DatabaseType.SQLSERVER.name().toLowerCase())) {
report.setDatabaseType(Report.DatabaseType.SQLSERVER);
}
}
}
}
break;
case "yml":
break;
}
}
// for(Path path:propertiesConfigPaths){
......@@ -253,7 +267,7 @@ public class Inspector {
// e.printStackTrace();
// }
// }
return null;
return report;
}
public class Counter {
private int i = 0;
......
......@@ -25,7 +25,7 @@ public class MavenCompiler {
public void compiler(){
InvocationRequest request = new DefaultInvocationRequest();
request.setPomFile(new File(project.getReport().getCompileFilePath()));
request.setGoals(Collections.singletonList("compile"));
request.setGoals(Collections.singletonList("package"));
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(mavenHome));
......@@ -34,7 +34,7 @@ public class MavenCompiler {
@Override
public void consumeLine(String s) throws IOException {
WebSocketServer.sendInfo(webSocketId,s,"编译","running",project.getProjectName());
//System.out.println(s);
System.out.println(s);
}
});
try {
......
......@@ -289,6 +289,10 @@ public class Regular {
public static void main(String[] args) {
mySqlRegular("D:\\sqlFile\\uploads\\63c6e098-73fd-4999-b289-b3d120a07e87.sql","test11111");
//mySqlRegular("D:\\sqlFile\\uploads\\63c6e098-73fd-4999-b289-b3d120a07e87.sql","test11111");
//
File file = new File("D:\\root\\projects\\adaptationMaster\\uploads\\czq测试系统5\\swiper-4.5.0/target/threem-0.0.1-SNAPSHOT.war");
System.out.println(file.length());
System.out.println(file.getName());
}
}
......@@ -28,8 +28,11 @@ spring.jpa.open-in-view=true
spring.jpa.properties.javax.persistence.validation.mode=none
# spring-http-文件上传相关配置
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
spring.servlet.multipart.max-file-size=200MB
spring.servlet.multipart.max-request-size=200MB
#配置时间格式
spring.jacksondate-format = yyyy-MM-dd HH:mm:ss
spring.thymeleaf.cache=false
spring.mvc.static-path-pattern=/**
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论