Package org.apache.maven.enforcer.rules
Class RequirePluginVersions
java.lang.Object
org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
org.apache.maven.enforcer.rules.AbstractStandardEnforcerRule
org.apache.maven.enforcer.rules.RequirePluginVersions
- All Implemented Interfaces:
EnforcerRuleBase
@Named("requirePluginVersions")
public final class RequirePluginVersions
extends AbstractStandardEnforcerRule
This rule will enforce that all plugins specified in the poms have a version declared.
-
Field Summary
FieldsModifier and TypeFieldDescriptionAdditional plugins to enforce have versions.private boolean
Don't allow the LATEST identifier.private boolean
private boolean
Don't allow the RELEASE identifier.private boolean
Don't allow snapshot plugins.private boolean
Don't allow timestamp snapshot plugins.private final org.codehaus.plexus.PlexusContainer
private final org.apache.maven.lifecycle.DefaultLifecycles
private final ExpressionEvaluator
private final org.apache.maven.artifact.factory.ArtifactFactory
The factory.private Collection
<org.apache.maven.lifecycle.Lifecycle> The lifecycles.private String
The comma separated list of phases that should be used to find lifecycle plugin bindings.The phase to lifecycle map.private final org.apache.maven.plugin.PluginManager
The plugin manager.private final org.apache.maven.project.MavenProject
private final org.eclipse.aether.RepositorySystem
private final org.apache.maven.rtinfo.RuntimeInformation
private final org.apache.maven.execution.MavenSession
The session.private String
Same as unCheckedPlugins but as a comma list to better support properties.Plugins to skip for version enforcement.private final EnforcerRuleUtils
The utils. -
Constructor Summary
ConstructorsConstructorDescriptionRequirePluginVersions
(org.apache.maven.plugin.PluginManager pluginManager, org.apache.maven.artifact.factory.ArtifactFactory factory, org.eclipse.aether.RepositorySystem repositorySystem, org.apache.maven.execution.MavenSession session, EnforcerRuleUtils utils, org.apache.maven.rtinfo.RuntimeInformation runtimeInformation, org.apache.maven.lifecycle.DefaultLifecycles defaultLifeCycles, org.apache.maven.project.MavenProject project, ExpressionEvaluator evaluator, org.codehaus.plexus.PlexusContainer container) -
Method Summary
Modifier and TypeMethodDescriptionSet
<org.apache.maven.model.Plugin> addAdditionalPlugins
(Set<org.apache.maven.model.Plugin> existing, List<String> additional) Add the additional plugins if they don't exist yet.private void
addPluginsInProfiles
(List<PluginWrapper> plugins, org.apache.maven.model.Model model) combineUncheckedPlugins
(Collection<String> uncheckedPlugins, String uncheckedPluginsList) Combines the old Collection with the new comma separated list.void
execute()
This is the interface into the rule.private org.apache.maven.model.Plugin
findCurrentPlugin
(org.apache.maven.model.Plugin plugin, org.apache.maven.project.MavenProject project) Given a plugin, this will retrieve the matching plugin artifact from the model.private Object
findExtension
(org.apache.maven.project.MavenProject project, String role, String roleHint, org.apache.maven.settings.Settings settings, org.apache.maven.artifact.repository.ArtifactRepository localRepository) Find extension.findMappingsForLifecycle
(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle) Find mappings for lifecycle.private 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 Set
<org.apache.maven.model.Plugin> getAllPlugins
(org.apache.maven.project.MavenProject project, org.apache.maven.lifecycle.Lifecycle lifecycle) Gets the all plugins.private Set
<org.apache.maven.model.Plugin> getBoundPlugins
(org.apache.maven.project.MavenProject project, String thePhases) Gets the plugins that are bound to the defined phases.private org.apache.maven.lifecycle.Lifecycle
getLifecycleForPhase
(String phase) Gets the lifecycle for phase.Gets the phase to lifecycle map.private void
getPluginManagementPlugins
(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private void
getPlugins
(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private void
getProfilePluginManagementPlugins
(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) private void
getProfilePlugins
(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) 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
(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) private void
getReportingPlugins
(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private void
handleBanMessages
(StringBuilder newMsg) private void
handleMessagesToTheUser
(org.apache.maven.project.MavenProject project, List<org.apache.maven.model.Plugin> failures) boolean
hasValidVersionSpecified
(org.apache.maven.model.Plugin source, List<PluginWrapper> pluginWrappers) Checks for valid version specified.boolean
Checks if is ban snapshots.private boolean
isMatchingPlugin
(org.apache.maven.model.Plugin source, PluginWrapper plugin) private boolean
isSnapshot
(String baseVersion) Checks if is snapshot.private boolean
isValidVersion
(String version) private org.apache.maven.model.Plugin
parsePluginString
(String pluginString, String field) Helper method to parse and inject a Plugin.(package private) Set
<org.apache.maven.model.Plugin> removeUncheckedPlugins
(Collection<String> uncheckedPlugins, Set<org.apache.maven.model.Plugin> plugins) Remove the plugins that the user doesn't want to check.void
setBanLatest
(boolean theBanLatest) Sets the ban latest.void
setBanRelease
(boolean theBanRelease) Sets the ban release.void
setBanSnapshots
(boolean theBanSnapshots) Sets the ban snapshots.void
setBanTimestamps
(boolean theBanTimestamps) Sets the ban timestamps.toString()
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.enforcer.rules.AbstractStandardEnforcerRule
formatLocation, getMessage, setMessage
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRule
getCacheId, getLevel
Methods inherited from class org.apache.maven.enforcer.rule.api.AbstractEnforcerRuleBase
getLog, setLog
-
Field Details
-
banLatest
private boolean banLatestDon't allow the LATEST identifier. -
banRelease
private boolean banReleaseDon't allow the RELEASE identifier. -
banSnapshots
private boolean banSnapshotsDon't allow snapshot plugins. -
banTimestamps
private boolean banTimestampsDon't allow timestamp snapshot plugins. -
banMavenDefaults
private boolean banMavenDefaults- Since:
- 3.0.0
-
phases
The comma separated list of phases that should be used to find lifecycle plugin bindings. The default value is "clean,deploy,site". -
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
Plugins to skip for version enforcement. The plugins should be specified in the form:group:artifactId
. NOTE: This is deprecated, use unCheckedPluginList instead. -
unCheckedPluginList
Same as unCheckedPlugins but as a comma list to better support properties. Sample form:group:artifactId,group2:artifactId2
- Since:
- 1.0-beta-1
-
phaseToLifecycleMap
The phase to lifecycle map. -
lifecycles
The lifecycles. -
pluginManager
private final org.apache.maven.plugin.PluginManager pluginManagerThe plugin manager. -
factory
private final org.apache.maven.artifact.factory.ArtifactFactory factoryThe factory. -
repositorySystem
private final org.eclipse.aether.RepositorySystem repositorySystem -
session
private final org.apache.maven.execution.MavenSession sessionThe session. -
utils
The utils. -
runtimeInformation
private final org.apache.maven.rtinfo.RuntimeInformation runtimeInformation -
defaultLifeCycles
private final org.apache.maven.lifecycle.DefaultLifecycles defaultLifeCycles -
project
private final org.apache.maven.project.MavenProject project -
evaluator
-
container
private final org.codehaus.plexus.PlexusContainer container
-
-
Constructor Details
-
RequirePluginVersions
@Inject public RequirePluginVersions(org.apache.maven.plugin.PluginManager pluginManager, org.apache.maven.artifact.factory.ArtifactFactory factory, org.eclipse.aether.RepositorySystem repositorySystem, org.apache.maven.execution.MavenSession session, EnforcerRuleUtils utils, org.apache.maven.rtinfo.RuntimeInformation runtimeInformation, org.apache.maven.lifecycle.DefaultLifecycles defaultLifeCycles, org.apache.maven.project.MavenProject project, ExpressionEvaluator evaluator, org.codehaus.plexus.PlexusContainer container)
-
-
Method Details
-
execute
Description copied from class:AbstractEnforcerRule
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 and rule level if it should stop or just log the message as a warning.- Specified by:
execute
in classAbstractEnforcerRule
- Throws:
EnforcerRuleException
- the enforcer rule exception
-
handleMessagesToTheUser
private void handleMessagesToTheUser(org.apache.maven.project.MavenProject project, List<org.apache.maven.model.Plugin> failures) throws EnforcerRuleException - Throws:
EnforcerRuleException
-
handleBanMessages
-
removeUncheckedPlugins
Set<org.apache.maven.model.Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Set<org.apache.maven.model.Plugin> plugins) throws EnforcerRuleError Remove the plugins that the user doesn't want to check.- Parameters:
uncheckedPlugins
-plugins
-- Returns:
- The plugins which have been removed.
- Throws:
EnforcerRuleError
-
combineUncheckedPlugins
public Collection<String> combineUncheckedPlugins(Collection<String> uncheckedPlugins, String uncheckedPluginsList) Combines the old Collection with the new comma separated list.- Parameters:
uncheckedPlugins
- a new collectionsuncheckedPluginsList
- a list to merge- Returns:
- List of unchecked plugins.
-
addAdditionalPlugins
public Set<org.apache.maven.model.Plugin> addAdditionalPlugins(Set<org.apache.maven.model.Plugin> existing, List<String> additional) throws EnforcerRuleError Add the additional plugins if they don't exist yet.- Parameters:
existing
- the existingadditional
- the additional- Returns:
- the sets the
- Throws:
EnforcerRuleError
- the enforcer error
-
parsePluginString
private org.apache.maven.model.Plugin parsePluginString(String pluginString, String field) throws EnforcerRuleError Helper method to parse and inject a Plugin.- Parameters:
pluginString
- a plugin description to parsefield
- a source of pluginString- Returns:
- the prepared plugin
- Throws:
EnforcerRuleError
-
getProfilePlugins
public 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
private org.apache.maven.model.Plugin findCurrentPlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.MavenProject project) throws EnforcerRuleException 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. - Throws:
EnforcerRuleException
-
getBoundPlugins
private Set<org.apache.maven.model.Plugin> getBoundPlugins(org.apache.maven.project.MavenProject project, String thePhases) throws org.apache.maven.plugin.PluginNotFoundException, org.apache.maven.lifecycle.LifecycleExecutionException 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:
project
- the projectthePhases
- the phases- Returns:
- the bound plugins
- Throws:
org.apache.maven.plugin.PluginNotFoundException
- the plugin not found exceptionorg.apache.maven.lifecycle.LifecycleExecutionException
- the lifecycle execution exception
-
hasValidVersionSpecified
public boolean hasValidVersionSpecified(org.apache.maven.model.Plugin source, 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:
source
- the sourcepluginWrappers
- the plugins- Returns:
- true, if successful
-
isValidVersion
-
isMatchingPlugin
-
isSnapshot
Checks if is snapshot.- Parameters:
baseVersion
- the base version- Returns:
- true, if is snapshot
-
getAllPlugins
private 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 Map<String,org.apache.maven.lifecycle.Lifecycle> getPhaseToLifecycleMap() throws org.apache.maven.lifecycle.LifecycleExecutionExceptionGets 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(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 Map<String,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
-
findExtension
private Object findExtension(org.apache.maven.project.MavenProject project, String role, 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
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
-
addPluginsInProfiles
-
getProfilePluginManagementPlugins
private void getProfilePluginManagementPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) -
getProfileReportingPlugins
private void getProfileReportingPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) -
getProfilePlugins
-
getPlugins
-
getPluginManagementPlugins
private void getPluginManagementPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Model model) -
getReportingPlugins
-
setBanLatest
public void setBanLatest(boolean theBanLatest) Sets the ban latest.- Parameters:
theBanLatest
- the banLatest to set
-
setBanRelease
public void setBanRelease(boolean theBanRelease) Sets the ban release.- Parameters:
theBanRelease
- the banRelease 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
-
setBanTimestamps
public void setBanTimestamps(boolean theBanTimestamps) Sets the ban timestamps.- Parameters:
theBanTimestamps
- the banTimestamps to set
-
toString
-