private static int getNumLicenseFilesOutsideMetaInfDirectory()

in tools/ci/paimon-ci-tools/src/main/java/org/apache/paimon/tools/ci/licensecheck/JarFileChecker.java [250:296]


    private static int getNumLicenseFilesOutsideMetaInfDirectory(Path jar, Path jarRoot)
            throws IOException {
        try (Stream<Path> files = Files.walk(jarRoot)) {
            /*
             * LICENSE or NOTICE files found outside of the META-INF directory are most likely shading mistakes (we are including the files from other dependencies, thus providing an invalid LICENSE file)
             *
             * <p>In such a case, we recommend updating the shading exclusions, and adding the license file to META-INF/licenses.
             */
            final List<String> filesWithIssues =
                    files.filter(path -> !path.equals(jarRoot))
                            .filter(
                                    path ->
                                            getFileName(path).contains("license")
                                                    || getFileName(path).contains("notice"))
                            .filter(
                                    path ->
                                            !Files.isDirectory(
                                                    path)) // ignore directories, e.g. "license/"
                            .filter(JarFileChecker::isNoClassFile) // some class files contain
                            // LICENSE in their name
                            .filter(
                                    path ->
                                            !getFileName(path)
                                                    .endsWith(".ftl")) // a false positive in
                            // python
                            .map(Path::toString)
                            .filter(
                                    path ->
                                            !path.contains(
                                                    "META-INF")) // license files in META-INF are
                            // expected
                            .filter(
                                    path ->
                                            !path.endsWith(
                                                    "web/3rdpartylicenses.txt")) // a false positive
                            // in
                            // web
                            .collect(Collectors.toList());
            for (String fileWithIssue : filesWithIssues) {
                LOG.error(
                        "Jar file {} contains a LICENSE file in an unexpected location: {}",
                        jar,
                        fileWithIssue);
            }
            return filesWithIssues.size();
        }
    }