Java Code Examples for org.apache.ivy.core.module.id.ModuleRevisionId#getBranch()

The following examples show how to use org.apache.ivy.core.module.id.ModuleRevisionId#getBranch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MRIDTransformationRule.java    From ant-ivy with Apache License 2.0 6 votes vote down vote up
public boolean match(MRIDRule src, ModuleRevisionId mrid) {
    // CheckStyle:MagicNumber| OFF
    matchers[0] = Pattern.compile(getPattern(src.getOrg())).matcher(mrid.getOrganisation());
    if (!matchers[0].matches()) {
        return false;
    }
    matchers[1] = Pattern.compile(getPattern(src.getModule())).matcher(mrid.getName());
    if (!matchers[1].matches()) {
        return false;
    }
    if (mrid.getBranch() == null) {
        matchers[2] = null;
    } else {
        matchers[2] = Pattern.compile(getPattern(src.getBranch()))
                .matcher(mrid.getBranch());
        if (!matchers[2].matches()) {
            return false;
        }
    }
    matchers[3] = Pattern.compile(getPattern(src.getRev())).matcher(mrid.getRevision());
    return matchers[3].matches();
    // CheckStyle:MagicNumber| ON
}
 
Example 2
Source File: LatestVersionMatcher.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public boolean accept(ModuleRevisionId askedMrid, ModuleDescriptor foundMD) {
    String askedBranch = askedMrid.getBranch();
    String foundBranch = foundMD.getModuleRevisionId().getBranch();
    boolean sameBranch = (askedBranch == null) ? foundBranch == null
            : askedBranch.equals(foundBranch);
    if (!sameBranch) {
        return false;
    }
    String askedStatus = askedMrid.getRevision().substring("latest.".length());
    return StatusManager.getCurrent().getPriority(askedStatus) >= StatusManager.getCurrent()
            .getPriority(foundMD.getStatus());
}
 
Example 3
Source File: IvyXmlModuleDescriptorWriter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void printDependency(ModuleDescriptor md, DependencyDescriptor dep,
                                      SimpleXmlWriter writer) throws IOException {
    writer.startElement("dependency");

    ModuleRevisionId dependencyRevisionId = dep.getDependencyRevisionId();
    writer.attribute("org", dependencyRevisionId.getOrganisation());
    writer.attribute("name", dependencyRevisionId.getName());
    if (dependencyRevisionId.getBranch() != null) {
        writer.attribute("branch", dependencyRevisionId.getBranch());
    }
    writer.attribute("rev", dependencyRevisionId.getRevision());
    if (!dep.getDynamicConstraintDependencyRevisionId().equals(dependencyRevisionId)) {
        if (dep.getDynamicConstraintDependencyRevisionId().getBranch() != null) {
            writer.attribute("branchConstraint", dep.getDynamicConstraintDependencyRevisionId().getBranch());
        }
        writer.attribute("revConstraint", dep.getDynamicConstraintDependencyRevisionId().getRevision());
    }
    if (dep.isForce()) {
        writer.attribute("force", "true");
    }
    if (dep.isChanging()) {
        writer.attribute("changing", "true");
    }
    if (!dep.isTransitive()) {
        writer.attribute("transitive", "false");
    }
    writer.attribute("conf", getConfMapping(dep));

    printExtraAttributes(dep, writer);

    DependencyArtifactDescriptor[] depArtifacts = dep.getAllDependencyArtifacts();
    printDependencyArtefacts(md, writer, depArtifacts);

    IncludeRule[] includes = dep.getAllIncludeRules();
    printDependencyIncludeRules(md, writer, includes);

    ExcludeRule[] excludes = dep.getAllExcludeRules();
    printDependencyExcludeRules(md, writer, excludes);

    writer.endElement();
}
 
