Search in sources :

Example 6 with Exclusion

use of org.apache.maven.model.Exclusion in project gradle by gradle.

the class DefaultPomDependenciesConverter method initExcludeAll.

private static List<Exclusion> initExcludeAll() {
    Exclusion excludeAll = new Exclusion();
    excludeAll.setGroupId("*");
    excludeAll.setArtifactId("*");
    return Collections.singletonList(excludeAll);
}
Also used : Exclusion(org.apache.maven.model.Exclusion)

Example 7 with Exclusion

use of org.apache.maven.model.Exclusion in project maven-plugins by apache.

the class AnalyzeDepMgt method checkDependencyManagement.

/**
     * Does the work of checking the DependencyManagement Section.
     *
     * @return true if errors are found.
     * @throws MojoExecutionException
     */
private boolean checkDependencyManagement() throws MojoExecutionException {
    boolean foundError = false;
    getLog().info("Found Resolved Dependency/DependencyManagement mismatches:");
    List<Dependency> depMgtDependencies = null;
    DependencyManagement depMgt = project.getDependencyManagement();
    if (depMgt != null) {
        depMgtDependencies = depMgt.getDependencies();
    }
    if (depMgtDependencies != null && !depMgtDependencies.isEmpty()) {
        // put all the dependencies from depMgt into a map for quick lookup
        Map<String, Dependency> depMgtMap = new HashMap<String, Dependency>();
        Map<String, Exclusion> exclusions = new HashMap<String, Exclusion>();
        for (Dependency depMgtDependency : depMgtDependencies) {
            depMgtMap.put(depMgtDependency.getManagementKey(), depMgtDependency);
            // now put all the exclusions into a map for quick lookup
            exclusions.putAll(addExclusions(depMgtDependency.getExclusions()));
        }
        // get dependencies for the project (including transitive)
        Set<Artifact> allDependencyArtifacts = new LinkedHashSet<Artifact>(project.getArtifacts());
        // depMgt. That's ok.
        if (this.ignoreDirect) {
            getLog().info("\tIgnoring Direct Dependencies.");
            Set<Artifact> directDependencies = project.getDependencyArtifacts();
            allDependencyArtifacts.removeAll(directDependencies);
        }
        // log exclusion errors
        List<Artifact> exclusionErrors = getExclusionErrors(exclusions, allDependencyArtifacts);
        for (Artifact exclusion : exclusionErrors) {
            getLog().info(StringUtils.stripEnd(getArtifactManagementKey(exclusion), ":") + " was excluded in DepMgt, but version " + exclusion.getVersion() + " has been found in the dependency tree.");
            foundError = true;
        }
        // find and log version mismatches
        Map<Artifact, Dependency> mismatch = getMismatch(depMgtMap, allDependencyArtifacts);
        for (Map.Entry<Artifact, Dependency> entry : mismatch.entrySet()) {
            logMismatch(entry.getKey(), entry.getValue());
            foundError = true;
        }
        if (!foundError) {
            getLog().info("\tNone");
        }
    } else {
        getLog().info("\tNothing in DepMgt.");
    }
    return foundError;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) Exclusion(org.apache.maven.model.Exclusion) HashMap(java.util.HashMap) Map(java.util.Map) DependencyManagement(org.apache.maven.model.DependencyManagement)

Example 8 with Exclusion

use of org.apache.maven.model.Exclusion in project maven-plugins by apache.

the class TestAnalyzeDepMgt method setUp.

protected void setUp() throws Exception {
    mojo = new AnalyzeDepMgt();
    MavenProject project = new DependencyProjectStub();
    stubFactory = new DependencyArtifactStubFactory(new File(""), false);
    Set<Artifact> allArtifacts = stubFactory.getMixedArtifacts();
    Set<Artifact> directArtifacts = stubFactory.getClassifiedArtifacts();
    exclusionArtifact = stubFactory.getReleaseArtifact();
    directArtifacts.add(exclusionArtifact);
    ex = new Exclusion();
    ex.setArtifactId(exclusionArtifact.getArtifactId());
    ex.setGroupId(exclusionArtifact.getGroupId());
    exclusion = new Dependency();
    exclusion.setArtifactId(exclusionArtifact.getArtifactId());
    exclusion.setGroupId(exclusionArtifact.getGroupId());
    exclusion.setType(exclusionArtifact.getType());
    exclusion.setClassifier("");
    exclusion.setVersion("3.0");
    exclusion.addExclusion(ex);
    List<Dependency> list = new ArrayList<Dependency>();
    list.add(exclusion);
    depMgt = new DependencyManagement();
    depMgt.setDependencies(list);
    project.setArtifacts(allArtifacts);
    project.setDependencyArtifacts(directArtifacts);
    mojo.setProject(project);
}
Also used : AnalyzeDepMgt(org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt) MavenProject(org.apache.maven.project.MavenProject) Exclusion(org.apache.maven.model.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) DependencyProjectStub(org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) DependencyManagement(org.apache.maven.model.DependencyManagement) DependencyArtifactStubFactory(org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)

