Author: olamy Date: Thu Sep 10 21:59:24 2009 New Revision: 813614 URL: http://svn.apache.org/viewvc?rev=813614&view=rev Log: [MCHECKSTYLE-123] start some refactoring with moving rss generation to a dedicated component.
Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java (with props) maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java (with props) maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java (with props) Modified: maven/plugins/trunk/maven-checkstyle-plugin/pom.xml maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/CheckstyleReport.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=813614&r1=813613&r2=813614&view=diff ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/pom.xml (original) +++ maven/plugins/trunk/maven-checkstyle-plugin/pom.xml Thu Sep 10 21:59:24 2009 @@ -220,6 +220,20 @@ </plugin> </plugins> </pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-maven-plugin</artifactId> + <version>1.3.4</version> + <executions> + <execution> + <goals> + <goal>descriptor</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> </build> <profiles> 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=813614&r1=813613&r2=813614&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 Thu Sep 10 21:59:24 2009 @@ -38,6 +38,8 @@ import org.apache.maven.doxia.tools.SiteTool; import org.apache.maven.model.ReportPlugin; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator; +import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGeneratorRequest; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.AbstractMavenReport; import org.apache.maven.reporting.MavenReportException; @@ -90,9 +92,8 @@ */ public class CheckstyleReport extends AbstractMavenReport - implements Serviceable { - private static final String PLUGIN_RESOURCES = "org/apache/maven/plugin/checkstyle"; + public static final String PLUGIN_RESOURCES = "org/apache/maven/plugin/checkstyle"; /** * @deprecated Remove with format parameter. @@ -502,24 +503,7 @@ * @readonly */ private Renderer siteRenderer; - - /** - * Velocity Component. - */ - private VelocityComponent velocityComponent; - - /** - * ServiceLocator used to lookup VelocityComponent - * Fix for MCHECKSTYLE-101 to avoid VelocityComponent beeing initialized when skip=true - */ - private ServiceLocator serviceLocator; - - /** {...@inheritdoc} */ - public void service( ServiceLocator locator ) - { - this.serviceLocator = locator; - } - + private static final File[] EMPTY_FILE_ARRAY = new File[0]; private ByteArrayOutputStream stringOutputStream; @@ -530,6 +514,16 @@ * @readonly */ private ResourceManager locator; + + /** + * CheckstyleRssGenerator. + * + * @since 2.4 + * @component role="org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator" role-hint="default" + * @required + * @readonly + */ + protected CheckstyleRssGenerator checkstyleRssGenerator; /** {...@inheritdoc} */ public String getName( Locale locale ) @@ -641,7 +635,9 @@ generateMainReport( results, config, moduleFactory, bundle ); if ( enableRSS ) { - generateRSS( results ); + CheckstyleRssGeneratorRequest request = + new CheckstyleRssGeneratorRequest( this.project, this.getCopyright(), outputDirectory, getLog() ); + checkstyleRssGenerator.generateRSS( results, request ); } } @@ -671,55 +667,7 @@ } } - private void generateRSS( CheckstyleResults results ) - 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, PLUGIN_RESOURCES ); - vtemplate.setLog( getLog() ); - - Context context = new VelocityContext(); - context.put( "results", results ); - context.put( "project", project ); - context.put( "copyright", getCopyright() ); - context.put( "levelInfo", SeverityLevel.INFO ); - context.put( "levelWarning", SeverityLevel.WARNING ); - context.put( "levelError", SeverityLevel.ERROR ); - context.put( "stringutils", new StringUtils() ); - - try - { - vtemplate.generate( outputDirectory.getPath() + "/checkstyle.rss", "checkstyle-rss.vm", context ); - } - catch ( ResourceNotFoundException e ) - { - throw new MavenReportException( "Unable to find checkstyle-rss.vm resource.", e ); - } - catch ( MojoExecutionException e ) - { - throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); - } - catch ( VelocityException e ) - { - throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); - } - catch ( IOException e ) - { - throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); - } - } - + private String getCopyright() { String copyright; Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java?rev=813614&view=auto ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java (added) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java Thu Sep 10 21:59:24 2009 @@ -0,0 +1,36 @@ +package org.apache.maven.plugin.checkstyle.rss; + +/* + * 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. + */ + +import org.apache.maven.plugin.checkstyle.CheckstyleResults; +import org.apache.maven.reporting.MavenReportException; + + + +/** + * @author Olivier Lamy + * @since 2.4 + * + */ +public interface CheckstyleRssGenerator +{ + void generateRSS( CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest ) + throws MavenReportException; +} Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGenerator.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java?rev=813614&view=auto ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java (added) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java Thu Sep 10 21:59:24 2009 @@ -0,0 +1,90 @@ +package org.apache.maven.plugin.checkstyle.rss; + +import java.io.File; + +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; + +/* + * 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. + */ + +/** + * @author Olivier Lamy + * @since 2.4 + * + */ +public class CheckstyleRssGeneratorRequest +{ + private MavenProject mavenProject; + + private String copyright; + + private File outputDirectory; + + private Log log; + + public CheckstyleRssGeneratorRequest( MavenProject mavenProject, String copyright, File outputDirectory, Log log ) + { + this.mavenProject = mavenProject; + this.copyright = copyright; + this.outputDirectory = outputDirectory; + this.log = log; + } + + public MavenProject getMavenProject() + { + return mavenProject; + } + + public void setMavenProject( MavenProject mavenProject ) + { + this.mavenProject = mavenProject; + } + + public String getCopyright() + { + return copyright; + } + + public void setCopyright( String copyright ) + { + this.copyright = copyright; + } + + public File getOutputDirectory() + { + return outputDirectory; + } + + public void setOutputDirectory( File outputDirectory ) + { + this.outputDirectory = outputDirectory; + } + + public Log getLog() + { + return log; + } + + public void setLog( Log log ) + { + this.log = log; + } + +} Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/CheckstyleRssGeneratorRequest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: 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=813614&view=auto ============================================================================== --- maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java (added) +++ maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java Thu Sep 10 21:59:24 2009 @@ -0,0 +1,119 @@ +package org.apache.maven.plugin.checkstyle.rss; + +/* + * 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. + */ + +import java.io.IOException; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.checkstyle.CheckstyleReport; +import org.apache.maven.plugin.checkstyle.CheckstyleResults; +import org.apache.maven.plugin.checkstyle.VelocityTemplate; +import org.apache.maven.reporting.MavenReportException; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.context.Context; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.apache.velocity.exception.VelocityException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceLocator; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Serviceable; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.velocity.VelocityComponent; + +import com.puppycrawl.tools.checkstyle.api.SeverityLevel; + +/** + * @author Olivier Lamy + * @since 2.4 + * @plexus.component role="org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator" + * role-hint="default" + */ +public class DefaultCheckstyleRssGenerator + implements CheckstyleRssGenerator, Serviceable +{ + + /** + * Velocity Component. + */ + 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) + */ + 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() ); + + Context context = new VelocityContext(); + context.put( "results", results ); + context.put( "project", checkstyleRssGeneratorRequest.getMavenProject() ); + context.put( "copyright", checkstyleRssGeneratorRequest.getCopyright() ); + context.put( "levelInfo", SeverityLevel.INFO ); + context.put( "levelWarning", SeverityLevel.WARNING ); + context.put( "levelError", SeverityLevel.ERROR ); + context.put( "stringutils", new StringUtils() ); + + try + { + vtemplate.generate( checkstyleRssGeneratorRequest.getOutputDirectory().getPath() + "/checkstyle.rss", "checkstyle-rss.vm", context ); + } + catch ( ResourceNotFoundException e ) + { + throw new MavenReportException( "Unable to find checkstyle-rss.vm resource.", e ); + } + catch ( MojoExecutionException e ) + { + throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); + } + catch ( VelocityException e ) + { + throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); + } + catch ( IOException e ) + { + throw new MavenReportException( "Unable to generate checkstyle.rss.", e ); + } + } + + /** {...@inheritdoc} */ + public void service( ServiceLocator locator ) + { + this.serviceLocator = locator; + } +} Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-checkstyle-plugin/src/main/java/org/apache/maven/plugin/checkstyle/rss/DefaultCheckstyleRssGenerator.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision