code: public void enforceVersion( Log log, String variableName, String requiredVersionRange, ArtifactVersion actualVersion )
          throws EnforcerRuleException
      {
          if ( StringUtils.isEmpty( requiredVersionRange ) )
          {
              throw new EnforcerRuleException( variableName + " version can't be empty." );
          }
          else
          {
  
              VersionRange vr;
              String msg = "Detected " + variableName + " Version: " + actualVersion;
  
              // short circuit check if the strings are exactly equal
              if ( actualVersion.toString().equals( requiredVersionRange ) )
              {
                  log.debug( msg + " is allowed in the range " + requiredVersionRange + "." );
              }
              else
              {
                  try
                  {
                      vr = VersionRange.createFromVersionSpec( requiredVersionRange );
  
                      if ( containsVersion( vr, actualVersion ) )
                      {
                          log.debug( msg + " is allowed in the range " + requiredVersionRange + "." );
                      }
                      else
                      {
                          String message = getMessage();
                          
                          if ( StringUtils.isEmpty( message ) )
                          {
                              message = msg + " is not in the allowed range " + vr + ".";
                          }
  
                          throw new EnforcerRuleException( message );
                      }
                  }
                  catch ( InvalidVersionSpecificationException e )
                  {
                      throw new EnforcerRuleException( "The requested " + variableName + " version "
                          + requiredVersionRange + " is invalid.", e );
                  }
              }
          }
      }
docs: Compares the specified version to see if it is allowed by the defined version range.
  
  @param log the log
  @param variableName name of variable to use in messages (Example: "Maven" or "Java" etc).
  @param requiredVersionRange range of allowed versions.
  @param actualVersion the version to be checked.
  @throws EnforcerRuleException the enforcer rule exception