@NonNull private static XmlElement createOrGetElement( @NonNull ActionRecorder actionRecorder, @NonNull XmlDocument document, @NonNull ManifestModel.NodeTypes nodeType, @NonNull String message) { Element manifest = document.getXml().getDocumentElement(); NodeList nodes = manifest.getElementsByTagName(nodeType.toXmlName()); if (nodes.getLength() == 0) { nodes = manifest.getElementsByTagNameNS( SdkConstants.ANDROID_URI, nodeType.toXmlName()); } if (nodes.getLength() == 0) { // create it first. Element node = manifest.getOwnerDocument().createElement(nodeType.toXmlName()); manifest.appendChild(node); XmlElement xmlElement = new XmlElement(node, document); Actions.NodeRecord nodeRecord = new Actions.NodeRecord( Actions.ActionType.INJECTED, new SourceFilePosition(xmlElement.getSourceFile(), SourcePosition.UNKNOWN), xmlElement.getId(), message, NodeOperationType.STRICT); actionRecorder.recordNodeAction(xmlElement, nodeRecord); return xmlElement; } else { return new XmlElement((Element) nodes.item(0), document); } }
private String getLogs() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(HEADER); for (Map.Entry<XmlNode.NodeKey, Actions.DecisionTreeRecord> record : mRecords.entrySet()) { stringBuilder.append(record.getKey()).append("\n"); for (Actions.NodeRecord nodeRecord : record.getValue().getNodeRecords()) { nodeRecord.print(stringBuilder); stringBuilder.append('\n'); } for (Map.Entry<XmlNode.NodeName, List<Actions.AttributeRecord>> attributeRecords : record.getValue().mAttributeRecords.entrySet()) { stringBuilder.append('\t').append(attributeRecords.getKey()).append('\n'); for (Actions.AttributeRecord attributeRecord : attributeRecords.getValue()) { stringBuilder.append("\t\t"); attributeRecord.print(stringBuilder); stringBuilder.append('\n'); } } } return stringBuilder.toString(); }
/** * Record a node that was added due to an implicit presence in earlier SDK release but requires * an explicit declaration in the application targeted SDK. * @param xmlElement the implied element that was added to the resulting xml. * @param reason optional contextual information whey the implied element was added. */ synchronized void recordImpliedNodeAction(@NonNull XmlElement xmlElement, @Nullable String reason) { NodeKey storageKey = xmlElement.getOriginalId(); Actions.DecisionTreeRecord nodeDecisionTree = mRecords.get(storageKey); if (nodeDecisionTree == null) { nodeDecisionTree = new Actions.DecisionTreeRecord(); mRecords.put(storageKey, nodeDecisionTree); } Actions.NodeRecord record = new Actions.NodeRecord(Actions.ActionType.IMPLIED, new SourceFilePosition( xmlElement.getDocument().getSourceFile(), xmlElement.getDocument().getRootNode().getPosition()), xmlElement.getOriginalId(), reason, xmlElement.getOperationType() ); nodeDecisionTree.addNodeRecord(record); }
/** * Record a node action taken by the merging tool. * * @param mergedElement the merged xml element * @param actionType the action's type * @param targetElement the action's target when the action is rejected or replaced, it * indicates what is the element being rejected or replaced. */ synchronized void recordNodeAction( @NonNull XmlElement mergedElement, @NonNull Actions.ActionType actionType, @NonNull XmlElement targetElement) { Actions.NodeRecord record = new Actions.NodeRecord(actionType, new SourceFilePosition( targetElement.getDocument().getSourceFile(), targetElement.getPosition()), targetElement.getOriginalId(), null, /* reason */ mergedElement.getOperationType() ); recordNodeAction(mergedElement, record); }
/** * Check in our list of applied actions that a particular * {@link com.android.manifmerger.Actions.ActionType} action was recorded on the passed element. * @return true if it was applied, false otherwise. */ private static boolean isNodeOperationPresent(@NonNull XmlElement xmlElement, @NonNull Actions actions, ActionType action) { for (Actions.NodeRecord nodeRecord : actions.getNodeRecords(xmlElement.getId())) { if (nodeRecord.getActionType() == action) { return true; } } return false; }
@Nullable private static Actions.NodeRecord findNodeRecord(@NonNull DecisionTreeRecord decisionTreeRecord) { for (Actions.NodeRecord nodeRecord : decisionTreeRecord.getNodeRecords()) { if (nodeRecord.getActionType() == Actions.ActionType.ADDED) { return nodeRecord; } } return null; }
@NonNull @Override public String toString() { return "Id=" + mTargetId.toString() + " actionType=" + getActionType() + " location=" + getActionLocation() + " opType=" + mNodeOperationType; } }