Search in sources :

Example 1 with ConfigurationScopeMapping

use of org.apache.ivy.plugins.parser.m2.PomWriterOptions.ConfigurationScopeMapping in project ant-ivy by apache.

the class PomModuleDescriptorWriter method printDependencies.

private static void printDependencies(ModuleDescriptor md, PrintWriter out, PomWriterOptions options, int indent, boolean printDependencies) {
    List<ExtraDependency> extraDeps = options.getExtraDependencies();
    DependencyDescriptor[] dds = getDependencies(md, options);
    if (!extraDeps.isEmpty() || (dds.length > 0)) {
        if (printDependencies) {
            indent(out, indent);
            out.println("<dependencies>");
        }
        // print the extra dependencies first
        for (ExtraDependency dep : extraDeps) {
            String groupId = dep.getGroup();
            if (groupId == null) {
                groupId = md.getModuleRevisionId().getOrganisation();
            }
            String version = dep.getVersion();
            if (version == null) {
                version = md.getModuleRevisionId().getRevision();
            }
            printDependency(out, indent, groupId, dep.getArtifact(), version, dep.getType(), dep.getClassifier(), dep.getScope(), dep.isOptional(), true, null);
        }
        // now print the dependencies listed in the ModuleDescriptor
        ConfigurationScopeMapping mapping = options.getMapping();
        if (mapping == null) {
            mapping = DEFAULT_MAPPING;
        }
        for (DependencyDescriptor dd : dds) {
            ModuleRevisionId mrid = dd.getDependencyRevisionId();
            ExcludeRule[] excludes = null;
            if (dd.canExclude()) {
                excludes = dd.getAllExcludeRules();
            }
            DependencyArtifactDescriptor[] dads = dd.getAllDependencyArtifacts();
            if (dads.length > 0) {
                for (DependencyArtifactDescriptor dad : dads) {
                    String type = dad.getType();
                    String classifier = dad.getExtraAttribute("classifier");
                    String scope = mapping.getScope(dd.getModuleConfigurations());
                    boolean optional = mapping.isOptional(dd.getModuleConfigurations());
                    printDependency(out, indent, mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), type, classifier, scope, optional, dd.isTransitive(), excludes);
                }
            } else {
                String scope = mapping.getScope(dd.getModuleConfigurations());
                boolean optional = mapping.isOptional(dd.getModuleConfigurations());
                final String classifier = dd.getExtraAttribute("classifier");
                printDependency(out, indent, mrid.getOrganisation(), mrid.getName(), mrid.getRevision(), null, classifier, scope, optional, dd.isTransitive(), excludes);
            }
        }
        if (printDependencies) {
            indent(out, indent);
            out.println("</dependencies>");
        }
    }
}
Also used : ConfigurationScopeMapping(org.apache.ivy.plugins.parser.m2.PomWriterOptions.ConfigurationScopeMapping) DependencyArtifactDescriptor(org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor) DependencyDescriptor(org.apache.ivy.core.module.descriptor.DependencyDescriptor) ExtraDependency(org.apache.ivy.plugins.parser.m2.PomWriterOptions.ExtraDependency) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) ExcludeRule(org.apache.ivy.core.module.descriptor.ExcludeRule)

Aggregations

DependencyArtifactDescriptor (org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor)1 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)1 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)1 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)1 ConfigurationScopeMapping (org.apache.ivy.plugins.parser.m2.PomWriterOptions.ConfigurationScopeMapping)1 ExtraDependency (org.apache.ivy.plugins.parser.m2.PomWriterOptions.ExtraDependency)1