Example 9 with Exclusion

use of org.apache.maven.model.Exclusion in project maven-plugins by apache.

the class ShadeMojo method updateExcludesInDeps.

public boolean updateExcludesInDeps(MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps) throws DependencyGraphBuilderException {
    DependencyNode node = dependencyGraphBuilder.buildDependencyGraph(project, null);
    boolean modified = false;
    for (DependencyNode n2 : node.getChildren()) {
        for (DependencyNode n3 : n2.getChildren()) {
            // check if it really isn't in the list of original dependencies. Maven
            // prior to 2.0.8 may grab versions from transients instead of
            // from the direct deps in which case they would be marked included
            // instead of OMITTED_FOR_DUPLICATE
            // also, if not promoting the transitives, level 2's would be included
            boolean found = false;
            for (Dependency dep : transitiveDeps) {
                if (dep.getArtifactId().equals(n3.getArtifact().getArtifactId()) && dep.getGroupId().equals(n3.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n3.getArtifact().getType()))) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                for (Dependency dep : dependencies) {
                    if (dep.getArtifactId().equals(n2.getArtifact().getArtifactId()) && dep.getGroupId().equals(n2.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n2.getArtifact().getType()))) {
                        Exclusion exclusion = new Exclusion();
                        exclusion.setArtifactId(n3.getArtifact().getArtifactId());
                        exclusion.setGroupId(n3.getArtifact().getGroupId());
                        dep.addExclusion(exclusion);
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    return modified;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency)

Example 10 with Exclusion

use of org.apache.maven.model.Exclusion in project maven-plugins by apache.

the class MavenJDOMWriter method iterateExclusion.

// -- void iterateDeveloper(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
     * Method iterateExclusion
     *
     * @param counter
     * @param childTag
     * @param parentTag
     * @param list
     * @param parent
     */
protected void iterateExclusion(Counter counter, Element parent, java.util.Collection list, java.lang.String parentTag, java.lang.String childTag) {
    boolean shouldExist = list != null && list.size() > 0;
    Element element = updateElement(counter, parent, parentTag, shouldExist);
    if (shouldExist) {
        Iterator it = list.iterator();
        Iterator elIt = element.getChildren(childTag, element.getNamespace()).iterator();
        if (!elIt.hasNext()) {
            elIt = null;
        }
        Counter innerCount = new Counter(counter.getDepth() + 1);
        while (it.hasNext()) {
            Exclusion value = (Exclusion) it.next();
            Element el;
            if (elIt != null && elIt.hasNext()) {
                el = (Element) elIt.next();
                if (!elIt.hasNext()) {
                    elIt = null;
                }
            } else {
                el = factory.element(childTag, element.getNamespace());
                insertAtPreferredLocation(element, el, innerCount);
            }
            updateExclusion(value, childTag, innerCount, el);
            innerCount.increaseCount();
        }
        if (elIt != null) {
            while (elIt.hasNext()) {
                elIt.next();
                elIt.remove();
            }
        }
    }
}
Also used : Element(org.jdom.Element) Exclusion(org.apache.maven.model.Exclusion) Iterator(java.util.Iterator)

Aggregations

Exclusion (org.apache.maven.model.Exclusion)11 Dependency (org.apache.maven.model.Dependency)7 Artifact (org.apache.maven.artifact.Artifact)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)2 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 DependencyManagement (org.apache.maven.model.DependencyManagement)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ExecutableDependency (org.codehaus.mojo.exec.ExecutableDependency)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 XPath (javax.xml.xpath.XPath)1 XPathExpression (javax.xml.xpath.XPathExpression)1 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)1 AnalyzeDepMgt (org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt)1