RE: [aspectwerkz-user] Speeding up roundtrip

Mattias Jiderhamn <[email protected]> Mon, 28 Nov 2005 15:52:24 +0100
Newsgroups gmane.comp.java.aspectwerkz.user
Message-ID <[email protected]>
Well, I managed to get it (partially) working by 
myself. Took me a while to get a hang of Ants 
task API, but after that very little code was 
required. Below is my compilation task implementation.

It seems to work as expected, although I get a 
warning claiming that the aspect cannot be found. 
I may have a closer look later this week.

import org.apache.tools.ant.types.Path;

import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;

public class JavacTask extends org.apache.tools.ant.taskdefs.Javac {

   private Set sourceDirs = new HashSet();

   protected void scanDir(File srcDir, File destDir, String[] files) {
     super.scanDir(srcDir, destDir, files);
     sourceDirs.add(srcDir);
   }

   protected void compile() {
     super.compile();
     Path compiledClasses = new Path(getProject());
     File destDir = getDestdir();
     for(int i = 0; i < compileList.length; i++) {
       final String javaFilePath = compileList[i].getAbsolutePath();
       if(destDir != null) {
         for(Iterator iter = sourceDirs.iterator(); iter.hasNext(); ) {
           File srcDir = (File) iter.next();
           if(javaFilePath.startsWith(srcDir.getAbsolutePath())) {
             final String classFilePath = 
getClassFilePath(destDir, srcDir, compileList[i]);
             compiledClasses.add(new Path(getProject(), classFilePath));
             break;
           }
         }
       }
       else {
         compiledClasses.add(new 
Path(getProject(), getClassFilePath(compileList[i])));
       }
     }
     getProject().addReference("compiled.classes", 
compiledClasses); // TODO: Make tag attribute
   }

   private String getClassFilePath(File destDir, File srcDir, File javaFile) {
     String javaFilePath = javaFile.getAbsolutePath();
     return destDir.getAbsolutePath() +
         javaFilePath.substring(srcDir.getAbsolutePath().length(), 
javaFilePath.length() - 4) + "class";
   }

   private String getClassFilePath(File javaFile) {
     String javaFilePath = javaFile.getAbsolutePath();
     return javaFilePath.substring(0, javaFilePath.length() - 4) + "class";
   }
}

At 2005-11-28 15:44, you wrote:
>I apologize for never following up on the 
>previous thread. I would definitely try to take 
>out some time this week and send what I did.
>
>Regards
>Atif Khan
>
>
>
>----------
>From: Mattias Jiderhamn [mailto:[email protected]]
>Sent: Thursday, November 24, 2005 2:43 AM
>To: [email protected]
>Cc: Khan, Atif (Matrix)
>Subject: RE: [aspectwerkz-user] Speeding up roundtrip
>
>[Bringing an old thread to life again...]
>
>Since we discussed this I have tried the other 
>approach; trying to find out why the online 
>weaving is so slow. It was a bit hard since I'm 
>not very used to profiling and Alexandre has 
>limited insight in our environment and application.
>
>Recently I also added Hibernate to the project, 
>which adds to the reloading time even furhter. 
>Therefore I am now eager to try other alternatives.
>
>Atif, could you post to the list the javac 
>wrapper you were talkning about, and an Ant file with usage example?
>If it works for me, we can try to refine it and 
>then contribute it to the AW project.
>
>In my dreams I would also like to create an IDE 
>plugin, that does automatic "post compile 
>weaving" after compiling classes in IntelliJ.
>But for now, an Ant task that only (compiles 
>and) weaves changed classes would be great.
>
>Thanks in advance,
>
>   Mattias Jiderhamn
>
>At 2005-06-22 15:24, Khan, Atif (Matrix) wrote:
>
>Let me clarify my environment a little.
>
>My Eclipse IDE doesn't weave the classes using 
>AspectWerkz. It uses a separate directory for 
>classes. We use ANT scripts to do out builds for 
>different environments and that's where we use 
>Aspectwerkz and compile time weaving.
>
>Regards
>Atif Khan
>
>----------
>From: Mattias Jiderhamn [ mailto:[email protected]]
>Sent: Wednesday, June 22, 2005 4:05 AM
>To: [email protected]
>Subject: RE: [aspectwerkz-user] Speeding up roundtrip
>
>So your project still compiles against the weaved classes?
>My experience is that I have to recompile all 
>classes, or I will get compilation errors.
>But honestly, when I try to recreate this to 
>post the error it works just fine. I will get 
>back to you if the problem reappears.
>
>At 2005-06-21 16:56, you wrote:
>
>I can definitely share this. I am just not sure 
>how do I do that. Is this something that I can 
>contribute to the base of AspectWerkz?
>
>I do not use a different output directory. So, I 
>don't have to copy any classes. Only the classes 
>written to the text file by JAVAC task are weaved by the AspectWerkzCTask.
>
>Regards
>Atif Khan
>
>----------
>From: Mattias Jiderhamn [ mailto:[email protected]]
>Sent: Tuesday, June 21, 2005 10:12 AM
>To: [email protected]
>Subject: RE: [aspectwerkz-user] Speeding up roundtrip
>
>Interresting. Is this something you would like to share?
>
>Have you also made AspectWerkzC use a different 
>output directory, or do you make a copy of all 
>the (modified) class files first, so that you 
>don't have to recompile all classes next time?
>
>At 2005-06-21 15:13, you wrote:
>
>
>We had the same issue. Our codebase is really 
>big. So, what I did was to override the "javac" 
>ANT task to write the file list to a text file. 
>Since javac already checks for the timestamps, 
>it only compiles the modified classes. This way 
>I have a list of only modified classes. I then 
>extended the AspectwerkzCTask to read the files 
>from this text file and AOP compile them. This 
>way I don't have to weave the whole codebase evrytime.
>
>Regards
>Atif Khan
>
>-----Original Message-----
>From: Alexandre Vasseur 
>[<mailto:[email protected]>mailto:[email protected]]
>Sent: Tuesday, June 21, 2005 7:04 AM
>To: [email protected]
>Subject: Re: [aspectwerkz-user] Speeding up roundtrip
>
>Hi
>
>...
>
>AspectWerkzC does not support writing to a different location.
>On the other hand you may be able to implement a 
>wrapper that checks for .class file timestamps 
>to compile only modified files (then keep track 
>of the lastRun timestamp in some per project file)
>
>Alex
>
>On 6/21/05, Mattias Jiderhamn <[email protected]> wrote:
> > Our application is big enough to require a few minutes of offline
> > weaving on my machine, so we use online weaving in development. On the
> > other hand, reloading the application in the web container using
> > online weaving isn't much better (say ½-1 minute). This makes
> > developing very slow, since the code-compile-test cycle has a lot of
> > weaving overhead.
> >
> > Is there any better way to do this? Can I have AspectWerkz weave only
> > modified classes offline?
> > If I weave the whole project and then try to compile in my IDE
> > (IntelliJ), I get compiler errors. Could I make AspectWerkzC output
> > the weaved files in a different directory, so that I can compile from
> > the IDE and then have AspectWerkz weave the modified classes only?
> >
> > Thanks in advance,
> >    Mattias Jiderhamn