提交 4f93a29f authored 作者: 王林巧's avatar 王林巧

init

上级
/target/
!.mvn/wrapper/maven-wrapper.jar
/logs/
/errorLogs/
.mvn/
mvnw
mvnw.cmd
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
/**/*.yml
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
target
report-web/logs
#/report-web/src/main/resources/bootstrap.yml
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.msl</groupId>
<artifactId>jdk17-update</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
</dependency>
<dependency>
<groupId>org.javatuples</groupId>
<artifactId>javatuples</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext7-core</artifactId>
<version>7.2.3</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.15.3</version>
</dependency>
<dependency>
<groupId>org.xhtmlrenderer</groupId>
<artifactId>flying-saucer-pdf</artifactId>
<version>9.1.22</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>html2pdf</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.3.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.msl;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
/**
* @author wanglq
* Date 2024/8/7
* Time 13:23
*/
@Getter
@Setter
public class FileContext {
private File file;
private String content;
private String fileName;
public FileContext(File file) throws IOException {
this.file = file;
this.fileName = file.getName();
content = FileUtils.readFileToString(file, "UTF-8");
}
}
package com.msl;
/**
* @author wanglq
* Date 2024/8/7
* Time 13:26
*/
public interface FileUpdater {
/**
* 能否更新文件
*
* @param context 文件上下文
* @return 能否更新
*/
boolean canApply(FileContext context);
/**
* 更新文件上下文
*
* @param context 文件上下文
*/
void update(FileContext context);
}
package com.msl;
import com.msl.java.JavaNormalUpdater;
import com.msl.xml.XmlNormalUpdater;
import java.util.ArrayList;
import java.util.List;
/**
* @author wanglq
* Date 2024/8/7
* Time 13:53
*/
public class FileUpdaterManager {
private final static List<FileUpdater> UPDATERS = new ArrayList<>();
static {
register(new XmlNormalUpdater());
register(new JavaNormalUpdater());
// register(new FeignClassAnnotationUpdater());
// register(new FeignMethodAnnotationUpdater1());
// register(new FeignMethodAnnotationUpdater2());
}
public static void register(FileUpdater fileUpdater) {
UPDATERS.add(fileUpdater);
}
public static void update(FileContext context) {
for (FileUpdater updater : UPDATERS) {
if (updater.canApply(context)) {
updater.update(context);
}
}
}
}
package com.msl;
import com.google.common.collect.Sets;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.Set;
/**
* @author wanglq
* Date 2024/8/2
* Time 17:06
*/
public class Main {
public static Set<String> ignorePath = Sets.newHashSet();
static {
ignorePath.add(".git");
ignorePath.add(".idea");
}
public static void main(String[] args) throws Exception {
// doReplace("D:\\develop\\clx_projects\\msl-supervise\\supervise-web");
// doReplace("D:\\develop\\clx_projects\\msl-common-starter\\log-spring-boot-starter");
doReplace("D:\\develop\\clx_projects\\msl-supervise-trade");
}
public static void doReplace(String path) throws Exception {
File file = new File(path);
if (!file.exists()) {
System.out.println("路径不存在,无法替换……");
}
doReplace(file);
}
public static void doReplace(File file) throws Exception {
if (file.isFile()) {
FileContext context = new FileContext(file);
System.out.println("处理文件:" + file.getName());
FileUpdaterManager.update(context);
//写回文件
FileUtils.write(file, context.getContent(), "UTF-8");
} else {
if (ignorePath.contains(file.getName())) {
return;
}
for (File childFile : file.listFiles()) {
doReplace(childFile);
}
}
}
}
\ No newline at end of file
package com.msl;
import org.javatuples.Pair;
import java.util.List;
/**
* @author wanglq
* Date 2024/8/7
* Time 14:06
*/
public abstract class NormalUpdater implements FileUpdater {
/**
* 更新文件上下文
*
* @param context 文件上下文
*/
@Override
public void update(FileContext context) {
String content = context.getContent();
for (Pair<String, String> pair : replaceList()) {
content = content.replace(pair.getValue0(), pair.getValue1());
}
context.setContent(content);
}
protected abstract List<Pair<String, String>> replaceList();
}
package com.msl;
import java.util.Iterator;
import java.util.ServiceLoader;
/**
* @author wanglq
* Date 2024/8/7
* Time 13:36
*/
public class Test {
public static void main(String[] args) {
ServiceLoader<FileUpdater> loaders = ServiceLoader.load(FileUpdater.class);
Iterator<FileUpdater> iterator = loaders.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}
package com.msl;
/**
* @author wanglq
* Date 2024/8/7
* Time 16:02
*/
public class Test2 {
}
package com.msl;
import com.itextpdf.html2pdf.HtmlConverter;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.FileOutputStream;
import java.io.IOException;
public class WebPageToPdf {
public static void main(String[] args) {
String url = "http://ams-open.devclx.cn/in-store/I2405000001"; // 替换为你想要转换的 URL
String pdfPath = "d:/pdf/output1.pdf";
// 设置 ChromeDriver
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
WebDriver driver = new ChromeDriver(options);
try {
// 加载网页
driver.get(url);
// 等待动态内容加载
Thread.sleep(1000);
// 获取网页内容
String htmlContent = driver.getPageSource();
// 将HTML转换为PDF
try (FileOutputStream fileOutputStream = new FileOutputStream(pdfPath)) {
HtmlConverter.convertToPdf(htmlContent, fileOutputStream);
}
System.out.println("PDF created successfully at " + pdfPath);
} catch (InterruptedException | IOException e) {
e.printStackTrace();
} finally {
// 关闭浏览器
driver.quit();
}
}
}
package com.msl.java;
import com.msl.FileContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author wanglq
* Date 2024/8/7
* Time 9:01
*/
public class FeignClassAnnotationUpdater implements FeignUpdater {
private final Pattern pattern = Pattern.compile("@FeignClient\\(name\\s*=\\s*\"([^\"]+)\"\\)\\s+@RequestMapping\\(\"([^\"]+)\"\\)");
/**
* 更新文件上下文
*
* @param context 文件上下文
*/
@Override
public void update(FileContext context) {
context.setContent(replaceAnnotation(context.getContent()));
}
private String replaceAnnotation(String content) {
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
// 获取第一个捕获组的值,即 服务名
String nameValue = matcher.group(1);
// 获取第二个捕获组的值,即 路径
String pathValue = matcher.group(2);
// 构造替换后的注解内容
String replaced = String.format("@FeignClient(name = \"%s\", path = \"%s\")", nameValue, pathValue);
// 替换原始文本中匹配的部分
return matcher.replaceFirst(replaced);
}
// 如果没有匹配到则返回原始输入
return content;
}
}
package com.msl.java;
import com.msl.FileContext;
import java.util.regex.*;
/**
* @author wanglq
* Date 2024/8/7
* Time 9:06
*/
public class FeignMethodAnnotationUpdater1 implements FeignUpdater {
public final Pattern pattern = Pattern.compile("@RequestMapping\\(method = RequestMethod.(GET|POST),\\s+value = \"([^\"]+)\"\\)");
public static void main(String[] args) {
// 原始的方法上注解内容
String originalAnnotation = "@RequestMapping(method = RequestMethod.POST, value = \"/uploadUrl\")\n" +
" afaf @RequestMapping(method = RequestMethod.POST, value = \"/uploadUrl2222\")\n" +
" asdfs @RequestMapping(method = RequestMethod.POST, value = \"/uploadUrl333\")";
// 替换后的内容
String replacedAnnotation = new FeignMethodAnnotationUpdater1().replaceAnnotation(originalAnnotation);
System.out.println("替换后的注解内容:");
System.out.println(replacedAnnotation);
}
/**
* 更新文件上下文
*
* @param context 文件上下文
*/
@Override
public void update(FileContext context) {
context.setContent(replaceAnnotation(context.getContent()));
}
public String replaceAnnotation(String input) {
StringBuffer sb = new StringBuffer();
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
// 获取第一个捕获组的值,即 "POST"
String methodValue = matcher.group(1);
// 获取第二个捕获组的值,即 "/msl-user/product/listProducts"
String pathValue = matcher.group(2);
// 构造替换后的注解内容
String annotationType = methodValue.equals("GET") ? "@GetMapping" : "@PostMapping";
String replaced = String.format("%s(\"%s\")", annotationType, pathValue);
// 替换原始文本中匹配的部分
matcher.appendReplacement(sb, replaced);
}
// 将剩余部分追加到结果中
matcher.appendTail(sb);
// 如果没有匹配到则返回原始输入
return sb.toString();
}
}
package com.msl.java;
import com.msl.FileContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author wanglq
* Date 2024/8/7
* Time 9:06
*/
public class FeignMethodAnnotationUpdater2 implements FeignUpdater {
public final Pattern pattern = Pattern.compile("@RequestMapping\\(value = \"([^\"]+)\",\\s+method = RequestMethod.(GET|POST)\\)");
public static void main(String[] args) {
// 原始的方法上注解内容
String originalAnnotation = " 12341234 @RequestMapping(value = \"/uploadBase64\", method = RequestMethod.POST)\n" +
" adf @RequestMapping(value = \"/uploadBase64111\", method = RequestMethod.POST)\n" +
" 3241zsdf1234 @RequestMapping(value = \"/uploadBase642222\", method = RequestMethod.POST)";
// 替换后的内容
String replacedAnnotation = new FeignMethodAnnotationUpdater2().replaceAnnotation(originalAnnotation);
System.out.println("替换后的注解内容:");
System.out.println(replacedAnnotation);
}
/**
* 更新文件上下文
*
* @param context 文件上下文
*/
@Override
public void update(FileContext context) {
context.setContent(replaceAnnotation(context.getContent()));
}
public String replaceAnnotation(String input) {
StringBuffer sb = new StringBuffer();
Matcher matcher = pattern.matcher(input);
while (matcher.find()) {
// 获取第一个捕获组的值,即 "/msl-user/product/listProducts"
String pathValue = matcher.group(1);
// 获取第二个捕获组的值,即 "POST"
String methodValue = matcher.group(2);
// 构造替换后的注解内容
String annotationType = methodValue.equals("GET") ? "@GetMapping" : "@PostMapping";
String replaced = String.format("%s(\"%s\")", annotationType, pathValue);
// 替换原始文本中匹配的部分
matcher.appendReplacement(sb, replaced);
}
// 将剩余部分追加到结果中
matcher.appendTail(sb);
// 如果没有匹配到则返回原始输入
return sb.toString();
}
}
package com.msl.java;
import com.msl.FileContext;
import com.msl.FileUpdater;
/**
* @author wanglq
* Date 2024/8/7
* Time 14:26
*/
public interface FeignUpdater extends FileUpdater {
/**
* 能否更新文件
*
* @param context 文件上下文
* @return 能否更新
*/
@Override
default boolean canApply(FileContext context) {
return context.getFileName().endsWith("Feign.java")
&& context.getFile().getParent().endsWith("feign");
}
}
package com.msl.java;
import com.google.common.collect.Lists;
import com.msl.FileContext;
import com.msl.NormalUpdater;
import org.javatuples.Pair;
import java.util.List;
/**
* @author wanglq
* Date 2024/8/7
* Time 14:05
*/
public class JavaNormalUpdater extends NormalUpdater {
public static final List<Pair<String, String>> LIST = Lists.newArrayList();
static {
// javax 相关
LIST.add(Pair.with("import javax.servlet", "import jakarta.servlet"));
LIST.add(Pair.with("import javax.validation", "import jakarta.validation"));
// swagger 相关
LIST.add(Pair.with("import io.swagger.annotations.ApiModelProperty;", "import io.swagger.v3.oas.annotations.media.Schema;"));
LIST.add(Pair.with("@ApiModelProperty(value", "@Schema(description"));
LIST.add(Pair.with("@ApiModelProperty(\"", "@Schema(description=\""));
LIST.add(Pair.with("@ApiModelProperty(hidden = true)", "@Schema(hidden = true)"));
LIST.add(Pair.with("import io.swagger.annotations.Api;", "import io.swagger.v3.oas.annotations.tags.Tag;"));
LIST.add(Pair.with("@Api(value", "@Tag(name"));
LIST.add(Pair.with("@Api(tags", "@Tag(name"));
LIST.add(Pair.with("import io.swagger.annotations.ApiOperation;", "import io.swagger.v3.oas.annotations.Operation;"));
LIST.add(Pair.with("@ApiOperation(value", "@Operation(summary"));
LIST.add(Pair.with("@ApiOperation(\"", "@Operation(summary = \""));
LIST.add(Pair.with("notes = \"", "description = \""));
LIST.add(Pair.with("import io.swagger.annotations.ApiParam;", "import io.swagger.v3.oas.annotations.Parameter;"));
LIST.add(Pair.with("@ApiParam(\"", "@Parameter(name = \""));
}
@Override
protected List<Pair<String, String>> replaceList() {
return LIST;
}
/**
* 能否更新文件
*
* @param context 文件上下文
* @return 能否更新
*/
@Override
public boolean canApply(FileContext context) {
return context.getFileName().endsWith(".java");
}
}
package com.msl.xml;
import com.msl.FileContext;
import com.msl.NormalUpdater;
import org.javatuples.Pair;
import java.util.ArrayList;
import java.util.List;
/**
* @author wanglq
* Date 2024/8/7
* Time 13:20
*/
public class XmlNormalUpdater extends NormalUpdater {
public static final List<Pair<String, String>> LIST = new ArrayList<>();
static {
//jdk相关
LIST.add(Pair.with("<maven.compiler.source>8</maven.compiler.source>", "<maven.compiler.source>17</maven.compiler.source>"));
LIST.add(Pair.with("<maven.compiler.target>8</maven.compiler.target>", "<maven.compiler.target>17</maven.compiler.target>"));
LIST.add(Pair.with("<groupId>javax.validation</groupId>", "<groupId>jakarta.validation</groupId>"));
LIST.add(Pair.with("<artifactId>validation-api</artifactId>", "<artifactId>jakarta.validation-api</artifactId>"));
//druid
LIST.add(Pair.with("<artifactId>druid-spring-boot-starter</artifactId>", "<artifactId>druid-spring-boot-3-starter</artifactId>"));
}
/**
* 能否更新文件
*
* @param context 文件上下文
* @return 能否更新
*/
@Override
public boolean canApply(FileContext context) {
return context.getFileName().endsWith(".xml");
}
@Override
protected List<Pair<String, String>> replaceList() {
return LIST;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论