Class DependencyConvergence

  • All Implemented Interfaces:
    EnforcerRule

    public class DependencyConvergence
    extends java.lang.Object
    implements EnforcerRule
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.codehaus.plexus.i18n.I18N i18n  
      private static org.apache.maven.plugin.logging.Log log  
      private boolean uniqueVersions  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String buildConvergenceErrorMsg​(java.util.List<org.apache.maven.shared.dependency.graph.DependencyNode> nodeList)  
      private java.lang.StringBuilder buildTreeString​(org.apache.maven.shared.dependency.graph.DependencyNode node)  
      void execute​(EnforcerRuleHelper helper)
      This is the interface into the rule.
      java.lang.String getCacheId()
      If your rule is cacheable, you must return a unique id when parameters or conditions change that would cause the result to be different.
      private java.util.List<java.lang.String> getConvergenceErrorMsgs​(java.util.List<java.util.List<org.apache.maven.shared.dependency.graph.DependencyNode>> errors)  
      private java.lang.String getFullArtifactName​(org.apache.maven.artifact.Artifact artifact)  
      private org.apache.maven.shared.dependency.graph.DependencyNode getNode​(EnforcerRuleHelper helper)
      Uses the EnforcerRuleHelper to populate the values of the DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector) factory method.
      boolean isCacheable()
      This tells the system if the results are cacheable at all.
      boolean isResultValid​(EnforcerRule rule)
      If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to allow double checking of the results.
      void setUniqueVersions​(boolean uniqueVersions)  
      • Methods inherited from class java.lang.Object

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

      • log

        private static org.apache.maven.plugin.logging.Log log
      • i18n

        private static org.codehaus.plexus.i18n.I18N i18n
      • uniqueVersions

        private boolean uniqueVersions
    • Constructor Detail

      • DependencyConvergence

        public DependencyConvergence()
    • Method Detail

      • setUniqueVersions

        public void setUniqueVersions​(boolean uniqueVersions)
      • getNode

        private org.apache.maven.shared.dependency.graph.DependencyNode getNode​(EnforcerRuleHelper helper)
                                                                         throws EnforcerRuleException
        Uses the EnforcerRuleHelper to populate the values of the DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector) factory method.
        This method simply exists to hide all the ugly lookup that the EnforcerRuleHelper has to do.
        Parameters:
        helper -
        Returns:
        a Dependency Node which is the root of the project's dependency tree
        Throws:
        EnforcerRuleException
      • 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.
        Specified by:
        execute in interface EnforcerRule
        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
      • getFullArtifactName

        private java.lang.String getFullArtifactName​(org.apache.maven.artifact.Artifact artifact)
      • buildTreeString

        private java.lang.StringBuilder buildTreeString​(org.apache.maven.shared.dependency.graph.DependencyNode node)
      • getConvergenceErrorMsgs

        private java.util.List<java.lang.String> getConvergenceErrorMsgs​(java.util.List<java.util.List<org.apache.maven.shared.dependency.graph.DependencyNode>> errors)
      • buildConvergenceErrorMsg

        private java.lang.String buildConvergenceErrorMsg​(java.util.List<org.apache.maven.shared.dependency.graph.DependencyNode> nodeList)
      • getCacheId

        public java.lang.String getCacheId()
        If your rule is cacheable, you must return a unique id when parameters or conditions change that would cause the result to be different. Multiple cached results are stored based on their id. The easiest way to do this is to return a hash computed from the values of your parameters. If your rule is not cacheable, then the result here is not important, you may return anything.
        Specified by:
        getCacheId in interface EnforcerRule
        Returns:
        id to be used by the enforcer to determine uniqueness of cache results. The ids only need to be unique within a given rule implementation as the full key will be [classname]-[id]
      • isCacheable

        public boolean isCacheable()
        This tells the system if the results are cacheable at all. Keep in mind that during forked builds and other things, a given rule may be executed more than once for the same project. This means that even things that change from project to project may still be cacheable in certain instances.
        Specified by:
        isCacheable in interface EnforcerRule
        Returns:
        true if rule is cacheable
      • isResultValid

        public boolean isResultValid​(EnforcerRule rule)
        If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes the results of objects returned by the helper need to be queried. You may for example, store certain objects in your rule and then query them later.
        Specified by:
        isResultValid in interface EnforcerRule
        Parameters:
        rule -
        Returns:
        true if the stored results are valid for the same id.