Package com.android.manifmerger
Class XmlDocument
java.lang.Object
com.android.manifmerger.XmlDocument
Represents a loaded xml document.
Has pointers to the root XmlElement element and provides services to persist the
document to an external format. Also provides abilities to be merged with other XmlDocument as well as access to the line numbers for all document's xml elements and
attributes.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXmlDocument(com.android.ide.common.blame.SourceFile sourceLocation, KeyResolver<String> selectors, PlaceholderHandler.KeyBasedValueResolver<com.android.manifmerger.ManifestSystemProperty> systemPropertyResolver, Element element, XmlDocument.Type type, String namespace, com.android.manifmerger.DocumentModel<com.android.manifmerger.ManifestModel.NodeTypes> model) -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the android namespace from all nodes.cloneAndTransform(com.google.common.base.Predicate<Node> transform, com.google.common.base.Predicate<Node> shouldRemove) Clones and transforms an XML document.compareTo(XmlDocument other) Compares this document to anotherXmlDocumentignoring all attributes belonging to theSdkConstants.TOOLS_URInamespace.getByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, String keyValue) getMaxSdkVersion(MergingReport.Builder mergingReport) Returns the maxSdkVersion version for this manifest file.getMinSdkVersion(MergingReport.Builder mergingReport) Returns the minSdk version for this manifest file.com.android.manifmerger.DocumentModel<com.android.manifmerger.ManifestModel.NodeTypes>getModel()Namespace for this android manifest which will be used to resolve partial paths.Returns aKeyResolvercapable of resolving all selectors typescom.android.ide.common.blame.SourceFileReturns theSourceFileassociated with this XML document.Returns the split name if this manifest file has one.PlaceholderHandler.KeyBasedValueResolver<com.android.manifmerger.ManifestSystemProperty>Returns thePlaceholderHandler.KeyBasedValueResolvercapable of resolving all injectedManifestSystemPropertygetTargetSdkVersion(MergingReport.Builder mergingReport) Returns the targetSdk version for this manifest file.getXml()merge(XmlDocument lowerPriorityDocument, MergingReport.Builder mergingReportBuilder, boolean addImplicitPermissions, boolean disableMinSdkVersionCheck, boolean keepGoingOnErrors, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) merge this higher priority document with a higher priority document.merge(XmlDocument lowerPriorityDocument, MergingReport.Builder mergingReportBuilder, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) merge this higher priority document with a higher priority document.Returns a pretty string representation of this document.static StringprettyPrint(Document document) Returns a pretty string representation of this document.void
-
Field Details
-
originalNodeOperation
-
-
Constructor Details
-
XmlDocument
public XmlDocument(@NonNull com.android.ide.common.blame.SourceFile sourceLocation, @NonNull KeyResolver<String> selectors, @NonNull PlaceholderHandler.KeyBasedValueResolver<com.android.manifmerger.ManifestSystemProperty> systemPropertyResolver, @NonNull Element element, @NonNull XmlDocument.Type type, @Nullable String namespace, @NonNull com.android.manifmerger.DocumentModel<com.android.manifmerger.ManifestModel.NodeTypes> model)
-
-
Method Details
-
cloneAndTransform
@NonNull public com.android.utils.Pair<Document,Boolean> cloneAndTransform(com.google.common.base.Predicate<Node> transform, com.google.common.base.Predicate<Node> shouldRemove) throws ManifestMerger2.MergeFailureException Clones and transforms an XML document.- Returns:
- a pair of document and flag on whether new document is differ from original one.
- Throws:
ManifestMerger2.MergeFailureException
-
getFileType
-
getModel
@NonNull public com.android.manifmerger.DocumentModel<com.android.manifmerger.ManifestModel.NodeTypes> getModel() -
prettyPrint
Returns a pretty string representation of this document. -
prettyPrint
Returns a pretty string representation of this document. -
merge
@NonNull public Optional<XmlDocument> merge(@NonNull XmlDocument lowerPriorityDocument, @NonNull MergingReport.Builder mergingReportBuilder, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) merge this higher priority document with a higher priority document.- Parameters:
lowerPriorityDocument- the lower priority document to merge in.mergingReportBuilder- the merging report to record errors and actions.processCancellationChecker- checks if the request to merge is cancelled.- Returns:
- a new merged
XmlDocumentorOptional.empty()if there were errors during the merging activities.
-
merge
@NonNull public Optional<XmlDocument> merge(@NonNull XmlDocument lowerPriorityDocument, @NonNull MergingReport.Builder mergingReportBuilder, boolean addImplicitPermissions, boolean disableMinSdkVersionCheck, boolean keepGoingOnErrors, ManifestMerger2.ProcessCancellationChecker processCancellationChecker) merge this higher priority document with a higher priority document.- Parameters:
lowerPriorityDocument- the lower priority document to merge in.mergingReportBuilder- the merging report to record errors and actions.addImplicitPermissions- whether to perform implicit permission addition.processCancellationChecker- checks if the request to merge is cancelled.- Returns:
- a new merged
XmlDocumentorOptional.empty()if there were errors during the merging activities.
-
getSelectors
Returns aKeyResolvercapable of resolving all selectors types -
getSystemPropertyResolver
@NonNull public PlaceholderHandler.KeyBasedValueResolver<com.android.manifmerger.ManifestSystemProperty> getSystemPropertyResolver()Returns thePlaceholderHandler.KeyBasedValueResolvercapable of resolving all injectedManifestSystemProperty -
compareTo
Compares this document to anotherXmlDocumentignoring all attributes belonging to theSdkConstants.TOOLS_URInamespace.- Parameters:
other- the other document to compare against.- Returns:
- a
Stringdescribing the differences between the two XML elements orOptional.empty()if they are equals.
-
getSourceFile
@NonNull public com.android.ide.common.blame.SourceFile getSourceFile()Returns theSourceFileassociated with this XML document.NOTE: You should not read the contents of the file directly; if you need to access the content, use
ManifestMerger2.getFileStreamProvider()instead.- Returns:
- the source file
-
resetRootNode
public void resetRootNode() -
getRootNode
-
getByTypeAndKey
public Optional<XmlElement> getByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, @Nullable String keyValue) -
getNamespace
Namespace for this android manifest which will be used to resolve partial paths.- Returns:
- the namespace to do partial class names resolution.
-
getSplitName
Returns the split name if this manifest file has one.- Returns:
- the split name or empty string.
-
getPackage
-
getXml
-
getMinSdkVersion
Returns the minSdk version for this manifest file. It can be injected from the outer build.gradle or can be expressed in the uses_sdk element (which is now ignored, generates a warning and will be an error in 8.0). -
getTargetSdkVersion
Returns the targetSdk version for this manifest file. It can be injected from the outer build.gradle or can be expressed in the uses_sdk element. -
getMaxSdkVersion
Returns the maxSdkVersion version for this manifest file. It can be injected from the outer build.gradle or can be expressed in the uses_sdk element. -
clearNodeNamespaces
public void clearNodeNamespaces()Removes the android namespace from all nodes.
-