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

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


    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
        {
            StringBuilder buffer = new StringBuilder( 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

        {
            project = (MavenProject) helper.evaluate( "${project}" );
        }
        catch ( ExpressionEvaluationException eee )
        {
            throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee );
        }

        // get the correct list of dependencies
        Set<Artifact> dependencies = getDependenciesToCheck( project );

        // look for banned dependencies
        Set<Artifact> foundExcludes = checkDependencies( dependencies, helper.getLog() );

        // if any are found, fail the check but list all of them
        if ( foundExcludes != null && !foundExcludes.isEmpty() )
        {
            StringBuilder buf = new StringBuilder();
            if ( message != null )
            {
                buf.append( message + "\n" );
            }
            for ( Artifact artifact : foundExcludes )
            {
                buf.append( getErrorMessage( artifact ) );
            }
            message = buf.toString()+ "Use 'mvn dependency:tree' to locate the source of the banned dependencies.";

            throw new EnforcerRuleException( message );
        }

    }
View Full Code Here

                                                           collector );
            return node;
        }
        catch ( ExpressionEvaluationException e )
        {
            throw new EnforcerRuleException( "Unable to lookup an expression " + e.getLocalizedMessage(), e );
        }
        catch ( ComponentLookupException e )
        {
            throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e );
        }
        catch ( DependencyTreeBuilderException e )
        {
            throw new EnforcerRuleException( "Could not build dependency tree " + e.getLocalizedMessage(), e );
        }
    }
View Full Code Here

            RequireUpperBoundDepsVisitor visitor = 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 );
        }
        return propValue;
    }
View Full Code Here

                    for ( String profile : missingProfiles )
                    {
                        buf.append( "Profile \"" + profile + "\" 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

            if ( message != null )
            {
                buf.append( message + "\n" );
            }
            buf.append( "This project cannot be a snapshot:" + project.getArtifact().getId() );
            throw new EnforcerRuleException( buf.toString() );
        }
        if ( failWhenParentIsSnapshot )
        {
            Artifact parentArtifact = project.getParentArtifact();
            if ( parentArtifact != null && parentArtifact.isSnapshot() )
            {
                throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() );
            }
        }

    }
View Full Code Here

        {
            return (MavenProject) helper.evaluate( "${project}" );
        }
        catch ( ExpressionEvaluationException eee )
        {
            throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee );
        }
    }
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.