}
if ( ignoreIdentifiers )
{
p.setProperty( JavaTokenizer.IGNORE_IDENTIFIERS, "true" );
}
CPD cpd = new CPD( minimumTokens, new JavaLanguage( p ) );
Map<File, PmdFileInfo> files = null;
try
{
files = getFilesToProcess();
if ( StringUtils.isNotEmpty( getSourceEncoding() ) )
{
cpd.setEncoding( getSourceEncoding() );
// test encoding as CPD will convert exception into a RuntimeException
WriterFactory.newWriter( new ByteArrayOutputStream(), getSourceEncoding() );
}
else if ( !files.isEmpty() )
{
getLog().warn(
"File encoding has not been set, using platform encoding "
+ WriterFactory.FILE_ENCODING + ", i.e. build is platform dependent!" );
}
for ( File file : files.keySet() )
{
cpd.add( file );
}
}
catch ( UnsupportedEncodingException e )
{
throw new MavenReportException( "Encoding '" + getSourceEncoding() + "' is not supported.", e );
}
catch ( IOException e )
{
throw new MavenReportException( e.getMessage(), e );
}
cpd.go();
CpdReportGenerator gen =
new CpdReportGenerator( getSink(), files, getBundle( locale ), aggregate );
gen.generate( cpd.getMatches() );
return cpd;
}