Coverage Report - org.apache.maven.plugin.changes.ChangesMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
ChangesMojo
0%
0/29
0%
0/6
1.857
 
 1  
 package org.apache.maven.plugin.changes;
 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.File;
 23  
 import java.io.IOException;
 24  
 import java.net.URL;
 25  
 import java.util.Locale;
 26  
 import java.util.Map;
 27  
 import java.util.ResourceBundle;
 28  
 
 29  
 import org.apache.maven.reporting.MavenReportException;
 30  
 import org.codehaus.plexus.util.FileUtils;
 31  
 
 32  
 /**
 33  
  * Goal which creates a nicely formatted Changes Report in html format from a changes.xml file.
 34  
  *
 35  
  * @goal changes-report
 36  
  * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
 37  
  * @version $Id: org.apache.maven.plugin.changes.ChangesMojo.html 816588 2012-05-08 12:37:27Z hboutemy $
 38  
  */
 39  0
 public class ChangesMojo
 40  
     extends AbstractChangesReport
 41  
 {
 42  
     /**
 43  
      * The path of the <code>changes.xml</code> file that will be converted into an HTML report.
 44  
      *
 45  
      * @parameter expression="${changes.xmlPath}" default-value="src/changes/changes.xml"
 46  
      */
 47  
     private File xmlPath;
 48  
 
 49  
     /**
 50  
      * Template string that is used to discover the URL to use to display an issue report.
 51  
      * There are 2 template tokens you can use. <code>%URL%</code>: this is computed by getting the
 52  
      * <code>&lt;issueManagement&gt;/&lt;url&gt;</code> value from the POM, and removing the last '/'
 53  
      * and everything that comes after it. <code>%ISSUE%</code>: this is the issue number.
 54  
      * <p>
 55  
      * <strong>Note:</strong> In versions of this plugin prior to 2.0-beta-2 this parameter was called
 56  
      * <code>link_template</code>.
 57  
      * </p>
 58  
      *
 59  
      * @parameter expression="${changes.issueLinkTemplate}" default-value="%URL%/ViewIssue.jspa?key=%ISSUE%"
 60  
      * @since 2.0-beta-2
 61  
      * @deprecated As of 2.1 use issueLinkTemplatePerSystem : this one will be with system default
 62  
      */
 63  
     private String issueLinkTemplate;
 64  
     
 65  
     /**
 66  
      * Template strings per system that is used to discover the URL to use to display an issue report. Each key in this
 67  
      * map denotes the (case-sensitive) identifier of the issue tracking system and its value gives the URL template.
 68  
      * <p>
 69  
      * There are 2 template tokens you can use. <code>%URL%</code>: this is computed by getting the
 70  
      * <code>&lt;issueManagement&gt;/&lt;url&gt;</code> value from the POM, and removing the last '/'
 71  
      * and everything that comes after it. <code>%ISSUE%</code>: this is the issue number.
 72  
      * </p>
 73  
      * <p>
 74  
      * <strong>Note:</strong> The deprecated issueLinkTemplate will be used for a system called "default".
 75  
      * </p>
 76  
      *
 77  
      * @parameter
 78  
      * @since 2.1
 79  
      */    
 80  
     private Map issueLinkTemplatePerSystem;
 81  
 
 82  
     /**
 83  
      * @parameter default-value="${project.issueManagement.url}"
 84  
      * @readonly
 85  
      */
 86  
     private String url;
 87  
 
 88  
     /**
 89  
      * A flag whether the report should also include the dates of individual actions. If set to <code>false</code>, only
 90  
      * the dates of releases will be written to the report.
 91  
      * 
 92  
      * @parameter expression="${changes.addActionDate}" default-value="false"
 93  
      * @since 2.1
 94  
      */        
 95  
     private boolean addActionDate;    
 96  
     
 97  
     public boolean canGenerateReport()
 98  
     {
 99  0
         return xmlPath.isFile();
 100  
     }
 101  
 
 102  
     private void copyStaticResources()
 103  
         throws MavenReportException
 104  
     {
 105  0
         final String pluginResourcesBase = "org/apache/maven/plugin/changes";
 106  0
         String resourceNames[] = {
 107  
             "images/add.gif",
 108  
             "images/fix.gif",
 109  
             "images/icon_help_sml.gif",
 110  
             "images/remove.gif",
 111  
             "images/rss.png",
 112  
             "images/update.gif" };
 113  
         try
 114  
         {
 115  0
             getLog().debug( "Copying static resources." );
 116  0
             for ( int i = 0; i < resourceNames.length; i++ )
 117  
             {
 118  0
                 URL url = this.getClass().getClassLoader().getResource( pluginResourcesBase + "/" + resourceNames[i] );
 119  0
                 FileUtils.copyURLToFile( url, new File( getReportOutputDirectory(), resourceNames[i] ) );
 120  
             }
 121  
         }
 122  0
         catch ( IOException e )
 123  
         {
 124  0
             throw new MavenReportException( "Unable to copy static resources." );
 125  0
         }
 126  0
     }
 127  
 
 128  
     public void executeReport( Locale locale )
 129  
         throws MavenReportException
 130  
     {
 131  
         
 132  0
         if ( !xmlPath.exists() )
 133  
         {
 134  0
             getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist." );
 135  0
             return;
 136  
         }
 137  
         
 138  0
         ChangesReportGenerator report = new ChangesReportGenerator( xmlPath, getLog() );
 139  
         
 140  0
         report.setIssueLinksPerSystem( issueLinkTemplatePerSystem ); 
 141  0
         report.setIssueLink( issueLinkTemplate );
 142  
         
 143  0
         report.setUrl( url );
 144  
 
 145  0
         report.setAddActionDate( addActionDate );
 146  
         
 147  0
         if ( !report.canGenerateIssueLinks() )
 148  
         {
 149  0
             getLog().warn( "No issue management URL defined in POM. Links to your issues will not work correctly." );
 150  
         }
 151  
 
 152  0
         report.doGenerateReport( getBundle( locale ), getSink() );
 153  
 
 154  
         // Copy the images
 155  0
         copyStaticResources();
 156  0
     }
 157  
 
 158  
     public String getName( Locale locale )
 159  
     {
 160  0
         return getBundle( locale ).getString( "report.changes.name" );
 161  
     }
 162  
 
 163  
     public String getDescription( Locale locale )
 164  
     {
 165  0
         return getBundle( locale ).getString( "report.changes.description" );
 166  
     }
 167  
 
 168  
     public String getOutputName()
 169  
     {
 170  0
         return "changes-report";
 171  
     }
 172  
 
 173  
     private ResourceBundle getBundle( Locale locale )
 174  
     {
 175  0
         return ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() );
 176  
     }
 177  
 }