HADOOP-8749. HADOOP-8031 changed the way in which relative xincludes are handled in Configuration. (ahmed via tucu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1381703 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alejandro Abdelnur 2012-09-06 18:15:37 +00:00
parent 0654590853
commit 11312adedb
3 changed files with 41 additions and 6 deletions

View File

@ -473,6 +473,9 @@ Branch-2 ( Unreleased changes )
HADOOP-8766. FileContextMainOperationsBaseTest should randomize the root
dir. (Colin Patrick McCabe via atm)
HADOOP-8749. HADOOP-8031 changed the way in which relative xincludes are handled in
Configuration. (ahmed via tucu)
BREAKDOWN OF HDFS-3042 SUBTASKS
HADOOP-8220. ZKFailoverController doesn't handle failure to become active

View File

@ -1871,11 +1871,11 @@ private Document parse(DocumentBuilder builder, URL url)
if (url == null) {
return null;
}
return parse(builder, url.openStream());
return parse(builder, url.openStream(), url.toString());
}
private Document parse(DocumentBuilder builder, InputStream is)
throws IOException, SAXException {
private Document parse(DocumentBuilder builder, InputStream is,
String systemId) throws IOException, SAXException {
if (!quietmode) {
LOG.info("parsing input stream " + is);
}
@ -1883,7 +1883,8 @@ private Document parse(DocumentBuilder builder, InputStream is)
return null;
}
try {
return builder.parse(is);
return (systemId == null) ? builder.parse(is) : builder.parse(is,
systemId);
} finally {
is.close();
}
@ -1951,10 +1952,11 @@ private Resource loadResource(Properties properties, Resource wrapper, boolean q
if (!quiet) {
LOG.info("parsing File " + file);
}
doc = parse(builder, new BufferedInputStream(new FileInputStream(file)));
doc = parse(builder, new BufferedInputStream(
new FileInputStream(file)), ((Path)resource).toString());
}
} else if (resource instanceof InputStream) {
doc = parse(builder, (InputStream) resource);
doc = parse(builder, (InputStream) resource, null);
returnCachedProperties = true;
} else if (resource instanceof Properties) {
overlay(properties, (Properties)resource);

View File

@ -358,6 +358,36 @@ public void testIncludes() throws Exception {
tearDown();
}
public void testRelativeIncludes() throws Exception {
tearDown();
String relConfig = new File("./tmp/test-config.xml").getAbsolutePath();
String relConfig2 = new File("./tmp/test-config2.xml").getAbsolutePath();
new File(new File(relConfig).getParent()).mkdirs();
out = new BufferedWriter(new FileWriter(relConfig2));
startConfig();
appendProperty("a", "b");
endConfig();
out = new BufferedWriter(new FileWriter(relConfig));
startConfig();
// Add the relative path instead of the absolute one.
addInclude(new File(relConfig2).getName());
appendProperty("c", "d");
endConfig();
// verify that the includes file contains all properties
Path fileResource = new Path(relConfig);
conf.addResource(fileResource);
assertEquals(conf.get("a"), "b");
assertEquals(conf.get("c"), "d");
// Cleanup
new File(relConfig).delete();
new File(relConfig2).delete();
new File(new File(relConfig).getParent()).delete();
}
BufferedWriter out;
public void testIntegerRanges() {