Class RequirePluginVersions
- java.lang.Object
-
- org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
-
- org.apache.maven.plugins.enforcer.AbstractNonCacheableEnforcerRule
-
- org.apache.maven.plugins.enforcer.RequirePluginVersions
-
- All Implemented Interfaces:
EnforcerRule
,EnforcerRule2
public class RequirePluginVersions extends AbstractNonCacheableEnforcerRule
This rule will enforce that all plugins specified in the poms have a version declared.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
additionalPlugins
Additional plugins to enforce have versions.private boolean
banLatest
Don't allow the LATEST identifier.private boolean
banRelease
Don't allow the RELEASE identifier.private boolean
banSnapshots
Don't allow snapshot plugins.private boolean
banTimestamps
Don't allow timestamp snapshot plugins.private org.apache.maven.artifact.factory.ArtifactFactory
factory
The factory.private EnforcerRuleHelper
helper
private java.util.Collection<org.apache.maven.lifecycle.Lifecycle>
lifecycles
The lifecycles.private org.apache.maven.plugin.logging.Log
log
The log.private java.lang.String
phases
The comma separated list of phases that should be used to find lifecycle plugin bindings.private java.util.Map<java.lang.String,org.apache.maven.lifecycle.Lifecycle>
phaseToLifecycleMap
The phase to lifecycle map.private org.apache.maven.plugin.PluginManager
pluginManager
The plugin manager.private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver
resolver
The resolver.private org.apache.maven.execution.MavenSession
session
The session.private java.lang.String
unCheckedPluginList
Same as unCheckedPlugins but as a comma list to better support properties.private java.util.List<java.lang.String>
unCheckedPlugins
Plugins to skip for version enforcement.private EnforcerRuleUtils
utils
The utils.
-
Constructor Summary
Constructors Constructor Description RequirePluginVersions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<org.apache.maven.model.Plugin>
addAdditionalPlugins(java.util.Set<org.apache.maven.model.Plugin> existing, java.util.List<java.lang.String> additional)
Add the additional plugins if they don't exist yet.private void
addPluginsInProfiles(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
java.util.Collection<java.lang.String>
combineUncheckedPlugins(java.util.Collection<java.lang.String> uncheckedPlugins, java.lang.String uncheckedPluginsList)
Combines the old Collection with the new comma separated list.void
execute(EnforcerRuleHelper helper)
This is the interface into the rule.protected org.apache.maven.model.Plugin
findCurrentPlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest)
Given a plugin, this will retrieve the matching plugin artifact from the model.private java.lang.Object
findExtension(org.apache.maven.project.MavenProject project, java.lang.String role, java.lang.String roleHint, org.apache.maven.settings.Settings settings, org.apache.maven.artifact.repository.ArtifactRepository localRepository)
Find extension.private java.util.Map<java.lang.String,java.lang.String>
findMappingsForLifecycle(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle)
Find mappings for lifecycle.private java.util.List<java.lang.String>
findOptionalMojosForLifecycle(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle)
Find optional mojos for lifecycle.java.util.List<java.lang.String>
getAdditionalPlugins()
protected java.util.List<PluginWrapper>
getAllPluginEntries(org.apache.maven.project.MavenProject project)
Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and profile.reporting in this project and all parentsprivate java.util.Set<org.apache.maven.model.Plugin>
getAllPlugins(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle)
Gets the all plugins.protected java.util.Set<org.apache.maven.model.Plugin>
getBoundPlugins(org.apache.maven.lifecycle.LifecycleExecutor life, org.apache.maven.project.MavenProject project, java.lang.String thePhases)
Gets the plugins that are bound to the defined phases.private org.apache.maven.lifecycle.Lifecycle
getLifecycleForPhase(java.lang.String phase)
Gets the lifecycle for phase.private void
getOriginalModelFromAllParents(java.util.List<org.apache.maven.model.Model> models, java.util.List<org.apache.maven.project.MavenProject> sortedProjects)
java.lang.String
getPhases()
java.util.Map<java.lang.String,org.apache.maven.lifecycle.Lifecycle>
getPhaseToLifecycleMap()
Gets the phase to lifecycle map.private void
getPluginManagementPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
private void
getPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
private void
getProfilePluginManagementPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
private void
getProfilePlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
java.util.Set<org.apache.maven.model.Plugin>
getProfilePlugins(org.apache.maven.project.MavenProject project)
Finds the plugins that are listed in active profiles.private void
getProfileReportingPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
private void
getReportingPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
java.util.List<java.lang.String>
getUnCheckedPlugins()
protected EnforcerRuleUtils
getUtils()
Gets the utils.private void
handleBanMessages(java.lang.StringBuilder newMsg)
private void
handleMessagesToTheUser(org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest, java.util.List<org.apache.maven.model.Plugin> failures)
protected boolean
hasValidVersionSpecified(EnforcerRuleHelper helper, org.apache.maven.model.Plugin source, java.util.List<PluginWrapper> pluginWrappers)
Checks for valid version specified.protected boolean
isBanLatest()
Checks if is ban latest.protected boolean
isBanRelease()
Checks if is ban release.boolean
isBanSnapshots()
Checks if is ban snapshots.boolean
isBanTimestamps()
Checks if is ban timestamps.private boolean
isMatchingPlugin(org.apache.maven.model.Plugin source, PluginWrapper plugin)
protected boolean
isSnapshot(java.lang.String baseVersion)
Checks if is snapshot.private boolean
isValidVersion(java.lang.String version)
protected org.apache.maven.model.Plugin
parsePluginString(java.lang.String pluginString, java.lang.String field)
Helper method to parse and inject a Plugin.java.util.Set<org.apache.maven.model.Plugin>
removeUncheckedPlugins(java.util.Collection<java.lang.String> uncheckedPlugins, java.util.Set<org.apache.maven.model.Plugin> plugins)
Remove the plugins that the user doesn't want to check.protected org.apache.maven.model.Plugin
resolvePlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest)
Resolve plugin.void
setAdditionalPlugins(java.util.List<java.lang.String> additionalPlugins)
protected void
setBanLatest(boolean theBanLatest)
Sets the ban latest.protected void
setBanRelease(boolean theBanRelease)
Sets the ban release.void
setBanSnapshots(boolean theBanSnapshots)
Sets the ban snapshots.void
setBanTimestamps(boolean theBanTimestamps)
Sets the ban timestamps.void
setPhases(java.lang.String phases)
void
setUnCheckedPlugins(java.util.List<java.lang.String> unCheckedPlugins)
protected void
setUtils(EnforcerRuleUtils theUtils)
Sets the utils.private org.apache.maven.plugin.descriptor.PluginDescriptor
verifyPlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.MavenProject project, org.apache.maven.settings.Settings settings, org.apache.maven.artifact.repository.ArtifactRepository localRepository)
Verify plugin.-
Methods inherited from class org.apache.maven.plugins.enforcer.AbstractNonCacheableEnforcerRule
getCacheId, isCacheable, isResultValid
-
Methods inherited from class org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
getLevel, getMessage, setLevel, setMessage
-
-
-
-
Field Detail
-
helper
private EnforcerRuleHelper helper
-
banLatest
private boolean banLatest
Don't allow the LATEST identifier.
-
banRelease
private boolean banRelease
Don't allow the RELEASE identifier.
-
banSnapshots
private boolean banSnapshots
Don't allow snapshot plugins.
-
banTimestamps
private boolean banTimestamps
Don't allow timestamp snapshot plugins.
-
phases
private java.lang.String phases
The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is "clean,deploy,site".
-
additionalPlugins
private java.util.List<java.lang.String> additionalPlugins
Additional plugins to enforce have versions. These are plugins that may not be in the poms but are used anyway, like help, eclipse etc.
The plugins should be specified in the form:group:artifactId
.
-
unCheckedPlugins
private java.util.List<java.lang.String> unCheckedPlugins
Plugins to skip for version enforcement. The plugins should be specified in the form:group:artifactId
. NOTE: This is deprecated, use unCheckedPluginList instead.
-
unCheckedPluginList
private java.lang.String unCheckedPluginList
Same as unCheckedPlugins but as a comma list to better support properties. Sample form:group:artifactId,group2:artifactId2
- Since:
- 1.0-beta-1
-
pluginManager
private org.apache.maven.plugin.PluginManager pluginManager
The plugin manager.
-
phaseToLifecycleMap
private java.util.Map<java.lang.String,org.apache.maven.lifecycle.Lifecycle> phaseToLifecycleMap
The phase to lifecycle map.
-
lifecycles
private java.util.Collection<org.apache.maven.lifecycle.Lifecycle> lifecycles
The lifecycles.
-
factory
private org.apache.maven.artifact.factory.ArtifactFactory factory
The factory.
-
resolver
private org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver resolver
The resolver.
-
log
private org.apache.maven.plugin.logging.Log log
The log.
-
session
private org.apache.maven.execution.MavenSession session
The session.
-
utils
private EnforcerRuleUtils utils
The utils.
-
-
Method Detail
-
execute
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
Description copied from interface:EnforcerRule
This is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag if it should stop or just log the message as a warning.- Parameters:
helper
- The helper provides access to the log, MavenSession and has helpers to get common components. It is also able to lookup components by class name.- Throws:
EnforcerRuleException
- the enforcer rule exception
-
handleMessagesToTheUser
private void handleMessagesToTheUser(org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest, java.util.List<org.apache.maven.model.Plugin> failures) throws EnforcerRuleException
- Throws:
EnforcerRuleException
-
handleBanMessages
private void handleBanMessages(java.lang.StringBuilder newMsg)
-
removeUncheckedPlugins
public java.util.Set<org.apache.maven.model.Plugin> removeUncheckedPlugins(java.util.Collection<java.lang.String> uncheckedPlugins, java.util.Set<org.apache.maven.model.Plugin> plugins) throws org.apache.maven.plugin.MojoExecutionException
Remove the plugins that the user doesn't want to check.- Parameters:
uncheckedPlugins
-plugins
-- Returns:
- The plugins which have been removed.
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
combineUncheckedPlugins
public java.util.Collection<java.lang.String> combineUncheckedPlugins(java.util.Collection<java.lang.String> uncheckedPlugins, java.lang.String uncheckedPluginsList)
Combines the old Collection with the new comma separated list.- Parameters:
uncheckedPlugins
-uncheckedPluginsList
-- Returns:
- List of unchecked plugins.
-
addAdditionalPlugins
public java.util.Set<org.apache.maven.model.Plugin> addAdditionalPlugins(java.util.Set<org.apache.maven.model.Plugin> existing, java.util.List<java.lang.String> additional) throws org.apache.maven.plugin.MojoExecutionException
Add the additional plugins if they don't exist yet.- Parameters:
existing
- the existingadditional
- the additional- Returns:
- the sets the
- Throws:
org.apache.maven.plugin.MojoExecutionException
- the mojo execution exception
-
parsePluginString
protected org.apache.maven.model.Plugin parsePluginString(java.lang.String pluginString, java.lang.String field) throws org.apache.maven.plugin.MojoExecutionException
Helper method to parse and inject a Plugin.- Parameters:
pluginString
-field
-- Returns:
- the plugin
- Throws:
org.apache.maven.plugin.MojoExecutionException
-
getProfilePlugins
public java.util.Set<org.apache.maven.model.Plugin> getProfilePlugins(org.apache.maven.project.MavenProject project)
Finds the plugins that are listed in active profiles.- Parameters:
project
- the project- Returns:
- the profile plugins
-
findCurrentPlugin
protected org.apache.maven.model.Plugin findCurrentPlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest)
Given a plugin, this will retrieve the matching plugin artifact from the model.- Parameters:
plugin
- plugin to lookupproject
- project to search- Returns:
- matching plugin,
null
if not found.
-
resolvePlugin
protected org.apache.maven.model.Plugin resolvePlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest)
Resolve plugin.- Parameters:
plugin
- the pluginproject
- the project- Returns:
- the plugin
-
getBoundPlugins
protected java.util.Set<org.apache.maven.model.Plugin> getBoundPlugins(org.apache.maven.lifecycle.LifecycleExecutor life, org.apache.maven.project.MavenProject project, java.lang.String thePhases) throws org.apache.maven.plugin.PluginNotFoundException, org.apache.maven.lifecycle.LifecycleExecutionException, java.lang.IllegalAccessException
Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase later than the plugin is executing.- Parameters:
life
- the lifeproject
- the projectthePhases
- the the phases- Returns:
- the bound plugins
- Throws:
org.apache.maven.plugin.PluginNotFoundException
- the plugin not found exceptionorg.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exceptionjava.lang.IllegalAccessException
- the illegal access exception
-
hasValidVersionSpecified
protected boolean hasValidVersionSpecified(EnforcerRuleHelper helper, org.apache.maven.model.Plugin source, java.util.List<PluginWrapper> pluginWrappers)
Checks for valid version specified. Checks to see if the version is specified for the plugin. Can optionally ban "RELEASE" or "LATEST" even if specified.- Parameters:
helper
- the helpersource
- the sourcepluginWrappers
- the plugins- Returns:
- true, if successful
-
isValidVersion
private boolean isValidVersion(java.lang.String version)
-
isMatchingPlugin
private boolean isMatchingPlugin(org.apache.maven.model.Plugin source, PluginWrapper plugin)
-
isSnapshot
protected boolean isSnapshot(java.lang.String baseVersion)
Checks if is snapshot.- Parameters:
baseVersion
- the base version- Returns:
- true, if is snapshot
-
getAllPlugins
private java.util.Set<org.apache.maven.model.Plugin> getAllPlugins(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle) throws org.apache.maven.plugin.PluginNotFoundException, org.apache.maven.lifecycle.LifecycleExecutionException
Gets the all plugins.- Parameters:
project
- the projectlifecycle
- the lifecycle- Returns:
- the all plugins
- Throws:
org.apache.maven.plugin.PluginNotFoundException
- the plugin not found exceptionorg.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exception
-
getPhaseToLifecycleMap
public java.util.Map<java.lang.String,org.apache.maven.lifecycle.Lifecycle> getPhaseToLifecycleMap() throws org.apache.maven.lifecycle.LifecycleExecutionException
Gets the phase to lifecycle map.- Returns:
- the phase to lifecycle map
- Throws:
org.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exception
-
getLifecycleForPhase
private org.apache.maven.lifecycle.Lifecycle getLifecycleForPhase(java.lang.String phase) throws org.apache.maven.BuildFailureException, org.apache.maven.lifecycle.LifecycleExecutionException
Gets the lifecycle for phase.- Parameters:
phase
- the phase- Returns:
- the lifecycle for phase
- Throws:
org.apache.maven.BuildFailureException
- the build failure exceptionorg.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exception
-
findMappingsForLifecycle
private java.util.Map<java.lang.String,java.lang.String> findMappingsForLifecycle(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle) throws org.apache.maven.lifecycle.LifecycleExecutionException, org.apache.maven.plugin.PluginNotFoundException
Find mappings for lifecycle.- Parameters:
project
- the projectlifecycle
- the lifecycle- Returns:
- the map
- Throws:
org.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exceptionorg.apache.maven.plugin.PluginNotFoundException
- the plugin not found exception
-
findOptionalMojosForLifecycle
private java.util.List<java.lang.String> findOptionalMojosForLifecycle(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle) throws org.apache.maven.lifecycle.LifecycleExecutionException, org.apache.maven.plugin.PluginNotFoundException
Find optional mojos for lifecycle.- Parameters:
project
- the projectlifecycle
- the lifecycle- Returns:
- the list
- Throws:
org.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exceptionorg.apache.maven.plugin.PluginNotFoundException
- the plugin not found exception
-
findExtension
private java.lang.Object findExtension(org.apache.maven.project.MavenProject project, java.lang.String role, java.lang.String roleHint, org.apache.maven.settings.Settings settings, org.apache.maven.artifact.repository.ArtifactRepository localRepository) throws org.apache.maven.lifecycle.LifecycleExecutionException, org.apache.maven.plugin.PluginNotFoundException
Find extension.- Parameters:
project
- the projectrole
- the roleroleHint
- the role hintsettings
- the settingslocalRepository
- the local repository- Returns:
- the object
- Throws:
org.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exceptionorg.apache.maven.plugin.PluginNotFoundException
- the plugin not found exception
-
verifyPlugin
private org.apache.maven.plugin.descriptor.PluginDescriptor verifyPlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.MavenProject project, org.apache.maven.settings.Settings settings, org.apache.maven.artifact.repository.ArtifactRepository localRepository) throws org.apache.maven.lifecycle.LifecycleExecutionException, org.apache.maven.plugin.PluginNotFoundException
Verify plugin.- Parameters:
plugin
- the pluginproject
- the projectsettings
- the settingslocalRepository
- the local repository- Returns:
- the plugin descriptor
- Throws:
org.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exceptionorg.apache.maven.plugin.PluginNotFoundException
- the plugin not found exception
-
getAllPluginEntries
protected java.util.List<PluginWrapper> getAllPluginEntries(org.apache.maven.project.MavenProject project) throws org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException, java.io.IOException, org.codehaus.plexus.util.xml.pull.XmlPullParserException
Gets all plugin entries in build.plugins, build.pluginManagement.plugins, profile.build.plugins, reporting and profile.reporting in this project and all parents- Parameters:
project
- the project- Returns:
- the all plugin entries wrapped in a PluginWrapper Object
- Throws:
org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException
- the artifact resolution exceptionjava.io.IOException
- Signals that an I/O exception has occurred.org.codehaus.plexus.util.xml.pull.XmlPullParserException
- the xml pull parser exception
-
getOriginalModelFromAllParents
private void getOriginalModelFromAllParents(java.util.List<org.apache.maven.model.Model> models, java.util.List<org.apache.maven.project.MavenProject> sortedProjects)
-
addPluginsInProfiles
private void addPluginsInProfiles(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
-
getProfilePluginManagementPlugins
private void getProfilePluginManagementPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
-
getProfileReportingPlugins
private void getProfileReportingPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
-
getProfilePlugins
private void getProfilePlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model, org.apache.maven.model.Profile profile)
-
getPlugins
private void getPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
-
getPluginManagementPlugins
private void getPluginManagementPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
-
getReportingPlugins
private void getReportingPlugins(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)
-
isBanLatest
protected boolean isBanLatest()
Checks if is ban latest.- Returns:
- the banLatest
-
setBanLatest
protected void setBanLatest(boolean theBanLatest)
Sets the ban latest.- Parameters:
theBanLatest
- the banLatest to set
-
isBanRelease
protected boolean isBanRelease()
Checks if is ban release.- Returns:
- the banRelease
-
setBanRelease
protected void setBanRelease(boolean theBanRelease)
Sets the ban release.- Parameters:
theBanRelease
- the banRelease to set
-
getUtils
protected EnforcerRuleUtils getUtils()
Gets the utils.- Returns:
- the utils
-
setUtils
protected void setUtils(EnforcerRuleUtils theUtils)
Sets the utils.- Parameters:
theUtils
- the utils to set
-
isBanSnapshots
public boolean isBanSnapshots()
Checks if is ban snapshots.- Returns:
- the banSnapshots
-
setBanSnapshots
public void setBanSnapshots(boolean theBanSnapshots)
Sets the ban snapshots.- Parameters:
theBanSnapshots
- the banSnapshots to set
-
isBanTimestamps
public boolean isBanTimestamps()
Checks if is ban timestamps.- Returns:
- the banTimestamps
-
setBanTimestamps
public void setBanTimestamps(boolean theBanTimestamps)
Sets the ban timestamps.- Parameters:
theBanTimestamps
- the banTimestamps to set
-
getUnCheckedPlugins
public java.util.List<java.lang.String> getUnCheckedPlugins()
-
setUnCheckedPlugins
public void setUnCheckedPlugins(java.util.List<java.lang.String> unCheckedPlugins)
-
setPhases
public final void setPhases(java.lang.String phases)
-
getPhases
public final java.lang.String getPhases()
-
setAdditionalPlugins
public final void setAdditionalPlugins(java.util.List<java.lang.String> additionalPlugins)
-
getAdditionalPlugins
public final java.util.List<java.lang.String> getAdditionalPlugins()
-
-