Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
adaptation-master
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
912协同工作系统
项目监控管理工具
adaptation-master
Commits
d6c4f217
提交
d6c4f217
authored
12月 23, 2019
作者:
zhangshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
zs
上级
22122486
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
25 行增加
和
326 行删除
+25
-326
pom.xml
pom.xml
+14
-11
Adaptor.java
...m/zjty/adaptationmaster/adaptor/service/Impl/Adaptor.java
+0
-308
WebSocketConfig.java
.../adaptationmaster/base/configuration/WebSocketConfig.java
+2
-3
Const.java
...main/java/com/zjty/adaptationmaster/base/enums/Const.java
+2
-0
application-dev.properties
src/main/resources/application-dev.properties
+4
-4
application.properties
src/main/resources/application.properties
+3
-0
没有找到文件。
pom.xml
浏览文件 @
d6c4f217
...
...
@@ -13,7 +13,7 @@
<version>
0.0.1-SNAPSHOT
</version>
<name>
adaptation-master
</name>
<description>
Demo project for Spring Boot
</description>
<packaging>
jar
</packaging>
<properties>
<java.version>
1.8
</java.version>
</properties>
...
...
@@ -25,10 +25,10 @@
</dependency>
<!--webSocket 后台向前端推送消息-->
<dependency>
<
!--<
dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependency>
-->
<dependency>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
...
...
@@ -95,11 +95,11 @@
<artifactId>
commons-compress
</artifactId>
<version>
1.8.1
</version>
</dependency>
<dependency>
<!--
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-websocket</artifactId>
<!-- <version>4.3.17.RELEASE</version>-->
</dependency>
<!– <version>4.3.17.RELEASE</version>–>
</dependency>
-->
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
...
...
@@ -131,11 +131,6 @@
<artifactId>
snakeyaml
</artifactId>
<version>
1.25
</version>
</dependency>
<dependency>
<groupId>
org.apache.zookeeper
</groupId>
<artifactId>
zookeeper
</artifactId>
<version>
3.3.4
</version>
</dependency>
<dependency>
<groupId>
ant
</groupId>
<artifactId>
ant
</artifactId>
...
...
@@ -160,6 +155,14 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-surefire-plugin
</artifactId>
<version>
2.5
</version>
<configuration>
<skip>
true
</skip>
</configuration>
</plugin>
</plugins>
</build>
...
...
src/main/java/com/zjty/adaptationmaster/adaptor/service/Impl/Adaptor.java
deleted
100644 → 0
浏览文件 @
22122486
//package com.zjty.adaptationmaster.adaptor.service.Impl;
//
//import com.zjty.adaptationmaster.adaptor.controller.WebSocketServer;
//import com.zjty.adaptationmaster.adaptor.entity.Project;
//import com.zjty.adaptationmaster.adaptor.repository.ProjectDao;
//import com.zjty.adaptationmaster.base.response.ServerResponse;
//import com.zjty.adaptationmaster.utils.ReadedFileTask;
//import com.zjty.adaptationmaster.adaptor.entity.OriginalFile;
//import com.zjty.adaptationmaster.adaptor.entity.Rule;
//import com.zjty.adaptationmaster.base.enums.Const;
//import com.zjty.adaptationmaster.adaptor.repository.OriginalFileDao;
//import com.zjty.adaptationmaster.utils.WriterBySort;
//import lombok.AllArgsConstructor;
//import lombok.Data;
//import lombok.NoArgsConstructor;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.io.*;
//import java.nio.charset.Charset;
//import java.nio.charset.StandardCharsets;
//import java.nio.file.*;
//import java.nio.file.attribute.BasicFileAttributes;
//import java.util.*;
//import java.util.concurrent.ArrayBlockingQueue;
//import java.util.concurrent.ThreadPoolExecutor;
//import java.util.concurrent.TimeUnit;
//
////适应四种规则的适配器,改成只适配java正则的,再util下面
////@Component
//public class Adaptor {
// //@Autowired
// //private AdaptationDetailLogEntityDao adaptationDetailLogEntityDao;
// @Autowired
// private OriginalFileDao originalFileDao;
//
// private ProjectDao projectDao;
//
// private String uuid;
// //@Value("${base.path}")
// private String basePath = Const.CONSOLE;
// //线程池数量,合适的线程数量能让程序更快
// private static final int poolSize = 20;
// //为避免内存溢出,对于超大文件,切分成部分分别读入处理,最后拼接写出
// private static final long LIMIT = 200*1024*1024;
// List<Rule> ruleList;
// Project project;
// //String projectPath;
// //private List<Rule> adaptorEntities = new ArrayList<>();
//
// //public void setProjectPath(String projectPath) {
// // this.projectPath = projectPath;
// //}
//
//
// public void setProject(Project project) {
// this.project = project;
// }
//
// public void setRuleList(List<Rule> ruleList) {
// this.ruleList = ruleList;
// }
//
// public void setUuid(String uuid) {
// this.uuid = uuid;
// }
//
// public ServerResponse doAdapt(){
// //String regular = preprocesAdaptation();
// //List<String> strings1 = preprocessRegular();
// List<MatchAndRule> strings1 = preprocessRegular();
// System.out.println(strings1.size()+"规则数量");
//
// if(strings1.size()<1){
// System.out.println("检测到匹配规则为空");
// return ServerResponse.error("检测到匹配规则为空");
// }
// if(project.getCodeUrl() == null || project.getCodeUrl().equals("")){
// System.out.println("未上传源代码");
// return ServerResponse.error("未上传源代码");
// }
// ThreadPoolExecutor pool = new ThreadPoolExecutor(poolSize,poolSize,10, TimeUnit.SECONDS,new ArrayBlockingQueue<>(poolSize*2));
// pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
// List<OriginalFile> originalFiles = new ArrayList<>();
// //记录实际具体适配内容
// //List<AdaptationDetailsLogEntity> detailsLogEntities = new ArrayList<>();
// ReadedFileRepository repository = new ReadedFileRepository();
// String storePathParent ="originalFile/"+ UUID.randomUUID().toString();
// try {
// Files.walkFileTree(Paths.get(project.getCodeUrl()),new SimpleFileVisitor<Path>() {
// @Override
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//// System.out.println(file);
//// String pathString = file.toString();
//// pathString.indexOf(System.getProperty("file.separator"),basePath.length());
//
// boolean match = false;
// List<Rule> thisFileMatched = null;
// //不符合规则的路径过滤掉
// for(MatchAndRule regular:strings1) {
// //if (FileSystems.getDefault().getPathMatcher("glob:"+regular.getMath()).matches(file)) {
// //直接用java正则
// if (FileSystems.getDefault().getPathMatcher(regular.getMath()).matches(file)) {
// if(thisFileMatched==null)thisFileMatched = new ArrayList<>();
// thisFileMatched.add(regular.getRule());
// match = true;
// }
// }
//
// if(match) {
// //System.out.println("match");
// String storePath = storePathParent+"/"+UUID.randomUUID().toString()+"/"+file.getFileName();
// //原先文件的新地址
// Path originalPath = Paths.get(basePath +storePath);
// File parentFile = originalPath.toFile().getParentFile();
// if(!parentFile.exists()||!parentFile.isDirectory())parentFile.mkdirs();
// OriginalFile originalFile = new OriginalFile(file.toString(),originalPath.toString(),new Date());
// originalFiles.add(originalFile);
// //Files.copy(file,originalPath);
// Files.move(file, originalPath);
// //splitedFile.setDeal(true);
// WebSocketServer.sendInfo(uuid,"过滤得到符合规则的文件" + file,"替换","过滤文件",project.getProjectName());
// //System.out.println();
// if (attrs.size() > LIMIT) {
// System.out.println("找到大文件" + file);
// ReadedLinesRepository linesRepository = new ReadedLinesRepository();
// int i = 0;
// WriterBySort bySort = new WriterBySort();
// File newFile = file.toFile();
// newFile.createNewFile();
// OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(newFile), StandardCharsets.UTF_8);
// bySort.setWriter(writer);
// for (String s : Files.readAllLines(originalPath, Charset.forName("utf-8"))) {
// if (linesRepository.put(s)) {
// List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
// readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
// ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
// apacheTask.setBySort(bySort);
// apacheTask.setIndex(i);
// pool.submit(apacheTask);
// i++;
// }
// }
// List<ReadedFileTask.ReadedFile> readedFiles = new ArrayList<>();
// readedFiles.add(new ReadedFileTask.ReadedFile(linesRepository.getReadedFiles(), attrs, file,thisFileMatched));
// ReadedFileTask apacheTask = new ReadedFileTask(readedFiles,project.getProjectName(),uuid);
// apacheTask.setBySort(bySort);
// apacheTask.setIndex(i);
// pool.submit(apacheTask);
// i++;
// bySort.setSize(i);
// }else {
// String s = new String(Files.readAllBytes(originalPath));
// ReadedFileTask.ReadedFile readedFile = new ReadedFileTask.ReadedFile(s, attrs, file,thisFileMatched);
// if (repository.put(readedFile)) {
// ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
// pool.submit(apacheTask);
// }
// }
// }/*else {
// Files.copy(file, Paths.get(newPath));
// }*/
// return FileVisitResult.CONTINUE;
// }
// });
// System.out.println("遍历结束");
// ReadedFileTask apacheTask = new ReadedFileTask(repository.getReadedFiles(),project.getProjectName(),uuid);
// pool.submit(apacheTask);
// pool.shutdown();
// try {
// pool.awaitTermination(1,TimeUnit.HOURS);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// //originalFileDao.saveAll(originalFiles);
// //adaptationDetailLogEntityDao.saveAll(detailsLogEntities);
// Project one = projectDao.getOne(project.getId());
// one.setStage(1);
// return ServerResponse.success("替换成功",one);
// } catch (IOException e) {
// e.printStackTrace();
// return ServerResponse.error("替换失败");
// }
// }
//
// /**
// * 预处理适配规则,将规则实体类处理成glob表达式
// * @return
// */
// private List<MatchAndRule> preprocessRegular() {
// //List<String> result = new ArrayList<>();
// List<MatchAndRule> result = new ArrayList<>();
// for (Rule adaptorEntity : ruleList) {
// System.out.println(adaptorEntity.getPath());
//// System.out.println(adaptorEntity.getTarget()+"11");
//// System.out.println(adaptorEntity.getPathMatchType());
//// System.out.println(adaptorEntity);
// switch (adaptorEntity.getPathMatchType()) {
// case SUFFIX:
// result.add(new MatchAndRule("**/**" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case PATH:
// result.add(new MatchAndRule("" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case NAME:
// result.add(new MatchAndRule("**/" + adaptorEntity.getPath(),adaptorEntity));
// break;
// case GLOB:
// result.add(new MatchAndRule(adaptorEntity.getPath(),adaptorEntity));
// }
// }
// return result;
// }
//
// /**
// * 对于大文件,按行读取,积攒到一定大小去处理
// * 这里put进来每行
// * 大小不够时返回false
// * 大小够时返回true
// */
// private class ReadedLinesRepository{
// private static final long LIMIT = 200*1024*1024;//字节*k*m
//
// private List<StringBuilder> readedFiles;
// private long count;
//
// public String getReadedFiles() {
// return readedFiles.toString();
// }
//
// public boolean put(String readedFile){
// if(readedFiles==null)readedFiles = new ArrayList<>();
// readedFiles.add(new StringBuilder(readedFile));
// count+=readedFile.length();
// return count > LIMIT;
// }
// }
//
// /**
// * 读取到的大量小文件,积累到一定的大小,才交给一个线程去处理
// */
// private class ReadedFileRepository{
// private List<ReadedFileTask.ReadedFile> readedFiles;
// private long count;
//
// public List<ReadedFileTask.ReadedFile> getReadedFiles() {
// return readedFiles;
// }
//
// public boolean put(ReadedFileTask.ReadedFile readedFile){
// if(readedFiles==null)readedFiles = new ArrayList<>();
// readedFiles.add(readedFile);
// count+=readedFile.getAttributes().size();
// return count > LIMIT;
// }
// }
//
// /**
// * 过大的文件,切割成几块,每块编号,分给每个线程处理,处理结束后,按编号顺序写出
// * 这里按编号控制写出顺序
// */
//// public class WriterBySort{
//// private int currentIndex = -1;
//// private Map<Integer,String> map = new TreeMap<>();
//// private Writer contentWriter;
//// private int size;
////
//// public void setWriter(Writer writer) {
//// this.contentWriter = writer;
//// }
//// public void setSize(int size) {
//// this.size = size;
//// if(currentIndex==size){
//// try {
//// contentWriter.close();
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//// }
//// }
//// public void insert(Integer key, String value){
//// map.put(key,value);
//// while (map.get(currentIndex+1)!=null){
//// try {
//// contentWriter.write(map.remove(currentIndex+1));
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//// currentIndex++;
//// if(currentIndex == size){
//// try {
//// contentWriter.close();
//// } catch (IOException e) {
//// e.printStackTrace();
//// }
//// }
//// }
//// }
//// }
//
// @NoArgsConstructor
// @AllArgsConstructor
// @Data
// private class MatchAndRule{
// private String math;
// private Rule rule;
// }
//}
src/main/java/com/zjty/adaptationmaster/base/configuration/WebSocketConfig.java
浏览文件 @
d6c4f217
...
...
@@ -2,12 +2,11 @@ package com.zjty.adaptationmaster.base.configuration;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.socket.server.standard.ServerEndpointExporter
;
@Configuration
public
class
WebSocketConfig
{
@Bean
/*
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
*/
}
src/main/java/com/zjty/adaptationmaster/base/enums/Const.java
浏览文件 @
d6c4f217
package
com
.
zjty
.
adaptationmaster
.
base
.
enums
;
import
org.apache.tomcat.websocket.server.WsFilter
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Component
;
...
...
src/main/resources/application-dev.properties
浏览文件 @
d6c4f217
# mysql数据库配置
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc
.Driver
spring.datasource.url
=
jdbc:
mysql://localhost:3306/adaptation?useSSL=false&serverTimezone=UTC&characterEncoding=utf-8
spring.datasource.username
=
root
spring.datasource.password
=
root
spring.datasource.driver-class-name
=
org.postgresql
.Driver
spring.datasource.url
=
jdbc:
postgresql://localhost:5866/adaptation
spring.datasource.username
=
sysdba
spring.datasource.password
=
highgo@123
src/main/resources/application.properties
浏览文件 @
d6c4f217
...
...
@@ -38,6 +38,9 @@ spring.thymeleaf.cache=false
spring.mvc.static-path-pattern
=
/**
spring.resources.static-locations
=
classpath:/uploads/
spring.jpa.properties.hibernate.dialect
=
org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults
=
false
#highgo
highgo.driver
=
org.postgresql.Driver
highgo.connectionType
=
postgresql
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论