private void startElementInDependency()

in src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java [545:655]


        private void startElementInDependency(Attributes attributes) {
            ExtendedBuffer buffer = new ExtendedBuffer(getContext());
            buffers.push(buffer);
            confAttributeBuffers.push(buffer);
            buffer.setDefaultPrint(isNullOrEmpty(attributes.getValue("conf")));
            write("<dependency");
            String org = substitute(settings, attributes.getValue("org"));
            if (org == null) {
                org = organisation;
            }
            String module = substitute(settings, attributes.getValue("name"));
            String branch = substitute(settings, attributes.getValue("branch"));
            String branchConstraint = substitute(settings, attributes.getValue("branchConstraint"));
            if (branchConstraint == null) {
                branchConstraint = branch;
            }

            // look for the branch used in resolved revisions
            if (branch == null) {
                ModuleId mid = ModuleId.newInstance(org, module);
                if (ns != null) {
                    mid = NameSpaceHelper.transform(mid, ns.getToSystemTransformer());
                }
                for (ModuleRevisionId mrid : resolvedRevisions.keySet()) {
                    if (mrid.getModuleId().equals(mid)) {
                        branch = mrid.getBranch();
                        break;
                    }
                }
            }

            String revision = substitute(settings, attributes.getValue("rev"));
            String revisionConstraint = substitute(settings, attributes.getValue("revConstraint"));
            Map<String, String> extraAttributes = ExtendableItemHelper.getExtraAttributes(settings, attributes,
                XmlModuleDescriptorParser.DEPENDENCY_REGULAR_ATTRIBUTES);
            ModuleRevisionId localMrid = ModuleRevisionId.newInstance(org, module, branch,
                revision, extraAttributes);
            ModuleRevisionId systemMrid = (ns == null) ? localMrid : ns.getToSystemTransformer()
                    .transform(localMrid);

            String newBranch = resolvedBranches.get(systemMrid);

            for (int i = 0; i < attributes.getLength(); i++) {
                String attName = attributes.getQName(i);
                switch (attName) {
                    case "org":
                        write(" org=\"" + systemMrid.getOrganisation() + "\"");
                        break;
                    case "name":
                        write(" name=\"" + systemMrid.getName() + "\"");
                        break;
                    case "rev":
                        String rev = resolvedRevisions.get(systemMrid);
                        if (rev == null) {
                            write(" rev=\"" + systemMrid.getRevision() + "\"");
                        } else {
                            write(" rev=\"" + rev + "\"");
                            if (attributes.getIndex("branchConstraint") == -1
                                    && branchConstraint != null) {
                                write(" branchConstraint=\"" + branchConstraint + "\"");
                            }
                            if (generateRevConstraint && attributes.getIndex("revConstraint") == -1
                                    && !rev.equals(systemMrid.getRevision())) {
                                write(" revConstraint=\"" + systemMrid.getRevision() + "\"");
                            }
                        }
                        break;
                    case "revConstraint":
                        write(" revConstraint=\"" + revisionConstraint + "\"");
                        break;
                    case "branch":
                        if (newBranch != null) {
                            write(" branch=\"" + newBranch + "\"");
                        } else if (!resolvedBranches.containsKey(systemMrid)) {
                            write(" branch=\"" + systemMrid.getBranch() + "\"");
                        } else {
                            // if resolvedBranches contains the systemMrid, but the new branch is null,
                            // the branch attribute will be removed altogether
                        }
                        break;
                    case "branchConstraint":
                        write(" branchConstraint=\"" + branchConstraint + "\"");
                        break;
                    case "conf":
                        String oldMapping = substitute(settings, attributes.getValue("conf"));
                        if (!oldMapping.isEmpty()) {
                            String newMapping = removeConfigurationsFromMapping(oldMapping);
                            if (!newMapping.isEmpty()) {
                                write(" conf=\"" + newMapping + "\"");
                                buffers.peek().setPrint(true);
                            }
                        }
                        break;
                    default:
                        write(" " + attName + "=\""
                                + substitute(settings, attributes.getValue(attName)) + "\"");
                        break;
                }
            }

            if (attributes.getIndex("branch") == -1) {
                // erase an existing branch attribute if its new value is blank
                if (!isNullOrEmpty(newBranch)) {
                    write(" branch=\"" + newBranch + "\"");
                } else if (options.isUpdateBranch() && systemMrid.getBranch() != null) {
                    // this dependency is on a specific branch, we set it explicitly in the updated
                    // file
                    write(" branch=\"" + systemMrid.getBranch() + "\"");
                }
            }
        }