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