You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2009/11/14 23:21:50 UTC

svn commit: r836274 - in /maven/plugins/trunk/maven-checkstyle-plugin: ./ src/it/ src/it/checkstyle-report/ src/main/java/org/apache/maven/plugin/checkstyle/ src/main/java/org/apache/maven/plugin/checkstyle/rss/ src/main/resources/META-INF/ src/test/ja...

Author: olamy
Date: Sat Nov 14 22:21:48 2009
New Revision: 836274

URL: http://svn.apache.org/viewvc?rev=836274&view=rev
Log:
[MCHECKSTYLE-123]  remove use of Serviceable (to be compatible wih maven 3.x).
Start some refactoring by creating a new component which will execute checkstyle to prevent check mojo to call report (@execute goal="checkstyle")
work in progress (other things to check for mvn 3.x) 

Added:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java   (with props)
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java   (with props)
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java   (with props)
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java   (with props)
Removed:
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/resources/META-INF/
Modified:
    maven/plugins/trunk/maven-checkstyle-plugin/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/checkstyle-report/pom.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/it/settings.xml
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportTest.java
    maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java

Modified: maven/plugins/trunk/maven-checkstyle-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/pom.xml?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/pom.xml Sat Nov 14 22:21:48 2009
@@ -139,7 +139,7 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-resources</artifactId>
-      <version>1.0-alpha-4</version>
+      <version>1.0-alpha-6-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
@@ -193,9 +193,9 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.maven.shared</groupId>
+      <groupId>org.apache.maven.plugin-testing</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
-      <version>1.0-beta-1</version>
+      <version>1.2</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
@@ -206,7 +206,7 @@
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-site-plugin</artifactId>
-          <version>2.0</version>
+          <version>2.0.1</version>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
@@ -218,12 +218,12 @@
     <plugins>
       <plugin>
         <groupId>org.codehaus.plexus</groupId>
-        <artifactId>plexus-maven-plugin</artifactId>
-        <version>1.3.4</version>
+        <artifactId>plexus-component-metadata</artifactId>
+        <version>1.5.1</version>
         <executions>
           <execution>
             <goals>
-              <goal>descriptor</goal>
+              <goal>generate-metadata</goal>
             </goals>
           </execution>
         </executions>
@@ -238,7 +238,7 @@
         <plugins>
           <plugin>
             <artifactId>maven-invoker-plugin</artifactId>
-            <version>1.4</version>
+            <version>1.5</version>
             <configuration>
               <debug>true</debug>
               <projectsDirectory>src/it</projectsDirectory>
@@ -322,6 +322,53 @@
         <sitePluginVersion>3.0-beta-1-SNAPSHOT</sitePluginVersion>
       </properties>
     </profile>
+    
+    <profile>
+      <id>m2e</id>
+      <properties>
+        <m2BuildDirectory>target</m2BuildDirectory>
+      </properties>
+      <activation>
+        <property>
+          <name>m2e.version</name>
+        </property>
+      </activation>
+      <build>
+        <directory>${m2BuildDirectory}</directory>
+        <plugins>
+          <plugin>
+            <groupId>org.maven.ide.eclipse</groupId>
+            <artifactId>lifecycle-mapping</artifactId>
+            <version>0.9.9-SNAPSHOT</version>
+            <configuration>
+              <mappingId>customizable</mappingId>
+              <configurators>
+                <configurator id="org.maven.ide.eclipse.jdt.javaConfigurator" />
+                <configurator id="org.maven.ide.eclipse.plexus.annotations.plexusConfigurator" />
+              </configurators>
+              <mojoExecutions>
+                <mojoExecution>org.apache.maven.plugins:maven-resources-plugin::</mojoExecution>
+              </mojoExecutions>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    
 
   </profiles>
