You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by eo...@apache.org on 2019/05/01 07:13:56 UTC

[maven-checkstyle-plugin] branch MCHECKSTYLE-374 created (now 15ca59a)

This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a change to branch MCHECKSTYLE-374
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git.


      at 15ca59a  [MCHECKSTYLE-374] - replace deprecated method calls with newer checkstyle version

This branch includes the following new commits:

     new 15ca59a  [MCHECKSTYLE-374] - replace deprecated method calls with newer checkstyle version

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-checkstyle-plugin] 01/01: [MCHECKSTYLE-374] - replace deprecated method calls with newer checkstyle version

Posted by eo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

eolivelli pushed a commit to branch MCHECKSTYLE-374
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit 15ca59a25b4fabf0a5b6c4f1bb85565549f19a6a
Author: rnveach <rv...@gmail.com>
AuthorDate: Tue Apr 23 06:57:19 2019 -0400

    [MCHECKSTYLE-374] - replace deprecated method calls with newer
    checkstyle version
---
 src/it/MCHECKSTYLE-332_cache-checker/pom.xml       | 10 +---
 .../invoker.properties                             | 18 -------
 src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml    | 63 ----------------------
 .../src/main/java/org/MyClass.java                 | 26 ---------
 .../MCHECKSTYLE-332_cache-treewalker/verify.groovy | 23 --------
 .../checkstyle/AbstractCheckstyleReport.java       |  9 ++--
 .../checkstyle/CheckstyleViolationCheckMojo.java   | 11 ++--
 .../checkstyle/exec/DefaultCheckstyleExecutor.java | 51 +++++-------------
 8 files changed, 24 insertions(+), 187 deletions(-)

diff --git a/src/it/MCHECKSTYLE-332_cache-checker/pom.xml b/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
index 925f858..388aaa8 100644
--- a/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
+++ b/src/it/MCHECKSTYLE-332_cache-checker/pom.xml
@@ -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>
@@ -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>
diff --git a/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties b/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
deleted file mode 100644
index 4adad81..0000000
--- a/src/it/MCHECKSTYLE-332_cache-treewalker/invoker.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-# 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
diff --git a/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml b/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
deleted file mode 100644
index fffb756..0000000
--- a/src/it/MCHECKSTYLE-332_cache-treewalker/pom.xml
+++ /dev/null
@@ -1,63 +0,0 @@
-<?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>@project.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>
-            <exclusions>
-              <exclusion>
-                <groupId>com.sun</groupId>
-                <artifactId>tools</artifactId>
-              </exclusion>
-            </exclusions>
-          </dependency>
-        </dependencies>
-      </plugin>
-    </plugins>
-  </build>
-
-</project>
diff --git a/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java b/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
deleted file mode 100644
index 84a40d3..0000000
--- a/src/it/MCHECKSTYLE-332_cache-treewalker/src/main/java/org/MyClass.java
+++ /dev/null
@@ -1,26 +0,0 @@
-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 {
-}
diff --git a/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy b/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
deleted file mode 100644
index abe0aa7..0000000
--- a/src/it/MCHECKSTYLE-332_cache-treewalker/verify.groovy
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * 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
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
index f89d059..04ccba1 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/AbstractCheckstyleReport.java
@@ -60,6 +60,7 @@ import org.codehaus.plexus.util.StringUtils;
 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;
 
 /**
@@ -628,11 +629,11 @@ public abstract class AbstractCheckstyleReport
 
             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
             {
@@ -681,13 +682,13 @@ public abstract class AbstractCheckstyleReport
         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;
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
index 8c50001..b9b8e0e 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/CheckstyleViolationCheckMojo.java
@@ -62,6 +62,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 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;
 
 /**
@@ -731,13 +732,13 @@ public class CheckstyleViolationCheckMojo
         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;
@@ -778,7 +779,7 @@ public class CheckstyleViolationCheckMojo
 
             if ( "xml".equals( outputFileFormat ) )
             {
-                listener = new XMLLogger( out, true );
+                listener = new XMLLogger( out, OutputStreamOptions.CLOSE );
             }
             else if ( "plain".equals( outputFileFormat ) )
             {
@@ -790,8 +791,8 @@ public class CheckstyleViolationCheckMojo
                     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 )
diff --git a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
index dcf3fba..9a35945 100644
--- a/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
+++ b/src/main/java/org/apache/maven/plugins/checkstyle/exec/DefaultCheckstyleExecutor.java
@@ -25,14 +25,12 @@ 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;
@@ -58,6 +56,7 @@ import org.codehaus.plexus.util.StringUtils;
 
 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;
@@ -373,9 +372,18 @@ public class DefaultCheckstyleExecutor
             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" );
             
@@ -385,18 +393,6 @@ 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() ) )
             {
@@ -404,36 +400,13 @@ public class DefaultCheckstyleExecutor
                 {
                     // 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 )