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 booleanDon't allow the LATEST identifier.private booleanprivate booleanDon't allow the RELEASE identifier.private booleanDon't allow snapshot plugins.private booleanDon't allow timestamp snapshot plugins.private final org.codehaus.plexus.PlexusContainerprivate final org.apache.maven.lifecycle.DefaultLifecyclesprivate final ExpressionEvaluatorprivate final org.apache.maven.artifact.factory.ArtifactFactoryThe factory.private Collection<org.apache.maven.lifecycle.Lifecycle> The lifecycles.private StringThe 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.PluginManagerThe plugin manager.private final org.apache.maven.project.MavenProjectprivate final org.eclipse.aether.RepositorySystemprivate final org.apache.maven.rtinfo.RuntimeInformationprivate final org.apache.maven.execution.MavenSessionThe session.private StringSame as unCheckedPlugins but as a comma list to better support properties.Plugins to skip for version enforcement.private final EnforcerRuleUtilsThe 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 voidaddPluginsInProfiles(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.voidexecute()This is the interface into the rule.private org.apache.maven.model.PluginfindCurrentPlugin(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 ObjectfindExtension(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 phases) Gets the plugins that are bound to the defined phases.private org.apache.maven.lifecycle.LifecyclegetLifecycleForPhase(String phase) Gets the lifecycle for phase.Gets the phase to lifecycle map.private voidgetPluginManagementPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private voidgetPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private voidgetProfilePluginManagementPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) private voidgetProfilePlugins(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 voidgetProfileReportingPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Profile profile) private voidgetReportingPlugins(List<PluginWrapper> plugins, org.apache.maven.model.Model model) private voidhandleBanMessages(StringBuilder newMsg) private voidhandleMessagesToTheUser(org.apache.maven.project.MavenProject project, List<org.apache.maven.model.Plugin> failures) booleanhasValidVersionSpecified(org.apache.maven.model.Plugin source, List<PluginWrapper> pluginWrappers) Checks for valid version specified.booleanChecks if is ban snapshots.private booleanisMatchingPlugin(org.apache.maven.model.Plugin source, PluginWrapper plugin) private booleanisSnapshot(String baseVersion) Checks if is snapshot.private booleanisValidVersion(String version) private org.apache.maven.model.PluginparsePluginString(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.voidsetBanLatest(boolean banLatest) Sets the ban latest.voidsetBanRelease(boolean banRelease) Sets the ban release.voidsetBanSnapshots(boolean banSnapshots) Sets the ban snapshots.voidsetBanTimestamps(boolean banTimestamps) Sets the ban timestamps.toString()private voidverifyPlugin(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 AbstractStandardEnforcerRule
formatLocation, getMessage, setMessageMethods inherited from class AbstractEnforcerRule
getCacheId, getLevel, getRuleNameMethods inherited from class 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
-
unCheckedPlugins
-
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
-
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:AbstractEnforcerRuleThis 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:
executein 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 existing pluginsadditional- the additional plugins- Returns:
- the additional and existing plugins
- 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,
nullif not found. - Throws:
EnforcerRuleException
-
getBoundPlugins
private Set<org.apache.maven.model.Plugin> getBoundPlugins(org.apache.maven.project.MavenProject project, String phases) 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 projectphases- 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 void 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- 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 banLatest) Sets the ban latest.- Parameters:
banLatest- the banLatest to set
-
setBanRelease
public void setBanRelease(boolean banRelease) Sets the ban release.- Parameters:
banRelease- the banRelease to set
-
isBanSnapshots
public boolean isBanSnapshots()Checks if is ban snapshots.- Returns:
- the banSnapshots
-
setBanSnapshots
public void setBanSnapshots(boolean banSnapshots) Sets the ban snapshots.- Parameters:
banSnapshots- the banSnapshots to set
-
setBanTimestamps
public void setBanTimestamps(boolean banTimestamps) Sets the ban timestamps.- Parameters:
banTimestamps- the banTimestamps to set
-
toString
-