+  
+  <repositories>
+    <repository>
+      <id>plexus.snapshots</id>
+      <url>http://oss.repository.sonatype.org/content/repositories/plexus-snapshots</url>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+    </repository>
+  </repositories>
+  
 </project>

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/it/checkstyle-report/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/checkstyle-report/pom.xml?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/checkstyle-report/pom.xml (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/checkstyle-report/pom.xml Sat Nov 14 22:21:48 2009
@@ -41,6 +41,11 @@
         <artifactId>maven-checkstyle-plugin</artifactId>
         <version>@pom.version@</version>
       </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>@sitePluginVersion@</version>
+      </plugin>      
     </plugins>
   </build>
   <reporting>

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/it/settings.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/it/settings.xml?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/it/settings.xml (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/it/settings.xml Sat Nov 14 22:21:48 2009
@@ -37,6 +37,18 @@
             <enabled>true</enabled>
           </snapshots>
         </repository>
+
+        <repository>
+          <id>plexus.snapshots</id>
+          <url>http://oss.repository.sonatype.org/content/repositories/plexus-snapshots</url>
+          <releases>
+            <enabled>false</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </repository>
+       
       </repositories>
       <pluginRepositories>
         <pluginRepository>
@@ -52,4 +64,5 @@
       </pluginRepositories>
     </profile>
   </profiles>
+  
 </settings>

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java?rev=836274&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java Sat Nov 14 22:21:48 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.checkstyle;
+
+import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 2.5
+ * @version $Id$
+ */
+public interface CheckstyleExecutor
+{
+
+    CheckstyleResults executeCheckstyle( CheckstyleExecutorRequest request )
+        throws CheckstyleExecutorException, CheckstyleException;
+}

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java?rev=836274&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java Sat Nov 14 22:21:48 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.checkstyle;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 2.5
+ * @version $Id$
+ */
+public class CheckstyleExecutorException
+    extends Exception
+{
+
+    /**
+     * 
+     */
+    public CheckstyleExecutorException()
+    {
+        // nothing
+    }
+
+    /**
+     * @param message
+     */
+    public CheckstyleExecutorException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * @param cause
+     */
+    public CheckstyleExecutorException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public CheckstyleExecutorException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java?rev=836274&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java Sat Nov 14 22:21:48 2009
@@ -0,0 +1,231 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.checkstyle;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+import com.puppycrawl.tools.checkstyle.DefaultLogger;
+import com.puppycrawl.tools.checkstyle.api.AuditListener;
+import com.puppycrawl.tools.checkstyle.api.Configuration;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 2.5
+ * @version $Id$
+ */
+public class CheckstyleExecutorRequest
+{
+    private Configuration configuration;
+    
+    /**
+     * Specifies the names filter of the source files to be used for Checkstyle.
+     */
+    private String includes;
+
+    /**
+     * Specifies the names filter of the source files to be excluded for Checkstyle.
+     */
+    private String excludes;
+    
+    private MavenProject project;
+    
+    private Log log;
+    
+    private String suppressionsLocation;
+    
+    private boolean includeTestSourceDirectory;
+    
+    private File testSourceDirectory;
+    
+    private File sourceDirectory;
+    
+    private boolean failsOnError;
+    
+    private AuditListener listener;
+    
+    private boolean consoleOutput;
+    
+    private DefaultLogger defaultLogger;
+    
+    private ByteArrayOutputStream stringOutputStream;
+    
+    public CheckstyleExecutorRequest(Configuration configuration)
+    {
+        this.configuration = configuration;
+    }
+
+    public Configuration getConfiguration()
+    {
+        return configuration;
+    }
+
+    public CheckstyleExecutorRequest setConfiguration( Configuration configuration )
+    {
+        this.configuration = configuration;
+        return this;
+    }
+
+    public String getIncludes()
+    {
+        return includes;
+    }
+
+    public CheckstyleExecutorRequest setIncludes( String includes )
+    {
+        this.includes = includes;
+        return this;
+    }
+
+    public String getExcludes()
+    {
+        return excludes;
+    }
+
+    public CheckstyleExecutorRequest setExcludes( String excludes )
+    {
+        this.excludes = excludes;
+        return this;
+    }
+
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+    public CheckstyleExecutorRequest setProject( MavenProject project )
+    {
+        this.project = project;
+        return this;
+    }
+
+    public Log getLog()
+    {
+        return log;
+    }
+
+    public CheckstyleExecutorRequest setLog( Log log )
+    {
+        this.log = log;
+        return this;
+    }
+
+    public String getSuppressionsLocation()
+    {
+        return suppressionsLocation;
+    }
+
+    public CheckstyleExecutorRequest setSuppressionsLocation( String suppressionsLocation )
+    {
+        this.suppressionsLocation = suppressionsLocation;
+        return this;
+    }
+
+    public boolean isIncludeTestSourceDirectory()
+    {
+        return includeTestSourceDirectory;
+    }
+
+    public CheckstyleExecutorRequest setIncludeTestSourceDirectory( boolean includeTestSourceDirectory )
+    {
+        this.includeTestSourceDirectory = includeTestSourceDirectory;
+        return this;
+    }
+
+    public File getTestSourceDirectory()
+    {
+        return testSourceDirectory;
+    }
+
+    public CheckstyleExecutorRequest setTestSourceDirectory( File testSourceDirectory )
+    {
+        this.testSourceDirectory = testSourceDirectory;
+        return this;
+    }
+
+    public File getSourceDirectory()
+    {
+        return sourceDirectory;
+    }
+
+    public CheckstyleExecutorRequest setSourceDirectory( File sourceDirectory )
+    {
+        this.sourceDirectory = sourceDirectory;
+        return this;
+    }
+
+    public boolean isFailsOnError()
+    {
+        return failsOnError;
+    }
+
+    public CheckstyleExecutorRequest setFailsOnError( boolean failsOnError )
+    {
+        this.failsOnError = failsOnError;
+        return this;
+    }
+
+    public AuditListener getListener()
+    {
+        return listener;
+    }
+
+    public CheckstyleExecutorRequest setListener( AuditListener listener )
+    {
+        this.listener = listener;
+        return this;
+    }
+
+    public boolean isConsoleOutput()
+    {
+        return consoleOutput;
+    }
+
+    public CheckstyleExecutorRequest setConsoleOutput( boolean consoleOutput )
+    {
+        this.consoleOutput = consoleOutput;
+        return this;
+    }
+    
+    public CheckstyleExecutorRequest setConsoleListener(DefaultLogger defaultLogger)
+    {
+        this.defaultLogger = defaultLogger;
+        return this;
+    }
+
+    public DefaultLogger getConsoleListener()
+    {
+        return this.defaultLogger;
+    }
+
+    public ByteArrayOutputStream getStringOutputStream()
+    {
+        return stringOutputStream;
+    }
+
+    public CheckstyleExecutorRequest setStringOutputStream( ByteArrayOutputStream stringOutputStream )
+    {
+        this.stringOutputStream = stringOutputStream;
+        return this;
+    }
+    
+}

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleExecutorRequest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.java Sat Nov 14 22:21:48 2009
@@ -27,10 +27,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
 import java.util.HashMap;
@@ -41,7 +38,6 @@
 import java.util.Properties;
 import java.util.ResourceBundle;
 
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.model.ReportPlugin;
@@ -57,7 +53,6 @@
 import org.codehaus.plexus.util.PathTool;
 import org.codehaus.plexus.util.StringUtils;
 
-import com.puppycrawl.tools.checkstyle.Checker;
 import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
 import com.puppycrawl.tools.checkstyle.DefaultLogger;
@@ -493,7 +488,7 @@
      * @readonly
      */
     private Renderer siteRenderer;
-    
+        
     private static final File[] EMPTY_FILE_ARRAY = new File[0];
 
     private ByteArrayOutputStream stringOutputStream;
@@ -513,7 +508,15 @@
      * @required
      * @readonly
      */
-    protected CheckstyleRssGenerator checkstyleRssGenerator;    
+    protected CheckstyleRssGenerator checkstyleRssGenerator;
+    
+    /**
+     * @since 2.5
+     * @component role="org.apache.maven.plugin.checkstyle.CheckstyleExecutor" role-hint="default"
+     * @required
+     * @readonly
+     */
+    protected CheckstyleExecutor checkstyleExecutor;    
 
     /** {@inheritDoc} */
     public String getName( Locale locale )
@@ -584,10 +587,9 @@
 
                 String configFile = getConfigFile();
                 Properties overridingProperties = getOverridingProperties();
-                Configuration config;
                 CheckstyleResults results;
 
-                config = ConfigurationLoader.loadConfiguration( configFile,
+                Configuration config = ConfigurationLoader.loadConfiguration( configFile,
                                                                 new PropertiesExpander( overridingProperties ) );
                 String effectiveEncoding =
                     StringUtils.isNotEmpty( encoding ) ? encoding : System.getProperty( "file.encoding", "UTF-8" );
@@ -644,6 +646,10 @@
             {
                 throw new MavenReportException( "Failed during checkstyle configuration", e );
             }
+            catch (CheckstyleExecutorException e)
+            {
+                throw new MavenReportException( "Failed during checkstyle execution", e );
+            }
             finally
             {
                 //be sure to restore original context classloader
@@ -781,141 +787,16 @@
     }
 
     private CheckstyleResults executeCheckstyle( Configuration config )
-        throws MavenReportException, CheckstyleException
+        throws MavenReportException, CheckstyleException, CheckstyleExecutorException
     {
-        File[] files;
-        try
-        {
-            files = getFilesToProcess( includes, excludes );
-        }
-        catch ( IOException e )
-        {
-            throw new MavenReportException( "Error getting files to process", e );
-        }
-
-        FilterSet filterSet = getSuppressions();
-
-        Checker checker = new Checker();
-
-        // setup classloader, needed to avoid "Unable to get class information
-        // for ..." errors
-        List classPathStrings;
-        List outputDirectories = new ArrayList();
-        try
-        {
-            classPathStrings = this.project.getCompileClasspathElements();
-            outputDirectories.add( this.project.getBuild().getOutputDirectory() );
-
-            if ( includeTestSourceDirectory && ( testSourceDirectory != null ) && ( testSourceDirectory.exists() )
-                && ( testSourceDirectory.isDirectory() ) )
-            {
-                classPathStrings = this.project.getTestClasspathElements();
-                outputDirectories.add( this.project.getBuild().getTestOutputDirectory() );
-            }
-        }
-        catch ( DependencyResolutionRequiredException e )
-        {
-            throw new MavenReportException( e.getMessage(), e );
-        }
-
-        List urls = new ArrayList( classPathStrings.size() );
-
-        Iterator iter = classPathStrings.iterator();
-        while ( iter.hasNext() )
-        {
-            try
-            {
-                urls.add( new File( ( (String) iter.next() ) ).toURL() );
-            }
-            catch ( MalformedURLException e )
-            {
-                throw new MavenReportException( e.getMessage(), e );
-            }
-        }
-
-        Iterator iterator = outputDirectories.iterator();
-        while ( iterator.hasNext() )
-        {
-            try
-            {
-                String outputDirectoryString = (String) iterator.next();
-                if ( outputDirectoryString != null )
-                {
-                    File outputDirectoryFile = new File( outputDirectoryString );
-                    if ( outputDirectoryFile.exists() )
-                    {
-                        URL outputDirectoryUrl = outputDirectoryFile.toURL();
-                        getLog().debug( "Adding the outputDirectory " + outputDirectoryUrl.toString()
-                            + " to the Checkstyle class path" );
-                        urls.add( outputDirectoryUrl );
-                    }
-                }
-            }
-            catch ( MalformedURLException e )
-            {
-                throw new MavenReportException( e.getMessage(), e );
-            }
-        }
-
-        URLClassLoader projectClassLoader = new URLClassLoader( (URL[]) urls.toArray( new URL[urls.size()] ), null );
-        checker.setClassloader( projectClassLoader );
-
-        checker.setModuleClassLoader( Thread.currentThread().getContextClassLoader() );
-
-        if ( filterSet != null )
-        {
-            checker.addFilter( filterSet );
-        }
-
-        checker.configure( config );
-
-        AuditListener listener = getListener();
-
-        if ( listener != null )
-        {
-            checker.addListener( listener );
-        }
-
-        if ( consoleOutput )
-        {
-            checker.addListener( getConsoleListener() );
-        }
-
-        CheckstyleReportListener sinkListener = new CheckstyleReportListener( sourceDirectory );
-        if ( includeTestSourceDirectory && ( testSourceDirectory != null ) && ( testSourceDirectory.exists() )
-            && ( testSourceDirectory.isDirectory() ) )
-        {
-            sinkListener.addSourceDirectory( testSourceDirectory );
-        }
-
-        checker.addListener( sinkListener );
-
-        ArrayList filesList = new ArrayList();
-        for (int i = 0; i < files.length; i++) {
-            filesList.add(files[i]);
-        }
-        int nbErrors = checker.process( filesList );
-
-        checker.destroy();
-
-        if ( stringOutputStream != null )
-        {
-            getLog().info( stringOutputStream.toString() );
-        }
-
-        if ( failsOnError && nbErrors > 0 )
-        {
-            // TODO: should be a failure, not an error. Report is not meant to
-            // throw an exception here (so site would
-            // work regardless of config), but should record this information
-            throw new MavenReportException( "There are " + nbErrors + " checkstyle errors." );
-        }
-        else if ( nbErrors > 0 )
-        {
-            getLog().info( "There are " + nbErrors + " checkstyle errors." );
-        }
-
-        return sinkListener.getResults();
+        CheckstyleExecutorRequest request = new CheckstyleExecutorRequest( config );
+        request.setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput ).setExcludes( excludes )
+            .setFailsOnError( failsOnError ).setIncludes( includes )
+            .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() ).setLog( getLog() )
+            .setProject( project ).setSourceDirectory( sourceDirectory ).setStringOutputStream( stringOutputStream )
+            .setSuppressionsLocation( suppressionsLocation ).setTestSourceDirectory( testSourceDirectory );
+        
+        return checkstyleExecutor.executeCheckstyle( request );
     }
 
     /** {@inheritDoc} */

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojo.java Sat Nov 14 22:21:48 2009
@@ -19,18 +19,40 @@
  * under the License.
  */
 
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Properties;
+
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.resource.ResourceManager;
+import org.codehaus.plexus.resource.loader.FileResourceCreationException;
+import org.codehaus.plexus.resource.loader.FileResourceLoader;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.MXParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParser;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.Reader;
+import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
+import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
+import com.puppycrawl.tools.checkstyle.DefaultLogger;
+import com.puppycrawl.tools.checkstyle.PackageNamesLoader;
+import com.puppycrawl.tools.checkstyle.PropertiesExpander;
+import com.puppycrawl.tools.checkstyle.XMLLogger;
+import com.puppycrawl.tools.checkstyle.api.AuditListener;
+import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
+import com.puppycrawl.tools.checkstyle.api.Configuration;
 
 /**
  * Perform a violation check against the last Checkstyle run to see if there are
@@ -41,7 +63,6 @@
  * @version $Id$
  * @goal check
  * @phase verify
- * @execute goal="checkstyle"
  * @requiresDependencyResolution compile
  */
 public class CheckstyleViolationCheckMojo
@@ -98,6 +119,14 @@
      * @since 2.2
      */
     private boolean skip;
+    
+    /**
+     * Skip checktyle execution will only scan the outputFile.
+     *
+     * @parameter expression="${checkstyle.skipExec}" default-value="false"
+     * @since 2.5
+     */
+    private boolean skipExec;    
 
     /**
      * Output the detected violations to the console.
@@ -106,13 +135,332 @@
      * @since 2.3
      */
     private boolean logViolationsToConsole;
+    
+    /**
+     * <p>
+     * Specifies the location of the XML configuration to use.
+     * </p>
+     *
+     * <p>
+     * Potential values are a filesystem path, a URL, or a classpath resource.
+     * This parameter expects that the contents of the location conform to the
+     * xml format (Checkstyle <a
+     * href="http://checkstyle.sourceforge.net/config.html#Modules">Checker
+     * module</a>) configuration of rulesets.
+     * </p>
+     *
+     * <p>
+     * This parameter is resolved as resource, URL, then file. If successfully
+     * resolved, the contents of the configuration is copied into the
+     * <code>${project.build.directory}/checkstyle-configuration.xml</code>
+     * file before being passed to Checkstyle as a configuration.
+     * </p>
+     *
+     * <p>
+     * There are 4 predefined rulesets.
+     * </p>
+     *
+     * <ul>
+     * <li><code>config/sun_checks.xml</code>: Sun Checks.</li>
+     * <li><code>config/turbine_checks.xml</code>: Turbine Checks.</li>
+     * <li><code>config/avalon_checks.xml</code>: Avalon Checks.</li>
+     * <li><code>config/maven_checks.xml</code>: Maven Source Checks.</li>
+     * </ul>
+     * @since 2.5
+     * @parameter expression="${checkstyle.config.location}"
+     *            default-value="config/sun_checks.xml"
+     */
+    private String configLocation;    
+
+    /**
+     * <p>
+     * Specifies the location of the properties file.
+     * </p>
+     *
+     * <p>
+     * This parameter is resolved as URL, File then resource. If successfully
+     * resolved, the contents of the properties location is copied into the
+     * <code>${project.build.directory}/checkstyle-checker.properties</code>
+     * file before being passed to Checkstyle for loading.
+     * </p>
+     *
+     * <p>
+     * The contents of the <code>propertiesLocation</code> will be made
+     * available to Checkstyle for specifying values for parameters within the
+     * xml configuration (specified in the <code>configLocation</code>
+     * parameter).
+     * </p>
+     *
+     * @parameter expression="${checkstyle.properties.location}"
+     * @since 2.5
+     */
+    private String propertiesLocation;
+    
+    /**
+     * Allows for specifying raw property expansion information.
+     *
+     * @parameter
+     */
+    private String propertyExpansion;
+    
+    /**
+     * <p>
+     * Specifies the location of the License file (a.k.a. the header file) that
+     * can be used by Checkstyle to verify that source code has the correct
+     * license header.
+     * </p>
+     * <p>
+     * You need to use ${checkstyle.header.file} in your Checkstyle xml
+     * configuration to reference the name of this header file.
+     * </p>
+     * <p>
+     * For instance:
+     * </p>
+     * <p>
+     * <code>
+     * &lt;module name="RegexpHeader">
+     *   &lt;property name="headerFile" value="${checkstyle.header.file}"/>
+     * &lt;/module>
+     * </code>
+     * </p>
+     *
+     * @parameter expression="${checkstyle.header.file}"
+     *            default-value="LICENSE.txt"
+     * @since 2.0-beta-2
+     */
+    private String headerLocation;    
+    
+    /**
+     * Specifies the cache file used to speed up Checkstyle on successive runs.
+     *
+     * @parameter default-value="${project.build.directory}/checkstyle-cachefile"
+     */
+    private String cacheFile;    
+    
+    /**
+     * The key to be used in the properties for the suppressions file.
+     *
+     * @parameter expression="${checkstyle.suppression.expression}"
+     *            default-value="checkstyle.suppressions.file"
+     * @since 2.1
+     */
+    private String suppressionsFileExpression;    
+ 
+    /**
+     * <p>
+     * Specifies the location of the suppressions XML file to use.
+     * </p>
+     *
+     * <p>
+     * This parameter is resolved as resource, URL, then file. If successfully
+     * resolved, the contents of the suppressions XML is copied into the
+     * <code>${project.build.directory}/checkstyle-supressions.xml</code> file
+     * before being passed to Checkstyle for loading.
+     * </p>
+     *
+     * <p>
+     * See <code>suppressionsFileExpression</code> for the property that will
+     * be made available to your checkstyle configuration.
+     * </p>
+     *
+     * @parameter expression="${checkstyle.suppressions.location}"
+     * @since 2.0-beta-2
+     */
+    private String suppressionsLocation;    
+    
+    /**
+     * The file encoding to use when reading the source files. If the property <code>project.build.sourceEncoding</code>
+     * is not set, the platform default encoding is used. <strong>Note:</strong> This parameter always overrides the
+     * property <code>charset</code> from Checkstyle's <code>TreeWalker</code> module.
+     *
+     * @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
+     * @since 2.2
+     */
+    private String encoding;    
+    
+    /**
+     * @since 2.5
+     * @component role="org.codehaus.plexus.resource.ResourceManager" role-hint="default"
+     * @required
+     * @readonly
+     */
+    protected ResourceManager locator;    
+    
+    /**
+     * @since 2.5
+     * @component role="org.apache.maven.plugin.checkstyle.CheckstyleExecutor" role-hint="default"
+     * @required
+     * @readonly
+     */
+    protected CheckstyleExecutor checkstyleExecutor;    
+    
+    /**
+     * Output errors to console.
+     *
+     * @parameter default-value="false"
+     */
+    private boolean consoleOutput;    
+    
+    /**
+     * The Maven Project Object.
+     *
+     * @parameter default-value="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+
+    /**
+     * If <code>null</code>, the Checkstyle plugin will display violations on stdout.
+     * Otherwise, a text file will be created with the violations.
+     *
+     * @parameter
+     */
+    private File useFile;
+
+    /**
+     * Specifies the names filter of the source files to be excluded for
+     * Checkstyle.
+     *
+     * @parameter expression="${checkstyle.excludes}"
+     */
+    private String excludes;    
+    
+    /**
+     * Specifies the names filter of the source files to be used for Checkstyle.
+     *
+     * @parameter expression="${checkstyle.includes}" default-value="**\/*.java"
+     * @required
+     */
+    private String includes;
+    
+    /**
+     * Specifies if the build should fail upon a violation.
+     *
+     * @parameter default-value="false"
+     */
+    private boolean failsOnError;    
+    
+    /**
+     * Specifies the location of the test source directory to be used for
+     * Checkstyle.
+     *
+     * @parameter default-value="${project.build.testSourceDirectory}"
+     * @since 2.2
+     */
+    private File testSourceDirectory;
 
+    /**
+     * Include or not the test source directory to be used for Checkstyle.
+     *
+     * @parameter default-value="${false}"
+     * @since 2.2
+     */
+    private boolean includeTestSourceDirectory;    
+    
+    /**
+     * Specifies the location of the source directory to be used for Checkstyle.
+     *
+     * @parameter default-value="${project.build.sourceDirectory}"
+     * @required
+     */
+    private File sourceDirectory;    
+    
+    private ByteArrayOutputStream stringOutputStream;
+    
+    
     /** {@inheritDoc} */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
+        
         if ( !skip )
         {
+
+            if ( !skipExec )
+            {
+                locator.addSearchPath( FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath() );
+                locator.addSearchPath( "url", "" );
+
+                locator.setOutputDirectory( new File( project.getBuild().getDirectory() ) );
+
+                ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
+
+                try
+                {
+                    // checkstyle will always use the context classloader in order
+                    // to load resources (dtds),
+                    // so we have to fix it
+                    ClassLoader checkstyleClassLoader = PackageNamesLoader.class.getClassLoader();
+                    Thread.currentThread().setContextClassLoader( checkstyleClassLoader );
+                    String configFile = getConfigFile();
+                    Properties overridingProperties = getOverridingProperties();
+                    Configuration config = ConfigurationLoader
+                        .loadConfiguration( configFile, new PropertiesExpander( overridingProperties ) );
+                    String effectiveEncoding = StringUtils.isNotEmpty( encoding ) ? encoding : System
+                        .getProperty( "file.encoding", "UTF-8" );
+                    if ( StringUtils.isEmpty( encoding ) )
+                    {
+                        getLog().warn(
+                                       "File encoding has not been set, using platform encoding " + effectiveEncoding
+                                           + ", i.e. build is platform dependent!" );
+                    }
+                    Configuration[] modules = config.getChildren();
+                    for ( int i = 0; i < modules.length; i++ )
+                    {
+                        Configuration module = modules[i];
+                        if ( "Checker".equals( module.getName() )
+                            || "com.puppycrawl.tools.checkstyle.Checker".equals( module.getName() ) )
+                        {
+                            if ( module instanceof DefaultConfiguration )
+                            {
+                                ( (DefaultConfiguration) module ).addAttribute( "charset", effectiveEncoding );
+                            }
+                            else
+                            {
+                                getLog().warn( "Failed to configure file encoding on module " + module );
+                            }
+                        }
+                        if ( "TreeWalker".equals( module.getName() )
+                            || "com.puppycrawl.tools.checkstyle.TreeWalker".equals( module.getName() ) )
+                        {
+                            if ( module instanceof DefaultConfiguration )
+                            {
+                                ( (DefaultConfiguration) module ).addAttribute( "cacheFile", cacheFile );
+                            }
+                            else
+                            {
+                                getLog().warn( "Failed to configure cache file on module " + module );
+                            }
+                        }
+                    }
+
+                    CheckstyleExecutorRequest request = new CheckstyleExecutorRequest( config );
+                    request.setConsoleListener( getConsoleListener() ).setConsoleOutput( consoleOutput )
+                        .setExcludes( excludes ).setFailsOnError( failsOnError ).setIncludes( includes )
+                        .setIncludeTestSourceDirectory( includeTestSourceDirectory ).setListener( getListener() )
+                        .setLog( getLog() ).setProject( project ).setSourceDirectory( sourceDirectory )
+                        .setStringOutputStream( stringOutputStream ).setSuppressionsLocation( suppressionsLocation )
+                        .setTestSourceDirectory( testSourceDirectory );
+
+                    checkstyleExecutor.executeCheckstyle( request );
+
+                }
+                catch ( CheckstyleException e )
+                {
+                    throw new MojoExecutionException( "Failed during checkstyle configuration", e );
+                }
+                catch ( CheckstyleExecutorException e )
+                {
+                    throw new MojoExecutionException( "Failed during checkstyle execution", e );
+                }
+                finally
+                {
+                    //be sure to restore original context classloader
+                    Thread.currentThread().setContextClassLoader( currentClassLoader );
+                }
+            
+            }
             if ( !"xml".equals( outputFileFormat ) )
             {
                 throw new MojoExecutionException( "Output format is '" + outputFileFormat
@@ -127,6 +475,8 @@
                 return;
             }
 
+            System.out.println("outputFile " + outputFile.getPath());
+            
             try
             {
                 XmlPullParser xpp = new MXParser();
@@ -204,7 +554,7 @@
 
     /**
      * Checks if the given severity is considered a violation.
-     *
+     * 
      * @param severity The severity to check
      * @return <code>true</code> if the given severity is a violation, otherwise <code>false</code>
      */
@@ -228,4 +578,191 @@
             return false;
         }
     }
+
+    private String getConfigFile()
+        throws MojoExecutionException
+    {
+        try
+        {
+            File configFile = locator.getResourceAsFile( configLocation, "checkstyle-checker.xml" );
+
+            if ( configFile == null )
+            {
+                throw new MojoExecutionException( "Unable to process config location: " + configLocation );
+            }
+            return configFile.getAbsolutePath();
+        }
+        catch ( org.codehaus.plexus.resource.loader.ResourceNotFoundException e )
+        {
+            throw new MojoExecutionException( "Unable to find configuration file at location " + configLocation, e );
+        }
+        catch ( FileResourceCreationException e )
+        {
+            throw new MojoExecutionException( "Unable to process configuration file location " + configLocation, e );
+        }
+
+    }
+
+    private Properties getOverridingProperties()
+        throws MojoExecutionException
+    {
+        Properties p = new Properties();
+
+        try
+        {
+            File propertiesFile = locator.resolveLocation( propertiesLocation, "checkstyle-checker.properties" );
+
+            if ( propertiesFile != null )
+            {
+                p.load( new FileInputStream( propertiesFile ) );
+            }
+
+            if ( StringUtils.isNotEmpty( propertyExpansion ) )
+            {
+                // Convert \ to \\, so that p.load will convert it back properly
+                propertyExpansion = StringUtils.replace( propertyExpansion, "\\", "\\\\" );
+                p.load( new ByteArrayInputStream( propertyExpansion.getBytes() ) );
+            }
+
+            // Workaround for MCHECKSTYLE-48
+            // Make sure that "config/maven-header.txt" is the default value
+            // for headerLocation, if configLocation="config/maven_checks.xml"
+            if ( "config/maven_checks.xml".equals( configLocation ) )
+            {
+                if ( "LICENSE.txt".equals( headerLocation ) )
+                {
+                    headerLocation = "config/maven-header.txt";
+                }
+            }
+            if ( StringUtils.isNotEmpty( headerLocation ) )
+            {
+                try
+                {
+                    File headerFile = locator.resolveLocation( headerLocation, "checkstyle-header.txt" );
+
+                    if ( headerFile != null )
+                    {
+                        p.setProperty( "checkstyle.header.file", headerFile.getAbsolutePath() );
+                    }
+                }
+                catch ( IOException e )
+                {
+                    throw new MojoExecutionException( "Unable to process header location: " + headerLocation, e );
+                }
+            }
+
+            if ( cacheFile != null )
+            {
+                p.setProperty( "checkstyle.cache.file", cacheFile );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Failed to get overriding properties", e );
+        }
+
+        if ( suppressionsFileExpression != null )
+        {
+            String suppresionFile = getSuppressionLocation();
+
+            if ( suppresionFile != null )
+            {
+                p.setProperty( suppressionsFileExpression, suppresionFile );
+            }
+        }
+
+        return p;
+    }
+
+    private String getSuppressionLocation()
+        throws MojoExecutionException
+    {
+        try
+        {
+            File suppressionsFile = locator.resolveLocation( suppressionsLocation, "checkstyle-suppressions.xml" );
+
+            if ( suppressionsFile == null )
+            {
+                return null;
+            }
+
+            return suppressionsFile.getAbsolutePath();
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Failed to process supressions location: " + suppressionsLocation, e );
+        }
+    }
+    
+    private DefaultLogger getConsoleListener()
+        throws MojoExecutionException
+    {
+        DefaultLogger consoleListener;
+
+        if ( useFile == null )
+        {
+            stringOutputStream = new ByteArrayOutputStream();
+            consoleListener = new DefaultLogger( stringOutputStream, false );
+        }
+        else
+        {
+            OutputStream out = getOutputStream( useFile );
+
+            consoleListener = new DefaultLogger( out, true );
+        }
+
+        return consoleListener;
+    }
+
+    private OutputStream getOutputStream( File file )
+        throws MojoExecutionException
+    {
+        File parentFile = file.getAbsoluteFile().getParentFile();
+
+        if ( !parentFile.exists() )
+        {
+            parentFile.mkdirs();
+        }
+
+        FileOutputStream fileOutputStream;
+        try
+        {
+            fileOutputStream = new FileOutputStream( file );
+        }
+        catch ( FileNotFoundException e )
+        {
+            throw new MojoExecutionException( "Unable to create output stream: " + file, e );
+        }
+        return fileOutputStream;
+    }
+
+    private AuditListener getListener()
+        throws MojoFailureException, MojoExecutionException
+    {
+        AuditListener listener = null;
+
+        if ( StringUtils.isNotEmpty( outputFileFormat ) )
+        {
+            File resultFile = outputFile;
+
+            OutputStream out = getOutputStream( resultFile );
+
+            if ( "xml".equals( outputFileFormat ) )
+            {
+                listener = new XMLLogger( out, true );
+            }
+            else if ( "plain".equals( outputFileFormat ) )
+            {
+                listener = new DefaultLogger( out, true );
+            }
+            else
+            {
+                throw new MojoFailureException( "Invalid output file format: (" + outputFileFormat
+                    + "). Must be 'plain' or 'xml'." );
+            }
+        }
+
+        return listener;
+    }
+    
 }
\ No newline at end of file

Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java?rev=836274&view=auto
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java (added)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java Sat Nov 14 22:21:48 2009
@@ -0,0 +1,262 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.checkstyle;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.codehaus.plexus.resource.ResourceManager;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
+
+import com.puppycrawl.tools.checkstyle.Checker;
+import com.puppycrawl.tools.checkstyle.api.AuditListener;
+import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
+import com.puppycrawl.tools.checkstyle.api.FilterSet;
+import com.puppycrawl.tools.checkstyle.filters.SuppressionsLoader;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @plexus.component role="org.apache.maven.plugin.checkstyle.CheckstyleExecutor" role-hint="default"
+ * @since 2.5
+ * @version $Id$
+ */
+public class DefaultCheckstyleExecutor
+    implements CheckstyleExecutor
+{
+    
+    /**
+     * @plexus.requirement role="org.codehaus.plexus.resource.ResourceManager" role-hint="default"
+     */
+    private ResourceManager locator;    
+    
+    private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+    public CheckstyleResults executeCheckstyle( CheckstyleExecutorRequest request )
+        throws CheckstyleExecutorException, CheckstyleException
+    {
+        File[] files;
+        try
+        {
+            files = getFilesToProcess( request );
+        }
+        catch ( IOException e )
+        {
+            throw new CheckstyleExecutorException( "Error getting files to process", e );
+        }
+
+        FilterSet filterSet = getSuppressions( request );
+
+        Checker checker = new Checker();
+
+        // setup classloader, needed to avoid "Unable to get class information
+        // for ..." errors
+        List classPathStrings = new ArrayList();
+        List outputDirectories = new ArrayList();
+        try
+        {
+            classPathStrings = request.getProject().getCompileClasspathElements();
+            outputDirectories.add( request.getProject().getBuild().getOutputDirectory() );
+
+            if ( request.isIncludeTestSourceDirectory() && ( request.getSourceDirectory() != null )
+                && ( request.getTestSourceDirectory().exists() ) && ( request.getTestSourceDirectory().isDirectory() ) )
+            {
+                classPathStrings = request.getProject().getTestClasspathElements();
+                outputDirectories.add( request.getProject().getBuild().getTestOutputDirectory() );
+            }
+        }
+        catch ( DependencyResolutionRequiredException e )
+        {
+            throw new CheckstyleExecutorException( e.getMessage(), e );
+        }
+
+        if (classPathStrings == null)
+        {
+            classPathStrings = Collections.EMPTY_LIST;
+        }
+        
+        List urls = new ArrayList( classPathStrings.size() );
+
+        Iterator iter = classPathStrings.iterator();
+        while ( iter.hasNext() )
+        {
+            try
+            {
+                urls.add( new File( ( (String) iter.next() ) ).toURL() );
+            }
+            catch ( MalformedURLException e )
+            {
+                throw new CheckstyleExecutorException( e.getMessage(), e );
+            }
+        }
+
+        Iterator iterator = outputDirectories.iterator();
+        while ( iterator.hasNext() )
+        {
+            try
+            {
+                String outputDirectoryString = (String) iterator.next();
+                if ( outputDirectoryString != null )
+                {
+                    File outputDirectoryFile = new File( outputDirectoryString );
+                    if ( outputDirectoryFile.exists() )
+                    {
+                        URL outputDirectoryUrl = outputDirectoryFile.toURL();
+                        request.getLog().debug(
+                                                "Adding the outputDirectory " + outputDirectoryUrl.toString()
+                                                    + " to the Checkstyle class path" );
+                        urls.add( outputDirectoryUrl );
+                    }
+                }
+            }
+            catch ( MalformedURLException e )
+            {
+                throw new CheckstyleExecutorException( e.getMessage(), e );
+            }
+        }
+
+        URLClassLoader projectClassLoader = new URLClassLoader( (URL[]) urls.toArray( new URL[urls.size()] ), null );
+        checker.setClassloader( projectClassLoader );
+
+        checker.setModuleClassLoader( Thread.currentThread().getContextClassLoader() );
+
+        if ( filterSet != null )
+        {
+            checker.addFilter( filterSet );
+        }
+
+        checker.configure( request.getConfiguration() );
+
+        AuditListener listener = request.getListener();
+
+        if ( listener != null )
+        {
+            checker.addListener( listener );
+        }
+
+        if ( request.isConsoleOutput() )
+        {
+            checker.addListener( request.getConsoleListener() );
+        }
+
+        CheckstyleReportListener sinkListener = new CheckstyleReportListener( request.getSourceDirectory() );
+        if ( request.isIncludeTestSourceDirectory() && ( request.getTestSourceDirectory() != null )
+            && ( request.getTestSourceDirectory().exists() ) && ( request.getTestSourceDirectory().isDirectory() ) )
+        {
+            sinkListener.addSourceDirectory( request.getTestSourceDirectory() );
+        }
+
+        checker.addListener( sinkListener );
+
+        ArrayList filesList = new ArrayList();
+        for ( int i = 0; i < files.length; i++ )
+        {
+            filesList.add( files[i] );
+        }
+        int nbErrors = checker.process( filesList );
+
+        checker.destroy();
+
+        if ( request.getStringOutputStream() != null )
+        {
+            request.getLog().info( request.getStringOutputStream().toString() );
+        }
+
+        if ( request.isFailsOnError() && nbErrors > 0 )
+        {
+            // TODO: should be a failure, not an error. Report is not meant to
+            // throw an exception here (so site would
+            // work regardless of config), but should record this information
+            throw new CheckstyleExecutorException( "There are " + nbErrors + " checkstyle errors." );
+        }
+        else if ( nbErrors > 0 )
+        {
+            request.getLog().info( "There are " + nbErrors + " checkstyle errors." );
+        }
+
+        return sinkListener.getResults();
+    }
+
+    private File[] getFilesToProcess( CheckstyleExecutorRequest request )
+        throws IOException
+    {
+        StringBuffer excludesStr = new StringBuffer();
+
+        if ( StringUtils.isNotEmpty( request.getExcludes() ) )
+        {
+            excludesStr.append( request.getExcludes() );
+        }
+
+        String[] defaultExcludes = FileUtils.getDefaultExcludes();
+        for ( int i = 0; i < defaultExcludes.length; i++ )
+        {
+            if ( excludesStr.length() > 0 )
+            {
+                excludesStr.append( "," );
+            }
+
+            excludesStr.append( defaultExcludes[i] );
+        }
+
+        List files = FileUtils.getFiles( request.getSourceDirectory(), request.getIncludes(), excludesStr.toString() );
+        if ( request.isIncludeTestSourceDirectory() && ( request.getTestSourceDirectory() != null )
+            && ( request.getTestSourceDirectory().exists() ) && ( request.getTestSourceDirectory().isDirectory() ) )
+        {
+            files.addAll( FileUtils.getFiles( request.getTestSourceDirectory(), request.getIncludes(), excludesStr
+                .toString() ) );
+        }
+
+        return (File[]) files.toArray( EMPTY_FILE_ARRAY );
+    }
+
+    private FilterSet getSuppressions( CheckstyleExecutorRequest request )
+        throws CheckstyleExecutorException
+    {
+        try
+        {
+            File suppressionsFile = locator.resolveLocation( request.getSuppressionsLocation(),
+                                                             "checkstyle-suppressions.xml" );
+
+            if ( suppressionsFile == null )
+            {
+                return null;
+            }
+
+            return SuppressionsLoader.loadSuppressions( suppressionsFile.getAbsolutePath() );
+        }
+        catch ( CheckstyleException ce )
+        {
+            throw new CheckstyleExecutorException( "failed to load suppressions location: "
+                + request.getSuppressionsLocation(), ce );
+        }
+        catch ( IOException e )
+        {
+            throw new CheckstyleExecutorException( "Failed to process supressions location: "
+                + request.getSuppressionsLocation(), e );
+        }
+    }
+}

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/DefaultCheckstyleExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java Sat Nov 14 22:21:48 2009
@@ -45,19 +45,14 @@
  *                   role-hint="default"
  */
 public class DefaultCheckstyleRssGenerator
-    implements CheckstyleRssGenerator, Serviceable
+    implements CheckstyleRssGenerator
 {
    
     /**
-     * Velocity Component.
+     * @plexus.requirement
      */
     private VelocityComponent velocityComponent;
 
-    /**
-     * ServiceLocator used to lookup VelocityComponent
-     * Fix for MCHECKSTYLE-101 to avoid VelocityComponent beeing initialized when skip=true
-     */
-    private ServiceLocator serviceLocator;
     
     /**
      * @see org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator#generateRSS(org.apache.maven.plugin.checkstyle.CheckstyleResults)
@@ -65,17 +60,6 @@
     public void generateRSS( CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest )
         throws MavenReportException
     {
-        if ( velocityComponent == null )
-        {
-            try
-            {
-                velocityComponent = (VelocityComponent) serviceLocator.lookup( VelocityComponent.ROLE );
-            }
-            catch ( ComponentLookupException e )
-            {
-                throw new MavenReportException( "Failed to setup Velocity", e );
-            }
-        }
 
         VelocityTemplate vtemplate = new VelocityTemplate( velocityComponent, CheckstyleReport.PLUGIN_RESOURCES );
         vtemplate.setLog( checkstyleRssGeneratorRequest.getLog() );
@@ -111,9 +95,4 @@
         }
     }
     
-    /** {@inheritDoc} */
-    public void service( ServiceLocator locator )
-    {
-        this.serviceLocator = locator;
-    }
 }

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportTest.java?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportTest.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleReportTest.java Sat Nov 14 22:21:48 2009
@@ -86,7 +86,7 @@
     public void testMinConfiguration()
         throws Exception
     {
-        File htmlFile = generateReport( "min-plugin-config.xml" );
+        generateReport( "min-plugin-config.xml" );
     }
 
     public void testCustomConfiguration()
@@ -143,9 +143,10 @@
         }
         catch ( Exception e )
         {
-            if ( !( e.getCause().getCause() instanceof DependencyResolutionRequiredException ) )
+            if ( !( e.getCause().getCause().getCause() instanceof DependencyResolutionRequiredException ) )
             {
-                fail( "Must throw exception on errors" );
+                e.printStackTrace();
+                fail( "Must throw exception DependencyResolutionRequiredException on errors and not " + e.getClass().getName() + ", " + e.getMessage() );
             }
         }
     }

Modified: maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java?rev=836274&r1=836273&r2=836274&view=diff
==============================================================================
--- maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java (original)
+++ maven/plugins/trunk/maven-checkstyle-plugin/src/test/java/org/apache/maven/plugin/checkstyle/CheckstyleViolationCheckMojoTest.java Sat Nov 14 22:21:48 2009
@@ -19,12 +19,14 @@
  * under the License.
  */
 
+import java.io.File;
+
+import org.apache.maven.model.Build;
 import org.apache.maven.plugin.Mojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-
-import java.io.File;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 
 /**
  * @author Edwin Punzalan
@@ -33,15 +35,24 @@
 public class CheckstyleViolationCheckMojoTest
     extends AbstractMojoTestCase
 {
+    
+    
+    
     public void testDefaultConfig()
         throws Exception
     {
         File pluginXmlFile = new File( getBasedir(), "src/test/plugin-configs/check-plugin-config.xml" );
 
-        Mojo mojo = lookupMojo( "check", pluginXmlFile );
-
+        CheckstyleViolationCheckMojo mojo = (CheckstyleViolationCheckMojo) lookupMojo( "check", pluginXmlFile );
+        
+        mojoSetup( mojo );
+        
         assertNotNull( "Mojo found.", mojo );
-
+        
+        assertNotNull( "project null.", mojo.project );
+        
+        assertNotNull( "locator null.", mojo.locator );
+        
         try
         {
             mojo.execute();
@@ -63,6 +74,8 @@
 
         assertNotNull( "Mojo found.", mojo );
 
+        mojoSetup( mojo );
+        
         setVariableValueToObject( mojo, "outputFileFormat", "plain" );
 
         try
@@ -86,6 +99,8 @@
 
         assertNotNull( "Mojo found.", mojo );
 
+        mojoSetup( mojo );
+        
         setVariableValueToObject( mojo, "outputFile", new File( "target/NoSuchFile.xml" ) );
 
         mojo.execute();
@@ -100,8 +115,44 @@
 
         assertNotNull( "Mojo found.", mojo );
 
+        mojoSetup( mojo );
+        
         setVariableValueToObject( mojo, "failOnViolation", Boolean.FALSE );
 
         mojo.execute();
     }
+    
+    protected void mojoSetup( Mojo mojo )
+        throws Exception
+    {
+        // mojo setup
+
+        setVariableValueToObject( mojo, "project", new MavenProjectStub()
+        {
+
+            public File getFile()
+            {
+                return new File( getBasedir(), "target/classes" );
+            }
+
+            public Build getBuild()
+            {
+                return new Build()
+                {
+                    public String getDirectory()
+                    {
+                        return getBasedir() + "/target/classes";
+                    }
+                };
+            }
+
+        } );
+
+        setVariableValueToObject( mojo, "configLocation", "config/sun_checks.xml" );
+        setVariableValueToObject( mojo, "cacheFile", getBasedir() + "/target/classes/checkstyle-cachefile" );
+        setVariableValueToObject( mojo, "sourceDirectory", new File( getBasedir(), "src/test/plugin-configs/src" ));// new File( getBasedir() + "/target" ) );
+        setVariableValueToObject( mojo, "encoding", "UTF-8" );
+        setVariableValueToObject( mojo, "skipExec", Boolean.TRUE );
+
+    }
 }