开发者

how to create ant listener for specific task

We have around 80 jars in our applications. All are created using javac task and jar task in ant.

I would like to introduce findbug checks. One option was to create single findbug check ant project. This has all jars , all source paths defined in it. This works -- require lot of space. Analysis of result too not very straight forward. There are thousands of warnings to start with.

One option I am considering is to run ant with special listener on javac task ant , extract source and class location, call findbug task with source and class file information. Any other w开发者_如何学JAVAay introduce findbug to a large project.


tweaked taskFinished()... Fine for my usage.

public class JavacListener implements BuildListener 

     public void taskFinished(BuildEvent be) {

            if ( be.getTask() instanceof UnknownElement ) {
                UnknownElement ue= (UnknownElement) be.getTask();
                ue.maybeConfigure();

                if ( ue.getTask() instanceof Javac ) {
                Javac task = (Javac)ue.getTask();
                    final Path sourcepath = task.getSrcdir();
                    FindBugsTask fbtask = new FindBugsTask();
                    System.out.println ("Trying FindBugs");
                    fbtask.setSourcePath(sourcepath);
                    fbtask.setAuxClasspath(task.getClasspath());
                    Path destPath = new Path( task.getProject() );
                    destPath.setPath(task.getDestdir().getAbsolutePath());
                    fbtask.setAuxAnalyzepath(destPath);
                    fbtask.setOutputFile(getFileName(task.getProject()));
                    fbtask.setProject(task.getProject());

                    fbtask.setHome(new File("C:\\apps\\findbugs-1.3.0"));
                    fbtask.execute();
                }

            } else {
                System.out.println(be.getTask().getClass().getName());
                System.out.println(be.getTask().getTaskName());
            }
        }
..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