Skip to content

Commit 03a2658

Browse files
authored
Merge pull request #550 from corebonts/488-auxclasspath
#549 Pass the auxiliary classpath using the -auxclasspathFromFile agument
2 parents 6ac7bf3 + 6a9bb44 commit 03a2658

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
870870
private ArrayList<String> getSpotbugsArgs(File htmlTempFile, File xmlTempFile, File sarifTempFile) {
871871
ResourceHelper resourceHelper = new ResourceHelper(log, spotbugsXmlOutputDirectory, resourceManager)
872872
def args = new ArrayList<String>()
873+
def auxClasspathFile = createSpotbugsAuxClasspathFile()
873874

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

892+
if (auxClasspathFile) {
893+
args << "-auxclasspathFromFile"
894+
args << auxClasspathFile.getAbsolutePath()
895+
}
896+
891897
args << "-projectName"
892898
args << "${project.name}"
893899

@@ -1022,42 +1028,37 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
10221028
}
10231029

10241030
/**
1025-
* Get the Spotbugs AuxClasspath.
1031+
* Create the Spotbugs AuxClasspath file.
10261032
*
10271033
*/
1028-
private String getSpotbugsAuxClasspath() {
1034+
private File createSpotbugsAuxClasspathFile() {
10291035
def auxClasspathElements
10301036

1031-
if (classFilesDirectory.exists() && classFilesDirectory.isDirectory()) {
1032-
auxClasspathElements = project.compileClasspathElements
1033-
}
1034-
10351037
if (testClassFilesDirectory.exists() && testClassFilesDirectory.isDirectory() && includeTests) {
10361038
auxClasspathElements = project.testClasspathElements
1039+
} else if (classFilesDirectory.exists() && classFilesDirectory.isDirectory()) {
1040+
auxClasspathElements = project.compileClasspathElements
10371041
}
10381042

1039-
def auxClasspath = ""
1043+
File auxClasspathFile = null
10401044

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

10441050
def auxClasspathList = auxClasspathElements.findAll { project.build.outputDirectory != it.toString() }
10451051
if (auxClasspathList.size() > 0) {
1046-
1047-
auxClasspath += File.pathSeparator
1048-
10491052
log.debug(" Last AuxClasspath is ->" + auxClasspathList[auxClasspathList.size() - 1])
10501053

10511054
auxClasspathList.each() { auxClasspathElement ->
10521055
log.debug(" Adding to AuxClasspath ->" + auxClasspathElement.toString())
1053-
auxClasspath += auxClasspathElement.toString() + File.pathSeparator
1056+
auxClasspathFile << auxClasspathElement.toString() + "\n"
10541057
}
10551058
}
10561059
}
10571060

1058-
log.debug(" AuxClasspath is ->" + auxClasspath)
1059-
1060-
return auxClasspath
1061+
return auxClasspathFile
10611062
}
10621063

10631064
/**
@@ -1142,7 +1143,7 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
11421143
effectiveEncoding = sourceEncoding
11431144
}
11441145

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

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

0 commit comments

Comments
 (0)