Coverage Report - org.apache.maven.changes.ChangesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesMojo
0% 
0% 
1,4
 
 1  
 package org.apache.maven.changes;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.maven.doxia.siterenderer.Renderer;
 20  
 import org.apache.maven.project.MavenProject;
 21  
 import org.apache.maven.reporting.AbstractMavenReport;
 22  
 import org.apache.maven.reporting.MavenReportException;
 23  
 import org.codehaus.plexus.util.FileUtils;
 24  
 
 25  
 import java.io.File;
 26  
 import java.io.IOException;
 27  
 import java.net.URL;
 28  
 import java.util.Locale;
 29  
 import java.util.ResourceBundle;
 30  
 
 31  
 /**
 32  
  * Goal which creates a nicely formatted Changes Report in html format from a changes.xml file.
 33  
  *
 34  0
  * @goal changes-report
 35  0
  * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
 36  
  * @version $Id: org.apache.maven.changes.ChangesMojo.html 816584 2012-05-08 12:33:35Z hboutemy $
 37  
  */
 38  0
 public class ChangesMojo
 39  
     extends AbstractMavenReport
 40  
 {
 41  
     /**
 42  
      * Directory where reports will go.
 43  
      *
 44  
      * @parameter expression="${project.build.directory}/site "
 45  
      * @required
 46  
      * @readonly
 47  
      */
 48  
     private String outputDirectory;
 49  
 
 50  
     /**
 51  
      * @parameter expression="${component.org.apache.maven.doxia.siterenderer.Renderer}"
 52  
      * @required
 53  
      * @readonly
 54  
      */
 55  
     private Renderer siteRenderer;
 56  
 
 57  
     /**
 58  
      * @parameter expression="${project}"
 59  
      * @required
 60  
      * @readonly
 61  
      */
 62  
     private MavenProject project;
 63  
 
 64  
     /**
 65  
      * The path of the changes.xml file that will be converted into an html report.
 66  
      *
 67  
      * @parameter expression="${basedir}/src/changes/changes.xml"
 68  
      * @required
 69  
      */
 70  
     private String xmlPath;
 71  
 
 72  
     /**
 73  
      * Template string that is used to discover the URL to use to display an issue report.
 74  
      * There are 2 template tokens you can use. %URL%: this is computed by getting the
 75  
      * &lt;issueManagement&gt;&lt;url&gt; value from the POM, and removing the context path. %ISSUE% :
 76  
      * this is the issue number.
 77  
      * <p>
 78  
      * <strong>Note:</strong> In versions of this plugin prior to 2.0-beta-2 this parameter was called
 79  
      * <code>link_template</code>.
 80  
      * </p>
 81  
      * 
 82  
      * @parameter expression="%URL%/ViewIssue.jspa?key=%ISSUE%"
 83  
      *
 84  0
      */
 85  0
     private String issueLinkTemplate;
 86  
 
 87  
     /**
 88  0
      * @parameter expression="${project.issueManagement.url}"
 89  0
      * @readonly
 90  
      */
 91  0
     private String url;
 92  0
 
 93  0
     public boolean canGenerateReport()
 94  0
     {
 95  0
         File xmlFile = new File( xmlPath );
 96  0
         return xmlFile.exists();
 97  0
     }
 98  0
 
 99  0
     private void copyStaticResources()
 100  0
         throws MavenReportException
 101  0
     {
 102  0
         final String pluginResourcesBase = "org/apache/maven/plugin/changes";
 103  0
         String resourceNames[] =
 104  0
             {"images/add.gif", "images/fix.gif", "images/remove.gif", "images/rss.png", "images/update.gif"};
 105  0
         try
 106  0
         {
 107  0
             getLog().debug( "Copying static resources." );
 108  0
             for ( int i = 0; i < resourceNames.length; i++ )
 109  0
             {
 110  0
                 URL url =
 111  0
                     this.getClass().getClassLoader().getResource( pluginResourcesBase + "/" + resourceNames[i] );
 112  0
                 FileUtils.copyURLToFile( url, new File( outputDirectory, resourceNames[i] ) );
 113  0
             }
 114  0
         }
 115  0
         catch ( IOException e )
 116  0
         {
 117  0
             throw new MavenReportException( "Unable to copy static resources." );
 118  0
         }
 119  0
     }
 120  0
 
 121  0
     public void executeReport( Locale locale )
 122  0
         throws MavenReportException
 123  0
     {
 124  0
         ChangesReportGenerator report = new ChangesReportGenerator( xmlPath, getLog() );
 125  0
 
 126  0
         if ( ( url == null ) || ( url.trim().equals( "" ) ) )
 127  0
         {
 128  0
             getLog().warn( getBundle( locale ).getString( "report.changes.warn.url" ) );
 129  0
         }
 130  0
 
 131  0
         report.setIssueLink( issueLinkTemplate );
 132  0
         report.setUrl( url );
 133  0
         report.doGenerateReport( getBundle( locale ), getSink() );
 134  0
 
 135  0
         // Copy the images
 136  0
         copyStaticResources();
 137  0
     }
 138  0
 
 139  0
     public String getName( Locale locale )
 140  0
     {
 141  0
         return getBundle( locale ).getString( "report.changes.name" );
 142  0
     }
 143  0
 
 144  0
     public String getDescription( Locale locale )
 145  0
     {
 146  0
         return getBundle( locale ).getString( "report.changes.description" );
 147  0
     }
 148  0
 
 149  0
     protected Renderer getSiteRenderer()
 150  0
     {
 151  0
         return siteRenderer;
 152  0
     }
 153  0
 
 154  0
     protected MavenProject getProject()
 155  0
     {
 156  0
         return project;
 157  0
     }
 158  0
 
 159  0
     public String getOutputName()
 160  0
     {
 161  0
         return "changes-report";
 162  0
     }
 163  0
 
 164  0
     protected String getOutputDirectory()
 165  0
     {
 166  0
         return outputDirectory;
 167  0
     }
 168  0
 
 169  0
     private ResourceBundle getBundle( Locale locale )
 170  0
     {
 171  0
         return ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() );
 172  
     }
 173  0
 }