Example 4
Source File: IvyXmlModuleDescriptorWriter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    Date publicationDate = md.getResolvedPublicationDate();
    if (publicationDate != null) {
        writer.attribute("publication", ivyDateFormat.format(publicationDate));
    }
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        if (extraDescr.getKey() instanceof NamespaceId) {
            NamespaceId id = (NamespaceId) extraDescr.getKey();
            writer.startElement(String.format("ns:%s", id.getName()));
            writer.attribute("xmlns:ns", id.getNamespace());
        } else {
            writer.startElement(extraDescr.getKey().toString());
        }
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 5
Source File: IvyXmlModuleDescriptorWriter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void printDependency(ModuleDescriptor md, DependencyDescriptor dep,
                                      SimpleXmlWriter writer) throws IOException {
    writer.startElement("dependency");

    ModuleRevisionId dependencyRevisionId = dep.getDependencyRevisionId();
    writer.attribute("org", dependencyRevisionId.getOrganisation());
    writer.attribute("name", dependencyRevisionId.getName());
    if (dependencyRevisionId.getBranch() != null) {
        writer.attribute("branch", dependencyRevisionId.getBranch());
    }
    writer.attribute("rev", dependencyRevisionId.getRevision());
    if (!dep.getDynamicConstraintDependencyRevisionId().equals(dependencyRevisionId)) {
        if (dep.getDynamicConstraintDependencyRevisionId().getBranch() != null) {
            writer.attribute("branchConstraint", dep.getDynamicConstraintDependencyRevisionId().getBranch());
        }
        writer.attribute("revConstraint", dep.getDynamicConstraintDependencyRevisionId().getRevision());
    }
    if (dep.isForce()) {
        writer.attribute("force", "true");
    }
    if (dep.isChanging()) {
        writer.attribute("changing", "true");
    }
    if (!dep.isTransitive()) {
        writer.attribute("transitive", "false");
    }
    writer.attribute("conf", getConfMapping(dep));

    printExtraAttributes(dep, writer);

    DependencyArtifactDescriptor[] depArtifacts = dep.getAllDependencyArtifacts();
    printDependencyArtefacts(md, writer, depArtifacts);

    IncludeRule[] includes = dep.getAllIncludeRules();
    printDependencyIncludeRules(md, writer, includes);

    ExcludeRule[] excludes = dep.getAllExcludeRules();
    printDependencyExcludeRules(md, writer, excludes);

    writer.endElement();
}
 
Example 6
Source File: IvyXmlModuleDescriptorWriter.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    writer.attribute("publication", ivyDateFormat.format(md.getResolvedPublicationDate()));
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        writer.startElement(extraDescr.getKey().toString());
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 7
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void printDependency(ModuleDescriptor md, DependencyDescriptor dep,
                                      SimpleXmlWriter writer) throws IOException {
    writer.startElement("dependency");

    ModuleRevisionId dependencyRevisionId = dep.getDependencyRevisionId();
    writer.attribute("org", dependencyRevisionId.getOrganisation());
    writer.attribute("name", dependencyRevisionId.getName());
    if (dependencyRevisionId.getBranch() != null) {
        writer.attribute("branch", dependencyRevisionId.getBranch());
    }
    writer.attribute("rev", dependencyRevisionId.getRevision());
    if (!dep.getDynamicConstraintDependencyRevisionId().equals(dependencyRevisionId)) {
        if (dep.getDynamicConstraintDependencyRevisionId().getBranch() != null) {
            writer.attribute("branchConstraint", dep.getDynamicConstraintDependencyRevisionId().getBranch());
        }
        writer.attribute("revConstraint", dep.getDynamicConstraintDependencyRevisionId().getRevision());
    }
    if (dep.isForce()) {
        writer.attribute("force", "true");
    }
    if (dep.isChanging()) {
        writer.attribute("changing", "true");
    }
    if (!dep.isTransitive()) {
        writer.attribute("transitive", "false");
    }
    writer.attribute("conf", getConfMapping(dep));

    printExtraAttributes(dep, writer);

    DependencyArtifactDescriptor[] depArtifacts = dep.getAllDependencyArtifacts();
    printDependencyArtefacts(md, writer, depArtifacts);

    IncludeRule[] includes = dep.getAllIncludeRules();
    printDependencyIncludeRules(md, writer, includes);

    ExcludeRule[] excludes = dep.getAllExcludeRules();
    printDependencyExcludeRules(md, writer, excludes);

    writer.endElement();
}
 
