Author: gboue
Date: Sun Nov 20 15:04:12 2016
New Revision: 1770564

URL: http://svn.apache.org/viewvc?rev=1770564&view=rev
Log:
[MCHECKSTYLE-332] maven plugin not using cache property

Starting with Checkstyle 6.16, the cache configuration was moved from the 
TreeWalker module to the Checker module, as per 
https://github.com/checkstyle/checkstyle/issues/569. To detect this change, we 
can rely on the presence of the public API method "setCacheFile(String)" in the 
Checker class.

Added:
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
   (with props)
    
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
   (with props)
Modified:
    
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=clean checkstyle:checkstyle

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle</groupId>
+  <artifactId>check-pass</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <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)
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <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>
+
+</project>

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,26 @@
+package org;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Yada yada yada.
+ */
+public class MyClass {
+}

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/src/main/java/org/MyClass.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,23 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert new File( basedir, 'target/checkstyle-cachefile' ).exists();
+
+return true;
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-checker/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=clean checkstyle:checkstyle

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.checkstyle</groupId>
+  <artifactId>check-pass</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MCHECKSTYLE-332</url>
+  <description>
+    Tests that the cache file is correctly set with Checkstyle 6.15 
(https://github.com/checkstyle/checkstyle/issues/569)
+  </description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-checkstyle-plugin</artifactId>
+        <version>@pom.version@</version>
+        <dependencies>
+          <!-- force usage of 6.15, where the cacheFile property is in the 
TreeWalker module -->
+          <dependency>
+            <groupId>com.puppycrawl.tools</groupId>
+            <artifactId>checkstyle</artifactId>
+            <version>6.15</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,26 @@
+package org;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Yada yada yada.
+ */
+public class MyClass {
+}

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy?rev=1770564&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
 (added)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
 Sun Nov 20 15:04:12 2016
@@ -0,0 +1,23 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+assert new File( basedir, 'target/checkstyle-cachefile' ).exists();
+
+return true;
\ No newline at end of file

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-checkstyle-plugin/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: 
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java?rev=1770564&r1=1770563&r2=1770564&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java
 (original)
+++ 
maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/exec/DefaultCheckstyleExecutor.java
 Sun Nov 20 15:04:12 2016
@@ -25,12 +25,14 @@ import java.io.File;
 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;
@@ -389,23 +391,28 @@ public class DefaultCheckstyleExecutor
                                       + ", 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
-                    try
+                    addAttributeIfNotExists( (DefaultConfiguration) config, 
"charset", effectiveEncoding );
+                    if ( cacheInChecker )
                     {
-                        if ( 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 );
+                        addAttributeIfNotExists( (DefaultConfiguration) 
config, "cacheFile", request.getCacheFile() );
                     }
                 }
                 else
@@ -421,20 +428,10 @@ public class DefaultCheckstyleExecutor
                 {
                     if ( module instanceof DefaultConfiguration )
                     {
-                        // MCHECKSTYLE-132 DefaultConfiguration addAttribute 
has changed in checkstyle 5.3
-                        try
-                        {
-                            if ( module.getAttribute( "cacheFile" ) == null )
-                            {
-                                ( (DefaultConfiguration) module 
).addAttribute( "cacheFile", request.getCacheFile() );
-                            }
-                        }
-                        catch ( CheckstyleException ex )
+                        if ( !cacheInChecker )
                         {
-                            // MCHECKSTYLE-159 - checkstyle 5.4 throws an 
exception instead of return null if
-                            // "cacheFile"
-                            // doesn't exist
-                            ( (DefaultConfiguration) module ).addAttribute( 
"cacheFile", request.getCacheFile() );
+                            addAttributeIfNotExists( (DefaultConfiguration) 
module, "cacheFile",
+                                                     request.getCacheFile() );
                         }
                     }
                     else
@@ -451,6 +448,23 @@ public class DefaultCheckstyleExecutor
         }
     }
 
+    private void addAttributeIfNotExists( DefaultConfiguration config, String 
name, String value )
+    {
+        try
+        {
+            // MCHECKSTYLE-132 DefaultConfiguration addAttribute has changed 
in checkstyle 5.3
+            if ( config.getAttribute( name ) == null )
+            {
+                config.addAttribute( name, value );
+            }
+        }
+        catch ( CheckstyleException ex )
+        {
+            // MCHECKSTYLE-159 Checkstyle 5.4+ throws an exception when trying 
to access an attribute that doesn't exist
+            config.addAttribute( name, value );
+        }
+    }
+
     private void prepareCheckstylePaths( CheckstyleExecutorRequest request, 
MavenProject project,
                                          List<String> classPathStrings, 
List<String> outputDirectories,
                                          Collection<File> sourceDirectories, 
Collection<File> testSourceDirectories )


Reply via email to