/**
* @ClassName Test
* @Description TODO(去掉没有用的接口)
* @author feizhou
* @Date 2018年5月9日 下午3:41:31
* @version 1.0.0
*/
public class Test {
private static Set<String> urls=new HashSet<String>();
private static Set<String> jsurls=new HashSet<String>();
//获取java文件的所有@RequestMapping(value = "/account/findAccounts.do")的url
// 存在在集合中 list<url>
//获取页面的所有js,
//url : '/upload/findFileUpload.do',
/*$(function() {
showFileGrid();
// showProcessGrid();
});*/
public static void main(String[] args) throws Exception {
String controllerPath="D:\\workspace\\money\\src\\main\\java\\cn\\xiniu\\core\\controller";
String jsPath="D:\\workspace\\money\\src\\main\\webapp\\js";
File srcFile =new File(controllerPath);
readControllerFiles(srcFile);
File jsPathsrc =new File(jsPath);
readJsFiles(jsPathsrc);
String dest="D:\\test\\urls.txt";
writeUnUsedUrl(dest);
}
/**
*
* @Description (获取controller的所有映射URl)
* @author feizhou
* @Date 2018年5月9日下午4:03:24
* @version 1.0.0
* @param src
* @throws IOException
*/
public static void getUrl(File src) throws IOException{
BufferedReader reader = new BufferedReader(new FileReader(src));
String line = null;
while ((line = reader.readLine()) != null) {
//当前行操作
String newLine=line.trim();
if(newLine.startsWith("//")){
continue;
}
if(newLine.contains("@RequestMapping(")){
newLine=newLine.replace("@RequestMapping(", "");
newLine=newLine.replace(")", "");
newLine=newLine.replace("value", "");
newLine=newLine.replace("=", "");
newLine=newLine.replace("\"", "");
newLine=newLine.replace("\'", "");
newLine=newLine.trim();
System.out.println("当前的RequestMapping: "+newLine);
urls.add(newLine);
}
}
}
/**
*
* @Description (读取controller的所有文件)
* @author feizhou
* @Date 2018年5月9日下午4:01:50
* @version 1.0.0
* @param srcFile
* @param destFile
* @throws IOException
*/
@SuppressWarnings("unused")
private static void readControllerFiles(File srcFile)
throws IOException {
if (srcFile.isDirectory()) { //是目录
// 获取该File对象下的所有文件或者文件夹File对象
File[] fileArray = srcFile.listFiles();
//递归操作
for (File file : fileArray) {
//子文件,重复copyFolder
readControllerFiles(file);
}
} else {
//是文件
getUrl(srcFile);
}
}
@SuppressWarnings("unused")
private static void readJsFiles(File srcFile)
throws IOException {
if (srcFile.isDirectory()) { //是目录
// 获取该File对象下的所有文件或者文件夹File对象
File[] fileArray = srcFile.listFiles();
//递归操作
for (File file : fileArray) {
//子文件,重复copyFolder
readJsFiles(file);
}
} else {
//是文件
readJsFile(srcFile);
}
}
public static void readJsFile(File src) throws IOException{
BufferedReader reader = new BufferedReader(new FileReader(src));
String line = null;
while ((line = reader.readLine()) != null) {
//当前行操作
String newLine=line.trim();
if(newLine.startsWith("//")){
continue;
}
isContains(newLine);
}
}
public static void isContains(String line){
Iterator<String> keys = urls.iterator();
while(keys.hasNext()){
String url=keys.next();
if(line.contains(url)){
jsurls.add(url);
}
}
}
public static void writeUnUsedUrl(String dest) throws IOException{
//去掉已存在的url
Iterator<String> keys = jsurls.iterator();
while(keys.hasNext()){
String url=keys.next();
if(url.contains("/financial/moneyPaymentController/bankSave")){
System.out.println(url);
}
urls.remove(url);
}
fileToFileByBuffString(urls, dest);
}
public static void fileToFileByBuffString(Set<String> urls,String dest) throws IOException{
BufferedWriter bw=new BufferedWriter(new FileWriter(dest));
//没有用的url写到文件中
Iterator<String> urlskey = urls.iterator();
while(urlskey.hasNext()){
String url=urlskey.next();
bw.write(url);
bw.newLine();
bw.flush();
}
bw.close();
}
}
去掉controller不用的URL
最新推荐文章于 2023-02-22 10:15:01 发布