Example 8
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    Date publicationDate = md.getResolvedPublicationDate();
    if (publicationDate != null) {
        writer.attribute("publication", ivyDateFormat.format(publicationDate));
    }
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        if (extraDescr.getKey() instanceof NamespaceId) {
            NamespaceId id = (NamespaceId) extraDescr.getKey();
            writer.startElement(String.format("ns:%s", id.getName()));
            writer.attribute("xmlns:ns", id.getNamespace());
        } else {
            writer.startElement(extraDescr.getKey().toString());
        }
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 9
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void printDependency(ModuleDescriptor md, DependencyDescriptor dep,
                                      SimpleXmlWriter writer) throws IOException {
    writer.startElement("dependency");

    ModuleRevisionId dependencyRevisionId = dep.getDependencyRevisionId();
    writer.attribute("org", dependencyRevisionId.getOrganisation());
    writer.attribute("name", dependencyRevisionId.getName());
    if (dependencyRevisionId.getBranch() != null) {
        writer.attribute("branch", dependencyRevisionId.getBranch());
    }
    writer.attribute("rev", dependencyRevisionId.getRevision());
    if (!dep.getDynamicConstraintDependencyRevisionId().equals(dependencyRevisionId)) {
        if (dep.getDynamicConstraintDependencyRevisionId().getBranch() != null) {
            writer.attribute("branchConstraint", dep.getDynamicConstraintDependencyRevisionId().getBranch());
        }
        writer.attribute("revConstraint", dep.getDynamicConstraintDependencyRevisionId().getRevision());
    }
    if (dep.isForce()) {
        writer.attribute("force", "true");
    }
    if (dep.isChanging()) {
        writer.attribute("changing", "true");
    }
    if (!dep.isTransitive()) {
        writer.attribute("transitive", "false");
    }
    writer.attribute("conf", getConfMapping(dep));

    printExtraAttributes(dep, writer);

    DependencyArtifactDescriptor[] depArtifacts = dep.getAllDependencyArtifacts();
    printDependencyArtefacts(md, writer, depArtifacts);

    IncludeRule[] includes = dep.getAllIncludeRules();
    printDependencyIncludeRules(md, writer, includes);

    ExcludeRule[] excludes = dep.getAllExcludeRules();
    printDependencyExcludeRules(md, writer, excludes);

    writer.endElement();
}
 
Example 10
Source File: IvyXmlModuleDescriptorWriter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static void printInfoTag(ModuleDescriptor md, SimpleXmlWriter writer) throws IOException {
    ModuleRevisionId moduleRevisionId = md.getModuleRevisionId();
    writer.startElement("info");

    writer.attribute("organisation", moduleRevisionId.getOrganisation());
    writer.attribute("module", moduleRevisionId.getName());

    ModuleRevisionId resolvedModuleRevisionId = md.getResolvedModuleRevisionId();
    String branch = resolvedModuleRevisionId.getBranch();
    if (branch != null) {
        writer.attribute("branch", branch);
    }
    String revision = resolvedModuleRevisionId.getRevision();
    if (revision != null) {
        writer.attribute("revision", revision);
    }
    writer.attribute("status", md.getStatus());

    SimpleDateFormat ivyDateFormat = new SimpleDateFormat(IVY_DATE_PATTERN);
    writer.attribute("publication", ivyDateFormat.format(md.getResolvedPublicationDate()));
    if (md.isDefault()) {
        writer.attribute("default", "true");
    }
    if (md instanceof DefaultModuleDescriptor) {
        DefaultModuleDescriptor dmd = (DefaultModuleDescriptor) md;
        if (dmd.getNamespace() != null && !dmd.getNamespace().getName().equals("system")) {
            writer.attribute("namespace", dmd.getNamespace().getName());
        }
    }
    if (!md.getExtraAttributes().isEmpty()) {
        printExtraAttributes(md, writer);
    }

    ExtendsDescriptor[] parents = md.getInheritedDescriptors();
    if (parents.length != 0) {
        throw new UnsupportedOperationException("Extends descriptors not supported.");
    }

    License[] licenses = md.getLicenses();
    for (int i = 0; i < licenses.length; i++) {
        License license = licenses[i];
        writer.startElement("license");
        if (license.getName() != null) {
            writer.attribute("name", license.getName());
        }
        if (license.getUrl() != null) {
            writer.attribute("url", license.getUrl());
        }
        writer.endElement();
    }

    if (md.getHomePage() != null || md.getDescription() != null) {
        writer.startElement("description");
        if (md.getHomePage() != null) {
            writer.attribute("homepage", md.getHomePage());
        }
        if (md.getDescription() != null && md.getDescription().trim().length() > 0) {
            writer.characters(md.getDescription());
        }
        writer.endElement();
    }

    for (Iterator it = md.getExtraInfo().entrySet().iterator(); it.hasNext();) {
        Map.Entry extraDescr = (Map.Entry) it.next();
        if (extraDescr.getValue() == null || ((String) extraDescr.getValue()).length() == 0) {
            continue;
        }
        writer.startElement(extraDescr.getKey().toString());
        writer.characters(extraDescr.getValue().toString());
        writer.endElement();
    }

    writer.endElement();
}
 
