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 wa...@apache.org on 2018/03/29 16:58:10 UTC
[20/33] hadoop git commit: HADOOP-14067. VersionInfo should load
version-info.properties from its own classloader. Contributed by Thejas M
Nair.
HADOOP-14067. VersionInfo should load version-info.properties from its own classloader. Contributed by Thejas M Nair.
(cherry picked from commit 91b98ad03a430e0b84d78ad7170d56f016a90d2f)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/7155ef28
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/7155ef28
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/7155ef28
Branch: refs/heads/branch-3.1.0
Commit: 7155ef28f98fd7920405f1646b811489610e7756
Parents: 7580c52
Author: Jitendra Pandey <ji...@apache.org>
Authored: Thu Mar 22 14:08:18 2018 -0700
Committer: Wangda Tan <wa...@apache.org>
Committed: Thu Mar 29 09:45:29 2018 -0700
----------------------------------------------------------------------
.../java/org/apache/hadoop/util/ThreadUtil.java | 26 ++++++++++++++++++--
.../org/apache/hadoop/util/VersionInfo.java | 3 ++-
2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/7155ef28/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ThreadUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ThreadUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ThreadUtil.java
index 6444428..2cda8a4 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ThreadUtil.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/ThreadUtil.java
@@ -53,8 +53,7 @@ public class ThreadUtil {
* Convenience method that returns a resource as inputstream from the
* classpath.
* <p>
- * It first attempts to use the Thread's context classloader and if not
- * set it uses the class' classloader.
+ * Uses the Thread's context classloader to load resource.
*
* @param resourceName resource to retrieve.
*
@@ -68,6 +67,27 @@ public class ThreadUtil {
throw new IOException("Can not read resource file '" + resourceName +
"' because class loader of the current thread is null");
}
+ return getResourceAsStream(cl, resourceName);
+ }
+
+ /**
+ * Convenience method that returns a resource as inputstream from the
+ * classpath using given classloader.
+ * <p>
+ *
+ * @param cl ClassLoader to be used to retrieve resource.
+ * @param resourceName resource to retrieve.
+ *
+ * @throws IOException thrown if resource cannot be loaded
+ * @return inputstream with the resource.
+ */
+ public static InputStream getResourceAsStream(ClassLoader cl,
+ String resourceName)
+ throws IOException {
+ if (cl == null) {
+ throw new IOException("Can not read resource file '" + resourceName +
+ "' because given class loader is null");
+ }
InputStream is = cl.getResourceAsStream(resourceName);
if (is == null) {
throw new IOException("Can not read resource file '" +
@@ -75,4 +95,6 @@ public class ThreadUtil {
}
return is;
}
+
+
}
http://git-wip-us.apache.org/repos/asf/hadoop/blob/7155ef28/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java
index ca09050..ea83502 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/VersionInfo.java
@@ -43,7 +43,8 @@ public class VersionInfo {
String versionInfoFile = component + "-version-info.properties";
InputStream is = null;
try {
- is = ThreadUtil.getResourceAsStream(versionInfoFile);
+ is = ThreadUtil.getResourceAsStream(VersionInfo.class.getClassLoader(),
+ versionInfoFile);
info.load(is);
} catch (IOException ex) {
LoggerFactory.getLogger(getClass()).warn("Could not read '" +
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org