|
Lines 18-23
Link Here
|
| 18 |
import java.net.URL; |
18 |
import java.net.URL; |
| 19 |
import java.net.URLConnection; |
19 |
import java.net.URLConnection; |
| 20 |
import java.net.URLEncoder; |
20 |
import java.net.URLEncoder; |
|
|
21 |
import java.util.regex.Matcher; |
| 22 |
import java.util.regex.Pattern; |
| 21 |
|
23 |
|
| 22 |
import javax.security.auth.login.LoginException; |
24 |
import javax.security.auth.login.LoginException; |
| 23 |
|
25 |
|
|
Lines 33-41
Link Here
|
| 33 |
import org.eclipse.mylar.provisional.tasklist.TaskRepository; |
35 |
import org.eclipse.mylar.provisional.tasklist.TaskRepository; |
| 34 |
import org.eclipse.search.ui.NewSearchUI; |
36 |
import org.eclipse.search.ui.NewSearchUI; |
| 35 |
|
37 |
|
| 36 |
import com.sun.org.apache.xerces.internal.impl.xpath.regex.Match; |
|
|
| 37 |
import com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression; |
| 38 |
|
| 39 |
/** |
38 |
/** |
| 40 |
* Queries the Bugzilla server for the list of bugs matching search criteria. |
39 |
* Queries the Bugzilla server for the list of bugs matching search criteria. |
| 41 |
* |
40 |
* |
|
Lines 46-64
Link Here
|
| 46 |
protected static final String QUERYING_SERVER = "Querying Bugzilla Server..."; |
45 |
protected static final String QUERYING_SERVER = "Querying Bugzilla Server..."; |
| 47 |
|
46 |
|
| 48 |
/** regular expression matching Bugzilla query results format used in Eclipse.org Bugzilla */ |
47 |
/** regular expression matching Bugzilla query results format used in Eclipse.org Bugzilla */ |
| 49 |
protected static final RegularExpression re = new RegularExpression("<a href=\"show_bug.cgi\\?id=(\\d+)\">", "i"); |
48 |
public static final Pattern re = Pattern.compile("<a href=\"show_bug.cgi\\?id=(\\d+)\">", Pattern.CASE_INSENSITIVE); |
| 50 |
|
49 |
|
| 51 |
/** regular expression matching values of query matches' attributes in Eclipse.org Bugzilla */ |
50 |
/** regular expression matching values of query matches' attributes in Eclipse.org Bugzilla */ |
| 52 |
public static final RegularExpression reValue = new RegularExpression("<td><nobr>([^<]*)</nobr>"); |
51 |
public static final Pattern reValue = Pattern.compile("<td><nobr>([^<]*)</nobr>"); |
| 53 |
|
|
|
| 54 |
public static final RegularExpression reValueBugzilla220 = new RegularExpression( |
| 55 |
"<td style=\"white-space: nowrap\">([^<]*)"); |
| 56 |
|
52 |
|
|
|
53 |
public static final Pattern reValueBugzilla220 = Pattern.compile("<td style=\"white-space: nowrap\">([^<]*)"); |
| 54 |
|
| 57 |
/** regular expression matching Bugzilla query results format used in v2.12 */ |
55 |
/** regular expression matching Bugzilla query results format used in v2.12 */ |
| 58 |
protected static final RegularExpression reOld = new RegularExpression( |
56 |
protected static final Pattern reOld = Pattern.compile("<a href=\"show_bug.cgi\\?id=(\\d+)\">\\d+</a>\\s*<td class=severity><nobr>([^>]+)</nobr><td class=priority><nobr>([^>]+)</nobr><td class=platform><nobr>([^>]*)</nobr><td class=owner><nobr>([^>]*)</nobr><td class=status><nobr>([^>]*)</nobr><td class=resolution><nobr>([^>]*)</nobr><td class=summary>(.*)$", Pattern.CASE_INSENSITIVE); |
| 59 |
"<a href=\"show_bug.cgi\\?id=(\\d+)\">\\d+</a>\\s*<td class=severity><nobr>([^>]+)</nobr><td class=priority><nobr>([^>]+)</nobr><td class=platform><nobr>([^>]*)</nobr><td class=owner><nobr>([^>]*)</nobr><td class=status><nobr>([^>]*)</nobr><td class=resolution><nobr>([^>]*)</nobr><td class=summary>(.*)$", |
57 |
|
| 60 |
"i"); |
|
|
| 61 |
|
| 62 |
private String urlString; |
58 |
private String urlString; |
| 63 |
|
59 |
|
| 64 |
private TaskRepository repository; |
60 |
private TaskRepository repository; |
|
Lines 192-198
Link Here
|
| 192 |
throw new OperationCanceledException("Search cancelled"); |
188 |
throw new OperationCanceledException("Search cancelled"); |
| 193 |
} |
189 |
} |
| 194 |
|
190 |
|
| 195 |
Match match = new Match(); |
|
|
| 196 |
String line; |
191 |
String line; |
| 197 |
while ((line = in.readLine()) != null) { |
192 |
while ((line = in.readLine()) != null) { |
| 198 |
if (maxMatches != -1 && numCollected >= maxMatches) { |
193 |
if (maxMatches != -1 && numCollected >= maxMatches) { |
|
Lines 207-234
Link Here
|
| 207 |
// create regular expressions that can be mathced to check if we |
202 |
// create regular expressions that can be mathced to check if we |
| 208 |
// have |
203 |
// have |
| 209 |
// bad login information |
204 |
// bad login information |
| 210 |
RegularExpression loginRe = new RegularExpression("<title>.*login.*</title>.*"); |
205 |
Pattern loginRe = Pattern.compile("<title>.*login.*</title>.*"); |
| 211 |
RegularExpression invalidRe = new RegularExpression(".*<title>.*invalid.*password.*</title>.*"); |
206 |
Pattern invalidRe = Pattern.compile(".*<title>.*invalid.*password.*</title>.*"); |
| 212 |
RegularExpression passwordRe = new RegularExpression(".*<title>.*password.*invalid.*</title>.*"); |
207 |
Pattern passwordRe = Pattern.compile(".*<title>.*password.*invalid.*</title>.*"); |
| 213 |
RegularExpression emailRe = new RegularExpression(".*<title>.*check e-mail.*</title>.*"); |
208 |
Pattern emailRe = Pattern.compile(".*<title>.*check e-mail.*</title>.*"); |
| 214 |
RegularExpression errorRe = new RegularExpression(".*<title>.*error.*</title>.*"); |
209 |
Pattern errorRe = Pattern.compile(".*<title>.*error.*</title>.*"); |
| 215 |
|
210 |
|
| 216 |
String lowerLine = line.toLowerCase(); |
211 |
String lowerLine = line.toLowerCase(); |
| 217 |
|
212 |
|
| 218 |
// check if we have anything that suggests bad login info |
213 |
// check if we have anything that suggests bad login info |
| 219 |
if (loginRe.matches(lowerLine) || invalidRe.matches(lowerLine) || passwordRe.matches(lowerLine) |
214 |
if (loginRe.matcher(lowerLine).find() || invalidRe.matcher(lowerLine).find() || passwordRe.matcher(lowerLine).find() |
| 220 |
|| emailRe.matches(lowerLine) || errorRe.matches(lowerLine)) |
215 |
|| emailRe.matcher(lowerLine).find() || errorRe.matcher(lowerLine).find()) |
| 221 |
possibleBadLogin = true; |
216 |
possibleBadLogin = true; |
| 222 |
|
217 |
|
| 223 |
if (reOld.matches(line, match)) { |
218 |
Matcher matcher = reOld.matcher(line); |
| 224 |
int id = Integer.parseInt(match.getCapturedText(1)); |
219 |
if (matcher.find()) { |
| 225 |
String severity = match.getCapturedText(2); |
220 |
int id = Integer.parseInt(matcher.group(1)); |
| 226 |
String priority = match.getCapturedText(3); |
221 |
String severity = matcher.group(2); |
| 227 |
String platform = match.getCapturedText(4); |
222 |
String priority = matcher.group(3); |
| 228 |
String owner = match.getCapturedText(5); |
223 |
String platform = matcher.group(4); |
| 229 |
String state = match.getCapturedText(6); |
224 |
String owner = matcher.group(5); |
| 230 |
String result = match.getCapturedText(7); |
225 |
String state = matcher.group(6); |
| 231 |
String description = match.getCapturedText(8); |
226 |
String result = matcher.group(7); |
|
|
227 |
String description = matcher.group(8); |
| 232 |
String query = BugzillaPlugin.getMostRecentQuery(); |
228 |
String query = BugzillaPlugin.getMostRecentQuery(); |
| 233 |
if (query == null) |
229 |
if (query == null) |
| 234 |
query = ""; |
230 |
query = ""; |
|
Lines 240-258
Link Here
|
| 240 |
collector.accept(hit); |
236 |
collector.accept(hit); |
| 241 |
numCollected++; |
237 |
numCollected++; |
| 242 |
|
238 |
|
| 243 |
} else if (re.matches(line, match)) { |
239 |
} else { |
| 244 |
RegularExpression regularExpression; |
240 |
matcher = re.matcher(line); |
| 245 |
if (BugzillaPlugin.getDefault().isServerCompatability220()) { |
241 |
if (matcher.find()) { |
| 246 |
regularExpression = reValueBugzilla220; |
242 |
Pattern regularExpression; |
| 247 |
} else { |
243 |
if (BugzillaPlugin.getDefault().isServerCompatability220()) { |
| 248 |
regularExpression = reValue; |
244 |
regularExpression = reValueBugzilla220; |
|
|
245 |
} else { |
| 246 |
regularExpression = reValue; |
| 247 |
} |
| 248 |
|
| 249 |
int id = Integer.parseInt(matcher.group(1)); |
| 250 |
BugzillaSearchHit hit = createHit(regularExpression, monitor, in, repository.getUrl() |
| 251 |
.toExternalForm(), id); |
| 252 |
collector.accept(hit); |
| 253 |
numCollected++; |
| 249 |
} |
254 |
} |
| 250 |
|
|
|
| 251 |
int id = Integer.parseInt(match.getCapturedText(1)); |
| 252 |
BugzillaSearchHit hit = createHit(regularExpression, monitor, in, match, repository.getUrl() |
| 253 |
.toExternalForm(), id); |
| 254 |
collector.accept(hit); |
| 255 |
numCollected++; |
| 256 |
} |
255 |
} |
| 257 |
if (monitor.isCanceled()) { |
256 |
if (monitor.isCanceled()) { |
| 258 |
throw new OperationCanceledException("Search cancelled"); |
257 |
throw new OperationCanceledException("Search cancelled"); |
|
Lines 305-312
Link Here
|
| 305 |
return status; |
304 |
return status; |
| 306 |
} |
305 |
} |
| 307 |
|
306 |
|
| 308 |
public static BugzillaSearchHit createHit(RegularExpression regularExpression, IProgressMonitor monitor, |
307 |
public static BugzillaSearchHit createHit(Pattern regularExpression, IProgressMonitor monitor, |
| 309 |
BufferedReader in, Match match, String serverUrl, int id) throws IOException { |
308 |
BufferedReader in, String serverUrl, int id) throws IOException { |
| 310 |
String line; |
309 |
String line; |
| 311 |
String severity = null; |
310 |
String severity = null; |
| 312 |
String priority = null; |
311 |
String priority = null; |
|
Lines 315-320
Link Here
|
| 315 |
String state = null; |
314 |
String state = null; |
| 316 |
String result = null; |
315 |
String result = null; |
| 317 |
for (int i = 0; i < 6; i++) { |
316 |
for (int i = 0; i < 6; i++) { |
|
|
317 |
Matcher matcher = null; |
| 318 |
do { |
318 |
do { |
| 319 |
if (monitor.isCanceled()) { |
319 |
if (monitor.isCanceled()) { |
| 320 |
throw new OperationCanceledException("Search cancelled"); |
320 |
throw new OperationCanceledException("Search cancelled"); |
|
Lines 323-348
Link Here
|
| 323 |
if (line == null) |
323 |
if (line == null) |
| 324 |
break; |
324 |
break; |
| 325 |
line = line.trim(); |
325 |
line = line.trim(); |
| 326 |
} while (!regularExpression.matches(line, match)); |
326 |
matcher = regularExpression.matcher(line); |
| 327 |
switch (i) { |
327 |
} while (!matcher.find()); |
| 328 |
case 0: |
328 |
if (null != matcher) { |
| 329 |
severity = match.getCapturedText(1); |
329 |
switch (i) { |
| 330 |
break; |
330 |
case 0: |
| 331 |
case 1: |
331 |
severity = matcher.group(1); |
| 332 |
priority = match.getCapturedText(1); |
332 |
break; |
| 333 |
break; |
333 |
case 1: |
| 334 |
case 2: |
334 |
priority = matcher.group(1); |
| 335 |
platform = match.getCapturedText(1); |
335 |
break; |
| 336 |
break; |
336 |
case 2: |
| 337 |
case 3: |
337 |
platform = matcher.group(1); |
| 338 |
owner = match.getCapturedText(1); |
338 |
break; |
| 339 |
break; |
339 |
case 3: |
| 340 |
case 4: |
340 |
owner = matcher.group(1); |
| 341 |
state = match.getCapturedText(1); |
341 |
break; |
| 342 |
break; |
342 |
case 4: |
| 343 |
case 5: |
343 |
state = matcher.group(1); |
| 344 |
result = match.getCapturedText(1); |
344 |
break; |
| 345 |
break; |
345 |
case 5: |
|
|
346 |
result = matcher.group(1); |
| 347 |
break; |
| 348 |
} |
| 346 |
} |
349 |
} |
| 347 |
} |
350 |
} |
| 348 |
|
351 |
|