Class 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

      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 banMavenDefaults  
      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.codehaus.plexus.PlexusContainer container  
      private org.apache.maven.lifecycle.DefaultLifecycles defaultLifeCycles  
      private ExpressionEvaluator evaluator  
      private org.apache.maven.artifact.factory.ArtifactFactory factory
      The factory.
      private java.util.Collection<org.apache.maven.lifecycle.Lifecycle> lifecycles
      The lifecycles.
      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.project.MavenProject project  
      private org.eclipse.aether.RepositorySystem repositorySystem  
      private org.apache.maven.rtinfo.RuntimeInformation runtimeInformation  
      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​(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

      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()
      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 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<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 parents
      private 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.
      private java.util.Set<org.apache.maven.model.Plugin> getBoundPlugins​(org.apache.maven.project.MavenProject project, java.lang.String phases)
      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.
      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.Profile profile)  
      private void getProfilePlugins​(java.util.List<PluginWrapper> plugins, 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.Profile profile)  
      private void getReportingPlugins​(java.util.List<PluginWrapper> plugins, org.apache.maven.model.Model model)  
      private void handleBanMessages​(java.lang.StringBuilder newMsg)  
      private void handleMessagesToTheUser​(org.apache.maven.project.MavenProject project, java.util.List<org.apache.maven.model.Plugin> failures)  
      boolean hasValidVersionSpecified​(org.apache.maven.model.Plugin source, java.util.List<PluginWrapper> pluginWrappers)
      Checks for valid version specified.
      boolean isBanSnapshots()
      Checks if is ban snapshots.
      private boolean isMatchingPlugin​(org.apache.maven.model.Plugin source, PluginWrapper plugin)  
      private boolean isSnapshot​(java.lang.String baseVersion)
      Checks if is snapshot.
      private boolean isValidVersion​(java.lang.String version)  
      private org.apache.maven.model.Plugin parsePluginString​(java.lang.String pluginString, java.lang.String field)
      Helper method to parse and inject a Plugin.
      (package private) 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.
      void setBanLatest​(boolean banLatest)
      Sets the ban latest.
      void setBanRelease​(boolean banRelease)
      Sets the ban release.
      void setBanSnapshots​(boolean banSnapshots)
      Sets the ban snapshots.
      void setBanTimestamps​(boolean banTimestamps)
      Sets the ban timestamps.
      java.lang.String toString()  
      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)
      Verify plugin.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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.
      • banMavenDefaults

        private boolean banMavenDefaults
        Since:
        3.0.0
      • 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
      • 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.
      • pluginManager

        private final org.apache.maven.plugin.PluginManager pluginManager
        The plugin manager.
      • factory

        private final org.apache.maven.artifact.factory.ArtifactFactory factory
        The factory.
      • repositorySystem

        private final org.eclipse.aether.RepositorySystem repositorySystem
      • session

        private final org.apache.maven.execution.MavenSession session
        The session.
      • 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
      • container

        private final org.codehaus.plexus.PlexusContainer container
    • Constructor Detail

      • 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 Detail

      • execute

        public void execute()
                     throws EnforcerRuleException
        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 class AbstractEnforcerRule
        Throws:
        EnforcerRuleException - the enforcer rule exception
        EnforcerRuleError - in order to brake a build immediately
      • handleMessagesToTheUser

        private void handleMessagesToTheUser​(org.apache.maven.project.MavenProject project,
                                             java.util.List<org.apache.maven.model.Plugin> failures)
                                      throws EnforcerRuleException
        Throws:
        EnforcerRuleException
      • handleBanMessages

        private void handleBanMessages​(java.lang.StringBuilder newMsg)
      • removeUncheckedPlugins

        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 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 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 - a new collections
        uncheckedPluginsList - a list to merge
        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 EnforcerRuleError
        Add the additional plugins if they don't exist yet.
        Parameters:
        existing - the existing plugins
        additional - the additional plugins
        Returns:
        the additional and existing plugins
        Throws:
        EnforcerRuleError - the enforcer error
      • parsePluginString

        private org.apache.maven.model.Plugin parsePluginString​(java.lang.String pluginString,
                                                                java.lang.String field)
                                                         throws EnforcerRuleError
        Helper method to parse and inject a Plugin.
        Parameters:
        pluginString - a plugin description to parse
        field - a source of pluginString
        Returns:
        the prepared plugin
        Throws:
        EnforcerRuleError
      • 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

        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 lookup
        project - project to search
        Returns:
        matching plugin, null if not found.
        Throws:
        EnforcerRuleException
      • getBoundPlugins

        private java.util.Set<org.apache.maven.model.Plugin> getBoundPlugins​(org.apache.maven.project.MavenProject project,
                                                                             java.lang.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 project
        phases - the phases
        Returns:
        the bound plugins
        Throws:
        org.apache.maven.plugin.PluginNotFoundException - the plugin not found exception
        org.apache.maven.lifecycle.LifecycleExecutionException - the lifecycle execution exception
      • hasValidVersionSpecified

        public boolean hasValidVersionSpecified​(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:
        source - the source
        pluginWrappers - 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

        private 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 project
        lifecycle - the lifecycle
        Returns:
        the all plugins
        Throws:
        org.apache.maven.plugin.PluginNotFoundException - the plugin not found exception
        org.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 exception
        org.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 project
        lifecycle - the lifecycle
        Returns:
        the map
        Throws:
        org.apache.maven.lifecycle.LifecycleExecutionException - the lifecycle execution exception
        org.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 project
        role - the role
        roleHint - the role hint
        settings - the settings
        localRepository - the local repository
        Returns:
        the object
        Throws:
        org.apache.maven.lifecycle.LifecycleExecutionException - the lifecycle execution exception
        org.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 plugin
        project - the project
        settings - the settings
        localRepository - the local repository
        Throws:
        org.apache.maven.lifecycle.LifecycleExecutionException - the lifecycle execution exception
        org.apache.maven.plugin.PluginNotFoundException - the plugin not found exception
      • getAllPluginEntries

        private 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 parents
        Parameters:
        project - the project
        Returns:
        the all plugin entries wrapped in a PluginWrapper Object
      • 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.Profile profile)
      • getProfileReportingPlugins

        private void getProfileReportingPlugins​(java.util.List<PluginWrapper> plugins,
                                                org.apache.maven.model.Profile profile)
      • getProfilePlugins

        private void getProfilePlugins​(java.util.List<PluginWrapper> plugins,
                                       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)
      • 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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object