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));
}
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));
}
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>");
}
}
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()]);
}
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);
}
}
}
}
}
Aggregations