getLog().debug( "Preparing ruleset: " + set );
File ruleset = locator.getResourceAsFile( set, getLocationTemp( set ) );
if ( null == ruleset )
{
throw new MavenReportException( "Could not resolve " + set );
}
InputStream rulesInput = new FileInputStream( ruleset );
try
{
RuleSet ruleSet = ruleSetFactory.createRuleSet( rulesInput );
sets[idx] = ruleSet;
ruleSet.start( ruleContext );
}
finally
{
rulesInput.close();
}
}
}
catch ( IOException e )
{
throw new MavenReportException( e.getMessage(), e );
}
catch ( ResourceNotFoundException e )
{
throw new MavenReportException( e.getMessage(), e );
}
catch ( FileResourceCreationException e )
{
throw new MavenReportException( e.getMessage(), e );
}
Map<File, PmdFileInfo> files;
try
{
files = getFilesToProcess();
}
catch ( IOException e )
{
throw new MavenReportException( "Can't get file list", e );
}
if ( StringUtils.isEmpty( getSourceEncoding() ) && !files.isEmpty() )
{
getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
+ ", i.e. build is platform dependent!" );
}
for ( Map.Entry<File, PmdFileInfo> entry : files.entrySet() )
{
File file = entry.getKey();
PmdFileInfo fileInfo = entry.getValue();
// TODO: lazily call beginFile in case there are no rules
reportSink.beginFile( file, fileInfo );
ruleContext.setSourceCodeFilename( file.getAbsolutePath() );
for ( int idx = 0; idx < rulesets.length; idx++ )
{
try
{
// PMD closes this Reader even though it did not open it so we have
// to open a new one with every call to processFile().
Reader reader;
if ( StringUtils.isNotEmpty( getSourceEncoding() ) )
{
reader = ReaderFactory.newReader( file, getSourceEncoding() );
}
else
{
reader = ReaderFactory.newPlatformReader( file );
}
try
{
pmd.processFile( reader, sets[idx], ruleContext );
}
finally
{
reader.close();
}
}
catch ( UnsupportedEncodingException e1 )
{
throw new MavenReportException( "Encoding '" + getSourceEncoding() + "' is not supported.", e1 );
}
catch ( PMDException pe )
{
String msg = pe.getLocalizedMessage();
Throwable r = pe.getCause();