1 package org.apache.maven.plugin.changes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37
38
39 public class ChangesMojo
40 extends AbstractChangesReport
41 {
42
43
44
45
46
47 private File xmlPath;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 private String issueLinkTemplate;
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 private Map issueLinkTemplatePerSystem;
81
82
83
84
85
86 private String url;
87
88
89
90
91
92
93
94
95 private boolean addActionDate;
96
97 public boolean canGenerateReport()
98 {
99 return xmlPath.isFile();
100 }
101
102 private void copyStaticResources()
103 throws MavenReportException
104 {
105 final String pluginResourcesBase = "org/apache/maven/plugin/changes";
106 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 getLog().debug( "Copying static resources." );
116 for ( int i = 0; i < resourceNames.length; i++ )
117 {
118 URL url = this.getClass().getClassLoader().getResource( pluginResourcesBase + "/" + resourceNames[i] );
119 FileUtils.copyURLToFile( url, new File( getReportOutputDirectory(), resourceNames[i] ) );
120 }
121 }
122 catch ( IOException e )
123 {
124 throw new MavenReportException( "Unable to copy static resources." );
125 }
126 }
127
128 public void executeReport( Locale locale )
129 throws MavenReportException
130 {
131
132 if ( !xmlPath.exists() )
133 {
134 getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist." );
135 return;
136 }
137
138 ChangesReportGenerator report = new ChangesReportGenerator( xmlPath, getLog() );
139
140 report.setIssueLinksPerSystem( issueLinkTemplatePerSystem );
141 report.setIssueLink( issueLinkTemplate );
142
143 report.setUrl( url );
144
145 report.setAddActionDate( addActionDate );
146
147 if ( !report.canGenerateIssueLinks() )
148 {
149 getLog().warn( "No issue management URL defined in POM. Links to your issues will not work correctly." );
150 }
151
152 report.doGenerateReport( getBundle( locale ), getSink() );
153
154
155 copyStaticResources();
156 }
157
158 public String getName( Locale locale )
159 {
160 return getBundle( locale ).getString( "report.changes.name" );
161 }
162
163 public String getDescription( Locale locale )
164 {
165 return getBundle( locale ).getString( "report.changes.description" );
166 }
167
168 public String getOutputName()
169 {
170 return "changes-report";
171 }
172
173 private ResourceBundle getBundle( Locale locale )
174 {
175 return ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() );
176 }
177 }