Class ReactorModuleConvergence

All Implemented Interfaces:
EnforcerRuleBase

@Named("reactorModuleConvergence") public final class ReactorModuleConvergence extends AbstractStandardEnforcerRule
This rule will check if a multi module build will follow the best practices.
Since:
1.4
  • Field Details

    • MODULE_TEXT

      private static final String MODULE_TEXT
      See Also:
    • ignoreModuleDependencies

      private boolean ignoreModuleDependencies
    • session

      private final org.apache.maven.execution.MavenSession session
  • Constructor Details

    • ReactorModuleConvergence

      @Inject public ReactorModuleConvergence(org.apache.maven.execution.MavenSession session)
  • Method Details

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

      private void checkParentsPartOfTheReactor(List<org.apache.maven.project.MavenProject> sortedProjects) throws EnforcerRuleException
      Throws:
      EnforcerRuleException
    • checkMissingParentsInReactor

      private void checkMissingParentsInReactor(List<org.apache.maven.project.MavenProject> sortedProjects) throws EnforcerRuleException
      Convenience method to create a user readable message.
      Parameters:
      sortedProjects - The list of reactor projects.
      Throws:
      EnforcerRuleException - In case of a violation.
    • checkDependenciesWithinReactor

      private void checkDependenciesWithinReactor(List<org.apache.maven.project.MavenProject> sortedProjects) throws EnforcerRuleException
      Throws:
      EnforcerRuleException
    • checkParentsInReactor

      private void checkParentsInReactor(List<org.apache.maven.project.MavenProject> sortedProjects) throws EnforcerRuleException
      Convenience method to create a user readable message.
      Parameters:
      sortedProjects - The list of reactor projects.
      Throws:
      EnforcerRuleException - In case of a violation.
    • checkReactor

      private void checkReactor(List<org.apache.maven.project.MavenProject> sortedProjects) throws EnforcerRuleException
      Convenience method to create user readable message.
      Parameters:
      sortedProjects - The list of reactor projects.
      Throws:
      EnforcerRuleException - In case of a violation.
    • areParentsFromTheReactor

      private List<org.apache.maven.project.MavenProject> areParentsFromTheReactor(String reactorVersion, List<org.apache.maven.project.MavenProject> sortedProjects)
    • existParentsWhichAreNotPartOfTheReactor

      private List<org.apache.maven.project.MavenProject> existParentsWhichAreNotPartOfTheReactor(List<org.apache.maven.project.MavenProject> sortedProjects)
    • isProjectPartOfTheReactor

      private boolean isProjectPartOfTheReactor(org.apache.maven.project.MavenProject project, List<org.apache.maven.project.MavenProject> sortedProjects)
      This will check of the groupId/artifactId can be found in any reactor project. The version will be ignored cause versions are checked before.
      Parameters:
      project - The project which should be checked if it is contained in the sortedProjects.
      sortedProjects - The list of existing projects.
      Returns:
      true if the project has been found within the list false otherwise.
    • isDependencyPartOfTheReactor

      private boolean isDependencyPartOfTheReactor(org.apache.maven.model.Dependency dependency, List<org.apache.maven.project.MavenProject> sortedProjects)
    • isGAPartOfTheReactor

      private boolean isGAPartOfTheReactor(String groupId, String artifactId, List<org.apache.maven.project.MavenProject> sortedProjects)
      This will check if the given groupId/artifactId is part of the current reactor.
      Parameters:
      groupId - The groupId
      artifactId - The artifactId
      sortedProjects - The list of projects within the reactor.
      Returns:
      true if the groupId/artifactId is part of the reactor false otherwise.
    • existModulesWithoutParentsInReactor

      private List<org.apache.maven.project.MavenProject> existModulesWithoutParentsInReactor(List<org.apache.maven.project.MavenProject> sortedProjects)
      Assume we have a module which is a child of a multi module build but this child does not have a parent. This method will exactly search for such cases.
      Parameters:
      sortedProjects - The sorted list of the reactor modules.
      Returns:
      The resulting list will contain the modules in the reactor which do not have a parent. The list will never null. If the list is empty no violation have happened.
    • addDep

      private void addDep(Map<org.apache.maven.project.MavenProject,List<org.apache.maven.model.Dependency>> result, org.apache.maven.project.MavenProject project, org.apache.maven.model.Dependency dependency)
      Convenience method to handle adding a dependency to the Map of List.
      Parameters:
      result - The result List which should be handled.
      project - The MavenProject which will be added.
      dependency - The dependency which will be added.
    • areThereDependenciesWhichAreNotPartOfTheReactor

      private Map<org.apache.maven.project.MavenProject,List<org.apache.maven.model.Dependency>> areThereDependenciesWhichAreNotPartOfTheReactor(String reactorVersion, List<org.apache.maven.project.MavenProject> sortedProjects)
      Go through the list of modules in the builds and check if we have dependencies. If yes we will check every dependency based on groupId/artifactId if it belongs to the multi module build. In such a case it will be checked if the version does fit the version in the rest of build.
      Parameters:
      reactorVersion - The version of the reactor.
      sortedProjects - The list of existing projects within this build.
      Returns:
      List of violations. Never null. If the list is empty than no violation has happened.
    • isReactorVersionConsistent

      private List<org.apache.maven.project.MavenProject> isReactorVersionConsistent(List<org.apache.maven.project.MavenProject> projectList)
      This method will check the following situation within a multi-module build.
        <parent>
          <groupId>...</groupId>
          <artifactId>...</artifactId>
          <version>1.0-SNAPSHOT</version>
        </parent>
        <version>1.1-SNAPSHOT</version>
       
      Parameters:
      projectList - The sorted list of the reactor modules.
      Returns:
      The resulting list will contain the modules in the reactor which do the thing in the example above. The list will never null. If the list is empty no violation have happened.
    • hasDependencies

      private boolean hasDependencies(List<org.apache.maven.model.Dependency> dependencies)
    • hasParent

      private boolean hasParent(org.apache.maven.project.MavenProject mavenProject)
    • isIgnoreModuleDependencies

      public boolean isIgnoreModuleDependencies()
    • addMessageIfExist

      private void addMessageIfExist(StringBuilder sb)
      This will add the given user message to the output.
      Parameters:
      sb - The already initialized exception message part.
    • getCacheId

      public String getCacheId()
      Description copied from class: AbstractEnforcerRule
      If the rule is to be cached during session scope, whole executing of Maven build, this id is used as part of the key.

      Rule of the same class and the same cache id will be executed once.

      Overrides:
      getCacheId in class AbstractEnforcerRule
      Returns:
      id to be used by the Enforcer to determine uniqueness of cache results. Return null disable cache of rule executing.
    • toString

      public String toString()
      Overrides:
      toString in class Object