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 org.apache.maven.doxia.siterenderer.Renderer;
23 import org.apache.maven.project.MavenProject;
24 import org.apache.maven.reporting.MavenReportException;
25 import org.codehaus.plexus.util.FileUtils;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.net.URL;
30 import java.util.Locale;
31 import java.util.ResourceBundle;
32
33 /**
34 * Goal which creates a nicely formatted Changes Report in html format from a changes.xml file.
35 *
36 * @goal changes-report
37 * @author <a href="mailto:jruiz@exist.com">Johnny R. Ruiz III</a>
38 * @version $Id: ChangesMojo.html 816584 2012-05-08 12:33:35Z hboutemy $
39 */
40 public class ChangesMojo
41 extends AbstractChangesReport
42 {
43 /**
44 * The path of the changes.xml file that will be converted into an html report.
45 *
46 * @parameter expression="${basedir}/src/changes/changes.xml"
47 * @required
48 */
49 private File xmlPath;
50
51 /**
52 * Template string that is used to discover the URL to use to display an issue report.
53 * There are 2 template tokens you can use. %URL%: this is computed by getting the
54 * <issueManagement>/<url> value from the POM, and removing the last '/'
55 * and everything that comes after it. %ISSUE% : this is the issue number.
56 * <p>
57 * <strong>Note:</strong> In versions of this plugin prior to 2.0-beta-2 this parameter was called
58 * <code>link_template</code>.
59 * </p>
60 *
61 * @parameter expression="%URL%/ViewIssue.jspa?key=%ISSUE%"
62 * @since 2.0-beta-2
63 */
64 private String issueLinkTemplate;
65
66 /**
67 * @parameter expression="${project.issueManagement.url}"
68 * @readonly
69 */
70 private String url;
71
72 public boolean canGenerateReport()
73 {
74 return xmlPath.isFile();
75 }
76
77 private void copyStaticResources()
78 throws MavenReportException
79 {
80 final String pluginResourcesBase = "org/apache/maven/plugin/changes";
81 String resourceNames[] = {
82 "images/add.gif",
83 "images/fix.gif",
84 "images/icon_help_sml.gif",
85 "images/remove.gif",
86 "images/rss.png",
87 "images/update.gif" };
88 try
89 {
90 getLog().debug( "Copying static resources." );
91 for ( int i = 0; i < resourceNames.length; i++ )
92 {
93 URL url = this.getClass().getClassLoader().getResource( pluginResourcesBase + "/" + resourceNames[i] );
94 FileUtils.copyURLToFile( url, new File( outputDirectory, resourceNames[i] ) );
95 }
96 }
97 catch ( IOException e )
98 {
99 throw new MavenReportException( "Unable to copy static resources." );
100 }
101 }
102
103 public void executeReport( Locale locale )
104 throws MavenReportException
105 {
106 ChangesReportGenerator report = new ChangesReportGenerator( xmlPath, getLog() );
107
108 if ( ( url == null ) || ( url.trim().equals( "" ) ) )
109 {
110 getLog().warn(
111 "No Issue Management/URL defined in pom.xml. Links to your issues will not work correctly." );
112 }
113
114 report.setIssueLink( issueLinkTemplate );
115 report.setUrl( url );
116 report.doGenerateReport( getBundle( locale ), getSink() );
117
118 // Copy the images
119 copyStaticResources();
120 }
121
122 public String getName( Locale locale )
123 {
124 return getBundle( locale ).getString( "report.changes.name" );
125 }
126
127 public String getDescription( Locale locale )
128 {
129 return getBundle( locale ).getString( "report.changes.description" );
130 }
131
132 public String getOutputName()
133 {
134 return "changes-report";
135 }
136
137 private ResourceBundle getBundle( Locale locale )
138 {
139 return ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() );
140 }
141 }