// so we have to fix it
ClassLoader checkstyleClassLoader = PackageNamesLoader.class.getClassLoader();
Thread.currentThread().setContextClassLoader( checkstyleClassLoader );
String configFile = getConfigFile( request );
Properties overridingProperties = getOverridingProperties( request );
Configuration config = ConfigurationLoader
.loadConfiguration( configFile, new PropertiesExpander( overridingProperties ) );
String effectiveEncoding = StringUtils.isNotEmpty( request.getEncoding() ) ? request.getEncoding() : System
.getProperty( "file.encoding", "UTF-8" );
if ( StringUtils.isEmpty( request.getEncoding() ) )
{
request.getLog().warn(
"File encoding has not been set, using platform encoding " + effectiveEncoding
+ ", i.e. build is platform dependent!" );
}
if ( "Checker".equals( config.getName() )
|| "com.puppycrawl.tools.checkstyle.Checker".equals( config.getName() ) )
{
if ( config instanceof DefaultConfiguration )
{
// MCHECKSTYLE-173 Only add the "charset" attribute if it has not been set
try
{
if ( ( (DefaultConfiguration) config ).getAttribute( "charset" ) == null )
{
( (DefaultConfiguration) config ).addAttribute( "charset", effectiveEncoding );
}
}
catch ( CheckstyleException ex )
{
// Checkstyle 5.4+ throws an exception when trying to access an attribute that doesn't exist
( (DefaultConfiguration) config ).addAttribute( "charset", effectiveEncoding );
}
}
else
{
request.getLog().warn( "Failed to configure file encoding on module " + config );
}
}
Configuration[] modules = config.getChildren();
for ( int i = 0; i < modules.length; i++ )
{
Configuration module = modules[i];
if ( "TreeWalker".equals( module.getName() )
|| "com.puppycrawl.tools.checkstyle.TreeWalker".equals( module.getName() ) )
{
if ( module instanceof DefaultConfiguration )
{
//MCHECKSTYLE-132 DefaultConfiguration addAttribute has changed in checkstyle 5.3
try