删一个类之前查与其单独相关的类一起删除 以及 使用找出使用了这个类共有常量的类找出来 的工具类

喜夏-厌秋 提交于 2020-04-23 05:37:31

直接贴代码算了,主要运用了正则表达式找引用类名,文件递归遍历目录树,看得懂的自然懂:

1.删一个类之前查与其单独相关的类一起删除

package allocationsearch;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ImportFinder {
    public ImportFinder(String delFile, String rootPath) throws Exception {
        List<String> ls = getImportedBatchFiles(delFile);
        
        System.out.println(delFile+"中导入的batch类:");
        for (String importedCls : ls) {
            System.out.println(importedCls);
        }
        System.out.println("\n");

        Map<String,List<String>> map=new LinkedHashMap<String,List<String>>();
        for (String importedCls : ls) {
            //System.out.println(importedCls);
            List<String> usedFileList=new ArrayList<>();
            tranversal(new File(rootPath),importedCls,usedFileList);
            map.put(importedCls, usedFileList);
        }
        
        for(Entry<String,List<String>> entry:map.entrySet()) {
            String importedCls=entry.getKey();
            List<String> usedFileList=entry.getValue();
            
            System.out.println(importedCls+" was used for "+usedFileList.size()+" times by files below:");
            for (String file : usedFileList) {
                System.out.println("    "+file);
            }
            
            System.out.println("");
        }
    }

    void tranversal(File dir,String importedCls,List<String> usedFileList) throws Exception {
        File[] fs = dir.listFiles();
        for (int i = 0; i < fs.length; i++) {
            
            if(fs[i].isFile()) {
                String filePath=fs[i].getAbsolutePath();
                List<String> ls = getImportedBatchFiles(filePath);
                if(ls.contains(importedCls)) {
                    //System.out.println("    "+filePath+" used "+importedCls);
                    usedFileList.add(filePath);
                }
            }
            
            
            if (fs[i].isDirectory()) {
                try {
                    tranversal(fs[i],importedCls,usedFileList);
                } catch (Exception e) {
                    //e.printStackTrace();
                }
            }
        }
    }

    private List<String> getImportedBatchFiles(String filepath) {
        List<String> list = new ArrayList<String>();

        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filepath), "UTF-8"));) {
            java.util.regex.Pattern pattern = Pattern
                    .compile("^\\s*(import)\\s+(jp\\.co\\.rakuten\\.rtms\\.batch(\\w|\\.)+)\\s*[;]\\s*$");

            String line = null;
            while ((line = br.readLine()) != null) {

                Matcher matcher = pattern.matcher(line);
                while (matcher.find()) {
                    list.add(matcher.group(2));
                }
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return list;
    }

    public static void main(String[] args) throws Exception  {
        ImportFinder finder = new ImportFinder(
                "D:\\Users\\ufo\\git\\ufo-batch\\src\\main\\java\\jp\\co\\ufo\\rtms\\batch\\job\\AllocationRequestFileToDbJob.java",
                "D:\\Users\\ufo\\git\\ufo-batch\\src\\main\\java");
    }
}

查找效果:

D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java中导入的batch类:
jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
jp.co.ufo.rtms.batch.business.service.SendMailService
jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean
jp.co.ufo.rtms.batch.reader.AllocationRequestCsvFileReader
jp.co.ufo.rtms.batch.reader.AllocationRequestDetailsCsvFileReader


jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\AllocationRequstUtilService.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationRequstUtilServiceImpl.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AbstractCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\WalmartCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.bean.DefaultAreaCodeOrderBean

jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestFiletoDbServiceImpl.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendMailServiceImpl.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\SendMailService.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\CompactCommonCheckUtil.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestDetailsCsvFileReader.java used jp.co.ufo.rtms.batch.bean.MaterialDefaultBean

jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationResultCalcReTryServiceImpl.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestFiletoDbServiceImpl.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestSubmitJobsServiceImpl.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\MaterialFileToDbServiceImpl.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendMailServiceImpl.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\DltApiCheckUtil.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AbstractCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\CleanExpiredDataJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\CompactAllocationRequestFiletoDbJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\MaterialFileToDbJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\WalmartPascoResultDownloadJob.java used jp.co.ufo.rtms.batch.business.service.SendMailService

jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\BatchMain.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\bean\StartAllocationCalcRequestBean.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationCalculateServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationRequstUtilServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationResultRetreiveServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestFiletoDbServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestSubmitJobsServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\MaterialFileToDbServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\PascoResultFileToDbServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\ReDeliveryRequestSendMailServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendAllocationReqToPascoServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendMailServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\StartAllocationCalcServiceImpl.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\DltApiCheckUtil.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\FileProcessingUtil.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\RtmsBatchUtil.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\RtmsWarehouseUtil.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AbstractCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestDbtoFileJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\CleanExpiredDataJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\CompactAllocationRequestFiletoDbJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\FileCreateCompletionNoticeJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\PascoResultFileToDbJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\ResultFileCreateCompletionNoticeJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\SendAllocationReqToPascoJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\StartAllocationCalcJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\WalmartPascoResultDownloadJob.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AbstractFileReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestDetailsCsvFileReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationResultDetailsCsvFlieReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\OrderCsvReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\PackingConfirmedCsvFileReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\PascoResultCsvFileReader.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\AbstractFileWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\ActualGoodsInfoCsvWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\AllocationResultDetailsDbWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\CompactAllocationRequestWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\OrderCsvWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\ResultCsvWriter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\SiteCsvWhiter.java used jp.co.ufo.rtms.batch.common.exception.BatchApplicationException

jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\http\HttpRequestClient.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AbstractCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\ActualGoodsInfoCsvWriter.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\CompactAllocationRequestDbWriter.java used jp.co.ufo.rtms.batch.common.util.DltApiCheckUtil

jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\AllocationResultCalcReTryServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\CompactAllocationRequestFiletoDbServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\MaterialFileToDbServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\ReDeliveryRequestSendMailServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendAllocationReqToPascoServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\SendMailServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\business\service\impl\TCDepotServiceImpl.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\http\HttpRequestClient.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AbstractCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\CleanExpiredDataJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\DirectCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\MaterialFileToDbJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\SendAllocationReqToPascoJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\ShukaCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\WayBillCompactAllocationRequestSubmitJob.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\CompactAllocationRequestDbWriter.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\CompactAllocationRequestWriter.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\writer\MaterialDbWriter.java used jp.co.ufo.rtms.batch.common.util.RtmsBatchConstant

jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestDetailsCsvFileReader.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\PackingConfirmedCsvFileReader.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\unused\PackingConfirmedFileToDbJob.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestDetailInputCsvBean

jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\common\util\DltApiCheckUtil.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\reader\AllocationRequestCsvFileReader.java used jp.co.ufo.rtms.batch.data.input.AllocationRequestInputCsvBean

jp.co.ufo.rtms.batch.reader.AllocationRequestCsvFileReader
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.reader.AllocationRequestCsvFileReader
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.reader.AllocationRequestCsvFileReader

jp.co.ufo.rtms.batch.reader.AllocationRequestDetailsCsvFileReader
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbAnyJob.java used jp.co.ufo.rtms.batch.reader.AllocationRequestDetailsCsvFileReader
    D:\Users\ufo\src\main\java\jp\co\ufo\rtms\batch\job\AllocationRequestFileToDbJob.java used jp.co.ufo.rtms.batch.reader.AllocationRequestDetailsCsvFileReader

 

2.使用找出使用了这个类共有常量的类

package allocationsearch;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Public0030Finder {
    public Public0030Finder(String publicMember, String rootPath) throws Exception {
        tranversal(new File(rootPath),publicMember);
    }

    void tranversal(File dir,String publicMember) throws Exception {
        File[] fs = dir.listFiles();
        for (int i = 0; i < fs.length; i++) {
            
            if(fs[i].isFile()) {
                String filePath=fs[i].getAbsolutePath();
                findPublicMember(filePath,publicMember);
            }
            
            
            if (fs[i].isDirectory()) {
                try {
                    tranversal(fs[i],publicMember);
                } catch (Exception e) {
                    //e.printStackTrace();
                }
            }
        }
    }

    private List<String> findPublicMember(String filepath,String publicMember) {
        List<String> list = new ArrayList<String>();

        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filepath), "UTF-8"));) {
            String line = null;
            int index=1;
            while ((line = br.readLine()) != null) {

                if(line.contains(publicMember)) {
                    System.out.println(filepath+"\n"+"L"+index+"   "+line);
                }
                
                index++;
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return list;
    }

    public static void main(String[] args) throws Exception  {
        Public0030Finder finder = new Public0030Finder(
                "BufferedReader",
                "D:\\Users\\os-yang.he\\git\\rtms-batch");
    }
}

--2020-04-21--

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!