From 3c10716d0883ef79e0d55836a1ac0382426140c4 Mon Sep 17 00:00:00 2001 From: Jeremy Landis Date: Thu, 29 Aug 2024 19:15:17 -0400 Subject: [PATCH] Use maven session api for local and remote repositories --- .../mojo/spotbugs/BaseViolationCheckMojo.groovy | 11 ----------- .../org/codehaus/mojo/spotbugs/SpotBugsGui.groovy | 12 ------------ .../org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy | 11 ----------- .../mojo/spotbugs/SpotBugsPluginsTrait.groovy | 11 ++++------- 4 files changed, 4 insertions(+), 41 deletions(-) diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy index e7e515e9..2ecbebd5 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/BaseViolationCheckMojo.groovy @@ -21,7 +21,6 @@ import groovy.xml.XmlSlurper import javax.inject.Inject import org.apache.commons.io.FileUtils -import org.apache.maven.artifact.repository.ArtifactRepository import org.apache.maven.doxia.siterenderer.Renderer import org.apache.maven.doxia.tools.SiteTool import org.apache.maven.execution.MavenSession @@ -118,16 +117,6 @@ abstract class BaseViolationCheckMojo extends AbstractMojo { @Parameter(property = "plugin.artifacts", required = true, readonly = true) List pluginArtifacts - /** - * The local repository, needed to download the coreplugin jar. - */ - @Parameter(property = "localRepository", required = true, readonly = true) - ArtifactRepository localRepository - - /** Remote repositories which will be searched for the coreplugin jar. */ - @Parameter(property = "project.remoteArtifactRepositories", required = true, readonly = true) - List remoteArtifactRepositories - /** Maven Session. */ @Parameter (defaultValue = '${session}', required = true, readonly = true) MavenSession session diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsGui.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsGui.groovy index 8cab24ee..e94d758d 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsGui.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsGui.groovy @@ -19,7 +19,6 @@ import groovy.ant.AntBuilder import javax.inject.Inject -import org.apache.maven.artifact.repository.ArtifactRepository import org.apache.maven.execution.MavenSession import org.apache.maven.plugin.AbstractMojo import org.apache.maven.plugins.annotations.Mojo @@ -82,17 +81,6 @@ class SpotBugsGui extends AbstractMojo implements SpotBugsPluginsTrait { @Inject RepositorySystem factory - /** List of Remote Repositories used by the resolver. */ - @Parameter(property = "project.remoteArtifactRepositories", required = true, readonly = true) - List remoteRepositories - - /** - * The local repository, needed to download the coreplugin jar. - * - */ - @Parameter(property = "localRepository", required = true, readonly = true) - ArtifactRepository localRepository - /** Maven Session. */ @Parameter (defaultValue = '${session}', required = true, readonly = true) MavenSession session diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy index ec81f225..05888ef2 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy @@ -22,7 +22,6 @@ import groovy.xml.XmlSlurper import groovy.xml.slurpersupport.GPathResult; import groovy.xml.StreamingMarkupBuilder -import org.apache.maven.artifact.repository.ArtifactRepository import org.apache.maven.doxia.siterenderer.Renderer import org.apache.maven.doxia.tools.SiteTool import org.apache.maven.execution.MavenSession @@ -187,16 +186,6 @@ class SpotBugsMojo extends AbstractMavenReport implements SpotBugsPluginsTrait { @Parameter(property = "plugin.artifacts", required = true, readonly = true) List pluginArtifacts - /** List of Remote Repositories used by the resolver. */ - @Parameter(property = "project.remoteArtifactRepositories", required = true, readonly = true) - List remoteRepositories - - /** - * The local repository, needed to download the coreplugin jar. - */ - @Parameter(property = "localRepository", required = true, readonly = true) - ArtifactRepository localRepository - /** Remote repositories which will be searched for the coreplugin jar. */ @Parameter(property = "project.remoteArtifactRepositories", required = true, readonly = true) List remoteArtifactRepositories diff --git a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsPluginsTrait.groovy b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsPluginsTrait.groovy index 24acd649..146c22c2 100644 --- a/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsPluginsTrait.groovy +++ b/src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsPluginsTrait.groovy @@ -16,7 +16,6 @@ package org.codehaus.mojo.spotbugs import org.apache.maven.artifact.Artifact -import org.apache.maven.artifact.repository.ArtifactRepository import org.apache.maven.plugin.logging.Log import org.apache.maven.project.ProjectBuildingRequest @@ -37,8 +36,6 @@ trait SpotBugsPluginsTrait { // classes implement them with implicitly generated property getters abstract ArtifactResolver getArtifactResolver() abstract RepositorySystem getFactory() - abstract List getRemoteRepositories() - abstract ArtifactRepository getLocalRepository() abstract File getSpotbugsXmlOutputDirectory() abstract Log getLog() abstract ResourceManager getResourceManager() @@ -89,10 +86,10 @@ trait SpotBugsPluginsTrait { Artifact pomArtifact - ProjectBuildingRequest configuration = session.getProjectBuildingRequest() + ProjectBuildingRequest projectBuildingRequest = session.getProjectBuildingRequest() log.debug(" Session is: " + session.toString()) - configuration.setRemoteRepositories(this.remoteRepositories) - configuration.setLocalRepository(this.localRepository) + projectBuildingRequest.setRemoteRepositories(session.getCurrentProject().getRemoteArtifactRepositories()) + projectBuildingRequest.setLocalRepository(session.getLocalRepository()) plugins.each() { plugin -> @@ -107,7 +104,7 @@ trait SpotBugsPluginsTrait { log.debug("pomArtifact is ${pomArtifact} ****** groupId is ${pomArtifact['groupId']} ****** artifactId is ${pomArtifact['artifactId']} ****** version is ${pomArtifact['version']} ****** type is ${pomArtifact['type']} ****** classfier is ${pomArtifact['classifier']}") } - pomArtifact = artifactResolver.resolveArtifact(configuration, pomArtifact).getArtifact() + pomArtifact = artifactResolver.resolveArtifact(projectBuildingRequest, pomArtifact).getArtifact() urlPlugins += resourceHelper.getResourceFile(pomArtifact.file.absolutePath).absolutePath + ((plugin == plugins[plugins.size() - 1]) ? "" : File.pathSeparator) }