Coverage Report - org.apache.maven.plugin.checkstyle.rss.DefaultCheckstyleRssGenerator
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultCheckstyleRssGenerator
63%
14/22
N/A
9
 
 1  
 package org.apache.maven.plugin.checkstyle.rss;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.IOException;
 23  
 
 24  
 import org.apache.maven.plugin.MojoExecutionException;
 25  
 import org.apache.maven.plugin.checkstyle.CheckstyleReport;
 26  
 import org.apache.maven.plugin.checkstyle.CheckstyleResults;
 27  
 import org.apache.maven.plugin.checkstyle.VelocityTemplate;
 28  
 import org.apache.maven.reporting.MavenReportException;
 29  
 import org.apache.velocity.VelocityContext;
 30  
 import org.apache.velocity.context.Context;
 31  
 import org.apache.velocity.exception.ResourceNotFoundException;
 32  
 import org.apache.velocity.exception.VelocityException;
 33  
 import org.codehaus.plexus.util.StringUtils;
 34  
 import org.codehaus.plexus.velocity.VelocityComponent;
 35  
 
 36  
 import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
 37  
 
 38  
 /**
 39  
  * @author Olivier Lamy
 40  
  * @since 2.4
 41  
  * @plexus.component role="org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator"
 42  
  *                   role-hint="default"
 43  
  */
 44  11
 public class DefaultCheckstyleRssGenerator
 45  
     implements CheckstyleRssGenerator
 46  
 {
 47  
    
 48  
     /**
 49  
      * @plexus.requirement
 50  
      */
 51  
     private VelocityComponent velocityComponent;
 52  
 
 53  
     
 54  
     /**
 55  
      * @see org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator#generateRSS(org.apache.maven.plugin.checkstyle.CheckstyleResults)
 56  
      */
 57  
     public void generateRSS( CheckstyleResults results, CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest )
 58  
         throws MavenReportException
 59  
     {
 60  
 
 61  16
         VelocityTemplate vtemplate = new VelocityTemplate( velocityComponent, CheckstyleReport.PLUGIN_RESOURCES );
 62  16
         vtemplate.setLog( checkstyleRssGeneratorRequest.getLog() );
 63  
 
 64  16
         Context context = new VelocityContext();
 65  16
         context.put( "results", results );
 66  16
         context.put( "project", checkstyleRssGeneratorRequest.getMavenProject() );
 67  16
         context.put( "copyright", checkstyleRssGeneratorRequest.getCopyright() );
 68  16
         context.put( "levelInfo", SeverityLevel.INFO );
 69  16
         context.put( "levelWarning", SeverityLevel.WARNING );
 70  16
         context.put( "levelError", SeverityLevel.ERROR );
 71  16
         context.put( "stringutils", new StringUtils() );
 72  
 
 73  
         try
 74  
         {
 75  16
             vtemplate.generate( checkstyleRssGeneratorRequest.getOutputDirectory().getPath() + "/checkstyle.rss",
 76  
                                 "checkstyle-rss.vm", context );
 77  
         }
 78  0
         catch ( ResourceNotFoundException e )
 79  
         {
 80  0
             throw new MavenReportException( "Unable to find checkstyle-rss.vm resource.", e );
 81  
         }
 82  0
         catch ( MojoExecutionException e )
 83  
         {
 84  0
             throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
 85  
         }
 86  0
         catch ( VelocityException e )
 87  
         {
 88  0
             throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
 89  
         }
 90  0
         catch ( IOException e )
 91  
         {
 92  0
             throw new MavenReportException( "Unable to generate checkstyle.rss.", e );
 93  16
         }
 94  16
     }
 95  
     
 96  
 }