提交 43095f76 authored 作者: wyl's avatar wyl

init

上级
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
### VS Code ###
.vscode/
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.5";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar
差异被折叠。
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.zjty</groupId>
<artifactId>adaptation-master</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>adaptation-master</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package com.zjty.adaptationmaster;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AdaptationMasterApplication {
public static void main(String[] args) {
SpringApplication.run(AdaptationMasterApplication.class, args);
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdaptorEntity {
/**
* 匹配模式及处理方式
* 文件匹配模式
* https://blog.csdn.net/qq_36263601/article/details/74260553
* 文本位置匹配模式
* 全文匹配
* 文本处理模式
* 全文替换
*/
private MatchType matchType;//匹配方式
private String parent;//文件路径匹配
private String matching;//文本匹配
private String replacing;//更改方式
}
package com.zjty.adaptationmaster.adaptor.enginer;
import com.zjty.adaptation.adaptor.enginer.util.StringCompareUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class ApacheTask implements Runnable {
private List<File> file1;
private List<AdaptorEntity> adaptorEntities;
public void setFile(List<File> file) {
this.file1 = file;
}
/**
* 规则示例1
* 将/src/com/zjty/hrmanager/util/BeginYearClear下的
* import org.slf4j.Logger;改为import org.apache.log4j.Logger
*
*
* 规则示例2
* 将pom.xml文件中的mysql依赖改为postgresql依赖
*
* 规则示例3
* 将数据库实体类所映射的表明 table1 改为 table2
*
* 规则示例4
* 将前端代码中请求地址192.168.1.81:8011/***改为192.168.1.81:6888/hrm/***
*
* 规则示例5
*
*/
//对于 处理规则 的预处理
public void preAdaptation(){
for(AdaptorEntity adaptorEntity:adaptorEntities){
switch (adaptorEntity.getMatchType()){
case ALL:
}
}
}
@Override
public void run() {
try {
for (File file:file1) {
//List<String> stringList = FileUtils.readLines(file, "utf-8");
// String s = FileUtils.readFileToString(file, "utf-8");
// if(KMP.kmpMatch(s,"一二三四五")==-1){
//
// }
LineIterator lineIterator = FileUtils.lineIterator(file, "gbk");
while (lineIterator.hasNext()) {
int index = /*KMP.kmpMatch*/StringCompareUtil.compare(lineIterator.next(), "2019-11-27 13:55:36,648 INFO [DefaultSoapUICore] Settings saved to [C:\\Users\\wyl\\soapui-setting中华s.xml]");
if(index>-1){
System.out.println("存在");
}
//System.out.println(lineIterator.next());
//if(lineIterator.next().contains("tyConfig extends WebSecurityConfigurerAdapte")){
// if (lineIterator.next().indexOf("一二三四五")!=-1) {
//
// System.out.println("存在");
// }
// if(lineIterator.next().contains("\\u4e00\\u4e8c\\u4e09\\u56db\\u4e94")){
// System.out.println("存在2");
// }
//
// if(lineIterator.next().contains("liuqibajiushi")){
// System.out.println("存在1");
// }
}
//for(String s:stringList){
// if(s.contains(" LOGINUSER = \"loginuser\"; //ca")){
// System.out.println("存在");
// }
//}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
public class Counter {
private int i = 0;
public void plus(){
i++;
}
public int getI() {
return i;
}
public void reset(){
i = 0;
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import org.apache.commons.io.FileUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.*;
public class Engine {
//判断一个文件够不够称作大文件的阈值,大文件单独占用一个线程,小文件凑够阈值合用一个线程
private final static long LIMIT = 200*1024;
private String path;
private String projectName;
private List<AdaptorEntity> adaptorEntities;
private ThreadPoolExecutor pool;
public int threadNum;
public void setPath(String path) {
this.path = path;
}
public void setProjectName(String name){
this.projectName = name;
}
public void initAdaptorEntities(List adaptorEntities){
this.adaptorEntities = adaptorEntities;
}
public void setThreadNum(int threadNum) {
this.threadNum = threadNum;
}
public void addAdaptorEntities(List adaptorEntities){
if(this.adaptorEntities == null)this.adaptorEntities = new ArrayList<>();
this.adaptorEntities.addAll(adaptorEntities);
}
long beginTime ;
public void enginer(){
pool = new ThreadPoolExecutor(threadNum, threadNum, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(400));
pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
beginTime = System.currentTimeMillis();
System.out.println(beginTime+"开始时间,线程池数量"+threadNum);
doDir(path);
pool.shutdown();
try {
//该方法会被阻塞,直到子线程全部执行完毕,并且shutdown()方法被调用,或者等待时间超时。这里等待时间设置一小时
pool.awaitTermination(1,TimeUnit.HOURS);
} catch (InterruptedException e) {
e.printStackTrace();
}
long l = System.currentTimeMillis();
System.out.println("所有线程执行完毕"+l+"总时间差"+(l-beginTime));
}
final Counter i = new Counter();
SmallFileRepository repository = new SmallFileRepository();
private void doDir(String path){
//final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:**/*.{java,txt,properties}");
//Collection<File> files = FileUtils.listFiles(new File(path), null, true);
Iterator<File> fileIterator = FileUtils.iterateFiles(new File(path), new String[]{"java","txt","properties"}, true);
while (fileIterator.hasNext()){
File next = fileIterator.next();
long length = next.length();
if(length>LIMIT) {
System.out.println("大文件出没");
List<File> files = new ArrayList<>();
files.add(next);
execute(files);
} else {
repository.fileList.add(next);
repository.length+=length;
if(repository.length>LIMIT){
execute(repository.fileList);
repository.length=0;
repository.fileList = new ArrayList<>();
}
}
i.plus();
//List<String> stringList = FileUtils.readLines(fileIterator.next(), "utf-8");
//execute(stringFactory);
}
// try {
// Files.walkFileTree(Paths.get(path),new SimpleFileVisitor<Path>(){
// @Override
// public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//
// StringTask task = new StringTask(file,pathMatcher);
// execute(task);
// i.plus();
// //过滤文件名后缀
//// if(pathMatcher.matches(file)){
//// i.plus();
//// List<String> list = Files.readAllLines(file);
//// if(list.size()>200){
//// //System.out.println("文件够大,开线程"+file);
//// execute(new StringFactory().setProduct(list));
//// //new StringFactory().setProduct(list).run();
//// }else {
//// //System.out.println("文件不够大,存起来"+file);
//// stringList.addAll(list);
//// if(stringList.size()>200){
//// //System.out.println("存够了,开线程");
//// ArrayList<String> strings = new ArrayList<>();
//// strings.addAll(stringList);
//// execute(new StringFactory().setProduct(strings));
//// //new StringFactory().setProduct(strings).run();
//// stringList.clear();
//// }
//// }
//// }
// return FileVisitResult.CONTINUE;
// }
// @Override
// public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
// return FileVisitResult.CONTINUE;
// }
//};
// if(stringList.size()>0){
// ArrayList<String> strings = new ArrayList<>();
// strings.addAll(stringList);
// execute(new StringFactory().setProduct(strings));
// //new StringFactory().setProduct(strings).run();
// }
long endTime = System.currentTimeMillis();
System.out.println(endTime+"结束时间");
System.out.println(i.getI()+"处理总数量");
System.out.println((endTime-beginTime)+"时间差");
i.reset();
}
List<Runnable> rejectedTask = new ArrayList<>();
private void execute(List<File> files){
ApacheTask stringFactory = new ApacheTask();
stringFactory.setFile(files);
pool.submit(stringFactory);
}
/**
* 文件如果过小,先存起来,大小存够了再交给一个线程去处理
*/
private class SmallFileRepository{
public long length = 0;
public List<File> fileList = new ArrayList<>();
}
public static void main(String[] args) {
Engine engine = new Engine();
engine.setPath("C:\\Users\\wyl\\Desktop\\testReplace");
//engine.setPath("C:\\Users\\wyl\\Desktop\\testReplace\\testReplace1\\java\\com\\zjty\\hrmanager\\base\\request");
engine.setProjectName("testReplace");
List<AdaptorEntity> adaptorEntities = new ArrayList<>();
adaptorEntities.add(new AdaptorEntity(MatchType.ALL,"**/resources/*.properties","log4j","log5j"));
engine.initAdaptorEntities(adaptorEntities);
for(int i = 10;i<200;i++){
engine.setThreadNum(i);
engine.enginer();
}
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
public class Engine1 {
private static final String path = "C:\\Users\\wyl\\Desktop\\testReplace";
private long totalSize;
private ReadedFileRepository repository = new ReadedFileRepository();
public void readFile(){
//List<>
try {
Files.walkFileTree(Paths.get(path),new SimpleFileVisitor<Path>(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String s = new String(Files.readAllBytes(file));
ReadedFile readedFile = new ReadedFile(s,attrs);
if(repository.put(readedFile)){
ApacheTask apacheTask = new ApacheTask();
apacheTask.setFile(repository.getReadedFiles());
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
//先把文件读取到内存中
private class ReadedFileRepository{
private static final long LIMIT = 200*1024*1024;//字节*k*m
private List<ReadedFile> readedFiles;
private long count;
public List<ReadedFile> getReadedFiles() {
return readedFiles;
}
public boolean put(ReadedFile readedFile){
if(readedFile==null)readedFiles = new ArrayList<>();
readedFiles.add(readedFile);
count+=readedFile.getAttributes().size();
if(count>LIMIT){
return true;
}
return false;
}
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class KMP {
/**
* 求出一个字符数组的next数组
* @param t 字符数组
* @return next数组
*/
public static int[] getNextArray(char[] t) {
int[] next = new int[t.length];
next[0] = -1;
next[1] = 0;
int k;
for (int j = 2; j < t.length; j++) {
k=next[j-1];
while (k!=-1) {
if (t[j - 1] == t[k]) {
next[j] = k + 1;
break;
}
else {
k = next[k];
}
next[j] = 0; //当k==-1而跳出循环时,next[j] = 0,否则next[j]会在break之前被赋值
}
}
return next;
}
/**
* 对主串s和模式串t进行KMP模式匹配
* @param s 主串
* @param t 模式串
* @return 若匹配成功,返回t在s中的位置(第一个相同字符对应的位置),若匹配失败,返回-1
*/
public static int kmpMatch(String s, String t){
char[] s_arr = s.toCharArray();
char[] t_arr = t.toCharArray();
int[] next = getNextArray(t_arr);
int i = 0, j = 0;
while (i<s_arr.length && j<t_arr.length){
if(j == -1 || s_arr[i]==t_arr[j]){
i++;
j++;
}
else
j = next[j];
}
if(j == t_arr.length)
return i-j;
else
return -1;
}
public static void main(String[] args) {
String path = "C:\\Users\\wyl\\Desktop\\testReplace\\testReplace1\\java\\soapui.properties";
try {
System.out.println(kmpMatch(new String(Files.readAllBytes(Paths.get(path))), "2019-11-27 13:55:36,631 INFO [WorkspaceImpl] Saved workspace to [C:\\Users\\wyl\\intellij-soapui-workspace.xml]\n" +
"2019-11-27 13:55:36,648 INFO [DefaultSoapUICore] Settings saved to [C:\\Users\\wyl\\soapui-setting中华s.xml]"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
package com.zjty.adaptationmaster.adaptor.enginer;
public enum MatchType {
ALL,PATTERN
}
package com.zjty.adaptationmaster.adaptor.enginer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.nio.file.attribute.BasicFileAttributes;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ReadedFile {
private String content;
private BasicFileAttributes attributes;
}
package com.zjty.adaptationmaster.adaptor.enginer;
import java.util.List;
public class ReadedFileTask implements Runnable {
private List<ReadedFile> readedFiles;
@Override
public void run() {
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import java.util.List;
public class StringFactory implements Runnable {
private List<String> product;
public StringFactory setProduct(List<String> product) {
this.product = product;
return this;
}
@Override
public void run() {
//System.out.println("我开始处理了+++"+Thread.currentThread().getName()+System.currentTimeMillis());
for(String s:product){
if(s.contains("一二三四五")){
System.out.println("包含");
}
int i = 0;
while (true){
i++;
}
// try {
// Object o = new Object();
// synchronized (o) {
// o.wait(20);
// }
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
product.clear();
//System.out.println("我处理完了---"+Thread.currentThread().getName()+"\t"+System.currentTimeMillis());
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import lombok.AllArgsConstructor;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.util.List;
@AllArgsConstructor
public class StringTask implements Runnable {
private Path path;
private PathMatcher pathMatcher;
@Override
public void run() {
//过滤文件名后缀
if(pathMatcher.matches(path)){
List<String> list = null;
try {
list = Files.readAllLines(path);
for (String s:list){
if(s.contains("一二三四五")){
System.out.println("包含");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
package com.zjty.adaptationmaster.adaptor.enginer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TimeAreaEngine {
public static void main(String[] args) {
TimeAreaEngine engine = new TimeAreaEngine();
engine.setPath("C:\\Users\\wyl\\Desktop\\testReplace");
engine.setProjectName("testReplace");
List<AdaptorEntity> adaptorEntities = new ArrayList<>();
adaptorEntities.add(new AdaptorEntity(null,"log4j",null,"log5j"));
engine.setAdaptorEntities(adaptorEntities);
engine.enginer();
}
private String path;
private List<AdaptorEntity> adaptorEntities;
private static final int THREADCOUNT = 4;
private String projectName;
public void enginer(){
try {
Iterator<File> fileIterator = FileUtils.iterateFiles(new File(path), new String[]{"java", "txt", "properties"}, true);
while (fileIterator.hasNext()){
List<String> stringList = FileUtils.readLines(fileIterator.next(), "utf-8");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.zjty.adaptationmaster.adaptor.enginer.examination;
import com.zjty.adaptation.adaptor.enginer.Counter;
import com.zjty.adaptation.adaptor.enginer.util.StringCompareUtil;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 项目体检,根据既定特征值,
* 扫描、统计、分析项目特征,
* 生成报告
*
*/
public class Inspectors {
private String path;
private Map<String, Counter> matchMap;
private List<Path> propertiesConfigPaths = new ArrayList<>();
private List<Path> ymlConfigPaths = new ArrayList<>();
private List<Path> xmlConfigPaths = new ArrayList<>();
private Report report = new Report();
public void setPath(String path) {
this.path = path;
}
public void setMatchMap(Map<String, Counter> matchMap) {
this.matchMap = matchMap;
}
public static void main(String[] args) {
Inspectors inspectors = new Inspectors();
inspectors.setPath("C:\\Users\\wyl\\Desktop\\testReplace");
Map<String,Counter> map = new HashMap<>();
map.put("java",new Counter());
map.put("jsp",new Counter());
map.put("html",new Counter());
inspectors.setMatchMap(map);
inspectors.inspect();
//打印分析数据
for(Map.Entry<String,Counter> entry:map.entrySet()) {
System.out.println("项目中"+entry.getKey()+"类型文件共有" + entry.getValue().getI()+"个");
}
//打印体检报告
System.out.println(inspectors.analysis());
}
/**
* FileVisitResult.CONTINUE 继续遍历
* FileVisitResult.TERMINATE 中止访问
* FileVisitResult.SKIP_SIBLINGS 不访问同级的文件或目录
* FileVisitResult.SKIP_SUBTREE 不访问子目录
*/
public void inspect(){
try {
String glob = "glob:**/*.txt";
final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher( glob);
Files.walkFileTree(Paths.get(path), new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
//判断后缀
for (Map.Entry<String, Counter> s : matchMap.entrySet()) {
if (dir.endsWith(s.getKey())) {
s.getValue().plus();
}
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
boolean matches = pathMatcher.matches(file);
if (file.endsWith("properties")) {
propertiesConfigPaths.add(file);
}
if(file.endsWith("yml")){
ymlConfigPaths.add(file);
}
if(file.endsWith("xml")){
xmlConfigPaths.add(file);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
public Report analysis(){
if(matchMap.get("java").getI()>0){
report.setType("java");
}
if(matchMap.get("jsp").getI()>0){
report.setStructure("whole");
}
if(matchMap.get("html").getI()>0){
report.setStructure("separation");
}
for(Path path:propertiesConfigPaths){
try {
for(String s:Files.readAllLines(path)){
int index = StringCompareUtil.compare(s, "spring.datasource.driver-class-name");
if(index >- 1){
if(!s.startsWith("#")){
/**
* MySQL数据库:
*
*     1)驱动包:https://mvnrepository.com/artifact/mysql/mysql-connector-java(下载路径)
*
*     2)驱动类名:com.mysql.jdbc.Driver
*
*     3)JDBC的URL:jdbc:mysql://IP地址:端口号/数据库名字
*
*      注:端口号缺省为:3306
*
* SQL server数据库:
*
*     1)驱动包:https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4(下载路径)
*
*     2)驱动类名:com.microsoft.jdbc.sqlserver.SQLServerDriver
*
*     3)JDBC的URL:jdbc:microsoft:sqlserver://IP地址:端口号;DatabaseName=数据库名
*
*     4)sqljdbc和sqljdbc4区别:https://blog.csdn.net/cainiao_M/article/details/53404222
*
*     注:端口号缺省为:1433
*
* Oracle数据库:
*
*     1)驱动包:https://mvnrepository.com/artifact/com.oracle/ojdbc6(下载路径)
*
*     2)驱动类名:oracle.jdbc.driver.OracleDriver
*
*     3)JDBC的URL:jdbc:oracle:thin:@IP地址:端口号:数据库名
*
*     4)ojdbc6和ojdbc14的区别:ojdbc14.jar(适合java-1.4和1.5),ojdbc6(适合java-1.6)
*
*     注:端口号缺省为:1521
*/
if(StringCompareUtil.compare(s, "mysql")>-1){
report.setSqlType("mysql");
}else if(StringCompareUtil.compare(s, "sqlserver")>-1){
report.setSqlType("SQLServer");
}else if(StringCompareUtil.compare(s, "oracle")>-1){
report.setSqlType("oracle");
}else if(StringCompareUtil.compare(s, "postgre")>-1){
report.setSqlType("postgre");
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
package com.zjty.adaptationmaster.adaptor.enginer.examination;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Report {
public String type;//语言类型
public String structure;//项目架构
public String sqlType;//数据库类型
@Override
public String toString(){
return ""+type+structure+sqlType;
}
}
package com.zjty.adaptationmaster.adaptor.enginer.exception;
public class FileTypeNotMatchException extends Exception {
public FileTypeNotMatchException(){
super();
}
public FileTypeNotMatchException(String message){
super(message);
}
public FileTypeNotMatchException(String message,Throwable cause){
super(message,cause);
}
public FileTypeNotMatchException(Throwable cause){
super(cause);
}
}
package com.zjty.adaptationmaster.adaptor.enginer.util;
public class StringCompareUtil {
/**
* 长字符串中是否包含arg2
* 原生方法速度慢
* 用kmp重写之
*
*
* @param text
* @param pattern
* @return
*/
public static int compare(String text,String pattern){
//return text.indexOf(pattern);
return KMP(text,pattern);
}
//KMP算法实现
private static int KMP(String source, String pattern) {
int[] N=getN(pattern);
int res=0;
int sourceLength=source.length();
int patternLength=pattern.length();
for(int i=0;i<=(sourceLength-patternLength);){
res++;
String str=source.substring(i, i+patternLength);//要比较的字符串
p(str);
int count=getNext(pattern, str,N);
p("移动"+count+"步");
if(count==0){
p("KMP:匹配成功");
//break;
return i;
}
i=i+count;
}
p("KMP:一共匹配"+res+"次数");
return -1;
}
/**
* 得到下一次要移动的次数
*
* @param pattern
* @param str
* @param N
* @return 0,字符串匹配;
*/
private static int getNext(String pattern,String str,int[] N) {
int n = pattern.length();
char v1[] = str.toCharArray();
char v2[] = pattern.toCharArray();
int x = 0;
while (n-- != 0) {
if (v1[x] != v2[x]){
if(x==0){
return 1;//如果第一个不相同,移动1步
}
return x-N[x-1];//x:第一次出现不同的索引的位置,即j
}
x++;
}
return 0;
}
private static int[] getN(String pattern) {
char[] pat=pattern.toCharArray();
int j=pattern.length()-1;
int[] N=new int[j+1];
for(int i=j;i>=2;i--){
N[i-1]=getK(i,pat);
}
for(int a:N)
p(a);
return N;
}
private static int getK(int j, char[] pat) {
int x=j-2;
int y=1;
while (x>=0 && compare(pat, 0, x, y, j-1)) {
x--;
y++;
}
return x+1;
}
private static boolean compare(char[] pat,int b1,int e1,int b2,int e2){
int n = e1-b1+1;
while (n-- != 0) {
if (pat[b1] != pat[b2]){
return true;
}
b1++;
b2++;
}
return false;
}
public static void p(Object obj) {
//System.out.println(obj);
}
}
package com.zjty.adaptationmaster.adaptor.enginer.util;
public class StringCompareUtil1 {
/**
* 长字符串中是否包含arg2
* 原生方法速度慢
* 用kmp重写之
*
*
* @param text
* @param pattern
* @return
*/
public int compare(String text,String pattern){
//return text.indexOf(pattern);
return KMP(text,pattern);
}
//KMP算法实现
private int KMP(String source, String pattern) {
int[] N=getN(pattern);
int res=0;
int sourceLength=source.length();
int patternLength=pattern.length();
for(int i=0;i<=(sourceLength-patternLength);){
res++;
String str=source.substring(i, i+patternLength);//要比较的字符串
int count=getNext(pattern, str,N);
if(count==0){
return i;
}
i=i+count;
}
return -1;
}
/**
* 得到下一次要移动的次数
*
* @param pattern
* @param str
* @param N
* @return 0,字符串匹配;
*/
private int getNext(String pattern,String str,int[] N) {
int n = pattern.length();
char v1[] = str.toCharArray();
char v2[] = pattern.toCharArray();
int x = 0;
while (n-- != 0) {
if (v1[x] != v2[x]){
if(x==0){
return 1;//如果第一个不相同,移动1步
}
return x-N[x-1];//x:第一次出现不同的索引的位置,即j
}
x++;
}
return 0;
}
private int[] getN(String pattern) {
char[] pat=pattern.toCharArray();
int j=pattern.length()-1;
int[] N=new int[j+1];
for(int i=j;i>=2;i--){
N[i-1]=getK(i,pat);
}
return N;
}
/**
*
* @param j 匹配字符长度-1,递减
* @param pat
* @return
*/
private int getK(int j, char[] pat) {
int x=j-2;//匹配字符长度-3
int y=1;
while (x>=0 && compare(pat, 0, x, y, j-1)) {
x--;
y++;
}
return x+1;
}
//逐字匹配,发现不对,返回true
private boolean compare(char[] pat,int b1,int e1,int b2,int e2){
int n = e1-b1+1;
while (n-- != 0) {
if (pat[b1] != pat[b2]){
return true;
}
b1++;
b2++;
}
return false;
}
}
package com.zjty.adaptationmaster;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class AdaptationMasterApplicationTests {
@Test
void contextLoads() {
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论