Skip to content

Commit

Permalink
Merge pull request #910 from hazendaz/formatting
Browse files Browse the repository at this point in the history
[maven] Use source/test roots from session
  • Loading branch information
hazendaz authored Oct 21, 2024
2 parents b7cbbde + 800b0b4 commit cb3c776
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,6 @@ abstract class BaseViolationCheckMojo extends AbstractMojo {
@Parameter(defaultValue = '${project.reporting.outputDirectory}/xref-test')
File xrefTestLocation

/** The directories containing the sources to be compiled. */
@Parameter(defaultValue = '${project.compileSourceRoots}', required = true, readonly = true)
List compileSourceRoots

/**
* The directories containing the test-sources to be compiled.
*
* @since 2.0
*/
@Parameter(defaultValue = '${project.testCompileSourceRoots}', required = true, readonly = true)
List testSourceRoots

/**
* Run Spotbugs on the tests.
*
Expand Down
28 changes: 8 additions & 20 deletions src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,6 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
@Parameter(defaultValue = '${project.reporting.outputDirectory}/xref-test')
File xrefTestLocation

/** The directories containing the sources to be compiled. */
@Parameter(defaultValue = '${project.compileSourceRoots}', required = true, readonly = true)
List compileSourceRoots

/**
* The directories containing the test-sources to be compiled.
*
* @since 2.0
*/
@Parameter(defaultValue = '${project.testCompileSourceRoots}', required = true, readonly = true)
List testSourceRoots

/**
* Run Spotbugs on the tests.
*
Expand Down Expand Up @@ -663,8 +651,8 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
generator.setIsJXRReportEnabled(isJxrPluginEnabled)

if (isJxrPluginEnabled) {
generator.setCompileSourceRoots(this.compileSourceRoots)
generator.setTestSourceRoots(this.testSourceRoots)
generator.setCompileSourceRoots(session.getCurrentProject().compileSourceRoots)
generator.setTestSourceRoots(session.getCurrentProject().testCompileSourceRoots)
generator.setXrefLocation(this.xrefLocation)
generator.setXrefTestLocation(this.xrefTestLocation)
generator.setIncludeTests(this.includeTests)
Expand Down Expand Up @@ -723,8 +711,8 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
XDocsReporter xDocsReporter = new XDocsReporter(getBundle(locale), log, threshold, effort, outputEncoding)
xDocsReporter.setOutputWriter(Files.newBufferedWriter(Paths.get("${xmlOutputDirectory}/spotbugs.xml"), Charset.forName(outputEncoding)))
xDocsReporter.setSpotbugsResults(new XmlSlurper().parse(outputSpotbugsFile))
xDocsReporter.setCompileSourceRoots(this.compileSourceRoots)
xDocsReporter.setTestSourceRoots(this.testSourceRoots)
xDocsReporter.setCompileSourceRoots(session.getCurrentProject().compileSourceRoots)
xDocsReporter.setTestSourceRoots(session.getCurrentProject().testCompileSourceRoots)

xDocsReporter.generateReport()
}
Expand Down Expand Up @@ -938,9 +926,9 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {
log.debug(" Adding Source directories (To process source exclusions)")
args << "-sourcepath"
String sourceRoots = ""
compileSourceRoots.each() { sourceRoots += it + File.pathSeparator }
session.getCurrentProject().compileSourceRoots.each() { sourceRoots += it + File.pathSeparator }
if (includeTests) {
testSourceRoots.each() { sourceRoots + it + File.pathSeparator }
session.getCurrentProject().testCompileSourceRoots.each() { sourceRoots + it + File.pathSeparator }
}
args << sourceRoots.substring(0, sourceRoots.length() -1)
}
Expand Down Expand Up @@ -1149,12 +1137,12 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait {

def xmlProject = path.Project

compileSourceRoots.each() { compileSourceRoot ->
session.getCurrentProject().compileSourceRoots.each() { compileSourceRoot ->
xmlProject.appendNode { SrcDir(compileSourceRoot) }
}

if (testClassFilesDirectory.isDirectory() && includeTests) {
testSourceRoots.each() { testSourceRoot ->
session.getCurrentProject().testCompileSourceRoots.each() { testSourceRoot ->
xmlProject.appendNode { SrcDir(testSourceRoot) }
}
}
Expand Down

0 comments on commit cb3c776

Please # to comment.