Search in sources :

Example 46 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class PomModuleDescriptorBuilder method getDependencyManagements.

public static List<PomDependencyMgt> getDependencyManagements(ModuleDescriptor md) {
    List<PomDependencyMgt> result = new ArrayList<>();
    if (md instanceof PomModuleDescriptor) {
        result.addAll(((PomModuleDescriptor) md).getDependencyManagementMap().values());
    } else {
        for (ExtraInfoHolder extraInfoHolder : md.getExtraInfos()) {
            String key = extraInfoHolder.getName();
            if (key.startsWith(DEPENDENCY_MANAGEMENT)) {
                String[] parts = key.split(EXTRA_INFO_DELIMITER);
                if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
                    Message.warn("what seem to be a dependency management extra info " + "doesn't match expected pattern: " + key);
                } else {
                    String versionKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1] + EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER + "version";
                    String scopeKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1] + EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER + "scope";
                    String version = md.getExtraInfoContentByTagName(versionKey);
                    String scope = md.getExtraInfoContentByTagName(scopeKey);
                    List<ModuleId> exclusions = getDependencyMgtExclusions(md, parts[1], parts[2]);
                    result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope, exclusions));
                }
            }
        }
    }
    return result;
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) ArrayList(java.util.ArrayList)

Example 47 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class XmlReportWriter method output.

public void output(ConfigurationResolveReport report, String[] confs, OutputStream stream) {
    OutputStreamWriter encodedOutStream;
    try {
        encodedOutStream = new OutputStreamWriter(stream, REPORT_ENCODING);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(REPORT_ENCODING + " is not known on your jvm", e);
    }
    PrintWriter out = new PrintWriter(new BufferedWriter(encodedOutStream));
    ModuleRevisionId mrid = report.getModuleDescriptor().getModuleRevisionId();
    // out.println("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
    out.println("<?xml version=\"1.0\" encoding=\"" + REPORT_ENCODING + "\"?>");
    out.println("<?xml-stylesheet type=\"text/xsl\" href=\"ivy-report.xsl\"?>");
    out.println("<ivy-report version=\"1.0\">");
    out.println("\t<info");
    out.println("\t\torganisation=\"" + XMLHelper.escape(mrid.getOrganisation()) + "\"");
    out.println("\t\tmodule=\"" + XMLHelper.escape(mrid.getName()) + "\"");
    out.println("\t\trevision=\"" + XMLHelper.escape(mrid.getRevision()) + "\"");
    if (mrid.getBranch() != null) {
        out.println("\t\tbranch=\"" + XMLHelper.escape(mrid.getBranch()) + "\"");
    }
    out.println(extraToString(mrid.getExtraAttributes(), "\t\t"));
    out.println("\t\tconf=\"" + XMLHelper.escape(report.getConfiguration()) + "\"");
    out.println("\t\tconfs=\"" + XMLHelper.escape(joinArray(confs, ", ")) + "\"");
    out.println("\t\tdate=\"" + DateUtil.format(report.getDate()) + "\"/>");
    out.println("\t<dependencies>");
    // create a list of ModuleRevisionIds indicating the position for each dependency
    List<ModuleRevisionId> dependencies = new ArrayList<>(report.getModuleRevisionIds());
    for (ModuleId mid : report.getModuleIds()) {
        out.println("\t\t<module organisation=\"" + XMLHelper.escape(mid.getOrganisation()) + "\"" + " name=\"" + XMLHelper.escape(mid.getName()) + "\">");
        for (IvyNode dep : report.getNodes(mid)) {
            outputRevision(report, out, dependencies, dep);
        }
        out.println("\t\t</module>");
    }
    out.println("\t</dependencies>");
    out.println("</ivy-report>");
    out.flush();
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ModuleRevisionId(org.apache.ivy.core.module.id.ModuleRevisionId) OutputStreamWriter(java.io.OutputStreamWriter) IvyNode(org.apache.ivy.core.resolve.IvyNode) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter)

Example 48 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class PomModuleDescriptorBuilder method getDependencyManagementMap.

public static Map<ModuleId, String> getDependencyManagementMap(ModuleDescriptor md) {
    Map<ModuleId, String> ret = new LinkedHashMap<>();
    if (md instanceof PomModuleDescriptor) {
        for (Map.Entry<ModuleId, PomDependencyMgt> e : ((PomModuleDescriptor) md).getDependencyManagementMap().entrySet()) {
            PomDependencyMgt dependencyMgt = e.getValue();
            ret.put(e.getKey(), dependencyMgt.getVersion());
        }
    } else {
        for (ExtraInfoHolder extraInfoHolder : md.getExtraInfos()) {
            String key = extraInfoHolder.getName();
            if (key.startsWith(DEPENDENCY_MANAGEMENT)) {
                String[] parts = key.split(EXTRA_INFO_DELIMITER);
                if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
                    Message.warn("what seem to be a dependency management extra info " + "doesn't match expected pattern: " + key);
                } else {
                    ret.put(ModuleId.newInstance(parts[1], parts[2]), extraInfoHolder.getContent());
                }
            }
        }
    }
    return ret;
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 49 with ModuleId

use of org.apache.ivy.core.module.id.ModuleId in project ant-ivy by apache.

the class PomModuleDescriptorBuilder method getDependencyMgtExclusions.

private static List<ModuleId> getDependencyMgtExclusions(ModuleDescriptor descriptor, String groupId, String artifactId) {
    if (descriptor instanceof PomModuleDescriptor) {
        PomDependencyMgt dependencyMgt = ((PomModuleDescriptor) descriptor).getDependencyManagementMap().get(ModuleId.newInstance(groupId, artifactId));
        if (dependencyMgt != null) {
            return dependencyMgt.getExcludedModules();
        }
    }
    String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion(groupId, artifactId);
    List<ModuleId> exclusionIds = new LinkedList<>();
    for (ExtraInfoHolder extraInfoHolder : descriptor.getExtraInfos()) {
        String key = extraInfoHolder.getName();
        if (key.startsWith(exclusionPrefix)) {
            String fullExclusion = extraInfoHolder.getContent();
            String[] exclusionParts = fullExclusion.split(EXTRA_INFO_DELIMITER);
            if (exclusionParts.length != 2) {
                Message.error(WRONG_NUMBER_OF_PARTS_MSG + exclusionParts.length + " : " + fullExclusion);
                continue;
            }
            exclusionIds.add(ModuleId.newInstance(exclusionParts[0], exclusionParts[1]));
        }
    }
    return exclusionIds;
}
Also used : ModuleId(org.apache.ivy.core.module.id.ModuleId) ExtraInfoHolder(org.apache.ivy.core.module.descriptor.ExtraInfoHolder) LinkedList(java.util.LinkedList)

Aggregations

ModuleId (org.apache.ivy.core.module.id.ModuleId)49 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)19 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)13 File (java.io.File)9 HashMap (java.util.HashMap)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Date (java.util.Date)6 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)6 DefaultModuleDescriptor (org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor)6 DependencyDescriptor (org.apache.ivy.core.module.descriptor.DependencyDescriptor)6 BuildException (org.apache.tools.ant.BuildException)6 Ivy (org.apache.ivy.Ivy)5 ArtifactId (org.apache.ivy.core.module.id.ArtifactId)5 ResolveReport (org.apache.ivy.core.report.ResolveReport)5 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)5 IvySettings (org.apache.ivy.core.settings.IvySettings)5 IOException (java.io.IOException)4 Map (java.util.Map)4 Configuration (org.apache.ivy.core.module.descriptor.Configuration)4