1 |
|
package org.apache.maven.announcement; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
import org.apache.maven.changes.Action; |
20 |
|
import org.apache.maven.changes.Release; |
21 |
|
import org.xml.sax.Attributes; |
22 |
|
import org.xml.sax.SAXException; |
23 |
|
import org.xml.sax.helpers.DefaultHandler; |
24 |
|
|
25 |
0 |
import javax.xml.parsers.SAXParser; |
26 |
|
import javax.xml.parsers.SAXParserFactory; |
27 |
|
import java.io.File; |
28 |
|
import java.util.ArrayList; |
29 |
0 |
import java.util.List; |
30 |
|
|
31 |
|
|
32 |
0 |
|
33 |
0 |
|
34 |
|
|
35 |
0 |
|
36 |
0 |
|
37 |
|
public class JiraAnnouncementParser |
38 |
|
extends DefaultHandler |
39 |
0 |
{ |
40 |
0 |
private String elementValue; |
41 |
0 |
|
42 |
0 |
private String parentElement = ""; |
43 |
|
|
44 |
|
private JiraAnnouncement issue; |
45 |
0 |
|
46 |
0 |
private List issues = new ArrayList(); |
47 |
|
|
48 |
|
public JiraAnnouncementParser( String xmlPath ) |
49 |
0 |
{ |
50 |
0 |
File xml = new File( xmlPath ); |
51 |
0 |
|
52 |
0 |
parseJira( xml ); |
53 |
0 |
} |
54 |
|
|
55 |
0 |
public JiraAnnouncementParser( File xmlPath ) |
56 |
0 |
{ |
57 |
0 |
parseJira( xmlPath ); |
58 |
0 |
} |
59 |
|
|
60 |
|
public void parseJira( File xml ) |
61 |
|
{ |
62 |
0 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
63 |
|
|
64 |
0 |
try |
65 |
|
{ |
66 |
0 |
SAXParser parser = factory.newSAXParser(); |
67 |
|
|
68 |
0 |
parser.parse( xml, this ); |
69 |
|
} |
70 |
0 |
catch ( Throwable t ) |
71 |
|
{ |
72 |
0 |
t.printStackTrace(); |
73 |
0 |
} |
74 |
0 |
} |
75 |
0 |
|
76 |
|
public void startElement( String namespaceURI, String sName, String qName, Attributes attrs ) |
77 |
0 |
throws SAXException |
78 |
|
{ |
79 |
0 |
if ( qName.equals( "item" ) ) |
80 |
|
{ |
81 |
0 |
issue = new JiraAnnouncement(); |
82 |
|
|
83 |
0 |
parentElement = "item"; |
84 |
|
} |
85 |
0 |
} |
86 |
|
|
87 |
0 |
public void endElement( String namespaceURI, String sName, String qName ) |
88 |
|
throws SAXException |
89 |
0 |
{ |
90 |
0 |
if ( qName.equals( "item" ) ) |
91 |
0 |
{ |
92 |
0 |
issues.add( issue ); |
93 |
0 |
|
94 |
0 |
parentElement = ""; |
95 |
0 |
} |
96 |
0 |
else if ( qName.equals( "title" ) && parentElement.equals( "item" ) ) |
97 |
0 |
{ |
98 |
0 |
issue.setTitle( elementValue ); |
99 |
0 |
} |
100 |
0 |
else if ( qName.equals( "key" ) ) |
101 |
0 |
{ |
102 |
0 |
issue.setKey( elementValue ); |
103 |
0 |
} |
104 |
0 |
else if ( qName.equals( "link" ) && parentElement.equals( "item" ) ) |
105 |
0 |
{ |
106 |
0 |
issue.setLink( elementValue ); |
107 |
0 |
} |
108 |
0 |
else if ( qName.equals( "summary" ) ) |
109 |
0 |
{ |
110 |
0 |
issue.setSummary( elementValue ); |
111 |
0 |
} |
112 |
0 |
else if ( qName.equals( "type" ) ) |
113 |
0 |
{ |
114 |
0 |
issue.setType( elementValue ); |
115 |
0 |
} |
116 |
0 |
else if ( qName.equals( "status" ) ) |
117 |
0 |
{ |
118 |
0 |
issue.setStatus( elementValue ); |
119 |
0 |
} |
120 |
0 |
else if ( qName.equals( "resolution" ) ) |
121 |
0 |
{ |
122 |
0 |
issue.setResolution( elementValue ); |
123 |
0 |
} |
124 |
0 |
else if ( qName.equals( "assignee" ) ) |
125 |
|
{ |
126 |
0 |
issue.setAssignee( elementValue ); |
127 |
|
} |
128 |
0 |
else if ( qName.equals( "reporter" ) ) |
129 |
|
{ |
130 |
0 |
issue.setReporter( elementValue ); |
131 |
|
} |
132 |
0 |
else if ( qName.equals( "fixVersion" ) ) |
133 |
|
{ |
134 |
0 |
issue.setFixVersion( elementValue ); |
135 |
|
} |
136 |
0 |
else if ( qName.equals( "comment" ) ) |
137 |
|
{ |
138 |
0 |
issue.addComment( elementValue ); |
139 |
|
} |
140 |
0 |
} |
141 |
|
|
142 |
|
public void characters( char[] buff, int offset, int len ) |
143 |
|
throws SAXException |
144 |
|
{ |
145 |
0 |
String str = new String( buff, offset, len ); |
146 |
|
|
147 |
0 |
String string = str.trim(); |
148 |
|
|
149 |
0 |
if ( !string.equals( "" ) ) |
150 |
|
{ |
151 |
0 |
elementValue = string; |
152 |
|
} |
153 |
0 |
} |
154 |
|
|
155 |
0 |
public List getIssues() |
156 |
|
{ |
157 |
0 |
return this.issues; |
158 |
|
} |
159 |
0 |
|
160 |
|
public List getReleases( List issues ) |
161 |
0 |
{ |
162 |
0 |
List releases = new ArrayList(); |
163 |
0 |
|
164 |
0 |
Release release = new Release(); |
165 |
0 |
|
166 |
0 |
String type = ""; |
167 |
0 |
|
168 |
0 |
for ( int i = 0; i < issues.size(); i++ ) |
169 |
0 |
{ |
170 |
0 |
JiraAnnouncement issue = ( JiraAnnouncement ) issues.get( i ); |
171 |
0 |
|
172 |
0 |
Action action = new Action(); |
173 |
0 |
|
174 |
0 |
action.setIssue( issue.getKey() ); |
175 |
|
|
176 |
0 |
if ( issue.getType().equals( "Bug" ) ) |
177 |
0 |
{ |
178 |
0 |
type = "fix"; |
179 |
0 |
} |
180 |
0 |
else if ( issue.getType().equals( "New Feature" ) ) |
181 |
0 |
{ |
182 |
0 |
type = "add"; |
183 |
|
} |
184 |
0 |
else if ( issue.getType().equals( "Improvement" ) ) |
185 |
0 |
{ |
186 |
0 |
type = "update"; |
187 |
0 |
} |
188 |
0 |
action.setType( type ); |
189 |
0 |
|
190 |
0 |
action.setDev( issue.getAssignee() ); |
191 |
0 |
|
192 |
|
|
193 |
0 |
|
194 |
0 |
if ( issue.getComments() != null && !issue.getComments().isEmpty() ) |
195 |
0 |
{ |
196 |
0 |
int commentSize = issue.getComments().size(); |
197 |
|
|
198 |
0 |
action.setAction( issue.getComments().get( commentSize - 1 ).toString() ); |
199 |
|
} |
200 |
|
else |
201 |
|
{ |
202 |
0 |
action.setAction( "" ); |
203 |
|
} |
204 |
0 |
release.addAction( action ); |
205 |
|
|
206 |
0 |
release.setDescription( issue.getSummary() ); |
207 |
|
|
208 |
0 |
release.setVersion( issue.getFixVersion() ); |
209 |
|
|
210 |
0 |
releases.add( release ); |
211 |
|
} |
212 |
0 |
return releases; |
213 |
|
} |
214 |
|
} |