Example 11
Source File: XmlModuleDescriptorWriter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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>");
    }
}
 
Example 12
Source File: XmlModuleDescriptorUpdater.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void infoStarted(Attributes attributes) {

            String module = substitute(settings, attributes.getValue("module"));
            String rev = null;
            String branch = null;
            String status = null;
            String namespace = null;
            Map<String, String> extraAttributes = null;

            if (options.isMerge()) {
                // get attributes from merged descriptor, ignoring raw XML
                ModuleDescriptor merged = options.getMergedDescriptor();
                ModuleRevisionId mergedMrid = merged.getModuleRevisionId();
                organisation = mergedMrid.getOrganisation();
                branch = mergedMrid.getBranch();
                rev = mergedMrid.getRevision();
                status = merged.getStatus();

                // TODO: should namespace be added to ModuleDescriptor interface, so we don't
                // have to do this kind of check?
                if (merged instanceof DefaultModuleDescriptor) {
                    Namespace ns = ((DefaultModuleDescriptor) merged).getNamespace();
                    if (ns != null) {
                        namespace = ns.getName();
                    }
                }
                if (namespace == null) {
                    namespace = attributes.getValue("namespace");
                }

                extraAttributes = merged.getQualifiedExtraAttributes();
            } else {
                // get attributes from raw XML, performing property substitution
                organisation = substitute(settings, attributes.getValue("organisation"));
                rev = substitute(settings, attributes.getValue("revision"));
                branch = substitute(settings, attributes.getValue("branch"));
                status = substitute(settings, attributes.getValue("status"));
                namespace = substitute(settings, attributes.getValue("namespace"));
                extraAttributes = new LinkedHashMap<>(attributes.getLength());
                for (int i = 0; i < attributes.getLength(); i++) {
                    String qname = attributes.getQName(i);
                    if (!STD_ATTS.contains(qname)) {
                        extraAttributes.put(qname, substitute(settings, attributes.getValue(i)));
                    }
                }
            }

            // apply override values provided in options
            if (revision != null) {
                rev = revision;
            }
            if (options.getBranch() != null) {
                branch = options.getBranch();
            }
            if (this.status != null) {
                status = this.status;
            }

            // if necessary translate mrid using optional namespace argument
            ModuleRevisionId localMid = ModuleRevisionId.newInstance(organisation, module, branch,
                rev, ExtendableItemHelper.getExtraAttributes(settings, attributes,
                            Arrays.asList("organisation", "module", "revision", "status",
                                    "publication", "namespace")));
            ModuleRevisionId systemMid = (ns == null) ? localMid : ns.getToSystemTransformer()
                    .transform(localMid);

            write("<info");
            if (organisation != null) {
                write(" organisation=\"" + XMLHelper.escape(systemMid.getOrganisation()) + "\"");
            }
            write(" module=\"" + XMLHelper.escape(systemMid.getName()) + "\"");
            if (branch != null) {
                write(" branch=\"" + XMLHelper.escape(systemMid.getBranch()) + "\"");
            }
            if (systemMid.getRevision() != null) {
                write(" revision=\"" + XMLHelper.escape(systemMid.getRevision()) + "\"");
            }
            write(" status=\"" + XMLHelper.escape(status) + "\"");
            if (pubdate != null) {
                write(" publication=\"" + DateUtil.format(pubdate) + "\"");
            } else if (attributes.getValue("publication") != null) {
                write(" publication=\"" + substitute(settings, attributes.getValue("publication"))
                        + "\"");
            }
            if (namespace != null) {
                write(" namespace=\"" + namespace + "\"");
            }

            for (Map.Entry<String, String> extra : extraAttributes.entrySet()) {
                write(" " + extra.getKey() + "=\"" + extra.getValue() + "\"");
            }
        }
 
