Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCHECKSTYLE-374 remove deprecated method calls #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/it/MCHECKSTYLE-332_cache-checker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<url>https://issues.apache.org/jira/browse/MCHECKSTYLE-332</url>
<description>
Tests that the cache file is correctly set with Checkstyle 6.16 (https://github.com/checkstyle/checkstyle/issues/569)
Tests that the cache file is correctly set with Checkstyle 6.16+ (https://github.com/checkstyle/checkstyle/issues/569)
</description>

<properties>
Expand All @@ -42,14 +42,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>@pom.version@</version>
<dependencies>
<!-- force usage of 6.16, where the cacheFile property is in the Checker module -->
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.16</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
18 changes: 0 additions & 18 deletions src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties

This file was deleted.

63 changes: 0 additions & 63 deletions src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml

This file was deleted.

This file was deleted.

23 changes: 0 additions & 23 deletions src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.puppycrawl.tools.checkstyle.DefaultLogger;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;

/**
Expand Down Expand Up @@ -628,11 +629,11 @@ protected AuditListener getListener()

if ( "xml".equals( outputFileFormat ) )
{
listener = new XMLLogger( out, true );
listener = new XMLLogger( out, OutputStreamOptions.CLOSE );
}
else if ( "plain".equals( outputFileFormat ) )
{
listener = new DefaultLogger( out, true );
listener = new DefaultLogger( out, OutputStreamOptions.CLOSE );
}
else
{
Expand Down Expand Up @@ -681,13 +682,13 @@ protected DefaultLogger getConsoleListener()
if ( useFile == null )
{
stringOutputStream = new ByteArrayOutputStream();
consoleListener = new DefaultLogger( stringOutputStream, false );
consoleListener = new DefaultLogger( stringOutputStream, OutputStreamOptions.NONE );
}
else
{
OutputStream out = getOutputStream( useFile );

consoleListener = new DefaultLogger( out, true );
consoleListener = new DefaultLogger( out, OutputStreamOptions.CLOSE );
}

return consoleListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import com.puppycrawl.tools.checkstyle.DefaultLogger;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean.OutputStreamOptions;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;

/**
Expand Down Expand Up @@ -731,13 +732,13 @@ private DefaultLogger getConsoleListener()
if ( useFile == null )
{
stringOutputStream = new ByteArrayOutputStream();
consoleListener = new DefaultLogger( stringOutputStream, false );
consoleListener = new DefaultLogger( stringOutputStream, OutputStreamOptions.NONE );
}
else
{
OutputStream out = getOutputStream( useFile );

consoleListener = new DefaultLogger( out, true );
consoleListener = new DefaultLogger( out, OutputStreamOptions.CLOSE );
}

return consoleListener;
Expand Down Expand Up @@ -778,7 +779,7 @@ private AuditListener getListener()

if ( "xml".equals( outputFileFormat ) )
{
listener = new XMLLogger( out, true );
listener = new XMLLogger( out, OutputStreamOptions.CLOSE );
}
else if ( "plain".equals( outputFileFormat ) )
{
Expand All @@ -790,8 +791,8 @@ else if ( "plain".equals( outputFileFormat ) )
outputXmlFile.deleteOnExit();
OutputStream xmlOut = getOutputStream( outputXmlFile );
CompositeAuditListener compoundListener = new CompositeAuditListener();
compoundListener.addListener( new XMLLogger( xmlOut, true ) );
compoundListener.addListener( new DefaultLogger( out, true ) );
compoundListener.addListener( new XMLLogger( xmlOut, OutputStreamOptions.CLOSE ) );
compoundListener.addListener( new DefaultLogger( out, OutputStreamOptions.CLOSE ) );
listener = compoundListener;
}
catch ( IOException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
Expand All @@ -58,6 +56,7 @@

import com.puppycrawl.tools.checkstyle.Checker;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
import com.puppycrawl.tools.checkstyle.ConfigurationLoader.IgnoredModulesOptions;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
import com.puppycrawl.tools.checkstyle.PropertiesExpander;
Expand Down Expand Up @@ -373,9 +372,18 @@ public Configuration getConfiguration( CheckstyleExecutorRequest request )
Thread.currentThread().setContextClassLoader( checkstyleClassLoader );
String configFile = getConfigFile( request );
Properties overridingProperties = getOverridingProperties( request );
IgnoredModulesOptions omitIgnoredModules;
if ( request.isOmitIgnoredModules() )
{
omitIgnoredModules = IgnoredModulesOptions.OMIT;
}
else
{
omitIgnoredModules = IgnoredModulesOptions.EXECUTE;
}
Configuration config =
ConfigurationLoader.loadConfiguration( configFile, new PropertiesExpander( overridingProperties ),
request.isOmitIgnoredModules() );
omitIgnoredModules );
String effectiveEncoding = StringUtils.isNotEmpty( request.getEncoding() ) ? request.getEncoding() : System
.getProperty( "file.encoding", "UTF-8" );

Expand All @@ -385,55 +393,20 @@ public Configuration getConfiguration( CheckstyleExecutorRequest request )
+ ", i.e. build is platform dependent!" );
}

// MCHECKSTYLE-332 Checkstyle 6.16+ (#569): the cache is moved to the Checker module instead of TreeWalker
boolean cacheInChecker = false;
for ( Method method : Checker.class.getMethods() )
{
if ( "setCacheFile".equals( method.getName() )
&& Arrays.equals( method.getParameterTypes(), new Class<?>[] { String.class } ) )
{
cacheInChecker = true;
break;
}
}

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
addAttributeIfNotExists( (DefaultConfiguration) config, "charset", effectiveEncoding );
if ( cacheInChecker )
{
addAttributeIfNotExists( (DefaultConfiguration) config, "cacheFile", request.getCacheFile() );
}
addAttributeIfNotExists( (DefaultConfiguration) config, "cacheFile", request.getCacheFile() );
}
else
{
getLogger().warn( "Failed to configure file encoding on module " + config );
}
}
Configuration[] modules = config.getChildren();
for ( Configuration module : modules )
{
if ( "TreeWalker".equals( module.getName() )
|| "com.puppycrawl.tools.checkstyle.TreeWalker".equals( module.getName() ) )
{
if ( module instanceof DefaultConfiguration )
{
if ( !cacheInChecker )
{
addAttributeIfNotExists( (DefaultConfiguration) module, "cacheFile",
request.getCacheFile() );
}
}
else
{
getLogger().warn( "Failed to configure cache file on module " + module );
}
}
}
return config;
}
catch ( CheckstyleException e )
Expand Down