Revision: 1368
Author: sberlin
Date: Mon Nov 8 21:35:13 2010
Log: make sure $$EnhancerByGuice$$ & $$FastClassByGuice$$ stay named that
way and don't become $$$EnhancerByGuice$$ & $$$FastClassByGuice$$ after
jarjar renames the cglib classes.
http://code.google.com/p/google-guice/source/detail?r=1368
Modified:
/trunk/core/src/com/google/inject/internal/BytecodeGen.java
/trunk/core/test/com/googlecode/guice/BytecodeGenTest.java
=======================================
--- /trunk/core/src/com/google/inject/internal/BytecodeGen.java Tue Oct 26
19:03:52 2010
+++ /trunk/core/src/com/google/inject/internal/BytecodeGen.java Mon Nov 8
21:35:13 2010
@@ -30,6 +30,8 @@
import java.util.Map;
import java.util.logging.Logger;
+import net.sf.cglib.core.Predicate;
+
/**
* Utility methods for runtime code generation and class loading. We use
this stuff for {...@link
* net.sf.cglib.reflect.FastClass faster reflection}, {...@link
net.sf.cglib.proxy.Enhancer method
@@ -79,11 +81,37 @@
static final String CGLIB_PACKAGE
=
net.sf.cglib.proxy.Enhancer.class.getName().replaceFirst("\\.cglib\\..*$", ".cglib");
- static final net.sf.cglib.core.NamingPolicy NAMING_POLICY
+ static final net.sf.cglib.core.NamingPolicy FASTCLASS_NAMING_POLICY
= new net.sf.cglib.core.DefaultNamingPolicy() {
@Override protected String getTag() {
return "ByGuice";
}
+
+ @Override
+ public String getClassName(String prefix, String source, Object key,
Predicate names) {
+ // we explicitly set the source here to "FastClass" so that our
jarjar renaming
+ // to $FastClass doesn't leak into the class names. if we did not
do this,
+ // classes would end up looking like $$$FastClassByGuice$$, with the
extra $
+ // at the front.
+ return super.getClassName(prefix, "FastClass", key, names);
+ }
+ };
+
+ static final net.sf.cglib.core.NamingPolicy ENHANCER_NAMING_POLICY
+ = new net.sf.cglib.core.DefaultNamingPolicy() {
+ @Override
+ protected String getTag() {
+ return "ByGuice";
+ }
+
+ @Override
+ public String getClassName(String prefix, String source, Object key,
Predicate names) {
+ // we explicitly set the source here to "Enhancer" so that our
jarjar renaming
+ // to $Enhancer doesn't leak into the class names. if we did not do
this,
+ // classes would end up looking like $$$EnhancerByGuice$$, with the
extra $
+ // at the front.
+ return super.getClassName(prefix, "Enhancer", key, names);
+ }
};
/*end[AOP]*/
/*if[NO_AOP]
@@ -174,7 +202,7 @@
if (visibility == Visibility.PUBLIC) {
generator.setClassLoader(getClassLoader(type));
}
- generator.setNamingPolicy(NAMING_POLICY);
+ generator.setNamingPolicy(FASTCLASS_NAMING_POLICY);
logger.fine("Loading " + type + " FastClass with " +
generator.getClassLoader());
return generator.create();
}
@@ -186,7 +214,7 @@
if (visibility == Visibility.PUBLIC) {
enhancer.setClassLoader(getClassLoader(type));
}
- enhancer.setNamingPolicy(NAMING_POLICY);
+ enhancer.setNamingPolicy(ENHANCER_NAMING_POLICY);
logger.fine("Loading " + type + " Enhancer with " +
enhancer.getClassLoader());
return enhancer;
}
=======================================
--- /trunk/core/test/com/googlecode/guice/BytecodeGenTest.java Sun May 9
05:48:24 2010
+++ /trunk/core/test/com/googlecode/guice/BytecodeGenTest.java Mon Nov 8
21:35:13 2010
@@ -64,6 +64,15 @@
Injector injector = Guice.createInjector(interceptorModule, new
PackageVisibilityTestModule());
injector.getInstance(PublicUserOfPackagePrivate.class); // This must
pass.
}
+
+ public void testEnhancerNaming() {
+ Injector injector = Guice.createInjector(interceptorModule, new
PackageVisibilityTestModule());
+ PublicUserOfPackagePrivate pupp =
injector.getInstance(PublicUserOfPackagePrivate.class);
+ assertTrue(pupp.getClass().getName().startsWith(
+ PublicUserOfPackagePrivate.class.getName()
+ "$$EnhancerByGuice$$"));
+ }
+
+ // TODO(sameb): Figure out how to test FastClass naming tests.
/**
* Custom URL classloader with basic visibility rules
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.