You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by st...@apache.org on 2020/09/21 18:13:36 UTC
[hadoop] branch branch-3.3 updated: HADOOP-17088. Failed to load
XInclude files with relative path. (#2097)
This is an automated email from the ASF dual-hosted git repository.
stevel pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new c3cb86b HADOOP-17088. Failed to load XInclude files with relative path. (#2097)
c3cb86b is described below
commit c3cb86ba42ce3a11a9126a0e5402de2fe3fcde57
Author: crossfire <bs...@outlook.com>
AuthorDate: Tue Sep 22 03:10:51 2020 +0900
HADOOP-17088. Failed to load XInclude files with relative path. (#2097)
Contributed by Yushi Hayasaka.
Change-Id: I8aad5143c34fb831bef0077f7b659643f8ae073a
---
.../java/org/apache/hadoop/conf/Configuration.java | 12 +++++++-
.../org/apache/hadoop/conf/TestConfiguration.java | 32 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
index d821638..732752d 100755
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java
@@ -40,6 +40,8 @@ import java.io.Writer;
import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
import java.net.JarURLConnection;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
@@ -3243,7 +3245,15 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
File href = new File(confInclude);
if (!href.isAbsolute()) {
// Included resources are relative to the current resource
- File baseFile = new File(name).getParentFile();
+ File baseFile;
+
+ try {
+ baseFile = new File(new URI(name));
+ } catch (IllegalArgumentException | URISyntaxException e) {
+ baseFile = new File(name);
+ }
+
+ baseFile = baseFile.getParentFile();
href = new File(baseFile, href.getPath());
}
if (!href.exists()) {
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
index 81c5395..a2273ef 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java
@@ -1063,6 +1063,38 @@ public class TestConfiguration {
}
@Test
+ public void testRelativeIncludesWithLoadingViaUri() throws Exception {
+ tearDown();
+ File configFile = new File("./tmp/test-config.xml");
+ File configFile2 = new File("./tmp/test-config2.xml");
+
+ new File(configFile.getParent()).mkdirs();
+ out = new BufferedWriter(new FileWriter(configFile2));
+ startConfig();
+ appendProperty("a", "b");
+ endConfig();
+
+ out = new BufferedWriter(new FileWriter(configFile));
+ startConfig();
+ // Add the relative path instead of the absolute one.
+ startInclude(configFile2.getName());
+ endInclude();
+ appendProperty("c", "d");
+ endConfig();
+
+ // verify that the includes file contains all properties
+ Path fileResource = new Path(configFile.toURI());
+ conf.addResource(fileResource);
+ assertEquals("b", conf.get("a"));
+ assertEquals("d", conf.get("c"));
+
+ // Cleanup
+ configFile.delete();
+ configFile2.delete();
+ new File(configFile.getParent()).delete();
+ }
+
+ @Test
public void testIntegerRanges() {
Configuration conf = new Configuration();
conf.set("first", "-100");
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org