[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Runtime weaving
|
You've perhaps seen
http://bugs.eclipse.org/bugs/show_bug.cgi?id=31460
But there's some issues with it...
Wes
Joel Shellman wrote:
>
> Can someone just post a very brief sample code of runtime weaving?
>
> I'm trying to get it to work, but can't seem to get it. Here's what I have
> so far (don't laugh too hard, I just hacked this together quickly):
>
> public static void main(String[] args) throws Exception {
> BcelWorld world = new BcelWorld();
> BcelWeaver w = new BcelWeaver(world);
> w.addLibraryAspect("org.sparrowdb.enhancer.EnhancerAspect");
> byte[] bytes = new byte[128000];
> InputStream is =
> EnhancerLoader.class.getClassLoader().getResourceAsStream("org/sparrowdb/obj
> /Item.class");
> int length = is.read(bytes);
> System.out.println("bytes: "+length);
> byte[] usebytes = new byte[length];
> System.arraycopy(bytes, 0, usebytes, 0, length);
>
> UnwovenClassFile clsFile = new UnwovenClassFile("org.sparrowdb.obj.Item",
> usebytes);
> w.addClassFile(clsFile);
> w.weave(new File("C:/temp/test.zip"));
>
> ResolvedTypeX t = world.resolve(clsFile.getClassName());
> BcelObjectType type = BcelWorld.getBcelObjectType(t);
> LazyClassGen lcg = w.weaveWithoutDump(clsFile, type);
> byte[] newBytes = lcg.getJavaClass().getBytes();
>
> System.out.println("nb: "+newBytes);
> }
>
> The problem above is that lcg is returned null from the weaveWithoutDump
> call.
>
> Thanks!
>
> -joel shellman
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users