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 | 0 | public class GitHubMojo |
48 | |
extends AbstractChangesReport |
49 | |
{ |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | private static Map<String, Integer> GITHUB_COLUMNS = new HashMap<String, Integer>(); |
55 | |
|
56 | |
static |
57 | |
{ |
58 | 0 | GITHUB_COLUMNS.put( "Assignee", Integer.valueOf( IssuesReportHelper.COLUMN_ASSIGNEE ) ); |
59 | 0 | GITHUB_COLUMNS.put( "Created", Integer.valueOf( IssuesReportHelper.COLUMN_CREATED ) ); |
60 | 0 | GITHUB_COLUMNS.put( "Fix Version", Integer.valueOf( IssuesReportHelper.COLUMN_FIX_VERSION ) ); |
61 | 0 | GITHUB_COLUMNS.put( "Id", Integer.valueOf( IssuesReportHelper.COLUMN_ID ) ); |
62 | 0 | GITHUB_COLUMNS.put( "Reporter", Integer.valueOf( IssuesReportHelper.COLUMN_REPORTER ) ); |
63 | 0 | GITHUB_COLUMNS.put( "Status", Integer.valueOf( IssuesReportHelper.COLUMN_STATUS ) ); |
64 | 0 | GITHUB_COLUMNS.put( "Summary", Integer.valueOf( IssuesReportHelper.COLUMN_SUMMARY ) ); |
65 | 0 | GITHUB_COLUMNS.put( "Type", Integer.valueOf( IssuesReportHelper.COLUMN_TYPE ) ); |
66 | 0 | GITHUB_COLUMNS.put( "Updated", Integer.valueOf( IssuesReportHelper.COLUMN_UPDATED ) ); |
67 | 0 | } |
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 | 0 | return "github-report"; |
118 | |
} |
119 | |
|
120 | |
public String getName( Locale locale ) |
121 | |
{ |
122 | 0 | return getBundle( locale ).getString( "report.issues.name" ); |
123 | |
} |
124 | |
|
125 | |
public String getDescription( Locale locale ) |
126 | |
{ |
127 | 0 | return getBundle( locale ).getString( "report.issues.description" ); |
128 | |
} |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public boolean canGenerateReport() |
138 | |
{ |
139 | 0 | return ProjectUtils.validateIfIssueManagementComplete( project, "GitHub", "GitHub Report", getLog() ); |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
protected void executeReport( Locale locale ) |
144 | |
throws MavenReportException |
145 | |
{ |
146 | |
|
147 | |
|
148 | 0 | List<Integer> columnIds = IssuesReportHelper.getColumnIds( columnNames, GITHUB_COLUMNS ); |
149 | 0 | if ( columnIds.size() == 0 ) |
150 | |
{ |
151 | |
|
152 | 0 | throw new MavenReportException( |
153 | |
"maven-changes-plugin: None of the configured columnNames '" + columnNames + "' are valid." ); |
154 | |
} |
155 | |
|
156 | |
try |
157 | |
{ |
158 | |
|
159 | 0 | GitHubDownloader issueDownloader = |
160 | |
new GitHubDownloader( project, githubAPIScheme, githubAPIPort, includeOpenIssues, onlyMilestoneIssues ); |
161 | |
|
162 | 0 | List<Issue> issueList = issueDownloader.getIssueList(); |
163 | |
|
164 | 0 | if ( onlyCurrentVersion ) |
165 | |
{ |
166 | 0 | issueList = IssueUtils.getIssuesForVersion( issueList, project.getVersion() ); |
167 | 0 | getLog().info( "The GitHub Report will contain issues only for the current version." ); |
168 | |
} |
169 | |
|
170 | |
|
171 | 0 | IssuesReportGenerator report = new IssuesReportGenerator( IssuesReportHelper.toIntArray( columnIds ) ); |
172 | |
|
173 | 0 | if ( issueList.isEmpty() ) |
174 | |
{ |
175 | 0 | report.doGenerateEmptyReport( getBundle( locale ), getSink() ); |
176 | 0 | getLog().warn( "No issue was matched." ); |
177 | |
} |
178 | |
else |
179 | |
{ |
180 | 0 | report.doGenerateReport( getBundle( locale ), getSink(), issueList ); |
181 | |
} |
182 | |
} |
183 | 0 | catch ( MalformedURLException e ) |
184 | |
{ |
185 | |
|
186 | 0 | throw new MavenReportException( "The Github URL is incorrect." ); |
187 | |
} |
188 | 0 | catch ( Exception e ) |
189 | |
{ |
190 | 0 | throw new MavenReportException( e.getMessage(), e ); |
191 | 0 | } |
192 | 0 | } |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
private ResourceBundle getBundle( Locale locale ) |
199 | |
{ |
200 | 0 | return ResourceBundle.getBundle( "github-report", locale, this.getClass().getClassLoader() ); |
201 | |
} |
202 | |
|
203 | |
} |