protected void writeClassPathChecksums()

in core-it-support/core-it-plugins/maven-it-plugin-dependency-resolution/src/main/java/org/apache/maven/plugin/coreit/AbstractDependencyMojo.java [162:219]


    protected void writeClassPathChecksums(String pathname, Collection classPath) throws MojoExecutionException {
        if (pathname == null || pathname.length() <= 0) {
            return;
        }

        File file = resolveFile(pathname);

        getLog().info("[MAVEN-CORE-IT-LOG] Dumping class path checksums: " + file);

        Properties checksums = new Properties();

        if (classPath != null) {
            for (Object aClassPath : classPath) {
                String element = aClassPath.toString();

                File jarFile = new File(element);

                if (!jarFile.isFile()) {
                    getLog().info("[MAVEN-CORE-IT-LOG]   ( no file )                              < " + element);
                    continue;
                }

                String key = stripLeadingDirs(element, significantPathLevels);

                String hash;
                try {
                    hash = calcChecksum(jarFile);
                } catch (NoSuchAlgorithmException e) {
                    throw new MojoExecutionException("Failed to lookup message digest", e);
                } catch (IOException e) {
                    throw new MojoExecutionException("Failed to calculate checksum for " + jarFile, e);
                }

                checksums.setProperty(key, hash);

                getLog().info("[MAVEN-CORE-IT-LOG]   " + hash + " < " + element);
            }
        }

        FileOutputStream os = null;
        try {
            file.getParentFile().mkdirs();

            os = new FileOutputStream(file);

            checksums.store(os, "MAVEN-CORE-IT");
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to write class path checksums", e);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    // just ignore
                }
            }
        }
    }