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.- Version:
- $Id: RequirePluginVersions.java 1697215 2015-08-23 16:27:17Z khmarbaise $
- Author:
- Brian Fox
-
-
Constructor Summary
Constructors Constructor Description RequirePluginVersions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<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.Collection<String>combineUncheckedPlugins(Collection<String> uncheckedPlugins, String uncheckedPluginsList)Combines the old Collection with the new comma separated list.voidexecute(EnforcerRuleHelper helper)This is the interface into the rule.protected org.apache.maven.model.PluginfindCurrentPlugin(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.List<String>getAdditionalPlugins()protected 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 parentsprotected Set<org.apache.maven.model.Plugin>getBoundPlugins(org.apache.maven.lifecycle.LifecycleExecutor life, org.apache.maven.project.MavenProject project, String thePhases)Gets the plugins that are bound to the defined phases.StringgetPhases()Map<String,org.apache.maven.lifecycle.Lifecycle>getPhaseToLifecycleMap()Gets the phase to lifecycle map.Set<org.apache.maven.model.Plugin>getProfilePlugins(org.apache.maven.project.MavenProject project)Finds the plugins that are listed in active profiles.ListgetUnCheckedPlugins()protected EnforcerRuleUtilsgetUtils()Gets the utils.protected booleanhasValidVersionSpecified(EnforcerRuleHelper helper, org.apache.maven.model.Plugin source, List<PluginWrapper> pluginWrappers)Checks for valid version specified.protected booleanisBanLatest()Checks if is ban latest.protected booleanisBanRelease()Checks if is ban release.booleanisBanSnapshots()Checks if is ban snapshots.booleanisBanTimestamps()Checks if is ban timestamps.protected booleanisSnapshot(String baseVersion)Checks if is snapshot.protected org.apache.maven.model.PluginparsePluginString(String pluginString, String field)Helper method to parse and inject a Plugin.Collection<org.apache.maven.model.Plugin>removeUncheckedPlugins(Collection<String> uncheckedPlugins, Collection<org.apache.maven.model.Plugin> plugins)Remove the plugins that the user doesn't want to check.protected org.apache.maven.model.PluginresolvePlugin(org.apache.maven.model.Plugin plugin, org.apache.maven.project.ProjectBuildingRequest projectBuildingRequest)Resolve plugin.voidsetAdditionalPlugins(List<String> additionalPlugins)protected voidsetBanLatest(boolean theBanLatest)Sets the ban latest.protected voidsetBanRelease(boolean theBanRelease)Sets the ban release.voidsetBanSnapshots(boolean theBanSnapshots)Sets the ban snapshots.voidsetBanTimestamps(boolean theBanTimestamps)Sets the ban timestamps.voidsetPhases(String phases)voidsetUnCheckedPlugins(List unCheckedPlugins)protected voidsetUtils(EnforcerRuleUtils theUtils)Sets the utils.-
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
-
-
-
-
Method Detail
-
execute
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
Description copied from interface:EnforcerRuleThis 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
-
removeUncheckedPlugins
public Collection<org.apache.maven.model.Plugin> removeUncheckedPlugins(Collection<String> uncheckedPlugins, Collection<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 Collection<String> combineUncheckedPlugins(Collection<String> uncheckedPlugins, String uncheckedPluginsList)
Combines the old Collection with the new comma separated list.- Parameters:
uncheckedPlugins-uncheckedPluginsList-- 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 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(String pluginString, 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 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,
nullif 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 Set<org.apache.maven.model.Plugin> getBoundPlugins(org.apache.maven.lifecycle.LifecycleExecutor life, org.apache.maven.project.MavenProject project, String thePhases) throws org.apache.maven.plugin.PluginNotFoundException, org.apache.maven.lifecycle.LifecycleExecutionException, 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 exceptionIllegalAccessException- the illegal access exception
-
hasValidVersionSpecified
protected boolean hasValidVersionSpecified(EnforcerRuleHelper helper, org.apache.maven.model.Plugin source, List<PluginWrapper> pluginWrappers)
Checks for valid version specified.- Parameters:
helper- the helpersource- the sourcepluginWrappers- the plugins- Returns:
- true, if successful
-
isSnapshot
protected boolean isSnapshot(String baseVersion)
Checks if is snapshot.- Parameters:
baseVersion- the base version- Returns:
- true, if is snapshot
-
getPhaseToLifecycleMap
public Map<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
-
getAllPluginEntries
protected List<PluginWrapper> getAllPluginEntries(org.apache.maven.project.MavenProject project) throws org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException, 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 exceptionIOException- Signals that an I/O exception has occurred.org.codehaus.plexus.util.xml.pull.XmlPullParserException- the xml pull parser exception
-
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 List getUnCheckedPlugins()
-
setUnCheckedPlugins
public void setUnCheckedPlugins(List unCheckedPlugins)
-
setPhases
public final void setPhases(String phases)
-
getPhases
public final String getPhases()
-
-