throw new CheckstyleExecutorException( "Error getting files to process", e );
}
FilterSet filterSet = getSuppressions( request );
Checker checker = new Checker();
// setup classloader, needed to avoid "Unable to get class information
// for ..." errors
List<String> classPathStrings = new ArrayList<String>();
List<String> outputDirectories = new ArrayList<String>();
File sourceDirectory = request.getSourceDirectory();
File testSourceDirectory = request.getTestSourceDirectory();
if ( request.isAggregate() )
{
for ( MavenProject childProject : request.getReactorProjects() )
{
prepareCheckstylePaths( request, childProject, classPathStrings, outputDirectories,
new File( childProject.getBuild().getSourceDirectory() ),
new File( childProject.getBuild().getTestSourceDirectory() ) );
}
}
else
{
prepareCheckstylePaths( request, project, classPathStrings, outputDirectories, sourceDirectory,
testSourceDirectory );
}
List<URL> urls = new ArrayList<URL>( classPathStrings.size() );
for ( String path : classPathStrings )
{
try
{
urls.add( new File( path ).toURL() );
}
catch ( MalformedURLException e )
{
throw new CheckstyleExecutorException( e.getMessage(), e );
}
}
for ( String outputDirectoryString : outputDirectories )
{
try
{
if ( outputDirectoryString != null )
{
File outputDirectoryFile = new File( outputDirectoryString );
if ( outputDirectoryFile.exists() )
{
URL outputDirectoryUrl = outputDirectoryFile.toURL();
request.getLog().debug(
"Adding the outputDirectory " + outputDirectoryUrl.toString()
+ " to the Checkstyle class path" );
urls.add( outputDirectoryUrl );
}
}
}
catch ( MalformedURLException e )
{
throw new CheckstyleExecutorException( e.getMessage(), e );
}
}
URLClassLoader projectClassLoader = new URLClassLoader( (URL[]) urls.toArray( new URL[urls.size()] ), null );
checker.setClassloader( projectClassLoader );
checker.setModuleClassLoader( Thread.currentThread().getContextClassLoader() );
if ( filterSet != null )
{
checker.addFilter( filterSet );
}
Configuration configuration = getConfiguration( request );
checker.configure( configuration );
AuditListener listener = request.getListener();
if ( listener != null )
{
checker.addListener( listener );
}
if ( request.isConsoleOutput() )
{
checker.addListener( request.getConsoleListener() );
}
CheckstyleReportListener sinkListener = new CheckstyleReportListener( configuration );
if ( request.isAggregate() )
{
for ( MavenProject childProject : request.getReactorProjects() )
{
addSourceDirectory( sinkListener, new File( childProject.getBuild().getSourceDirectory() ),
new File( childProject.getBuild().getTestSourceDirectory() ),
childProject.getResources(), request );
}
}
else
{
addSourceDirectory( sinkListener, sourceDirectory, testSourceDirectory, request.getResources(), request );
}
checker.addListener( sinkListener );
List<File> filesList = Arrays.asList( files );
int nbErrors = checker.process( filesList );
checker.destroy();
if ( request.getStringOutputStream() != null )
{
request.getLog().info( request.getStringOutputStream().toString() );
}