在工作中,大家或多或少都会碰到关于漏洞升级的问题,漏洞包含的问题很多,比如框架自身的问题、代码逻辑的问题等,这里我写了一种关于Maven版本问题中的一小部分,怎么用代码分析本地代码的依赖版本。
package cn.com.gg.controller.mygg;
import com.alibaba.excel.EasyExcel;
import lombok.Data;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @date 2022/8/17/017
*/
public class test {
private static Set<MyggController.Version> set = new HashSet<>();
public static void main(String[] args) {
String path = "D:\\environment\\maven\\";
File file = new File(path);
set = func(file);
EasyExcel.write("F://work.xls").sheet(1).doWrite(Arrays.asList(set.toArray()));
System.out.println("文档完成");
}
@Data
static class Version {
private String groupId;
private String version;
}
private static Set<MyggController.Version> func(File file) {
File[] files = file.listFiles();
//List<Version> list = new ArrayList<>();
for (File f : files) {
MyPggController.Version version1 = new MyggController.Version();
if (f.isDirectory() && !f.toString().contains("cn")) {
func(f);
}
if (f.isFile()) {
String s1 = f.toString();
int indexOf = s1.indexOf("\\", 20);
String substring = s1.substring(indexOf, s1.lastIndexOf("\\")).replaceFirst("\\\\", "");
int lastIndexOf = substring.lastIndexOf("\\");
String g1 = substring.substring(0, lastIndexOf).replaceAll("\\\\", ".");
int lastIndexOf1 = g1.lastIndexOf(".");
g1 = g1.replace(g1.charAt(lastIndexOf1 - 1) + ".", "/");
String v1 = substring.substring(lastIndexOf).replaceAll("\\\\", "");
version1.setGroupId(g1);
version1.setVersion(v1);
set.add(version1);
}
}
return set;
}
}