Search in sources :

Example 1 with ClazzpathUnit

use of org.vafer.jdependency.ClazzpathUnit in project maven-plugins by apache.

the class MinijarFilter method removeSpecificallyIncludedClasses.

private void removeSpecificallyIncludedClasses(MavenProject project, List<SimpleFilter> simpleFilters) throws IOException {
    // remove classes specifically included in filters
    Clazzpath checkCp = new Clazzpath();
    for (Artifact dependency : project.getArtifacts()) {
        File jar = dependency.getFile();
        for (SimpleFilter simpleFilter : simpleFilters) {
            if (simpleFilter.canFilter(jar)) {
                ClazzpathUnit depClazzpathUnit = addDependencyToClasspath(checkCp, dependency);
                if (depClazzpathUnit != null) {
                    Set<Clazz> clazzes = depClazzpathUnit.getClazzes();
                    Iterator<Clazz> j = removable.iterator();
                    while (j.hasNext()) {
                        Clazz clazz = j.next();
                        if (//
                        clazzes.contains(clazz) && simpleFilter.isSpecificallyIncluded(clazz.getName().replace('.', '/'))) {
                            log.info(clazz.getName() + " not removed because it was specifically included");
                            j.remove();
                        }
                    }
                }
            }
        }
    }
}
Also used : Clazzpath(org.vafer.jdependency.Clazzpath) ClazzpathUnit(org.vafer.jdependency.ClazzpathUnit) Clazz(org.vafer.jdependency.Clazz) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with ClazzpathUnit

use of org.vafer.jdependency.ClazzpathUnit in project maven-plugins by apache.

the class MinijarFilter method addDependencyToClasspath.

private ClazzpathUnit addDependencyToClasspath(Clazzpath cp, Artifact dependency) throws IOException {
    InputStream is = null;
    ClazzpathUnit clazzpathUnit = null;
    try {
        is = new FileInputStream(dependency.getFile());
        clazzpathUnit = cp.addClazzpathUnit(is, dependency.toString());
        is.close();
        is = null;
    } catch (ZipException e) {
        log.warn(dependency.getFile() + " could not be unpacked/read for minimization; dependency is probably malformed.");
        IOException ioe = new IOException("Dependency " + dependency.toString() + " in file " + dependency.getFile() + " could not be unpacked. File is probably corrupt");
        ioe.initCause(e);
        throw ioe;
    } catch (ArrayIndexOutOfBoundsException e) {
        // trap ArrayIndexOutOfBoundsExceptions caused by malformed dependency classes (MSHADE-107)
        log.warn(dependency.toString() + " could not be analyzed for minimization; dependency is probably malformed.");
    } finally {
        IOUtil.close(is);
    }
    return clazzpathUnit;
}
Also used : ClazzpathUnit(org.vafer.jdependency.ClazzpathUnit) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

ClazzpathUnit (org.vafer.jdependency.ClazzpathUnit)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipException (java.util.zip.ZipException)1 Artifact (org.apache.maven.artifact.Artifact)1 Clazz (org.vafer.jdependency.Clazz)1 Clazzpath (org.vafer.jdependency.Clazzpath)1