getLog().debug( "Preparing ruleset: " + set );
RuleSetReferenceId id = new RuleSetReferenceId( set );
File ruleset = locator.getResourceAsFile( id.getRuleSetFileName(), getLocationTemp( set ) );
if ( null == ruleset )
{
throw new MavenReportException( "Could not resolve " + set );
}
sets[idx] = ruleset.getAbsolutePath();
}
}
catch ( ResourceNotFoundException e )
{
throw new MavenReportException( e.getMessage(), e );
}
catch ( FileResourceCreationException e )
{
throw new MavenReportException( e.getMessage(), e );
}
pmdConfiguration.setRuleSets( StringUtils.join( sets, "," ) );
try
{
if ( filesToProcess == null )
{
filesToProcess = getFilesToProcess();
}
if ( filesToProcess.isEmpty() && !"java".equals( language ) )
{
getLog().warn(
"No files found to process. Did you add your additional source folders like javascript? (see also build-helper-maven-plugin)" );
}
}
catch ( IOException e )
{
throw new MavenReportException( "Can't get file list", e );
}
String encoding = getSourceEncoding();
if ( StringUtils.isEmpty( encoding ) && !filesToProcess.isEmpty() )
{
getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
+ ", i.e. build is platform dependent!" );
encoding = ReaderFactory.FILE_ENCODING;
}
pmdConfiguration.setSourceEncoding( encoding );
List<DataSource> dataSources = new ArrayList<DataSource>( filesToProcess.size() );
for ( File f : filesToProcess.keySet() )
{
dataSources.add( new FileDataSource( f ) );
}
try
{
getLog().debug( "Executing PMD..." );
PMD.processFiles( pmdConfiguration, ruleSetFactory, dataSources, ruleContext,
Collections.<Renderer> emptyList() );
if ( getLog().isDebugEnabled() )
{
getLog().debug( "PMD finished. Found " + reportListener.getViolations().size() + " violations." );
}
}
catch ( Exception e )
{
String message = "Failure executing PMD: " + e.getLocalizedMessage();
if ( !skipPmdError )
{
throw new MavenReportException( message, e );
}
getLog().warn( message, e );
}
// if format is XML, we need to output it even if the file list is empty or we have no violations