Skip to content

Commit

Permalink
Merge pull request spotbugs#896 from hazendaz/maven-api
Browse files Browse the repository at this point in the history
Use maven session api for local and remote repositories
  • Loading branch information
hazendaz authored Oct 20, 2024
2 parents 173de30 + 3c10716 commit 88e4540
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsGui.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/main/groovy/org/codehaus/mojo/spotbugs/SpotBugsMojo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 ->

Expand All @@ -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)
}
Expand Down

0 comments on commit 88e4540

Please sign in to comment.