/** * Add an element and its leading comments as the last sub-element of the current element. * @param elementToBeAdded xml element to be added to the current element. * @param mergingReport the merging report to log errors and actions. */ private void addElement( @NonNull XmlElement elementToBeAdded, @NonNull MergingReport.Builder mergingReport) { List<Node> comments = getLeadingComments(elementToBeAdded.getXml()); // record all the actions before the node is moved from the library document to the main // merged document. mergingReport.getActionRecorder().recordDefaultNodeAction(elementToBeAdded); // only in the new file, just import it. Node node = getXml().getOwnerDocument().adoptNode(elementToBeAdded.getXml()); getXml().appendChild(node); // also adopt the child's comments if any. for (Node comment : comments) { Node newComment = getXml().getOwnerDocument().adoptNode(comment); getXml().insertBefore(newComment, node); } mergingReport.getLogger().verbose("Adopted " + node); }
/** * When the first xml file is loaded, there is nothing to merge with, however, each xml element * and attribute added to the initial merged file need to be recorded. * * @param xmlElement xml element added to the initial merged document. */ synchronized void recordDefaultNodeAction(@NonNull XmlElement xmlElement) { if (!mRecords.containsKey(xmlElement.getOriginalId())) { recordNodeAction(xmlElement, Actions.ActionType.ADDED); for (XmlAttribute xmlAttribute : xmlElement.getAttributes()) { AttributeOperationType attributeOperation = xmlElement .getAttributeOperationType(xmlAttribute.getName()); recordAttributeAction( xmlAttribute, Actions.ActionType.ADDED, attributeOperation); } for (XmlElement childNode : xmlElement.getMergeableElements()) { recordDefaultNodeAction(childNode); } } }
private Optional<XmlDocument> merge( @NonNull Optional<XmlDocument> xmlDocument, @NonNull LoadedManifestInfo lowerPriorityDocument, @NonNull MergingReport.Builder mergingReportBuilder) throws MergeFailureException { MergingReport.Result validationResult = PreValidator .validate(mergingReportBuilder, lowerPriorityDocument.getXmlDocument()); if (validationResult == MergingReport.Result.ERROR) { mergingReportBuilder.addMessage( lowerPriorityDocument.getXmlDocument().getSourceFile(), MergingReport.Record.Severity.ERROR, "Validation failed, exiting"); return Optional.absent(); } Optional<XmlDocument> result; if (xmlDocument.isPresent()) { result = xmlDocument.get().merge( lowerPriorityDocument.getXmlDocument(), mergingReportBuilder); } else { mergingReportBuilder.getActionRecorder().recordDefaultNodeAction( lowerPriorityDocument.getXmlDocument().getRootNode()); result = Optional.of(lowerPriorityDocument.getXmlDocument()); } // if requested, dump each intermediary merging stage into the report. if (mOptionalFeatures.contains(Invoker.Feature.KEEP_INTERMEDIARY_STAGES) && result.isPresent()) { mergingReportBuilder.addMergingStage(result.get().prettyPrint()); } return result; }
/** * merge this higher priority document with a higher priority document. * @param lowerPriorityDocument the lower priority document to merge in. * @param mergingReportBuilder the merging report to record errors and actions. * @return a new merged {@link com.android.manifmerger.XmlDocument} or * {@link Optional#absent()} if there were errors during the merging activities. */ @NonNull public Optional<XmlDocument> merge( @NonNull XmlDocument lowerPriorityDocument, @NonNull MergingReport.Builder mergingReportBuilder) { if (getFileType() == Type.MAIN) { mergingReportBuilder.getActionRecorder().recordDefaultNodeAction(getRootNode()); } getRootNode().mergeWithLowerPriorityNode( lowerPriorityDocument.getRootNode(), mergingReportBuilder); addImplicitElements(lowerPriorityDocument, mergingReportBuilder); // force re-parsing as new nodes may have appeared. return mergingReportBuilder.hasErrors() ? Optional.<XmlDocument>absent() : Optional.of(reparse()); }
builder.getActionRecorder().recordDefaultNodeAction(libraryDocument.getRootNode()); performPlaceHolderSubstitution( manifestInfo, libraryDocument, builder, MergeType.LIBRARY);
: new MergingReport.Builder(mergingReportBuilder.getLogger()); builder.getActionRecorder().recordDefaultNodeAction( xmlDocument.getRootNode());