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

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


            checkPatterns(srcDir, patterns);
            checkClasses(srcDir, classes);

        } catch (ExpressionEvaluationException e) {
            throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
        } catch (IOException e) {
            throw new EnforcerRuleException(e.getMessage(), e);
        }
    }
View Full Code Here


                    CompilationUnit cu = JavaParser.parse(file);

                    if (cu.getImports() != null) {
                        for (ImportDeclaration importDeclaration : cu.getImports()) {
                            if (classesPredicate.apply(importDeclaration.getName().toString())) {
                                throw new EnforcerRuleException(
                                        String.format("%s: Illegal class import - %s at %s:%d:%d is bad!", file.getPath(), importDeclaration.getName().toString(), file.getPath(), importDeclaration.getBeginLine(), importDeclaration.getBeginColumn()));
                            }
                        }
                    }

                } catch (Exception e) {
                    throw new EnforcerRuleException(String.format("%s: %s", file.getPath(), e.getMessage()));
                }
            }
        });
    }
View Full Code Here

                                StringBuilder sb = new StringBuilder();
                                sb.append("Found pattern " + pattern + " at " + file.getPath() + ":" + reader.getLineNumber());
                                sb.append("\n");
                                sb.append(line);

                                throw new EnforcerRuleException(String.format("%s: %s", file.getPath(), sb.toString()));
                            }
                        }
                    }
                } catch (IOException e) {
                    log.error(e.getMessage());
                    throw new EnforcerRuleException(String.format("%s: %s", file.getPath(), e.getMessage()));
                }


            }
        });
View Full Code Here

        log.info("checking availability of port : " + this.port);

        // make sure it's > 0
        if (!(this.port > 0))
        {
            throw new EnforcerRuleException("Port is not valid " + this.port);
        }

        // check availability
        if (!available(this.port))
        {
            throw new EnforcerRuleException("Port is not available " + this.port);
        }

        if (this.shouldIfail)
        {
            throw new EnforcerRuleException("Failing because my param said so.");
        }
    }
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
                    {
                        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 );
                }
            }
        }
    }
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() )
            {
                String message = getMessage();
                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 );
        }

        // consider including profile based artifacts
        Map<String, List<String>> versionMembers = new LinkedHashMap<String, List<String>>();

        Set<String> buildPluginSet = new HashSet<String>( buildPlugins );
        buildPluginSet.addAll( plugins );
        Set<String> reportPluginSet = new HashSet<String>( reportPlugins );
        reportPluginSet.addAll( plugins );

        versionMembers.putAll( collectVersionMembers( project.getArtifacts(), dependencies, " (dependency)" ) );
        versionMembers.putAll( collectVersionMembers( project.getPluginArtifacts(), buildPlugins, " (buildPlugin)" ) );
        versionMembers.putAll( collectVersionMembers( project.getReportArtifacts(), reportPlugins, " (reportPlugin)" ) );

        if ( versionMembers.size() > 1 )
        {
            StringBuilder builder = new StringBuilder( "Found entries with different versions\n" );
            for ( Map.Entry<String, List<String>> entry : versionMembers.entrySet() )
            {
                builder.append( "Entries with version " ).append( entry.getKey() ).append( '\n' );
                for ( String conflictId : entry.getValue() )
                {
                    builder.append( "- " ).append( conflictId ).append( '\n' );
                }
            }
            throw new EnforcerRuleException( builder.toString() );
        }
    }
View Full Code Here

                        AbstractVersionEnforcer.containsVersion( VersionRange.createFromVersionSpec( pattern[2] ),
                                                                 new DefaultArtifactVersion( artifact.getBaseVersion() ) );
                }
                catch ( InvalidVersionSpecificationException e )
                {
                    throw new EnforcerRuleException( "Invalid Version Range: ", e );
                }
            }
        }

        if ( result && pattern.length > 3 )
View Full Code Here

                    project = getProject( helper );
                }
                Artifact parentArtifact = project.getParentArtifact();
                if ( parentArtifact != null && parentArtifact.isSnapshot() )
                {
                    throw new EnforcerRuleException( "Parent Cannot be a snapshot: " + parentArtifact.getId() );
                }
            }
        }
    }
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.