{
project = (MavenProject) helper.evaluate( "${project}" );
}
catch ( ExpressionEvaluationException eee )
{
throw new EnforcerRuleException( "Unable to retrieve the MavenProject: ", eee );
}
try
{
graphBuilder = (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class );
}
catch ( ComponentLookupException e )
{
// real cause is probably that one of the Maven3 graph builder could not be initiated and fails with a ClassNotFoundException
try
{
graphBuilder = (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class.getName(), "maven2" );
}
catch ( ComponentLookupException e1 )
{
throw new EnforcerRuleException( "Unable to lookup DependencyGraphBuilder: ", e );
}
}
// 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() )
{
String message = getMessage();
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 );
}
}