Search in sources :

Example 1 with DependencyArtifactDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor in project gradle by gradle.

the class IvyModuleDescriptorConverter method addDependency.

private void addDependency(List<IvyDependencyMetadata> result, DependencyDescriptor dependencyDescriptor) {
    ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
    ModuleVersionSelector requested = DefaultModuleVersionSelector.newSelector(revisionId.getOrganisation(), revisionId.getName(), revisionId.getRevision());
    ListMultimap<String, String> configMappings = ArrayListMultimap.create();
    for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
        configMappings.putAll(entry.getKey(), entry.getValue());
    }
    List<Artifact> artifacts = Lists.newArrayList();
    for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
        IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
        artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
    }
    List<Exclude> excludes = Lists.newArrayList();
    for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
        excludes.add(forIvyExclude(excludeRule));
    }
    result.add(new IvyDependencyMetadata(requested, dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(), false, dependencyDescriptor.isChanging(), dependencyDescriptor.isTransitive(), configMappings, artifacts, excludes));
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultModuleVersionSelector(org.gradle.api.internal.artifacts.DefaultModuleVersionSelector) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) Exclude(org.gradle.internal.component.model.Exclude) DefaultExclude(org.gradle.internal.component.external.descriptor.DefaultExclude) IvyDependencyMetadata(org.gradle.internal.component.external.model.IvyDependencyMetadata) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) Artifact(org.gradle.internal.component.external.descriptor.Artifact) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) List(java.util.List) Map(java.util.Map)

Example 2 with DependencyArtifactDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor in project gradle by gradle.

the class IvyModuleDescriptorConverter method addDependency.

private void addDependency(List<IvyDependencyDescriptor> result, DependencyDescriptor dependencyDescriptor) {
    ModuleRevisionId revisionId = dependencyDescriptor.getDependencyRevisionId();
    ModuleComponentSelector requested = DefaultModuleComponentSelector.newSelector(revisionId.getOrganisation(), revisionId.getName(), new DefaultImmutableVersionConstraint(revisionId.getRevision()));
    ListMultimap<String, String> configMappings = ArrayListMultimap.create();
    for (Map.Entry<String, List<String>> entry : readConfigMappings(dependencyDescriptor).entrySet()) {
        configMappings.putAll(entry.getKey(), entry.getValue());
    }
    List<Artifact> artifacts = Lists.newArrayList();
    for (DependencyArtifactDescriptor ivyArtifact : dependencyDescriptor.getAllDependencyArtifacts()) {
        IvyArtifactName ivyArtifactName = new DefaultIvyArtifactName(ivyArtifact.getName(), ivyArtifact.getType(), ivyArtifact.getExt(), (String) ivyArtifact.getExtraAttributes().get(CLASSIFIER));
        artifacts.add(new Artifact(ivyArtifactName, Sets.newHashSet(ivyArtifact.getConfigurations())));
    }
    List<Exclude> excludes = Lists.newArrayList();
    for (ExcludeRule excludeRule : dependencyDescriptor.getAllExcludeRules()) {
        excludes.add(forIvyExclude(excludeRule));
    }
    result.add(new IvyDependencyDescriptor(requested, dependencyDescriptor.getDynamicConstraintDependencyRevisionId().getRevision(), dependencyDescriptor.isChanging(), dependencyDescriptor.isTransitive(), false, configMappings, artifacts, excludes));
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) Exclude(org.gradle.internal.component.model.Exclude) DefaultExclude(org.gradle.internal.component.external.descriptor.DefaultExclude) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) Artifact(org.gradle.internal.component.external.descriptor.Artifact) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) IvyDependencyDescriptor(org.gradle.internal.component.external.model.IvyDependencyDescriptor) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) List(java.util.List) Map(java.util.Map)

Example 3 with DependencyArtifactDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor 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 4 with DependencyArtifactDescriptor

use of org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor 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 5 with DependencyArtifactDescriptor

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

the class IvyNode method addArtifactsFromMergedUsage.

private void addArtifactsFromMergedUsage(String rootModuleConf, Set<Artifact> artifacts) {
    for (IvyNodeUsage usage : mergedUsages.values()) {
        Set<DependencyArtifactDescriptor> mergedDependencyArtifacts = usage.getDependencyArtifactsSet(rootModuleConf);
        if (mergedDependencyArtifacts != null) {
            for (DependencyArtifactDescriptor dad : mergedDependencyArtifacts) {
                Map<String, String> extraAttributes = new HashMap<>(dad.getQualifiedExtraAttributes());
                MDArtifact artifact = new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad.getUrl(), extraAttributes);
                if (!artifacts.contains(artifact)) {
                    // this is later used to know that this is a merged artifact
                    extraAttributes.put("ivy:merged", dad.getDependencyDescriptor().getParentRevisionId() + " -> " + usage.getNode().getId());
                    artifacts.add(artifact);
                }
            }
        }
    }
}
Also used : DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MDArtifact(org.apache.ivy.core.module.descriptor.MDArtifact)

Aggregations

DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)9 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)5 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)2 IncludeRule (org.apache.ivy.core.module.descriptor.IncludeRule)2 MDArtifact (org.apache.ivy.core.module.descriptor.MDArtifact)2 Artifact (org.gradle.internal.component.external.descriptor.Artifact)2 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)2 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)2 Exclude (org.gradle.internal.component.model.Exclude)2 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Artifact (org.apache.ivy.core.module.descriptor.Artifact)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)1