All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yes.tools.build.utils.CommonUtils Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
package org.yes.tools.build.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;

/**
 * @author Co.
 * @name CommonUtils
 * @date 2023/6/19 11:01
 */
public class CommonUtils {

    /**
     * 获取jar下的路径
     *
     * @param properties
     * @return
     */
    public static List getJarPath(List properties) {
        List propertiesList = new ArrayList<>();
        String property = System.getProperty("user.dir");
        File file = new File(property);
        String[] fileNames = file.list();
        for (String fileName : fileNames) {
            for (Properties proper : properties) {
                if (fileName.contains(proper.get("moduleName").toString())) {
                    proper.put("jarPath", fileName);
                    propertiesList.add(proper);
                }
            }
        }
        return propertiesList;
    }

    /**
     * 获取jar文件
     *
     * @param dirFile
     * @return
     */
    public static List getJarFile(File dirFile) {
        // 如果文件夹不存在或着不是文件夹,则返回 null
        if (Objects.isNull(dirFile) || !dirFile.exists() || dirFile.isFile()) {
            return null;
        }

        File[] childrenFiles = dirFile.listFiles();
        if (Objects.isNull(childrenFiles) || childrenFiles.length == 0) {
            return null;
        }
        List files = new ArrayList<>();
        for (File childFile : childrenFiles) {
            // 如果是文件,直接添加到结果集合
            if (childFile.isFile()
                    && childFile.getName().contains(".jar")
                    && !childFile.getName().contains("sources.jar")
                    && !childFile.getName().contains(".jar.original")) {
                files.add(childFile);
            }
            //以下几行代码取消注释后可以将所有子文件夹里的文件也获取到列表里
//            else {
//                // 如果是文件夹,则将其内部文件添加进结果集合
//                List cFiles = getAllFile(childFile);
//                if (Objects.isNull(cFiles) || cFiles.isEmpty()) continue;
//                files.addAll(cFiles);
//            }
        }
        return files;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy