Class names from file names

3 views
Skip to first unread message

Alessio Soldano

unread,
Nov 28, 2009, 1:22:50 PM11/28/09
to tested...@googlegroups.com
Hi there,
while working on the maven plugin, I've come to the point where I need
to get the list of changed classes to be passed to the TestedBy runner.
That's basically a List<Class<?>>. Let's forget about the classloader
that's going to load those classes, as -at least for now- that's going
to be the bootclassloader whose classpath elements are specified by the
plugin when launching the instrumentation. The point now is that I know
the changed class files, but need the class names (and of course there
might be inner classes, etc.). Do you have any special (reliable) idea
besides looking at the class name in every class bytecode? (which is not
going to be that fast imho...) I'm wondering if a
class-name-to-file-name mapping convention is specified anywhere or not.
I did not find anything about that in the JVM spec, but I might have
missed that... and quite frankly I'm not a real expert here.
Cheers
Alessio

Stefano Maestri

unread,
Nov 29, 2009, 8:03:33 AM11/29/09
to tested...@googlegroups.com
AFAIK javaassist could help you with this:

ClassPool cp = ClassPool.getDefault();
InputStream ins = an input stream for reading a class file;
CtClass cc = cp.makeClass(ins);
Class<?> cc.toCLass():
Isn't it what you need?

bye
S.


--

You received this message because you are subscribed to the Google Groups "testedby-dev" group.
To post to this group, send email to tested...@googlegroups.com.
To unsubscribe from this group, send email to testedby-dev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testedby-dev?hl=en.



Alessio Soldano

unread,
Nov 29, 2009, 6:51:45 PM11/29/09
to tested...@googlegroups.com
Hi Stefano,
thanks for the suggestion.
The proposed code did not actually work as we can't use cc.toClass()
because that freezes the class, preventing the instrumentation agent
from redefining it.
However, your hint made me see there's a simple getName() method on
CtClass... which allows for full class name retrieval without having to
actually load the class. And that solves my problem of deriving the
class name from a file name.
Cheers
Alessio


Stefano Maestri wrote:
> AFAIK javaassist could help you with this:
>
> ClassPool cp = ClassPool.getDefault();
> InputStream ins = /an input stream for reading a class file/;
> <mailto:tested...@googlegroups.com>.
> To unsubscribe from this group, send email to
> testedby-dev...@googlegroups.com
> <mailto:testedby-dev%2Bunsu...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages