1 package org.apache.maven.plugin.github;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.MalformedURLException;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Locale;
26 import java.util.Map;
27 import java.util.ResourceBundle;
28
29 import org.apache.maven.plugin.changes.AbstractChangesReport;
30 import org.apache.maven.plugin.changes.ProjectUtils;
31 import org.apache.maven.plugin.issues.Issue;
32 import org.apache.maven.plugin.issues.IssueUtils;
33 import org.apache.maven.plugin.issues.IssuesReportGenerator;
34 import org.apache.maven.plugin.issues.IssuesReportHelper;
35 import org.apache.maven.plugins.annotations.Mojo;
36 import org.apache.maven.plugins.annotations.Parameter;
37 import org.apache.maven.reporting.MavenReportException;
38 import org.apache.maven.settings.Settings;
39
40
41
42
43
44
45
46 @Mojo( name = "github-report", threadSafe = true )
47 public class GitHubMojo
48 extends AbstractChangesReport
49 {
50
51
52
53
54 private static Map<String, Integer> githubColumns = new HashMap<String, Integer>();
55
56 static
57 {
58 githubColumns.put( "Assignee", IssuesReportHelper.COLUMN_ASSIGNEE );
59 githubColumns.put( "Created", IssuesReportHelper.COLUMN_CREATED );
60 githubColumns.put( "Fix Version", IssuesReportHelper.COLUMN_FIX_VERSION );
61 githubColumns.put( "Id", IssuesReportHelper.COLUMN_ID );
62 githubColumns.put( "Reporter", IssuesReportHelper.COLUMN_REPORTER );
63 githubColumns.put( "Status", IssuesReportHelper.COLUMN_STATUS );
64 githubColumns.put( "Summary", IssuesReportHelper.COLUMN_SUMMARY );
65 githubColumns.put( "Type", IssuesReportHelper.COLUMN_TYPE );
66 githubColumns.put( "Updated", IssuesReportHelper.COLUMN_UPDATED );
67 }
68
69
70
71
72
73
74
75
76
77 @Parameter( defaultValue = "Id,Type,Summary,Assignee,Reporter,Status,Created,Updated,Fix Version" )
78 private String columnNames;
79
80
81
82
83 @Parameter( defaultValue = "http" )
84 private String githubAPIScheme;
85
86
87
88
89 @Parameter( defaultValue = "80" )
90 private int githubAPIPort;
91
92
93
94
95
96 @Parameter( defaultValue = "github" )
97 private String githubAPIServerId;
98
99
100
101
102 @Parameter( defaultValue = "${settings}", readonly = true, required = true )
103 private Settings settings;
104
105
106
107
108 @Parameter( defaultValue = "true" )
109 private boolean includeOpenIssues;
110
111
112
113
114 @Parameter( defaultValue = "true" )
115 private boolean onlyMilestoneIssues;
116
117
118
119
120
121 @Parameter( defaultValue = "false" )
122 private boolean onlyCurrentVersion;
123
124 public String getOutputName()
125 {
126 return "github-report";
127 }
128
129 public String getName( Locale locale )
130 {
131 return getBundle( locale ).getString( "report.issues.name" );
132 }
133
134 public String getDescription( Locale locale )
135 {
136 return getBundle( locale ).getString( "report.issues.description" );
137 }
138
139
140
141
142
143
144
145
146 public boolean canGenerateReport()
147 {
148
149 if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() )
150 {
151 getLog().info( "Skipping the GitHub Report in this project because it's not the Execution Root" );
152 return false;
153 }
154 String message = ProjectUtils.validateIssueManagement( project, "GitHub", "GitHub Report" );
155 if ( message != null )
156 {
157 getLog().warn( message );
158 }
159 return message == null;
160 }
161
162 @Override
163 protected void executeReport( Locale locale )
164 throws MavenReportException
165 {
166
167
168 List<Integer> columnIds = IssuesReportHelper.getColumnIds( columnNames, githubColumns );
169 if ( columnIds.size() == 0 )
170 {
171
172 throw new MavenReportException( "maven-changes-plugin: None of the configured columnNames '" + columnNames
173 + "' are valid." );
174 }
175
176 try
177 {
178
179 GitHubDownloader issueDownloader =
180 new GitHubDownloader( project, githubAPIScheme, githubAPIPort, includeOpenIssues, onlyMilestoneIssues );
181
182 issueDownloader.configureAuthentication( githubAPIServerId, settings, getLog() );
183
184 List<Issue> issueList = issueDownloader.getIssueList();
185
186 if ( onlyCurrentVersion )
187 {
188 issueList = IssueUtils.getIssuesForVersion( issueList, project.getVersion() );
189 getLog().info( "The GitHub Report will contain issues only for the current version." );
190 }
191
192
193 IssuesReportGenerator report = new IssuesReportGenerator( IssuesReportHelper.toIntArray( columnIds ) );
194
195 if ( issueList.isEmpty() )
196 {
197 report.doGenerateEmptyReport( getBundle( locale ), getSink() );
198 getLog().warn( "No issue was matched." );
199 }
200 else
201 {
202 report.doGenerateReport( getBundle( locale ), getSink(), issueList );
203 }
204 }
205 catch ( MalformedURLException e )
206 {
207
208 throw new MavenReportException( "The Github URL is incorrect." );
209 }
210 catch ( Exception e )
211 {
212 throw new MavenReportException( e.getMessage(), e );
213 }
214 }
215
216
217
218
219
220 private ResourceBundle getBundle( Locale locale )
221 {
222 return ResourceBundle.getBundle( "github-report", locale, this.getClass().getClassLoader() );
223 }
224
225 }