Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Running findbugs under ant + ivy

Help
2009-10-14
2013-02-05
  • Leon Rosenberg
    Leon Rosenberg
    2009-10-14

    Findbugs doesn't find dependent libs (asm, commons-lang, etc) if they have different name. Thats makes it pretty hard to use findbugs with ivy, you either have to define multiple versions of each lib (which makes ivy kindof obsolete) or you have to rename the libs during the build. Thats really suboptimal. Is there a workaround of some sort to force findbugs to use the libs it finds?

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-15

    I'm not quite sure if I fully understand your question … and unfortunately I don't know Ivy.

    But I want to try to give you some basic thoughts about classpathes:

    Basically a Java program does not know about libs/jars. It simply searches the classpath for the class it needs. A class is identified by its full name, consisting of package and the classname itself. So it doesn't matter in which jar a class is located. And in particular it doesn't matter if a jar is called "myLib.jar" or "myLib_V2.0.jar" as long as it contains the required class(es).

    I guess your problem lies in the construction of the classpath when you start FindBugs. Obviously you provide wrong libraries or not all libraries that are necessary for FindBugs to run. Do you maybe have a script to start FindBugs which includes wrong names of the Jars?

    Regards
    Dirk

     
  • Leon Rosenberg
    Leon Rosenberg
    2009-10-15

    Ok, i make my self more clear:
    if you have dom4j-1.6.1.jar in the classpath/findbugs home -> it works.
    If you rename it do dom4j.jar -> it doesnt.
    Is there a mailing list or something? You can't put an xml config herein…

    regards
    leon

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-16

    Hi Leon,

    the reason for this behaviour is that the standard script starts FindBugs from the JAR-archive with option "-jar". This way the manifest-file from the archive is used, which defines the names of the libraries. You should use your own script that puts all JARs in the classpath and calls the main class, like that:

    java -cp findbugs.jar;bcel.jar;dom4j.jar;jaxen-1.1.1.jar;asm-3.1.jar;asm-tree-3.1.jar;asm-commons-3.1.jar;jsr305.jar;jFormatString.jar;commons-lang-2.4.jar edu.umd.cs.findbugs.LaunchAppropriateUI

    Here you can use your own JAR-names as long as all classes are in the classpath. (You probably will have to use pathnames in the script!)

    Regards
    Dirk

     
  • Leon Rosenberg
    Leon Rosenberg
    2009-10-16

    Hello Dirk,
    thank you for your reply. It all makes sense, except that I don't start findbugs via script or anything, but via ant. Does findbugs ant task start a new java process instead of using the ant provided lib path?
    Leon

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-19

    Hi Leon,

    I assume you use the "home"-attribute in the Ant-Findbugs-task!? Try to use an explicit classpath instead, which includes all JARs from the findbugs-lib-directory. This should overwrite the standard set of libraries. Like this:

    <pre>
       <property name="fb.lib.dir" value="D:\Software\findbugs-1.3.8\lib"/>
       <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
          <classpath>
             <pathelement location="${fb.lib.dir}/findbugs-ant.jar"/>
          </classpath>
       </taskdef>

       <target name="findbugs" depends="buildJar">
          <findbugs output="xml" outputFile="libToTest.xml">
             <classpath>
                <fileset dir="${fb.lib.dir}">
                   <include name="**/*.jar"/>
                </fileset>
             </classpath>
             <pluginList/>
             <sourcePath path="../src"/>
             <class location="../build/jar/libToTest.jar"/>
          </findbugs>
       </target>
    </pre>

    <br/>
    Regards Dirk

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-19

    hmmm … another try with "markdown" … in the preview window it was looking fine :-|

    <pre><code>

    <property name="fb.lib.dir" value="D:\Software\findbugs-1.3.8\lib"/>
    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
       <classpath>
          <pathelement location="${fb.lib.dir}/findbugs-ant.jar"/>
       </classpath>
    </taskdef>

    <target name="findbugs" depends="buildJar">
       <findbugs output="xml" outputFile="libToTest.xml">
          <classpath>
             <fileset dir="${fb.lib.dir}">
                <include name="**/*.jar"/>
             </fileset>
          </classpath>
          <pluginList/>
          <sourcePath path="../src"/>
          <class location="../build/jar/libToTest.jar"/>
       </findbugs>
    </target>

    </code></pre>

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-19

    <property name="fb.lib.dir" value="D:\Software\findbugs-1.3.8\lib"/><br/>
    <taskdef name="findbugs" <br/>classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
       <classpath><br/>
          <pathelement location="${fb.lib.dir}/findbugs-ant.jar"/><br/>
       </classpath><br/>
    </taskdef><br/>
    <br/>
    <target name="findbugs" depends="buildJar"><br/>
       <findbugs output="xml" outputFile="libToTest.xml"><br/>
          <classpath><br/>
             <fileset dir="${fb.lib.dir}"><br/>
                <include name="**/*.jar"/><br/>
             </fileset><br/>
          </classpath><br/>
          <pluginList/><br/>
          <sourcePath path="../src"/><br/>
          <class location="../build/jar/libToTest.jar"/><br/>
       </findbugs><br/>
    </target>

     
  • Dirk Jagalski
    Dirk Jagalski
    2009-10-19

    whatever … and you cannot even edit your posts! :-(