private Report generateReport( Locale locale )
throws MavenReportException
{
Sink sink = getSink();
PMDConfiguration pmdConfiguration = getPMDConfiguration();
final PmdReportListener reportSink = new PmdReportListener( getLog(), sink, getBundle( locale ), aggregate );
RuleContext ruleContext = new RuleContext()
{
@Override
public void setReport( Report report )
{
super.setReport( report );
// make sure our listener is added - the Report is created by PMD internally now
report.addListener( reportSink );
}
};
reportSink.beginDocument();
RuleSetFactory ruleSetFactory = new RuleSetFactory();
ruleSetFactory.setMinimumPriority( RulePriority.valueOf( this.minimumPriority ) );
String[] sets = new String[rulesets.length];
try
{
for ( int idx = 0; idx < rulesets.length; idx++ )
{
String set = rulesets[idx];
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, "," ) );
Map<File, PmdFileInfo> files;
try
{
files = getFilesToProcess();
if ( files.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 ) && !files.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 );
reportSink.setFiles( files );
List<DataSource> dataSources = new ArrayList<DataSource>( files.size() );
for ( File f : files.keySet() )
{
dataSources.add( new FileDataSource( f ) );
}
try
{
List<Renderer> renderers = Collections.emptyList();
// Unfortunately we need to disable multi-threading for now - as otherwise our PmdReportListener
// will be ignored.
// Longer term solution could be to use a custom renderer instead. And collect with this renderer
// all the violations.
pmdConfiguration.setThreads( 0 );
PMD.processFiles( pmdConfiguration, ruleSetFactory, dataSources, ruleContext, renderers );
}
catch ( Exception e )
{