private Path readingPomFromJarFile()

in src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java [201:233]


    private Path readingPomFromJarFile() {
        Pattern pomEntry = Pattern.compile("META-INF/maven/.*/pom\\.xml");
        try {
            try (JarFile jarFile = new JarFile(file.toFile())) {
                JarEntry entry = jarFile.stream()
                        .filter(e -> pomEntry.matcher(e.getName()).matches())
                        .findFirst()
                        .orElse(null);
                if (entry != null) {
                    getLog().debug("Using " + entry.getName() + " as pomFile");

                    try (InputStream pomInputStream = jarFile.getInputStream(entry)) {
                        String base = file.getFileName().toString();
                        if (base.indexOf('.') > 0) {
                            base = base.substring(0, base.lastIndexOf('.'));
                        }
                        Path pomFile = File.createTempFile(base, ".pom").toPath();

                        Files.copy(pomInputStream, pomFile, StandardCopyOption.REPLACE_EXISTING);

                        processModel(readModel(pomFile));

                        return pomFile;
                    }
                } else {
                    getLog().info("pom.xml not found in " + file.getFileName());
                }
            }
        } catch (IOException e) {
            // ignore, artifact not packaged by Maven
        }
        return null;
    }