The Proxy from cglib.sourceforge.net is a drop-in
replacement for the java.lang.reflect.Proxy class with
two important extra features:
- It can proxy concrete classes, not just interfaces.
- It can operate under JDK 1.2.2
The attached patch replaces references to the reflect
Proxy with the cglib Proxy.
This does add extra dependencies to mockobjects, in the
form of cglib and the underlying asm code.
CGLib is released under the Apache License. It's
available from http://cglib.sourceforge.net/
ASM is released under LGPL. It's available from
http://asm.objectweb.org/
Patch to use the cglib proxy
Logged In: YES
user_id=123464
This is interesting. We've discussed using bcel to do this,
but I'm wary of adding dependencies. At present, the core
library is completely independant. Maybe we could provide a
hook for multiple implementations.
Logged In: YES
user_id=694803
CGLib comes in an ASM or BCEL version - I'm not sure if it's
switchable... I'm pretty sure they just removed BCEL support
and replaced it with ASM. Abstracting away the library that
is extracting away the bytecode for you wouldn't be a cup of
tea.
Oops - I was wrong -just looked through the sourcecode, and
it looks like it detects whichever one is available
(favouring ASM).
You'd be putting a dependency on cglib - with the option to
depend on either ASM of BCEL.
Logged In: YES
user_id=694803
If you really wanted to have no external dependencies, you
COULD inline the cglib code, but I'd advise against it.
It would be fairly simple to abstract away which proxy you
are using. If you want I can whip up another patch that
selects cglib if it is available and otherwise falls back on
the java.lang.reflect proxy.
Logged In: YES
user_id=694803
It's a bit rushed and messy, but heres another patch that
will use CgLib if available, otherwise it'll fall back on
the java.reflect code.
Logged In: YES
user_id=694803
Hmmm... seems the file didn't attach last time. I've updated
it to match the latest cvs now.
There's going to be a compile-time dependency on cglib for
core as it stands.
Options for removing that are:
- Make the cglib proxy implementation an extension and
trigger it using a system property. I don't want to do this,
as it makes it pretty hard for people to use.
- Make the calling to Proxy happen via reflection. Slower,
seems a bit silly, but it'd work.
- ???
Patch to OPTIONALLY use the cglib proxy
Logged In: YES
user_id=694803
Appears the file didn't go through last time.
Fixed it up to match current cvs. Enjoy.
There's still going to be compile-time dependencies on
cglib. Is this a problem? I could probably do some dodgy
work with reflection to make that go away. I could also make
it driven by a system property, but I think that'd just
confuse users.
Logged In: YES
user_id=646960
I just did essentially the same patch using CGLib; glad I
checked here first before submitting it! I really hope this
patch gets submitted; it's extremely handy.
Depending on an external library doesn't seem like that big of
a deal to me. (Reuse is good!) But even if the reflection
option has to be used to load CGLib, I sure hope this patch
gets included!
Logged In: YES
user_id=123464
we would like to do this, but the dynamic mocks are a bit of
a moving target right now. As soon as we can, we'll get back
to this patch.
Steve
Logged In: YES
user_id=694803
It's been two months since the last update on this. Any
progress? Do you want a patch made up against the current cvs?