jjzjj

java - Maven Codehaus findbugs 插件 "onlyAnalyze"选项未按预期工作

coder 2024-03-27 原文

不耐烦的更新:很简单,使用package.-代替package.*进行分包扫描,as-per下面是 martoe 的回答!

我似乎无法让 onlyAnalyze 为我的多模块项目工作:无论我设置什么包(或模式),maven-findbugs-plugin 都不会评估子包,因为我' d 期望通过 packagename.*.

为了证明我自己或插件有问题(尽管我总是认为是前者!),我设置了一个具有以下结构的小型 Maven 项目:

pom.xml
src/
    main/java/acme/App.java
    main/java/acme/moo/App.java
    main/java/no_detect/App.java

这很简单!

POM 具有以下 findbugs 配置:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>2.4.0</version>
            <executions>
                <execution>
                    <phase>verify</phase>
                    <goals><goal>findbugs</goal><goal>check</goal></goals>
                </execution>
            </executions>
            <configuration>
                <debug>true</debug>
                <effort>Max</effort>
                <threshold>Low</threshold>
                <onlyAnalyze>acme.*</onlyAnalyze>
            </configuration>
        </plugin>
    </plugins>
</build>

并且每个 App.java 都有以下代码,其中有两个明显的违规行为:

package acme;
import java.io.Serializable;

public class App implements Serializable
{
    private static final class NotSer {
        private String meh = "meh";
    }

    private static final NotSer ns = new NotSer();// Violation: not serializable field

    public static void main( String[] args )
    {
        ns.meh = "hehehe";// Vilation: unused
        System.out.println( "Hello World!" );
    }
}

请注意,no_detect.App 与上面的内容相同,但我的预期是它不会被 findbugs 评估,因为我将“onlyAnalyze”选项设置为 acme。 * 我认为它会评估 acme.Appacme.moo.App 而不是其他。

我现在执行 mvn clean install 来清理、构建、测试、运行 findbugs、打包、安装,这会生成以下 findbugs 报告(为简洁起见被删减)并导致构建失败,即预期是因为 acme.Appacme.moo.App:

<BugInstance category='BAD_PRACTICE' type='SE_NO_SERIALVERSIONID' instanceOccurrenceMax='0'>
<ShortMessage>Class is Serializable, but doesn't define serialVersionUID</ShortMessage>
<LongMessage>acme.App is Serializable; consider declaring a serialVersionUID</LongMessage>
<Details>
  &lt;p&gt; This field is never read.&amp;nbsp; Consider removing it from the class.&lt;/p&gt;
</Details>
<BugPattern category='BAD_PRACTICE' abbrev='SnVI' type='SE_NO_SERIALVERSIONID'><ShortDescription>Class is Serializable, but doesn't define serialVersionUID</ShortDescription><Details>
<BugCode abbrev='UrF'><Description>Unread field</Description></BugCode><BugCode abbrev='SnVI'><Description>Serializable class with no Version ID</Description></BugCode>

总结一下:只分析了 acme.Appacme.moo.App 不是(坏的),no_detect.App 也不是>(好)。

我尝试在 onlyAnalyze 选项中使用两个通配符,但这会生成成功构建,但会出现 findbugs 错误(悬挂元字符“*” 等)。

我尝试将 onlyAnalyze 设置为 acme.*,acme.moo.* 来分析所有预期的类(acme.Appacme.moo.App) 这意味着它“有效”但不像我预期的那样;也就是说,我必须为我要分析的类显式声明所有父包:这可能会变得很大并且难以在多模块项目中维护!

我是否必须定义每个要分析的包,或者我是否可以声明一个通配符/正则表达式模式来执行我想要的操作?

我宁愿不使用包含/排除 XML,因为这需要更多的设置和推理,而我目前没有时间......

最佳答案

引用Findbugs manual : "将 .* 替换为 .- 以同时分析所有子包"

关于java - Maven Codehaus findbugs 插件 "onlyAnalyze"选项未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9259280/

有关java - Maven Codehaus findbugs 插件 "onlyAnalyze"选项未按预期工作的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  4. ruby - 如何每月在 Heroku 运行一次 Scheduler 插件? - 2

    在选择我想要运行操作的频率时,唯一的选项是“每天”、“每小时”和“每10分钟”。谢谢!我想为我的Rails3.1应用程序运行调度程序。 最佳答案 这不是一个优雅的解决方案,但您可以安排它每天运行,并在实际开始工作之前检查日期是否为当月的第一天。 关于ruby-如何每月在Heroku运行一次Scheduler插件?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/8692687/

  5. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  6. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  7. ruby - 默认情况下使选项为 false - 2

    这是在Ruby中设置默认值的常用方法:classQuietByDefaultdefinitialize(opts={})@verbose=opts[:verbose]endend这是一个容易落入的陷阱:classVerboseNoMatterWhatdefinitialize(opts={})@verbose=opts[:verbose]||trueendend正确的做法是:classVerboseByDefaultdefinitialize(opts={})@verbose=opts.include?(:verbose)?opts[:verbose]:trueendend编写Verb

  8. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  9. java - 等价于 Java 中的 Ruby Hash - 2

    我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/

  10. ruby-on-rails - rspec should have_select ('cars' , :options => ['volvo' , 'saab' ] 不工作 - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion在首页我有:汽车:VolvoSaabMercedesAudistatic_pages_spec.rb中的测试代码:it"shouldhavetherightselect"dovisithome_pathit{shouldhave_select('cars',:options=>['volvo','saab','mercedes','audi'])}end响应是rspec./spec/request

随机推荐