@NonNull @Override public SourceFile getSourceFile() { return mDocument.getSourceFile(); }
throw new RuntimeException(MergingException.wrapException(e) .withMessage(errorMessage) .withFile(mDocument.getSourceFile()) .withPosition(XmlDocument.getNodePosition(xml)).build());
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; }
xmlElement.getId(), attributeOperation.getKey(), xmlElement.getDocument().getSourceFile().print(true), xmlElement.getPosition().getStartLine() + 1 )); xmlElement.getId(), attributeOperation.getKey(), xmlElement.getDocument().getSourceFile().print(true), xmlElement.getPosition().getStartLine() + 1 ));
/** * Records when a default value that should be merged was rejected due to a tools:replace * annotation. * * @param attribute the attribute which default value was ignored. * @param implicitAttributeOwner the element owning the implicit default value. */ synchronized void recordImplicitRejection( @NonNull XmlAttribute attribute, @NonNull XmlElement implicitAttributeOwner) { List<Actions.AttributeRecord> attributeRecords = getAttributeRecords(attribute); Actions.AttributeRecord attributeRecord = new Actions.AttributeRecord( Actions.ActionType.REJECTED, new SourceFilePosition( implicitAttributeOwner.getDocument().getSourceFile(), implicitAttributeOwner.getPosition()), attribute.getOriginalId(), null, /* reason */ AttributeOperationType.REPLACE ); attributeRecords.add(attributeRecord); }
.addMessage( new SourceFilePosition( getSourceFile(), usesSdkElement.getPosition()), MergingReport.Record.Severity.ERROR, mergingReport.addMessage(getSourceFile(), MergingReport.Record.Severity.ERROR, String.format( "uses-sdk:targetSdkVersion %1$s cannot be different than version " getTargetSdkVersion(), libraryTargetSdkVersion, lowerPriorityDocument.getSourceFile().print(false) mergingReport.addMessage(getSourceFile(), MergingReport.Record.Severity.ERROR, String.format( "uses-sdk:minSdkVersion %1$s cannot be different than version " getMinSdkVersion(), libraryMinSdkVersion, lowerPriorityDocument.getSourceFile().print(false) getMinSdkVersion(), lowerPriorityDocument.getRawMinSdkVersion(), lowerPriorityDocument.getSourceFile().print(false), lowerPriorityDocument.getPackageName()); if (usesSdk.isPresent()) { mergingReport.addMessage( new SourceFilePosition(getSourceFile(), usesSdk.get().getPosition()),
if (mDocumentType != XmlDocument.Type.OVERLAY && !mainPackageAttribute.isPresent()) { mergingReportBuilder.addMessage( loadedMainManifestInfo.getXmlDocument().getSourceFile(), MergingReport.Record.Severity.ERROR, String.format( "Main AndroidManifest.xml at %1$s manifest:package attribute " + "is not declared", loadedMainManifestInfo.getXmlDocument().getSourceFile() .print(true))); return mergingReportBuilder.build(); mainPackageAttribute.get().printPosition()); mergingReportBuilder.addMessage( overlayDocument.getXmlDocument().getSourceFile(), MergingReport.Record.Severity.ERROR, message);
/** * 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); }
void addMessage(@NonNull MergingReport.Builder report, @NonNull SourcePosition position, @NonNull MergingReport.Record.Severity severity, @NonNull String message) { report.addMessage( new SourceFilePosition(getOwnerElement().getDocument().getSourceFile(), position), severity, message); }
+ "but no other declaration present", xmlElement.getId(), xmlElement.getDocument().getSourceFile().print(true), xmlElement.getPosition().getStartLine() + 1 )); + "but no other declaration present", xmlElement.getId(), xmlElement.getDocument().getSourceFile().print(true), xmlElement.getPosition().getStartLine() + 1 ));
/** * 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); }
/** * Records an attribute action taken by the merging tool * * @param attribute the attribute in question. * @param attributePosition the attribute's position. * @param actionType the action's type * @param attributeOperationType the original tool annotation leading to the merging tool * decision. */ synchronized void recordAttributeAction( @NonNull XmlAttribute attribute, @NonNull SourcePosition attributePosition, @NonNull Actions.ActionType actionType, @Nullable AttributeOperationType attributeOperationType) { XmlElement originElement = attribute.getOwnerElement(); Actions.AttributeRecord attributeRecord = new Actions.AttributeRecord( actionType, new SourceFilePosition( originElement.getDocument().getSourceFile(), attributePosition), attribute.getOriginalId(), null, /* reason */ attributeOperationType ); recordAttributeAction(attribute, attributeRecord); }