ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-10965 - Views: @Inject using com.google.inject.Inject is broken. (tbeerbower)
Date Wed, 06 May 2015 20:05:46 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.maint 990af9d26 -> 3608de943


AMBARI-10965 - Views: @Inject using com.google.inject.Inject is broken. (tbeerbower)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3608de94
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3608de94
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3608de94

Branch: refs/heads/branch-2.0.maint
Commit: 3608de9431a2f5aee615369d0831d5c1a2018c3c
Parents: 990af9d
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Wed May 6 16:03:38 2015 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Wed May 6 16:05:28 2015 -0400

----------------------------------------------------------------------
 .../ambari/server/view/ViewClassLoader.java     | 20 ++++++++++++++++----
 .../ambari/server/view/ViewClassLoaderTest.java |  8 ++++++++
 2 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3608de94/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
index ad8c805..5b0c317 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewClassLoader.java
@@ -53,13 +53,25 @@ public class ViewClassLoader extends WebAppClassLoader {
    * @param urls    the URLs from which to load classes and resources
    */
   public ViewClassLoader(ClassLoader parent, URL[] urls) throws IOException {
-    // Use no-arg web app context to initialize the class loader.  For now we are just using
the default context
-    // values for things like parent loader priority and server classes.  In the future we
may allow overrides at
-    // the view level.
-    super(parent, new WebAppContext());
+    super(parent, getInitContext());
 
     for (URL url : urls) {
       addURL(url);
     }
   }
+
+
+  // ----- helper methods ----------------------------------------------------
+
+  // Get a context to initialize the class loader.
+  private static WebAppContext getInitContext() {
+    // For now we are using defaults or setting the values for things like parent loader
priority and
+    // system classes.  In the future we may allow overrides at the view level.
+    WebAppContext webAppContext = new WebAppContext();
+
+    // add com.google.inject as system classes to allow for injection in view components
using the google annotation
+    webAppContext.addSystemClass("com.google.inject.");
+
+    return webAppContext;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3608de94/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
index 3a9ecd3..b6a1396 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewClassLoaderTest.java
@@ -71,6 +71,7 @@ public class ViewClassLoaderTest {
     expect(parentClassLoader.loadClass("java.lang.Object")).andReturn(parentClass).anyTimes();
     expect(parentClassLoader.loadClass("ParentClass")).andReturn(parentClass).once();
     expect(parentClassLoader.loadClass("javax.xml.parsers.SAXParserFactory")).andReturn(parentClass).once();
+    expect(parentClassLoader.loadClass("com.google.inject.AbstractModule")).andReturn(parentClass).once();
 
     replay(parentClassLoader);
 
@@ -90,11 +91,18 @@ public class ViewClassLoaderTest {
     Assert.assertNotNull(clazz);
     Assert.assertSame(parentClass, clazz);
 
+    // should be loaded by parent loader
     clazz = classLoader.loadClass("javax.xml.parsers.SAXParserFactory");
 
     Assert.assertNotNull(clazz);
     Assert.assertSame(parentClass, clazz);
 
+    // should be loaded by parent loader
+    clazz = classLoader.loadClass("com.google.inject.AbstractModule");
+
+    Assert.assertNotNull(clazz);
+    Assert.assertSame(parentClass, clazz);
+
     verify(parentClassLoader);
   }
 


Mime
View raw message