Search in sources :

Example 1 with ExcludeRule

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

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

the class PomModuleDescriptorWriter method printExclusions.

private static void printExclusions(ExcludeRule[] exclusions, PrintWriter out, int indent) {
    indent(out, indent * 3);
    out.println("<exclusions>");
    for (ExcludeRule exclusion : exclusions) {
        indent(out, indent * 4);
        out.println("<exclusion>");
        indent(out, indent * 5);
        out.println("<groupId>" + exclusion.getId().getModuleId().getOrganisation() + "</groupId>");
        indent(out, indent * 5);
        out.println("<artifactId>" + exclusion.getId().getModuleId().getName() + "</artifactId>");
        indent(out, indent * 4);
        out.println("</exclusion>");
    }
    indent(out, indent * 3);
    out.println("</exclusions>");
}
Also used : ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule)

Example 3 with ExcludeRule

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

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

the class XmlModuleDescriptorWriter method printDependencyExcludeRules.

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

Example 5 with ExcludeRule

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

the class PomModuleDescriptorParserTest method testOverrideParentVersionPropertyDependencyMgt.

@Test
public void testOverrideParentVersionPropertyDependencyMgt() throws ParseException, IOException {
    settings.setDictatorResolver(new MockResolver() {

        public ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data) throws ParseException {
            try {
                ModuleDescriptor moduleDescriptor = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-versionPropertyDependencyMgt.pom"), false);
                return new ResolvedModuleRevision(null, null, moduleDescriptor, null);
            } catch (IOException e) {
                throw new AssertionError(e);
            }
        }
    });
    ModuleDescriptor md = PomModuleDescriptorParser.getInstance().parseDescriptor(settings, getClass().getResource("test-overrideParentVersionPropertyDependencyMgt.pom"), false);
    assertNotNull(md);
    assertEquals(ModuleRevisionId.newInstance("org.apache", "test-parentdep", "1.0"), md.getModuleRevisionId());
    DependencyDescriptor[] dds = md.getDependencies();
    assertNotNull(dds);
    assertEquals(2, dds.length);
    assertEquals(ModuleRevisionId.newInstance("commons-collections", "commons-collections", "3.2.1"), dds[0].getDependencyRevisionId());
    assertEquals(ModuleRevisionId.newInstance("commons-logging", "commons-logging", "1.1.1"), dds[1].getDependencyRevisionId());
    ExcludeRule[] excludes = dds[0].getAllExcludeRules();
    assertNotNull(excludes);
    assertEquals(2, excludes.length);
    assertEquals("javax.mail", excludes[0].getId().getModuleId().getOrganisation());
    assertEquals("mail", excludes[0].getId().getModuleId().getName());
    assertEquals("javax.jms", excludes[1].getId().getModuleId().getOrganisation());
    assertEquals("jms", excludes[1].getId().getModuleId().getName());
}
Also used : ResolveData(org.apache.ivy.core.resolve.ResolveData) DefaultModuleDescriptor(org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor) ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ResolvedModuleRevision(org.apache.ivy.core.resolve.ResolvedModuleRevision) MockResolver(org.apache.ivy.plugins.resolver.MockResolver) ParseException(java.text.ParseException) IOException(java.io.IOException) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule) XmlModuleDescriptorParserTest(org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest) Test(org.junit.Test)

Aggregations

ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)15 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)5 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)5 DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)4 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 List (java.util.List)2 Map (java.util.Map)2 Configuration (org.apache.ivy.core.module.descriptor.Configuration)2 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)2 License (org.apache.ivy.core.module.descriptor.License)2 ModuleId (org.apache.ivy.core.module.id.ModuleId)2 ResolveData (org.apache.ivy.core.resolve.ResolveData)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 XmlModuleDescriptorParserTest (org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParserTest)2 MockResolver (org.apache.ivy.plugins.resolver.MockResolver)2 Artifact (org.gradle.internal.component.external.descriptor.Artifact)2