Package org.apache.maven.enforcer.rule.api

Examples of org.apache.maven.enforcer.rule.api.EnforcerRuleException


                    = new RequireUpperBoundDepsVisitor();
            node.accept( visitor );
            List<String> errorMessages = buildErrorMessages( visitor.getConflicts() );
            if ( errorMessages.size() > 0 )
            {
                throw new EnforcerRuleException(
                        "Failed while enforcing RequireUpperBoundDeps. The error(s) are "
                        + errorMessages );
            }
        }
        catch ( ComponentLookupException e )
        {
            throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e );
        }
        catch ( Exception e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage(), e );
        }
    }
View Full Code Here


        {
            propValue = helper.evaluate( "${" + property + "}" );
        }
        catch ( ExpressionEvaluationException eee )
        {
            throw new EnforcerRuleException( "Unable to evaluate property: " + property, eee );
        }

        // Check that the property is not null or empty string
        if ( propValue == null )
        {
            if ( message == null )
            {
                message = "Property \"" + property + "\" is required for this build.";
            }
            throw new EnforcerRuleException( message );
        }
        // If there is a regex, check that the property matches it
        if ( regex != null && !propValue.toString().matches( regex ) )
        {
            if ( regexMessage == null )
            {
                regexMessage =
                    "Property \"" + property + "\" evaluates to \"" + propValue + "\".  " +
                        "This does not match the regular expression \"" + regex + "\"";
            }
            throw new EnforcerRuleException( regexMessage );
        }
    }
View Full Code Here

                    while ( iter.hasNext() )
                    {
                        buf.append( "Profile \"" + iter.next().toString() + "\" is not activated.\n" );
                    }

                    throw new EnforcerRuleException( buf.toString() );
                }

            }

        }
        catch ( ExpressionEvaluationException e )
        {
            throw new EnforcerRuleException( "Unable to retrieve the project.", e );
        }

    }
View Full Code Here

        throws EnforcerRuleException
    {

        if ( !allowNulls && files.length == 0 )
      {
            throw new EnforcerRuleException( "The file list is empty and Null files are disabled." );
      }

        ArrayList failures = new ArrayList();
        for ( int i = 0; i < files.length; i++ )
        {
            if ( !allowNulls && files[i] == null )
          {
                failures.add( files[i] );
          }
          else if ( !checkFile( files[i] ) )
            {
                failures.add( files[i] );
            }
        }

        // if anything was found, log it with the optional message.
        if ( !failures.isEmpty() )
        {
            StringBuffer buf = new StringBuffer();
            if ( message != null )
            {
                buf.append( message + "\n" );
            }
            buf.append( getErrorMsg() );

            Iterator iter = failures.iterator();
            while ( iter.hasNext() )
            {
                File file = (File) iter.next();
                if ( file != null )
                {
                    buf.append( file.getAbsolutePath() + "\n" );
                }
                else
                {
                    buf.append( "(an empty filename was given and allowNulls is false)\n" );
                }
            }

            throw new EnforcerRuleException( buf.toString() );
        }
    }
View Full Code Here

    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
                    {
                        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 );
                }
            }
        }
    }
View Full Code Here

        displayOSInfo( helper.getLog(), display );

        if ( allParamsEmpty() )
        {
            throw new EnforcerRuleException( "All parameters can not be empty. You must pick at least one of (family, name, version, arch) or use -Denforcer.os.display=true to see the current OS information." );
        }

        if ( isValidFamily( this.family ) )
        {
            if ( !isAllowed() )
            {
                if ( StringUtils.isEmpty( message ) )
                {
                    message =
                        ( "OS Arch: " + Os.OS_ARCH + " Family: " + Os.OS_FAMILY + " Name: " + Os.OS_NAME +
                            " Version: " + Os.OS_VERSION + " is not allowed by" +
                            ( arch != null ? " Arch=" + arch : "" ) + ( family != null ? " Family=" + family : "" ) +
                            ( name != null ? " Name=" + name : "" ) + ( version != null ? " Version=" + version : "" ) );
                }
                throw new EnforcerRuleException( message );
            }
        }
        else
        {
            StringBuffer buffer = new StringBuffer( 50 );
            Iterator iter = Os.getValidFamilies().iterator();
            while ( iter.hasNext() )
            {
                buffer.append( iter.next() );
                buffer.append( ", " );
            }
            String help = StringUtils.stripEnd( buffer.toString().trim(), "." );
            throw new EnforcerRuleException( "Invalid Family type used. Valid family types are: " + help );
        }
    }
View Full Code Here

                if ( StringUtils.isNotEmpty( message ) )
                {
                    newMsg.append( message );
                }

                throw new EnforcerRuleException( newMsg.toString() );
            }

        }
        catch ( ExpressionEvaluationException e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage() );
        }
        catch ( ArtifactResolutionException e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage() );
        }
        catch ( ArtifactNotFoundException e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage() );
        }
        catch ( IOException e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage() );
        }
        catch ( XmlPullParserException e )
        {
            throw new EnforcerRuleException( e.getLocalizedMessage() );
        }
    }
View Full Code Here

        String baseDir = mavenProject.getBasedir().getName();
        String artifactId = mavenProject.getArtifactId();
        String difference = StringUtils.difference(baseDir, artifactId);
        if (!difference.isEmpty()) {
            String template = "Artifact id: [%s] is not the same with base dir: [%s]. Difference is started at: [%s]";
            throw new EnforcerRuleException(String.format(template, artifactId, baseDir, difference));
        }
    }
View Full Code Here

                return;
            }
        }

        // FAILED
        throw new EnforcerRuleException("No matching Java package for groupId [" + groupId + "]");
    }
View Full Code Here

                sb.append(newLine);
            }
        }

        if (sb.length() != 0) {
            throw new EnforcerRuleException(sb.toString() +
                    (message != null ? message :
                            "Some files produce errors, please check the error message for the individual file above."));
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.maven.enforcer.rule.api.EnforcerRuleException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.