Class XmlDocument

java.lang.Object
com.android.manifmerger.XmlDocument

public class XmlDocument extends Object
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.

  • Field Details

  • 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

      @NonNull public XmlDocument.Type getFileType()
    • getModel

      @NonNull public com.android.manifmerger.DocumentModel<com.android.manifmerger.ManifestModel.NodeTypes> getModel()
    • prettyPrint

      @NonNull public String prettyPrint()
      Returns a pretty string representation of this document.
    • prettyPrint

      @NonNull public static String prettyPrint(Document document)
      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 XmlDocument or Optional.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 XmlDocument or Optional.empty() if there were errors during the merging activities.
    • getSelectors

      @NonNull public KeyResolver<String> getSelectors()
      Returns a KeyResolver capable of resolving all selectors types
    • getSystemPropertyResolver

      @NonNull public PlaceholderHandler.KeyBasedValueResolver<com.android.manifmerger.ManifestSystemProperty> getSystemPropertyResolver()
      Returns the PlaceholderHandler.KeyBasedValueResolver capable of resolving all injected ManifestSystemProperty
    • compareTo

      public Optional<String> compareTo(@NonNull XmlDocument other)
      Compares this document to another XmlDocument ignoring all attributes belonging to the SdkConstants.TOOLS_URI namespace.
      Parameters:
      other - the other document to compare against.
      Returns:
      a String describing the differences between the two XML elements or Optional.empty() if they are equals.
    • getSourceFile

      @NonNull public com.android.ide.common.blame.SourceFile getSourceFile()
      Returns the SourceFile associated 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

      public XmlElement getRootNode()
    • getByTypeAndKey

      public Optional<XmlElement> getByTypeAndKey(com.android.manifmerger.ManifestModel.NodeTypes type, @Nullable String keyValue)
    • getNamespace

      @Nullable public String getNamespace()
      Namespace for this android manifest which will be used to resolve partial paths.
      Returns:
      the namespace to do partial class names resolution.
    • getSplitName

      public String getSplitName()
      Returns the split name if this manifest file has one.
      Returns:
      the split name or empty string.
    • getPackage

      public Optional<XmlAttribute> getPackage()
    • getXml

      public Document getXml()
    • getMinSdkVersion

      @NonNull public String getMinSdkVersion(@NonNull MergingReport.Builder mergingReport)
      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

      @NonNull public String getTargetSdkVersion(@NonNull MergingReport.Builder mergingReport)
      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

      @Nullable public String getMaxSdkVersion(@NonNull MergingReport.Builder mergingReport)
      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.