如何为特定任务创建蚂蚁侦听器 [英] how to create ant listener for specific task

查看:25
本文介绍了如何为特定任务创建蚂蚁侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序中有大约 80 个 jar.都是在ant中使用javac task和jar task创建的.

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

我想介绍 findbug 检查.一种选择是创建单个 findbug 检查蚂蚁项目.这包含所有 jars ,其中定义了所有源路径.这有效 - 需要大量空间.结果分析也不是很直接.一开始就有数以千计的警告.

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.

我正在考虑的一个选项是在 javac 任务 ant 上运行带有特殊侦听器的 ant,提取源和类位置,使用源和类文件信息调用 findbug 任务.任何其他方式将 findbug 引入大型项目.

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 way introduce findbug to a large project.

推荐答案

tweaked taskFinished()... 适合我的用法.

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());
            }
        }
..

这篇关于如何为特定任务创建蚂蚁侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