Search in sources :

Example 1 with Exclusion

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

the class DefaultPomDependenciesConverter method getExclusions.

private List<Exclusion> getExclusions(ModuleDependency dependency, Set<Configuration> configurations) {
    if (!dependency.isTransitive()) {
        return EXCLUDE_ALL;
    }
    List<Exclusion> mavenExclusions = new ArrayList<Exclusion>();
    Set<ExcludeRule> excludeRules = new HashSet<ExcludeRule>(dependency.getExcludeRules());
    for (Configuration configuration : configurations) {
        excludeRules.addAll(configuration.getExcludeRules());
    }
    for (ExcludeRule excludeRule : excludeRules) {
        Exclusion mavenExclusion = (Exclusion) excludeRuleConverter.convert(excludeRule);
        if (mavenExclusion != null) {
            mavenExclusions.add(mavenExclusion);
        }
    }
    return mavenExclusions;
}
Also used : Exclusion(org.apache.maven.model.Exclusion)

Example 2 with Exclusion

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

the class BomGeneratorMojo method overwriteDependencyManagement.

private void overwriteDependencyManagement(Document pom, List<Dependency> dependencies) throws Exception {
    XPath xpath = XPathFactory.newInstance().newXPath();
    XPathExpression expr = xpath.compile("/project/dependencyManagement/dependencies");
    NodeList nodes = (NodeList) expr.evaluate(pom, XPathConstants.NODESET);
    if (nodes.getLength() == 0) {
        throw new IllegalStateException("No dependencies found in the dependencyManagement section of the current pom");
    }
    Node dependenciesSection = nodes.item(0);
    // cleanup the dependency management section
    while (dependenciesSection.hasChildNodes()) {
        Node child = dependenciesSection.getFirstChild();
        dependenciesSection.removeChild(child);
    }
    for (Dependency dep : dependencies) {
        Element dependencyEl = pom.createElement("dependency");
        Element groupIdEl = pom.createElement("groupId");
        groupIdEl.setTextContent(dep.getGroupId());
        dependencyEl.appendChild(groupIdEl);
        Element artifactIdEl = pom.createElement("artifactId");
        artifactIdEl.setTextContent(dep.getArtifactId());
        dependencyEl.appendChild(artifactIdEl);
        Element versionEl = pom.createElement("version");
        versionEl.setTextContent(dep.getVersion());
        dependencyEl.appendChild(versionEl);
        if (!"jar".equals(dep.getType())) {
            Element typeEl = pom.createElement("type");
            typeEl.setTextContent(dep.getType());
            dependencyEl.appendChild(typeEl);
        }
        if (dep.getClassifier() != null) {
            Element classifierEl = pom.createElement("classifier");
            classifierEl.setTextContent(dep.getClassifier());
            dependencyEl.appendChild(classifierEl);
        }
        if (dep.getScope() != null && !"compile".equals(dep.getScope())) {
            Element scopeEl = pom.createElement("scope");
            scopeEl.setTextContent(dep.getScope());
            dependencyEl.appendChild(scopeEl);
        }
        if (dep.getExclusions() != null && !dep.getExclusions().isEmpty()) {
            Element exclsEl = pom.createElement("exclusions");
            for (Exclusion e : dep.getExclusions()) {
                Element exclEl = pom.createElement("exclusion");
                Element groupIdExEl = pom.createElement("groupId");
                groupIdExEl.setTextContent(e.getGroupId());
                exclEl.appendChild(groupIdExEl);
                Element artifactIdExEl = pom.createElement("artifactId");
                artifactIdExEl.setTextContent(e.getArtifactId());
                exclEl.appendChild(artifactIdExEl);
                exclsEl.appendChild(exclEl);
            }
            dependencyEl.appendChild(exclsEl);
        }
        dependenciesSection.appendChild(dependencyEl);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency)

Example 3 with Exclusion

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

the class RunMojo method getAllDependencies.

// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
    List<Artifact> artifacts = new ArrayList<Artifact>();
    for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
        Dependency dependency = (Dependency) dependencies.next();
        String groupId = dependency.getGroupId();
        String artifactId = dependency.getArtifactId();
        VersionRange versionRange;
        try {
            versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
        } catch (InvalidVersionSpecificationException e) {
            throw new MojoExecutionException("unable to parse version", e);
        }
        String type = dependency.getType();
        if (type == null) {
            type = "jar";
        }
        String classifier = dependency.getClassifier();
        boolean optional = dependency.isOptional();
        String scope = dependency.getScope();
        if (scope == null) {
            scope = Artifact.SCOPE_COMPILE;
        }
        Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
        if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
            art.setFile(new File(dependency.getSystemPath()));
        }
        List<String> exclusions = new ArrayList<String>();
        for (Exclusion exclusion : dependency.getExclusions()) {
            exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
        }
        ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
        art.setDependencyFilter(newFilter);
        artifacts.add(art);
    }
    return artifacts;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 4 with Exclusion

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

the class BundlePlugin method updateExcludesInDeps.

public boolean updateExcludesInDeps(MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps) throws DependencyTreeBuilderException {
    org.apache.maven.shared.dependency.tree.DependencyNode node = dependencyTreeBuilder.buildDependencyTree(project, localRepository, artifactFactory, artifactMetadataSource, null, artifactCollector);
    boolean modified = false;
    Iterator it = node.getChildren().listIterator();
    while (it.hasNext()) {
        org.apache.maven.shared.dependency.tree.DependencyNode n2 = (org.apache.maven.shared.dependency.tree.DependencyNode) it.next();
        Iterator it2 = n2.getChildren().listIterator();
        while (it2.hasNext()) {
            org.apache.maven.shared.dependency.tree.DependencyNode n3 = (org.apache.maven.shared.dependency.tree.DependencyNode) it2.next();
            // remains excluded IF promoting transitives.
            if (n3.getState() == org.apache.maven.shared.dependency.tree.DependencyNode.INCLUDED) {
                // 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 (int x = 0; x < transitiveDeps.size(); x++) {
                    Dependency dep = transitiveDeps.get(x);
                    if (dep.getArtifactId().equals(n3.getArtifact().getArtifactId()) && dep.getGroupId().equals(n3.getArtifact().getGroupId())) {
                        found = true;
                    }
                }
                if (!found) {
                    for (int x = 0; x < dependencies.size(); x++) {
                        Dependency dep = dependencies.get(x);
                        if (dep.getArtifactId().equals(n2.getArtifact().getArtifactId()) && dep.getGroupId().equals(n2.getArtifact().getGroupId())) {
                            Exclusion exclusion = new Exclusion();
                            exclusion.setArtifactId(n3.getArtifact().getArtifactId());
                            exclusion.setGroupId(n3.getArtifact().getGroupId());
                            dep.addExclusion(exclusion);
                            modified = true;
                            break;
                        }
                    }
                }
            }
        }
    }
    return modified;
}
Also used : Dependency(org.apache.maven.model.Dependency) DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Exclusion(org.apache.maven.model.Exclusion) Iterator(java.util.Iterator)

Example 5 with Exclusion

use of org.apache.maven.model.Exclusion in project felix 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, Collection list, String parentTag, 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)19 Dependency (org.apache.maven.model.Dependency)11 Artifact (org.apache.maven.artifact.Artifact)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 DependencyManagement (org.apache.maven.model.DependencyManagement)4 Element (org.jdom.Element)4 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 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 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AnalyzeDepMgt (org.apache.maven.plugins.dependency.analyze.AnalyzeDepMgt)2 DependencyArtifactStubFactory (org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory)2 DependencyProjectStub (org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub)2 MavenProject (org.apache.maven.project.MavenProject)2