@Nullable public static String mergeXml(@NotNull RenderingContext context,String sourceXml,String targetXml,File targetFile){
  boolean ok;
  String fileName=targetFile.getName();
  String contents;
  if (fileName.equals(SdkConstants.FN_ANDROID_MANIFEST_XML)) {
    Document currentDocument=XmlUtils.parseDocumentSilently(targetXml,true);
    assert currentDocument != null : targetXml + " failed to parse";
    Document fragment=XmlUtils.parseDocumentSilently(sourceXml,true);
    assert fragment != null : sourceXml + " failed to parse";
    contents=mergeManifest(targetFile,targetXml,sourceXml);
    ok=contents != null;
  }
 else {
    String parentFolderName=targetFile.getParentFile().getName();
    ResourceFolderType folderType=ResourceFolderType.getFolderType(parentFolderName);
    contents=mergeResourceFile(context,targetXml,sourceXml,fileName,folderType);
    ok=contents != null;
  }
  if (!ok) {
    contents=wrapWithMergeConflict(targetXml,sourceXml);
    context.getWarnings().add(String.format("Merge conflict for: %1$s this file must be fixed by hand",targetFile.getName()));
  }
  return contents;
}

@ Nullable public static String mergeXml ( @ NotNull RenderingContext context , String sourceXml , String targetXml , File targetFile ) { boolean ok ; String fileName = targetFile . getName ( ) ; String contents ; if ( fileName . equals ( SdkConstants . FN_ANDROID_MANIFEST_XML ) ) { Document currentDocument = XmlUtils . parseDocumentSilently ( targetXml , true ) ; assert currentDocument != null : targetXml + " failed to parse" ; Document fragment = XmlUtils . parseDocumentSilently ( sourceXml , true ) ; assert fragment != null : sourceXml + " failed to parse" ; contents = mergeManifest ( targetFile , targetXml , sourceXml ) ; ok = contents != null ; } else { String parentFolderName = targetFile . getParentFile ( ) . getName ( ) ; ResourceFolderType folderType = ResourceFolderType . getFolderType ( parentFolderName ) ; contents = mergeResourceFile ( context , targetXml , sourceXml , fileName , folderType ) ; ok = contents != null ; } if ( ! ok ) { contents = wrapWithMergeConflict ( targetXml , sourceXml ) ; context . getWarnings ( ) . add ( String . format ( "Merge conflict for: %1$s this file must be fixed by hand" , targetFile . getName ( ) ) ) ; } return contents ; }
merges sourcexml into targetxml / targetfile ( targetxml is the contents of targetfile ) . returns the resulting xml if it still needs to be written to targetfile , or null if the file has already been / doesn ' t need to be updated .
