Search in sources :

Example 1 with IncludeRule

use of org.apache.ivy.core.module.descriptor.IncludeRule in project ant-ivy by apache.

the class XmlModuleDescriptorWriter method printDependency.

protected static void printDependency(ModuleDescriptor md, DependencyDescriptor dep, PrintWriter out) {
    final ModuleRevisionId dependencyRevisionId = dep.getDependencyRevisionId();
    out.print(String.format("<dependency org=\"%s\" name=\"%s\"", XMLHelper.escape(dependencyRevisionId.getOrganisation()), XMLHelper.escape(dependencyRevisionId.getName())));
    if (dependencyRevisionId.getBranch() != null) {
        out.print(" branch=\"" + XMLHelper.escape(dependencyRevisionId.getBranch()) + "\"");
    }
    out.print(" rev=\"" + XMLHelper.escape(dependencyRevisionId.getRevision()) + "\"");
    final ModuleRevisionId dynamicConstraintDependencyRevisionId = dep.getDynamicConstraintDependencyRevisionId();
    if (!dynamicConstraintDependencyRevisionId.equals(dependencyRevisionId)) {
        if (dynamicConstraintDependencyRevisionId.getBranch() != null) {
            out.print(" branchConstraint=\"" + XMLHelper.escape(dynamicConstraintDependencyRevisionId.getBranch()) + "\"");
        }
        out.print(" revConstraint=\"" + XMLHelper.escape(dynamicConstraintDependencyRevisionId.getRevision()) + "\"");
    }
    if (dep.isForce()) {
        out.print(" force=\"" + dep.isForce() + "\"");
    }
    if (dep.isChanging()) {
        out.print(" changing=\"" + dep.isChanging() + "\"");
    }
    if (!dep.isTransitive()) {
        out.print(" transitive=\"" + dep.isTransitive() + "\"");
    }
    StringBuilder sb = new StringBuilder();
    for (String modConf : dep.getModuleConfigurations()) {
        if (sb.length() > 0) {
            sb.append(";");
        }
        sb.append(XMLHelper.escape(modConf)).append(listToPrefixedString(dep.getDependencyConfigurations(modConf), "->"));
    }
    out.print(" conf=\"" + sb + "\"");
    printExtraAttributes(dep, out, " ");
    DependencyArtifactDescriptor[] depArtifacts = dep.getAllDependencyArtifacts();
    if (depArtifacts.length > 0) {
        out.println(">");
    }
    printDependencyArtefacts(md, out, depArtifacts);
    IncludeRule[] includes = dep.getAllIncludeRules();
    if (includes.length > 0 && depArtifacts.length == 0) {
        out.println(">");
    }
    printDependencyIncludeRules(md, out, includes);
    ExcludeRule[] excludes = dep.getAllExcludeRules();
    if (excludes.length > 0 && includes.length == 0 && depArtifacts.length == 0) {
        out.println(">");
    }
    printDependencyExcludeRules(md, out, excludes);
    if (includes.length + excludes.length + depArtifacts.length == 0) {
        out.println("/>");
    } else {
        out.println("\t\t</dependency>");
    }
}
Also used : DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) IncludeRule(org.apache.ivy.core.module.descriptor.IncludeRule) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule)

Example 2 with IncludeRule

use of org.apache.ivy.core.module.descriptor.IncludeRule in project ant-ivy by apache.

the class XmlModuleDescriptorWriter method printDependencyIncludeRules.

private static void printDependencyIncludeRules(ModuleDescriptor md, PrintWriter out, IncludeRule[] includes) {
    if (includes.length > 0) {
        for (IncludeRule include : includes) {
            out.print(String.format("\t\t\t<include name=\"%s\" type=\"%s\" ext=\"%s\"", XMLHelper.escape(include.getId().getName()), XMLHelper.escape(include.getId().getType()), XMLHelper.escape(include.getId().getExt())));
            String[] ruleConfs = include.getConfigurations();
            if (!Arrays.asList(ruleConfs).equals(Arrays.asList(md.getConfigurationsNames()))) {
                out.print(listToPrefixedString(ruleConfs, " conf=\""));
            }
            out.print(" matcher=\"" + XMLHelper.escape(include.getMatcher().getName()) + "\"");
            out.println("/>");
        }
    }
}
Also used : IncludeRule(org.apache.ivy.core.module.descriptor.IncludeRule)

Example 3 with IncludeRule

use of org.apache.ivy.core.module.descriptor.IncludeRule in project ant-ivy by apache.

the class IvyNode method getArtifacts.

/**
 * Returns the artifacts of this dependency required in the configurations themselves required
 * in the given root module configuration
 *
 * @param rootModuleConf String
 * @return array of {@link Artifact}s
 */
