private String getLibraryPathWithPattern()

in src/main/java/pemja/utils/CommonUtils.java [111:151]


    private String getLibraryPathWithPattern(String pythonExec, String pattern) {
        if (pythonExec == null) {
            // run in source code
            String pythonModulePath =
                    String.join(
                            File.separator,
                            System.getProperty("user.dir"),
                            "src",
                            "main",
                            "python");
            File pythonModuleFile = new File(pythonModulePath);
            for (File f : Objects.requireNonNull(pythonModuleFile.listFiles())) {
                if (f.isFile() && Pattern.matches(pattern, f.getName())) {
                    return f.getAbsolutePath();
                }
            }
            throw new IllegalArgumentException(
                    "Test in source, you need to execute"
                            + "`python setup.py build_ext --inplace --force ` to"
                            + " build pemja.");
        } else {
            String sitePackagesPath;
            try {
                String out =
                        execute(new String[] {pythonExec, "-c", GET_SITE_PACKAGES_PATH_SCRIPT});
                sitePackagesPath = String.join(File.pathSeparator, out.trim().split("\n"));
            } catch (IOException e) {
                throw new RuntimeException(
                        "Failed to get pemja path. You need to `pip install pemja` firstly.", e);
            }
            File libFile = new File(sitePackagesPath);
            if (libFile.isDirectory()) {
                for (File f : Objects.requireNonNull(libFile.listFiles())) {
                    if (f.isFile() && Pattern.matches(pattern, f.getName())) {
                        return f.getAbsolutePath();
                    }
                }
            }
            throw new RuntimeException("Failed to find PemJa Library");
        }
    }