Example 13
Source File: XmlReportWriter.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
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.getQualifiedExtraAttributes(), "\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();
}
 
Example 14
Source File: BasicResolver.java    From ant-ivy with Apache License 2.0 4 votes vote down vote up
private void checkDescriptorConsistency(ModuleRevisionId mrid, ModuleDescriptor md,
        ResolvedResource ivyRef) throws ParseException {
    boolean ok = true;
    StringBuilder errors = new StringBuilder();
    if (!mrid.getOrganisation().equals(md.getModuleRevisionId().getOrganisation())) {
        Message.error(String.format("\t%s: bad organisation found in %s: expected='%s' found='%s'",
                getName(), ivyRef.getResource(), mrid.getOrganisation(),
                md.getModuleRevisionId().getOrganisation()));
        errors.append("bad organisation: expected='").append(mrid.getOrganisation())
                .append("' found='").append(md.getModuleRevisionId().getOrganisation()).append("'; ");
        ok = false;
    }
    if (!mrid.getName().equals(md.getModuleRevisionId().getName())) {
        Message.error(String.format("\t%s: bad module name found in %s: expected='%s found='%s'",
                getName(), ivyRef.getResource(), mrid.getName(),
                md.getModuleRevisionId().getName()));
        errors.append("bad module name: expected='").append(mrid.getName()).append("' found='")
                .append(md.getModuleRevisionId().getName()).append("'; ");
        ok = false;
    }
    if (mrid.getBranch() != null
            && !mrid.getBranch().equals(md.getModuleRevisionId().getBranch())) {
        Message.error(String.format("\t%s: bad branch name found in %s: expected='%s found='%s'",
                getName(), ivyRef.getResource(), mrid.getBranch(),
                md.getModuleRevisionId().getBranch()));
        errors.append("bad branch name: expected='").append(mrid.getBranch()).append("' found='")
                .append(md.getModuleRevisionId().getBranch()).append("'; ");
        ok = false;
    }
    if (ivyRef.getRevision() != null && !ivyRef.getRevision().startsWith("working@")
            && !mrid.getRevision().equals(md.getModuleRevisionId().getRevision())) {
        ModuleRevisionId expectedMrid = ModuleRevisionId.newInstance(mrid, mrid.getRevision());
        if (!getSettings().getVersionMatcher().accept(expectedMrid, md)) {
            Message.error(String.format("\t%s: bad revision found in %s: expected='%s found='%s'",
                    getName(), ivyRef.getResource(), ivyRef.getRevision(),
                    md.getModuleRevisionId().getRevision()));
            errors.append("bad revision: expected='").append(ivyRef.getRevision())
                    .append("' found='").append(md.getModuleRevisionId().getRevision()).append("'; ");
            ok = false;
        }
    }
    if (!getSettings().getStatusManager().isStatus(md.getStatus())) {
        Message.error(String.format("\t%s: bad status found in %s: '%s'",
                getName(), ivyRef.getResource(), md.getStatus()));
        errors.append("bad status: '").append(md.getStatus()).append("'; ");
        ok = false;
    }
    for (Map.Entry<String, String> extra : mrid.getExtraAttributes().entrySet()) {
        if (extra.getValue() != null
                && !extra.getValue().equals(md.getExtraAttribute(extra.getKey()))) {
            String errorMsg = String.format("bad %s found in %s: expected='%s' found='%s'",
                    extra.getKey(), ivyRef.getResource(), extra.getValue(),
                    md.getExtraAttribute(extra.getKey()));
            Message.error("\t" + getName() + ": " + errorMsg);
            errors.append(errorMsg).append(";");
            ok = false;
        }
    }
    if (!ok) {
        throw new ParseException("inconsistent module descriptor file found in '"
                + ivyRef.getResource() + "': " + errors, 0);
    }
}