public Artifact[] getArtifacts(String rootModuleConf) {
    // first we look for the dependency configurations required
    // in the given root module configuration
    String[] confs = getConfigurations(rootModuleConf);
    if (confs == null || confs.length == 0) {
        // no configuration required => no artifact required
        return new Artifact[0];
    }
    if (md == null) {
        throw new IllegalStateException("impossible to get artifacts when data has not been loaded. IvyNode = " + this);
    }
    // the set we fill before returning
    Set<Artifact> artifacts = new HashSet<>();
    // we check if we have dependencyArtifacts includes description for this rootModuleConf
    Set<DependencyArtifactDescriptor> dependencyArtifacts = usage.getDependencyArtifactsSet(rootModuleConf);
    if (md.isDefault() && dependencyArtifacts != null && !dependencyArtifacts.isEmpty()) {
        addArtifactsFromOwnUsage(artifacts, dependencyArtifacts);
        addArtifactsFromMergedUsage(rootModuleConf, artifacts);
    } else {
        Set<IncludeRule> includes = new LinkedHashSet<>();
        addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf));
        for (IvyNodeUsage usage : mergedUsages.values()) {
            addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf));
        }
        if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty()) && includes.isEmpty()) {
            // no artifacts / includes: we get all artifacts as defined by the descriptor
            for (String conf : confs) {
                artifacts.addAll(Arrays.asList(md.getArtifacts(conf)));
            }
        } else {
            // we have to get only artifacts listed as "includes";
            // first we get all artifacts as defined by the module descriptor
            // and classify them by artifact id
            Map<ArtifactId, Artifact> allArtifacts = new HashMap<>();
            for (String conf : confs) {
                for (Artifact art : md.getArtifacts(conf)) {
                    allArtifacts.put(art.getId().getArtifactId(), art);
                }
            }
            // now we add caller defined ones
            if (dependencyArtifacts != null) {
                addArtifactsFromOwnUsage(artifacts, dependencyArtifacts);
            }
            addArtifactsFromMergedUsage(rootModuleConf, artifacts);
            // and now we filter according to include rules
            Iterator<IncludeRule> it = includes.iterator();
            while (it.hasNext()) {
                IncludeRule dad = it.next();
                Collection<Artifact> arts = findArtifactsMatching(dad, allArtifacts);
                if (arts.isEmpty()) {
                    Message.error("a required artifact is not listed by module descriptor: " + dad.getId());
                    // we remove it from required list to prevent message to be displayed more
                    // than once
                    it.remove();
                } else {
                    Message.debug(this + " in " + rootModuleConf + ": including " + arts);
                    artifacts.addAll(arts);
                }
            }
        }
    }
    // now exclude artifacts that aren't accepted by any caller
    Iterator<Artifact> iter = artifacts.iterator();
    while (iter.hasNext()) {
        Artifact artifact = iter.next();
        boolean excluded = callers.doesCallersExclude(rootModuleConf, artifact);
        if (excluded) {
            Message.debug(this + " in " + rootModuleConf + ": excluding " + artifact);
            iter.remove();
        }
    }
    return artifacts.toArray(new Artifact[artifacts.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactId(org.apache.ivy.core.module.id.ArtifactId) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IncludeRule(org.apache.ivy.core.module.descriptor.IncludeRule) Artifact(org.apache.ivy.core.module.descriptor.Artifact) DefaultArtifact(org.apache.ivy.core.module.descriptor.DefaultArtifact) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 4 with IncludeRule

use of org.apache.ivy.core.module.descriptor.IncludeRule in project ant-ivy by apache.

the class AbstractModuleDescriptorParserTester method assertDependencyArtifactIncludeRules.

protected void assertDependencyArtifactIncludeRules(DependencyDescriptor dd, String[] confs, String[] artifactsNames) {
    IncludeRule[] dads = dd.getIncludeRules(confs);
    assertNotNull(dads);
    assertEquals(artifactsNames.length, dads.length);
    for (String artifactsName : artifactsNames) {
        boolean found = false;
        for (IncludeRule dad : dads) {
            assertNotNull(dad);
            if (dad.getId().getName().equals(artifactsName)) {
                found = true;
                break;
            }
        }
        assertTrue("dependency include not found: " + artifactsName, found);
    }
}
Also used : IncludeRule(org.apache.ivy.core.module.descriptor.IncludeRule)

Aggregations

IncludeRule (org.apache.ivy.core.module.descriptor.IncludeRule)4 DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)1 MDArtifact (org.apache.ivy.core.module.descriptor.MDArtifact)1 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1