Skip to content

Commit

Permalink
Merge pull request #550 from corebonts/488-auxclasspath
Browse files Browse the repository at this point in the history
#549 Pass the auxiliary classpath using the -auxclasspathFromFile agument
  • Loading branch information
hazendaz authored Feb 25, 2023
2 parents 6ac7bf3 + 6a9bb44 commit 03a2658
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
private ArrayList<String> getSpotbugsArgs(File htmlTempFile, File xmlTempFile, File sarifTempFile) {
ResourceHelper resourceHelper = new ResourceHelper(log, spotbugsXmlOutputDirectory, resourceManager)
def args = new ArrayList<String>()
def auxClasspathFile = createSpotbugsAuxClasspathFile()

if (userPrefs) {
log.debug(" Adding User Preferences File -> ${userPrefs}" )
Expand All @@ -888,6 +889,11 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
args << "-sarif=" + sarifTempFile.getAbsolutePath()
}

if (auxClasspathFile) {
args << "-auxclasspathFromFile"
args << auxClasspathFile.getAbsolutePath()
}

args << "-projectName"
args << "${project.name}"

Expand Down Expand Up @@ -1022,42 +1028,37 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
}

/**
* Get the Spotbugs AuxClasspath.
* Create the Spotbugs AuxClasspath file.
*
*/
private String getSpotbugsAuxClasspath() {
private File createSpotbugsAuxClasspathFile() {
def auxClasspathElements

if (classFilesDirectory.exists() && classFilesDirectory.isDirectory()) {
auxClasspathElements = project.compileClasspathElements
}

if (testClassFilesDirectory.exists() && testClassFilesDirectory.isDirectory() && includeTests) {
auxClasspathElements = project.testClasspathElements
} else if (classFilesDirectory.exists() && classFilesDirectory.isDirectory()) {
auxClasspathElements = project.compileClasspathElements
}

def auxClasspath = ""
File auxClasspathFile = null

if (auxClasspathElements) {
auxClasspathFile = File.createTempFile("auxclasspath", ".tmp")
auxClasspathFile.deleteOnExit()
log.debug(" AuxClasspath Elements ->" + auxClasspathElements)

def auxClasspathList = auxClasspathElements.findAll { project.build.outputDirectory != it.toString() }
if (auxClasspathList.size() > 0) {

auxClasspath += File.pathSeparator

log.debug(" Last AuxClasspath is ->" + auxClasspathList[auxClasspathList.size() - 1])

auxClasspathList.each() { auxClasspathElement ->
log.debug(" Adding to AuxClasspath ->" + auxClasspathElement.toString())
auxClasspath += auxClasspathElement.toString() + File.pathSeparator
auxClasspathFile << auxClasspathElement.toString() + "\n"
}
}
}

log.debug(" AuxClasspath is ->" + auxClasspath)

return auxClasspath
return auxClasspathFile
}

/**
Expand Down Expand Up @@ -1142,7 +1143,7 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
effectiveEncoding = sourceEncoding
}

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

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

Expand Down

0 comments on commit 03a2658

Please sign in to comment.