Created
July 7, 2014 17:58
-
-
Save gissuebot/7edb189a9c0cea24d1d8 to your computer and use it in GitHub Desktop.
Migrated attachment for Guice issue 94, comment 3
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
Index: src/com/google/inject/internal/GuiceEnhancer.java | |
=================================================================== | |
--- src/com/google/inject/internal/GuiceEnhancer.java (revision 0) | |
+++ src/com/google/inject/internal/GuiceEnhancer.java (revision 0) | |
@@ -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.internal; | |
+ | |
+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(); | |
+ } | |
+ } | |
+} | |
Property changes on: src/com/google/inject/internal/GuiceEnhancer.java | |
___________________________________________________________________ | |
Name: svn:eol-style | |
+ native | |
Index: src/com/google/inject/internal/GuiceFastClass.java | |
=================================================================== | |
--- src/com/google/inject/internal/GuiceFastClass.java (revision 332) | |
+++ src/com/google/inject/internal/GuiceFastClass.java (working copy) | |
@@ -26,7 +26,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) { | |
Index: src/com/google/inject/internal/GuiceClassLoader.java | |
=================================================================== | |
--- src/com/google/inject/internal/GuiceClassLoader.java (revision 0) | |
+++ src/com/google/inject/internal/GuiceClassLoader.java (revision 0) | |
@@ -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.internal; | |
+ | |
+/** | |
+ * 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); | |
+ } | |
+ } | |
+} | |
Property changes on: src/com/google/inject/internal/GuiceClassLoader.java | |
___________________________________________________________________ | |
Name: svn:eol-style | |
+ native | |
Index: src/com/google/inject/ProxyFactory.java | |
=================================================================== | |
--- src/com/google/inject/ProxyFactory.java (revision 332) | |
+++ src/com/google/inject/ProxyFactory.java (working copy) | |
@@ -16,6 +16,7 @@ | |
package com.google.inject; | |
+import com.google.inject.internal.GuiceEnhancer; | |
import com.google.inject.internal.GuiceFastClass; | |
import com.google.inject.internal.GuiceNamingPolicy; | |
import com.google.inject.internal.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() { | |
Index: src/com/google/inject/ConstructionContext.java | |
=================================================================== | |
--- src/com/google/inject/ConstructionContext.java (revision 332) | |
+++ src/com/google/inject/ConstructionContext.java (working copy) | |
@@ -23,6 +23,8 @@ | |
import java.util.ArrayList; | |
import java.util.List; | |
+import com.google.inject.internal.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); | |
} | |
Index: guice.bnd | |
=================================================================== | |
--- guice.bnd (revision 0) | |
+++ guice.bnd (revision 0) | |
@@ -0,0 +1,13 @@ | |
+Import-Package:\ | |
+ javax.naming;resolution:=optional,\ | |
+ javax.management;resolution:=optional,\ | |
+ junit.framework;resolution:=optional,\ | |
+ !com.google.inject.asm.*,\ | |
+ !com.google.inject.cglib.*,\ | |
+ !com.google.inject.internal.*,\ | |
+ * | |
+Export-Package:\ | |
+ !com.google.inject.asm.*,\ | |
+ !com.google.inject.cglib.*,\ | |
+ !com.google.inject.internal.*,\ | |
+ com.google.inject.* | |
Index: build.xml | |
=================================================================== | |
--- build.xml (revision 332) | |
+++ build.xml (working copy) | |
@@ -24,7 +24,24 @@ | |
</jarjar> | |
</target> | |
- <target name="dist" depends="jar, javadoc" | |
+ <target name="bnd" depends="jar"> | |
+ <mkdir dir="${build.dir}/osgi"/> | |
+ <java classname="aQute.bnd.main.bnd"> | |
+ <arg value="wrap"/> | |
+ <arg value="-output"/> | |
+ <arg value="${build.dir}/osgi/guice-${version}.jar"/> | |
+ <arg value="-properties"/> | |
+ <arg value="guice.bnd"/> | |
+ <arg value="${build.dir}/dist/guice-${version}.jar"/> | |
+ <classpath> | |
+ <pathelement location="lib/build/bnd-0.0.134.jar"/> | |
+ <pathelement path="${java.class.path}"/> | |
+ </classpath> | |
+ </java> | |
+ <move toDir="${build.dir}/dist" file="${build.dir}/osgi/guice-${version}.jar"/> | |
+ </target> | |
+ | |
+ <target name="dist" depends="bnd, javadoc" | |
description="Build entire distribution."> | |
<ant antfile="servlet/build.xml" target="jar" inheritAll="false"/> | |
<ant antfile="spring/build.xml" target="jar" inheritAll="false"/> | |
@@ -57,7 +74,7 @@ | |
</target> | |
<target name="test.dist" | |
- depends="jar, test.compile" | |
+ depends="bnd, test.compile" | |
description="Execute JUnit tests against distribution jar."> | |
<java fork="true" | |
classname="junit.textui.TestRunner" | |
Index: lib/build/bnd-0.0.134.jar | |
=================================================================== | |
Cannot display: file marked as a binary type. | |
svn:mime-type = application/octet-stream | |
Property changes on: lib/build/bnd-0.0.134.jar | |
___________________________________________________________________ | |
Name: svn:mime-type | |
+ application/octet-stream | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment