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

合并分支 'zs' 到 'master'

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