From 800b0b4b04a5e77f2bccf9f80b581c9bb673dd8e Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Sun, 20 Oct 2024 02:42:34 -0400 Subject: [PATCH] [maven] Use source/test roots from session --- .../spotbugs/BaseViolationCheckMojo.groovy | 12 -------- .../mojo/spotbugs/SpotBugsMojo.groovy | 28 ++++++------------- 2 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy index 2d0fe6d7..270e079c 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy @@ -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. * diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy index d12ca865..edd12bb5 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy @@ -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. * @@ -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) @@ -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() } @@ -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) } @@ -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) } } }