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 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
35
36
37
38
39
40 public class ChangesMojo
41 extends AbstractChangesReport
42 {
43
44
45
46
47
48
49 private File xmlPath;
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 private String issueLinkTemplate;
65
66
67
68
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
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 }