Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 41790 invoked from network); 7 Nov 2007 19:00:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Nov 2007 19:00:05 -0000 Received: (qmail 79916 invoked by uid 500); 7 Nov 2007 18:59:53 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 79878 invoked by uid 500); 7 Nov 2007 18:59:53 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 79869 invoked by uid 99); 7 Nov 2007 18:59:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2007 10:59:52 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Nov 2007 19:00:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1E1641A9832; Wed, 7 Nov 2007 10:59:41 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r592854 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java src/test/org/apache/hadoop/conf/TestConfiguration.java Date: Wed, 07 Nov 2007 18:59:40 -0000 To: hadoop-commits@lucene.apache.org From: enis@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071107185941.1E1641A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: enis Date: Wed Nov 7 10:59:39 2007 New Revision: 592854 URL: http://svn.apache.org/viewvc?rev=592854&view=rev Log: HADOOP-1348. Allow XML comments inside configuration files. Contributed by Rajagopal Natarajan and Enis Soztutar. Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=592854&r1=592853&r2=592854&view=diff ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Wed Nov 7 10:59:39 2007 @@ -76,6 +76,8 @@ wrapped over the DFSInputStream since mark/reset aren't supported by DFSInputStream anymore. (Lohit Vijayarenu via acmurthy) + HADOOP-1348. Allow XML comments inside configuration files. + (Rajagopal Natarajan and Enis Soztutar via enis) Release 0.15.1 - Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=592854&r1=592853&r2=592854&view=diff ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/conf/Configuration.java Wed Nov 7 10:59:39 2007 @@ -18,25 +18,44 @@ package org.apache.hadoop.conf; -import java.util.*; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.net.URL; -import java.io.*; - -import javax.xml.parsers.*; -import org.w3c.dom.*; -import javax.xml.transform.TransformerFactory; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.apache.commons.logging.*; - -import org.apache.hadoop.util.*; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.util.StringUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; /** * Provides access to configuration parameters. @@ -112,10 +131,12 @@ /** * @deprecated Remove in hadoop-0.16.0 via HADOOP-1843 */ + @Deprecated private ArrayList defaultResources = new ArrayList(); /** * @deprecated Remove in hadoop-0.16.0 via HADOOP-1843 */ + @Deprecated private ArrayList finalResources = new ArrayList(); /** @@ -172,6 +193,7 @@ * Add a default resource. * @deprecated Use {@link #addResource(String)} instead */ + @Deprecated public void addDefaultResource(String name) { addResource(defaultResources, name); } @@ -180,6 +202,7 @@ * Add a default resource. * @deprecated Use {@link #addResource(URL)} instead */ + @Deprecated public void addDefaultResource(URL url) { addResource(defaultResources, url); } @@ -188,6 +211,7 @@ * Add a default resource. * @deprecated Use {@link #addResource(Path)} instead */ + @Deprecated public void addDefaultResource(Path file) { addResource(defaultResources, file); } @@ -196,6 +220,7 @@ * Add a final resource. * @deprecated Use {@link #addResource(String)} instead */ + @Deprecated public void addFinalResource(String name) { addResource(finalResources, name); } @@ -204,6 +229,7 @@ * Add a final resource. * @deprecated Use {@link #addResource(URL)} instead */ + @Deprecated public void addFinalResource(URL url) { addResource(finalResources, url); } @@ -212,6 +238,7 @@ * Add a final resource. * @deprecated Use {@link #addResource(Path)} instead */ + @Deprecated public void addFinalResource(Path file) { addResource(finalResources, file); } @@ -270,11 +297,13 @@ * property exists. * @deprecated A side map of Configuration to Object should be used instead. */ + @Deprecated public Object getObject(String name) { return getProps().get(name);} /** Sets the value of the name property. * @deprecated */ + @Deprecated public void setObject(String name, Object value) { getProps().put(name, value); } @@ -283,6 +312,7 @@ * exists, then defaultValue is returned. * @deprecated A side map of Configuration to Object should be used instead. */ + @Deprecated public Object get(String name, Object defaultValue) { Object res = getObject(name); if (res != null) return res; @@ -349,6 +379,7 @@ /** Sets the value of the name property. * @deprecated */ + @Deprecated public void set(String name, Object value) { getOverlay().setProperty(name, value.toString()); getProps().setProperty(name, value.toString()); @@ -724,6 +755,7 @@ /** @return Iterator< Map.Entry<String,String> > * @deprecated Use {@link #iterator()} instead. */ + @Deprecated public Iterator entries() { return iterator(); } @@ -759,8 +791,11 @@ private void loadResource(Properties properties, Object name, boolean quiet) { try { - DocumentBuilder builder = - DocumentBuilderFactory.newInstance().newDocumentBuilder(); + DocumentBuilderFactory docBuilderFactory + = DocumentBuilderFactory.newInstance(); + //ignore all comments inside the xml file + docBuilderFactory.setIgnoringComments(true); + DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = null; @@ -917,6 +952,7 @@ this.classLoader = classLoader; } + @Override public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Configuration: "); Modified: lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java?rev=592854&r1=592853&r2=592854&view=diff ============================================================================== --- lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java (original) +++ lucene/hadoop/trunk/src/test/org/apache/hadoop/conf/TestConfiguration.java Wed Nov 7 10:59:39 2007 @@ -34,11 +34,13 @@ final static String CONFIG = new File("./test-config.xml").getAbsolutePath(); final static String CONFIG2 = new File("./test-config2.xml").getAbsolutePath(); + @Override protected void setUp() throws Exception { super.setUp(); conf = new Configuration(); } + @Override protected void tearDown() throws Exception { super.tearDown(); new File(CONFIG).delete(); @@ -171,6 +173,17 @@ assertEquals(clone.get("d"), "e"); assertEquals(clone.get("e"), "f"); + } + + public void testCommentsInValue() throws IOException { + out=new BufferedWriter(new FileWriter(CONFIG)); + startConfig(); + appendProperty("my.comment", "this contains a comment"); + endConfig(); + Path fileResource = new Path(CONFIG); + conf.addResource(fileResource); + //two spaces one after "this", one before "contains" + assertEquals("this contains a comment", conf.get("my.comment")); } BufferedWriter out;