Created
July 7, 2014 17:58
-
-
Save gissuebot/790d6e95ffba175a6649 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 94, comment 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -urN /Users/stuart/Desktop/guice/src/com/google/inject/ConstructionContext.java src/com/google/inject/ConstructionContext.java | |
--- /Users/stuart/Desktop/guice/src/com/google/inject/ConstructionContext.java 2007-03-01 19:35:52.000000000 +0800 | |
+++ src/com/google/inject/ConstructionContext.java 2007-04-20 12:33:19.000000000 +0800 | |
@@ -23,6 +23,8 @@ | |
import java.util.ArrayList; | |
import java.util.List; | |
+import com.google.inject.util.GuiceClassLoader; | |
+ | |
/** | |
* Context of a dependency construction. Used to manage circular references. | |
* | |
@@ -80,7 +82,7 @@ | |
= new DelegatingInvocationHandler<T>(); | |
invocationHandlers.add(invocationHandler); | |
- Object object = Proxy.newProxyInstance(expectedType.getClassLoader(), | |
+ Object object = Proxy.newProxyInstance(new GuiceClassLoader(expectedType), | |
new Class[] { expectedType }, invocationHandler); | |
return expectedType.cast(object); | |
} | |
diff -urN /Users/stuart/Desktop/guice/src/com/google/inject/ProxyFactory.java src/com/google/inject/ProxyFactory.java | |
--- /Users/stuart/Desktop/guice/src/com/google/inject/ProxyFactory.java 2007-03-02 13:01:44.000000000 +0800 | |
+++ src/com/google/inject/ProxyFactory.java 2007-04-20 12:17:02.000000000 +0800 | |
@@ -16,6 +16,7 @@ | |
package com.google.inject; | |
+import com.google.inject.util.GuiceEnhancer; | |
import com.google.inject.util.GuiceFastClass; | |
import com.google.inject.util.GuiceNamingPolicy; | |
import com.google.inject.util.Objects; | |
@@ -140,7 +141,7 @@ | |
} | |
// Create the proxied class. | |
- Enhancer enhancer = new Enhancer(); | |
+ Enhancer enhancer = new GuiceEnhancer(); | |
enhancer.setSuperclass(declaringClass); | |
enhancer.setUseCache(false); // We do enough caching. | |
enhancer.setCallbackFilter(new CallbackFilter() { | |
diff -urN /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceClassLoader.java src/com/google/inject/util/GuiceClassLoader.java | |
--- /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceClassLoader.java 1970-01-01 07:30:00.000000000 +0730 | |
+++ src/com/google/inject/util/GuiceClassLoader.java 2007-04-20 16:30:03.000000000 +0800 | |
@@ -0,0 +1,39 @@ | |
+/** | |
+ * Copyright (C) 2007 Stuart McCulloch | |
+ * | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+ | |
+package com.google.inject.util; | |
+ | |
+/** | |
+ * Provide bridge between Guice and Application classloaders | |
+ * | |
+ * @author stuart.mcculloch@jayway.net (Stuart McCulloch) | |
+ */ | |
+public class GuiceClassLoader extends ClassLoader { | |
+ private ClassLoader loader; | |
+ | |
+ public GuiceClassLoader(Class type) { | |
+ super(GuiceClassLoader.class.getClassLoader()); | |
+ loader = type.getClassLoader(); | |
+ } | |
+ | |
+ protected Class findClass(String name) throws ClassNotFoundException { | |
+ if (null == loader || name.startsWith("com.google.inject.")) { | |
+ return super.findClass(name); | |
+ } else { | |
+ return loader.loadClass(name); | |
+ } | |
+ } | |
+} | |
diff -urN /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceEnhancer.java src/com/google/inject/util/GuiceEnhancer.java | |
--- /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceEnhancer.java 1970-01-01 07:30:00.000000000 +0730 | |
+++ src/com/google/inject/util/GuiceEnhancer.java 2007-04-20 14:38:55.000000000 +0800 | |
@@ -0,0 +1,41 @@ | |
+/** | |
+ * Copyright (C) 2007 Stuart McCulloch | |
+ * | |
+ * Licensed under the Apache License, Version 2.0 (the "License"); | |
+ * you may not use this file except in compliance with the License. | |
+ * You may obtain a copy of the License at | |
+ * | |
+ * http://www.apache.org/licenses/LICENSE-2.0 | |
+ * | |
+ * Unless required by applicable law or agreed to in writing, software | |
+ * distributed under the License is distributed on an "AS IS" BASIS, | |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
+ * See the License for the specific language governing permissions and | |
+ * limitations under the License. | |
+ */ | |
+ | |
+package com.google.inject.util; | |
+ | |
+import net.sf.cglib.proxy.Enhancer; | |
+ | |
+/** | |
+ * Provide custom classloading for Guice | |
+ * | |
+ * @author stuart.mcculloch@jayway.net (Stuart McCulloch) | |
+ */ | |
+public class GuiceEnhancer extends Enhancer { | |
+ private ClassLoader loader; | |
+ | |
+ public void setSuperclass(Class superclass) { | |
+ loader = new GuiceClassLoader(superclass); | |
+ super.setSuperclass(superclass); | |
+ } | |
+ | |
+ protected ClassLoader getDefaultClassLoader() { | |
+ if (loader != null) { | |
+ return loader; | |
+ } else { | |
+ return super.getDefaultClassLoader(); | |
+ } | |
+ } | |
+} | |
diff -urN /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceFastClass.java src/com/google/inject/util/GuiceFastClass.java | |
--- /Users/stuart/Desktop/guice/src/com/google/inject/util/GuiceFastClass.java 2007-02-25 18:54:12.000000000 +0800 | |
+++ src/com/google/inject/util/GuiceFastClass.java 2007-04-20 12:01:22.000000000 +0800 | |
@@ -18,6 +18,7 @@ | |
import net.sf.cglib.reflect.FastClass; | |
import com.google.inject.util.GuiceNamingPolicy; | |
+import com.google.inject.util.GuiceClassLoader; | |
/** | |
* Gives Guice classes custom names. | |
@@ -27,7 +28,7 @@ | |
public class GuiceFastClass { | |
public static FastClass create(Class type) { | |
- return create(type.getClassLoader(), type); | |
+ return create(new GuiceClassLoader(type), type); | |
} | |
public static FastClass create(ClassLoader loader, Class type) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment