From ce797a170669524224cfeaaf70647047e7626816 Mon Sep 17 00:00:00 2001 From: Lei Xu Date: Mon, 14 Aug 2017 10:27:47 -0700 Subject: [PATCH] HDFS-12221. Replace xcerces in XmlEditsVisitor. (Ajay Kumar via lei) --- .../hadoop-client-minicluster/pom.xml | 6 -- .../hadoop-client-runtime/pom.xml | 7 -- hadoop-hdfs-project/hadoop-hdfs/pom.xml | 5 -- .../offlineEditsViewer/XmlEditsVisitor.java | 41 ++++++++---- .../src/test/resources/editsStored | Bin 5850 -> 5850 bytes .../src/test/resources/editsStored.xml | 62 +++++++++--------- .../hadoop-mapreduce-client/pom.xml | 10 +-- hadoop-project-dist/pom.xml | 10 +-- hadoop-project/pom.xml | 8 --- hadoop-yarn-project/hadoop-yarn/pom.xml | 10 +-- 10 files changed, 62 insertions(+), 97 deletions(-) diff --git a/hadoop-client-modules/hadoop-client-minicluster/pom.xml b/hadoop-client-modules/hadoop-client-minicluster/pom.xml index 5255640dfcd..5cf1fad8c8b 100644 --- a/hadoop-client-modules/hadoop-client-minicluster/pom.xml +++ b/hadoop-client-modules/hadoop-client-minicluster/pom.xml @@ -628,12 +628,6 @@ **/*.class - - xerces:xercesImpl - - **/* - - org.apache.hadoop:hadoop-mapreduce-client-jobclient:* diff --git a/hadoop-client-modules/hadoop-client-runtime/pom.xml b/hadoop-client-modules/hadoop-client-runtime/pom.xml index 2f64152b8b8..24c6b7a8365 100644 --- a/hadoop-client-modules/hadoop-client-runtime/pom.xml +++ b/hadoop-client-modules/hadoop-client-runtime/pom.xml @@ -174,13 +174,6 @@ org/apache/jasper/compiler/Localizer.class - - - xerces:xercesImpl - - META-INF/services/* - - com.sun.jersey:* diff --git a/hadoop-hdfs-project/hadoop-hdfs/pom.xml b/hadoop-hdfs-project/hadoop-hdfs/pom.xml index 1c50d3116e7..fa1044d435d 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/pom.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/pom.xml @@ -173,11 +173,6 @@ http://maven.apache.org/xsd/maven-4.0.0.xsd"> netty-all compile - - xerces - xercesImpl - compile - org.apache.htrace htrace-core4 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java index 7a39ba6072b..ddf7933f032 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java @@ -20,17 +20,21 @@ package org.apache.hadoop.hdfs.tools.offlineEditsViewer; import java.io.IOException; import java.io.OutputStream; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.sax.SAXTransformerFactory; +import javax.xml.transform.sax.TransformerHandler; +import javax.xml.transform.stream.StreamResult; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; + import org.apache.hadoop.hdfs.util.XMLUtils; import org.apache.hadoop.hdfs.server.namenode.FSEditLogOp; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; /** * An XmlEditsVisitor walks over an EditLog structure and writes out @@ -41,26 +45,37 @@ import org.apache.xml.serialize.XMLSerializer; public class XmlEditsVisitor implements OfflineEditsVisitor { private final OutputStream out; private ContentHandler contentHandler; + private final SAXTransformerFactory factory; + private final static String XML_INDENTATION_PROP ="{http://xml.apache.org/" + + "xslt}indent-amount"; + private final static String XML_INDENTATION_NUM ="2"; /** * Create a processor that writes to the file named and may or may not * also output to the screen, as specified. * - * @param filename Name of file to write output to - * @param printToScreen Mirror output to screen? + * @param out output stream to write + * @throws IOException on any error */ public XmlEditsVisitor(OutputStream out) throws IOException { this.out = out; - OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true); - outFormat.setIndenting(true); - outFormat.setIndent(2); - outFormat.setDoctype(null, null); - XMLSerializer serializer = new XMLSerializer(out, outFormat); - contentHandler = serializer.asContentHandler(); + factory =(SAXTransformerFactory)SAXTransformerFactory.newInstance(); try { + TransformerHandler handler = factory.newTransformerHandler(); + handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml"); + handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes"); + handler.getTransformer().setOutputProperty(XML_INDENTATION_PROP, + XML_INDENTATION_NUM); + handler.getTransformer().setOutputProperty(OutputKeys.STANDALONE, "yes"); + handler.setResult(new StreamResult(out)); + contentHandler = handler; + contentHandler.startDocument(); contentHandler.startElement("", "", "EDITS", new AttributesImpl()); + } catch (TransformerConfigurationException e) { + throw new IOException("SAXTransformer error: " + e.getMessage()); } catch (SAXException e) { throw new IOException("SAX error: " + e.getMessage()); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored index a32cd98c49f86aeeb04fd679db463a00f2c15408..e271cb574bdc16e9069e68904ee1fa77f2a86f74 100644 GIT binary patch delta 13 VcmcbmdrOz)|Ns97HnLn30{}I=2XO!Z delta 13 VcmcbmdrOz)|Ns97H?mw40{}I_2XX)a diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored.xml b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored.xml index 201db9eb7da..f9011450555 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored.xml +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/resources/editsStored.xml @@ -1,6 +1,6 @@ - + - -63 + -64 OP_START_LOG_SEGMENT @@ -63,8 +63,8 @@ 1422406380369 1422406380345 512 - - + + false xyao @@ -96,8 +96,8 @@ 1422406380376 1422406380345 512 - - + + false xyao @@ -238,8 +238,8 @@ 1422406380425 1422406380423 512 - - + + false xyao @@ -360,7 +360,7 @@ 0 1001 - + -2 @@ -393,7 +393,7 @@ 0 1002 - + -2 @@ -426,7 +426,7 @@ 0 1003 - + -2 @@ -441,8 +441,8 @@ 1422406380534 1422406380446 512 - - + + false 1073741825 @@ -513,7 +513,7 @@ 0 1004 - + -2 @@ -546,7 +546,7 @@ 0 1005 - + -2 @@ -579,7 +579,7 @@ 0 1006 - + -2 @@ -594,8 +594,8 @@ 1422406380558 1422406380537 512 - - + + false 1073741828 @@ -666,7 +666,7 @@ 0 1007 - + -2 @@ -699,7 +699,7 @@ 0 1008 - + -2 @@ -732,7 +732,7 @@ 0 1009 - + -2 @@ -747,8 +747,8 @@ 1422406380579 1422406380560 512 - - + + false 1073741831 @@ -834,7 +834,7 @@ 0 1010 - + -2 @@ -867,7 +867,7 @@ 0 1011 - + -2 @@ -882,8 +882,8 @@ 1422406380599 1422406380586 512 - - + + false 1073741834 @@ -979,7 +979,7 @@ 0 1012 - + -2 @@ -993,7 +993,7 @@ 11 1012 - + -2 @@ -1024,8 +1024,8 @@ 1422406383261 1422406380608 512 - - + + false 1073741836 diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml b/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml index 4e7a0aed2d7..212078bbd14 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/pom.xml @@ -238,14 +238,6 @@ ${project.build.directory} hadoop-annotations.jar - - xerces - xercesImpl - ${xerces.version.jdiff} - false - ${project.build.directory} - xerces.jar - @@ -283,7 +275,7 @@ sourceFiles="${dev-support.relative.dir}/jdiff/Null.java" maxmemory="${jdiff.javadoc.maxmemory}"> + path="${project.build.directory}/hadoop-annotations.jar:${project.build.directory}/jdiff.jar"> diff --git a/hadoop-project-dist/pom.xml b/hadoop-project-dist/pom.xml index 9da5e534247..cf432186022 100644 --- a/hadoop-project-dist/pom.xml +++ b/hadoop-project-dist/pom.xml @@ -194,14 +194,6 @@ ${project.build.directory} hadoop-annotations.jar - - xerces - xercesImpl - ${xerces.jdiff.version} - false - ${project.build.directory} - xerces.jar - @@ -267,7 +259,7 @@ sourceFiles="${basedir}/dev-support/jdiff/Null.java" maxmemory="${jdiff.javadoc.maxmemory}"> + path="${project.build.directory}/hadoop-annotations.jar:${project.build.directory}/jdiff.jar"> diff --git a/hadoop-project/pom.xml b/hadoop-project/pom.xml index 81510165166..6311cd9b0d0 100755 --- a/hadoop-project/pom.xml +++ b/hadoop-project/pom.xml @@ -45,8 +45,6 @@ 1.0.9 - - 2.11.0 0.8.2.1 1.2.6 @@ -1155,12 +1153,6 @@ - - xerces - xercesImpl - 2.9.1 - - org.apache.curator curator-recipes diff --git a/hadoop-yarn-project/hadoop-yarn/pom.xml b/hadoop-yarn-project/hadoop-yarn/pom.xml index 2e8ec69cdc9..12e46049a77 100644 --- a/hadoop-yarn-project/hadoop-yarn/pom.xml +++ b/hadoop-yarn-project/hadoop-yarn/pom.xml @@ -155,14 +155,6 @@ ${project.build.directory} hadoop-annotations.jar - - xerces - xercesImpl - ${xerces.version.jdiff} - false - ${project.build.directory} - xerces.jar - @@ -201,7 +193,7 @@ sourceFiles="${dev-support.relative.dir}/jdiff/Null.java" maxmemory="${jdiff.javadoc.maxmemory}"> + path="${project.build.directory}/hadoop-annotations.jar:${project.build.directory}/jdiff.jar">