maven 插件findbugs源代码的解析

  为了了解findbugs的插件运行原理,特地翻了findbugs插件的源码,插件的源码视图如下:

                                                  

FindBugsMojo.java就是我们的findbugs主类

代码如下:

   /**
 * Generates a FindBugs Report when the site plugin is run.

 * The HTML report is generated for site commands only.

 *

 * @goal findbugs

 * @phase compile

 * @requiresDependencyResolution compile

 * @requiresProject

 * @threadSafe

 * @author <a href="mailto:gleclaire@codehaus.org">Garvin LeClaire</a>

 * @version $Id: FindBugsMojo.groovy 16932 2012-06-21 01:13:14Z gleclaire $

 */

public class FindBugsMojo

    extends AbstractMavenReport

    implements groovy.lang.GroovyObject

findbugs的实现是使用groovy实现的,在FindBugsMojo.groovy中找到executeFindbugs的方法,

 ant.java(classname: "edu.umd.cs.findbugs.FindBugs2", inputstring: getFindbugsAuxClasspath(), fork: "${fork}", failonerror: "true", clonevm: "false", timeout: "${timeout}", maxmemory: "${maxHeap}m") {

            def effectiveEncoding = System.getProperty( "file.encoding", "UTF-8" )

            if ( sourceEncoding ) {
                effectiveEncoding = sourceEncoding
            }

            log.debug("File Encoding is " + effectiveEncoding)

            sysproperty(key: "file.encoding" , value: effectiveEncoding)

            if ( jvmArgs && fork ) {
                log.debug("Adding JVM Args => ${jvmArgs}")

                String[] args = jvmArgs.split(FindBugsInfo.BLANK)

                args.each() {jvmArg ->
                    log.debug("Adding JVM Arg => ${jvmArg}")
                    jvmarg(value: jvmArg)
                }
            }

            if ( debug || trace ) {
                sysproperty(key: "findbugs.debug" , value: true)
            }

            classpath() {

                pluginArtifacts.each() {pluginArtifact ->
                    log.debug("  Adding to pluginArtifact ->" + pluginArtifact.file.toString())

                    pathelement(location: pluginArtifact.file)
                }
            }


            findbugsArgs.each { findbugsArg ->
                log.debug("Findbugs arg is ${findbugsArg}")
                arg(value: findbugsArg)
            }

        }

调用的是edu.umd.cs.findbugs.FindBugs2来实现检查代码的,这个是findbugs.jar中实现的,maven插件是调用findbugs.jar来实现的。
findbugs.jar可以单独使用,findbugs的maven插件中java与groovy是如何相关交互的这些都是新的问题
然后在findbugs的maven pom中的依赖
<dependency>
<groupId> com.google.code.findbugs </groupId>
<artifactId> findbugs-ant </artifactId>
<version> ${findbugsVersion} </version>
</dependency>
version是2.0.1
<findbugsVersion>2.0.1</findbugsVersion>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值