Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 136219 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/bugzilla/core/BugzillaRemoteContextDelegate.java (-9 / +9 lines)
Lines 17-45 Link Here
17
17
18
/**
18
/**
19
 * @author Rob Elves
19
 * @author Rob Elves
20
 * TODO: Find a better spot for this
20
 * TODO: Use of this delegate probably isn't necessary anymore
21
 */
21
 */
22
public class BugzillaRemoteContextDelegate implements IRemoteContextDelegate {
22
public class BugzillaRemoteContextDelegate implements IRemoteContextDelegate {
23
23
24
	private Comment comment;
24
	private ReportAttachment attachment;
25
	
25
	
26
	public BugzillaRemoteContextDelegate(Comment comment) {
26
	public BugzillaRemoteContextDelegate(ReportAttachment attachment) {
27
		this.comment = comment;
27
		this.attachment = attachment;
28
	}
28
	}
29
	public Date getDate() {
29
	public Date getDate() {
30
		return comment.getCreated();
30
		return attachment.getDateCreated();
31
	}
31
	}
32
32
33
	public String getAuthor() {
33
	public String getAuthor() {
34
		return comment.getAuthor();
34
		return attachment.getAuthor();
35
	}
35
	}
36
36
37
	public String getComment() {
37
	public String getComment() {
38
		return comment.getText().trim();
38
		return attachment.getDescription();
39
	}
39
	}
40
40
41
	public int getId() {
41
	public int getId() {
42
		return comment.getAttachmentId();
42
		return attachment.getId();
43
	}
43
	}
44
	
44
		
45
}
45
}
(-)src/org/eclipse/mylar/bugzilla/core/Comment.java (-87 / +110 lines)
Lines 12-46 Link Here
12
package org.eclipse.mylar.bugzilla.core;
12
package org.eclipse.mylar.bugzilla.core;
13
13
14
import java.io.Serializable;
14
import java.io.Serializable;
15
import java.text.SimpleDateFormat;
16
import java.util.Calendar;
15
import java.util.Date;
17
import java.util.Date;
16
18
19
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
20
17
21
18
/**
22
/**
19
 * A comment posted on a bug.
23
 * A comment posted on a bug.
20
 */
24
 */
21
public class Comment implements Serializable {
25
public class Comment extends AttributeContainer implements Serializable {
22
	/**
26
	
23
	 * Comment for <code>serialVersionUID</code>
27
	private static final long serialVersionUID = -1760372869047050979L;
24
	 */
25
	private static final long serialVersionUID = 3978422529214199344L;
26
28
29
	/** Parser for dates in the report */
30
	public static SimpleDateFormat creation_ts_date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
31
	
27
	/** Comment's bug */
32
	/** Comment's bug */
28
	private final BugReport bug;
33
	private final AbstractRepositoryReport bug;
29
34
30
	/** Comment's number */
35
	/** Comment's number */
31
	private final int number;
36
	private final int number;
32
37
33
	/** Comment's text */
38
//	/** Comment's text */
34
	private String text;
39
//	private String text;
35
40
//
36
	/** Comment's author */
41
//	/** Comment's author */
37
	private final String author;
42
//	private final String author;
38
43
//
39
	/** Author's realname, if known */
44
//	/** Author's realname, if known */
40
	private final String authorName;
45
//	private final String authorName;
41
46
42
	/** Comment's creation timestamp */
47
	/** Comment's creation timestamp */
43
	private final Date created;
48
	private Date created;
44
49
45
	/** Preceding comment */
50
	/** Preceding comment */
46
	private Comment previous;
51
	private Comment previous;
Lines 48-87 Link Here
48
	/** Following comment */
53
	/** Following comment */
49
	private Comment next;
54
	private Comment next;
50
55
51
	private boolean hasAttachment = false;
56
//	private boolean hasAttachment = false;
52
57
//
53
	private int attachmentId = -1;
58
//	private int attachmentId = -1;
54
59
//
55
	private String attachmentDescription = "";
60
//	private String attachmentDescription = "";
56
61
//
57
	private boolean obsolete = false;
62
//	private boolean obsolete = false;
58
63
	
59
	/**
64
	public Comment(AbstractRepositoryReport report, int num) {
60
	 * Constructor
65
		this.bug = report;
61
	 * 
66
		this.number = num;
62
	 * @param bug
63
	 *            The bug that this comment is associated with
64
	 * @param date
65
	 *            The date taht this comment was entered on
66
	 * @param author
67
	 *            The author of the bug
68
	 * @param authorName
69
	 *            The authors real name
70
	 */
71
	public Comment(BugReport bug, int number, Date date, String author, String authorName) {
72
		this.bug = bug;
73
		this.number = number;
74
		this.created = date;
75
		this.author = author;
76
		this.authorName = authorName;
77
	}
67
	}
68
	
69
	
70
//	/**
71
//	 * Constructor
72
//	 * 
73
//	 * @param bug
74
//	 *            The bug that this comment is associated with
75
//	 * @param date
76
//	 *            The date taht this comment was entered on
77
//	 * @param author
78
//	 *            The author of the bug
79
//	 * @param authorName
80
//	 *            The authors real name
81
//	 * @depricated This use Comment(AbstractRepositoryReport report, int num) instead
82
//	 */
83
//	public Comment(AbstractRepositoryReport bug, int number, Date date, String author, String authorName) {
84
//		this.bug = bug;
85
//		this.number = number;
86
////		this.created = date;
87
////		this.author = author;
88
////		this.authorName = authorName;
89
//	}
78
90
79
	/**
91
	/**
80
	 * Get the bug that this comment is associated with
92
	 * Get the bug that this comment is associated with
81
	 * 
93
	 * 
82
	 * @return The bug that this comment is associated with
94
	 * @return The bug that this comment is associated with
83
	 */
95
	 */
84
	public BugReport getBug() {
96
	public AbstractRepositoryReport getBug() {
85
		return bug;
97
		return bug;
86
	}
98
	}
87
99
Lines 100-105 Link Here
100
	 * @return The comments creation timestamp
112
	 * @return The comments creation timestamp
101
	 */
113
	 */
102
	public Date getCreated() {
114
	public Date getCreated() {
115
		if(created == null) {
116
			created = Calendar.getInstance().getTime();
117
			try {
118
				created = creation_ts_date_format.parse(getAttribute(BugzillaReportElement.CREATION_TS).getValue());
119
			} catch (Exception e) {
120
			}			
121
		}
103
		return created;
122
		return created;
104
	}
123
	}
105
124
Lines 108-124 Link Here
108
	 * 
127
	 * 
109
	 * @return The comments author
128
	 * @return The comments author
110
	 */
129
	 */
111
	public String getAuthor() {
130
	public String getAuthor() {		
112
		return author;
131
		return getAttributeValue(BugzillaReportElement.WHO);
113
	}
132
	}
114
133
	
115
	/**
134
	/**
116
	 * Get the authors real name
135
	 * Get the authors real name
117
	 * 
136
	 *
118
	 * @return Returns author's name, or <code>null</code> if not known
137
	 * @return Returns author's name, or <code>null</code> if not known
119
	 */
138
	 */
120
	public String getAuthorName() {
139
	public String getAuthorName() {
121
		return authorName;
140
		// TODO: Currently we don't get the real name from the xml.
141
		//       Need retrieve these names somehow
142
		return getAuthor();
122
	}
143
	}
123
144
124
	/**
145
	/**
Lines 127-144 Link Here
127
	 * @return The comments text
148
	 * @return The comments text
128
	 */
149
	 */
129
	public String getText() {
150
	public String getText() {
130
		return text;
151
		return  getAttributeValue(BugzillaReportElement.THETEXT);
131
	}
152
	}
132
153
133
	/**
154
//	/**
134
	 * Set the comments text
155
//	 * Set the comments text
135
	 * 
156
//	 * 
136
	 * @param text
157
//	 * @param text
137
	 *            The text to set the comment to have
158
//	 *            The text to set the comment to have
138
	 */
159
//	 */
139
	public void setText(String text) {
160
//	public void setText(String text) {
140
		this.text = text;
161
//		this.text = text;
141
	}
162
//	}
142
163
143
	/**
164
	/**
144
	 * Get the next comment for the bug
165
	 * Get the next comment for the bug
Lines 180-215 Link Here
180
		this.previous = previous;
201
		this.previous = previous;
181
	}
202
	}
182
203
183
	public void setHasAttachment(boolean b) {
204
//	public void setHasAttachment(boolean b) {
184
		this.hasAttachment  = b;
205
//		this.hasAttachment  = b;
185
	}
206
//	}
186
207
//
187
	public boolean hasAttachment() {
208
//	public boolean hasAttachment() {
188
		return hasAttachment;
209
//		return hasAttachment;
189
	}
210
//	}
190
	
211
//	
191
	public void setAttachmentId(int attachmentID) {
212
//	public void setAttachmentId(int attachmentID) {
192
		this.attachmentId  = attachmentID;
213
//		this.attachmentId  = attachmentID;
193
	}
214
//	}
215
//
216
//	public int getAttachmentId() {
217
//		return attachmentId;
218
//	}
219
//
220
//	public void setAttachmentDescription(String attachmentDescription) {
221
//		this.attachmentDescription  = attachmentDescription;		
222
//	}
223
//	
224
//	public String getAttachmentDescription() {
225
//		return attachmentDescription;
226
//	}
227
//
228
//	public void setObsolete(boolean obsolete) {
229
//		this.obsolete  = obsolete;		
230
//	}
231
//	
232
//	public boolean isObsolete() {
233
//		return obsolete;
234
//	}
235
//
194
236
195
	public int getAttachmentId() {
196
		return attachmentId;
197
	}
198
199
	public void setAttachmentDescription(String attachmentDescription) {
200
		this.attachmentDescription  = attachmentDescription;		
201
	}
202
	
203
	public String getAttachmentDescription() {
204
		return attachmentDescription;
205
	}
206
207
	public void setObsolete(boolean obsolete) {
208
		this.obsolete  = obsolete;		
209
	}
210
	
211
	public boolean isObsolete() {
212
		return obsolete;
213
	}
214
	
237
	
215
}
238
}
(-)src/org/eclipse/mylar/bugzilla/core/BugReport.java (-555 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.core;
12
13
import java.io.Serializable;
14
import java.io.UnsupportedEncodingException;
15
import java.nio.charset.Charset;
16
import java.util.ArrayList;
17
import java.util.Date;
18
import java.util.HashMap;
19
import java.util.HashSet;
20
import java.util.Iterator;
21
import java.util.List;
22
import java.util.Set;
23
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
27
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
29
/**
30
 * A bug report entered in Bugzilla.
31
 * 
32
 * @author Mik Kersten (hardening of prototype)
33
 */
34
public class BugReport implements Serializable, IBugzillaBug {
35
36
	private static final String ATTR_REPORTER = "Reporter";
37
38
	private static final String ATTR_RESOLUTION = "Resolution";
39
40
	private static final String ATTR_ASSIGNED_TO = "Assigned To";
41
42
	public static final String ATTR_SUMMARY = "Summary";
43
44
	public static final String ATTR_STATUS = "Status";
45
46
	public static final String ATTR_PRIORITY = "Priority";
47
	
48
	public static final String VAL_STATUS_VERIFIED = "VERIFIED";
49
50
	public static final String VAL_STATUS_CLOSED = "CLOSED";
51
52
	public static final String VAL_STATUS_RESOLVED = "RESOLVED";
53
54
	public static final String VAL_STATUS_NEW = "NEW";
55
56
	public static final String KEY_MILESTONE = "target_milestone";
57
58
	public static final String ATTRIBUTE_URL = "URL";
59
60
	public static final String ATTRIBUTE_PRIORITY = "Priority";
61
62
	public static final String ATTRIBUTE_COMPONENT = "Component";
63
64
	public static final String ATTRIBUTE_VERSION = "Version";
65
66
	public static final String ATTRIBUTE_PLATFORM = "Platform";
67
68
	public static final String ATTRIBUTE_MILESTONE = "Target Milestone";
69
70
	public static final String ATTRIBUTE_OS = "OS";
71
72
	public static final String ATTRIBUTE_SEVERITY = "Severity";
73
	
74
	private static final long serialVersionUID = 3258693199936631348L;
75
76
	/** Bug id */
77
	protected final int id;
78
79
	/** The bug's server */
80
	protected final String repositoryUrl;
81
82
	/** Description of the bug */
83
	protected String description;
84
85
	/** Creation timestamp */
86
	protected Date created;
87
88
	/** Modification timestamp */
89
	protected Date lastModified = null;
90
	
91
	/** The bugs valid keywords */
92
	protected List<String> validKeywords;
93
94
	/** The operations that can be done on the bug */
95
	protected List<Operation> operations = new ArrayList<Operation>();
96
97
	/** Bug attributes (status, resolution, etc.) */
98
	protected HashMap<String, Attribute> attributes = new HashMap<String, Attribute>();
99
100
//	/** Attachments (Id, Description) **/
101
//	protected HashMap<Integer, String> attachements = new HashMap<Integer, String>();
102
	
103
	/** The keys for the bug attributes */
104
	protected ArrayList<String> attributeKeys = new ArrayList<String>();
105
106
	/** A list of comments */
107
	protected ArrayList<Comment> comments = new ArrayList<Comment>();
108
109
	/** The value for the new comment to add (text that is saved) */
110
	protected String newComment = "";
111
112
	/** The new value for the new comment to add (text from submit editor) */
113
	protected String newNewComment = "";
114
115
	/** CC list */
116
	protected HashSet<String> cc = new HashSet<String>();
117
118
	/** The operation that was selected to do to the bug */
119
	protected Operation selectedOperation = null;
120
121
	/** Whether or not this bug report is saved offline. */
122
	protected boolean savedOffline = false;
123
124
	protected boolean hasChanges = false;
125
126
	protected String charset = null;
127
128
	public BugReport(int id, String server) {
129
		this.id = id;
130
		this.repositoryUrl = server;
131
	}
132
133
	/**
134
	 * Get the bugs id
135
	 * 
136
	 * @return The bugs id
137
	 */
138
	public int getId() {
139
		return id;
140
	}
141
142
	public String getRepositoryUrl() {
143
		return repositoryUrl;
144
	}
145
146
	public String getLabel() {
147
		return id + ": " + getSummary(); 
148
	}
149
150
	/**
151
	 * Get the bugs description
152
	 * 
153
	 * @return The description of the bug
154
	 */
155
	public String getDescription() {
156
		return description;
157
	}
158
159
	/**
160
	 * Set the description of the bug
161
	 * 
162
	 * @param description
163
	 *            The description to set the bug to have
164
	 */
165
	public void setDescription(String description) {
166
		this.description = decodeStringFromCharset(description);
167
	}
168
169
	/**
170
	 * Get the summary for the bug
171
	 * 
172
	 * @return The bugs summary
173
	 */
174
	public String getSummary() {
175
		if (getAttribute(ATTR_SUMMARY) == null) {
176
			BugzillaPlugin.log(new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
177
					"null summary for: " + id, null));
178
			return "";
179
		}
180
		return getAttribute(ATTR_SUMMARY).getValue();
181
	}
182
183
	/**
184
	 * Set the summary of the bug
185
	 * 
186
	 * @param summary
187
	 *            The summary to set the bug to have
188
	 */
189
	public void setSummary(String summary) {
190
		Attribute attribute = new Attribute(ATTR_SUMMARY);
191
		attribute.setValue(summary);
192
		addAttribute(attribute);
193
	}
194
195
	private String decodeStringFromCharset(String string) {
196
		String decoded = string;
197
		if (charset != null && string != null && Charset.availableCharsets().containsKey(charset)) {
198
			try {
199
				decoded = new String(string.getBytes(), charset);
200
			} catch (UnsupportedEncodingException e) {
201
				// ignore
202
			}
203
		}
204
		return decoded;
205
	}
206
207
	/**
208
	 * Get the date that the bug was created
209
	 * 
210
	 * @return The bugs creation date
211
	 */
212
	public Date getCreated() {
213
		return created;
214
	}
215
216
	/**
217
	 * Set the bugs creation date
218
	 * 
219
	 * @param created
220
	 *            The date the the bug was created
221
	 */
222
	public void setCreated(Date created) {
223
		this.created = created;
224
	}
225
226
	public Attribute getAttribute(String key) {
227
		return attributes.get(key);
228
	}
229
230
	/**
231
	 * Get the list of attributes for this bug
232
	 * 
233
	 * @return An <code>ArrayList</code> of the bugs attributes
234
	 */
235
	public List<Attribute> getAttributes() {
236
		// create an array list to store the attributes in
237
		ArrayList<Attribute> attributeEntries = new ArrayList<Attribute>(attributeKeys.size());
238
239
		// go through each of the attribute keys
240
		for (Iterator<String> it = attributeKeys.iterator(); it.hasNext();) {
241
			// get the key for the attribute
242
			String key = it.next();
243
244
			// get the attribute and add it to the list
245
			Attribute attribute = attributes.get(key);
246
			attributeEntries.add(attribute);
247
		}
248
249
		// return the list of attributes for the bug
250
		return attributeEntries;
251
	}
252
253
	public Attribute getAttributeForKnobName(String knobName) {
254
		for (Iterator<String> it = attributeKeys.iterator(); it.hasNext();) {
255
			String key = it.next();
256
257
			Attribute attribute = attributes.get(key);
258
			if (attribute != null && attribute.getParameterName() != null
259
					&& attribute.getParameterName().compareTo(knobName) == 0) {
260
				return attribute;
261
			}
262
		}
263
264
		return null;
265
	}
266
267
	/**
268
	 * @param attribute
269
	 *            The attribute to add to the bug
270
	 */
271
	public void addAttribute(Attribute attribute) {
272
		if (!attributes.containsKey(attribute.getName())) {
273
			attributeKeys.add(attribute.getName());
274
		}
275
276
		attribute.setValue(decodeStringFromCharset(attribute.getValue()));
277
278
		// put the value of the attribute into the map, using its name as the
279
		// key
280
		attributes.put(attribute.getName(), attribute);
281
	}
282
283
	/**
284
	 * Get the comments posted on the bug
285
	 * 
286
	 * @return A list of comments for the bug
287
	 */
288
	public ArrayList<Comment> getComments() {
289
		return comments;
290
	}
291
292
	/**
293
	 * Add a comment to the bug
294
	 * 
295
	 * @param comment
296
	 *            The comment to add to the bug
297
	 */
298
	public void addComment(Comment comment) {
299
		Comment preceding = null;
300
		if (comments.size() > 0) {
301
			// if there are some comments, get the last comment and set the next
302
			// value to be the new comment
303
			preceding = comments.get(comments.size() - 1);
304
			preceding.setNext(comment);
305
		}
306
		// set the comments previous value to the preceeding one
307
		comment.setPrevious(preceding);
308
309
		comment.setText(decodeStringFromCharset(comment.getText()));
310
		// add the comment to the comment list
311
		comments.add(comment);
312
	}
313
314
	/**
315
	 * Get the person who reported the bug
316
	 * 
317
	 * @return The person who reported the bug
318
	 */
319
	public String getReporter() {
320
		return getAttribute(ATTR_REPORTER).getValue();
321
	}
322
323
	/**
324
	 * Get the person to whom this bug is assigned
325
	 * 
326
	 * @return The person who is assigned to this bug
327
	 */
328
	public String getAssignedTo() {
329
		return getAttribute(ATTR_ASSIGNED_TO).getValue();
330
	}
331
332
	/**
333
	 * Get the resolution of the bug
334
	 * 
335
	 * @return The resolution of the bug
336
	 */
337
	public String getResolution() {
338
		return getAttribute(ATTR_RESOLUTION).getValue();
339
	}
340
341
	/**
342
	 * Get the status of the bug
343
	 * 
344
	 * @return The bugs status
345
	 */
346
	public String getStatus() {
347
		return getAttribute(ATTR_STATUS).getValue();
348
	}
349
350
	/**
351
	 * Get the keywords for the bug
352
	 * 
353
	 * @return The keywords for the bug
354
	 */
355
	public List<String> getKeywords() {
356
		return validKeywords;
357
	}
358
359
	/**
360
	 * Set the keywords for the bug
361
	 * 
362
	 * @param keywords
363
	 *            The keywords to set the bug to have
364
	 */
365
	public void setKeywords(List<String> keywords) {
366
		this.validKeywords = keywords;
367
	}
368
369
	/**
370
	 * Get the set of addresses in the CC list
371
	 * 
372
	 * @return A <code>Set</code> of addresses in the CC list
373
	 */
374
	public Set<String> getCC() {
375
		return cc;
376
	}
377
378
	/**
379
	 * Add an email to the bugs CC list
380
	 * 
381
	 * @param email
382
	 *            The email address to add to the CC list
383
	 */
384
	public void addCC(String email) {
385
		cc.add(email);
386
	}
387
388
	/**
389
	 * Remove an address from the bugs CC list
390
	 * 
391
	 * @param email
392
	 *            the address to be removed from the CC list
393
	 * @return <code>true</code> if the email is in the set and it was removed
394
	 */
395
	public boolean removeCC(String email) {
396
		return cc.remove(email);
397
	}
398
399
	/**
400
	 * Get the new comment that is to be added to the bug
401
	 * 
402
	 * @return The new comment
403
	 */
404
	public String getNewComment() {
405
		return newComment;
406
	}
407
408
	/**
409
	 * Set the new comment that will be added to the bug
410
	 * 
411
	 * @param newComment
412
	 *            The new comment to add to the bug
413
	 */
414
	public void setNewComment(String newComment) {
415
		this.newComment = newComment;
416
		newNewComment = newComment;
417
	}
418
419
	/**
420
	 * @return the new value of the new NewComment.
421
	 */
422
	public String getNewNewComment() {
423
		return newNewComment;
424
	}
425
426
	/**
427
	 * Set the new value of the new NewComment
428
	 * 
429
	 * @param newNewComment
430
	 *            The new value of the new NewComment.
431
	 */
432
	public void setNewNewComment(String newNewComment) {
433
		this.newNewComment = newNewComment;
434
	}
435
436
	/**
437
	 * Get all of the operations that can be done to the bug
438
	 * 
439
	 * @return The operations that can be done to the bug
440
	 */
441
	public List<Operation> getOperations() {
442
		return operations;
443
	}
444
445
	/**
446
	 * Add an operation to the bug
447
	 * 
448
	 * @param o
449
	 *            The operation to add
450
	 */
451
	public void addOperation(Operation o) {
452
		operations.add(o);
453
	}
454
455
	/**
456
	 * Get an operation from the bug based on its display name
457
	 * 
458
	 * @param displayText
459
	 *            The display text for the operation
460
	 * @return The operation that has the display text
461
	 */
462
	public Operation getOperation(String displayText) {
463
		Iterator<Operation> itr = operations.iterator();
464
		while (itr.hasNext()) {
465
			Operation o = itr.next();
466
			String opName = o.getOperationName();
467
			opName = opName.replaceAll("</.*>", "");
468
			opName = opName.replaceAll("<.*>", "");
469
			if (opName.equals(displayText))
470
				return o;
471
		}
472
		return null;
473
	}
474
475
	/**
476
	 * Set the selected operation
477
	 * 
478
	 * @param o
479
	 *            The selected operation
480
	 */
481
	public void setSelectedOperation(Operation o) {
482
		selectedOperation = o;
483
	}
484
485
	/**
486
	 * Get the selected operation
487
	 * 
488
	 * @return The selected operation
489
	 */
490
	public Operation getSelectedOperation() {
491
		return selectedOperation;
492
	}
493
494
	public boolean isSavedOffline() {
495
		return savedOffline;
496
	}
497
498
	public boolean isLocallyCreated() {
499
		return false;
500
	}
501
502
	public void setOfflineState(boolean newOfflineState) {
503
		savedOffline = newOfflineState;
504
	}
505
506
	public boolean hasChanges() {
507
		return hasChanges;
508
	}
509
510
	public void setHasChanged(boolean b) {
511
		hasChanges = b;
512
	}
513
514
	public boolean isResolved() {
515
		Attribute status = getAttribute(ATTR_STATUS);
516
		return status != null && isResolvedStatus(getAttribute(ATTR_STATUS).getValue());
517
	}
518
519
	/**
520
	 * TODO: move?
521
	 */
522
	public static boolean isResolvedStatus(String status) {
523
		if (status != null) {
524
			return status.equals(VAL_STATUS_RESOLVED) || status.equals(VAL_STATUS_CLOSED)
525
					|| status.equals(VAL_STATUS_VERIFIED);
526
		} else {
527
			return false;
528
		}
529
	}
530
531
	public String getCharset() {
532
		return charset;
533
	}
534
535
	public void setCharset(String charset) {
536
		this.charset = charset;
537
	}
538
539
	public Date getLastModified() {
540
		return lastModified;
541
	}
542
543
	public void setLastModified(Date date) {
544
		this.lastModified = date;		
545
	}
546
547
	
548
//	public void addAttachment(int id, String description) {
549
//		attachements.put(id, description);
550
//	}
551
//	
552
//	public HashMap<Integer, String> getAttachements() {
553
//		return attachements;
554
//	}
555
}
(-)src/org/eclipse/mylar/bugzilla/core/Attribute.java (-178 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import java.io.Serializable;
15
import java.util.LinkedHashMap;
16
import java.util.Map;
17
18
/**
19
 * Class representing a Bugzilla report attribute that can be changed on the
20
 * server.
21
 */
22
public class Attribute implements Serializable {
23
	/** Automatically generated serialVersionUID */
24
	private static final long serialVersionUID = 3257009873370757424L;
25
26
	private boolean hidden = false;
27
28
	/** Attribute name */
29
	private String name;
30
31
	/** Name of the option used when updating the attribute on the server */
32
	private String parameterName;
33
34
	/** Legal values of the attribute */
35
	private LinkedHashMap<String, String> optionValues;
36
37
	/**
38
	 * Attribute's value (input field or selected option; value that is saved or
39
	 * from the server)
40
	 */
41
	private String value;
42
43
	/** Attributes new Value (value chosen in submit editor) */
44
	private String newValue;
45
46
	/**
47
	 * Constructor
48
	 * 
49
	 * @param name
50
	 *            The name of the attribute
51
	 */
52
	public Attribute(String name) {
53
		// initialize the name and its legal values
54
		this.name = name;
55
		optionValues = new LinkedHashMap<String, String>();
56
	}
57
58
	/**
59
	 * Get the attribute's name
60
	 * 
61
	 * @return The name of the attribute
62
	 */
63
	public String getName() {
64
		return name;
65
	}
66
67
	/**
68
	 * Get name of the option used when updating the attribute on the server
69
	 * 
70
	 * @return The name of the option for server updates
71
	 */
72
	public String getParameterName() {
73
		return parameterName;
74
	}
75
76
	/**
77
	 * Get whether the attribute can be edited by the used
78
	 * 
79
	 * @return <code>true</code> if the attribute can be edited by the user
80
	 */
81
	public boolean isEditable() {
82
		return optionValues.size() > 0;
83
	}
84
85
	/**
86
	 * Get the legal values for the option
87
	 * 
88
	 * @return The <code>Map</code> of legal values for the option.
89
	 */
90
	public Map<String, String> getOptionValues() {
91
		return optionValues;
92
	}
93
94
	/**
95
	 * Get the value of the attribute
96
	 * 
97
	 * @return A <code>String</code> of the attributes value
98
	 */
99
	public String getValue() {
100
		return value;
101
	}
102
103
	/**
104
	 * Set the value of the attribute
105
	 * 
106
	 * @param value
107
	 *            The new value of the attribute
108
	 */
109
	public void setValue(String value) {
110
		this.value = value;
111
		newValue = value;
112
	}
113
114
	/**
115
	 * Set the new value of the attribute
116
	 * 
117
	 * @param newVal
118
	 *            The new value of the attribute
119
	 */
120
	public void setNewValue(String newVal) {
121
		newValue = newVal;
122
	}
123
124
	/**
125
	 * Get the new value for the attribute
126
	 * 
127
	 * @return The new value
128
	 */
129
	public String getNewValue() {
130
		return newValue;
131
	}
132
133
	/**
134
	 * Sets the name of the option used when updating the attribute on the
135
	 * server
136
	 * 
137
	 * @param parameterName
138
	 *            The name of the option when updating from the server
139
	 */
140
	public void setParameterName(String parameterName) {
141
		this.parameterName = parameterName;
142
	}
143
144
	/**
145
	 * Adds an attribute option value
146
	 * 
147
	 * @param readableValue
148
	 *            The value displayed on the screen
149
	 * @param parameterValue
150
	 *            The option value used when sending the form to the server
151
	 */
152
	public void addOptionValue(String readableValue, String parameterValue) {
153
		optionValues.put(readableValue, parameterValue);
154
	}
155
156
	/**
157
	 * Determine if the field was hidden or not
158
	 * 
159
	 * @return True if the field was hidden
160
	 */
161
	public boolean isHidden() {
162
		return hidden;
163
	}
164
165
	/**
166
	 * Set whether the field was hidden in the bug
167
	 * 
168
	 * @param b
169
	 *            Whether the field was hidden or not
170
	 */
171
	public void setHidden(boolean b) {
172
		hidden = b;
173
	}
174
175
	public String toString() {
176
		return "(" + getName() + " : " + getValue() + ")";
177
	}
178
}
(-)src/org/eclipse/mylar/bugzilla/core/IBugzillaBug.java (-38 / +78 lines)
Lines 10-34 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.core;
11
package org.eclipse.mylar.bugzilla.core;
12
12
13
import java.io.Serializable;
14
import java.util.Date;
13
import java.util.Date;
15
import java.util.List;
14
import java.util.List;
16
15
17
18
/**
16
/**
19
 * Interface representing a Bugzilla bug report.
17
 * Interface representing a Bugzilla bug report.
20
 */
18
 */
21
public interface IBugzillaBug extends Serializable {
19
public interface IBugzillaBug { // extends Serializable
22
20
23
	/**
21
	// /**
24
	 * @return bug's id.
22
	// * @return bug's id.
25
	 */
23
	// */
26
	public int getId();
24
	// public int getId();
27
25
	//
28
	/**
26
	// /**
29
	 * @return the server for this bug.
27
	// * @return the server for this bug.
30
	 */
28
	// */
31
	public String getRepositoryUrl();
29
	// public String getRepositoryUrl();
32
30
33
	/**
31
	/**
34
	 * @return the title label for this bug.
32
	 * @return the title label for this bug.
Lines 59-96 Link Here
59
	 */
57
	 */
60
	public void setSummary(String newSummary);
58
	public void setSummary(String newSummary);
61
59
62
	/**
60
	// /**
63
	 * Get an attribute given its key
61
	// * Get an attribute given its key
64
	 * 
62
	// *
65
	 * @return The value of the attribute or <code>null</code> if not present
63
	// * @return The value of the attribute or <code>null</code> if not present
66
	 */
64
	// */
67
	public Attribute getAttribute(String key);
65
	// public AbstractRepositoryReportAttribute getAttribute(String key);
66
	//
67
	// /**
68
	// * @return the attributes for this bug.
69
	// */
70
	// public List<AbstractRepositoryReportAttribute> getAttributes();
71
72
	// /**
73
	// * @return <code>true</code> if this bug report is saved offline.
74
	// */
75
	// public boolean isSavedOffline();
76
77
	// /**
78
	// * @return <code>true</code> if this bug was created locally, and does not
79
	// * yet exist on a bugzilla server.
80
	// */
81
	// public boolean isLocallyCreated();
82
83
	// /**
84
	// * Sets whether or not this bug is saved offline.
85
	// *
86
	// * @param newOfflineState
87
	// * <code>true</code> if this bug is saved offline
88
	// */
89
	// public void setOfflineState(boolean newOfflineState);
90
91
	// public boolean hasChanges();
92
93
	public void addCC(String email);
94
95
	public void addOperation(Operation o);
96
97
	public String getAssignedTo();
98
99
	public List<String> getCC();
68
100
69
	/**
101
	public List<String> getKeywords();
70
	 * @return the attributes for this bug.
71
	 */
72
	public List<Attribute> getAttributes();
73
102
74
	/**
103
	public String getNewComment();
75
	 * @return <code>true</code> if this bug report is saved offline.
76
	 */
77
	public boolean isSavedOffline();
78
104
79
	/**
105
	// public String getNewNewComment();
80
	 * @return <code>true</code> if this bug was created locally, and does not
106
	public void setNewComment(String newComment);
81
	 *         yet exist on a bugzilla server.
82
	 */
83
	public boolean isLocallyCreated();
84
107
85
	/**
108
	// public void setNewNewComment(String newNewComment);
86
	 * Sets whether or not this bug is saved offline.
87
	 * 
88
	 * @param newOfflineState
89
	 *            <code>true</code> if this bug is saved offline
90
	 */
91
	public void setOfflineState(boolean newOfflineState);
109
	public void setOfflineState(boolean newOfflineState);
92
110
93
	public boolean hasChanges();
111
	//public Operation getOperation(String displayText);
112
113
	public List<Operation> getOperations();
114
115
	public String getReporter();
116
117
	public String getResolution();
118
119
	public void setSelectedOperation(Operation o);
120
121
	public Operation getSelectedOperation();
122
123
	public String getStatus();
124
125
	public boolean isResolved();
126
127
	public void removeCC(String email);
128
129
	// public void setCreated(Date created);
130
	public void setKeywords(List<String> keywords);
131
132
	// public void setLastModified(Date date);
133
	public String getProduct();
94
134
95
	/**
135
	/**
96
	 * Get the date that the bug was created
136
	 * Get the date that the bug was created
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/SaxConfigurationContentHandler.java (+11 lines)
Lines 62-67 Link Here
62
	private static final String ELEMENT_SEVERITY = "severity";
62
	private static final String ELEMENT_SEVERITY = "severity";
63
63
64
	private static final String ELEMENT_PRIORITY = "priority";
64
	private static final String ELEMENT_PRIORITY = "priority";
65
	
66
	private static final String ELEMENT_KEYWORD = "keyword";
65
67
66
	private static final String ELEMENT_OP_SYS = "op_sys";
68
	private static final String ELEMENT_OP_SYS = "op_sys";
67
69
Lines 108-113 Link Here
108
	private static final int IN_STATUS_OPEN = 1 << 17;
110
	private static final int IN_STATUS_OPEN = 1 << 17;
109
	
111
	
110
	private static final int IN_RESOLUTION = 1 << 18;
112
	private static final int IN_RESOLUTION = 1 << 18;
113
	
114
	private static final int IN_KEYWORD = 1 << 19;
111
115
112
	private int state = EXPECTING_ROOT;
116
	private int state = EXPECTING_ROOT;
113
117
Lines 183-188 Link Here
183
		case IN_RESOLUTION | IN_LI:
187
		case IN_RESOLUTION | IN_LI:
184
			configuration.addResolution(String.copyValueOf(ch, start, length));
188
			configuration.addResolution(String.copyValueOf(ch, start, length));
185
			break;
189
			break;
190
		case IN_KEYWORD | IN_LI:
191
			configuration.addKeyword(String.copyValueOf(ch, start, length));
192
			break;
186
		case IN_STATUS_OPEN | IN_LI:
193
		case IN_STATUS_OPEN | IN_LI:
187
			configuration.addOpenStatusValue(String.copyValueOf(ch, start, length));
194
			configuration.addOpenStatusValue(String.copyValueOf(ch, start, length));
188
			break;
195
			break;
Lines 234-239 Link Here
234
			state = state | IN_STATUS_OPEN;
241
			state = state | IN_STATUS_OPEN;
235
		} else if (localName.equals(ELEMENT_RESOLUTION)) {
242
		} else if (localName.equals(ELEMENT_RESOLUTION)) {
236
			state = state | IN_RESOLUTION;
243
			state = state | IN_RESOLUTION;
244
		} else if (localName.equals(ELEMENT_KEYWORD)) {
245
			state = state | IN_KEYWORD;
237
		}
246
		}
238
247
239
	}
248
	}
Lines 345-350 Link Here
345
			state = state & ~IN_STATUS_OPEN;
354
			state = state & ~IN_STATUS_OPEN;
346
		} else if (localName.equals(ELEMENT_RESOLUTION)) {
355
		} else if (localName.equals(ELEMENT_RESOLUTION)) {
347
			state = state & ~IN_RESOLUTION;
356
			state = state & ~IN_RESOLUTION;
357
		} else if (localName.equals(ELEMENT_KEYWORD)) {
358
			state = state & ~IN_KEYWORD;
348
		}
359
		}
349
360
350
	}
361
	}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/NewBugParser.java (-427 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import java.io.IOException;
15
import java.io.Reader;
16
import java.text.ParseException;
17
18
import javax.security.auth.login.LoginException;
19
20
import org.eclipse.mylar.bugzilla.core.Attribute;
21
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
22
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
23
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
24
25
/**
26
 * @author Shawn Minto
27
 * 
28
 * This class parses the valid attribute values for a new bug
29
 */
30
public class NewBugParser {
31
	/** Tokenizer used on the stream */
32
	private HtmlStreamTokenizer tokenizer;
33
34
	/** Flag for whether we need to try to get the product or not */
35
	private static boolean getProd = false;
36
37
	public NewBugParser(Reader in) {
38
		tokenizer = new HtmlStreamTokenizer(in, null);
39
	}
40
41
	/**
42
	 * Parse the new bugs valid attributes
43
	 * 
44
	 * @param nbm
45
	 *            A reference to a NewBugModel where all of the information is
46
	 *            stored
47
	 * @throws IOException
48
	 * @throws ParseException
49
	 * @throws LoginException
50
	 */
51
	public void parseBugAttributes(NewBugModel nbm, boolean retrieveProducts) throws IOException, ParseException,
52
			LoginException {
53
		nbm.attributes.clear(); // clear any attriubtes in bug model from a
54
		// previous product
55
56
		NewBugParser.getProd = retrieveProducts;
57
58
		// create a new bug report and set the parser state to the start state
59
		ParserState state = ParserState.START;
60
		String attribute = null;
61
62
		boolean isTitle = false;
63
		boolean possibleBadLogin = false;
64
		boolean isErrorState = false;
65
		String title = "";
66
		// Default error message
67
		String errorMsg = "Bugzilla could not get the needed bug attribute since your login name or password is incorrect.  Please check your settings in the bugzilla preferences.";
68
69
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
70
			// make sure that bugzilla doesn't want us to login
71
			if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
72
					&& !((HtmlTag) (token.getValue())).isEndTag()) {
73
				isTitle = true;
74
				continue;
75
			}
76
77
			if (isTitle) {
78
				// get all of the data in the title tag to compare with
79
				if (token.getType() != Token.TAG) {
80
					title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
81
					continue;
82
				} else if (token.getType() == Token.TAG
83
						&& ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
84
						&& ((HtmlTag) token.getValue()).isEndTag()) {
85
					// check if the title looks like we may have a problem with
86
					// login
87
					if (title.indexOf("login") != -1) {
88
						possibleBadLogin = true; // generic / default msg
89
						// passed to constructor re:
90
						// bad login
91
					}
92
					if ((title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
93
							|| title.indexOf("check e-mail") != -1 || title.indexOf("error") != -1) {
94
						possibleBadLogin = true;
95
						isErrorState = true; // set flag so appropriate msg
96
						// is provide for the exception
97
						errorMsg = ""; // error message will be parsed from
98
						// error page
99
					}
100
101
					isTitle = false;
102
					title = "";
103
				}
104
				continue;
105
			}
106
107
			// we have found the start of an attribute name
108
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
109
				HtmlTag tag = (HtmlTag) token.getValue();				
110
				if (tag.getTagType() == HtmlTag.Type.TD && "right".equalsIgnoreCase(tag.getAttribute("align"))) {
111
					// parse the attribute's name
112
					attribute = parseAttributeName();
113
					if(attribute != null && attribute.contains(IBugzillaConstants.INVALID_2201_ATTRIBUTE_IGNORED)) {
114
						continue;
115
					}					
116
					if (attribute == null)
117
						continue;
118
					state = ParserState.ATT_VALUE;
119
					continue;
120
				}
121
122
				if (tag.getTagType() == HtmlTag.Type.TD && "#ff0000".equalsIgnoreCase(tag.getAttribute("bgcolor"))) {
123
					state = ParserState.ERROR;
124
					continue;
125
				}
126
			}
127
128
			// we have found the start of attribute values
129
			if (state == ParserState.ATT_VALUE && token.getType() == Token.TAG) {
130
				HtmlTag tag = (HtmlTag) token.getValue();
131
				if (tag.getTagType() == HtmlTag.Type.TD) {
132
					// parse the attribute values
133
					parseAttributeValue(nbm, attribute);
134
135
					state = ParserState.ATT_NAME;
136
					attribute = null;
137
					continue;
138
				}
139
			}
140
			// page being parsed contains an Error message
141
			// parse error message so it can be given to the constructor of the
142
			// exception
143
			// so an appropriate error message is displayed
144
			if (state == ParserState.ERROR && isErrorState) {
145
				// tag should be text token, not a tag
146
				// get the error message
147
				if (token.getType() == Token.TEXT) {
148
					// get string value of next token to add to error messgage
149
					// unescape the string so any escape sequences parsed appear
150
					// unescaped in the details pane
151
					errorMsg += HtmlStreamTokenizer.unescape(((StringBuffer) token.getValue()).toString()) + " ";
152
				}
153
				// expect </font> tag to indicate end of error end msg
154
				// set next state to continue parsing remainder of page
155
				else if (token.getType() == Token.TAG
156
						&& ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.FONT
157
						&& ((HtmlTag) (token.getValue())).isEndTag()) {
158
					state = ParserState.ATT_NAME;
159
				}
160
				continue;
161
			}
162
163
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
164
				HtmlTag tag = (HtmlTag) token.getValue();
165
				if (tag.getTagType() == HtmlTag.Type.INPUT && tag.getAttribute("type") != null
166
						&& "hidden".equalsIgnoreCase(tag.getAttribute("type").trim())) {
167
					Attribute a = new Attribute(tag.getAttribute("name"));
168
					a.setParameterName(tag.getAttribute("name"));
169
					a.setValue(tag.getAttribute("value"));
170
					a.setHidden(true);
171
					nbm.attributes.put(a.getName(), a);
172
					continue;
173
				}
174
			}
175
		}
176
177
		if (possibleBadLogin && (nbm.getAttributes() == null || nbm.getAttributes().size() == 0)) {
178
			throw new LoginException(errorMsg);
179
		}
180
	}
181
182
	/**
183
	 * Parse the case where we have found an attribute name
184
	 * 
185
	 * @param tokenizer
186
	 *            The tokenizer to use to find the name
187
	 * @return The name of the attribute
188
	 * @throws IOException
189
	 * @throws ParseException
190
	 */
191
	private String parseAttributeName() throws IOException, ParseException {
192
		StringBuffer sb = new StringBuffer();
193
194
		parseTableCell(sb);
195
		HtmlStreamTokenizer.unescape(sb);
196
		// remove the colon if there is one
197
		if (sb.length() == 0)
198
			return null;
199
		if (sb.charAt(sb.length() - 1) == ':') {
200
			sb.deleteCharAt(sb.length() - 1);
201
		}
202
		return sb.toString();
203
	}
204
205
	/**
206
	 * Reads text into a StringBuffer until it encounters a close table cell tag
207
	 * (&lt;/TD&gt;) or start of another cell. The text is appended to the
208
	 * existing value of the buffer. <b>NOTE:</b> Does not handle nested cells!
209
	 * 
210
	 * @param tokenizer
211
	 * @param sb
212
	 * @throws IOException
213
	 * @throws ParseException
214
	 */
215
	private void parseTableCell(StringBuffer sb) throws IOException, ParseException {
216
		boolean noWhitespace = false;
217
		for (HtmlStreamTokenizer.Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer
218
				.nextToken()) {
219
			if (token.getType() == Token.TAG) {
220
				HtmlTag tag = (HtmlTag) token.getValue();
221
				if (tag.getTagType() == HtmlTag.Type.TD) {
222
					if (!tag.isEndTag()) {
223
						tokenizer.pushback(token);
224
					}
225
					break;
226
				}
227
				noWhitespace = token.getWhitespace().length() == 0;
228
			} else if (token.getType() == Token.TEXT) {
229
				// if there was no whitespace between the tag and the
230
				// preceding text, don't insert whitespace before this text
231
				// unless it is there in the source
232
				if (!noWhitespace && token.getWhitespace().length() > 0 && sb.length() > 0) {
233
					sb.append(' ');
234
				}
235
				sb.append((StringBuffer) token.getValue());
236
			}
237
		}
238
	}
239
240
	/**
241
	 * Parse the case where we have found attribute values
242
	 * 
243
	 * @param nbm
244
	 *            The NewBugModel that is to contain information about a new bug
245
	 * @param attributeName
246
	 *            The name of the attribute that we are parsing
247
	 * @param tokenizer
248
	 *            The tokenizer to use for parsing
249
	 * @throws IOException
250
	 * @throws ParseException
251
	 */
252
	private void parseAttributeValue(NewBugModel nbm, String attributeName) throws IOException, ParseException {
253
254
		HtmlStreamTokenizer.Token token = tokenizer.nextToken();
255
		if (token.getType() == Token.TAG) {
256
			HtmlTag tag = (HtmlTag) token.getValue();
257
			if (tag.getTagType() == HtmlTag.Type.SELECT && !tag.isEndTag()) {
258
				String parameterName = tag.getAttribute("name");
259
				parseSelect(nbm, attributeName, parameterName);
260
			} else if (tag.getTagType() == HtmlTag.Type.INPUT && !tag.isEndTag()) {
261
				parseInput(nbm, attributeName, tag);
262
			} else if (!tag.isEndTag()) {
263
				parseAttributeValueCell(nbm, attributeName);
264
			}
265
		} else {
266
			StringBuffer sb = new StringBuffer();
267
			if (token.getType() == Token.TEXT) {
268
				sb.append((StringBuffer) token.getValue());
269
				parseAttributeValueCell(nbm, attributeName, sb);
270
			}
271
		}
272
	}
273
274
	/**
275
	 * Parse the case where the attribute value is just text in a table cell
276
	 * 
277
	 * @param attributeName
278
	 *            The name of the attribute we are parsing
279
	 * @param tokenizer
280
	 *            The tokenizer to use for parsing
281
	 * @throws IOException
282
	 * @throws ParseException
283
	 */
284
	private void parseAttributeValueCell(NewBugModel nbm, String attributeName) throws IOException, ParseException {
285
		StringBuffer sb = new StringBuffer();
286
287
		parseAttributeValueCell(nbm, attributeName, sb);
288
	}
289
290
	private void parseAttributeValueCell(NewBugModel nbm, String attributeName, StringBuffer sb) throws IOException,
291
			ParseException {
292
293
		parseTableCell(sb);
294
		HtmlStreamTokenizer.unescape(sb);
295
296
		// if we need the product we will get it
297
		if (getProd && attributeName.equalsIgnoreCase("product")) {
298
			nbm.setProduct(sb.toString());
299
		}
300
	}
301
302
	/**
303
	 * Parse the case where the attribute value is an input
304
	 * 
305
	 * @param nbm
306
	 *            The new bug model to add information that we get to
307
	 * @param attributeName
308
	 *            The name of the attribute that we are parsing
309
	 * @param tag
310
	 *            The HTML tag that we are currently on
311
	 * @throws IOException
312
	 */
313
	private static void parseInput(NewBugModel nbm, String attributeName, HtmlTag tag) throws IOException {
314
315
		Attribute a = new Attribute(attributeName);
316
		a.setParameterName(tag.getAttribute("name"));
317
		String value = tag.getAttribute("value");
318
		if (value == null)
319
			value = "";
320
321
		// if we found the summary, add it to the bug report
322
		if (attributeName.equalsIgnoreCase("summary")) {
323
			nbm.setSummary(value);
324
		} else if (attributeName.equalsIgnoreCase("Attachments")) {
325
			// do nothing - not a problem after 2.14
326
		} else if (attributeName.equalsIgnoreCase("add cc")) {
327
			// do nothing
328
		} else if (attributeName.toLowerCase().startsWith("cc")) {
329
			// do nothing cc's are options not inputs
330
		} else {
331
			// otherwise just add the attribute
332
			a.setValue(value);
333
			nbm.attributes.put(attributeName, a);
334
		}
335
	}
336
337
	/**
338
	 * Parse the case where the attribute value is an option
339
	 * 
340
	 * @param nbm
341
	 *            The NewBugModel that we are storing information in
342
	 * @param attributeName
343
	 *            The name of the attribute that we are parsing
344
	 * @param parameterName
345
	 *            The SELECT tag's name
346
	 * @param tokenizer
347
	 *            The tokenizer that we are using for parsing
348
	 * @throws IOException
349
	 * @throws ParseException
350
	 */
351
	private void parseSelect(NewBugModel nbm, String attributeName, String parameterName) throws IOException,
352
			ParseException {
353
354
		boolean first = false;
355
		Attribute a = new Attribute(attributeName);
356
		a.setParameterName(parameterName);
357
358
		HtmlStreamTokenizer.Token token = tokenizer.nextToken();
359
		while (token.getType() != Token.EOF) {
360
			if (token.getType() == Token.TAG) {
361
				HtmlTag tag = (HtmlTag) token.getValue();
362
				if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
363
					break;
364
				if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
365
					String optionName = tag.getAttribute("value");
366
					boolean selected = tag.hasAttribute("selected");
367
					StringBuffer optionText = new StringBuffer();
368
					for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer.nextToken()) {
369
						if (optionText.length() > 0) {
370
							optionText.append(' ');
371
						}
372
						optionText.append((StringBuffer) token.getValue());
373
					}
374
					a.addOptionValue(optionText.toString(), optionName);
375
376
					if (selected || first) {
377
						a.setValue(optionText.toString());
378
						first = false;
379
					}
380
				} else {
381
					token = tokenizer.nextToken();
382
				}
383
			} else {
384
				token = tokenizer.nextToken();
385
			}
386
		}
387
388
		if (!(nbm.attributes).containsKey(attributeName)) {
389
			(nbm.attributes).put(attributeName, a);
390
		}
391
	}
392
393
	/**
394
	 * Enum class for describing current state of Bugzilla report parser.
395
	 */
396
	private static class ParserState {
397
		/** An instance of the start state */
398
		protected static final ParserState START = new ParserState("start");
399
400
		/** An instance of the state when the parser found an attribute name */
401
		protected static final ParserState ATT_NAME = new ParserState("att_name");
402
403
		/** An instance of the state when the parser found an attribute value */
404
		protected static final ParserState ATT_VALUE = new ParserState("att_value");
405
406
		/** An instance of the state when an error page is found */
407
		protected static final ParserState ERROR = new ParserState("error");
408
409
		/** State's human-readable name */
410
		private String name;
411
412
		/**
413
		 * Constructor
414
		 * 
415
		 * @param description -
416
		 *            The states human readable name
417
		 */
418
		private ParserState(String description) {
419
			this.name = description;
420
		}
421
422
		@Override
423
		public String toString() {
424
			return name;
425
		}
426
	}
427
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/OfflineReportsFile.java (-174 / +187 lines)
Lines 28-35 Link Here
28
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.Status;
29
import org.eclipse.core.runtime.Status;
30
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.mylar.bugzilla.core.BugReport;
31
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
32
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
33
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
32
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
34
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
33
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
35
import org.eclipse.mylar.internal.bugzilla.core.compare.BugzillaCompareInput;
34
import org.eclipse.mylar.internal.bugzilla.core.compare.BugzillaCompareInput;
Lines 40-57 Link Here
40
 * Class to persist the data for the offline reports list
39
 * Class to persist the data for the offline reports list
41
 */
40
 */
42
public class OfflineReportsFile {
41
public class OfflineReportsFile {
43
	
42
44
	public enum BugzillaOfflineStatus {
43
	public enum BugzillaOfflineStatus {
45
		SAVED, SAVED_WITH_OUTGOING_CHANGES, DELETED, SAVED_WITH_INCOMMING_CHANGES, CONFLICT, ERROR
44
		SAVED, SAVED_WITH_OUTGOING_CHANGES, DELETED, SAVED_WITH_INCOMMING_CHANGES, CONFLICT, ERROR
46
	}
45
	}
47
	
46
48
	
49
	/** The file that the offline reports are written to */
47
	/** The file that the offline reports are written to */
50
	private File file;
48
	private File file;
51
49
52
	/** The directory to where the file is located */
53
	/** A list of offline reports */
50
	/** A list of offline reports */
54
	private ArrayList<IBugzillaBug> list = new ArrayList<IBugzillaBug>();
51
	private ArrayList<BugzillaReport> list = new ArrayList<BugzillaReport>();
55
52
56
	/** Sort by bug ID */
53
	/** Sort by bug ID */
57
	public static final int ID_SORT = 0;
54
	public static final int ID_SORT = 0;
Lines 74-82 Link Here
74
	 * @throws IOException
71
	 * @throws IOException
75
	 *             Error opening or closing the offline reports file
72
	 *             Error opening or closing the offline reports file
76
	 * @throws ClassNotFoundException
73
	 * @throws ClassNotFoundException
74
	 * @throws ClassNotFoundException
77
	 *             Error deserializing objects from the offline reports file
75
	 *             Error deserializing objects from the offline reports file
78
	 */
76
	 */
79
	public OfflineReportsFile(File file) throws IOException {
77
	public OfflineReportsFile(File file) throws IOException, ClassNotFoundException {
80
		this.file = file;
78
		this.file = file;
81
		if (file.exists()) {
79
		if (file.exists()) {
82
			readFile();
80
			readFile();
Lines 89-105 Link Here
89
	 * @param entry
87
	 * @param entry
90
	 *            The bug to add
88
	 *            The bug to add
91
	 */
89
	 */
92
	public BugzillaOfflineStatus add(IBugzillaBug entry, boolean saveChosen) throws CoreException {
90
	public BugzillaOfflineStatus add(BugzillaReport entry, boolean saveChosen) throws CoreException {
93
		
91
94
		BugzillaOfflineStatus status = BugzillaOfflineStatus.SAVED;
92
		BugzillaOfflineStatus status = BugzillaOfflineStatus.SAVED;
95
		
93
96
		try {
94
		try {
97
			
95
98
			// check for bug and do a compare
96
			// check for bug and do a compare
99
			int index = -1;
97
			int index = -1;
100
			if ((index = find(entry.getRepositoryUrl(), entry.getId())) >= 0) {
98
			if ((index = find(entry.getRepositoryUrl(), entry.getId())) >= 0) {
101
				IBugzillaBug oldBug = list.get(index);
99
				BugzillaReport oldBug = list.get(index);
102
				if (oldBug instanceof BugReport && entry instanceof BugReport && !saveChosen ) { 
100
				if (oldBug instanceof BugzillaReport && entry instanceof BugzillaReport && !saveChosen) {
103
					CompareConfiguration config = new CompareConfiguration();
101
					CompareConfiguration config = new CompareConfiguration();
104
					config.setLeftEditable(false);
102
					config.setLeftEditable(false);
105
					config.setRightEditable(false);
103
					config.setRightEditable(false);
Lines 110-117 Link Here
110
					config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(
108
					config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(
111
							ISharedImages.IMG_OBJ_ELEMENT));
109
							ISharedImages.IMG_OBJ_ELEMENT));
112
					final BugzillaCompareInput in = new BugzillaCompareInput(config);
110
					final BugzillaCompareInput in = new BugzillaCompareInput(config);
113
					in.setLeft((BugReport) oldBug);
111
					in.setLeft((BugzillaReport) oldBug);
114
					in.setRight((BugReport) entry);
112
					in.setRight((BugzillaReport) entry);
115
					in.setTitle("Bug #" + oldBug.getId());
113
					in.setTitle("Bug #" + oldBug.getId());
116
114
117
					try {
115
					try {
Lines 127-138 Link Here
127
					} catch (InvocationTargetException x) {
125
					} catch (InvocationTargetException x) {
128
						BugzillaPlugin.log(x);
126
						BugzillaPlugin.log(x);
129
						MessageDialog.openError(null, "Compare Failed", x.getTargetException().getMessage());
127
						MessageDialog.openError(null, "Compare Failed", x.getTargetException().getMessage());
130
						return  BugzillaOfflineStatus.ERROR;
128
						return BugzillaOfflineStatus.ERROR;
131
					}
129
					}
132
130
133
					if (in.getCompareResult() == null) {
131
					if (in.getCompareResult() == null) {
134
						status = BugzillaOfflineStatus.SAVED;
132
						status = BugzillaOfflineStatus.SAVED;
135
					} else if (oldBug.hasChanges()) { 
133
					} else if (oldBug.hasChanges()) {
136
						if (!MessageDialog
134
						if (!MessageDialog
137
								.openQuestion(
135
								.openQuestion(
138
										null,
136
										null,
Lines 140-153 Link Here
140
										"Local copy of Bug# "
138
										"Local copy of Bug# "
141
												+ entry.getId()
139
												+ entry.getId()
142
												+ " Has Changes.\nWould you like to override local changes? Note: if you select No, your added comment will be saved with the updated bug, but all other changes will be lost.")) {
140
												+ " Has Changes.\nWould you like to override local changes? Note: if you select No, your added comment will be saved with the updated bug, but all other changes will be lost.")) {
143
							((BugReport) entry).setNewComment(((BugReport) oldBug).getNewComment());
141
							((BugzillaReport) entry).setNewComment(((BugzillaReport) oldBug).getNewComment());
144
							((BugReport) entry).setHasChanged(true);						
142
							((BugzillaReport) entry).setHasChanged(true);
145
							status = BugzillaOfflineStatus.CONFLICT; 
143
							status = BugzillaOfflineStatus.CONFLICT;
146
						} else {
144
						} else {
147
							((BugReport) entry).setHasChanged(false);
145
							((BugzillaReport) entry).setHasChanged(false);
148
							status = BugzillaOfflineStatus.SAVED;
146
							status = BugzillaOfflineStatus.SAVED;
149
						}				
147
						}
150
					} else  { 
148
					} else {
151
						DiffNode node = (DiffNode) in.getCompareResult();
149
						DiffNode node = (DiffNode) in.getCompareResult();
152
						IDiffElement[] children = node.getChildren();
150
						IDiffElement[] children = node.getChildren();
153
						if (children.length != 0) {
151
						if (children.length != 0) {
Lines 158-164 Link Here
158
								}
156
								}
159
							}
157
							}
160
						} else {
158
						} else {
161
							status = BugzillaOfflineStatus.SAVED; // do we ever get here?
159
							status = BugzillaOfflineStatus.SAVED; // do we
160
							// ever get
161
							// here?
162
						}
162
						}
163
					}
163
					}
164
164
Lines 176-185 Link Here
176
			}
176
			}
177
			// add the entry to the list and write the file to disk
177
			// add the entry to the list and write the file to disk
178
			list.add(entry);
178
			list.add(entry);
179
			writeFile();			
179
			writeFile();
180
		} catch (Exception e) {
180
		} catch (Exception e) {
181
			e.printStackTrace();
181
			IStatus runtimestatus = new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.OK,
182
			IStatus runtimestatus = new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.OK,
182
					"failed to add of offline report", e);
183
					"failed to add offline report", e);
183
			throw new CoreException(runtimestatus);
184
			throw new CoreException(runtimestatus);
184
		}
185
		}
185
		return status;
186
		return status;
Lines 213-227 Link Here
213
	 */
214
	 */
214
	public int find(String repositoryUrl, int id) {
215
	public int find(String repositoryUrl, int id) {
215
		for (int i = 0; i < list.size(); i++) {
216
		for (int i = 0; i < list.size(); i++) {
216
			IBugzillaBug currBug = list.get(i);
217
			BugzillaReport currBug = list.get(i);
217
			if (currBug != null && currBug.getRepositoryUrl() != null 
218
			if (currBug != null && currBug.getRepositoryUrl() != null
218
					&& (currBug.getRepositoryUrl().equals(repositoryUrl) && currBug.getId() == id) && !currBug.isLocallyCreated())
219
					&& (currBug.getRepositoryUrl().equals(repositoryUrl) && currBug.getId() == id)
220
					&& !currBug.isLocallyCreated())
219
				return i;
221
				return i;
220
		}
222
		}
221
		return -1;
223
		return -1;
222
	}
224
	}
223
	
225
224
	public static IBugzillaBug findBug(String repositoryUrl, int bugId) {
226
	public static BugzillaReport findBug(String repositoryUrl, int bugId) {
225
		int location = BugzillaPlugin.getDefault().getOfflineReports().find(repositoryUrl, bugId);
227
		int location = BugzillaPlugin.getDefault().getOfflineReports().find(repositoryUrl, bugId);
226
		if (location != -1) {
228
		if (location != -1) {
227
			return BugzillaPlugin.getDefault().getOfflineReports().elements().get(location);
229
			return BugzillaPlugin.getDefault().getOfflineReports().elements().get(location);
Lines 234-240 Link Here
234
	 * 
236
	 * 
235
	 * @return The list of offline reports
237
	 * @return The list of offline reports
236
	 */
238
	 */
237
	public ArrayList<IBugzillaBug> elements() {
239
	public ArrayList<BugzillaReport> elements() {
238
		return list;
240
		return list;
239
	}
241
	}
240
242
Lines 252-258 Link Here
252
254
253
			// write each element in the array list
255
			// write each element in the array list
254
			for (int i = 0; i < list.size(); i++) {
256
			for (int i = 0; i < list.size(); i++) {
255
				IBugzillaBug item = list.get(i);
257
				BugzillaReport item = list.get(i);
256
				try {
258
				try {
257
					out.writeObject(item);
259
					out.writeObject(item);
258
				} catch (IOException e) {
260
				} catch (IOException e) {
Lines 277-306 Link Here
277
	 * @throws IOException
279
	 * @throws IOException
278
	 *             Error opening or closing the offline reports file
280
	 *             Error opening or closing the offline reports file
279
	 * @throws ClassNotFoundException
281
	 * @throws ClassNotFoundException
282
	 * @throws ClassNotFoundException
280
	 *             Error deserializing objects from the offline reports file
283
	 *             Error deserializing objects from the offline reports file
281
	 */
284
	 */
282
	private void readFile() throws IOException {
285
	private void readFile() throws IOException, ClassNotFoundException {
283
		ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
286
287
		ObjectInputStream in = null;
288
		try {
289
			in = new ObjectInputStream(new FileInputStream(file));
284
290
285
		// get the number of offline reports in the file
291
			// get the number of offline reports in the file
286
		int size = in.readInt();
292
			int size = in.readInt();
287
293
288
		// get the bug id of the most recently created offline report
294
			// get the bug id of the most recently created offline report
289
		latestNewBugId = in.readInt();
295
			latestNewBugId = in.readInt();
290
296
291
		// read in each of the offline reports in the file
297
			// read in each of the offline reports in the file
292
		for (int nX = 0; nX < size; nX++) {
298
			for (int nX = 0; nX < size; nX++) {
293
			try {
299
				// try {
294
				IBugzillaBug item = (IBugzillaBug) in.readObject();
300
				BugzillaReport item = (BugzillaReport) in.readObject();
295
				// add the offline report to the offlineReports list
301
				// add the offline report to the offlineReports list
296
				list.add(item);
302
				list.add(item);
297
			} catch (ClassNotFoundException e) {
303
				// } catch (ClassNotFoundException e) {
298
				// ignore this since we can't do anything
304
				//				
299
				BugzillaPlugin.log(new Status(Status.ERROR, IBugzillaConstants.PLUGIN_ID, Status.ERROR,
305
				// // // ignore this since we can't do anything
300
						"Unable to read bug object", e));
306
				// // BugzillaPlugin.log(new Status(Status.ERROR,
307
				// // IBugzillaConstants.PLUGIN_ID, Status.ERROR,
308
				// // "Unable to read bug object", e));
309
				//				
310
				// }
301
			}
311
			}
312
313
		} finally {
314
			in.close();
302
		}
315
		}
303
		in.close();
304
	}
316
	}
305
317
306
	/**
318
	/**
Lines 309-315 Link Here
309
	 * @param indicesToRemove
321
	 * @param indicesToRemove
310
	 *            An array of the indicies of the bugs to be removed
322
	 *            An array of the indicies of the bugs to be removed
311
	 */
323
	 */
312
	public void remove(List<IBugzillaBug> sel) {
324
	public void remove(List<BugzillaReport> sel) {
313
		list.removeAll(sel);
325
		list.removeAll(sel);
314
326
315
		// rewrite the file so that the data is persistant
327
		// rewrite the file so that the data is persistant
Lines 327-454 Link Here
327
	}
339
	}
328
340
329
}
341
}
330
	// /**
342
// /**
331
	// * Function to sort the offline reports list
343
// * Function to sort the offline reports list
332
	// * @param sortOrder The way to sort the bugs in the offline reports list
344
// * @param sortOrder The way to sort the bugs in the offline reports list
333
	// */
345
// */
334
	// public void sort(int sortOrder) {
346
// public void sort(int sortOrder) {
335
	// IBugzillaBug[] a = list.toArray(new IBugzillaBug[list.size()]);
347
// IBugzillaBug[] a = list.toArray(new IBugzillaBug[list.size()]);
336
	//		
348
//		
337
	// // decide which sorting method to use and sort the offline reports
349
// // decide which sorting method to use and sort the offline reports
338
	// switch(sortOrder) {
350
// switch(sortOrder) {
339
	// case ID_SORT:
351
// case ID_SORT:
340
	// Arrays.sort(a, new SortID());
352
// Arrays.sort(a, new SortID());
341
	// lastSel = ID_SORT;
353
// lastSel = ID_SORT;
342
	// break;
354
// break;
343
	// case TYPE_SORT:
355
// case TYPE_SORT:
344
	// Arrays.sort(a, new SortType());
356
// Arrays.sort(a, new SortType());
345
	// lastSel = TYPE_SORT;
357
// lastSel = TYPE_SORT;
346
	// break;
358
// break;
347
	// }
359
// }
348
	//		
360
//		
349
	// // remove all of the elements from the list so that we can re-add
361
// // remove all of the elements from the list so that we can re-add
350
	// // them in a sorted order
362
// // them in a sorted order
351
	// list.clear();
363
// list.clear();
352
	//		
364
//		
353
	// // add the sorted elements to the list and the table
365
// // add the sorted elements to the list and the table
354
	// for (int j = 0; j < a.length; j++) {
366
// for (int j = 0; j < a.length; j++) {
355
	// add(a[j]);
367
// add(a[j]);
356
	// }
368
// }
357
	// }
369
// }
358
370
359
	// /**
371
// /**
360
	// * Inner class to sort by bug id
372
// * Inner class to sort by bug id
361
	// */
373
// */
362
	// private class SortID implements Comparator<IBugzillaBug> {
374
// private class SortID implements Comparator<IBugzillaBug> {
363
	// public int compare(IBugzillaBug f1, IBugzillaBug f2) {
375
// public int compare(IBugzillaBug f1, IBugzillaBug f2) {
364
	// Integer id1 = f1.getId();
376
// Integer id1 = f1.getId();
365
	// Integer id2 = f2.getId();
377
// Integer id2 = f2.getId();
366
	//
378
//
367
	// if(id1 != null && id2 != null)
379
// if(id1 != null && id2 != null)
368
	// return id1.compareTo(id2);
380
// return id1.compareTo(id2);
369
	// else if(id1 == null && id2 != null)
381
// else if(id1 == null && id2 != null)
370
	// return -1;
382
// return -1;
371
	// else if(id1 != null && id2 == null)
383
// else if(id1 != null && id2 == null)
372
	// return 1;
384
// return 1;
373
	// else
385
// else
374
	// return 0;
386
// return 0;
375
	// }
387
// }
376
	// }
388
// }
377
	//
389
//
378
	// /**
390
// /**
379
	// * Inner class to sort by bug type (locally created or from the server)
391
// * Inner class to sort by bug type (locally created or from the server)
380
	// */
392
// */
381
	// private class SortType implements Comparator<IBugzillaBug> {
393
// private class SortType implements Comparator<IBugzillaBug> {
382
	// public int compare(IBugzillaBug f1, IBugzillaBug f2) {
394
// public int compare(IBugzillaBug f1, IBugzillaBug f2) {
383
	// boolean isLocal1 = f1.isLocallyCreated();
395
// boolean isLocal1 = f1.isLocallyCreated();
384
	// boolean isLocal2 = f2.isLocallyCreated();
396
// boolean isLocal2 = f2.isLocallyCreated();
385
	//			
397
//			
386
	// if (isLocal1 && !isLocal2) {
398
// if (isLocal1 && !isLocal2) {
387
	// return -1;
399
// return -1;
388
	// }
400
// }
389
	// else if (!isLocal1 && isLocal2) {
401
// else if (!isLocal1 && isLocal2) {
390
	// return 1;
402
// return 1;
391
	// }
403
// }
392
	//			
404
//			
393
	// // If they are both the same type, sort by ID
405
// // If they are both the same type, sort by ID
394
	// Integer id1 = f1.getId();
406
// Integer id1 = f1.getId();
395
	// Integer id2 = f2.getId();
407
// Integer id2 = f2.getId();
396
	//
408
//
397
	// if(id1 != null && id2 != null)
409
// if(id1 != null && id2 != null)
398
	// return id1.compareTo(id2);
410
// return id1.compareTo(id2);
399
	// else if(id1 == null && id2 != null)
411
// else if(id1 == null && id2 != null)
400
	// return -1;
412
// return -1;
401
	// else if(id1 != null && id2 == null)
413
// else if(id1 != null && id2 == null)
402
	// return 1;
414
// return 1;
403
	// else
415
// else
404
	// return 0;
416
// return 0;
405
	// }
417
// }
406
	// }
418
// }
407
419
408
//	/**
420
// /**
409
//	 * Saves the given report to the offlineReportsFile, or, if it already
421
// * Saves the given report to the offlineReportsFile, or, if it already
410
//	 * exists in the file, updates it.
422
// * exists in the file, updates it.
411
//	 * 
423
// *
412
//	 * @param bug
424
// * @param bug
413
//	 *            The bug to add/update.
425
// * The bug to add/update.
414
//	 */
426
// */
415
//	public static void saveOffline(IBugzillaBug bug, boolean saveChosen) throws CoreException {
427
// public static void saveOffline(IBugzillaBug bug, boolean saveChosen) throws
416
//		OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
428
// CoreException {
417
//		// If there is already an offline report for this bug, update the file.
429
// OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
418
//		if (bug.isSavedOffline()) {
430
// // If there is already an offline report for this bug, update the file.
419
//			file.update();
431
// if (bug.isSavedOffline()) {
420
//		}
432
// file.update();
421
//		// If this bug has not been saved offline before, add it to the file.
433
// }
422
//		else {
434
// // If this bug has not been saved offline before, add it to the file.
423
//			int index = -1;
435
// else {
424
//			// If there is already an offline report with the same id, don't
436
// int index = -1;
425
//			// save this report.
437
// // If there is already an offline report with the same id, don't
426
//			if ((index = file.find(bug.getId())) >= 0) {
438
// // save this report.
427
//				removeReport(getOfflineBugs().get(index));
439
// if ((index = file.find(bug.getId())) >= 0) {
428
//				// MessageDialog.openInformation(null, "Bug's Id is already
440
// removeReport(getOfflineBugs().get(index));
429
//				// used.", "There is already a bug saved offline with an
441
// // MessageDialog.openInformation(null, "Bug's Id is already
430
//				// identical id.");
442
// // used.", "There is already a bug saved offline with an
431
//				// return;
443
// // identical id.");
432
//			}
444
// // return;
433
//			file.add(bug, saveChosen);
445
// }
434
//			bug.setOfflineState(true);
446
// file.add(bug, saveChosen);
435
//			// file.sort(OfflineReportsFile.lastSel);
447
// bug.setOfflineState(true);
436
//		}
448
// // file.sort(OfflineReportsFile.lastSel);
437
//	}
449
// }
438
450
// }
439
//	public static List<IBugzillaBug> getOfflineBugs() {
451
440
//		OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
452
// public static List<IBugzillaBug> getOfflineBugs() {
441
//		return file.elements();
453
// OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
442
//	}
454
// return file.elements();
455
// }
443
//
456
//
444
//	/**
457
// /**
445
//	 * Removes the given report from the offlineReportsFile.
458
// * Removes the given report from the offlineReportsFile.
446
//	 * 
459
// *
447
//	 * @param bug
460
// * @param bug
448
//	 *            The report to remove.
461
// * The report to remove.
449
//	 */
462
// */
450
//	public static void removeReport(IBugzillaBug bug) {
463
// public static void removeReport(IBugzillaBug bug) {
451
//		ArrayList<IBugzillaBug> bugList = new ArrayList<IBugzillaBug>();
464
// ArrayList<IBugzillaBug> bugList = new ArrayList<IBugzillaBug>();
452
//		bugList.add(bug);
465
// bugList.add(bug);
453
//		BugzillaPlugin.getDefault().getOfflineReports().remove(bugList);
466
// BugzillaPlugin.getDefault().getOfflineReports().remove(bugList);
454
//	}
467
// }
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/ServerConfigurationFactory.java (-89 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.io.StringReader;
18
import java.net.URL;
19
import java.net.URLConnection;
20
21
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
22
import org.xml.sax.ErrorHandler;
23
import org.xml.sax.InputSource;
24
import org.xml.sax.SAXException;
25
import org.xml.sax.SAXParseException;
26
import org.xml.sax.XMLReader;
27
import org.xml.sax.helpers.XMLReaderFactory;
28
29
/**
30
 * Reads bugzilla product configuration from config.cgi on server in RDF format.
31
 * 
32
 * @author Rob Elves
33
 */
34
public class ServerConfigurationFactory {
35
36
	private static final String CONFIG_RDF_URL = "/config.cgi?ctype=rdf";
37
38
	private static ServerConfigurationFactory instance;
39
40
	private ServerConfigurationFactory() {
41
		// no initial setup needed
42
	}
43
44
	public static ServerConfigurationFactory getInstance() {
45
		if (instance == null) {
46
			instance = new ServerConfigurationFactory();
47
		}
48
		return instance;
49
	}
50
51
	public RepositoryConfiguration getConfiguration(String server) throws IOException {
52
		URL serverURL = new URL(server + CONFIG_RDF_URL);
53
		URLConnection c = serverURL.openConnection();
54
		BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
55
56
		SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
57
58
		try {
59
			StringBuffer result = XmlCleaner.clean(in);
60
			StringReader strReader = new StringReader(result.toString());
61
			XMLReader reader = XMLReaderFactory.createXMLReader();
62
			reader.setErrorHandler(new SaxErrorHandler());
63
			reader.setContentHandler(contentHandler);
64
			reader.parse(new InputSource(strReader));
65
		} catch (SAXException e) {
66
			throw new IOException("Unable to read server configuration.");
67
		}
68
		return contentHandler.getConfiguration();
69
70
	}
71
72
	class SaxErrorHandler implements ErrorHandler {
73
74
		public void error(SAXParseException exception) throws SAXException {
75
			MylarStatusHandler.fail(exception, "ServerConfigurationFactory: " + exception.getLocalizedMessage(), false);
76
		}
77
78
		public void fatalError(SAXParseException exception) throws SAXException {
79
			MylarStatusHandler.fail(exception, "ServerConfigurationFactory: " + exception.getLocalizedMessage(), false);
80
81
		}
82
83
		public void warning(SAXParseException exception) throws SAXException {
84
			// ignore
85
		}
86
87
	}
88
89
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/RepositoryConfiguration.java (-2 / +47 lines)
Lines 43-48 Link Here
43
43
44
	private List<String> resolutionValues = new ArrayList<String>();
44
	private List<String> resolutionValues = new ArrayList<String>();
45
45
46
	private List<String> keywords = new ArrayList<String>();
47
46
	// master lists
48
	// master lists
47
49
48
	private List<String> versions = new ArrayList<String>();
50
	private List<String> versions = new ArrayList<String>();
Lines 88-94 Link Here
88
	 */
90
	 */
89
	public List<String> getProducts() {
91
	public List<String> getProducts() {
90
		ArrayList<String> productList = new ArrayList<String>(products.keySet());
92
		ArrayList<String> productList = new ArrayList<String>(products.keySet());
91
		Collections.sort(productList); 
93
		Collections.sort(productList);
92
		return productList;
94
		return productList;
93
	}
95
	}
94
96
Lines 214-226 Link Here
214
	// }
216
	// }
215
	// }
217
	// }
216
218
219
	public void addKeyword(String keyword) {
220
		keywords.add(keyword);
221
	}
222
223
	public List<String> getKeywords() {
224
		return keywords;
225
	}
226
217
	public void addPlatform(String platform) {
227
	public void addPlatform(String platform) {
218
		platforms.add(platform);
228
		platforms.add(platform);
219
	}
229
	}
220
230
221
	public void addPriority(String priority) {
231
	public void addPriority(String priority) {
222
		priorities.add(priority);
232
		priorities.add(priority);
223
224
	}
233
	}
225
234
226
	public void addSeverity(String severity) {
235
	public void addSeverity(String severity) {
Lines 323-326 Link Here
323
		return versions;
332
		return versions;
324
	}
333
	}
325
334
335
	/*
336
	 * Intermediate step until configuration is made generic.
337
	 */
338
339
	public List<String> getOptionValues(BugzillaReportElement element, String product) {
340
		switch (element) {
341
		case PRODUCT:
342
			return getProducts();
343
		case TARGET_MILESTONE:
344
			// return getTargetMilestones();
345
			return getTargetMilestones(product);
346
		case BUG_STATUS:
347
			return getStatusValues();
348
		case VERSION:
349
			// return getVersions();
350
			return getVersions(product);
351
		case COMPONENT:
352
			// return getComponents();
353
			return getComponents(product);
354
		case REP_PLATFORM:
355
			return getPlatforms();
356
		case OP_SYS:
357
			return getOSs();
358
		case PRIORITY:
359
			return getPriorities();
360
		case BUG_SEVERITY:
361
			return getSeverities();
362
		case KEYWORDS:
363
			return getKeywords();
364
		case RESOLUTION:
365
			return getResolutions();
366
		default:
367
			return new ArrayList<String>();
368
		}
369
	}
370
326
}
371
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/Favorite.java (-2 / +2 lines)
Lines 14-20 Link Here
14
import java.util.Date;
14
import java.util.Date;
15
import java.util.Map;
15
import java.util.Map;
16
16
17
import org.eclipse.mylar.bugzilla.core.BugReport;
17
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
18
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchResultCollector;
18
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchResultCollector;
19
19
20
/**
20
/**
Lines 48-54 Link Here
48
	 * @param bug
48
	 * @param bug
49
	 *            The bug this favorite represents.
49
	 *            The bug this favorite represents.
50
	 */
50
	 */
51
	public Favorite(BugReport bug) {
51
	public Favorite(BugzillaReport bug) {
52
		this(bug.getRepositoryUrl(), bug.getId(), bug.getSummary(), "", BugzillaSearchResultCollector.getAttributeMap(bug));
52
		this(bug.getRepositoryUrl(), bug.getId(), bug.getSummary(), "", BugzillaSearchResultCollector.getAttributeMap(bug));
53
	}
53
	}
54
54
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/BugParser.java (-1107 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.core.internal;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.InputStreamReader;
16
import java.io.Reader;
17
import java.net.URL;
18
import java.net.URLConnection;
19
import java.net.URLEncoder;
20
import java.nio.charset.Charset;
21
import java.text.ParseException;
22
import java.text.SimpleDateFormat;
23
import java.util.Calendar;
24
import java.util.Date;
25
import java.util.Iterator;
26
import java.util.List;
27
28
import javax.security.auth.login.LoginException;
29
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.Status;
32
import org.eclipse.mylar.bugzilla.core.Attribute;
33
import org.eclipse.mylar.bugzilla.core.BugReport;
34
import org.eclipse.mylar.bugzilla.core.Comment;
35
import org.eclipse.mylar.bugzilla.core.Operation;
36
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
37
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
38
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
39
40
/**
41
 * @author Shawn Minto
42
 * @author Mik Kersten (hardening of prototype)
43
 * @author Rob Elves (attachments) This class parses bugs so that they can be
44
 *         displayed using the bug editor
45
 */
46
public class BugParser {
47
48
	private static final String VALUE_ATTACHMENT_OBSOLETE = "bz_obsolete";
49
50
	private static final String ATTRIBUTE_CLASS = "class";
51
52
	private static final String TAG_SPAN = "span";
53
54
	private static final String ATTRIBUTE_ID_TITLE = "title";
55
56
	private static final String ATTRIBUTE_ID_HREF = "href";
57
58
	private static final String ATTACHMENT_CGI_ID = "attachment.cgi?id=";
59
60
	private static final String KEY_BUG_NUM = "Bug#";
61
62
	private static final String KEY_RESOLUTION = "resolution";
63
64
	private static final String KEY_VALUE = "value";
65
66
	private static final String KEY_NAME = "name";
67
68
	private static final String ATTR_CHARSET = "charset";
69
70
	/** Parser for dates in the report */
71
	private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
72
73
	private static final String keywordsUrl = "describekeywords.cgi";
74
75
	/**
76
	 * Parse the case where we have found an attribute name
77
	 * 
78
	 * @param in
79
	 *            The input stream for the bug
80
	 * @return The name of the attribute that we are parsing
81
	 * @throws IOException
82
	 */
83
	private static String parseAttributeName(HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
84
		StringBuffer sb = new StringBuffer();
85
86
		parseTableCell(tokenizer, sb);
87
		HtmlStreamTokenizer.unescape(sb);
88
		// remove the colon if there is one
89
		if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ':') {
90
			sb.deleteCharAt(sb.length() - 1);
91
		}
92
		return sb.toString();
93
	}
94
95
	/**
96
	 * Parse the case where we have found attribute values
97
	 * 
98
	 * @param in
99
	 *            The input stream of the bug
100
	 * @param bug
101
	 *            The bug report for the current bug
102
	 * @param attribute
103
	 *            The name of the attribute
104
	 * @throws IOException
105
	 */
106
	private static void parseAttributeValue(BugReport bug, String originalAttributeName, HtmlStreamTokenizer tokenizer,
107
			String serverUrl, String userName, String password) throws IOException, ParseException {
108
109
		// NOTE: special rule to deal with change in 2.20.1
110
		String attributeName = originalAttributeName;
111
		if (attributeName.endsWith(KEY_BUG_NUM) && attributeName.length() > KEY_BUG_NUM.length()) {
112
			attributeName = originalAttributeName.substring(attributeName.length() - KEY_BUG_NUM.length(),
113
					attributeName.length());
114
		}
115
116
		Token token = tokenizer.nextToken();
117
		if (token.getType() == Token.TAG) {
118
			HtmlTag tag = (HtmlTag) token.getValue();
119
120
			// make sure that we are on a tag that we care about, not a label
121
			// fix added so that we can parse the mozilla bug pages
122
			if (tag.getTagType() == HtmlTag.Type.LABEL) {
123
				token = tokenizer.nextToken();
124
				if (token.getType() == Token.TAG)
125
					tag = (HtmlTag) token.getValue();
126
				else {
127
					StringBuffer sb = new StringBuffer();
128
					if (token.getType() == Token.TEXT) {
129
						sb.append((StringBuffer) token.getValue());
130
						parseAttributeValueCell(bug, attributeName, tokenizer, sb);
131
					}
132
				}
133
			}
134
135
			if (tag.getTagType() == HtmlTag.Type.SELECT && !tag.isEndTag()) {
136
				String parameterName = tag.getAttribute(KEY_NAME);
137
				parseSelect(bug, attributeName, parameterName, tokenizer);
138
			} else if (tag.getTagType() == HtmlTag.Type.INPUT && !tag.isEndTag()) {
139
				parseInput(bug, attributeName, tag, serverUrl, userName, password);
140
			} else if (!tag.isEndTag() || attributeName.equalsIgnoreCase(KEY_RESOLUTION)) {
141
				if (tag.isEndTag() && attributeName.equalsIgnoreCase(KEY_RESOLUTION)) {
142
					Attribute a = new Attribute(attributeName);
143
					a.setValue("");
144
					bug.addAttribute(a);
145
				}
146
				parseAttributeValueCell(bug, attributeName, tokenizer);
147
			}
148
		} else {
149
			StringBuffer sb = new StringBuffer();
150
			if (token.getType() == Token.TEXT) {
151
				sb.append((StringBuffer) token.getValue());
152
				parseAttributeValueCell(bug, attributeName, tokenizer, sb);
153
			}
154
		}
155
	}
156
157
	/**
158
	 * Parse the case where the attribute value is just text in a table cell
159
	 * 
160
	 * @param in
161
	 *            The input stream of the bug
162
	 * @param bug
163
	 *            The bug report for the current bug
164
	 * @param attributeName
165
	 *            The name of the attribute that we are parsing
166
	 * @throws IOException
167
	 */
168
	private static void parseAttributeValueCell(BugReport bug, String attributeName, HtmlStreamTokenizer tokenizer)
169
			throws IOException, ParseException {
170
		StringBuffer sb = new StringBuffer();
171
		parseAttributeValueCell(bug, attributeName, tokenizer, sb);
172
	}
173
174
	private static void parseAttributeValueCell(BugReport bug, String attributeName, HtmlStreamTokenizer tokenizer,
175
			StringBuffer sb) throws IOException, ParseException {
176
177
		parseTableCell(tokenizer, sb);
178
		HtmlStreamTokenizer.unescape(sb);
179
180
		// create a new attribute and set its value to the value that we
181
		// retrieved
182
		Attribute a = new Attribute(attributeName);
183
		a.setValue(sb.toString());
184
185
		// if we found an attachment attribute, forget about it, else add the
186
		// attribute to the bug report
187
		if (attributeName.toLowerCase().startsWith("attachments")) {
188
			// do nothing
189
		} else {
190
			if (attributeName.equals(KEY_BUG_NUM))
191
				a.setValue(a.getValue().replaceFirst("alias:", ""));
192
			bug.addAttribute(a);
193
		}
194
	}
195
196
	/**
197
	 * Reads text into a StringBuffer until it encounters a close table cell tag
198
	 * (&lt;/TD&gt;) or start of another cell. The text is appended to the
199
	 * existing value of the buffer. <b>NOTE:</b> Does not handle nested cells!
200
	 * 
201
	 * @param tokenizer
202
	 * @param sb
203
	 * @throws IOException
204
	 * @throws ParseException
205
	 */
206
	private static void parseTableCell(HtmlStreamTokenizer tokenizer, StringBuffer sb) throws IOException,
207
			ParseException {
208
		boolean noWhitespace = false;
209
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
210
			if (token.getType() == Token.TAG) {
211
				HtmlTag tag = (HtmlTag) token.getValue();
212
				if (tag.getTagType() == HtmlTag.Type.TD) {
213
					if (!tag.isEndTag()) {
214
						tokenizer.pushback(token);
215
					}
216
					break;
217
				}
218
				noWhitespace = token.getWhitespace().length() == 0;
219
			} else if (token.getType() == Token.TEXT) {
220
				// if there was no whitespace between the tag and the
221
				// preceding text, don't insert whitespace before this text
222
				// unless it is there in the source
223
				if (!noWhitespace && token.getWhitespace().length() > 0 && sb.length() > 0) {
224
					sb.append(' ');
225
				}
226
				sb.append((StringBuffer) token.getValue());
227
			}
228
		}
229
	}
230
231
	/**
232
	 * Parse the case where the attribute value is an option
233
	 * 
234
	 * @param in
235
	 *            The input stream for the bug
236
	 * @param bug
237
	 *            The bug report for the current bug
238
	 * @param attribute
239
	 *            The name of the attribute that we are parsing
240
	 * @param parameterName
241
	 *            the SELECT tag's name
242
	 * @throws IOException
243
	 */
244
	private static void parseSelect(BugReport bug, String attributeName, String parameterName,
245
			HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
246
247
		boolean first = false;
248
		Attribute a = new Attribute(attributeName);
249
		a.setParameterName(parameterName);
250
251
		Token token = tokenizer.nextToken();
252
		while (token.getType() != Token.EOF) {
253
			if (token.getType() == Token.TAG) {
254
				HtmlTag tag = (HtmlTag) token.getValue();
255
				if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
256
					break;
257
				if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
258
					String optionName = tag.getAttribute(KEY_VALUE);
259
					boolean selected = tag.hasAttribute("selected");
260
					StringBuffer optionText = new StringBuffer();
261
					for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer.nextToken()) {
262
						if (optionText.length() > 0) {
263
							optionText.append(' ');
264
						}
265
						optionText.append((StringBuffer) token.getValue());
266
					}
267
					a.addOptionValue(optionText.toString(), optionName);
268
					if (selected || first) {
269
						a.setValue(optionText.toString());
270
						first = false;
271
					}
272
				} else {
273
					token = tokenizer.nextToken();
274
				}
275
			} else {
276
				token = tokenizer.nextToken();
277
			}
278
		}
279
280
		// if we parsed the cc field add the e-mails to the bug report else add
281
		// the attribute to the bug report
282
		if (attributeName.toLowerCase().startsWith("cc")) {
283
			for (Iterator<String> it = a.getOptionValues().keySet().iterator(); it.hasNext();) {
284
				String email = it.next();
285
				bug.addCC(HtmlStreamTokenizer.unescape(email));
286
			}
287
		} else {
288
			bug.addAttribute(a);
289
		}
290
	}
291
292
	/**
293
	 * Parse the case where the attribute value is an input
294
	 * 
295
	 * @param bug
296
	 *            The bug report for the current bug
297
	 * @param attributeName
298
	 *            The name of the attribute
299
	 * @param tag
300
	 *            The INPUT tag
301
	 * @throws IOException
302
	 */
303
	private static void parseInput(BugReport bug, String attributeName, HtmlTag tag, String serverUrl, String userName,
304
			String password) throws IOException {
305
306
		Attribute a = new Attribute(attributeName);
307
		a.setParameterName(tag.getAttribute(KEY_NAME));
308
		String name = tag.getAttribute(KEY_NAME);
309
		String value = tag.getAttribute(KEY_VALUE);
310
		if (value == null)
311
			value = "";
312
313
		// if we found the summary, add it to the bug report
314
		if (name.equalsIgnoreCase("short_desc")) {
315
			bug.setSummary(value);
316
		} else if (name.equalsIgnoreCase("bug_file_loc")) {
317
			a.setValue(value);
318
			bug.addAttribute(a);
319
		} else if (name.equalsIgnoreCase("newcc")) {
320
			a.setValue(value);
321
			bug.addAttribute(a);
322
		} else {
323
			// otherwise just add the attribute
324
			a.setValue(value);
325
			bug.addAttribute(a);
326
327
			if (attributeName.equalsIgnoreCase("keywords") && serverUrl != null) {
328
329
				BufferedReader input = null;
330
				try {
331
332
					String urlText = "";
333
334
					// if we have a user name, may as well log in just in case
335
					// it is required
336
					if (userName != null && !userName.equals("") && password != null && !password.equals("")) {
337
						/*
338
						 * The UnsupportedEncodingException exception for
339
						 * URLEncoder.encode() should not be thrown, since every
340
						 * implementation of the Java platform is required to
341
						 * support the standard charset "UTF-8"
342
						 */
343
						urlText += "?GoAheadAndLogIn=1&Bugzilla_login=" + URLEncoder.encode(userName, "UTF-8")
344
								+ "&Bugzilla_password=" + URLEncoder.encode(password, "UTF-8");
345
					}
346
347
					// connect to the bugzilla server to get the keyword list
348
					URL url = new URL(serverUrl + "/" + keywordsUrl + urlText);
349
					URLConnection urlConnection = BugzillaPlugin.getDefault().getUrlConnection(url);
350
					input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
351
352
					// parse the valid keywords and add them to the bug
353
					List<String> keywords = new KeywordParser(input).getKeywords();
354
					bug.setKeywords(keywords);
355
356
				} catch (Exception e) {
357
					// throw an exception if there is a problem reading the bug
358
					// from the server
359
					throw new IOException("Exception while fetching the list of keywords from the server: "
360
							+ e.getMessage());
361
				} finally {
362
					try {
363
						if (input != null)
364
							input.close();
365
					} catch (IOException e) {
366
						BugzillaPlugin.log(new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
367
								"Problem closing the stream", e));
368
					}
369
				}
370
			}
371
		}
372
	}
373
374
	/**
375
	 * Parse the case where we are dealing with the description
376
	 * 
377
	 * @param bug
378
	 *            The bug report for the bug
379
	 * @throws IOException
380
	 */
381
	private static void parseDescription(BugReport bug, HtmlStreamTokenizer tokenizer) throws IOException,
382
			ParseException {
383
384
		StringBuffer sb = new StringBuffer();
385
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
386
			if (token.getType() == Token.TAG) {
387
				HtmlTag tag = (HtmlTag) token.getValue();
388
				if (sb.length() > 0) {
389
					sb.append(token.getWhitespace());
390
				}
391
				if (tag.getTagType() == HtmlTag.Type.PRE && tag.isEndTag())
392
					break;
393
			} else if (token.getType() == Token.TEXT) {
394
				if (sb.length() > 0) {
395
					sb.append(token.getWhitespace());
396
				}
397
				sb.append((StringBuffer) token.getValue());
398
			}
399
		}
400
401
		// set the bug to have the description we retrieved
402
		String text = HtmlStreamTokenizer.unescape(sb).toString();
403
		bug.setDescription(text);
404
	}
405
406
	// /**
407
	// * parses the description of an attachment on the report
408
	// */
409
	// private static String parseAttachementDescription(HtmlStreamTokenizer
410
	// tokenizer) throws IOException,
411
	// ParseException {
412
	//
413
	// StringBuffer sb = new StringBuffer();
414
	// for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF;
415
	// token = tokenizer.nextToken()) {
416
	// if (token.getType() == Token.TAG) {
417
	// HtmlTag tag = (HtmlTag) token.getValue();
418
	// if (tag.getTagType() == HtmlTag.Type.A && tag.isEndTag())
419
	// break;
420
	// } else if (token.getType() == Token.TEXT) {
421
	// if (sb.length() > 0) {
422
	// sb.append(token.getWhitespace());
423
	// }
424
	// sb.append((StringBuffer) token.getValue());
425
	// }
426
	// }
427
	//
428
	// // set the bug to have the description we retrieved
429
	// String text = HtmlStreamTokenizer.unescape(sb).toString();
430
	// return text;
431
	// }
432
433
	/**
434
	 * Parse the case where we have found the start of a comment
435
	 * 
436
	 * @param in
437
	 *            The input stream of the bug
438
	 * @param bug
439
	 *            The bug report for the current bug
440
	 * @return The comment that we have created with the information
441
	 * @throws IOException
442
	 * @throws ParseException
443
	 */
444
	private static Comment parseCommentHead(BugReport bug, HtmlStreamTokenizer tokenizer) throws IOException,
445
			ParseException {
446
		int number = 0;
447
		Date date = null;
448
		String author = null;
449
		String authorName = null;
450
451
		// get the comment's number
452
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
453
			if (token.getType() == Token.TAG) {
454
				HtmlTag tag = (HtmlTag) token.getValue();
455
				if (tag.getTagType() == HtmlTag.Type.A) {
456
					String href = tag.getAttribute(ATTRIBUTE_ID_HREF);
457
					if (href != null) {
458
						int index = href.toLowerCase().indexOf("#c");
459
						if (index == -1)
460
							continue;
461
						token = tokenizer.nextToken();
462
						number = Integer.parseInt(((StringBuffer) token.getValue()).toString().substring(1));
463
						break;
464
					}
465
				}
466
			}
467
		}
468
469
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
470
			if (token.getType() == Token.TAG) {
471
				HtmlTag tag = (HtmlTag) token.getValue();
472
				if (tag.getTagType() == HtmlTag.Type.A) {
473
					String href = tag.getAttribute(ATTRIBUTE_ID_HREF);
474
					if (href != null) {
475
						int index = href.toLowerCase().indexOf("mailto");
476
						if (index == -1)
477
							continue;
478
						author = href.substring(index + 7);
479
						break;
480
					}
481
				}
482
			}
483
		}
484
485
		// get the author's real name
486
		StringBuffer sb = new StringBuffer();
487
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
488
			if (token.getType() == Token.TAG) {
489
				HtmlTag tag = (HtmlTag) token.getValue();
490
				if (tag.getTagType() == HtmlTag.Type.A && tag.isEndTag())
491
					break;
492
			} else if (token.getType() == Token.TEXT) {
493
				if (sb.length() > 0) {
494
					sb.append(' ');
495
				}
496
				sb.append((StringBuffer) token.getValue());
497
			}
498
		}
499
		authorName = sb.toString();
500
501
		// get the comment's date
502
		sb.setLength(0);
503
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
504
			if (token.getType() == Token.TAG) {
505
				HtmlTag tag = (HtmlTag) token.getValue();
506
				if (tag.getTagType() == HtmlTag.Type.I && tag.isEndTag())
507
					break;
508
			} else if (token.getType() == Token.TEXT) {
509
				if (sb.length() > 0) {
510
					sb.append(' ');
511
				}
512
				sb.append((StringBuffer) token.getValue());
513
			}
514
		}
515
		try {
516
			if (sb.length() >= 16) {
517
				date = df.parse(sb.substring(0, 16));
518
			}
519
		} catch (Exception e) {
520
			date = Calendar.getInstance().getTime(); // XXX: could not
521
			// determine date
522
		}
523
		return new Comment(bug, number, date, author, authorName);
524
	}
525
526
	/**
527
	 * Parse the case where we have comment text
528
	 * 
529
	 * @param in
530
	 *            The input stream for the bug
531
	 * @param bug
532
	 *            The bug report for the current bug
533
	 * @param comment
534
	 *            The comment to add the text to
535
	 * @throws IOException
536
	 */
537
	private static void parseCommentText(BugReport bug, Comment comment, HtmlStreamTokenizer tokenizer)
538
			throws IOException, ParseException {
539
540
		StringBuffer commentStringBuffer = new StringBuffer();
541
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
542
			if (token.getType() == Token.TAG) {
543
				HtmlTag tag = (HtmlTag) token.getValue();
544
				if (tag.getTagName().equals(TAG_SPAN)) {
545
					if(tag.hasAttribute(ATTRIBUTE_CLASS) && tag.getAttribute(ATTRIBUTE_CLASS).equals("")) {
546
						parseAttachment(commentStringBuffer, comment, tokenizer, false);
547
						continue;
548
					} else if(tag.hasAttribute(ATTRIBUTE_CLASS) && tag.getAttribute(ATTRIBUTE_CLASS).equals(VALUE_ATTACHMENT_OBSOLETE)) {
549
						parseAttachment(commentStringBuffer, comment, tokenizer, true);
550
						continue;
551
					}
552
				}
553
				// added to ensure whitespace is not
554
				// lost if adding a tag within a tag
555
				if (commentStringBuffer.length() > 0) {
556
					commentStringBuffer.append(token.getWhitespace());
557
				}
558
				if (tag.getTagType() == HtmlTag.Type.PRE && tag.isEndTag())
559
					break;
560
			} else if (token.getType() == Token.TEXT) {
561
				if (commentStringBuffer.length() > 0) {
562
					commentStringBuffer.append(token.getWhitespace());
563
				}
564
				commentStringBuffer.append((StringBuffer) token.getValue());
565
			}
566
			// remove attachment description from comment body
567
			if (comment.hasAttachment() && commentStringBuffer.indexOf(comment.getAttachmentDescription()) == 0) {
568
				commentStringBuffer = new StringBuffer();
569
			}
570
		}
571
572
		HtmlStreamTokenizer.unescape(commentStringBuffer);
573
		comment.setText(commentStringBuffer.toString());
574
		bug.addComment(comment);
575
	}
576
577
	private static void parseAttachment(StringBuffer stringBuffer, Comment comment, HtmlStreamTokenizer tokenizer, boolean obsolete)
578
			throws IOException, ParseException {
579
580
		int attachmentID = -1;
581
		String attachmentDescription = "";
582
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
583
			if (token.getType() == Token.TAG) {
584
				HtmlTag tag = (HtmlTag) token.getValue();
585
586
				if (tag.getTagType() == HtmlTag.Type.A && !comment.hasAttachment()) {
587
					if (tag.getAttribute(ATTRIBUTE_ID_HREF) != null) {
588
						String link = tag.getAttribute(ATTRIBUTE_ID_HREF);
589
						if (link.startsWith(ATTACHMENT_CGI_ID)) {
590
							try {
591
								int endIndex = link.indexOf("&");
592
								if (endIndex > 0 && endIndex < link.length()) {
593
									attachmentID = Integer.parseInt(link
594
											.substring(ATTACHMENT_CGI_ID.length(), endIndex));
595
								}
596
							} catch (NumberFormatException e) {
597
								return;
598
							}
599
						}
600
						if (tag.getAttribute(ATTRIBUTE_ID_TITLE) != null) {
601
							attachmentDescription = tag.getAttribute(ATTRIBUTE_ID_TITLE);
602
						}
603
						if (attachmentID > 0) {
604
							comment.setHasAttachment(true);
605
							comment.setAttachmentId(attachmentID);
606
							comment.setAttachmentDescription(attachmentDescription);
607
							comment.setObsolete(obsolete);
608
						}
609
610
					}
611
				}
612
				if (tag.getTagName().equals(TAG_SPAN) && tag.isEndTag())
613
					break;
614
			}
615
		}
616
	}
617
618
	/**
619
	 * Parse the full html version of the bug
620
	 * 
621
	 * @param in -
622
	 *            the input stream for the bug
623
	 * @param id -
624
	 *            the id of the bug that is to be parsed
625
	 * @return A bug report for the bug that was parsed
626
	 * @throws IOException
627
	 * @throws ParseException
628
	 */
629
	public static BugReport parseBug(Reader in, int id, String serverUrl, boolean is218, String userName,
630
			String password, String contentType) throws IOException, ParseException, LoginException {
631
		// create a new bug report and set the parser state to the start state
632
		BugReport bug = new BugReport(id, serverUrl);
633
		boolean contentTypeResolved = false;
634
		if (contentType != null) {
635
			String charsetFromContentType = getCharsetFromString(contentType);
636
			if (charsetFromContentType != null) {
637
				bug.setCharset(charsetFromContentType);
638
				contentTypeResolved = true;
639
			}
640
		}
641
		ParserState state = ParserState.START;
642
		Comment comment = null;
643
		String attribute = null;
644
645
		HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
646
647
		boolean isTitle = false;
648
		boolean possibleBadLogin = false;
649
		boolean checkBody = false;
650
		String title = "";
651
		StringBuffer body = new StringBuffer();
652
653
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
654
655
			// get the charset from the HTML if not specified
656
			if (!contentTypeResolved) {
657
				if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.META
658
						&& !((HtmlTag) (token.getValue())).isEndTag()) {
659
					String charsetFromHtml = getCharsetFromString(token.toString());
660
					if (charsetFromHtml != null)
661
						bug.setCharset(charsetFromHtml);
662
				}
663
			}
664
665
			// make sure that bugzilla doesn't want us to login
666
			if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
667
					&& !((HtmlTag) (token.getValue())).isEndTag()) {
668
				isTitle = true;
669
				continue;
670
			}
671
672
			if (isTitle) {
673
				// get all of the data in the title tag
674
				if (token.getType() != Token.TAG) {
675
					title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
676
					continue;
677
				} else if (token.getType() == Token.TAG
678
						&& ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
679
						&& ((HtmlTag) token.getValue()).isEndTag()) {
680
					// check and see if the title seems as though we have wrong
681
					// login info
682
					if (title.indexOf("login") != -1
683
							|| (title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
684
							|| title.indexOf("check e-mail") != -1)
685
						possibleBadLogin = true; // we possibly have a bad
686
					// login
687
688
					// if the title starts with error, we may have a login
689
					// problem, or
690
					// there is a problem with the bug (doesn't exist), so we
691
					// must do
692
					// some more checks
693
					if (title.startsWith("error"))
694
						checkBody = true;
695
696
					isTitle = false;
697
					title = "";
698
				}
699
				continue;
700
			}
701
702
			// if we have to add all of the text so that we can check it later
703
			// for problems with the username and password
704
			if (checkBody && token.getType() == Token.TEXT) {
705
				body.append((StringBuffer) token.getValue());
706
				body.append(" ");
707
			}
708
709
			// we have found the start of an attribute name
710
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
711
				HtmlTag tag = (HtmlTag) token.getValue();
712
				if (tag.getTagType() == HtmlTag.Type.TD && "right".equalsIgnoreCase(tag.getAttribute("align"))) {
713
					// parse the attribute's name
714
					attribute = parseAttributeName(tokenizer);
715
					if (attribute != null && attribute.contains(IBugzillaConstants.INVALID_2201_ATTRIBUTE_IGNORED)) {
716
						continue;
717
					}
718
					if (attribute.toLowerCase().startsWith("opened")) {
719
						// find the colon so we can get the date
720
						int index = attribute.toLowerCase().indexOf(":");
721
						String date;
722
						if (index != -1)
723
							date = attribute.substring(index + 1).trim();
724
						else
725
							date = attribute.substring(6).trim();
726
727
						// set the bugs opened date to be the date we parsed
728
						bug.setCreated(df.parse(date));
729
						state = ParserState.ATT_NAME;
730
						continue;
731
					}
732
733
					// in 2.18, the last modified looks like the opened so we
734
					// need to parse it differently
735
					if (attribute.toLowerCase().startsWith("last modified") && is218) {
736
						// find the colon so we can get the date
737
						int index = attribute.toLowerCase().indexOf(":");
738
						String date;
739
						if (index != -1)
740
							date = attribute.substring(index + 1).trim();
741
						else
742
							date = attribute.substring(6).trim();
743
744
						// create a new attribute and set the date
745
						Attribute t = new Attribute("Last Modified");
746
						t.setValue(date);
747
748
						// add the attribute to the bug report
749
						bug.addAttribute(t);
750
						bug.setLastModified(df.parse(date));
751
						state = ParserState.ATT_NAME;
752
						continue;
753
					}
754
755
					state = ParserState.ATT_VALUE;
756
					continue;
757
				} else if (tag.getTagType() == HtmlTag.Type.INPUT && "radio".equalsIgnoreCase(tag.getAttribute("type"))
758
						&& "knob".equalsIgnoreCase(tag.getAttribute(KEY_NAME))) {
759
					// we found a radio button
760
					parseOperations(bug, tokenizer, tag, is218);
761
				}
762
			}
763
764
			// we have found the start of attribute values
765
			if (state == ParserState.ATT_VALUE && token.getType() == Token.TAG) {
766
				HtmlTag tag = (HtmlTag) token.getValue();
767
				if (tag.getTagType() == HtmlTag.Type.TD) {
768
					// parse the attribute values
769
					parseAttributeValue(bug, attribute, tokenizer, serverUrl, userName, password);
770
771
					state = ParserState.ATT_NAME;
772
					attribute = null;
773
					continue;
774
				}
775
			}
776
777
			// we have found the start of a comment
778
			if (state == ParserState.DESC_START && token.getType() == Token.TAG) {
779
				HtmlTag tag = (HtmlTag) token.getValue();
780
				if (tag.getTagType() == HtmlTag.Type.I) {
781
					// parse the comment's start
782
					comment = parseCommentHead(bug, tokenizer);
783
784
					state = ParserState.DESC_VALUE;
785
					continue;
786
				}
787
			}
788
789
			// we have found the start of the comment text
790
			if (state == ParserState.DESC_VALUE && token.getType() == Token.TAG) {
791
				HtmlTag tag = (HtmlTag) token.getValue();
792
				if (tag.getTagType() == HtmlTag.Type.PRE) {
793
					// parse the text of the comment
794
					parseCommentText(bug, comment, tokenizer);
795
796
					comment = null;
797
					state = ParserState.DESC_START;
798
					continue;
799
				}
800
			}
801
			
802
			// last modification date
803
			if (bug.getCreated() == null && (state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
804
				HtmlTag tag = (HtmlTag) token.getValue();
805
				if (tag.getTagType() == HtmlTag.Type.DIV && tag.getAttribute("id") != null && "header".equalsIgnoreCase(tag.getAttribute("id"))) {
806
					StringBuffer sb = new StringBuffer();
807
					parseLastModified(sb, tokenizer);					
808
					if(sb.length() > 0) {
809
						int index = sb.indexOf(":");
810
						String date;
811
						if (index != -1)
812
							date = sb.substring(index + 1).trim();
813
						else
814
							date = sb.substring(6).trim();
815
816
						// create a new attribute and set the date
817
						Attribute t = new Attribute("Last Modified");
818
						t.setValue(date);
819
820
						// add the attribute to the bug report
821
						bug.setLastModified(df.parse(date));
822
						bug.addAttribute(t);
823
					}
824
					continue;
825
				}
826
			}
827
			
828
829
			// look for date opened field
830
			if (bug.getCreated() == null && (state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
831
				HtmlTag tag = (HtmlTag) token.getValue();
832
				if (tag.getTagType() == HtmlTag.Type.TD && tag.getAttribute("align") != null && "left".equalsIgnoreCase(tag.getAttribute("align")) && tag.getAttribute("width") != null && "30%".equals(tag.getAttribute("width"))) {
833
					StringBuffer sb = new StringBuffer();
834
					parseDateOpened(sb, tokenizer);					
835
					if(sb.length() > 0) {
836
						int index = sb.indexOf(":");
837
						String date;
838
						if (index != -1)
839
							date = sb.substring(index + 1).trim();
840
						else
841
							date = sb.substring(6).trim();
842
843
						// set the bugs opened date to be the date we parsed
844
						bug.setCreated(df.parse(date));
845
					}
846
					continue;
847
				}
848
			}
849
850
			// we have found the description of the bug
851
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
852
				HtmlTag tag = (HtmlTag) token.getValue();
853
				if (tag.getTagType() == HtmlTag.Type.PRE) {
854
					// parse the description for the bug
855
					parseDescription(bug, tokenizer);
856
857
					state = ParserState.DESC_START;
858
					continue;
859
				}
860
			}
861
862
			// parse hidden fields
863
864
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
865
				HtmlTag tag = (HtmlTag) token.getValue();
866
				if (tag.getTagType() == HtmlTag.Type.INPUT && tag.getAttribute("type") != null
867
						&& "hidden".equalsIgnoreCase(tag.getAttribute("type").trim())) {
868
869
					Attribute a = new Attribute(tag.getAttribute(KEY_NAME));
870
					a.setParameterName(tag.getAttribute(KEY_NAME));
871
					a.setValue(tag.getAttribute(KEY_VALUE));
872
					a.setHidden(true);
873
					bug.addAttribute(a);
874
					continue;
875
				}
876
			}
877
878
			// // parse out attachments
879
			// if(token.getType() == Token.TAG) {
880
			// HtmlTag tag = (HtmlTag) token.getValue();
881
			// if(tag.getTagType() == HtmlTag.Type.A && tag.getAttribute("href")
882
			// != null) {
883
			// String link = tag.getAttribute("href");
884
			// if(link.startsWith("attachment.cgi?id=") &&
885
			// !link.contains("action")) {
886
			// int attachmentID = Integer.parseInt(link.substring(18));
887
			// String description = parseAttachementDescription(tokenizer);
888
			// bug.addAttachment(attachmentID, description);
889
			// }
890
			// }
891
			// }
892
893
		}
894
895
		// if we are to check the body, make sure that there wasn't a bad login
896
		if (checkBody) {
897
			String b = body.toString();
898
			if (b.indexOf("login") != -1
899
					|| ((b.indexOf("invalid") != -1 || b.indexOf("not valid") != -1) && b.indexOf("password") != -1)
900
					|| b.indexOf("check e-mail") != -1)
901
				possibleBadLogin = true; // we possibly have a bad login
902
		}
903
904
		// if there is no summary or created date, we expect that
905
		// the bug doesn't exist, so set it to null
906
907
		// if the bug seems like it doesn't exist, and we suspect a login
908
		// problem, assume that there was a login problem
909
		if (bug.getCreated() == null && bug.getAttributes().isEmpty()) {
910
			if (possibleBadLogin) {
911
				throw new LoginException(IBugzillaConstants.MESSAGE_LOGIN_FAILURE);
912
			} else {
913
				return null;
914
			}
915
		}
916
		// we are done...return the bug
917
		return bug;
918
	}
919
920
	private static void parseDateOpened(StringBuffer sb, HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
921
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
922
			if (token.getType() == Token.TAG) {
923
				HtmlTag tag = (HtmlTag) token.getValue();
924
				if (tag.getTagType() == HtmlTag.Type.TD && tag.isEndTag())
925
					break;
926
			} else if (token.getType() == Token.TEXT) {
927
				if (sb.length() > 0) {
928
					sb.append(' ');
929
				}
930
				sb.append((StringBuffer) token.getValue());
931
			}
932
		}
933
		
934
	}
935
	
936
	private static void parseLastModified(StringBuffer sb, HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
937
		boolean inH3 = false;
938
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
939
			if (token.getType() == Token.TAG) {
940
				HtmlTag tag = (HtmlTag) token.getValue();				
941
				if (tag.getTagType() == HtmlTag.Type.H3 && !tag.isEndTag()) {
942
					inH3 = true;
943
					continue;
944
				} else if (tag.getTagType() == HtmlTag.Type.DIV && tag.isEndTag()) {
945
					break;
946
				}
947
			} else if (token.getType() == Token.TEXT && inH3) {
948
				if (sb.length() > 0) {
949
					sb.append(' ');
950
				}
951
				sb.append((StringBuffer) token.getValue());
952
			}
953
		}
954
		
955
	}
956
957
	public static String getCharsetFromString(String string) {
958
		int charsetStartIndex = string.indexOf(ATTR_CHARSET);
959
		if (charsetStartIndex != -1) {
960
			int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
961
			// could
962
			// be
963
			// space
964
			// after?
965
			if (charsetEndIndex == -1) {
966
				charsetEndIndex = string.length();
967
			}
968
			String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
969
			if (Charset.availableCharsets().containsKey(charsetString)) {
970
				return charsetString;
971
			}
972
		}
973
		return null;
974
	}
975
976
	/**
977
	 * Parse the operations that are allowed on the bug (Assign, Re-open, fix)
978
	 * 
979
	 * @param bug
980
	 *            The bug to add the operations to
981
	 * @param tokenizer
982
	 *            The stream tokenizer for the bug
983
	 * @param tag
984
	 *            The last tag that we were on
985
	 */
986
	private static void parseOperations(BugReport bug, HtmlStreamTokenizer tokenizer, HtmlTag tag, boolean is218)
987
			throws ParseException, IOException {
988
989
		String knobName = tag.getAttribute(KEY_VALUE);
990
		boolean isChecked = false;
991
		if (tag.getAttribute("checked") != null && tag.getAttribute("checked").equals("checked"))
992
			isChecked = true;
993
		StringBuffer sb = new StringBuffer();
994
995
		Token lastTag = null;
996
997
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
998
			if (token.getType() == Token.TAG) {
999
				tag = (HtmlTag) token.getValue();
1000
1001
				if (!(tag.getTagType() == HtmlTag.Type.A || tag.getTagType() == HtmlTag.Type.B
1002
						|| tag.getTagType() == HtmlTag.Type.STRONG || tag.getTagType() == HtmlTag.Type.LABEL)) {
1003
					lastTag = token;
1004
					break;
1005
				} else {
1006
1007
					if (is218 && tag.getTagType() == HtmlTag.Type.LABEL) {
1008
						continue;
1009
					} else if (tag.getTagType() == HtmlTag.Type.A || tag.getTagType() == HtmlTag.Type.B
1010
							|| tag.getTagType() == HtmlTag.Type.STRONG) {
1011
						sb.append(tag.toString().trim() + " ");
1012
					} else {
1013
						break;
1014
					}
1015
				}
1016
			} else if (token.getType() == Token.TEXT && !token.toString().trim().equals("\n"))
1017
				sb.append(token.toString().trim() + " ");
1018
		}
1019
1020
		String displayName = HtmlStreamTokenizer.unescape(sb).toString();
1021
		Operation o = new Operation(knobName, displayName);
1022
		o.setChecked(isChecked);
1023
1024
		if (lastTag != null) {
1025
			tag = (HtmlTag) lastTag.getValue();
1026
			if (tag.getTagType() != HtmlTag.Type.SELECT) {
1027
				tokenizer.pushback(lastTag);
1028
				if (tag.getTagType() == HtmlTag.Type.INPUT
1029
						&& !("radio".equalsIgnoreCase(tag.getAttribute("type")) && "knob".equalsIgnoreCase(tag
1030
								.getAttribute(KEY_NAME)))) {
1031
					o.setInputName(((HtmlTag) lastTag.getValue()).getAttribute(KEY_NAME));
1032
					o.setInputValue(((HtmlTag) lastTag.getValue()).getAttribute(KEY_VALUE));
1033
				}
1034
			} else {
1035
				Token token = tokenizer.nextToken();
1036
				// parse the options
1037
1038
				tag = (HtmlTag) token.getValue();
1039
				o.setUpOptions(((HtmlTag) lastTag.getValue()).getAttribute(KEY_NAME));
1040
1041
				while (token.getType() != Token.EOF) {
1042
					if (token.getType() == Token.TAG) {
1043
						tag = (HtmlTag) token.getValue();
1044
						if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
1045
							break;
1046
						if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
1047
							String optionName = tag.getAttribute(KEY_VALUE);
1048
							StringBuffer optionText = new StringBuffer();
1049
							for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer
1050
									.nextToken()) {
1051
								if (optionText.length() > 0) {
1052
									optionText.append(' ');
1053
								}
1054
								optionText.append((StringBuffer) token.getValue());
1055
							}
1056
							o.addOption(optionText.toString(), optionName);
1057
						} else {
1058
							token = tokenizer.nextToken();
1059
						}
1060
					} else {
1061
						token = tokenizer.nextToken();
1062
					}
1063
				}
1064
			}
1065
		}
1066
1067
		bug.addOperation(o);
1068
	}
1069
1070
	/**
1071
	 * Enum class for describing current state of Bugzilla report parser.
1072
	 */
1073
	private static class ParserState {
1074
		/** An instance of the start state */
1075
		protected static final ParserState START = new ParserState("start");
1076
1077
		/** An instance of the state when the parser found an attribute name */
1078
		protected static final ParserState ATT_NAME = new ParserState("att_name");
1079
1080
		/** An instance of the state when the parser found an attribute value */
1081
		protected static final ParserState ATT_VALUE = new ParserState("att_value");
1082
1083
		/** An instance of the state when the parser found a description */
1084
		protected static final ParserState DESC_START = new ParserState("desc_start");
1085
1086
		/** An instance of the state when the parser found a description value */
1087
		protected static final ParserState DESC_VALUE = new ParserState("desc_value");
1088
1089
		/** State's human-readable name */
1090
		private String name;
1091
1092
		/**
1093
		 * Constructor
1094
		 * 
1095
		 * @param description -
1096
		 *            The states human readable name
1097
		 */
1098
		private ParserState(String description) {
1099
			this.name = description;
1100
		}
1101
1102
		@Override
1103
		public String toString() {
1104
			return name;
1105
		}
1106
	}
1107
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/BugReportElement.java (-85 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
/**
15
 * Bugzilla XML element enum. Each enum has the field name
16
 * and associated xml element tag name.
17
 * 
18
 * @author Rob Elves
19
 */
20
public enum BugReportElement {
21
	
22
	// Format: ENUM ( "pretty name", "xml key" )
23
	
24
	BUGZILLA ("bugzilla", "bugzilla"),
25
	BUG ("bug","bug"),
26
	BUG_ID ("Bug", "bug_id"),
27
	CREATION_TS ("Creation Date", "creation_ts"),
28
	SHORT_DESC ("Summary", "short_desc"),
29
	DELTA_TS ("Last Modification", "delta_ts"),
30
	REPORTER_ACCESSIBLE ("reporter_accessible", "reporter_accessible"),
31
	CCLIST_ACCESSIBLE ("cclist_accessible", "cclist_accessible"),
32
	CLASSIFICATION_ID ("Classification ID", "classification_id"),
33
	CLASSIFICATION ("Classification", "classification"),
34
	PRODUCT ("Product", "product"),
35
	COMPONENT ("Component", "component"),
36
	VERSION ("Version", "version"),
37
	REP_PLATFORM ("Platform", "rep_platform"),
38
	OP_SYS ("OS", "op_sys"),
39
	BUG_STATUS ("Status", "bug_status"),
40
	PRIORITY ("Priority", "priority"),
41
	BUG_SEVERITY ("Severity", "bug_severity"),
42
	TARGET_MILESTONE ("Target Milestone", "target_milestone"), 
43
	EVERCONFIRMED ("everconfirmed", "everconfirmed"), 
44
	REPORTER ("Reporter", "reporter"), 
45
	ASSIGNED_TO ("Assigned To", "assigned_to"), 
46
	CC ("CC", "cc"), 
47
	LONG_DESC ("Description", "long_desc"),
48
	WHO ("who", "who"),
49
	BUG_WHEN ("bug_when", "bug_when"), 
50
	THETEXT ("thetext", "thetext"), 
51
	ATTACHMENT ("attachment", "attachment"), 
52
	ATTACHID ("attachid", "attachid"), 
53
	DATE ("Date", "date"), 
54
	DESC ("desc", "desc"), 
55
	FILENAME ("filename", "filename"), 
56
	TYPE ("type", "type"), 
57
	DATA ("data", "data"),
58
	BUG_FILE_LOC ("URL", "bug_file_loc"),
59
	UNKNOWN ("UNKNOWN", "UNKNOWN");
60
	
61
	private final String prettyName;
62
	private final String keyString;
63
64
	BugReportElement(String prettyName, String fieldName) {		
65
		this.prettyName = prettyName;
66
		keyString = fieldName;
67
	}
68
69
	public String getKeyString() {
70
		return keyString;
71
	}
72
73
	public String toString() {
74
		return prettyName;
75
	}
76
77
//	public BugReportElementTag fromString(String str) {
78
//		for (BugReportElementTag tag : BugReportElementTag.values()) {
79
//			if (tag.toString().equals(str)) {
80
//				return tag;
81
//			}
82
//		}
83
//		return UNKNOWN;
84
//	}
85
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/compare/BugzillaCompareNode.java (-8 / +8 lines)
Lines 22-29 Link Here
22
import org.eclipse.compare.ITypedElement;
22
import org.eclipse.compare.ITypedElement;
23
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
23
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
26
import org.eclipse.mylar.bugzilla.core.BugReport;
26
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
27
import org.eclipse.mylar.bugzilla.core.Comment;
27
import org.eclipse.mylar.bugzilla.core.Comment;
28
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Image;
29
import org.eclipse.ui.ISharedImages;
29
import org.eclipse.ui.ISharedImages;
Lines 190-196 Link Here
190
	 *            The <code>BugReport</code> that needs parsing.
190
	 *            The <code>BugReport</code> that needs parsing.
191
	 * @return The tree of <code>BugzillaCompareNode</code>'s.
191
	 * @return The tree of <code>BugzillaCompareNode</code>'s.
192
	 */
192
	 */
193
	public static BugzillaCompareNode parseBugReport(BugReport bug) {
193
	public static BugzillaCompareNode parseBugReport(BugzillaReport bug) {
194
		Image defaultImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW);
194
		Image defaultImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_DEF_VIEW);
195
		BugzillaCompareNode topNode = new BugzillaCompareNode("Bug #" + bug.getId(), null, defaultImage);
195
		BugzillaCompareNode topNode = new BugzillaCompareNode("Bug #" + bug.getId(), null, defaultImage);
196
		Date creationDate = bug.getCreated();
196
		Date creationDate = bug.getCreated();
Lines 211-218 Link Here
211
211
212
		Image attributeImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
212
		Image attributeImage = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
213
		BugzillaCompareNode attributes = new BugzillaCompareNode("Attributes", null, attributeImage);
213
		BugzillaCompareNode attributes = new BugzillaCompareNode("Attributes", null, attributeImage);
214
		for (Iterator<Attribute> iter = bug.getAttributes().iterator(); iter.hasNext();) {
214
		for (Iterator<AbstractRepositoryReportAttribute> iter = bug.getAttributes().iterator(); iter.hasNext();) {
215
			Attribute attribute = iter.next();
215
			AbstractRepositoryReportAttribute attribute = iter.next();
216
			if (attribute.getName().compareTo("delta_ts") == 0 || attribute.getName().compareTo("Last Modified") == 0
216
			if (attribute.getName().compareTo("delta_ts") == 0 || attribute.getName().compareTo("Last Modified") == 0
217
					|| attribute.getName().compareTo("longdesclength") == 0)
217
					|| attribute.getName().compareTo("longdesclength") == 0)
218
				continue;
218
				continue;
Lines 220-226 Link Here
220
			// attribute's new
220
			// attribute's new
221
			// value, which is what is in the submit viewer.
221
			// value, which is what is in the submit viewer.
222
			
222
			
223
			attributes.addChild(new BugzillaCompareNode(attribute.getName(), attribute.getNewValue(), attributeImage));
223
			attributes.addChild(new BugzillaCompareNode(attribute.getName(), attribute.getValue(), attributeImage));
224
		}
224
		}
225
		topNode.addChild(attributes);
225
		topNode.addChild(attributes);
226
226
Lines 229-240 Link Here
229
		BugzillaCompareNode comments = new BugzillaCompareNode("Comments", null, defaultImage);
229
		BugzillaCompareNode comments = new BugzillaCompareNode("Comments", null, defaultImage);
230
		for (Iterator<Comment> iter = bug.getComments().iterator(); iter.hasNext();) {
230
		for (Iterator<Comment> iter = bug.getComments().iterator(); iter.hasNext();) {
231
			Comment comment = iter.next();
231
			Comment comment = iter.next();
232
			String bodyString = "Comment from " + comment.getAuthorName() + ":\n\n" + comment.getText();
232
			String bodyString = "Comment from " + comment.getAuthorName() + ":\n\n" + comment.getText();			
233
			comments.addChild(new BugzillaCompareNode(comment.getCreated().toString(), bodyString, defaultImage));
233
			comments.addChild(new BugzillaCompareNode(comment.getCreated().toString(), bodyString, defaultImage));
234
		}
234
		}
235
		topNode.addChild(comments);
235
		topNode.addChild(comments);
236
236
237
		topNode.addChild(new BugzillaCompareNode("New Comment", bug.getNewNewComment(), defaultImage));
237
		topNode.addChild(new BugzillaCompareNode("New Comment", bug.getNewComment(), defaultImage));
238
238
239
		BugzillaCompareNode ccList = new BugzillaCompareNode("CC List", null, defaultImage);
239
		BugzillaCompareNode ccList = new BugzillaCompareNode("CC List", null, defaultImage);
240
		for (Iterator<String> iter = bug.getCC().iterator(); iter.hasNext();) {
240
		for (Iterator<String> iter = bug.getCC().iterator(); iter.hasNext();) {
(-)src/org/eclipse/mylar/internal/bugzilla/core/compare/BugzillaCompareInput.java (-4 / +4 lines)
Lines 16-22 Link Here
16
import org.eclipse.compare.structuremergeviewer.Differencer;
16
import org.eclipse.compare.structuremergeviewer.Differencer;
17
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
17
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.mylar.bugzilla.core.BugReport;
19
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
20
20
21
/**
21
/**
22
 * A two-way or three-way compare for <code>BugReport</code> objects.
22
 * A two-way or three-way compare for <code>BugReport</code> objects.
Lines 72-78 Link Here
72
	 * @param newAncestor
72
	 * @param newAncestor
73
	 *            The new original object.
73
	 *            The new original object.
74
	 */
74
	 */
75
	public void setAncestor(BugReport newAncestor) {
75
	public void setAncestor(BugzillaReport newAncestor) {
76
		threeWay = (newAncestor != null);
76
		threeWay = (newAncestor != null);
77
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
77
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
78
		ancestor = structureCreator.getStructure(newAncestor);
78
		ancestor = structureCreator.getStructure(newAncestor);
Lines 93-99 Link Here
93
	 * @param newLeft
93
	 * @param newLeft
94
	 *            The new local object.
94
	 *            The new local object.
95
	 */
95
	 */
96
	public void setLeft(BugReport newLeft) {
96
	public void setLeft(BugzillaReport newLeft) {
97
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
97
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
98
		left = structureCreator.getStructure(newLeft);
98
		left = structureCreator.getStructure(newLeft);
99
	}
99
	}
Lines 113-119 Link Here
113
	 * @param newRight
113
	 * @param newRight
114
	 *            The new online object.
114
	 *            The new online object.
115
	 */
115
	 */
116
	public void setRight(BugReport newRight) {
116
	public void setRight(BugzillaReport newRight) {
117
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
117
		BugzillaStructureCreator structureCreator = new BugzillaStructureCreator();
118
		right = structureCreator.getStructure(newRight);
118
		right = structureCreator.getStructure(newRight);
119
	}
119
	}
(-)src/org/eclipse/mylar/internal/bugzilla/core/compare/BugzillaStructureCreator.java (-3 / +3 lines)
Lines 14-20 Link Here
14
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
14
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
15
import org.eclipse.compare.structuremergeviewer.IStructureCreator;
15
import org.eclipse.compare.structuremergeviewer.IStructureCreator;
16
import org.eclipse.jface.util.Assert;
16
import org.eclipse.jface.util.Assert;
17
import org.eclipse.mylar.bugzilla.core.BugReport;
17
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
18
18
19
/**
19
/**
20
 * This implementation of the <code>IStructureCreator</code> interface makes
20
 * This implementation of the <code>IStructureCreator</code> interface makes
Lines 38-45 Link Here
38
	}
38
	}
39
39
40
	public IStructureComparator getStructure(Object input) {
40
	public IStructureComparator getStructure(Object input) {
41
		if (input instanceof BugReport) {
41
		if (input instanceof BugzillaReport) {
42
			BugReport bugReport = (BugReport) input;
42
			BugzillaReport bugReport = (BugzillaReport) input;
43
			return BugzillaCompareNode.parseBugReport(bugReport);
43
			return BugzillaCompareNode.parseBugReport(bugReport);
44
		} else {
44
		} else {
45
			return null;
45
			return null;
(-)src/org/eclipse/mylar/internal/bugzilla/core/NewBugModel.java (-224 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.core;
12
13
import java.io.Serializable;
14
import java.util.ArrayList;
15
import java.util.Date;
16
import java.util.Iterator;
17
import java.util.LinkedHashMap;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.mylar.bugzilla.core.Attribute;
22
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
23
24
/**
25
 * This class is used to store data about the new bug that is being created
26
 * while the wizard is being used
27
 * 
28
 * @author Eric Booth
29
 */
30
public class NewBugModel implements Serializable, IBugzillaBug {
31
32
	/** Automatically generated serialVersionUID */
33
	private static final long serialVersionUID = 3977859587934335283L;
34
35
	/** Whether the attributes have been parsed yet or not */
36
	protected boolean hasParsedAttributes = false;
37
38
	/** Whether the products have been parsed yet or not */
39
	protected boolean hasParsedProducts = false;
40
41
	/** The bug's id */
42
	protected final int id;
43
44
	/** The product that the bug is for */
45
	protected String product;
46
47
	/** A list of the attributes that can be changed for the new bug */
48
	public Map<String, Attribute> attributes = new LinkedHashMap<String, Attribute>();
49
50
	/** The summary for the bug */
51
	protected String summary = "";
52
53
	/** The description for the bug */
54
	protected String description = "";
55
	
56
	/**
57
	 * Flag to indicate status of connection to Bugzilla server to identify
58
	 * whether ProductConfiguration should be used instead
59
	 */
60
	protected boolean connected = true;
61
62
	/** Whether or not this bug report is saved offline. */
63
	protected boolean savedOffline = false;
64
65
	/**
66
	 * Creates a new <code>NewBugModel</code>. The id chosen for this bug is
67
	 * based on the id of the last <code>NewBugModel</code> that was created.
68
	 */
69
	public NewBugModel() {
70
		super();
71
		id = BugzillaPlugin.getDefault().getOfflineReports().getNextOfflineBugId();
72
	}
73
74
	public Attribute getAttribute(String key) {
75
		return attributes.get(key);
76
	}
77
78
	/**
79
	 * Get the list of attributes for this model
80
	 * 
81
	 * @return An <code>ArrayList</code> of the models attributes
82
	 */
83
	public List<Attribute> getAttributes() {
84
		// create an array list to store the attributes in
85
		ArrayList<Attribute> attributeEntries = new ArrayList<Attribute>(attributes.keySet().size());
86
87
		// go through each of the attribute keys
88
		for (Iterator<String> it = attributes.keySet().iterator(); it.hasNext();) {
89
			// get the key for the attribute
90
			String key = it.next();
91
92
			// get the attribute and add it to the list
93
			Attribute attribute = attributes.get(key);
94
			attributeEntries.add(attribute);
95
		}
96
97
		// return the list of attributes for the bug
98
		return attributeEntries;
99
	}
100
101
	public int getId() {
102
		return id;
103
	}
104
105
	public String getRepositoryUrl() {
106
		return BugzillaTools.OFFLINE_SERVER_DEFAULT;
107
	}
108
109
	public String getLabel() {
110
		return "New Bug #" + id;
111
	}
112
113
	public String getDescription() {
114
		return description;
115
	}
116
117
	public void setDescription(String newDescription) {
118
		description = newDescription;
119
	}
120
121
	public String getSummary() {
122
		return summary;
123
	}
124
125
	public void setSummary(String newSummary) {
126
		summary = newSummary;
127
	}
128
129
	/**
130
	 * @return The product that the bug is for.
131
	 */
132
	public String getProduct() {
133
		return product;
134
	}
135
136
	/**
137
	 * Sets the product that the bug is for.
138
	 * 
139
	 * @param product
140
	 *            The product.
141
	 */
142
	public void setProduct(String product) {
143
		this.product = product;
144
	}
145
146
	/**
147
	 * @return Flag to indicate status of connection to Bugzilla server (to
148
	 *         identify whether ProductConfiguration should be used instead)
149
	 */
150
	public boolean isConnected() {
151
		return connected;
152
	}
153
154
	/**
155
	 * Sets the value of the flag to indicate status of connection to Bugzilla
156
	 * server (to identify whether ProductConfiguration should be used instead)
157
	 * 
158
	 * @param newConnectionStatus
159
	 *            <code>true</code> if the bug is connected.
160
	 */
161
	public void setConnected(boolean newConnectionStatus) {
162
		connected = newConnectionStatus;
163
	}
164
165
	/**
166
	 * @return Returns whether the attributes have been parsed yet or not.
167
	 */
168
	public boolean hasParsedAttributes() {
169
		return hasParsedAttributes;
170
	}
171
172
	/**
173
	 * Sets whether the attributes have been parsed yet or not.
174
	 * 
175
	 * @param hasParsedAttributes
176
	 *            <code>true</code> if the attributes have been parsed.
177
	 */
178
	public void setParsedAttributesStatus(boolean hasParsedAttributes) {
179
		this.hasParsedAttributes = hasParsedAttributes;
180
	}
181
182
	/**
183
	 * @return Returns whether the products have been parsed yet or not.
184
	 */
185
	public boolean hasParsedProducts() {
186
		return hasParsedProducts;
187
	}
188
189
	/**
190
	 * Sets whether the products have been parsed yet or not.
191
	 * 
192
	 * @param hasParsedProducts
193
	 *            <code>true</code> if the products have been parsed.
194
	 */
195
	public void setParsedProductsStatus(boolean hasParsedProducts) {
196
		this.hasParsedProducts = hasParsedProducts;
197
	}
198
199
	public boolean isSavedOffline() {
200
		return savedOffline;
201
	}
202
203
	public boolean isLocallyCreated() {
204
		return true;
205
	}
206
207
	public void setOfflineState(boolean newOfflineState) {
208
		savedOffline = newOfflineState;
209
	}
210
211
	public boolean hasChanges() {
212
		return true;
213
	}
214
215
	/** returns null */
216
	public Date getCreated() {		
217
		return null;
218
	}
219
220
	public Date getLastModified() {
221
		return null;
222
	}
223
224
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/IBugzillaConstants.java (-4 / +26 lines)
Lines 58-66 Link Here
58
	static final String HIT_MARKER_ATTR_OWNER = "owner";
58
	static final String HIT_MARKER_ATTR_OWNER = "owner";
59
59
60
	static final String HIT_MARKER_ATTR_QUERY = "query";
60
	static final String HIT_MARKER_ATTR_QUERY = "query";
61
	
61
62
62
	// Error code
63
	
63
	static final int ERROR_CODE = 1;
64
	// Error response from bugzilla server upon bug request
65
	static final String ERROR_INVALID_BUG_ID = "InvalidBugId";
66
	static final String ERROR_INVALID_USERNAME_OR_PASSWORD = "Invalid Username Or Password";	
67
//	static final int ERROR_CODE = 1;
64
68
65
	// Bugzilla Preferences keys
69
	// Bugzilla Preferences keys
66
	// static final String BUGZILLA_SERVER = "BUGZILLA_SERVER";
70
	// static final String BUGZILLA_SERVER = "BUGZILLA_SERVER";
Lines 146-153 Link Here
146
150
147
	static final String[] DEFAULT_PRESELECTED_STATUS_VALUES = { "New", "Assigned", "Reopened" };
151
	static final String[] DEFAULT_PRESELECTED_STATUS_VALUES = { "New", "Assigned", "Reopened" };
148
152
149
	static final String[] DEFAULT_RESOLUTION_VALUES = { "Fixed", "Invalid", "Wontfix", "Later", "Remind", "Duplicate",
153
	// static final String[] DEFAULT_RESOLUTION_VALUES = { "Fixed", "Invalid",
150
			"Worksforme", "Moved" };
154
	// "Wontfix", "Later", "Remind", "Duplicate",
155
	// "Worksforme", "Moved" };
151
156
152
	static final String[] DEFAULT_SEVERITY_VALUES = { "blocker", "critical", "major", "normal", "minor", "trivial",
157
	static final String[] DEFAULT_SEVERITY_VALUES = { "blocker", "critical", "major", "normal", "minor", "trivial",
153
			"enhancement" };
158
			"enhancement" };
Lines 176-179 Link Here
176
181
177
	public static final String INVALID_2201_ATTRIBUTE_IGNORED = "EclipsebugsBugzilla2.20.1";
182
	public static final String INVALID_2201_ATTRIBUTE_IGNORED = "EclipsebugsBugzilla2.20.1";
178
183
184
	public static final String VALUE_STATUS_RESOLVED = "RESOLVED";
185
	public static final String VALUE_STATUS_NEW = "NEW";
186
	public static final String VALUE_STATUS_CLOSED = "CLOSED";
187
	public static final String VALUE_STATUS_ASSIGNED = "ASSIGNED";
188
	public static final String VALUE_RESOLUTION_LATER = "LATER";
189
190
	public static enum BUGZILLA_OPERATION {
191
		none, accept, resolve, duplicate, reassign, reassignbycomponent, reopen, verify, close;
192
	}
193
	
194
	public static enum BUGZILLA_REPORT_STATUS {
195
		UNCONFIRMED, NEW, ASSIGNED, REOPENED, RESOLVED, VERIFIED, CLOSED;
196
	}
197
	
198
	public static enum BUGZILLA_RESOLUTION {
199
		FIXED, INVALID, WONTFIX, LATER, REMIND, WORKSFORME;		
200
	}
179
}
201
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/BugzillaRepositoryUtil.java (-125 / +557 lines)
Lines 22-30 Link Here
22
import java.net.URL;
22
import java.net.URL;
23
import java.net.URLConnection;
23
import java.net.URLConnection;
24
import java.net.URLEncoder;
24
import java.net.URLEncoder;
25
import java.nio.charset.Charset;
25
import java.util.ArrayList;
26
import java.util.ArrayList;
26
import java.util.HashMap;
27
import java.util.LinkedHashMap;
28
import java.util.List;
27
import java.util.List;
29
28
30
import javax.security.auth.login.LoginException;
29
import javax.security.auth.login.LoginException;
Lines 44-57 Link Here
44
import org.eclipse.core.runtime.Status;
43
import org.eclipse.core.runtime.Status;
45
import org.eclipse.jface.dialogs.MessageDialog;
44
import org.eclipse.jface.dialogs.MessageDialog;
46
import org.eclipse.jface.preference.IPreferenceStore;
45
import org.eclipse.jface.preference.IPreferenceStore;
47
import org.eclipse.mylar.bugzilla.core.Attribute;
46
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
48
import org.eclipse.mylar.bugzilla.core.BugReport;
47
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
48
import org.eclipse.mylar.bugzilla.core.BugzillaReportAttribute;
49
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
49
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
50
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
50
import org.eclipse.mylar.bugzilla.core.Operation;
51
import org.eclipse.mylar.internal.bugzilla.core.internal.BugReportElement;
51
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_OPERATION;
52
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_REPORT_STATUS;
53
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_RESOLUTION;
54
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
52
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
55
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
53
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
56
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
54
import org.eclipse.mylar.internal.bugzilla.core.internal.ServerConfigurationFactory;
57
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfigurationFactory;
58
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryReportFactory;
55
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
59
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
56
import org.eclipse.mylar.internal.core.util.ZipFileUtil;
60
import org.eclipse.mylar.internal.core.util.ZipFileUtil;
57
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
61
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
Lines 62-75 Link Here
62
66
63
/**
67
/**
64
 * @author Mik Kersten (some rewriting)
68
 * @author Mik Kersten (some rewriting)
65
 * @author Rob Elves (attachments)
69
 * @author Rob Elves
66
 */
70
 */
67
public class BugzillaRepositoryUtil {
71
public class BugzillaRepositoryUtil {
68
72
73
	private static final String ATTR_CHARSET = "charset";
74
	
75
	private static final String OPERATION_INPUT_ASSIGNED_TO = "assigned_to";
76
77
	private static final String OPERATION_INPUT_DUP_ID = "dup_id";
78
79
	private static final String OPERATION_OPTION_RESOLUTION = "resolution";
80
81
	private static final String OPERATION_LABEL_CLOSE = "Mark bug as CLOSED";
82
83
	private static final String OPERATION_LABEL_VERIFY = "Mark bug as VERIFIED";
84
85
	private static final String OPERATION_LABEL_REOPEN = "Reopen bug";
86
87
	private static final String OPERATION_LABEL_REASSIGN_DEFAULT = "Reassign bug to default assignee of selected component";
88
89
	private static final String OPERATION_LABEL_REASSIGN = "Reassign bug to";
90
91
	private static final String OPERATION_LABEL_DUPLICATE = "Resolve bug, mark it as duplicate of bug #";
92
93
	private static final String OPERATION_LABEL_RESOLVE = "Resolve bug, changing resolution to";
94
95
	private static final String OPERATION_LABEL_ACCEPT = "Accept bug (change status to ASSIGNED)";
96
69
	private static final String BUG_STATUS_NEW = "NEW";
97
	private static final String BUG_STATUS_NEW = "NEW";
70
98
71
	private static final String ATTACHMENT_DOWNLOAD_FAILED = "Attachment download FAILED.";
99
	private static final String ATTACHMENT_DOWNLOAD_FAILED = "Attachment download FAILED.";
72
	
100
73
	private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual";
101
	private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual";
74
102
75
	private static final String VALUE_ISPATCH = "1";
103
	private static final String VALUE_ISPATCH = "1";
Lines 108-114 Link Here
108
136
109
	private static final String POST_ARGS_LOGIN = "GoAheadAndLogIn=1&Bugzilla_login=";
137
	private static final String POST_ARGS_LOGIN = "GoAheadAndLogIn=1&Bugzilla_login=";
110
138
111
	public static BugReport getBug(String repositoryUrl, int id) throws IOException, MalformedURLException,
139
	// public static BugReport getBug(String repositoryUrl, int id) throws
140
	// IOException, MalformedURLException,
141
	// LoginException {
142
	//
143
	// BufferedReader in = null;
144
	// try {
145
	//
146
	// // create a new input stream for getting the bug
147
	// TaskRepository repository =
148
	// MylarTaskListPlugin.getRepositoryManager().getRepository(
149
	// BugzillaPlugin.REPOSITORY_KIND, repositoryUrl);
150
	// if (repository == null) {
151
	// PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
152
	// public void run() {
153
	// MessageDialog.openInformation(Display.getDefault().getActiveShell(),
154
	// IBugzillaConstants.TITLE_MESSAGE_DIALOG,
155
	// TaskRepositoryManager.MESSAGE_NO_REPOSITORY);
156
	// }
157
	// });
158
	// return null;
159
	// }
160
	//
161
	// String url = repositoryUrl + POST_ARGS_SHOW_BUG + id;
162
	//
163
	// url = addCredentials(repository, url);
164
	//
165
	// URL bugUrl = new URL(url);
166
	// URLConnection connection =
167
	// BugzillaPlugin.getDefault().getUrlConnection(bugUrl);
168
	// if (connection != null) {
169
	// InputStream input = connection.getInputStream();
170
	// if (input != null) {
171
	// in = new BufferedReader(new InputStreamReader(input));
172
	// // BugReport bugReport = new BugReport(id,
173
	// // repository.getUrl());
174
	// // setupExistingBugAttributes2(repository.getUrl(),
175
	// // bugReport);
176
	// RepositoryReportFactory reportFactory =
177
	// RepositoryReportFactory.getInstance();
178
	// AbstractRepositoryReport report = reportFactory.readReport(id,
179
	// repository);
180
	//
181
	// BugReport bugReport = null;
182
	// if (report != null && report instanceof BugReport) {
183
	// bugReport = (BugReport) report;
184
	// setupExistingBugAttributes(repository.getUrl(), bugReport);
185
	// addValidOperations(bugReport);
186
	// return bugReport;
187
	// }
188
	// // get the actual bug from the server and return it
189
	// // BugReport bugReport = BugParser.parseBug(in, id,
190
	// // repository.getUrl(), true, repository.getUserName(),
191
	// // repository
192
	// // .getPassword(), connection.getContentType());
193
	// // return bugReport;
194
	// }
195
	// }
196
	// // TODO handle the error
197
	// return null;
198
	// } catch (MalformedURLException e) {
199
	// throw e;
200
	// } catch (IOException e) {
201
	// throw e;
202
	// } catch (LoginException e) {
203
	// throw e;
204
	// } catch (Exception e) {
205
	// // BugzillaPlugin.log(new Status(IStatus.ERROR,
206
	// // IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
207
	// // "Problem getting report:\n"+e.getMessage(), e));
208
	// MylarStatusHandler.fail(e, "Problem getting report:\n" + e.getMessage(),
209
	// false);
210
	// return null;
211
	// } finally {
212
	// try {
213
	// if (in != null)
214
	// in.close();
215
	// } catch (IOException e) {
216
	// BugzillaPlugin.log(new Status(IStatus.ERROR,
217
	// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
218
	// "Problem closing the stream", e));
219
	// }
220
	// }
221
	// }
222
223
	public static BugzillaReport getBug(String repositoryUrl, int id) throws IOException, MalformedURLException,
112
			LoginException {
224
			LoginException {
113
225
114
		BufferedReader in = null;
226
		BufferedReader in = null;
Lines 129-140 Link Here
129
241
130
			String url = repositoryUrl + POST_ARGS_SHOW_BUG + id;
242
			String url = repositoryUrl + POST_ARGS_SHOW_BUG + id;
131
243
132
			if (repository.hasCredentials()) {
244
			url = addCredentials(repository, url);
133
				url += "&" + POST_ARGS_LOGIN
134
						+ URLEncoder.encode(repository.getUserName(), BugzillaPlugin.ENCODING_UTF_8)
135
						+ POST_ARGS_PASSWORD
136
						+ URLEncoder.encode(repository.getPassword(), BugzillaPlugin.ENCODING_UTF_8);
137
			}
138
245
139
			URL bugUrl = new URL(url);
246
			URL bugUrl = new URL(url);
140
			URLConnection connection = BugzillaPlugin.getDefault().getUrlConnection(bugUrl);
247
			URLConnection connection = BugzillaPlugin.getDefault().getUrlConnection(bugUrl);
Lines 142-156 Link Here
142
				InputStream input = connection.getInputStream();
249
				InputStream input = connection.getInputStream();
143
				if (input != null) {
250
				if (input != null) {
144
					in = new BufferedReader(new InputStreamReader(input));
251
					in = new BufferedReader(new InputStreamReader(input));
252
					BugzillaReport bugReport = new BugzillaReport(id, repository.getUrl());
253
254
					setupExistingBugAttributes(repository.getUrl(), bugReport);
255
256
					RepositoryReportFactory reportFactory = RepositoryReportFactory.getInstance();
257
					reportFactory.populateReport(bugReport, repository);
258
					updateBugAttributeOptions(repository, bugReport);
259
					addValidOperations(bugReport);
145
260
146
					// BugReportFactory reportFactory =
147
					// BugReportFactory.getInstance();
148
					// BugReport bugReport = reportFactory.readReport(in, id,
149
					// repository, connection.getContentType());
150
					// get the actual bug from the server and return it
151
					BugReport bugReport = BugParser.parseBug(in, id, repository.getUrl(), true, repository.getUserName(), repository
152
							.getPassword(), connection.getContentType());
153
					return bugReport;
261
					return bugReport;
262
154
				}
263
				}
155
			}
264
			}
156
			// TODO handle the error
265
			// TODO handle the error
Lines 162-169 Link Here
162
		} catch (LoginException e) {
271
		} catch (LoginException e) {
163
			throw e;
272
			throw e;
164
		} catch (Exception e) {
273
		} catch (Exception e) {
165
			BugzillaPlugin.log(new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
274
			// BugzillaPlugin.log(new Status(IStatus.ERROR,
166
					"Problem getting report", e));
275
			// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
276
			// "Problem getting report:\n"+e.getMessage(), e));
277
			MylarStatusHandler.fail(e, "Problem getting report:\n" + e.getMessage(), false);
167
			return null;
278
			return null;
168
		} finally {
279
		} finally {
169
			try {
280
			try {
Lines 176-181 Link Here
176
		}
287
		}
177
	}
288
	}
178
289
290
	public static String addCredentials(TaskRepository repository, String url) throws UnsupportedEncodingException {
291
		if (repository.hasCredentials()) {
292
			url += "&" + POST_ARGS_LOGIN + URLEncoder.encode(repository.getUserName(), BugzillaPlugin.ENCODING_UTF_8)
293
					+ POST_ARGS_PASSWORD + URLEncoder.encode(repository.getPassword(), BugzillaPlugin.ENCODING_UTF_8);
294
		}
295
		return url;
296
	}
297
179
	/**
298
	/**
180
	 * Get a bug from the server. If a bug with the given id is saved offline,
299
	 * Get a bug from the server. If a bug with the given id is saved offline,
181
	 * the offline version is returned instead.
300
	 * the offline version is returned instead.
Lines 187-193 Link Here
187
	 * @throws IOException,
306
	 * @throws IOException,
188
	 *             MalformedURLException, LoginException
307
	 *             MalformedURLException, LoginException
189
	 */
308
	 */
190
	public static BugReport getCurrentBug(String repositoryUrl, int id) throws MalformedURLException, LoginException,
309
	public static BugzillaReport getCurrentBug(String repositoryUrl, int id) throws MalformedURLException, LoginException,
191
			IOException {
310
			IOException {
192
		// Look among the offline reports for a bug with the given id.
311
		// Look among the offline reports for a bug with the given id.
193
		OfflineReportsFile reportsFile = BugzillaPlugin.getDefault().getOfflineReports();
312
		OfflineReportsFile reportsFile = BugzillaPlugin.getDefault().getOfflineReports();
Lines 196-203 Link Here
196
		// If an offline bug was found, return it if possible.
315
		// If an offline bug was found, return it if possible.
197
		if (offlineId != -1) {
316
		if (offlineId != -1) {
198
			IBugzillaBug bug = reportsFile.elements().get(offlineId);
317
			IBugzillaBug bug = reportsFile.elements().get(offlineId);
199
			if (bug instanceof BugReport) {
318
			if (bug instanceof BugzillaReport) {
200
				return (BugReport) bug;
319
				return (BugzillaReport) bug;
201
			}
320
			}
202
		}
321
		}
203
322
Lines 215-221 Link Here
215
	 */
334
	 */
216
	public static List<String> getProductList(TaskRepository repository) throws IOException, LoginException, Exception {
335
	public static List<String> getProductList(TaskRepository repository) throws IOException, LoginException, Exception {
217
336
218
		return BugzillaPlugin.getDefault().getProductConfiguration(repository.getUrl()).getProducts();
337
		return BugzillaPlugin.getDefault().getProductConfiguration(repository).getProducts();
219
338
220
		// BugzillaQueryPageParser parser = new
339
		// BugzillaQueryPageParser parser = new
221
		// BugzillaQueryPageParser(repository, new NullProgressMonitor());
340
		// BugzillaQueryPageParser(repository, new NullProgressMonitor());
Lines 227-232 Link Here
227
346
228
	}
347
	}
229
348
349
//	public static List<String> getValidKeywords(String repositoryURL) {
350
//		return BugzillaPlugin.getDefault().getProductConfiguration(repositoryURL).getKeywords();
351
//	}
352
230
	// /**
353
	// /**
231
	// * Get the attribute values for a new bug
354
	// * Get the attribute values for a new bug
232
	// *
355
	// *
Lines 302-428 Link Here
302
	// } catch (IOException e) {
425
	// } catch (IOException e) {
303
	// BugzillaPlugin.log(new Status(IStatus.ERROR,
426
	// BugzillaPlugin.log(new Status(IStatus.ERROR,
304
	// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
427
	// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
305
	//						"Problem closing the stream", e));
428
	// "Problem closing the stream", e));
306
	//			}
429
	// }
307
	//		}
430
	// }
308
	//	}
431
	// }
309
432
310
	/**
433
	/**
311
	 * Adds bug attributes to new bug model and sets defaults
434
	 * Adds bug attributes to new bug model and sets defaults
312
	 */
435
	 */
313
	public static void setupBugAttributes(String serverUrl, NewBugModel model) {
436
	public static void setupNewBugAttributes(TaskRepository repository, NewBugzillaReport newReport) {
437
438
		// // order is important
439
		// BugReportElement[] newBugElements = { BugReportElement.PRODUCT,
440
		// BugReportElement.BUG_STATUS,
441
		// BugReportElement.VERSION,
442
		// BugReportElement.COMPONENT,
443
		// BugReportElement.TARGET_MILESTONE,
444
		// BugReportElement.REP_PLATFORM,
445
		// BugReportElement.OP_SYS,
446
		// BugReportElement.PRIORITY,
447
		// BugReportElement.BUG_SEVERITY,
448
		// BugReportElement.ASSIGNED_TO,
449
		// // NOT USED BugReportElement.CC,
450
		// BugReportElement.BUG_FILE_LOC,
451
		// //NOT USED BugReportElement.SHORT_DESC,
452
		// //NOT USED BugReportElement.LONG_DESC
453
		// };
314
454
315
//		// order is important
455
		// HashMap<String, AbstractRepositoryReportAttribute> attributes = new
316
//		BugReportElement[] newBugElements = { BugReportElement.PRODUCT,
456
		// LinkedHashMap<String, AbstractRepositoryReportAttribute>();
317
//				BugReportElement.BUG_STATUS,
457
318
//				BugReportElement.VERSION,				
458
		AbstractRepositoryReportAttribute a = new BugzillaReportAttribute(BugzillaReportElement.PRODUCT);
319
//				BugReportElement.COMPONENT,
459
		List<String> optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getProducts();
320
//				BugReportElement.TARGET_MILESTONE,
321
//				BugReportElement.REP_PLATFORM,				
322
//				BugReportElement.OP_SYS,
323
//				BugReportElement.PRIORITY,
324
//				BugReportElement.BUG_SEVERITY,
325
//				BugReportElement.ASSIGNED_TO,
326
//// NOT USED	BugReportElement.CC,
327
//				BugReportElement.BUG_FILE_LOC,
328
// //NOT USED		BugReportElement.SHORT_DESC,
329
// //NOT USED		BugReportElement.LONG_DESC
330
//		};
331
332
				
333
		
334
		
335
		HashMap<String, Attribute> attributes = new LinkedHashMap<String, Attribute>();
336
337
		Attribute a = new Attribute(BugReportElement.PRODUCT.toString());
338
		a.setParameterName(BugReportElement.PRODUCT.getKeyString());
339
		List<String> optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getProducts();
340
		for (String option : optionValues) {
460
		for (String option : optionValues) {
341
			a.addOptionValue(option, option);
461
			a.addOptionValue(option, option);
342
		}
462
		}
343
		a.setValue(model.getProduct());
463
		a.setValue(newReport.getProduct());
344
		attributes.put(a.getName(), a);
464
		newReport.addAttribute(BugzillaReportElement.PRODUCT, a);
345
		
465
		// attributes.put(a.getName(), a);
346
		
466
347
		a = new Attribute(BugReportElement.BUG_STATUS.toString());
467
		a = new BugzillaReportAttribute(BugzillaReportElement.BUG_STATUS);
348
		a.setParameterName(BugReportElement.BUG_STATUS.getKeyString());
468
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getStatusValues();
349
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getStatusValues();
350
		for (String option : optionValues) {
469
		for (String option : optionValues) {
351
			a.addOptionValue(option, option);
470
			a.addOptionValue(option, option);
352
		}
471
		}
353
		a.setValue(BUG_STATUS_NEW);
472
		a.setValue(BUG_STATUS_NEW);
354
		attributes.put(a.getName(), a);
473
		newReport.addAttribute(BugzillaReportElement.BUG_STATUS, a);
355
		
474
		// attributes.put(a.getName(), a);
356
		a = new Attribute(BugReportElement.VERSION.toString());
475
357
		a.setParameterName(BugReportElement.VERSION.getKeyString());
476
		a = new BugzillaReportAttribute(BugzillaReportElement.VERSION);
358
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getVersions(model.getProduct());
477
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getVersions(
478
				newReport.getProduct());
359
		for (String option : optionValues) {
479
		for (String option : optionValues) {
360
			a.addOptionValue(option, option);
480
			a.addOptionValue(option, option);
361
		}
481
		}
362
		a.setValue(optionValues.get(optionValues.size() - 1));
482
		if (optionValues != null && optionValues.size() > 0) {
363
		attributes.put(a.getName(), a);
483
			a.setValue(optionValues.get(optionValues.size() - 1));
364
		
365
		a = new Attribute(BugReportElement.COMPONENT.toString());
366
		a.setParameterName(BugReportElement.COMPONENT.getKeyString());
367
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getComponents(model.getProduct());
368
		for (String option : optionValues) {
369
			a.addOptionValue(option, option);
370
		}
484
		}
371
		attributes.put(a.getName(), a);
485
		newReport.addAttribute(BugzillaReportElement.VERSION, a);
372
		
486
		// attributes.put(a.getName(), a);
373
		a = new Attribute(BugReportElement.REP_PLATFORM.toString());
487
374
		a.setParameterName(BugReportElement.REP_PLATFORM.getKeyString());
488
		a = new BugzillaReportAttribute(BugzillaReportElement.COMPONENT);
375
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPlatforms();
489
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getComponents(
490
				newReport.getProduct());
376
		for (String option : optionValues) {
491
		for (String option : optionValues) {
377
			a.addOptionValue(option, option);
492
			a.addOptionValue(option, option);
378
		}
493
		}
379
		attributes.put(a.getName(), a);
494
		newReport.addAttribute(BugzillaReportElement.COMPONENT, a);
380
495
381
		a = new Attribute(BugReportElement.OP_SYS.toString());
496
		a = new BugzillaReportAttribute(BugzillaReportElement.REP_PLATFORM);
382
		a.setParameterName(BugReportElement.OP_SYS.getKeyString());
497
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getPlatforms();
383
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getOSs();
384
		for (String option : optionValues) {
498
		for (String option : optionValues) {
385
			a.addOptionValue(option, option);
499
			a.addOptionValue(option, option);
386
		}
500
		}
387
		attributes.put(a.getName(), a);
501
		newReport.addAttribute(BugzillaReportElement.REP_PLATFORM, a);
502
		// attributes.put(a.getName(), a);
388
503
389
		a = new Attribute(BugReportElement.PRIORITY.toString());
504
		a = new BugzillaReportAttribute(BugzillaReportElement.OP_SYS);
390
		a.setParameterName(BugReportElement.PRIORITY.getKeyString());
505
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getOSs();
391
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPriorities();
392
		for (String option : optionValues) {
506
		for (String option : optionValues) {
393
			a.addOptionValue(option, option);
507
			a.addOptionValue(option, option);
394
		}
508
		}
395
		a.setValue(optionValues.get((optionValues.size() / 2)));
509
		newReport.addAttribute(BugzillaReportElement.OP_SYS, a);
396
		attributes.put(a.getName(), a);
510
		// attributes.put(a.getName(), a);
397
511
398
		a = new Attribute(BugReportElement.BUG_SEVERITY.toString());
512
		a = new BugzillaReportAttribute(BugzillaReportElement.PRIORITY);
399
		a.setParameterName(BugReportElement.BUG_SEVERITY.getKeyString());
513
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getPriorities();
400
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getSeverities();
401
		for (String option : optionValues) {
514
		for (String option : optionValues) {
402
			a.addOptionValue(option, option);
515
			a.addOptionValue(option, option);
403
		}
516
		}
404
		a.setValue(optionValues.get((optionValues.size() / 2)));
517
		a.setValue(optionValues.get((optionValues.size() / 2)));
405
		attributes.put(a.getName(), a);
518
		newReport.addAttribute(BugzillaReportElement.PRIORITY, a);
406
		
519
		// attributes.put(a.getName(), a);
407
		a = new Attribute(BugReportElement.TARGET_MILESTONE.toString());
520
408
		a.setParameterName(BugReportElement.TARGET_MILESTONE.getKeyString());
521
		a = new BugzillaReportAttribute(BugzillaReportElement.BUG_SEVERITY);
409
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(model.getProduct());
522
		optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getSeverities();
410
		for (String option : optionValues) {
523
		for (String option : optionValues) {
411
			a.addOptionValue(option, option);
524
			a.addOptionValue(option, option);
412
		}
525
		}
413
		attributes.put(a.getName(), a);
526
		a.setValue(optionValues.get((optionValues.size() / 2)));
527
		newReport.addAttribute(BugzillaReportElement.BUG_SEVERITY, a);
528
		// attributes.put(a.getName(), a);
529
530
		// a = new
531
		// BugzillaReportAttribute(BugzillaReportElement.TARGET_MILESTONE);
532
		// optionValues =
533
		// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(
534
		// newReport.getProduct());
535
		// for (String option : optionValues) {
536
		// a.addOptionValue(option, option);
537
		// }
538
		// if(optionValues.size() > 0) {
539
		// // new bug posts will fail if target_milestone element is included
540
		// // and there are no milestones on the server
541
		// newReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE, a);
542
		// }
414
543
415
		a = new Attribute(BugReportElement.ASSIGNED_TO.toString());
544
		a = new BugzillaReportAttribute(BugzillaReportElement.ASSIGNED_TO);
416
		a.setParameterName(BugReportElement.ASSIGNED_TO.getKeyString());
417
		a.setValue("");
545
		a.setValue("");
418
		attributes.put(a.getName(), a);
546
		newReport.addAttribute(BugzillaReportElement.ASSIGNED_TO, a);
419
		
547
		// attributes.put(a.getName(), a);
420
		a = new Attribute(BugReportElement.BUG_FILE_LOC.toString());
548
421
		a.setParameterName(BugReportElement.BUG_FILE_LOC.getKeyString());
549
		a = new BugzillaReportAttribute(BugzillaReportElement.BUG_FILE_LOC);
422
		a.setValue("http://");
550
		a.setValue("http://");
423
		attributes.put(a.getName(), a);
551
		a.setHidden(false);
424
		
552
		newReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC, a);
425
		model.attributes = attributes;
553
		// attributes.put(a.getName(), a);
554
555
		// newReport.attributes = attributes;
556
	}
557
558
	// /**
559
	// * Adds bug attributes to new bug model and sets defaults
560
	// */
561
	// public static void setupExistingBugAttributes(String serverUrl, BugReport
562
	// existingReport) {
563
	//
564
	// // // order is important
565
	// // BugReportElement[] newBugElements = { BugReportElement.PRODUCT,
566
	// // BugReportElement.BUG_STATUS,
567
	// // BugReportElement.VERSION,
568
	// // BugReportElement.COMPONENT,
569
	// // BugReportElement.TARGET_MILESTONE,
570
	// // BugReportElement.REP_PLATFORM,
571
	// // BugReportElement.OP_SYS,
572
	// // BugReportElement.PRIORITY,
573
	// // BugReportElement.BUG_SEVERITY,
574
	// // BugReportElement.ASSIGNED_TO,
575
	// // // NOT USED BugReportElement.CC,
576
	// // BugReportElement.BUG_FILE_LOC,
577
	// // //NOT USED BugReportElement.SHORT_DESC,
578
	// // //NOT USED BugReportElement.LONG_DESC
579
	// // };
580
	//
581
	// // HashMap<String, AbstractRepositoryReportAttribute> attributes = new
582
	// // LinkedHashMap<String, AbstractRepositoryReportAttribute>();
583
	// List<String> optionValues;
584
	// AbstractRepositoryReportAttribute a =
585
	// existingReport.getAttribute(BugzillaReportElement.PRODUCT);
586
	// if (a != null) {
587
	// optionValues =
588
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getProducts();
589
	// for (String option : optionValues) {
590
	// a.addOptionValue(option, option);
591
	// }
592
	// }
593
	// // existingReport.addAttribute(BugzillaReportElement.PRODUCT, a);
594
	//
595
	// a = existingReport.getAttribute(BugzillaReportElement.BUG_STATUS);
596
	// if (a != null) {
597
	// optionValues =
598
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getStatusValues();
599
	// for (String option : optionValues) {
600
	// a.addOptionValue(option, option);
601
	// }
602
	// }
603
	// // existingReport.addAttribute(BugzillaReportElement.BUG_STATUS, a);
604
	//
605
	// a = existingReport.getAttribute(BugzillaReportElement.VERSION);
606
	// if (a != null) {
607
	// optionValues =
608
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getVersions(
609
	// existingReport.getProduct());
610
	// for (String option : optionValues) {
611
	// a.addOptionValue(option, option);
612
	// }
613
	// }
614
	// // existingReport.addAttribute(BugzillaReportElement.VERSION, a);
615
	//
616
	// a = existingReport.getAttribute(BugzillaReportElement.COMPONENT);
617
	// if (a != null) {
618
	// optionValues =
619
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getComponents(
620
	// existingReport.getProduct());
621
	// for (String option : optionValues) {
622
	// a.addOptionValue(option, option);
623
	// }
624
	// }
625
	// // existingReport.addAttribute(BugzillaReportElement.COMPONENT, a);
626
	//
627
	// a = existingReport.getAttribute(BugzillaReportElement.REP_PLATFORM);
628
	// if (a != null) {
629
	// optionValues =
630
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPlatforms();
631
	// for (String option : optionValues) {
632
	// a.addOptionValue(option, option);
633
	// }
634
	// }
635
	// // existingReport.addAttribute(BugzillaReportElement.REP_PLATFORM, a);
636
	//
637
	// a = existingReport.getAttribute(BugzillaReportElement.OP_SYS);
638
	// if (a != null) {
639
	// optionValues =
640
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getOSs();
641
	// for (String option : optionValues) {
642
	// a.addOptionValue(option, option);
643
	// }
644
	// }
645
	// // existingReport.addAttribute(BugzillaReportElement.OP_SYS, a);
646
	//
647
	// a = existingReport.getAttribute(BugzillaReportElement.PRIORITY);
648
	// if (a != null) {
649
	// optionValues =
650
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getPriorities();
651
	// for (String option : optionValues) {
652
	// a.addOptionValue(option, option);
653
	// }
654
	// }
655
	// // existingReport.addAttribute(BugzillaReportElement.PRIORITY, a);
656
	//
657
	// a = existingReport.getAttribute(BugzillaReportElement.BUG_SEVERITY);
658
	// if (a != null) {
659
	// optionValues =
660
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getSeverities();
661
	// for (String option : optionValues) {
662
	// a.addOptionValue(option, option);
663
	// }
664
	// }
665
	// // existingReport.addAttribute(BugzillaReportElement.BUG_SEVERITY, a);
666
	//
667
	// a = existingReport.getAttribute(BugzillaReportElement.TARGET_MILESTONE);
668
	// if (a != null) {
669
	// optionValues =
670
	// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(
671
	// existingReport.getProduct());
672
	// for (String option : optionValues) {
673
	// a.addOptionValue(option, option);
674
	// }
675
	// }
676
	// // existingReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE,
677
	// // a);
678
	//
679
	// // a = new BugzillaReportAttribute(BugzillaReportElement.ASSIGNED_TO);
680
	// // existingReport.addAttribute(BugzillaReportElement.ASSIGNED_TO, a);
681
	// //
682
	// // a = new BugzillaReportAttribute(BugzillaReportElement.BUG_FILE_LOC);
683
	// // existingReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC, a);
684
	//
685
	// // Add fields that may not be present in xml but required for ui and
686
	// // submission. NOTE: Perhaps the bug reports should be set up with all
687
	// // valid attributes
688
	// // and then passed to the parser to populate the appropriate fields
689
	// // rather than
690
	//
691
	// a = existingReport.getAttribute(BugzillaReportElement.CC);
692
	// if (a == null) {
693
	// existingReport
694
	// .addAttribute(BugzillaReportElement.CC, new
695
	// BugzillaReportAttribute(BugzillaReportElement.CC));
696
	// }
697
	// a = existingReport.getAttribute(BugzillaReportElement.RESOLUTION);
698
	// if (a == null) {
699
	// existingReport.addAttribute(BugzillaReportElement.RESOLUTION, new
700
	// BugzillaReportAttribute(
701
	// BugzillaReportElement.RESOLUTION));
702
	// }
703
	// a = existingReport.getAttribute(BugzillaReportElement.BUG_FILE_LOC);
704
	// if (a == null) {
705
	// existingReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC, new
706
	// BugzillaReportAttribute(
707
	// BugzillaReportElement.BUG_FILE_LOC));
708
	// }
709
	// a = existingReport.getAttribute(BugzillaReportElement.NEWCC);
710
	// if (a == null) {
711
	// existingReport.addAttribute(BugzillaReportElement.NEWCC, new
712
	// BugzillaReportAttribute(
713
	// BugzillaReportElement.NEWCC));
714
	// }
715
	//
716
	// // Special hidden fields required when existing bug is submitted to
717
	// // bugzilla
718
	// a = existingReport.getAttribute(BugzillaReportElement.LONGDESCLENGTH);
719
	// if (a == null) {
720
	// a = new BugzillaReportAttribute(BugzillaReportElement.LONGDESCLENGTH);
721
	// a.setValue("" + existingReport.getComments().size());
722
	// existingReport.addAttribute(BugzillaReportElement.LONGDESCLENGTH, a);
723
	// }
724
	//
725
	// }
726
727
	public static void setupExistingBugAttributes(String serverUrl, BugzillaReport existingReport) {
728
		// ordered list of elements as they appear in UI
729
		// and additional elements that may not appear in the incoming xml
730
		// stream but need to be present for bug submission
731
		BugzillaReportElement[] reportElements = { BugzillaReportElement.BUG_STATUS, BugzillaReportElement.RESOLUTION,
732
				BugzillaReportElement.BUG_ID, BugzillaReportElement.REP_PLATFORM, BugzillaReportElement.PRODUCT,
733
				BugzillaReportElement.OP_SYS, BugzillaReportElement.COMPONENT, BugzillaReportElement.VERSION,
734
				BugzillaReportElement.PRIORITY, BugzillaReportElement.BUG_SEVERITY, BugzillaReportElement.ASSIGNED_TO,
735
				BugzillaReportElement.TARGET_MILESTONE, BugzillaReportElement.REPORTER, BugzillaReportElement.DEPENDSON, BugzillaReportElement.BLOCKED,
736
				BugzillaReportElement.BUG_FILE_LOC, BugzillaReportElement.NEWCC, BugzillaReportElement.KEYWORDS};
737
738
		for (BugzillaReportElement element : reportElements) {
739
			AbstractRepositoryReportAttribute reportAttribute = new BugzillaReportAttribute(element);
740
			existingReport.addAttribute(element, reportAttribute);
741
		}
742
	}
743
744
	private static void updateBugAttributeOptions(TaskRepository repository, BugzillaReport existingReport) {
745
		String product = existingReport.getAttributeValue(BugzillaReportElement.PRODUCT);
746
		for (AbstractRepositoryReportAttribute attribute : existingReport.getAttributes()) {			
747
			BugzillaReportElement element = BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());			
748
			attribute.clearOptions();
749
			List<String> optionValues = BugzillaPlugin.getDefault().getProductConfiguration(repository).getOptionValues(
750
					element, product);
751
			if (element == BugzillaReportElement.TARGET_MILESTONE && optionValues.isEmpty()) {
752
				existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
753
				continue;
754
			}
755
			for (String option : optionValues) {
756
				attribute.addOptionValue(option, option);
757
			}
758
		}
759
760
	}
761
762
	public static void addValidOperations(BugzillaReport bugReport) {
763
		BUGZILLA_REPORT_STATUS status = BUGZILLA_REPORT_STATUS.valueOf(bugReport.getStatus());
764
		switch (status) {
765
		case UNCONFIRMED:
766
		case REOPENED:
767
		case NEW:
768
			addOperation(bugReport, BUGZILLA_OPERATION.none);
769
			addOperation(bugReport, BUGZILLA_OPERATION.accept);
770
			addOperation(bugReport, BUGZILLA_OPERATION.resolve);
771
			addOperation(bugReport, BUGZILLA_OPERATION.duplicate);
772
			addOperation(bugReport, BUGZILLA_OPERATION.reassign);
773
			addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent);
774
			break;
775
		case ASSIGNED:
776
			addOperation(bugReport, BUGZILLA_OPERATION.none);
777
			addOperation(bugReport, BUGZILLA_OPERATION.resolve);
778
			addOperation(bugReport, BUGZILLA_OPERATION.duplicate);
779
			addOperation(bugReport, BUGZILLA_OPERATION.reassign);
780
			addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent);
781
			break;
782
		case RESOLVED:
783
			addOperation(bugReport, BUGZILLA_OPERATION.none);
784
			addOperation(bugReport, BUGZILLA_OPERATION.reopen);
785
			addOperation(bugReport, BUGZILLA_OPERATION.verify);
786
			addOperation(bugReport, BUGZILLA_OPERATION.close);
787
			break;
788
		case CLOSED:
789
			addOperation(bugReport, BUGZILLA_OPERATION.none);
790
			addOperation(bugReport, BUGZILLA_OPERATION.reopen);
791
			break;
792
		case VERIFIED:
793
			addOperation(bugReport, BUGZILLA_OPERATION.none);
794
			addOperation(bugReport, BUGZILLA_OPERATION.reopen);
795
			addOperation(bugReport, BUGZILLA_OPERATION.close);
796
		}
797
	}
798
799
	public static void addOperation(BugzillaReport bugReport, BUGZILLA_OPERATION opcode) {
800
		Operation newOperation = null;
801
		switch (opcode) {
802
		case none:
803
			newOperation = new Operation(opcode.toString(), "Leave as " + bugReport.getStatus() + " "
804
					+ bugReport.getResolution());
805
			newOperation.setChecked(true);
806
			break;
807
		case accept:
808
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_ACCEPT);
809
			break;
810
		case resolve:
811
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_RESOLVE);
812
			newOperation.setUpOptions(OPERATION_OPTION_RESOLUTION);
813
			for (BUGZILLA_RESOLUTION resolution: BUGZILLA_RESOLUTION.values()) {
814
				newOperation.addOption(resolution.toString(), resolution.toString());
815
			}			
816
			break;
817
		case duplicate:
818
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_DUPLICATE);
819
			newOperation.setInputName(OPERATION_INPUT_DUP_ID);
820
			newOperation.setInputValue("");
821
			break;
822
		case reassign:
823
			TaskRepository repository = MylarTaskListPlugin.getRepositoryManager().getRepository(
824
					BugzillaPlugin.REPOSITORY_KIND, bugReport.getRepositoryUrl());
825
			String localUser = repository.getUserName();
826
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_REASSIGN);
827
			newOperation.setInputName(OPERATION_INPUT_ASSIGNED_TO);
828
			newOperation.setInputValue(localUser);
829
			break;
830
		case reassignbycomponent:
831
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_REASSIGN_DEFAULT);
832
			break;
833
		case reopen:
834
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_REOPEN);
835
			break;
836
		case verify:
837
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_VERIFY);
838
			break;
839
		case close:
840
			newOperation = new Operation(opcode.toString(), OPERATION_LABEL_CLOSE);
841
			break;
842
		default:
843
			MylarStatusHandler.log("Unknown bugzilla operation code recieved", BugzillaRepositoryUtil.class);
844
		}
845
		if (newOperation != null) {
846
			bugReport.addOperation(newOperation);
847
		}
426
	}
848
	}
427
849
428
	public static String getBugUrl(String repositoryUrl, int id) {
850
	public static String getBugUrl(String repositoryUrl, int id) {
Lines 430-441 Link Here
430
				BugzillaPlugin.REPOSITORY_KIND, repositoryUrl);
852
				BugzillaPlugin.REPOSITORY_KIND, repositoryUrl);
431
		String url = repository.getUrl() + POST_ARGS_SHOW_BUG + id;
853
		String url = repository.getUrl() + POST_ARGS_SHOW_BUG + id;
432
		try {
854
		try {
433
			if (repository.hasCredentials()) {
855
			url = addCredentials(repository, url);
434
				url += "&" + POST_ARGS_LOGIN
435
						+ URLEncoder.encode(repository.getUserName(), BugzillaPlugin.ENCODING_UTF_8)
436
						+ POST_ARGS_PASSWORD
437
						+ URLEncoder.encode(repository.getPassword(), BugzillaPlugin.ENCODING_UTF_8);
438
			}
439
		} catch (UnsupportedEncodingException e) {
856
		} catch (UnsupportedEncodingException e) {
440
			return "";
857
			return "";
441
		}
858
		}
Lines 503-509 Link Here
503
		// if (!parser.wasSuccessful())
920
		// if (!parser.wasSuccessful())
504
		// return;
921
		// return;
505
922
506
		RepositoryConfiguration config = ServerConfigurationFactory.getInstance().getConfiguration(repositoryUrl);
923
		RepositoryConfiguration config = RepositoryConfigurationFactory.getInstance().getConfiguration(repository);
507
924
508
		// get the preferences store so that we can change the data in it
925
		// get the preferences store so that we can change the data in it
509
		IPreferenceStore prefs = BugzillaPlugin.getDefault().getPreferenceStore();
926
		IPreferenceStore prefs = BugzillaPlugin.getDefault().getPreferenceStore();
Lines 574-585 Link Here
574
		FileOutputStream outStream = null;
991
		FileOutputStream outStream = null;
575
		try {
992
		try {
576
			String url = repository.getUrl() + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
993
			String url = repository.getUrl() + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
577
			if (repository.hasCredentials()) {
994
			url = addCredentials(repository, url);
578
				url += "&" + POST_ARGS_LOGIN
579
						+ URLEncoder.encode(repository.getUserName(), BugzillaPlugin.ENCODING_UTF_8)
580
						+ POST_ARGS_PASSWORD
581
						+ URLEncoder.encode(repository.getPassword(), BugzillaPlugin.ENCODING_UTF_8);
582
			}
583
			URL downloadUrl = new URL(url);
995
			URL downloadUrl = new URL(url);
584
			URLConnection connection = BugzillaPlugin.getDefault().getUrlConnection(downloadUrl);
996
			URLConnection connection = BugzillaPlugin.getDefault().getUrlConnection(downloadUrl);
585
			if (connection != null) {
997
			if (connection != null) {
Lines 744-749 Link Here
744
		return uploadResult;
1156
		return uploadResult;
745
	}
1157
	}
746
1158
1159
	
1160
	public static String getCharsetFromString(String string) {
1161
		int charsetStartIndex = string.indexOf(ATTR_CHARSET);
1162
		if (charsetStartIndex != -1) {
1163
			int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
1164
			// could
1165
			// be
1166
			// space
1167
			// after?
1168
			if (charsetEndIndex == -1) {
1169
				charsetEndIndex = string.length();
1170
			}
1171
			String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
1172
			if (Charset.availableCharsets().containsKey(charsetString)) {
1173
				return charsetString;
1174
			}
1175
		}
1176
		return null;
1177
	}
1178
	
747
}
1179
}
748
1180
749
/**
1181
/**
(-)src/org/eclipse/mylar/internal/bugzilla/core/BugzillaPlugin.java (-125 / +158 lines)
Lines 35-45 Link Here
35
import org.eclipse.jface.dialogs.ErrorDialog;
35
import org.eclipse.jface.dialogs.ErrorDialog;
36
import org.eclipse.jface.dialogs.MessageDialog;
36
import org.eclipse.jface.dialogs.MessageDialog;
37
import org.eclipse.jface.preference.IPreferenceStore;
37
import org.eclipse.jface.preference.IPreferenceStore;
38
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
38
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
39
import org.eclipse.mylar.internal.bugzilla.core.internal.FavoritesFile;
39
import org.eclipse.mylar.internal.bugzilla.core.internal.FavoritesFile;
40
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
40
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
41
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
41
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
42
import org.eclipse.mylar.internal.bugzilla.core.internal.ServerConfigurationFactory;
42
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfigurationFactory;
43
import org.eclipse.mylar.internal.bugzilla.core.search.IBugzillaResultEditorMatchAdapter;
43
import org.eclipse.mylar.internal.bugzilla.core.search.IBugzillaResultEditorMatchAdapter;
44
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
44
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
45
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
45
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
Lines 105-125 Link Here
105
		Authenticator.setDefault(authenticator);
105
		Authenticator.setDefault(authenticator);
106
106
107
		// Removed since not repository specific
107
		// Removed since not repository specific
108
		//setDefaultQueryOptions();
108
		// setDefaultQueryOptions();
109
109
110
		readFavoritesFile();
110
		readFavoritesFile();
111
		readOfflineReportsFile();
111
		readOfflineReportsFile();
112
112
113
//		final Set<TaskRepository> repositories = MylarTaskListPlugin.getRepositoryManager().getRepositories(
113
		// final Set<TaskRepository> repositories =
114
//				REPOSITORY_KIND);
114
		// MylarTaskListPlugin.getRepositoryManager().getRepositories(
115
//		for (TaskRepository repository : repositories) {
115
		// REPOSITORY_KIND);
116
//			readCachedProductConfiguration(repository.getUrl());
116
		// for (TaskRepository repository : repositories) {
117
//		}
117
		// readCachedProductConfiguration(repository.getUrl());
118
		
118
		// }
119
119
		migrateOldAuthenticationData();
120
		migrateOldAuthenticationData();
120
	}
121
	}
121
122
122
	
123
	@SuppressWarnings("unchecked")
123
	@SuppressWarnings("unchecked")
124
	private void migrateOldAuthenticationData() {
124
	private void migrateOldAuthenticationData() {
125
		String OLD_PREF_SERVER = "BUGZILLA_SERVER";
125
		String OLD_PREF_SERVER = "BUGZILLA_SERVER";
Lines 141-154 Link Here
141
					password = pwd;
141
					password = pwd;
142
			}
142
			}
143
			TaskRepository repository;
143
			TaskRepository repository;
144
//			try {
144
			// try {
145
				repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, serverUrl);
145
			repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, serverUrl);
146
				repository.setAuthenticationCredentials(user, password);
146
			repository.setAuthenticationCredentials(user, password);
147
				MylarTaskListPlugin.getRepositoryManager().addRepository(repository);
147
			MylarTaskListPlugin.getRepositoryManager().addRepository(repository);
148
				BugzillaPlugin.getDefault().getPreferenceStore().setValue(OLD_PREF_SERVER, "");  
148
			BugzillaPlugin.getDefault().getPreferenceStore().setValue(OLD_PREF_SERVER, "");
149
//			} catch (MalformedURLException e) {
149
			// } catch (MalformedURLException e) {
150
//				MylarStatusHandler.fail(e, "could not create default repository", true);
150
			// MylarStatusHandler.fail(e, "could not create default repository",
151
//			}
151
			// true);
152
			// }
152
			try {
153
			try {
153
				// reset the authorization
154
				// reset the authorization
154
				Platform.addAuthorizationInfo(BugzillaPreferencePage.FAKE_URL, "Bugzilla",
155
				Platform.addAuthorizationInfo(BugzillaPreferencePage.FAKE_URL, "Bugzilla",
Lines 188-211 Link Here
188
		BugzillaPreferencePage.initDefaults(store);
189
		BugzillaPreferencePage.initDefaults(store);
189
	}
190
	}
190
191
191
//	/**
192
	// /**
192
//	 * // * Get the name of the bugzilla server // * // *
193
	// * // * Get the name of the bugzilla server // * // *
193
//	 * 
194
	// *
194
//	 * @return A string containing the prefered name of the bugzilla server //
195
	// * @return A string containing the prefered name of the bugzilla server //
195
//	 */
196
	// */
196
//	// public String getServerName() {
197
	// // public String getServerName() {
197
//	// return
198
	// // return
198
//	// plugin.getPreferenceStore().getString(IBugzillaConstants.BUGZILLA_SERVER);
199
	// //
199
//	// }
200
	// plugin.getPreferenceStore().getString(IBugzillaConstants.BUGZILLA_SERVER);
200
//	public boolean isServerCompatability218() {
201
	// // }
201
//		return IBugzillaConstants.SERVER_218.equals(getPreferenceStore().getString(IBugzillaConstants.SERVER_VERSION))
202
	// public boolean isServerCompatability218() {
202
//				|| IBugzillaConstants.SERVER_220.equals(getPreferenceStore().getString(
203
	// return
203
//						IBugzillaConstants.SERVER_VERSION));
204
	// IBugzillaConstants.SERVER_218.equals(getPreferenceStore().getString(IBugzillaConstants.SERVER_VERSION))
204
//	}
205
	// || IBugzillaConstants.SERVER_220.equals(getPreferenceStore().getString(
205
//
206
	// IBugzillaConstants.SERVER_VERSION));
206
//	public boolean isServerCompatability220() {
207
	// }
207
//		return IBugzillaConstants.SERVER_220.equals(getPreferenceStore().getString(IBugzillaConstants.SERVER_VERSION));
208
	//
208
//	}
209
	// public boolean isServerCompatability220() {
210
	// return
211
	// IBugzillaConstants.SERVER_220.equals(getPreferenceStore().getString(IBugzillaConstants.SERVER_VERSION));
212
	// }
209
213
210
	/**
214
	/**
211
	 * Get the most recent query key for the preferences
215
	 * Get the most recent query key for the preferences
Lines 216-237 Link Here
216
		return plugin.getPreferenceStore().getString(IBugzillaConstants.MOST_RECENT_QUERY);
220
		return plugin.getPreferenceStore().getString(IBugzillaConstants.MOST_RECENT_QUERY);
217
	}
221
	}
218
222
219
	public RepositoryConfiguration getProductConfiguration(String serverUrl) {
223
	public RepositoryConfiguration getProductConfiguration(TaskRepository repository) {
220
		if(! repositoryConfigurations.containsKey(serverUrl))  {
224
		if (!repositoryConfigurations.containsKey(repository.getUrl())) {
221
			try {
225
			try {
222
				repositoryConfigurations.put(serverUrl, ServerConfigurationFactory.getInstance().getConfiguration(
226
				repositoryConfigurations.put(repository.getUrl(), RepositoryConfigurationFactory.getInstance().getConfiguration(
223
						serverUrl));
227
						repository));
224
			} catch (IOException e) {
228
			} catch (IOException e) {
225
				MessageDialog
229
				MessageDialog.openInformation(null, "Retrieval of Bugzilla Configuration",
226
				.openInformation(
230
						"Bugzilla configuration retrieval failed.");
227
						null,
228
						"Retrieval of Bugzilla Configuration", "Bugzilla configuration retrieval failed.");
229
			}
231
			}
230
		}
232
		}
231
		
233
232
		return repositoryConfigurations.get(serverUrl);
234
		return repositoryConfigurations.get(repository.getUrl());
233
	}
235
	}
234
236
237
	
238
//	public RepositoryConfiguration getProductConfiguration(String serverUrl) {
239
//		if (!repositoryConfigurations.containsKey(serverUrl)) {
240
//			try {
241
//				repositoryConfigurations.put(serverUrl, RepositoryConfigurationFactory.getInstance().getConfiguration(
242
//						serverUrl));
243
//			} catch (IOException e) {
244
//				MessageDialog.openInformation(null, "Retrieval of Bugzilla Configuration",
245
//						"Bugzilla configuration retrieval failed.");
246
//			}
247
//		}
248
//
249
//		return repositoryConfigurations.get(serverUrl);
250
//	}
251
235
	protected void setProductConfiguration(String serverUrl, RepositoryConfiguration repositoryConfiguration) {
252
	protected void setProductConfiguration(String serverUrl, RepositoryConfiguration repositoryConfiguration) {
236
		repositoryConfigurations.put(serverUrl, repositoryConfiguration);
253
		repositoryConfigurations.put(serverUrl, repositoryConfiguration);
237
		// this.productConfiguration = productConfiguration;
254
		// this.productConfiguration = productConfiguration;
Lines 262-275 Link Here
262
		try {
279
		try {
263
			offlineReportsFile = new OfflineReportsFile(offlineReportsPath.toFile());
280
			offlineReportsFile = new OfflineReportsFile(offlineReportsPath.toFile());
264
		} catch (Exception e) {
281
		} catch (Exception e) {
265
			MylarStatusHandler.fail(e, "could not restore offline Bugzilla reports file", true);
282
			MylarStatusHandler.fail(e, "could not restore offline Bugzilla reports file, creating new one", false);
266
//			logAndShowExceptionDetailsDialog(e, "occurred while restoring saved offline Bugzilla reports.",
283
			// logAndShowExceptionDetailsDialog(e, "occurred while restoring
267
//					"Bugzilla Offline Reports Error");
284
			// saved offline Bugzilla reports.",
268
			offlineReportsPath.toFile().delete();
285
			// "Bugzilla Offline Reports Error");
269
			try {
286
			if (offlineReportsPath.toFile().delete()) {
270
				offlineReportsFile = new OfflineReportsFile(offlineReportsPath.toFile());
287
				try {
271
			} catch (IOException e1) {
288
					offlineReportsFile = new OfflineReportsFile(offlineReportsPath.toFile());
272
				MylarStatusHandler.fail(e, "could not reset offline Bugzilla reports file", true);
289
				} catch (Exception e1) {
290
					MylarStatusHandler.fail(e, "could not reset offline Bugzilla reports file", true);
291
				}
292
			} else {
293
				MylarStatusHandler.fail(null, "reset of Bugzilla offline reports file failed", true);
273
			}
294
			}
274
		}
295
		}
275
	}
296
	}
Lines 292-329 Link Here
292
		return configFile;
313
		return configFile;
293
	}
314
	}
294
315
295
//	/**
316
	// /**
296
//	 * Reads cached product configuration and stores it in the
317
	// * Reads cached product configuration and stores it in the
297
//	 * <code>productConfiguration</code> field.
318
	// * <code>productConfiguration</code> field.
298
//	 * 
319
	// *
299
//	 * TODO remove this?
320
	// * TODO remove this?
300
//	 */
321
	// */
301
//	private void readCachedProductConfiguration(String serverUrl) {
322
	// private void readCachedProductConfiguration(String serverUrl) {
302
//		IPath configFile = getProductConfigurationCachePath(serverUrl);
323
	// IPath configFile = getProductConfigurationCachePath(serverUrl);
303
//
324
	//
304
//		try {
325
	// try {
305
//			productConfigurations.put(serverUrl, ServerConfigurationFactory.getInstance().readConfiguration(
326
	// productConfigurations.put(serverUrl,
306
//					configFile.toFile()));
327
	// ServerConfigurationFactory.getInstance().readConfiguration(
307
//		} catch (IOException ex) {
328
	// configFile.toFile()));
308
//			try {
329
	// } catch (IOException ex) {
309
//				log(ex);
330
	// try {
310
//				productConfigurations.put(serverUrl, ServerConfigurationFactory.getInstance().getConfiguration(
331
	// log(ex);
311
//						serverUrl));
332
	// productConfigurations.put(serverUrl,
312
//			} catch (IOException e) {
333
	// ServerConfigurationFactory.getInstance().getConfiguration(
313
//				log(e);
334
	// serverUrl));
314
//				MessageDialog
335
	// } catch (IOException e) {
315
//						.openInformation(
336
	// log(e);
316
//								null,
337
	// MessageDialog
317
//								"Bugzilla product attributes check",
338
	// .openInformation(
318
//								"An error occurred while restoring saved Bugzilla product attributes: \n\n"
339
	// null,
319
//										+ ex.getMessage()
340
	// "Bugzilla product attributes check",
320
//										+ "\n\nUpdating them from the server also caused an error:\n\n"
341
	// "An error occurred while restoring saved Bugzilla product attributes:
321
//										+ e.getMessage()
342
	// \n\n"
322
//										+ "\n\nCheck the server URL in Bugzila preferences.\n"
343
	// + ex.getMessage()
323
//										+ "Offline submission of new bugs will be disabled until valid product attributes have been loaded.");
344
	// + "\n\nUpdating them from the server also caused an error:\n\n"
324
//			}
345
	// + e.getMessage()
325
//		}
346
	// + "\n\nCheck the server URL in Bugzila preferences.\n"
326
//	}
347
	// + "Offline submission of new bugs will be disabled until valid product
348
	// attributes have been loaded.");
349
	// }
350
	// }
351
	// }
327
352
328
	/**
353
	/**
329
	 * Returns the path to the file cacheing the product configuration.
354
	 * Returns the path to the file cacheing the product configuration.
Lines 391-397 Link Here
391
	/**
416
	/**
392
	 * @return a list of the BugReports saved offline.
417
	 * @return a list of the BugReports saved offline.
393
	 */
418
	 */
394
	public List<IBugzillaBug> getSavedBugReports() {
419
	public List<BugzillaReport> getSavedBugReports() {
395
		return offlineReportsFile.elements();
420
		return offlineReportsFile.elements();
396
	}
421
	}
397
422
Lines 432-473 Link Here
432
		return getPreferenceStore().getInt(IBugzillaConstants.MAX_RESULTS);
457
		return getPreferenceStore().getInt(IBugzillaConstants.MAX_RESULTS);
433
	}
458
	}
434
459
435
//	private void setDefaultQueryOptions() {
460
	// private void setDefaultQueryOptions() {
436
//		// get the preferences store for the bugzilla preferences
461
	// // get the preferences store for the bugzilla preferences
437
//		IPreferenceStore prefs = getPreferenceStore();
462
	// IPreferenceStore prefs = getPreferenceStore();
438
//
463
	//
439
//		prefs.setDefault(IBugzillaConstants.VALUES_STATUS, BugzillaRepositoryUtil
464
	// prefs.setDefault(IBugzillaConstants.VALUES_STATUS, BugzillaRepositoryUtil
440
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_STATUS_VALUES));
465
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_STATUS_VALUES));
441
//
466
	//
442
//		prefs.setDefault(IBugzillaConstants.VALUSE_STATUS_PRESELECTED, BugzillaRepositoryUtil
467
	// prefs.setDefault(IBugzillaConstants.VALUSE_STATUS_PRESELECTED,
443
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_PRESELECTED_STATUS_VALUES));
468
	// BugzillaRepositoryUtil
444
//
469
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_PRESELECTED_STATUS_VALUES));
445
//		prefs.setDefault(IBugzillaConstants.VALUES_RESOLUTION, BugzillaRepositoryUtil
470
	//
446
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_RESOLUTION_VALUES));
471
	// prefs.setDefault(IBugzillaConstants.VALUES_RESOLUTION,
447
//
472
	// BugzillaRepositoryUtil
448
//		prefs.setDefault(IBugzillaConstants.VALUES_SEVERITY, BugzillaRepositoryUtil
473
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_RESOLUTION_VALUES));
449
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_SEVERITY_VALUES));
474
	//
450
//
475
	// prefs.setDefault(IBugzillaConstants.VALUES_SEVERITY,
451
//		prefs.setDefault(IBugzillaConstants.VALUES_PRIORITY, BugzillaRepositoryUtil
476
	// BugzillaRepositoryUtil
452
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_PRIORITY_VALUES));
477
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_SEVERITY_VALUES));
453
//
478
	//
454
//		prefs.setDefault(IBugzillaConstants.VALUES_HARDWARE, BugzillaRepositoryUtil
479
	// prefs.setDefault(IBugzillaConstants.VALUES_PRIORITY,
455
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_HARDWARE_VALUES));
480
	// BugzillaRepositoryUtil
456
//
481
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_PRIORITY_VALUES));
457
//		prefs.setDefault(IBugzillaConstants.VALUES_OS, BugzillaRepositoryUtil
482
	//
458
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_OS_VALUES));
483
	// prefs.setDefault(IBugzillaConstants.VALUES_HARDWARE,
459
//
484
	// BugzillaRepositoryUtil
460
//		prefs.setDefault(IBugzillaConstants.VALUES_PRODUCT, BugzillaRepositoryUtil
485
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_HARDWARE_VALUES));
461
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_PRODUCT_VALUES));
486
	//
462
//
487
	// prefs.setDefault(IBugzillaConstants.VALUES_OS, BugzillaRepositoryUtil
463
//		prefs.setDefault(IBugzillaConstants.VALUES_COMPONENT, BugzillaRepositoryUtil
488
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_OS_VALUES));
464
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_COMPONENT_VALUES));
489
	//
465
//
490
	// prefs.setDefault(IBugzillaConstants.VALUES_PRODUCT,
466
//		prefs.setDefault(IBugzillaConstants.VALUES_VERSION, BugzillaRepositoryUtil
491
	// BugzillaRepositoryUtil
467
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_VERSION_VALUES));
492
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_PRODUCT_VALUES));
468
//
493
	//
469
//		prefs.setDefault(IBugzillaConstants.VALUES_TARGET, BugzillaRepositoryUtil
494
	// prefs.setDefault(IBugzillaConstants.VALUES_COMPONENT,
470
//				.queryOptionsToString(IBugzillaConstants.DEFAULT_TARGET_VALUES));
495
	// BugzillaRepositoryUtil
471
//	}
496
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_COMPONENT_VALUES));
472
	
497
	//
498
	// prefs.setDefault(IBugzillaConstants.VALUES_VERSION,
499
	// BugzillaRepositoryUtil
500
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_VERSION_VALUES));
501
	//
502
	// prefs.setDefault(IBugzillaConstants.VALUES_TARGET, BugzillaRepositoryUtil
503
	// .queryOptionsToString(IBugzillaConstants.DEFAULT_TARGET_VALUES));
504
	// }
505
473
}
506
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/BugzillaReportSubmitForm.java (-42 / +54 lines)
Lines 32-46 Link Here
32
32
33
import org.eclipse.core.runtime.IStatus;
33
import org.eclipse.core.runtime.IStatus;
34
import org.eclipse.core.runtime.Status;
34
import org.eclipse.core.runtime.Status;
35
import org.eclipse.mylar.bugzilla.core.Attribute;
35
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
36
import org.eclipse.mylar.bugzilla.core.BugReport;
36
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
37
import org.eclipse.mylar.bugzilla.core.BugzillaReportAttribute;
37
import org.eclipse.mylar.bugzilla.core.Operation;
38
import org.eclipse.mylar.bugzilla.core.Operation;
38
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BugzillaServerVersion;
39
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BugzillaServerVersion;
39
import org.eclipse.mylar.internal.bugzilla.core.internal.BugReportElement;
40
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
40
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer;
41
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer;
41
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlTag;
42
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlTag;
42
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
43
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
43
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
44
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
44
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
45
45
46
/**
46
/**
Lines 57-62 Link Here
57
57
58
	// private static final String KEY_PRODUCT = "product";
58
	// private static final String KEY_PRODUCT = "product";
59
59
60
	private static final String KEY_ID = "id";
61
60
	private static final String VAL_TRUE = "true";
62
	private static final String VAL_TRUE = "true";
61
63
62
	private static final String KEY_REMOVECC = "removecc";
64
	private static final String KEY_REMOVECC = "removecc";
Lines 71-78 Link Here
71
73
72
	private static final String METHOD_POST = "POST";
74
	private static final String METHOD_POST = "POST";
73
75
74
	private static final String KEY_NEWCC = "newcc";
75
76
	private static final String KEY_BUGZILLA_PASSWORD = "Bugzilla_password";
76
	private static final String KEY_BUGZILLA_PASSWORD = "Bugzilla_password";
77
77
78
	private static final String KEY_BUGZILLA_LOGIN = "Bugzilla_login";
78
	private static final String KEY_BUGZILLA_LOGIN = "Bugzilla_login";
Lines 95-102 Link Here
95
95
96
	private static final String KEY_SHORT_DESC = "short_desc";
96
	private static final String KEY_SHORT_DESC = "short_desc";
97
97
98
	private static final String KEY_ASSIGNED_TO = "Assigned To";
99
100
	// private static final String KEY_ASSIGN_TO = "Assign To";
98
	// private static final String KEY_ASSIGN_TO = "Assign To";
101
	//
99
	//
102
	// private static final String KEY_URL = "URL";
100
	// private static final String KEY_URL = "URL";
Lines 209-215 Link Here
209
	// return bugzillaReportSubmitForm;
207
	// return bugzillaReportSubmitForm;
210
	// }
208
	// }
211
209
212
	public static BugzillaReportSubmitForm makeNewBugPost(TaskRepository repository, NewBugModel model) {
210
	public static BugzillaReportSubmitForm makeNewBugPost(TaskRepository repository, NewBugzillaReport model) {
213
		BugzillaReportSubmitForm form = new BugzillaReportSubmitForm();
211
		BugzillaReportSubmitForm form = new BugzillaReportSubmitForm();
214
		form.setPrefix(BugzillaReportSubmitForm.FORM_PREFIX_BUG_218);
212
		form.setPrefix(BugzillaReportSubmitForm.FORM_PREFIX_BUG_218);
215
		form.setPrefix2(BugzillaReportSubmitForm.FORM_PREFIX_BUG_220);
213
		form.setPrefix2(BugzillaReportSubmitForm.FORM_PREFIX_BUG_220);
Lines 220-229 Link Here
220
		setURL(form, repository, POST_BUG_CGI);
218
		setURL(form, repository, POST_BUG_CGI);
221
		// go through all of the attributes and add them to
219
		// go through all of the attributes and add them to
222
		// the bug post
220
		// the bug post
223
		Iterator<Attribute> itr = model.getAttributes().iterator();
221
		Iterator<AbstractRepositoryReportAttribute> itr = model.getAttributes().iterator();
224
		while (itr.hasNext()) {
222
		while (itr.hasNext()) {
225
			Attribute a = itr.next();
223
			AbstractRepositoryReportAttribute a = itr.next();
226
			if (a != null && a.getParameterName() != null && a.getParameterName().compareTo("") != 0 && !a.isHidden()) {
224
			if (a != null && a.getID() != null && a.getID().compareTo("") != 0) { // &&
225
																					// !a.isHidden()
227
				// String key = a.getName();
226
				// String key = a.getName();
228
				String value = null;
227
				String value = null;
229
228
Lines 259-278 Link Here
259
				// && a.isHidden()) {
258
				// && a.isHidden()) {
260
				// // we have a hidden attribute, add it to the
259
				// // we have a hidden attribute, add it to the
261
				// // posting
260
				// // posting
262
				value = a.getValue();				
261
				value = a.getValue();
263
				if (value == null)
262
				if (value == null)
264
					continue;
263
					continue;
265
				form.add(a.getParameterName(), value);
264
				form.add(a.getID(), value);
266
			}
265
			}
267
		}
266
		}
268
267
269
		// form.add(KEY_BUG_FILE_LOC, "");
268
		// form.add(KEY_BUG_FILE_LOC, "");
270
269
271
		// specify the product
270
		// specify the product
272
		form.add(BugReportElement.PRODUCT.getKeyString(), model.getProduct());
271
		form.add(BugzillaReportElement.PRODUCT.getKeyString(), model.getProduct());
273
272
274
		// add the summary to the bug post
273
		// add the summary to the bug post
275
		form.add(BugReportElement.SHORT_DESC.getKeyString(), model.getSummary());
274
		form.add(BugzillaReportElement.SHORT_DESC.getKeyString(), model.getSummary());
276
275
277
		// BugzillaServerVersion bugzillaServerVersion =
276
		// BugzillaServerVersion bugzillaServerVersion =
278
		// IBugzillaConstants.BugzillaServerVersion.fromString(repository
277
		// IBugzillaConstants.BugzillaServerVersion.fromString(repository
Lines 304-310 Link Here
304
	 * 
303
	 * 
305
	 * @param removeCC
304
	 * @param removeCC
306
	 */
305
	 */
307
	public static BugzillaReportSubmitForm makeExistingBugPost(BugReport bug, TaskRepository repository,
306
	public static BugzillaReportSubmitForm makeExistingBugPost(BugzillaReport bug, TaskRepository repository,
308
			Set<String> removeCC) {
307
			Set<String> removeCC) {
309
308
310
		BugzillaReportSubmitForm bugReportPostHandler = new BugzillaReportSubmitForm();
309
		BugzillaReportSubmitForm bugReportPostHandler = new BugzillaReportSubmitForm();
Lines 317-335 Link Here
317
		}
316
		}
318
317
319
		// go through all of the attributes and add them to the bug post
318
		// go through all of the attributes and add them to the bug post
320
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
319
		for (Iterator<AbstractRepositoryReportAttribute> it = bug.getAttributes().iterator(); it.hasNext();) {
321
			Attribute a = it.next();
320
			AbstractRepositoryReportAttribute a = it.next();
322
			if (a != null && a.getParameterName() != null && a.getParameterName().compareTo("") != 0 && !a.isHidden()) {
321
323
				String value = a.getNewValue();
322
			if (a != null && a.getID() != null && a.getID().compareTo("") != 0 && !a.isHidden()) {
323
				String value = a.getValue();
324
				// add the attribute to the bug post
324
				// add the attribute to the bug post
325
				bugReportPostHandler.add(a.getParameterName(), value != null ? value : "");
325
				bugReportPostHandler.add(a.getID(), value != null ? value : "");
326
			} else if (a != null && a.getParameterName() != null && a.getParameterName().compareTo("") != 0
326
			} else if (a != null && a.getID() != null && a.getID().compareTo("") != 0 && a.isHidden()) {
327
					&& a.isHidden()) {
328
				// we have a hidden attribute and we should send it back.
327
				// we have a hidden attribute and we should send it back.
329
				bugReportPostHandler.add(a.getParameterName(), a.getValue());
328
				bugReportPostHandler.add(a.getID(), a.getValue());
330
			}
329
			}
331
		}
330
		}
332
331
332
		// when posting the bug id is encoded in a hidden field named 'id'
333
		bugReportPostHandler.add(KEY_ID, bug.getAttributeValue(BugzillaReportElement.BUG_ID));
334
333
		// add the operation to the bug post
335
		// add the operation to the bug post
334
		Operation o = bug.getSelectedOperation();
336
		Operation o = bug.getSelectedOperation();
335
		if (o == null)
337
		if (o == null)
Lines 345-358 Link Here
345
			}
347
			}
346
		}
348
		}
347
		bugReportPostHandler.add(KEY_FORM_NAME, VAL_PROCESS_BUG);
349
		bugReportPostHandler.add(KEY_FORM_NAME, VAL_PROCESS_BUG);
348
		bug.setNewNewComment(formatTextToLineWrap(bug.getNewNewComment(), repository));
350
		// bug.setNewNewComment(formatTextToLineWrap(bug.getNewComment(),
349
		if (bug.getAttribute(BugReport.ATTR_SUMMARY) != null) {
351
		// repository));
350
			bugReportPostHandler.add(KEY_SHORT_DESC, bug.getAttribute(BugReport.ATTR_SUMMARY).getNewValue());
352
		if (bug.getAttribute(BugzillaReportElement.SHORT_DESC) != null) {
353
			bugReportPostHandler.add(KEY_SHORT_DESC, bug.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
351
		}
354
		}
352
355
353
		// add the new comment to the bug post if there is some text in it
356
		// add the new comment to the bug post if there is some text in it
354
		if (bug.getNewNewComment().length() != 0) {
357
		if (bug.getNewComment().length() != 0) {
355
			bugReportPostHandler.add(KEY_COMMENT, bug.getNewNewComment());
358
			bugReportPostHandler.add(KEY_COMMENT, bug.getNewComment());
356
		}
359
		}
357
360
358
		if (removeCC != null && removeCC.size() > 0) {
361
		if (removeCC != null && removeCC.size() > 0) {
Lines 431-436 Link Here
431
			}
434
			}
432
			postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, contentTypeString);
435
			postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, contentTypeString);
433
			// get the url for the update with all of the changed values
436
			// get the url for the update with all of the changed values
437
438
			// Used to debug posted report
439
			// System.err.println(getPostBody());
440
434
			byte[] body = getPostBody().getBytes();
441
			byte[] body = getPostBody().getBytes();
435
			postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_LENGTH, String.valueOf(body.length));
442
			postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_LENGTH, String.valueOf(body.length));
436
443
Lines 455-461 Link Here
455
462
456
			String aString = in.readLine();
463
			String aString = in.readLine();
457
464
458
			// while(aString != null) {
465
			// Used to debug reponse from bugzilla server
466
			// while (aString != null) {
459
			// System.err.println(aString);
467
			// System.err.println(aString);
460
			// aString = in.readLine();
468
			// aString = in.readLine();
461
			// }
469
			// }
Lines 631-657 Link Here
631
639
632
	/**
640
	/**
633
	 * Sets the cc field to the user's address if a cc has not been specified to
641
	 * Sets the cc field to the user's address if a cc has not been specified to
634
	 * ensure that commenters are on the cc list.
642
	 * ensure that commenters are on the cc list. TODO: Review this mechanism
635
	 * 
643
	 * 
636
	 * @author Wesley Coelho
644
	 * @author Wesley Coelho
637
	 */
645
	 */
638
	private static void setDefaultCCValue(BugReport bug, TaskRepository repository) {
646
	private static void setDefaultCCValue(BugzillaReport bug, TaskRepository repository) {
639
		Attribute newCCattr = bug.getAttributeForKnobName(KEY_NEWCC);
647
		// AbstractRepositoryReportAttribute newCCattr =
640
		Attribute owner = bug.getAttribute(KEY_ASSIGNED_TO);
648
		// bug.getAttributeForKnobName(KEY_NEWCC);
649
		AbstractRepositoryReportAttribute owner = bug.getAttribute(BugzillaReportElement.ASSIGNED_TO);
641
650
642
		// Don't add the cc if the user is the bug owner
651
		// Don't add the cc if the user is the bug owner
643
		if (repository.getUserName() == null
652
		if (repository.getUserName() == null
644
				|| (owner != null && owner.getValue().indexOf(repository.getUserName()) != -1)) {
653
				|| (owner != null && owner.getValue().indexOf(repository.getUserName()) != -1)) {
645
			MylarStatusHandler.log("Could not determine CC value for repository: " + repository, null);
654
			// MylarStatusHandler.log("Could not determine CC value for
655
			// repository: " + repository, null);
646
			return;
656
			return;
647
		}
657
		}
648
658
		// Don't add cc if already there
649
		// Add the user to the cc list
659
		AbstractRepositoryReportAttribute ccAttribute = bug.getAttribute(BugzillaReportElement.CC);
650
		if (newCCattr != null) {
660
		if (ccAttribute != null && ccAttribute.getValues().contains(repository.getUserName())) {
651
			if (newCCattr.getNewValue().equals("")) {
661
			return;
652
				newCCattr.setNewValue(repository.getUserName());
653
			}
654
		}
662
		}
663
		BugzillaReportAttribute newCCattr = new BugzillaReportAttribute(BugzillaReportElement.NEWCC);
664
		// Add the user to the cc list
665
		newCCattr.setValue(repository.getUserName());
666
		bug.addAttribute(BugzillaReportElement.NEWCC, newCCattr);
655
	}
667
	}
656
668
657
	/**
669
	/**
(-)src/org/eclipse/mylar/internal/bugzilla/core/BugzillaTools.java (-3 / +3 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.core;
11
package org.eclipse.mylar.internal.bugzilla.core;
12
12
13
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
13
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
14
14
15
/**
15
/**
16
 * Miscellaneous constants and functions for this plugin.
16
 * Miscellaneous constants and functions for this plugin.
Lines 53-59 Link Here
53
		return name;
53
		return name;
54
	}
54
	}
55
55
56
	public static String getHandle(IBugzillaBug bug) {
56
	public static String getHandle(BugzillaReport bug) {
57
		return getHandle(bug.getRepositoryUrl(), bug.getId());
57
		return getHandle(bug.getRepositoryUrl(), bug.getId());
58
	}
58
	}
59
59
Lines 61-67 Link Here
61
		return server + ";" + id;
61
		return server + ";" + id;
62
	}
62
	}
63
63
64
	public static String getName(IBugzillaBug bug) {
64
	public static String getName(BugzillaReport bug) {
65
		return bug.getRepositoryUrl() + ": Bug#: " + bug.getId() + ": " + bug.getSummary();
65
		return bug.getRepositoryUrl() + ": Bug#: " + bug.getId() + ": " + bug.getSummary();
66
	}
66
	}
67
67
(-)src/org/eclipse/mylar/internal/bugzilla/core/search/BugzillaSearchResultCollector.java (-4 / +5 lines)
Lines 19-26 Link Here
19
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
23
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
23
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
24
import org.eclipse.search.ui.NewSearchUI;
25
import org.eclipse.search.ui.NewSearchUI;
25
import org.eclipse.search.ui.text.Match;
26
import org.eclipse.search.ui.text.Match;
26
27
Lines 120-134 Link Here
120
	 * Returns a map where BugReport's attributes are entered into a Map using
121
	 * Returns a map where BugReport's attributes are entered into a Map using
121
	 * the same key/value pairs as those created on a search hit marker.
122
	 * the same key/value pairs as those created on a search hit marker.
122
	 */
123
	 */
123
	public static Map<String, Object> getAttributeMap(BugReport bug) {
124
	public static Map<String, Object> getAttributeMap(BugzillaReport bug) {
124
		HashMap<String, Object> map = new HashMap<String, Object>();
125
		HashMap<String, Object> map = new HashMap<String, Object>();
125
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_ID, new Integer(bug.getId()));
126
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_ID, new Integer(bug.getId()));
126
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_REPOSITORY, bug.getRepositoryUrl());
127
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_REPOSITORY, bug.getRepositoryUrl());
127
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_DESC, bug.getDescription());
128
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_DESC, bug.getDescription());
128
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY,
129
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY,
129
				mapValue(bug.getAttribute("Severity").getValue(), severity));
130
				mapValue(bug.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue(), severity));
130
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY,
131
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY,
131
				mapValue(bug.getAttribute("Priority").getValue(), priority));
132
				mapValue(bug.getAttribute(BugzillaReportElement.PRIORITY).getValue(), priority));
132
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_PLATFORM, bug.getAttribute("Hardware").getValue());
133
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_PLATFORM, bug.getAttribute("Hardware").getValue());
133
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_STATE, mapValue(bug.getStatus(), state));
134
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_STATE, mapValue(bug.getStatus(), state));
134
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_RESULT, mapValue(bug.getResolution(), result));
135
		map.put(IBugzillaConstants.HIT_MARKER_ATTR_RESULT, mapValue(bug.getResolution(), result));
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/BugzillaReportElement.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
/**
15
 * Bugzilla XML element enum. Each enum has the attribute name
16
 * and associated xml element tag name.
17
 * 
18
 * @author Rob Elves
19
 */
20
public enum BugzillaReportElement {
21
	// Format: ENUM ( "pretty name", "xml key", <hidden: true/false>, <multivalued: true/false>)
22
	// Hidden elements are not automatically displayed in ui	
23
	ASSIGNED_TO ("Assigned to:", "assigned_to"),
24
	ATTACHID ("attachid", "attachid"),
25
	ATTACHMENT ("attachment", "attachment"),
26
	BLOCKED ("Bug blocks:", "blocked"),
27
	BUG ("bug","bug", true),
28
	BUG_FILE_LOC ("URL:", "bug_file_loc", true),
29
	BUG_ID ("Bug:", "bug_id", true),
30
	BUG_SEVERITY ("Severity:", "bug_severity", false),
31
	BUG_STATUS ("Status:", "bug_status", false, true),
32
	BUG_WHEN ("bug_when", "bug_when", true, true),
33
	BUGZILLA ("bugzilla", "bugzilla", true),
34
	CC ("CC:", "cc", true, true),
35
	CCLIST_ACCESSIBLE ("cclist_accessible", "cclist_accessible", true),
36
	CLASSIFICATION ("Classification:", "classification", true),
37
	CLASSIFICATION_ID ("Classification ID:", "classification_id", true),
38
	COMPONENT ("Component:", "component", false),
39
	CREATION_TS ("Creation date:", "creation_ts", true),
40
	CTYPE ("Content Type", "ctype"),
41
	DATA ("data", "data"), 
42
	DATE ("Date", "date"), 
43
	DELTA_TS ("Last Modification", "delta_ts", true), 
44
	DEPENDSON ("Bug depends on:", "dependson"), 
45
	DESC ("desc", "desc"), 
46
	EVERCONFIRMED ("everconfirmed", "everconfirmed", true),
47
	FILENAME ("filename", "filename"),
48
	IS_OBSOLETE ("Obsolete", "isobsolete", true), 
49
	KEYWORDS ("Keywords:", "keywords", true), 
50
	LONG_DESC ("Description:", "long_desc"), 
51
	LONGDESCLENGTH ("Number of comments", "longdesclength", true), 
52
	NEWCC ("Add CC:", "newcc", true), 
53
	OP_SYS ("OS:", "op_sys", false), 
54
	PRIORITY ("Priority:", "priority", false), 
55
	PRODUCT ("Product:", "product", false), 
56
	REP_PLATFORM ("Platform:", "rep_platform", false),
57
	REPORTER ("Reporter:", "reporter", false, true),
58
	REPORTER_ACCESSIBLE ("reporter_accessible", "reporter_accessible", true),
59
	RESOLUTION ("Resolution:", "resolution", false, true), // Exiting bug field, new cc
60
	SHORT_DESC ("Summary:", "short_desc", true),
61
	TARGET_MILESTONE ("Target milestone:", "target_milestone", false),
62
	THETEXT ("thetext", "thetext"),
63
	TYPE ("type", "type"),
64
	UNKNOWN ("UNKNOWN", "UNKNOWN"),
65
	VERSION ("Version:", "version", false),
66
	VOTES ("Votes:", "votes", false, true),
67
	WHO ("who", "who");
68
	
69
70
	
71
	private final boolean isHidden;
72
	private final boolean isReadOnly;
73
	private final String keyString;
74
	private final String prettyName;
75
76
	BugzillaReportElement(String prettyName, String fieldName) {		
77
		this(prettyName, fieldName, false, false);
78
	}
79
	
80
	BugzillaReportElement(String prettyName, String fieldName, boolean hidden) {		
81
		this(prettyName, fieldName, hidden, false);
82
	}
83
	
84
	BugzillaReportElement(String prettyName, String fieldName, boolean hidden, boolean readonly) {		
85
		this.prettyName = prettyName;
86
		this.keyString = fieldName;
87
		this.isHidden = hidden;
88
		this.isReadOnly = readonly;
89
	}
90
91
	public String getKeyString() {
92
		return keyString;
93
	}
94
95
	public boolean isHidden() {
96
		return isHidden;
97
	}	
98
	
99
	public boolean isReadOnly() {
100
		return isReadOnly;
101
	}
102
	
103
	public String toString() {
104
		return prettyName;
105
	}
106
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/NewBugzillaReport.java (+223 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.core;
12
13
import java.io.Serializable;
14
import java.util.Date;
15
16
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
17
18
/**
19
 * This class is used to store data about the new bug that is being created
20
 * while the wizard is being used
21
 * 
22
 * @author Eric Booth
23
 * @author Rob Elves
24
 */
25
public class NewBugzillaReport extends BugzillaReport implements Serializable { 
26
27
	/** Automatically generated serialVersionUID */
28
	private static final long serialVersionUID = 3977859587934335283L;
29
30
	/** Whether the attributes have been parsed yet or not */
31
	protected boolean hasParsedAttributes = false;
32
33
	/** Whether the products have been parsed yet or not */
34
	protected boolean hasParsedProducts = false;
35
//
36
//	// /** The bug's id */
37
//	// protected final int id;
38
//
39
	/** The product that the bug is for */
40
	protected String product;
41
//
42
//	// /** A list of the attributes that can be changed for the new bug */
43
//	// public Map<String, AbstractRepositoryReportAttribute> attributes = new
44
//	// LinkedHashMap<String, AbstractRepositoryReportAttribute>();
45
//
46
	/** The summary for the bug */
47
	protected String summary = "";
48
49
	/** The description for the bug */
50
	protected String description = "";
51
52
	/**
53
	 * Flag to indicate status of connection to Bugzilla server to identify
54
	 * whether ProductConfiguration should be used instead
55
	 */
56
	protected boolean connected = true;
57
58
	/** Whether or not this bug report is saved offline. */
59
	protected boolean savedOffline = false;
60
61
	/**
62
	 * Creates a new <code>NewBugModel</code>. The id chosen for this bug is
63
	 * based on the id of the last <code>NewBugModel</code> that was created.
64
	 */
65
	public NewBugzillaReport(String repositoryURL) {
66
		super(BugzillaPlugin.getDefault().getOfflineReports().getNextOfflineBugId(), repositoryURL);
67
		// id =
68
		// BugzillaPlugin.getDefault().getOfflineReports().getNextOfflineBugId();
69
	}
70
71
	// public AbstractRepositoryReportAttribute getAttribute(String key) {
72
	// return attributes.get(key);
73
	// }
74
75
	// /**
76
	// * Get the list of attributes for this model
77
	// *
78
	// * @return An <code>ArrayList</code> of the models attributes
79
	// */
80
	// public List<AbstractRepositoryReportAttribute> getAttributes() {
81
	// // create an array list to store the attributes in
82
	// ArrayList<AbstractRepositoryReportAttribute> attributeEntries = new
83
	// ArrayList<AbstractRepositoryReportAttribute>(attributes.keySet().size());
84
	//
85
	// // go through each of the attribute keys
86
	// for (Iterator<String> it = attributes.keySet().iterator(); it.hasNext();)
87
	// {
88
	// // get the key for the attribute
89
	// String key = it.next();
90
	//
91
	// // get the attribute and add it to the list
92
	// AbstractRepositoryReportAttribute attribute = attributes.get(key);
93
	// attributeEntries.add(attribute);
94
	// }
95
	//
96
	// // return the list of attributes for the bug
97
	// return attributeEntries;
98
	// }
99
100
	// public int getId() {
101
	// return id;
102
	// }
103
	//
104
	// public String getRepositoryUrl() {
105
	// return BugzillaTools.OFFLINE_SERVER_DEFAULT;
106
	// }
107
108
	public String getLabel() {
109
		return "New Bug #" + getId();
110
	}
111
112
	public String getDescription() {
113
		return description;
114
	}
115
116
	public void setDescription(String newDescription) {
117
		description = newDescription;
118
	}
119
120
	public String getSummary() {
121
		return summary;
122
	}
123
124
	public void setSummary(String newSummary) {
125
		summary = newSummary;
126
	}
127
128
	/**
129
	 * @return The product that the bug is for.
130
	 */
131
	public String getProduct() {
132
		return product;
133
	}
134
135
	/**
136
	 * Sets the product that the bug is for.
137
	 * 
138
	 * @param product
139
	 *            The product.
140
	 */
141
	public void setProduct(String product) {
142
		this.product = product;
143
	}
144
145
	/**
146
	 * @return Flag to indicate status of connection to Bugzilla server (to
147
	 *         identify whether ProductConfiguration should be used instead)
148
	 */
149
	public boolean isConnected() {
150
		return connected;
151
	}
152
153
	/**
154
	 * Sets the value of the flag to indicate status of connection to Bugzilla
155
	 * server (to identify whether ProductConfiguration should be used instead)
156
	 * 
157
	 * @param newConnectionStatus
158
	 *            <code>true</code> if the bug is connected.
159
	 */
160
	public void setConnected(boolean newConnectionStatus) {
161
		connected = newConnectionStatus;
162
	}
163
164
	/**
165
	 * @return Returns whether the attributes have been parsed yet or not.
166
	 */
167
	public boolean hasParsedAttributes() {
168
		return hasParsedAttributes;
169
	}
170
171
	/**
172
	 * Sets whether the attributes have been parsed yet or not.
173
	 * 
174
	 * @param hasParsedAttributes
175
	 *            <code>true</code> if the attributes have been parsed.
176
	 */
177
	public void setParsedAttributesStatus(boolean hasParsedAttributes) {
178
		this.hasParsedAttributes = hasParsedAttributes;
179
	}
180
181
	/**
182
	 * @return Returns whether the products have been parsed yet or not.
183
	 */
184
	public boolean hasParsedProducts() {
185
		return hasParsedProducts;
186
	}
187
188
	/**
189
	 * Sets whether the products have been parsed yet or not.
190
	 * 
191
	 * @param hasParsedProducts
192
	 *            <code>true</code> if the products have been parsed.
193
	 */
194
	public void setParsedProductsStatus(boolean hasParsedProducts) {
195
		this.hasParsedProducts = hasParsedProducts;
196
	}
197
198
	public boolean isSavedOffline() {
199
		return savedOffline;
200
	}
201
202
	public boolean isLocallyCreated() {
203
		return true;
204
	}
205
206
	public void setOfflineState(boolean newOfflineState) {
207
		savedOffline = newOfflineState;
208
	}
209
210
	public boolean hasChanges() {
211
		return true;
212
	}
213
214
	/** returns null */
215
	public Date getCreated() {
216
		return null;
217
	}
218
219
	public Date getLastModified() {
220
		return null;
221
	}
222
223
}
(-)src/org/eclipse/mylar/bugzilla/core/BugzillaAttributeFactory.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
15
16
/**
17
 * @author Rob Elves
18
 */
19
public class BugzillaAttributeFactory extends AbstractAttributeFactory {
20
21
	@Override
22
	public AbstractRepositoryReportAttribute createAttribute(Object key) {
23
		return new BugzillaReportAttribute((BugzillaReportElement) key);
24
	}
25
26
}
(-)src/org/eclipse/mylar/bugzilla/core/AbstractAttributeFactory.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
/**
15
 * @author Rob Elves
16
 */
17
public abstract class AbstractAttributeFactory {
18
19
	public abstract AbstractRepositoryReportAttribute createAttribute(Object key);
20
	
21
}
(-)src/org/eclipse/mylar/bugzilla/core/ReportAttachment.java (+85 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import java.io.Serializable;
15
import java.text.SimpleDateFormat;
16
import java.util.Date;
17
18
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
19
20
/**
21
 * TODO: Make generic. This currently represents Bugzilla attachments only
22
 * @author relves
23
 */
24
public class ReportAttachment extends AttributeContainer implements Serializable {
25
26
	private static final long serialVersionUID = -9123545810321250785L;
27
	
28
	/** Parser for dates in the report */
29
	private static SimpleDateFormat creation_ts_date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
30
31
	private boolean isObsolete = false;
32
33
	private Date created;
34
	
35
	public boolean isObsolete() {
36
		return isObsolete;
37
	}
38
39
	public void setObsolete(boolean isObsolete) {
40
		this.isObsolete = isObsolete;
41
	}
42
	
43
44
	/** 
45
	 * may return null if date is unknown/unparseable
46
	 */
47
	public Date getDateCreated() {
48
		if(created == null) {
49
			//created = Calendar.getInstance().getTime();
50
			try {
51
				created = creation_ts_date_format.parse(getAttributeValue(BugzillaReportElement.DATE));
52
			} catch (Exception e) {
53
			}			
54
		}
55
		return created;
56
	}
57
58
	/**
59
	 * Currently returns empty string. XML from bugzilla
60
	 * doesn't include who attached directly in attachment data
61
	 * TODO: Retrieve from associated comment
62
	 * @return
63
	 */
64
	public String getAuthor() {
65
		return "";
66
	}
67
68
	public String getDescription() {
69
		//System.err.println(getAttributeValue(BugzillaReportElement.DESC));
70
		return getAttributeValue(BugzillaReportElement.DESC);
71
	}
72
73
	public int getId() {
74
		try {
75
			return Integer.parseInt(getAttributeValue(BugzillaReportElement.ATTACHID));
76
		} catch (NumberFormatException e) {
77
			return -1;
78
		}
79
	}
80
81
	public Object getContentType() {
82
		return getAttributeValue(BugzillaReportElement.CTYPE);
83
	}
84
	
85
}
(-)src/org/eclipse/mylar/bugzilla/core/AbstractRepositoryReport.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import java.io.Serializable;
15
import java.io.UnsupportedEncodingException;
16
import java.nio.charset.Charset;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
/**
21
 * @author Mik Kersten
22
 * @author Rob Elves
23
 */
24
public abstract class AbstractRepositoryReport extends AttributeContainer implements Serializable {
25
26
	private String charset = null;
27
28
	private int reportID;
29
30
	private String repositoryURL;
31
32
	private List<Comment> comments = new ArrayList<Comment>();
33
34
	private List<ReportAttachment> attachments = new ArrayList<ReportAttachment>();
35
36
	private boolean hasChanges = false;
37
38
	public AbstractRepositoryReport(int id, String repositoryURL) {
39
		super();
40
		this.reportID = id;
41
		this.repositoryURL = repositoryURL;
42
	}
43
44
	public void addComment(Comment comment) {
45
		Comment preceding = null;
46
		if (comments.size() > 0) {
47
			// if there are some comments, get the last comment and set the next
48
			// value to be the new comment
49
			preceding = comments.get(comments.size() - 1);
50
			preceding.setNext(comment);
51
		}
52
		// set the comments previous value to the preceeding one
53
		comment.setPrevious(preceding);
54
55
		// comment.setText(decodeStringFromCharset(comment.getText()));
56
		// add the comment to the comment list
57
		comments.add(comment);
58
	}
59
60
	public List<Comment> getComments() {
61
		return comments;
62
	}
63
64
	public void addAttachment(ReportAttachment attachment) {
65
		attachments.add(attachment);
66
	}
67
68
	public List<ReportAttachment> getAttachments() {
69
		return attachments;
70
	}
71
72
	public int getId() {
73
		return reportID;
74
	}
75
76
	/**
77
	 * @return the server for this report
78
	 */
79
	public String getRepositoryUrl() {
80
		return repositoryURL;
81
	}
82
83
	public String getCharset() {
84
		return charset;
85
	}
86
87
	public void setCharset(String charset) {
88
		this.charset = charset;
89
	}
90
91
	public boolean hasChanges() {
92
		return hasChanges ;
93
	}
94
95
	public void setHasChanged(boolean b) {
96
		hasChanges = b;
97
	}
98
	
99
	/**
100
	 * @return <code>true</code> if this report was created locally, and does not
101
	 *         yet exist on a server.
102
	 */
103
	public abstract boolean isLocallyCreated();
104
	
105
	/**
106
	 * @return <code>true</code> if this report is saved offline.
107
	 */
108
	public abstract boolean isSavedOffline();
109
110
	/**
111
	 * Sets whether or not this report is saved offline.
112
	 * 
113
	 * @param newOfflineState
114
	 *            <code>true</code> if this bug is saved offline
115
	 */
116
	public abstract void setOfflineState(boolean newOfflineState);
117
118
//	public String getAttributeValue(Object key) {
119
//		AbstractRepositoryReportAttribute attribute = getAttribute(key);
120
//		if(attribute != null) {
121
//			return attribute.getValue();
122
//		}
123
//		return "";
124
//	}
125
	
126
	public List<String> getAttributeValues(Object key) {
127
		AbstractRepositoryReportAttribute attribute = getAttribute(key);
128
		if(attribute != null) {
129
			return attribute.getValues();
130
		}
131
		return new ArrayList<String>();
132
	}
133
134
	/** 
135
	 * sets a value on an attribute, if attribute doesn't exist,
136
	 * appropriate attribute is created
137
	 */
138
	public void setAttributeValue(Object key, String value) {
139
		AbstractRepositoryReportAttribute attrib = getAttribute(key);
140
		if(attrib == null) {
141
			attrib = getAttributeFactory().createAttribute(key);
142
			this.addAttribute(key, attrib);
143
		}
144
		attrib.setValue(value);		
145
	}
146
	
147
	public void addAttributeValue(Object key, String value) {
148
		AbstractRepositoryReportAttribute attrib = getAttribute(key);
149
		if (attrib != null) {
150
			attrib.addValue(value);
151
		} else {
152
			attrib = getAttributeFactory().createAttribute(key);
153
			attrib.addValue(value);
154
			this.addAttribute(key, attrib);
155
		}
156
	}
157
	
158
	public void removeAttributeValue(Object key, String value) {
159
		AbstractRepositoryReportAttribute attrib = getAttribute(key);
160
		if (attrib != null) {
161
			attrib.removeValue(value);
162
		} 
163
	}
164
165
	public abstract AbstractAttributeFactory getAttributeFactory();
166
	
167
	protected String decodeStringFromCharset(String string) {
168
		String decoded = string;
169
		if (charset != null && string != null && Charset.availableCharsets().containsKey(charset)) {
170
			try {
171
				decoded = new String(string.getBytes(), charset);
172
			} catch (UnsupportedEncodingException e) {
173
				// ignore
174
			}
175
		}
176
		return decoded;
177
	}
178
179
}
(-)src/org/eclipse/mylar/bugzilla/core/BugzillaReportAttribute.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
15
16
public class BugzillaReportAttribute extends AbstractRepositoryReportAttribute {
17
18
	private static final long serialVersionUID = 6959987055086133307L;
19
20
	public BugzillaReportAttribute(BugzillaReportElement element) {
21
		super(element.toString(), element.isHidden());
22
		super.setID(element.getKeyString());
23
		super.setReadOnly(element.isReadOnly());
24
	}
25
	
26
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/RepositoryConfigurationFactory.java (+117 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.io.StringReader;
18
import java.net.URL;
19
import java.net.URLConnection;
20
21
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
22
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
23
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
24
import org.xml.sax.ErrorHandler;
25
import org.xml.sax.InputSource;
26
import org.xml.sax.SAXException;
27
import org.xml.sax.SAXParseException;
28
import org.xml.sax.XMLReader;
29
import org.xml.sax.helpers.XMLReaderFactory;
30
31
/**
32
 * Reads bugzilla product configuration from config.cgi on server in RDF format.
33
 * 
34
 * @author Rob Elves
35
 */
36
public class RepositoryConfigurationFactory {
37
38
	private static final String CONFIG_RDF_URL = "/config.cgi?ctype=rdf";
39
40
	private static RepositoryConfigurationFactory instance;
41
42
	private RepositoryConfigurationFactory() {
43
		// no initial setup needed
44
	}
45
46
	public static RepositoryConfigurationFactory getInstance() {
47
		if (instance == null) {
48
			instance = new RepositoryConfigurationFactory();
49
		}
50
		return instance;
51
	}
52
53
	public RepositoryConfiguration getConfiguration(TaskRepository repository) throws IOException {
54
		String configUrlStr = repository.getUrl() + CONFIG_RDF_URL;
55
		configUrlStr = BugzillaRepositoryUtil.addCredentials(repository, configUrlStr);
56
		URLConnection c = new URL(configUrlStr).openConnection();
57
		BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream()));
58
59
		SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
60
61
		try {
62
			StringBuffer result = XmlCleaner.clean(in);
63
			StringReader strReader = new StringReader(result.toString());
64
			XMLReader reader = XMLReaderFactory.createXMLReader();
65
			reader.setErrorHandler(new SaxErrorHandler());
66
			reader.setContentHandler(contentHandler);
67
			reader.parse(new InputSource(strReader));
68
		} catch (SAXException e) {
69
			throw new IOException("Unable to read server configuration.");
70
		}
71
		return contentHandler.getConfiguration();
72
73
	}
74
75
	// public RepositoryConfiguration getConfiguration(String server) throws
76
	// IOException {
77
	// URL serverURL = new URL(server + CONFIG_RDF_URL);
78
	// BugzillaRepositoryUtil.addCredentials(repository, serverURL)
79
	// URLConnection c = serverURL.openConnection();
80
	// BufferedReader in = new BufferedReader(new
81
	// InputStreamReader(c.getInputStream()));
82
	//
83
	// SaxConfigurationContentHandler contentHandler = new
84
	// SaxConfigurationContentHandler();
85
	//
86
	// try {
87
	// StringBuffer result = XmlCleaner.clean(in);
88
	// StringReader strReader = new StringReader(result.toString());
89
	// XMLReader reader = XMLReaderFactory.createXMLReader();
90
	// reader.setErrorHandler(new SaxErrorHandler());
91
	// reader.setContentHandler(contentHandler);
92
	// reader.parse(new InputSource(strReader));
93
	// } catch (SAXException e) {
94
	// throw new IOException("Unable to read server configuration.");
95
	// }
96
	// return contentHandler.getConfiguration();
97
	//
98
	// }
99
100
	class SaxErrorHandler implements ErrorHandler {
101
102
		public void error(SAXParseException exception) throws SAXException {
103
			MylarStatusHandler.fail(exception, "ServerConfigurationFactory: " + exception.getLocalizedMessage(), false);
104
		}
105
106
		public void fatalError(SAXParseException exception) throws SAXException {
107
			MylarStatusHandler.fail(exception, "ServerConfigurationFactory: " + exception.getLocalizedMessage(), false);
108
109
		}
110
111
		public void warning(SAXParseException exception) throws SAXException {
112
			// ignore
113
		}
114
115
	}
116
117
}
(-)src/org/eclipse/mylar/bugzilla/core/AbstractRepositoryReportAttribute.java (+202 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import java.io.Serializable;
15
import java.util.ArrayList;
16
import java.util.LinkedHashMap;
17
import java.util.List;
18
import java.util.Map;
19
20
/**
21
 * Class representing a report attribute may contain child attributes
22
 * 
23
 * @author Rob Elves
24
 */
25
public abstract class AbstractRepositoryReportAttribute implements Serializable {
26
27
	private boolean hidden = false;
28
	private boolean isReadOnly = false;;
29
	
30
	/** Attribute pretty printing name */
31
	private String name;
32
33
	/** Name of the option used when updating the attribute on the server */
34
	private String id;
35
36
	/** Legal values of the attribute */
37
	private LinkedHashMap<String, String> optionValues;
38
39
	/**
40
	 * Attribute's values (selected or added) 
41
	 */
42
	private List<String> values = new ArrayList<String>();
43
44
	public AbstractRepositoryReportAttribute(String name, boolean hidden) {
45
		// initialize the name and its legal values
46
		this.name = name;
47
		this.hidden = hidden;
48
		optionValues = new LinkedHashMap<String, String>();
49
	}
50
51
	public String getName() {
52
		return name;
53
	}
54
55
	public String getID() {
56
		return id;
57
	}
58
59
	public boolean isReadOnly() {
60
		return isReadOnly ;//optionValues.size() > 0;
61
	}
62
	
63
	public void setReadOnly(boolean readonly) {
64
		this.isReadOnly = readonly;
65
	}
66
67
	public Map<String, String> getOptionValues() {
68
		return optionValues;
69
	}
70
71
	public String getValue() {
72
		if (values.size() > 0) {
73
			return values.get(0);
74
		} else {
75
			return "";
76
		}
77
	}
78
79
	public List<String> getValues() {
80
		return values;
81
	}
82
83
	public void setValue(String value) {
84
		if(values.size() > 0) {
85
			values.set(0, value);
86
		} else {
87
			values.add(value);
88
		}
89
		// newValues.add(value);
90
	}
91
92
	public void setValues(List<String> values) {
93
		values.clear();
94
		values.addAll(values);
95
	}
96
97
	public void addValue(String value) {
98
		values.add(value);
99
	}
100
101
	public void removeValue(String value) {
102
		if (values.contains(value)) {
103
			values.remove(values.indexOf(value));
104
		}
105
	}
106
	
107
	public void clearValues() {
108
		values.clear();
109
	}
110
	
111
112
113
	// /**
114
	// * Set the new value of the attribute
115
	// *
116
	// * @param newVal
117
	// * The new value of the attribute
118
	// */
119
	// public void setNewValue(String newVal) {
120
	// newValues.add(newVal);
121
	// }
122
	//
123
	// public void setNewValues(List<String> newVals) {
124
	// newValues.clear();
125
	// newValues.addAll(newVals);
126
	// }
127
128
	// /**
129
	// * Get the new value for the attribute
130
	// *
131
	// * @return The new value
132
	// */
133
	// public String getNewValue() {
134
	// if(newValues.size() > 0) {
135
	// return values.get(0);
136
	// } else {
137
	// return "";
138
	// }
139
	// }
140
141
	// public List<String> getNewValues() {
142
	// return newValues;
143
	// }
144
145
	// public boolean isMultiValued() {
146
	// return newValues.size() > 1;
147
	// }
148
149
	/**
150
	 * Sets the name of the option used when updating the attribute on the
151
	 * server
152
	 * 
153
	 * @param parameterName
154
	 *            The name of the option when updating from the server
155
	 */
156
	public void setID(String parameterName) {
157
		this.id = parameterName;
158
	}
159
160
	/**
161
	 * Adds an attribute option value
162
	 * 
163
	 * @param readableValue
164
	 *            The value displayed on the screen
165
	 * @param parameterValue
166
	 *            The option value used when sending the form to the server
167
	 */
168
	public void addOptionValue(String readableValue, String parameterValue) {
169
		optionValues.put(readableValue, parameterValue);
170
	}
171
172
	/**
173
	 * Determine if the field was hidden or not
174
	 * 
175
	 * @return True if the field was hidden
176
	 */
177
	public boolean isHidden() {
178
		return hidden;
179
	}
180
181
	/**
182
	 * Set whether the field was hidden in the bug
183
	 * 
184
	 * @param b
185
	 *            Whether the field was hidden or not
186
	 */
187
	public void setHidden(boolean b) {
188
		hidden = b;
189
	}
190
191
	public String toString() {
192
		return getValue();
193
	}
194
	
195
	public boolean hasOptions() {
196
		return optionValues.size() > 0;
197
	}
198
199
	public void clearOptions() {
200
		optionValues.clear();
201
	}
202
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/SaxBugReportContentHandler.java (+206 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
15
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
16
import org.eclipse.mylar.bugzilla.core.BugzillaReportAttribute;
17
import org.eclipse.mylar.bugzilla.core.Comment;
18
import org.eclipse.mylar.bugzilla.core.ReportAttachment;
19
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
20
import org.xml.sax.Attributes;
21
import org.xml.sax.SAXException;
22
import org.xml.sax.helpers.DefaultHandler;
23
24
/**
25
 * Parser for xml bugzilla reports.
26
 * 
27
 * @author Rob Elves
28
 */
29
public class SaxBugReportContentHandler extends DefaultHandler {
30
31
	private StringBuffer characters;
32
33
	private Comment comment;
34
35
	private int commentNum = 0;
36
37
	private ReportAttachment attachment;
38
39
	private BugzillaReport report;
40
41
	private String errorMessage = null;
42
43
	public SaxBugReportContentHandler(BugzillaReport rpt) {
44
		this.report = rpt;
45
	}
46
47
	public boolean errorOccurred() {
48
		return errorMessage != null;
49
	}
50
51
	public String getErrorMessage() {
52
		return errorMessage;
53
	}
54
55
	public BugzillaReport getReport() {
56
		return report;
57
	}
58
59
	@Override
60
	public void characters(char[] ch, int start, int length) throws SAXException {
61
		characters.append(ch, start, length);
62
	}
63
64
	@Override
65
	public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
66
		characters = new StringBuffer();
67
		BugzillaReportElement tag = BugzillaReportElement.UNKNOWN;
68
		try {
69
			tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase());
70
		} catch (RuntimeException e) {
71
			if (e instanceof IllegalArgumentException) {
72
				MylarStatusHandler.fail(new Exception(e), "Mylar: Bugzilla report element not known: "
73
						+ e.getMessage().trim(), false);
74
				errorMessage = "Mylar: Bugzilla report element not known: " + e.getMessage().trim();
75
			}
76
		}
77
		switch (tag) {
78
		case BUGZILLA:
79
			// Note: here we can get the bugzilla version if necessary
80
			break;
81
		case BUG:
82
			if (attributes != null && (attributes.getValue("error") != null)) {
83
				errorMessage = attributes.getValue("error");
84
			}
85
			break;
86
		case LONG_DESC:
87
			comment = new Comment(report, commentNum++);
88
			break;
89
		case ATTACHMENT:
90
			attachment = new ReportAttachment();
91
			if (attributes != null && (attributes.getValue(BugzillaReportElement.IS_OBSOLETE.getKeyString()) != null)) {
92
				attachment.addAttribute(BugzillaReportElement.IS_OBSOLETE, new BugzillaReportAttribute(
93
						BugzillaReportElement.IS_OBSOLETE));
94
			}
95
			break;
96
		}
97
98
	}
99
100
	@Override
101
	public void endElement(String uri, String localName, String qName) throws SAXException {
102
		BugzillaReportElement tag = BugzillaReportElement.valueOf(localName.trim().toUpperCase());
103
104
		switch (tag) {
105
		case BUG_ID: {
106
			try {
107
				if (report.getId() != Integer.parseInt(characters.toString())) {
108
					errorMessage = "Requested report number does not match returned report number.";
109
				}
110
			} catch (NumberFormatException e) {
111
				errorMessage = "Bug id from server did not match requested id.";
112
			}
113
114
			AbstractRepositoryReportAttribute attr = report.getAttribute(tag);
115
			if (attr == null) {
116
				attr = new BugzillaReportAttribute(tag);
117
				report.addAttribute(tag, attr);
118
			}
119
			attr.setValue(characters.toString());
120
			break;
121
		}
122
123
			// Comment attributes
124
		case WHO:
125
		case BUG_WHEN:
126
		case THETEXT:
127
			if (comment != null) {
128
				BugzillaReportAttribute attr = new BugzillaReportAttribute(tag);
129
				attr.setValue(characters.toString());
130
				// System.err.println(">>> "+comment.getNumber()+"
131
				// "+characters.toString());
132
				comment.addAttribute(tag, attr);
133
			}
134
			break;
135
		case LONG_DESC:
136
			if (comment != null) {
137
				report.addComment(comment);
138
			}
139
			break;
140
141
		// Attachment attributes
142
		case ATTACHID:
143
		case DATE:
144
		case DESC:
145
		case FILENAME:
146
		case CTYPE:
147
		case TYPE:
148
			if (attachment != null) {
149
				BugzillaReportAttribute attr = new BugzillaReportAttribute(tag);
150
				attr.setValue(characters.toString());
151
				attachment.addAttribute(tag, attr);
152
			}
153
			break;
154
		case DATA:
155
			// TODO: Need to figure out under what circumstanceswhen attachments
156
			// are inline and
157
			// what to do with them.
158
			break;
159
		case ATTACHMENT:
160
			if (attachment != null) {
161
				report.addAttachment(attachment);
162
			}
163
			break;
164
165
		// IGNORED ELEMENTS
166
		case REPORTER_ACCESSIBLE:
167
		case CLASSIFICATION_ID:
168
		case CLASSIFICATION:
169
		case CCLIST_ACCESSIBLE:
170
		case EVERCONFIRMED:
171
		case BUGZILLA:
172
			break;
173
		case BUG:
174
			// Reached end of bug. Need to set LONGDESCLENGTH to number of
175
			// comments
176
			AbstractRepositoryReportAttribute numCommentsAttribute = report
177
					.getAttribute(BugzillaReportElement.LONGDESCLENGTH);
178
			if (numCommentsAttribute == null) {
179
				numCommentsAttribute = new BugzillaReportAttribute(BugzillaReportElement.LONGDESCLENGTH);
180
				numCommentsAttribute.setValue("" + report.getComments().size());
181
				report.addAttribute(BugzillaReportElement.LONGDESCLENGTH, numCommentsAttribute);
182
			} else {
183
				numCommentsAttribute.setValue("" + report.getComments().size());
184
			}
185
			break;
186
187
		// All others added as report attribute
188
		default:
189
			AbstractRepositoryReportAttribute attribute = report.getAttribute(tag);
190
			if (attribute == null) {
191
				// System.err.println(">>> Undeclared attribute added: " +
192
				// tag.toString()+" value: "+characters.toString());
193
				attribute = new BugzillaReportAttribute(tag);
194
				attribute.setValue(characters.toString());
195
				report.addAttribute(tag, attribute);
196
			} else {
197
				// System.err.println("Attr: " + attribute.getName() + " = " +
198
				// characters.toString());
199
				attribute.addValue(characters.toString());
200
			}
201
			break;
202
		}
203
204
	}
205
206
}
(-)src/org/eclipse/mylar/bugzilla/core/BugzillaReport.java (+517 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.core;
12
13
import java.io.Serializable;
14
import java.text.SimpleDateFormat;
15
import java.util.ArrayList;
16
import java.util.Date;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.StringTokenizer;
20
21
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
22
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
23
24
/**
25
 * A bug report entered in Bugzilla.
26
 * 
27
 * @author Mik Kersten
28
 * @author Rob Elves
29
 */
30
public class BugzillaReport extends AbstractRepositoryReport implements IBugzillaBug, Serializable {
31
32
	private static final long serialVersionUID = 310066248657960823L;
33
34
	public static final String VAL_STATUS_VERIFIED = "VERIFIED";
35
36
	public static final String VAL_STATUS_CLOSED = "CLOSED";
37
38
	public static final String VAL_STATUS_RESOLVED = "RESOLVED";
39
40
	public static final String VAL_STATUS_NEW = "NEW";
41
42
	/** Parser for dates in the report */
43
	private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
44
45
	/** Description of the bug */
46
	protected String description;
47
48
	/** Creation timestamp */
49
	protected Date created;
50
51
	/** Modification timestamp */
52
	protected Date lastModified = null;
53
54
	/** The bugs valid keywords */
55
	protected List<String> validKeywords;
56
57
	/** The operations that can be done on the report */
58
	protected List<Operation> operations = new ArrayList<Operation>();
59
60
	private static final AbstractAttributeFactory attributeFactory = new BugzillaAttributeFactory();
61
62
	// /** Bug attributes (status, resolution, etc.) */
63
	// protected HashMap<String, AbstractRepositoryReportAttribute> attributes =
64
	// new HashMap<String, AbstractRepositoryReportAttribute>();
65
	//
66
	//
67
	// /** The keys for the bug attributes */
68
	// protected ArrayList<String> attributeKeys = new ArrayList<String>();
69
70
	// /** A list of comments */
71
	// protected ArrayList<Comment> comments = new ArrayList<Comment>();
72
73
	/** The value for the new comment to add (text that is saved) */
74
	protected String newComment = "";
75
76
	// /** The new value for the new comment to add (text from submit editor) */
77
	// protected String newNewComment = "";
78
79
	/** The operation that was selected to do to the bug */
80
	protected Operation selectedOperation = null;
81
82
	/** Whether or not this bug report is saved offline. */
83
	protected boolean savedOffline = false;
84
85
	protected boolean hasChanges = false;
86
87
	protected String charset = null;
88
89
	// /**
90
	// * Get the bugs id
91
	// *
92
	// * @return The bugs id
93
	// */
94
	// public int getId() {
95
	// return id;
96
	// }
97
	//
98
	// public String getRepositoryUrl() {
99
	// return repositoryUrl;
100
	// }
101
102
	public BugzillaReport(int id, String repositoryURL) {
103
		super(id, repositoryURL);
104
105
	}
106
107
	/**
108
	 * TODO: move?
109
	 */
110
	public static boolean isResolvedStatus(String status) {
111
		if (status != null) {
112
			return status.equals(VAL_STATUS_RESOLVED) || status.equals(VAL_STATUS_CLOSED)
113
					|| status.equals(VAL_STATUS_VERIFIED);
114
		} else {
115
			return false;
116
		}
117
	}
118
119
	public void addCC(String email) {
120
		addAttributeValue(BugzillaReportElement.CC, email);
121
	}
122
123
	/**
124
	 * Add an operation to the bug
125
	 * 
126
	 * @param o
127
	 *            The operation to add
128
	 */
129
	public void addOperation(Operation o) {
130
		operations.add(o);
131
	}
132
133
	/**
134
	 * Get the person to whom this bug is assigned
135
	 * 
136
	 * @return The person who is assigned to this bug
137
	 */
138
	public String getAssignedTo() {
139
		return getAttributeValue(BugzillaReportElement.ASSIGNED_TO);
140
	}
141
142
	// public AbstractRepositoryReportAttribute
143
	// getAttributeForKnobName(BugzillaReportElement element) {
144
	// return super.getAttribute(element.getKeyString());
145
	// }
146
147
	// private String decodeStringFromCharset(String string) {
148
	// String decoded = string;
149
	// if (charset != null && string != null &&
150
	// Charset.availableCharsets().containsKey(charset)) {
151
	// try {
152
	// decoded = new String(string.getBytes(), charset);
153
	// } catch (UnsupportedEncodingException e) {
154
	// // ignore
155
	// }
156
	// }
157
	// return decoded;
158
	// }
159
160
	/**
161
	 * Get the set of addresses in the CC list
162
	 * 
163
	 * @return A <code>Set</code> of addresses in the CC list
164
	 */
165
	public List<String> getCC() {
166
		return getAttributeValues(BugzillaReportElement.CC);
167
	}
168
169
	/**
170
	 * Get the date that the bug was created
171
	 * 
172
	 * @return The bugs creation date
173
	 */
174
	public Date getCreated() {
175
		if (created == null) {
176
			String dateString = getAttributeValue(BugzillaReportElement.CREATION_TS);
177
			try {
178
				created = df.parse(dateString);
179
			} catch (Exception e) {
180
				MylarStatusHandler.fail(e, "Mylar: Unable to parse report #" + getId() + "'s creation date.", false);
181
			}
182
		}
183
		return created;
184
	}
185
186
	/**
187
	 * Get the bugs description
188
	 * 
189
	 * @return The description of the bug
190
	 */
191
	public String getDescription() {
192
		List<Comment> coms = this.getComments();
193
		if (coms != null && coms.size() > 0) {
194
			return coms.get(0).getText();
195
		} else {
196
			return "";
197
		}
198
199
	}
200
201
	// public AbstractRepositoryReportAttribute getAttribute(String key) {
202
	// return attributes.get(key);
203
	// }
204
	//
205
	// /**
206
	// * Get the list of attributes for this bug
207
	// *
208
	// * @return An <code>ArrayList</code> of the bugs attributes
209
	// */
210
	// public List<AbstractRepositoryReportAttribute> getAttributes() {
211
	// // create an array list to store the attributes in
212
	// ArrayList<AbstractRepositoryReportAttribute> attributeEntries = new
213
	// ArrayList<AbstractRepositoryReportAttribute>(attributeKeys.size());
214
	//
215
	// // go through each of the attribute keys
216
	// for (Iterator<String> it = attributeKeys.iterator(); it.hasNext();) {
217
	// // get the key for the attribute
218
	// String key = it.next();
219
	//
220
	// // get the attribute and add it to the list
221
	// AbstractRepositoryReportAttribute attribute = attributes.get(key);
222
	// attributeEntries.add(attribute);
223
	// }
224
	//
225
	// // return the list of attributes for the bug
226
	// return attributeEntries;
227
	// }
228
229
	// public AbstractRepositoryReportAttribute getAttributeForKnobName(String
230
	// knobName) {
231
	// for (Iterator<String> it = attributeKeys.iterator(); it.hasNext();) {
232
	// String key = it.next();
233
	//
234
	// AbstractRepositoryReportAttribute attribute = attributes.get(key);
235
	// if (attribute != null && attribute.getID() != null
236
	// && attribute.getID().compareTo(knobName) == 0) {
237
	// return attribute;
238
	// }
239
	// }
240
	//
241
	// return null;
242
	// }
243
244
	// /**
245
	// * @param attribute
246
	// * The attribute to add to the bug
247
	// */
248
	// public void addAttribute(AbstractRepositoryReportAttribute attribute) {
249
	// if (!attributes.containsKey(attribute.getName())) {
250
	// attributeKeys.add(attribute.getName());
251
	// }
252
	//
253
	// attribute.setValue(decodeStringFromCharset(attribute.getValue()));
254
	//
255
	// // put the value of the attribute into the map, using its name as the
256
	// // key
257
	// attributes.put(attribute.getName(), attribute);
258
	// }
259
260
	// /**
261
	// * Get the comments posted on the bug
262
	// *
263
	// * @return A list of comments for the bug
264
	// */
265
	// public ArrayList<Comment> getComments() {
266
	// return comments;
267
	// }
268
269
	// /**
270
	// * Add a comment to the bug
271
	// *
272
	// * @param comment
273
	// * The comment to add to the bug
274
	// */
275
	// public void addComment(Comment comment) {
276
	// Comment preceding = null;
277
	// if (comments.size() > 0) {
278
	// // if there are some comments, get the last comment and set the next
279
	// // value to be the new comment
280
	// preceding = comments.get(comments.size() - 1);
281
	// preceding.setNext(comment);
282
	// }
283
	// // set the comments previous value to the preceeding one
284
	// comment.setPrevious(preceding);
285
	//
286
	// comment.setText(decodeStringFromCharset(comment.getText()));
287
	// // add the comment to the comment list
288
	// comments.add(comment);
289
	// }
290
291
	/**
292
	 * Get the keywords for the bug
293
	 * 
294
	 * @return The keywords for the bug
295
	 */
296
	public List<String> getKeywords() {
297
298
		// get the selected keywords for the bug
299
		StringTokenizer st = new StringTokenizer(getAttributeValue(BugzillaReportElement.KEYWORDS), ",", false);
300
		List<String> keywords = new ArrayList<String>();
301
		while (st.hasMoreTokens()) {
302
			String s = st.nextToken().trim();
303
			keywords.add(s);
304
		}
305
306
		return keywords;
307
		//		
308
		// String[] keywords =
309
		// getAttributeValue(BugzillaReportElement.KEYWORDS).split(",");
310
		// return getAttributeValue(BugzillaReportElement.KEYWORDS)
311
		// BugzillaPlugin.getDefault().getProductConfiguration(repository).getProducts()
312
		//		
313
		// return
314
		// BugzillaRepositoryUtil.getValidKeywords(this.getRepositoryUrl());
315
	}
316
317
	public String getLabel() {
318
		return getId() + ": " + getAttributeValue(BugzillaReportElement.SHORT_DESC);
319
	}
320
321
	public Date getLastModified() {
322
		if (lastModified == null) {
323
			String dateString = getAttributeValue(BugzillaReportElement.DELTA_TS);
324
			try {
325
				lastModified = df.parse(dateString);
326
			} catch (Exception e) {
327
				MylarStatusHandler
328
						.fail(e, "Mylar: Unable to parse report #" + getId() + "'s modification date.", false);
329
			}
330
		}
331
		return lastModified;
332
	}
333
334
	/**
335
	 * Get the new comment that is to be added to the bug
336
	 * 
337
	 * @return The new comment
338
	 */
339
	public String getNewComment() {
340
		return newComment;
341
	}
342
343
	// /**
344
	// * @return the new value of the new NewComment.
345
	// */
346
	// public String getNewNewComment() {
347
	// return newNewComment;
348
	// }
349
350
	/**
351
	 * Get an operation from the bug based on its display name
352
	 * 
353
	 * @param displayText
354
	 *            The display text for the operation
355
	 * @return The operation that has the display text
356
	 */
357
	public Operation getOperation(String displayText) {
358
		Iterator<Operation> itr = operations.iterator();
359
		while (itr.hasNext()) {
360
			Operation o = itr.next();
361
			String opName = o.getOperationName();
362
			opName = opName.replaceAll("</.*>", "");
363
			opName = opName.replaceAll("<.*>", "");
364
			if (opName.equals(displayText))
365
				return o;
366
		}
367
		return null;
368
	}
369
370
	/**
371
	 * Get all of the operations that can be done to the bug
372
	 * 
373
	 * @return The operations that can be done to the bug
374
	 */
375
	public List<Operation> getOperations() {
376
		return operations;
377
	}
378
379
	/**
380
	 * Get the person who reported the bug
381
	 * 
382
	 * @return The person who reported the bug
383
	 */
384
	public String getReporter() {
385
		return getAttributeValue(BugzillaReportElement.REPORTER);
386
	}
387
388
	/**
389
	 * Get the resolution of the bug
390
	 * 
391
	 * @return The resolution of the bug
392
	 */
393
	public String getResolution() {
394
		return getAttributeValue(BugzillaReportElement.RESOLUTION);
395
	}
396
397
	/**
398
	 * Get the status of the bug
399
	 * 
400
	 * @return The bugs status
401
	 */
402
	public String getStatus() {
403
		return getAttributeValue(BugzillaReportElement.BUG_STATUS);
404
	}
405
406
	/**
407
	 * Get the summary for the bug
408
	 * 
409
	 * @return The bugs summary
410
	 */
411
	public String getSummary() {
412
		return getAttributeValue(BugzillaReportElement.SHORT_DESC);
413
	}
414
415
	public void setSummary(String summary) {
416
		setAttributeValue(BugzillaReportElement.SHORT_DESC, summary);
417
	}
418
419
	public String getProduct() {
420
		return getAttributeValue(BugzillaReportElement.PRODUCT);
421
	}
422
423
	// public void setSummary(String newSummary) {
424
	// setAttributeValue(BugzillaReportElement.SHORT_DESC, newSummary);
425
	// }
426
427
	public boolean isLocallyCreated() {
428
		return false;
429
	}
430
431
	public boolean isResolved() {
432
		AbstractRepositoryReportAttribute status = getAttribute(BugzillaReportElement.BUG_STATUS);
433
		return status != null && isResolvedStatus(status.getValue());
434
	}
435
436
	public boolean isSavedOffline() {
437
		return savedOffline;
438
	}
439
440
	/**
441
	 * Remove an address from the bugs CC list
442
	 * 
443
	 * @param email
444
	 *            the address to be removed from the CC list
445
	 * @return <code>true</code> if the email is in the set and it was removed
446
	 */
447
	public void removeCC(String email) {
448
		removeAttributeValue(BugzillaReportElement.CC, email);
449
	}
450
451
	// /**
452
	// * Set the bugs creation date
453
	// *
454
	// * @param created
455
	// * The date the the bug was created
456
	// */
457
	// public void setCreated(Date created) {
458
	// this.created = created;
459
	// }
460
461
	public void setDescription(String description) {
462
		// ignore, used by NewBugReport
463
		// this.description = decodeStringFromCharset(description);
464
	}
465
466
	public void setKeywords(List<String> keywords) {
467
		this.validKeywords = keywords;
468
	}
469
470
	// public void setLastModified(Date date) {
471
	// this.lastModified = date;
472
	// }
473
474
	/**
475
	 * Set the new comment that will be added to the bug
476
	 * 
477
	 * @param newComment
478
	 *            The new comment to add to the bug
479
	 */
480
	public void setNewComment(String newComment) {
481
		this.newComment = newComment;
482
		// newNewComment = newComment;
483
	}
484
485
	// /**
486
	// * Set the new value of the new NewComment
487
	// *
488
	// * @param newNewComment
489
	// * The new value of the new NewComment.
490
	// */
491
	// public void setNewNewComment(String newNewComment) {
492
	// this.newNewComment = newNewComment;
493
	// }
494
495
	public void setOfflineState(boolean newOfflineState) {
496
		savedOffline = newOfflineState;
497
	}
498
499
	public void setSelectedOperation(Operation o) {
500
		selectedOperation = o;
501
	}
502
503
	public Operation getSelectedOperation() {
504
		return selectedOperation;
505
	}
506
507
	@Override
508
	public AbstractAttributeFactory getAttributeFactory() {
509
		return attributeFactory;
510
	}
511
512
	public AbstractRepositoryReportAttribute getAttribute(String test) {
513
514
		MylarStatusHandler.fail(new Exception(), "BugReport: getAttribute called with string", false);
515
		return new BugzillaReportAttribute(BugzillaReportElement.UNKNOWN);
516
	}
517
}
(-)src/org/eclipse/mylar/internal/bugzilla/core/internal/RepositoryReportFactory.java (+188 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.net.URL;
18
import java.net.URLConnection;
19
import java.nio.charset.Charset;
20
21
import javax.security.auth.login.LoginException;
22
23
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
26
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
27
import org.xml.sax.ErrorHandler;
28
import org.xml.sax.InputSource;
29
import org.xml.sax.SAXException;
30
import org.xml.sax.SAXParseException;
31
import org.xml.sax.XMLReader;
32
import org.xml.sax.helpers.XMLReaderFactory;
33
34
/**
35
 * Reads bug reports from repository.
36
 * 
37
 * @author Rob Elves
38
 */
39
public class RepositoryReportFactory {
40
41
	private static RepositoryReportFactory instance;
42
43
	private static final String SHOW_BUG_CGI_XML = "/show_bug.cgi?ctype=xml&id=";
44
45
	private static final String ATTR_CHARSET = "charset";
46
47
	private RepositoryReportFactory() {
48
		// no initial setup needed
49
	}
50
51
	public static RepositoryReportFactory getInstance() {
52
		if (instance == null) {
53
			instance = new RepositoryReportFactory();
54
		}
55
		return instance;
56
	}
57
58
	// /**
59
	// * Bugzilla specific, to be generalized
60
	// * TODO: Based on repository kind use appropriate loader
61
	// */
62
	// public AbstractRepositoryReport readReport(int id, TaskRepository
63
	// repository)
64
	// throws IOException, LoginException {
65
	// BugReport bugReport = new BugReport(id, repository.getUrl());
66
	// SaxBugReportContentHandler contentHandler = new
67
	// SaxBugReportContentHandler(bugReport);
68
	//
69
	// String xmlBugReportUrl = repository.getUrl() + SHOW_BUG_CGI_XML + id;
70
	//
71
	// URL serverURL = new URL(BugzillaRepositoryUtil.addCredentials(repository,
72
	// xmlBugReportUrl));
73
	// URLConnection connection = serverURL.openConnection();
74
	// String contentType = connection.getContentType();
75
	// if (contentType != null) {
76
	// String charsetFromContentType = getCharsetFromString(contentType);
77
	// if (charsetFromContentType != null) {
78
	// bugReport.setCharset(charsetFromContentType);
79
	// }
80
	// }
81
	//		
82
	// BufferedReader in = new BufferedReader(new
83
	// InputStreamReader(connection.getInputStream()));
84
	//
85
	// try {
86
	// XMLReader reader = XMLReaderFactory.createXMLReader();
87
	// reader.setContentHandler(contentHandler);
88
	// reader.setErrorHandler(new SaxErrorHandler());
89
	// reader.parse(new InputSource(in));
90
	//			
91
	// if(contentHandler.errorOccurred()) {
92
	// throw new BugzillaReportParseException(contentHandler.getErrorMessage());
93
	// }
94
	//			
95
	// } catch (SAXException e) {
96
	// throw new IOException(e.getMessage());
97
	// }
98
	// return bugReport;
99
	// }
100
101
	/**
102
	 * Bugzilla specific, to be generalized TODO: Based on repository kind use
103
	 * appropriate loader
104
	 */
105
	public void populateReport(BugzillaReport bugReport, TaskRepository repository) throws IOException, LoginException {
106
107
		SaxBugReportContentHandler contentHandler = new SaxBugReportContentHandler(bugReport);
108
109
		String xmlBugReportUrl = repository.getUrl() + SHOW_BUG_CGI_XML + bugReport.getId();
110
111
		URL serverURL = new URL(BugzillaRepositoryUtil.addCredentials(repository, xmlBugReportUrl));
112
		URLConnection connection = serverURL.openConnection();
113
		String contentType = connection.getContentType();
114
		if (contentType != null) {
115
			String charsetFromContentType = getCharsetFromString(contentType);
116
			if (charsetFromContentType != null) {
117
				bugReport.setCharset(charsetFromContentType);
118
			}
119
		}
120
121
		BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
122
123
		try {
124
			XMLReader reader = XMLReaderFactory.createXMLReader();
125
			reader.setContentHandler(contentHandler);
126
			reader.setErrorHandler(new SaxErrorHandler());
127
			reader.parse(new InputSource(in));
128
129
			if (contentHandler.errorOccurred()) {
130
				throw new BugzillaReportParseException(contentHandler.getErrorMessage());
131
			}
132
133
		} catch (SAXException e) {
134
			throw new IOException(e.getMessage());
135
		}
136
	}
137
138
	// TODO: pull up
139
	public static String getCharsetFromString(String string) {
140
		int charsetStartIndex = string.indexOf(ATTR_CHARSET);
141
		if (charsetStartIndex != -1) {
142
			int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
143
			// could
144
			// be
145
			// space
146
			// after?
147
			if (charsetEndIndex == -1) {
148
				charsetEndIndex = string.length();
149
			}
150
			String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
151
			if (Charset.availableCharsets().containsKey(charsetString)) {
152
				return charsetString;
153
			}
154
		}
155
		return null;
156
	}
157
158
	class SaxErrorHandler implements ErrorHandler {
159
160
		public void error(SAXParseException exception) throws SAXException {
161
			System.err.println("Error: " + exception.getLineNumber() + "\n" + exception.getLocalizedMessage());
162
163
		}
164
165
		public void fatalError(SAXParseException exception) throws SAXException {
166
			// System.err.println("Fatal Error: " + exception.getLineNumber() +
167
			// "\n" + exception.getLocalizedMessage());
168
			// TODO: Need to determine actual error from html
169
			throw new SAXException(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD);
170
		}
171
172
		public void warning(SAXParseException exception) throws SAXException {
173
			System.err.println("Warning: " + exception.getLineNumber() + "\n" + exception.getLocalizedMessage());
174
175
		}
176
177
	}
178
179
	public class BugzillaReportParseException extends IOException {
180
181
		private static final long serialVersionUID = 7269179766737288564L;
182
183
		public BugzillaReportParseException(String message) {
184
			super(message);
185
		}
186
	}
187
188
}
(-)src/org/eclipse/mylar/bugzilla/core/AttributeContainer.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.core;
13
14
import java.io.Serializable;
15
import java.util.ArrayList;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
19
20
public class AttributeContainer implements Serializable {
21
	
22
	private static final long serialVersionUID = -3990742719133977940L;
23
24
	/** The keys for the report attributes */
25
	private ArrayList<Object> attributeKeys;
26
27
	/** report attributes (status, resolution, etc.) */
28
	private HashMap<Object, AbstractRepositoryReportAttribute> attributes;
29
	
30
	public AttributeContainer() {
31
		attributeKeys = new ArrayList<Object>();
32
		attributes = new HashMap<Object, AbstractRepositoryReportAttribute>();
33
	}
34
	
35
	public void addAttribute(Object key, AbstractRepositoryReportAttribute attribute) {
36
		if (!attributes.containsKey(attribute.getName())) {
37
			attributeKeys.add(key);
38
		}
39
40
		// TODO: deal with character sets
41
		//attribute.setValue(decodeStringFromCharset(attribute.getValue()));
42
43
		attributes.put(key, attribute);
44
	}
45
	
46
	public AbstractRepositoryReportAttribute getAttribute(Object key) {
47
		return attributes.get(key);
48
	}
49
50
	public void removeAttribute(Object key) {
51
		attributeKeys.remove(key);
52
		attributes.remove(key);
53
	}
54
	
55
	public List<AbstractRepositoryReportAttribute> getAttributes() {
56
		ArrayList<AbstractRepositoryReportAttribute> attributeEntries = new ArrayList<AbstractRepositoryReportAttribute>(
57
				attributeKeys.size());
58
		for (Iterator<Object> it = attributeKeys.iterator(); it.hasNext();) {
59
			Object key = it.next();
60
			AbstractRepositoryReportAttribute attribute = attributes.get(key);
61
			attributeEntries.add(attribute);
62
		}
63
		return attributeEntries;
64
	}
65
66
	public String getAttributeValue(Object key) {
67
		AbstractRepositoryReportAttribute attribute = getAttribute(key);
68
		if(attribute != null) {
69
			return attribute.getValue();
70
		}
71
		return "";
72
	}
73
}
(-)src/org/eclipse/mylar/tests/misc/AllMiscTests.java (-1 / +1 lines)
Lines 26-32 Link Here
26
		// suite.addTestSuite(BugzillaSearchPluginTest.class);
26
		// suite.addTestSuite(BugzillaSearchPluginTest.class);
27
		suite.addTestSuite(AssertionsEnabledTest.class);
27
		suite.addTestSuite(AssertionsEnabledTest.class);
28
		suite.addTestSuite(HypertextStructureBridgeTest.class);
28
		suite.addTestSuite(HypertextStructureBridgeTest.class);
29
		suite.addTestSuite(BugzillaStackTraceTest.class);
29
		//suite.addTestSuite(BugzillaStackTraceTest.class);
30
		// $JUnit-END$
30
		// $JUnit-END$
31
		return suite;
31
		return suite;
32
	}
32
	}
(-)src/org/eclipse/mylar/tests/misc/BugzillaStackTraceTest.java (-196 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
////Created on Oct 12, 2004
12
package org.eclipse.mylar.tests.misc;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import junit.framework.TestCase;
21
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.mylar.bugzilla.tests.BugzillaTestPlugin;
24
import org.eclipse.mylar.core.tests.support.FileTool;
25
import org.eclipse.mylar.internal.bugs.search.BugzillaMylarSearchOperation;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
27
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchHit;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaReportNode;
29
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.StackTrace;
30
31
/**
32
 * Class to test the Bridge methods that do not require server queries
33
 * 
34
 * @author Shawn Minto
35
 */
36
public class BugzillaStackTraceTest extends TestCase {
37
38
	private static final String TEST_FILE_LOC = "testdata/reports-stacktrace/";
39
40
	private static final String BUGZILLA_SERVER_NAME = "https://bugs.eclipse.org/bugs";
41
42
	/**
43
	 * Test that the regular expression escaping mechanism works properly
44
	 */
45
	public void testREGEX() {
46
		String r = ".*+(){}[]^$|?/\\";
47
		String r2 = StackTrace.escapeForRegex(r);
48
		String ans = "\\.\\*\\+\\(\\)\\{\\}\\[\\]\\^\\$\\|\\?\\/\\\\";
49
		String msg = "Regular Expression matching wrong:\nwas: " + r2 + "\nshould be:" + ans;
50
		assertTrue(msg, r2.equals(ans));
51
	}
52
53
	// /**
54
	// * Test parsing the bug for multiple stacks in in
55
	// */
56
	// public void testMultipleStacksDiffComments(){
57
	// // REPORT_REPOSITORY 4862 - 2 stack traces - 1 in description, 1 in
58
	// comment - text
59
	// before and after
60
	// performParse(4862, "4862.html", 2, false);
61
	// }
62
63
	// /**
64
	// * Test parsing the bug for a single stack in the description with some
65
	// * text before it
66
	// */
67
	// public void testSingleStackCodeBeforeInDescription(){
68
	// // REPORT_REPOSITORY 76388 - 1 stack trace - description - text before
69
	// and formatted
70
	// ugly
71
	// performParse(76388, "76388.html", 1, false);
72
	// }
73
74
	/**
75
	 * Test parsing the bug for a single stack trace in the description with
76
	 * text before and after it
77
	 */
78
	public void testSingleStackCodeBeforeAndAfterInDescription() {
79
80
		// REPORT_REPOSITORY 76146 - 1 stack trace - description - text before
81
		// and code after
82
		performParse(76146, "76146.html", 1, false);
83
	}
84
85
	/**
86
	 * Test parsing a bug that has 1 stack trace in the description with no
87
	 * extra text, but has lines in it that span 3 lines
88
	 */
89
	public void testSingleStackPoorFormatInDescription() {
90
		// REPORT_REPOSITORY 67395 - 1 stack trace - description - no extra
91
		// text, 1 at line
92
		// spans 3 lines
93
		performParse(67395, "67395.html", 1, false);
94
	}
95
96
	/**
97
	 * Test parsing a bug with no stack traces and no qualified exception names
98
	 */
99
	public void testNoStackNoQualified() {
100
		// REPORT_REPOSITORY 4548 - no stack traces, no qualified reference to
101
		// an exception
102
		performParse(4548, "4548.html", 0, false);
103
	}
104
105
	/**
106
	 * Test parsing a bug with no stack traces, but a qualified reference to an
107
	 * exception
108
	 */
109
	public void testNoStackQual() {
110
		// REPORT_REPOSITORY 1 - no stack traces, qualified reference to
111
		// exception - made up
112
		// bug
113
		performParse(1, "1.html", 0, false);
114
	}
115
116
	/**
117
	 * Test parsing of a bug with 1 stack trace and multiple qualified
118
	 * references
119
	 */
120
	public void testSingleStackQual() {
121
		// REPORT_REPOSITORY 2 - 1 stack trace- 2 qual ref, stack trace, 1 qual
122
		// ref - made up
123
		// bug
124
		performParse(2, "2.html", 1, false);
125
	}
126
127
	/**
128
	 * Test parsing of a bug with many stacks traces in a single comment
129
	 */
130
	public void testMultipleStackSingleComment() {
131
		// REPORT_REPOSITORY 40152 - 1 stack trace- 2 qual ref, stack trace, 1
132
		// qual ref - made
133
		// up bug
134
		performParse(40152, "40152.html", 33, false);
135
	}
136
137
	/**
138
	 * Print out the stack traces
139
	 * 
140
	 * @param l
141
	 *            List of stack traces
142
	 */
143
	private void printStackTraces(List<StackTrace> l) {
144
		System.out.println("\n\n");
145
		for (int i = 0; i < l.size(); i++) {
146
			StackTrace trace = l.get(i);
147
			System.out.println("*****************?????????????????*****************\n");
148
			System.out.println("OFFSET: " + trace.getOffset() + " LENGTH: " + trace.getLength());
149
			System.out.println(trace.getStackTrace());
150
			System.out.println("*****************?????????????????*****************\n\n");
151
		}
152
	}
153
154
	private void performParse(int bugNumber, String bugFileName, int numTracesExpected, boolean printStackTraces) {
155
156
		BugzillaSearchHit hit = new BugzillaSearchHit("<TEST-SERVER>", bugNumber, "", "", "", "", "", "", "", ""); // stack
157
		// trace
158
		// in
159
		// desc
160
		// and
161
		// com
162
163
		// create a new doi info
164
		BugzillaReportNode doi = new BugzillaReportNode(0, hit, false);
165
		try {
166
167
			// read the bug in from a file
168
			File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(TEST_FILE_LOC + bugFileName)); // used
169
			// if
170
			// run
171
			// as a
172
			// plugin
173
			// test
174
			// File f = new File(TEST_FILE_LOC+bugFileName); // used if run as a
175
			// standalone test
176
			Reader reader = new FileReader(f);
177
			doi.setBug(BugParser.parseBug(reader, hit.getId(), BUGZILLA_SERVER_NAME, true, null, null, null));
178
			reader.close();
179
		} catch (Exception e) {
180
			e.printStackTrace();
181
		}
182
183
		// do a second pass parse on the bug
184
		List<BugzillaReportNode> l = new ArrayList<BugzillaReportNode>();
185
		l.add(doi);
186
		BugzillaMylarSearchOperation.secondPassBugzillaParser(l);
187
188
		// make sure that we received the right number of stack traces back
189
		// System.out.println("*** REPORT_REPOSITORY " + hit.getId() + " ***");
190
		// System.out.println("NumStackTraces = " +
191
		// doi.getStackTraces().size());
192
		assertEquals("Wrong Number stack traces", numTracesExpected, doi.getStackTraces().size());
193
		if (printStackTraces)
194
			printStackTraces(doi.getStackTraces());
195
	}
196
}
(-)developer/scratch/bugzilla/BugzillaParserTestNoBug.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.tests;
12
13
import java.io.File;
14
import java.io.FileReader;
15
import java.io.Reader;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.mylar.bugzilla.core.BugReport;
21
import org.eclipse.mylar.core.tests.support.FileTool;
22
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
23
24
/**
25
 * Tests for parsing Bugzilla reports
26
 */
27
public class BugzillaParserTestNoBug extends TestCase {
28
29
	public BugzillaParserTestNoBug() {
30
		super();
31
	}
32
33
	public BugzillaParserTestNoBug(String arg0) {
34
		super(arg0);
35
	}
36
37
	public void testBugNotFound() throws Exception {
38
39
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
40
				"testdata/pages/bug-not-found-eclipse.html"));
41
42
		Reader in = new FileReader(f);
43
44
		BugReport bug = BugParser.parseBug(in, 666, "<server>", false, null, null, null);
45
		assertNull(bug);
46
	}
47
}
(-)developer/scratch/bugzilla/BugzillaNewBugParserTestVE.java (+225 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestVE extends TestCase {
33
34
	public BugzillaNewBugParserTestVE() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestVE(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductVE() throws Exception {
43
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/ve-page.html"));
44
45
		Reader in = new FileReader(f);
46
47
		NewBugzillaReport nbm = new NewBugzillaReport();
48
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
49
															// **
50
51
		// attributes for this but model
52
		List<AbstractRepositoryReportAttribute> attributes = nbm.getAttributes();
53
		// printList(attributes);
54
55
		Iterator<AbstractRepositoryReportAttribute> itr = attributes.iterator();
56
		AbstractRepositoryReportAttribute att = itr.next();
57
58
		// Attribute: Severity
59
		assertEquals("Attribute: Severity", "Severity", att.getName());
60
61
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
62
		// options for the
63
		// current
64
		// attribute
65
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
66
		// the options of the
67
		// current attribute
68
		assertEquals("# Severity options", 7, options.length);
69
70
		int i = 0;
71
		while (i < options.length) {
72
			assertEquals("severity options", "blocker", options[i++]);
73
			assertEquals("severity options", "critical", options[i++]);
74
			assertEquals("severity options", "major", options[i++]);
75
			assertEquals("severity options", "normal", options[i++]);
76
			assertEquals("severity options", "minor", options[i++]);
77
			assertEquals("severity options", "trivial", options[i++]);
78
			assertEquals("severity options", "enhancement", options[i++]);
79
		}
80
81
		// Attribute: product
82
		att = itr.next();
83
		assertEquals("Attribute: product", "product", att.getName());
84
85
		attOptions = att.getOptionValues();
86
		options = attOptions.keySet().toArray();
87
		assertEquals("No product options", 0, options.length);
88
89
		// Attribute: AssignedTo
90
		att = itr.next();
91
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
92
93
		attOptions = att.getOptionValues();
94
		options = attOptions.keySet().toArray();
95
		assertEquals("No AssignedTo options", 0, options.length);
96
97
		// Attribute: OS
98
		att = itr.next();
99
		assertEquals("Attribute: OS", "OS", att.getName());
100
101
		attOptions = att.getOptionValues();
102
		options = attOptions.keySet().toArray();
103
		assertEquals("# of options", 20, options.length);
104
105
		i = 0;
106
		while (i < options.length) {
107
			assertEquals("OS options", "All", options[i++]);
108
			assertEquals("OS options", "AIX Motif", options[i++]);
109
			assertEquals("OS options", "Windows 95", options[i++]);
110
			assertEquals("OS options", "Windows 98", options[i++]);
111
			assertEquals("OS options", "Windows CE", options[i++]);
112
			assertEquals("OS options", "Windows ME", options[i++]);
113
			assertEquals("OS options", "Windows 2000", options[i++]);
114
			assertEquals("OS options", "Windows NT", options[i++]);
115
			assertEquals("OS options", "Windows XP", options[i++]);
116
			assertEquals("OS options", "Windows All", options[i++]);
117
			assertEquals("OS options", "MacOS X", options[i++]);
118
			assertEquals("OS options", "Linux", options[i++]);
119
			assertEquals("OS options", "Linux-GTK", options[i++]);
120
			assertEquals("OS options", "Linux-Motif", options[i++]);
121
			assertEquals("OS options", "HP-UX", options[i++]);
122
			assertEquals("OS options", "Neutrino", options[i++]);
123
			assertEquals("OS options", "QNX-Photon", options[i++]);
124
			assertEquals("OS options", "Solaris", options[i++]);
125
			assertEquals("OS options", "Unix All", options[i++]);
126
			assertEquals("OS options", "other", options[i++]);
127
		}
128
129
		// Attribute: Version
130
		att = itr.next();
131
		assertEquals("Attribute: Version", "Version", att.getName());
132
133
		// attOptions = (HashMap) att.getOptionValues();
134
		options = att.getOptionValues().keySet().toArray();
135
		assertEquals("# Version options", 3, options.length);
136
137
		i = 0;
138
		while (i < options.length) {
139
			assertEquals("Version options", "0.5.0", options[i++]);
140
			assertEquals("Version options", "1.0.0", options[i++]);
141
			assertEquals("Version options", "unspecified", options[i++]);
142
		}
143
144
		// Attribute: Platform
145
		att = itr.next();
146
		assertEquals("Attribute: Platform", "Platform", att.getName());
147
148
		options = att.getOptionValues().keySet().toArray();
149
		assertEquals("# Platform options", 6, options.length);
150
151
		i = 0;
152
		while (i < options.length) {
153
			assertEquals("Platform options", "All", options[i++]);
154
			assertEquals("Platform options", "Macintosh", options[i++]);
155
			assertEquals("Platform options", "PC", options[i++]);
156
			assertEquals("Platform options", "Power PC", options[i++]);
157
			assertEquals("Platform options", "Sun", options[i++]);
158
			assertEquals("Platform options", "Other", options[i++]);
159
		}
160
161
		att = itr.next();
162
		assertEquals("Attribute: Component", "Component", att.getName());
163
164
		options = att.getOptionValues().keySet().toArray();
165
		assertEquals("# Component options", 6, options.length);
166
167
		i = 0;
168
		while (i < options.length) {
169
			assertEquals("Component options", "CDE", options[i++]);
170
			assertEquals("Component options", "Doc", options[i++]);
171
			assertEquals("Component options", "Java Core", options[i++]);
172
			assertEquals("Component options", "Java Model (JEM)", options[i++]);
173
			assertEquals("Component options", "JFC/Swing", options[i++]);
174
			assertEquals("Component options", "SWT", options[i++]);
175
		}
176
177
		// Attribute: bug_status
178
		att = itr.next();
179
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
180
181
		options = att.getOptionValues().keySet().toArray();
182
		assertEquals("No bug_status options", 0, options.length);
183
184
		// Attribute: form_name
185
		att = itr.next();
186
		assertEquals("Attribute: form_name", "form_name", att.getName());
187
188
		options = att.getOptionValues().keySet().toArray();
189
		assertEquals("No form_name options", 0, options.length);
190
191
		// Attribute: bug_file_loc
192
		att = itr.next();
193
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
194
195
		options = att.getOptionValues().keySet().toArray();
196
		assertEquals("No bug_file_loc options", 0, options.length);
197
198
		// Attribute: priority
199
		att = itr.next();
200
		assertEquals("Attribute: priority", "priority", att.getName());
201
202
		options = att.getOptionValues().keySet().toArray();
203
		assertEquals("No priority options", 0, options.length);
204
205
	}
206
207
	// private void printList(List<Attribute> attributes) {
208
	//
209
	// Iterator<Attribute> itr = attributes.iterator();
210
	// System.out.println("Attributes for this Product:");
211
	// System.out.println("============================");
212
	//
213
	// while (itr.hasNext()) {
214
	// Attribute attr = itr.next();
215
	// System.out.println();
216
	// System.out.println(attr.getName() + ": ");
217
	// System.out.println("-----------");
218
	//
219
	// Map<String, String> options = attr.getOptionValues();
220
	// Object[] it = options.keySet().toArray();
221
	// for (int i = 0; i < it.length; i++)
222
	// System.out.println((String) it[i]);
223
	// }
224
	// }
225
}
(-)developer/scratch/bugzilla/BugzillaNewBugParserTestPlatform.java (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestPlatform extends TestCase {
33
34
	public BugzillaNewBugParserTestPlatform() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestPlatform(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductPlatform() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(),
45
				new Path("testdata/pages/platform-page.html"));
46
47
		Reader in = new FileReader(f);
48
49
		NewBugzillaReport nbm = new NewBugzillaReport();
50
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
51
															// **
52
53
		// attributes for this bug model
54
		List<AbstractRepositoryReportAttribute> attributes = nbm.getAttributes();
55
		// printList(attributes);
56
57
		// to iterator over the ArrayList of attributes
58
		Iterator<AbstractRepositoryReportAttribute> itr = attributes.iterator();
59
60
		// Attribute: Severity
61
		AbstractRepositoryReportAttribute att = itr.next(); // current attribute
62
63
		// Attribute: Severity
64
		assertEquals("Attribute: Severity", "Severity", att.getName());
65
66
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
67
		// options for the
68
		// current
69
		// attribute
70
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
71
		// the options of the
72
		// current attribute
73
		assertEquals("# Severity options", 7, options.length);
74
75
		int i = 0;
76
		while (i < options.length) {
77
			assertEquals("severity options", "blocker", options[i++]);
78
			assertEquals("severity options", "critical", options[i++]);
79
			assertEquals("severity options", "major", options[i++]);
80
			assertEquals("severity options", "normal", options[i++]);
81
			assertEquals("severity options", "minor", options[i++]);
82
			assertEquals("severity options", "trivial", options[i++]);
83
			assertEquals("severity options", "enhancement", options[i++]);
84
		}
85
86
		// Attribute: product
87
		att = itr.next();
88
		assertEquals("Attribute: product", "product", att.getName());
89
90
		attOptions = att.getOptionValues();
91
		options = attOptions.keySet().toArray();
92
		assertEquals("No product optins", 0, options.length);
93
94
		// Attribute: AssignedTo
95
		att = itr.next();
96
		assertEquals("Attribute: Assigned To", "Assigned To", att.getName());
97
98
		options = att.getOptionValues().keySet().toArray();
99
		assertEquals("No AssingedTo options", 0, options.length);
100
101
		// Attribute: OS
102
		att = itr.next();
103
		assertEquals("Attribute: OS", "OS", att.getName());
104
105
		attOptions = att.getOptionValues();
106
		options = attOptions.keySet().toArray();
107
		assertEquals("# OS options", 20, options.length);
108
109
		i = 0;
110
		while (i < options.length) {
111
			assertEquals("OS options", "All", options[i++]);
112
			assertEquals("OS options", "AIX Motif", options[i++]);
113
			assertEquals("OS options", "Windows 95", options[i++]);
114
			assertEquals("OS options", "Windows 98", options[i++]);
115
			assertEquals("OS options", "Windows CE", options[i++]);
116
			assertEquals("OS options", "Windows ME", options[i++]);
117
			assertEquals("OS options", "Windows 2000", options[i++]);
118
			assertEquals("OS options", "Windows NT", options[i++]);
119
			assertEquals("OS options", "Windows XP", options[i++]);
120
			assertEquals("OS options", "Windows All", options[i++]);
121
			assertEquals("OS options", "MacOS X", options[i++]);
122
			assertEquals("OS options", "Linux", options[i++]);
123
			assertEquals("OS options", "Linux-GTK", options[i++]);
124
			assertEquals("OS options", "Linux-Motif", options[i++]);
125
			assertEquals("OS options", "HP-UX", options[i++]);
126
			assertEquals("OS options", "Neutrino", options[i++]);
127
			assertEquals("OS options", "QNX-Photon", options[i++]);
128
			assertEquals("OS options", "Solaris", options[i++]);
129
			assertEquals("OS options", "Unix All", options[i++]);
130
			assertEquals("OS options", "other", options[i++]);
131
		}
132
133
		// Attribute: Version
134
		att = itr.next();
135
		assertEquals("Attribute: Version", "Version", att.getName());
136
137
		attOptions = att.getOptionValues();
138
		options = attOptions.keySet().toArray();
139
		assertEquals("# Version options", 8, options.length);
140
141
		i = 0;
142
		while (i < options.length) {
143
			assertEquals("Version options", "1.0", options[i++]);
144
			assertEquals("Version options", "2.0", options[i++]);
145
			assertEquals("Version options", "2.0.1", options[i++]);
146
			assertEquals("Version options", "2.0.2", options[i++]);
147
			assertEquals("Version options", "2.1", options[i++]);
148
			assertEquals("Version options", "2.1.1", options[i++]);
149
			assertEquals("Version options", "2.1.2", options[i++]);
150
			assertEquals("Version options", "3.0", options[i++]);
151
		}
152
153
		// Attribute: Platform
154
		att = itr.next();
155
		assertEquals("Attribute: Platform", "Platform", att.getName());
156
157
		options = att.getOptionValues().keySet().toArray();
158
		assertEquals("# Platform options", 6, options.length);
159
160
		i = 0;
161
		while (i < options.length) {
162
			assertEquals("Platform options", "All", options[i++]);
163
			assertEquals("Platform options", "Macintosh", options[i++]);
164
			assertEquals("Platform options", "PC", options[i++]);
165
			assertEquals("Platform options", "Power PC", options[i++]);
166
			assertEquals("Platform options", "Sun", options[i++]);
167
			assertEquals("Platform options", "Other", options[i++]);
168
		}
169
170
		// Attribute: Component
171
		att = itr.next();
172
		assertEquals("Attribute: Component", "Component", att.getName());
173
174
		attOptions = att.getOptionValues();
175
		options = attOptions.keySet().toArray();
176
		assertEquals("# Component options", 16, options.length);
177
178
		i = 0;
179
		while (i < options.length) {
180
			assertEquals("Component options", "Ant", options[i++]);
181
			assertEquals("Component options", "Compare", options[i++]);
182
			assertEquals("Component options", "Core", options[i++]);
183
			assertEquals("Component options", "CVS", options[i++]);
184
			assertEquals("Component options", "Debug", options[i++]);
185
			assertEquals("Component options", "Doc", options[i++]);
186
			assertEquals("Component options", "Help", options[i++]);
187
			assertEquals("Component options", "Releng", options[i++]);
188
			assertEquals("Component options", "Scripting", options[i++]);
189
			assertEquals("Component options", "Search", options[i++]);
190
			assertEquals("Component options", "SWT", options[i++]);
191
			assertEquals("Component options", "Team", options[i++]);
192
			assertEquals("Component options", "Text", options[i++]);
193
			assertEquals("Component options", "UI", options[i++]);
194
			assertEquals("Component options", "Update", options[i++]);
195
			assertEquals("Component options", "WebDAV", options[i++]);
196
		}
197
198
		// Attribute: bug_status
199
		att = itr.next();
200
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
201
202
		attOptions = att.getOptionValues();
203
		options = attOptions.keySet().toArray();
204
		assertEquals("No bug_status options", 0, options.length);
205
206
		// Attribute: form_name
207
		att = itr.next();
208
		assertEquals("Attribute: form_name", "form_name", att.getName());
209
210
		options = att.getOptionValues().keySet().toArray();
211
		assertEquals("No form_name options", 0, options.length);
212
213
		// Attribute: bug_file_loc
214
		att = itr.next();
215
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
216
217
		options = att.getOptionValues().keySet().toArray();
218
		assertEquals("No bug_file_loc options", 0, options.length);
219
220
		// Attribute: priority
221
		att = itr.next();
222
		assertEquals("Attribute: priority", "priority", att.getName());
223
224
		options = att.getOptionValues().keySet().toArray();
225
		assertEquals("No priority options", 0, options.length);
226
	}
227
228
	// private void printList(List<Attribute> attributes) {
229
	//
230
	// Iterator<Attribute> itr = attributes.iterator();
231
	// System.out.println("Attributes for this Product:");
232
	// System.out.println("============================");
233
	//
234
	// while (itr.hasNext()) {
235
	// Attribute attr = itr.next();
236
	// System.out.println();
237
	// System.out.println(attr.getName() + ": ");
238
	// System.out.println("-----------");
239
	//
240
	// Map<String, String> options = attr.getOptionValues();
241
	// Object[] it = options.keySet().toArray();
242
	// for (int i = 0; i < it.length; i++)
243
	// System.out.println((String) it[i]);
244
	// }
245
	// }
246
}
(-)developer/scratch/bugzilla/BugzillaParserTest.java (+196 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.tests;
12
13
import java.io.File;
14
import java.io.FileReader;
15
import java.io.Reader;
16
import java.util.Iterator;
17
18
import junit.framework.TestCase;
19
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.bugzilla.core.Comment;
23
import org.eclipse.mylar.core.tests.support.FileTool;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
25
26
/**
27
 * Tests for parsing Bugzilla reports
28
 */
29
public class BugzillaParserTest extends TestCase {
30
31
	public BugzillaParserTest() {
32
		super();
33
	}
34
35
	public BugzillaParserTest(String arg0) {
36
		super(arg0);
37
	}
38
39
	public void testFullReportBug1() throws Exception {
40
41
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/bug-1-full.html"));
42
43
		Reader in = new FileReader(f);
44
45
		BugReport bug = BugParser.parseBug(in, 1, "<server>", false, null, null, null);
46
47
		// displayBug(bug);
48
		assertEquals("Bug id", 1, bug.getId());
49
		assertEquals("Bug summary", "Usability issue with external editors (1GE6IRL)", bug.getSummary());
50
		assertEquals("Reporter", "andre_weinand@ch.ibm.com (Andre Weinand)", bug.getReporter());
51
		assertEquals("Reporter", "andre_weinand@ch.ibm.com (Andre Weinand)", bug.getAttribute("Reporter").getValue());
52
		assertEquals("Summary", "Usability issue with external editors (1GE6IRL)", bug.getSummary());
53
		assertEquals("Status", "VERIFIED", bug.getStatus());
54
		assertEquals("Resolution", "FIXED", bug.getResolution());
55
		assertEquals("Keywords", null, bug.getKeywords());
56
		assertEquals("Assigned To", "James_Moody@ca.ibm.com (James Moody)", bug.getAssignedTo());
57
		assertEquals("Priority", "P3", bug.getAttribute("Priority").getValue());
58
		assertEquals("OS", "All", bug.getAttribute("OS").getValue());
59
		assertEquals("Version", "2.0", bug.getAttribute("Version").getValue());
60
		assertEquals("Target Milestone", "---", bug.getAttribute("Target Milestone").getValue());
61
		assertEquals("Keywords", "", bug.getAttribute("Keywords").getValue());
62
		assertEquals("Severity", "normal", bug.getAttribute("Severity").getValue());
63
		assertEquals("Component", "VCM", bug.getAttribute("Component").getValue());
64
		assertEquals("CC", "Kevin_McGuire@oti.com", bug.getCC().iterator().next());
65
		assertEquals("Platform", "All", bug.getAttribute("Platform").getValue());
66
		assertEquals("Product", "Platform", bug.getAttribute("Product").getValue());
67
		assertEquals("URL", "", bug.getAttribute("URL").getValue());
68
		assertEquals("Bug#", "1", bug.getAttribute("Bug#").getValue());
69
70
		// Description
71
		String description = "- Setup a project that contains a *.gif resource\n"
72
				+ "\t- release project to CVS\n"
73
				+ "\t- edit the *.gif resource with an external editor, e.g. PaintShop\n"
74
				+ "\t- save and close external editor\n"
75
				+ "\t- in Navigator open the icon resource and verify that your changes are there\n"
76
				+ "\t- release project\n"
77
				+ "\t\t-> nothing to release!\n"
78
				+ "\t- in Navigator open the icon resource and verify that your changes are still there\n\n"
79
				+
80
81
				"\tProblem: because I never \"Refreshed from local\", the workspace hasn't changed so \"Release\" didn't find anything.\n"
82
				+ "\tHowever opening the resource with an external editor found the modified file on disk and showed the changes.\n\n"
83
				+
84
85
				"\tThe real problem occurs if \"Release\" actually finds something to release but you don't spot that some resources are missing.\n"
86
				+ "\tThis is extremely error prone: one of my changes didn't made it into build 110 because of this!\n\n"
87
				+
88
89
				"NOTES:\n"
90
				+ "EG (5/23/01 3:00:33 PM)\n"
91
				+ "\tRelease should do a refresh from local before doing the release.\n"
92
				+ "\tMoving to VCM\n\n\n"
93
				+
94
95
				"KM (05/27/01 5:10:19 PM)\n"
96
				+ "\tComments from JM in related email:\n\n"
97
				+
98
99
				"\tShould not do this for free.  Could have a setting which made it optoinal but should nt be mandatory.  Default setting could be to have it on.\n"
100
				+ "\tConsider the SWT team who keep their workspaces on network drives.  This will be slow.  \n\n"
101
				+
102
103
				"\tSide effects will be that a build runs when the refresh is completed unless you somehow do it in a workspace runnable and don't end the\n"
104
				+ "\trunnable until after the release.  This would be less than optimal as some builders may be responsible for maintaining some invariants and deriving resources which are releasable.  If you don't run the builders before releasing, the invariants will not be maintained and you will release inconsistent state.\n\n"
105
				+
106
107
				"\tSummary:  Offer to \"ensure local consistency\" before releasing.\n\n" +
108
109
				"KM (5/31/01 1:30:35 PM)\n"
110
				+ "\tSee also 1GEAG1A: ITPVCM:WINNT - Internal error comparing with a document\n"
111
				+ "\twhich failed with an error.  Never got log from Tod though.";
112
113
		assert (description.length() == bug.getDescription().length());
114
		assertEquals("Description", description, bug.getDescription());
115
116
		// Comments:
117
		Iterator<Comment> it = bug.getComments().iterator();
118
		while (it.hasNext()) {
119
			// COMMENT #1
120
			Comment comment = it.next();
121
			assertEquals("Author1", "James_Moody@ca.ibm.com", comment.getAuthor());
122
			assertEquals("Name1", "James Moody", comment.getAuthorName());
123
			assertEquals("Text1", "*** Bug 183 has been marked as a duplicate of this bug. ***", comment.getText());
124
125
			// COMMENT #2
126
			comment = it.next();
127
			assertEquals("Author2", "James_Moody@ca.ibm.com", comment.getAuthor());
128
			assertEquals("Name2", "James Moody", comment.getAuthorName());
129
			assertEquals("Text2", "Implemented 'auto refresh' option. Default value is off.", comment.getText());
130
131
			// COMMENT 3
132
			comment = it.next();
133
			assertEquals("Author3", "dj_houghton@ca.ibm.com", comment.getAuthor());
134
			assertEquals("Name3", "DJ Houghton", comment.getAuthorName());
135
			assertEquals("Text3", "PRODUCT VERSION:\n\t109\n\n", comment.getText());
136
137
			// COMMENT 4
138
			comment = it.next();
139
			assertEquals("Author4", "James_Moody@ca.ibm.com", comment.getAuthor());
140
			assertEquals("Name4", "James Moody", comment.getAuthorName());
141
			assertEquals("Text4", "Fixed in v206", comment.getText());
142
		}
143
	}
144
145
	// private static void displayBug(BugReport bug) {
146
	// System.out.println("Bug " + bug.getId() + ": " + bug.getSummary());
147
	// System.out.println("Opened: " + bug.getCreated());
148
	// for (Iterator<Attribute> it = bug.getAttributes().iterator();
149
	// it.hasNext();) {
150
	// Attribute attribute = it.next();
151
	// String key = attribute.getName();
152
	// System.out.println(key + ": " + attribute.getValue()
153
	// + (attribute.isEditable() ? " [OK]" : " %%"));
154
	// }
155
	//
156
	// System.out.print("CC: ");
157
	// for (Iterator<String> it = bug.getCC().iterator(); it.hasNext();) {
158
	// String email = it.next();
159
	// System.out.print(email + " ");
160
	// }
161
	// System.out.println();
162
	//
163
	// System.out.println(bug.getDescription());
164
	// for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();)
165
	// {
166
	// Comment comment = it.next();
167
	// System.out.println(comment.getAuthorName() + " <"
168
	// + comment.getAuthor() + "> (" + comment.getCreated() + ")");
169
	// System.out.print(comment.getText());
170
	// System.out.println();
171
	// }
172
	// }
173
	//
174
	// private static void printComments(BugReport bug) {
175
	// for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();)
176
	// {
177
	// Comment comment = it.next();
178
	// System.out.println("Author: " + comment.getAuthor());
179
	// System.out.println("Name: " + comment.getAuthorName());
180
	// System.out.println("Date: " + comment.getCreated());
181
	// System.out.println("Bug ID: " + comment.getBug().getId());
182
	// System.out.println("Comment: " + comment.getText());
183
	// System.out.println();
184
	// }
185
	// }
186
	//
187
	// /** prints names of attributes */
188
	// private static void printAttributes(BugReport bug) {
189
	// System.out.println("ATTRIBUTE KEYS:");
190
	// for (Iterator<Attribute> it = bug.getAttributes().iterator();
191
	// it.hasNext();) {
192
	// Attribute att = it.next();
193
	// System.out.println(att.getName());
194
	// }
195
	// }
196
}
(-)developer/scratch/bugzilla/Bugzilla220ParserTest.java (+92 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
18
import junit.framework.TestCase;
19
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.core.tests.support.FileTool;
23
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
27
28
/**
29
 * @author Mik Kersten
30
 * @author Rob Elves
31
 */
32
public class Bugzilla220ParserTest extends TestCase {
33
34
	public static final String TEST_SERVER = IBugzillaConstants.ECLIPSE_BUGZILLA_URL;
35
	
36
	private static final String PRODUCT_MYLAR = "Mylar";
37
38
	private static final String PRODUCT_TEST = "TestProduct";
39
40
	public void testId220() throws Exception {
41
42
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
43
				"testdata/pages/test-report-220.html"));
44
		Reader in = new FileReader(f);
45
46
		BugReport bug = BugParser.parseBug(in, 7, TEST_SERVER, false, null, null, null);
47
48
		assertEquals(7, bug.getId());
49
		assertEquals("summary", bug.getSummary());
50
		assertEquals("7", bug.getAttribute("Bug#").getValue());
51
		assertEquals("7", bug.getAttribute("id").getValue());
52
	}
53
54
	public void testId2201() throws Exception {
55
56
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
57
				"testdata/pages/test-report-2201.html"));
58
		Reader in = new FileReader(f);
59
60
		BugReport bug = BugParser.parseBug(in, 125527, TEST_SERVER, false, null, null, null);
61
62
		assertEquals(125527, bug.getId());
63
		assertEquals("bugzilla refresh incorrect for new reports and newly opened hits", bug.getSummary());
64
		assertEquals("125527", bug.getAttribute("Bug#").getValue());
65
		assertEquals("125527", bug.getAttribute("id").getValue());
66
	}
67
68
	public void testNewBugProduct220() throws Exception {
69
70
		NewBugzillaReport nbm = new NewBugzillaReport();
71
72
		File f = FileTool
73
				.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/enter-bug220.html"));
74
		Reader in = new FileReader(f);
75
76
		new NewBugParser(in).parseBugAttributes(nbm, true);
77
		assertEquals(PRODUCT_TEST, nbm.getAttribute("product").getValue());
78
	}
79
80
	public void testNewBugProduct2201() throws Exception {
81
82
		NewBugzillaReport nbm = new NewBugzillaReport();
83
84
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(),
85
				new Path("testdata/pages/enter-bug2201.html"));
86
		Reader in = new FileReader(f);
87
88
		new NewBugParser(in).parseBugAttributes(nbm, true);
89
		assertEquals(PRODUCT_MYLAR, nbm.getAttribute("product").getValue());
90
	}
91
92
}
(-)developer/scratch/bugzilla/BugzillaStackTraceTest.java (+196 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
////Created on Oct 12, 2004
12
package org.eclipse.mylar.tests.misc;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import junit.framework.TestCase;
21
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.mylar.bugzilla.tests.BugzillaTestPlugin;
24
import org.eclipse.mylar.core.tests.support.FileTool;
25
import org.eclipse.mylar.internal.bugs.search.BugzillaMylarSearchOperation;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
27
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchHit;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaReportNode;
29
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.StackTrace;
30
31
/**
32
 * Class to test the Bridge methods that do not require server queries
33
 * 
34
 * @author Shawn Minto
35
 */
36
public class BugzillaStackTraceTest extends TestCase {
37
38
	private static final String TEST_FILE_LOC = "testdata/reports-stacktrace/";
39
40
	private static final String BUGZILLA_SERVER_NAME = "https://bugs.eclipse.org/bugs";
41
42
	/**
43
	 * Test that the regular expression escaping mechanism works properly
44
	 */
45
	public void testREGEX() {
46
		String r = ".*+(){}[]^$|?/\\";
47
		String r2 = StackTrace.escapeForRegex(r);
48
		String ans = "\\.\\*\\+\\(\\)\\{\\}\\[\\]\\^\\$\\|\\?\\/\\\\";
49
		String msg = "Regular Expression matching wrong:\nwas: " + r2 + "\nshould be:" + ans;
50
		assertTrue(msg, r2.equals(ans));
51
	}
52
53
	// /**
54
	// * Test parsing the bug for multiple stacks in in
55
	// */
56
	// public void testMultipleStacksDiffComments(){
57
	// // REPORT_REPOSITORY 4862 - 2 stack traces - 1 in description, 1 in
58
	// comment - text
59
	// before and after
60
	// performParse(4862, "4862.html", 2, false);
61
	// }
62
63
	// /**
64
	// * Test parsing the bug for a single stack in the description with some
65
	// * text before it
66
	// */
67
	// public void testSingleStackCodeBeforeInDescription(){
68
	// // REPORT_REPOSITORY 76388 - 1 stack trace - description - text before
69
	// and formatted
70
	// ugly
71
	// performParse(76388, "76388.html", 1, false);
72
	// }
73
74
	/**
75
	 * Test parsing the bug for a single stack trace in the description with
76
	 * text before and after it
77
	 */
78
	public void testSingleStackCodeBeforeAndAfterInDescription() {
79
80
		// REPORT_REPOSITORY 76146 - 1 stack trace - description - text before
81
		// and code after
82
		performParse(76146, "76146.html", 1, false);
83
	}
84
85
	/**
86
	 * Test parsing a bug that has 1 stack trace in the description with no
87
	 * extra text, but has lines in it that span 3 lines
88
	 */
89
	public void testSingleStackPoorFormatInDescription() {
90
		// REPORT_REPOSITORY 67395 - 1 stack trace - description - no extra
91
		// text, 1 at line
92
		// spans 3 lines
93
		performParse(67395, "67395.html", 1, false);
94
	}
95
96
	/**
97
	 * Test parsing a bug with no stack traces and no qualified exception names
98
	 */
99
	public void testNoStackNoQualified() {
100
		// REPORT_REPOSITORY 4548 - no stack traces, no qualified reference to
101
		// an exception
102
		performParse(4548, "4548.html", 0, false);
103
	}
104
105
	/**
106
	 * Test parsing a bug with no stack traces, but a qualified reference to an
107
	 * exception
108
	 */
109
	public void testNoStackQual() {
110
		// REPORT_REPOSITORY 1 - no stack traces, qualified reference to
111
		// exception - made up
112
		// bug
113
		performParse(1, "1.html", 0, false);
114
	}
115
116
	/**
117
	 * Test parsing of a bug with 1 stack trace and multiple qualified
118
	 * references
119
	 */
120
	public void testSingleStackQual() {
121
		// REPORT_REPOSITORY 2 - 1 stack trace- 2 qual ref, stack trace, 1 qual
122
		// ref - made up
123
		// bug
124
		performParse(2, "2.html", 1, false);
125
	}
126
127
	/**
128
	 * Test parsing of a bug with many stacks traces in a single comment
129
	 */
130
	public void testMultipleStackSingleComment() {
131
		// REPORT_REPOSITORY 40152 - 1 stack trace- 2 qual ref, stack trace, 1
132
		// qual ref - made
133
		// up bug
134
		performParse(40152, "40152.html", 33, false);
135
	}
136
137
	/**
138
	 * Print out the stack traces
139
	 * 
140
	 * @param l
141
	 *            List of stack traces
142
	 */
143
	private void printStackTraces(List<StackTrace> l) {
144
		System.out.println("\n\n");
145
		for (int i = 0; i < l.size(); i++) {
146
			StackTrace trace = l.get(i);
147
			System.out.println("*****************?????????????????*****************\n");
148
			System.out.println("OFFSET: " + trace.getOffset() + " LENGTH: " + trace.getLength());
149
			System.out.println(trace.getStackTrace());
150
			System.out.println("*****************?????????????????*****************\n\n");
151
		}
152
	}
153
154
	private void performParse(int bugNumber, String bugFileName, int numTracesExpected, boolean printStackTraces) {
155
156
		BugzillaSearchHit hit = new BugzillaSearchHit("<TEST-SERVER>", bugNumber, "", "", "", "", "", "", "", ""); // stack
157
		// trace
158
		// in
159
		// desc
160
		// and
161
		// com
162
163
		// create a new doi info
164
		BugzillaReportNode doi = new BugzillaReportNode(0, hit, false);
165
		try {
166
167
			// read the bug in from a file
168
			File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(TEST_FILE_LOC + bugFileName)); // used
169
			// if
170
			// run
171
			// as a
172
			// plugin
173
			// test
174
			// File f = new File(TEST_FILE_LOC+bugFileName); // used if run as a
175
			// standalone test
176
			Reader reader = new FileReader(f);
177
			doi.setBug(BugParser.parseBug(reader, hit.getId(), BUGZILLA_SERVER_NAME, true, null, null, null));
178
			reader.close();
179
		} catch (Exception e) {
180
			e.printStackTrace();
181
		}
182
183
		// do a second pass parse on the bug
184
		List<BugzillaReportNode> l = new ArrayList<BugzillaReportNode>();
185
		l.add(doi);
186
		BugzillaMylarSearchOperation.secondPassBugzillaParser(l);
187
188
		// make sure that we received the right number of stack traces back
189
		// System.out.println("*** REPORT_REPOSITORY " + hit.getId() + " ***");
190
		// System.out.println("NumStackTraces = " +
191
		// doi.getStackTraces().size());
192
		assertEquals("Wrong Number stack traces", numTracesExpected, doi.getStackTraces().size());
193
		if (printStackTraces)
194
			printStackTraces(doi.getStackTraces());
195
	}
196
}
(-)developer/scratch/bugzilla/BugzillaNewBugParserTestCDT.java (+213 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes for new bug reports
31
 */
32
public class BugzillaNewBugParserTestCDT extends TestCase {
33
34
	public BugzillaNewBugParserTestCDT() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestCDT(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductCDT() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/cdt-page.html"));
45
46
		Reader in = new FileReader(f);
47
48
		NewBugzillaReport nbm = new NewBugzillaReport();
49
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
50
															// **
51
52
		// attributes for this bug model
53
		List<AbstractRepositoryReportAttribute> attributes = nbm.getAttributes();
54
		// printList(attributes);
55
56
		Iterator<AbstractRepositoryReportAttribute> itr = attributes.iterator();
57
		AbstractRepositoryReportAttribute att = itr.next();
58
59
		// Attribute: Severity
60
		assertEquals("Attribute: Severity", "Severity", att.getName());
61
62
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
63
		// options for the
64
		// current
65
		// attribute
66
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
67
		// the options of the
68
		// current attribute
69
		assertEquals("# Severity options", 7, options.length);
70
71
		int i = 0;
72
		while (i < options.length) {
73
			assertEquals("severity options", "blocker", options[i++]);
74
			assertEquals("severity options", "critical", options[i++]);
75
			assertEquals("severity options", "major", options[i++]);
76
			assertEquals("severity options", "normal", options[i++]);
77
			assertEquals("severity options", "minor", options[i++]);
78
			assertEquals("severity options", "trivial", options[i++]);
79
			assertEquals("severity options", "enhancement", options[i++]);
80
		}
81
82
		// Attribute: product
83
		att = itr.next();
84
		assertEquals("Attribute: product", "product", att.getName());
85
86
		attOptions = att.getOptionValues();
87
		options = attOptions.keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		attOptions = att.getOptionValues();
95
		options = attOptions.keySet().toArray();
96
		assertEquals("No AssignedTo options", 0, options.length);
97
98
		// Attribute: OS
99
		att = itr.next();
100
		assertEquals("Attribute: OS", "OS", att.getName());
101
102
		attOptions = att.getOptionValues();
103
		options = attOptions.keySet().toArray();
104
		assertEquals("# of options", 20, options.length);
105
106
		i = 0;
107
		while (i < options.length) {
108
			assertEquals("OS options", "All", options[i++]);
109
			assertEquals("OS options", "AIX Motif", options[i++]);
110
			assertEquals("OS options", "Windows 95", options[i++]);
111
			assertEquals("OS options", "Windows 98", options[i++]);
112
			assertEquals("OS options", "Windows CE", options[i++]);
113
			assertEquals("OS options", "Windows ME", options[i++]);
114
			assertEquals("OS options", "Windows 2000", options[i++]);
115
			assertEquals("OS options", "Windows NT", options[i++]);
116
			assertEquals("OS options", "Windows XP", options[i++]);
117
			assertEquals("OS options", "Windows All", options[i++]);
118
			assertEquals("OS options", "MacOS X", options[i++]);
119
			assertEquals("OS options", "Linux", options[i++]);
120
			assertEquals("OS options", "Linux-GTK", options[i++]);
121
			assertEquals("OS options", "Linux-Motif", options[i++]);
122
			assertEquals("OS options", "HP-UX", options[i++]);
123
			assertEquals("OS options", "Neutrino", options[i++]);
124
			assertEquals("OS options", "QNX-Photon", options[i++]);
125
			assertEquals("OS options", "Solaris", options[i++]);
126
			assertEquals("OS options", "Unix All", options[i++]);
127
			assertEquals("OS options", "other", options[i++]);
128
		}
129
130
		// Attribute: Version
131
		att = itr.next();
132
		assertEquals("Attribute: Version", "Version", att.getName());
133
134
		// attOptions = (HashMap) att.getOptionValues();
135
		options = att.getOptionValues().keySet().toArray();
136
		assertEquals("# Version options", 5, options.length);
137
138
		i = 0;
139
		while (i < options.length) {
140
			assertEquals("Version options", "1.0", options[i++]);
141
			assertEquals("Version options", "1.0.1", options[i++]);
142
			assertEquals("Version options", "1.1", options[i++]);
143
			assertEquals("Version options", "1.2", options[i++]);
144
			assertEquals("Version options", "2.0", options[i++]);
145
		}
146
147
		// Attribute: Platform
148
		att = itr.next();
149
		assertEquals("Attribute: Platform", "Platform", att.getName());
150
151
		options = att.getOptionValues().keySet().toArray();
152
		assertEquals("# Platform options", 6, options.length);
153
154
		i = 0;
155
		while (i < options.length) {
156
			assertEquals("Platform options", "All", options[i++]);
157
			assertEquals("Platform options", "Macintosh", options[i++]);
158
			assertEquals("Platform options", "PC", options[i++]);
159
			assertEquals("Platform options", "Power PC", options[i++]);
160
			assertEquals("Platform options", "Sun", options[i++]);
161
			assertEquals("Platform options", "Other", options[i++]);
162
		}
163
164
		// Attribute: Component
165
		att = itr.next();
166
		assertEquals("Attribute: Component", "Component", att.getName());
167
168
		options = att.getOptionValues().keySet().toArray();
169
		assertEquals("# Component options", 9, options.length);
170
171
		i = 0;
172
		while (i < options.length) {
173
			assertEquals("Component options", "CDT-parser", options[i++]);
174
			assertEquals("Component options", "Core", options[i++]);
175
			assertEquals("Component options", "Cpp-Extensions", options[i++]);
176
			assertEquals("Component options", "Debug", options[i++]);
177
			assertEquals("Component options", "Debug-MI", options[i++]);
178
			assertEquals("Component options", "Doc", options[i++]);
179
			assertEquals("Component options", "Generic-Extensions", options[i++]);
180
			assertEquals("Component options", "Launcher", options[i++]);
181
			assertEquals("Component options", "UI", options[i++]);
182
		}
183
184
		// Attribute: bug_status
185
		att = itr.next();
186
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
187
188
		options = att.getOptionValues().keySet().toArray();
189
		assertEquals("# bug_status options [none]", 0, options.length);
190
191
		// Attribute: form_name
192
		att = itr.next();
193
		assertEquals("Attribute: form_name", "form_name", att.getName());
194
195
		options = att.getOptionValues().keySet().toArray();
196
		assertEquals("No form_name options", 0, options.length);
197
198
		// Attribute: bug_file_loc
199
		att = itr.next();
200
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
201
202
		options = att.getOptionValues().keySet().toArray();
203
		assertEquals("No bug_file_loc options", 0, options.length);
204
205
		// Attribute: priority
206
		att = itr.next();
207
		assertEquals("Attribute: priority", "priority", att.getName());
208
209
		options = att.getOptionValues().keySet().toArray();
210
		assertEquals("No priority options", 0, options.length);
211
212
	}
213
}
(-)developer/scratch/bugzilla/NewBugParser.java (+427 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.bugzilla.core.internal;
13
14
import java.io.IOException;
15
import java.io.Reader;
16
import java.text.ParseException;
17
18
import javax.security.auth.login.LoginException;
19
20
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
21
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
22
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
23
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
24
25
/**
26
 * @author Shawn Minto
27
 * 
28
 * This class parses the valid attribute values for a new bug
29
 */
30
class NewBugParser {
31
	/** Tokenizer used on the stream */
32
	private HtmlStreamTokenizer tokenizer;
33
34
	/** Flag for whether we need to try to get the product or not */
35
	private static boolean getProd = false;
36
37
	public NewBugParser(Reader in) {
38
		tokenizer = new HtmlStreamTokenizer(in, null);
39
	}
40
41
	/**
42
	 * Parse the new bugs valid attributes
43
	 * 
44
	 * @param nbm
45
	 *            A reference to a NewBugModel where all of the information is
46
	 *            stored
47
	 * @throws IOException
48
	 * @throws ParseException
49
	 * @throws LoginException
50
	 */
51
	public void parseBugAttributes(NewBugzillaReport nbm, boolean retrieveProducts) throws IOException, ParseException,
52
			LoginException {
53
		nbm.attributes.clear(); // clear any attriubtes in bug model from a
54
		// previous product
55
56
		NewBugParser.getProd = retrieveProducts;
57
58
		// create a new bug report and set the parser state to the start state
59
		ParserState state = ParserState.START;
60
		String attribute = null;
61
62
		boolean isTitle = false;
63
		boolean possibleBadLogin = false;
64
		boolean isErrorState = false;
65
		String title = "";
66
		// Default error message
67
		String errorMsg = "Bugzilla could not get the needed bug attribute since your login name or password is incorrect.  Please check your settings in the bugzilla preferences.";
68
69
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
70
			// make sure that bugzilla doesn't want us to login
71
			if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
72
					&& !((HtmlTag) (token.getValue())).isEndTag()) {
73
				isTitle = true;
74
				continue;
75
			}
76
77
			if (isTitle) {
78
				// get all of the data in the title tag to compare with
79
				if (token.getType() != Token.TAG) {
80
					title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
81
					continue;
82
				} else if (token.getType() == Token.TAG
83
						&& ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
84
						&& ((HtmlTag) token.getValue()).isEndTag()) {
85
					// check if the title looks like we may have a problem with
86
					// login
87
					if (title.indexOf("login") != -1) {
88
						possibleBadLogin = true; // generic / default msg
89
						// passed to constructor re:
90
						// bad login
91
					}
92
					if ((title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
93
							|| title.indexOf("check e-mail") != -1 || title.indexOf("error") != -1) {
94
						possibleBadLogin = true;
95
						isErrorState = true; // set flag so appropriate msg
96
						// is provide for the exception
97
						errorMsg = ""; // error message will be parsed from
98
						// error page
99
					}
100
101
					isTitle = false;
102
					title = "";
103
				}
104
				continue;
105
			}
106
107
			// we have found the start of an attribute name
108
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
109
				HtmlTag tag = (HtmlTag) token.getValue();				
110
				if (tag.getTagType() == HtmlTag.Type.TD && "right".equalsIgnoreCase(tag.getAttribute("align"))) {
111
					// parse the attribute's name
112
					attribute = parseAttributeName();
113
					if(attribute != null && attribute.contains(IBugzillaConstants.INVALID_2201_ATTRIBUTE_IGNORED)) {
114
						continue;
115
					}					
116
					if (attribute == null)
117
						continue;
118
					state = ParserState.ATT_VALUE;
119
					continue;
120
				}
121
122
				if (tag.getTagType() == HtmlTag.Type.TD && "#ff0000".equalsIgnoreCase(tag.getAttribute("bgcolor"))) {
123
					state = ParserState.ERROR;
124
					continue;
125
				}
126
			}
127
128
			// we have found the start of attribute values
129
			if (state == ParserState.ATT_VALUE && token.getType() == Token.TAG) {
130
				HtmlTag tag = (HtmlTag) token.getValue();
131
				if (tag.getTagType() == HtmlTag.Type.TD) {
132
					// parse the attribute values
133
					parseAttributeValue(nbm, attribute);
134
135
					state = ParserState.ATT_NAME;
136
					attribute = null;
137
					continue;
138
				}
139
			}
140
			// page being parsed contains an Error message
141
			// parse error message so it can be given to the constructor of the
142
			// exception
143
			// so an appropriate error message is displayed
144
			if (state == ParserState.ERROR && isErrorState) {
145
				// tag should be text token, not a tag
146
				// get the error message
147
				if (token.getType() == Token.TEXT) {
148
					// get string value of next token to add to error messgage
149
					// unescape the string so any escape sequences parsed appear
150
					// unescaped in the details pane
151
					errorMsg += HtmlStreamTokenizer.unescape(((StringBuffer) token.getValue()).toString()) + " ";
152
				}
153
				// expect </font> tag to indicate end of error end msg
154
				// set next state to continue parsing remainder of page
155
				else if (token.getType() == Token.TAG
156
						&& ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.FONT
157
						&& ((HtmlTag) (token.getValue())).isEndTag()) {
158
					state = ParserState.ATT_NAME;
159
				}
160
				continue;
161
			}
162
163
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
164
				HtmlTag tag = (HtmlTag) token.getValue();
165
				if (tag.getTagType() == HtmlTag.Type.INPUT && tag.getAttribute("type") != null
166
						&& "hidden".equalsIgnoreCase(tag.getAttribute("type").trim())) {
167
					AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(tag.getAttribute("name"));
168
					a.setID(tag.getAttribute("name"));
169
					a.setValue(tag.getAttribute("value"));
170
					a.setHidden(true);
171
					nbm.attributes.put(a.getName(), a);
172
					continue;
173
				}
174
			}
175
		}
176
177
		if (possibleBadLogin && (nbm.getAttributes() == null || nbm.getAttributes().size() == 0)) {
178
			throw new LoginException(errorMsg);
179
		}
180
	}
181
182
	/**
183
	 * Parse the case where we have found an attribute name
184
	 * 
185
	 * @param tokenizer
186
	 *            The tokenizer to use to find the name
187
	 * @return The name of the attribute
188
	 * @throws IOException
189
	 * @throws ParseException
190
	 */
191
	private String parseAttributeName() throws IOException, ParseException {
192
		StringBuffer sb = new StringBuffer();
193
194
		parseTableCell(sb);
195
		HtmlStreamTokenizer.unescape(sb);
196
		// remove the colon if there is one
197
		if (sb.length() == 0)
198
			return null;
199
		if (sb.charAt(sb.length() - 1) == ':') {
200
			sb.deleteCharAt(sb.length() - 1);
201
		}
202
		return sb.toString();
203
	}
204
205
	/**
206
	 * Reads text into a StringBuffer until it encounters a close table cell tag
207
	 * (&lt;/TD&gt;) or start of another cell. The text is appended to the
208
	 * existing value of the buffer. <b>NOTE:</b> Does not handle nested cells!
209
	 * 
210
	 * @param tokenizer
211
	 * @param sb
212
	 * @throws IOException
213
	 * @throws ParseException
214
	 */
215
	private void parseTableCell(StringBuffer sb) throws IOException, ParseException {
216
		boolean noWhitespace = false;
217
		for (HtmlStreamTokenizer.Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer
218
				.nextToken()) {
219
			if (token.getType() == Token.TAG) {
220
				HtmlTag tag = (HtmlTag) token.getValue();
221
				if (tag.getTagType() == HtmlTag.Type.TD) {
222
					if (!tag.isEndTag()) {
223
						tokenizer.pushback(token);
224
					}
225
					break;
226
				}
227
				noWhitespace = token.getWhitespace().length() == 0;
228
			} else if (token.getType() == Token.TEXT) {
229
				// if there was no whitespace between the tag and the
230
				// preceding text, don't insert whitespace before this text
231
				// unless it is there in the source
232
				if (!noWhitespace && token.getWhitespace().length() > 0 && sb.length() > 0) {
233
					sb.append(' ');
234
				}
235
				sb.append((StringBuffer) token.getValue());
236
			}
237
		}
238
	}
239
240
	/**
241
	 * Parse the case where we have found attribute values
242
	 * 
243
	 * @param nbm
244
	 *            The NewBugModel that is to contain information about a new bug
245
	 * @param attributeName
246
	 *            The name of the attribute that we are parsing
247
	 * @param tokenizer
248
	 *            The tokenizer to use for parsing
249
	 * @throws IOException
250
	 * @throws ParseException
251
	 */
252
	private void parseAttributeValue(NewBugzillaReport nbm, String attributeName) throws IOException, ParseException {
253
254
		HtmlStreamTokenizer.Token token = tokenizer.nextToken();
255
		if (token.getType() == Token.TAG) {
256
			HtmlTag tag = (HtmlTag) token.getValue();
257
			if (tag.getTagType() == HtmlTag.Type.SELECT && !tag.isEndTag()) {
258
				String parameterName = tag.getAttribute("name");
259
				parseSelect(nbm, attributeName, parameterName);
260
			} else if (tag.getTagType() == HtmlTag.Type.INPUT && !tag.isEndTag()) {
261
				parseInput(nbm, attributeName, tag);
262
			} else if (!tag.isEndTag()) {
263
				parseAttributeValueCell(nbm, attributeName);
264
			}
265
		} else {
266
			StringBuffer sb = new StringBuffer();
267
			if (token.getType() == Token.TEXT) {
268
				sb.append((StringBuffer) token.getValue());
269
				parseAttributeValueCell(nbm, attributeName, sb);
270
			}
271
		}
272
	}
273
274
	/**
275
	 * Parse the case where the attribute value is just text in a table cell
276
	 * 
277
	 * @param attributeName
278
	 *            The name of the attribute we are parsing
279
	 * @param tokenizer
280
	 *            The tokenizer to use for parsing
281
	 * @throws IOException
282
	 * @throws ParseException
283
	 */
284
	private void parseAttributeValueCell(NewBugzillaReport nbm, String attributeName) throws IOException, ParseException {
285
		StringBuffer sb = new StringBuffer();
286
287
		parseAttributeValueCell(nbm, attributeName, sb);
288
	}
289
290
	private void parseAttributeValueCell(NewBugzillaReport nbm, String attributeName, StringBuffer sb) throws IOException,
291
			ParseException {
292
293
		parseTableCell(sb);
294
		HtmlStreamTokenizer.unescape(sb);
295
296
		// if we need the product we will get it
297
		if (getProd && attributeName.equalsIgnoreCase("product")) {
298
			nbm.setProduct(sb.toString());
299
		}
300
	}
301
302
	/**
303
	 * Parse the case where the attribute value is an input
304
	 * 
305
	 * @param nbm
306
	 *            The new bug model to add information that we get to
307
	 * @param attributeName
308
	 *            The name of the attribute that we are parsing
309
	 * @param tag
310
	 *            The HTML tag that we are currently on
311
	 * @throws IOException
312
	 */
313
	private static void parseInput(NewBugzillaReport nbm, String attributeName, HtmlTag tag) throws IOException {
314
315
		AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
316
		a.setID(tag.getAttribute("name"));
317
		String value = tag.getAttribute("value");
318
		if (value == null)
319
			value = "";
320
321
		// if we found the summary, add it to the bug report
322
		if (attributeName.equalsIgnoreCase("summary")) {
323
			nbm.setSummary(value);
324
		} else if (attributeName.equalsIgnoreCase("Attachments")) {
325
			// do nothing - not a problem after 2.14
326
		} else if (attributeName.equalsIgnoreCase("add cc")) {
327
			// do nothing
328
		} else if (attributeName.toLowerCase().startsWith("cc")) {
329
			// do nothing cc's are options not inputs
330
		} else {
331
			// otherwise just add the attribute
332
			a.setValue(value);
333
			nbm.attributes.put(attributeName, a);
334
		}
335
	}
336
337
	/**
338
	 * Parse the case where the attribute value is an option
339
	 * 
340
	 * @param nbm
341
	 *            The NewBugModel that we are storing information in
342
	 * @param attributeName
343
	 *            The name of the attribute that we are parsing
344
	 * @param parameterName
345
	 *            The SELECT tag's name
346
	 * @param tokenizer
347
	 *            The tokenizer that we are using for parsing
348
	 * @throws IOException
349
	 * @throws ParseException
350
	 */
351
	private void parseSelect(NewBugzillaReport nbm, String attributeName, String parameterName) throws IOException,
352
			ParseException {
353
354
		boolean first = false;
355
		AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
356
		a.setID(parameterName);
357
358
		HtmlStreamTokenizer.Token token = tokenizer.nextToken();
359
		while (token.getType() != Token.EOF) {
360
			if (token.getType() == Token.TAG) {
361
				HtmlTag tag = (HtmlTag) token.getValue();
362
				if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
363
					break;
364
				if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
365
					String optionName = tag.getAttribute("value");
366
					boolean selected = tag.hasAttribute("selected");
367
					StringBuffer optionText = new StringBuffer();
368
					for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer.nextToken()) {
369
						if (optionText.length() > 0) {
370
							optionText.append(' ');
371
						}
372
						optionText.append((StringBuffer) token.getValue());
373
					}
374
					a.addOptionValue(optionText.toString(), optionName);
375
376
					if (selected || first) {
377
						a.setValue(optionText.toString());
378
						first = false;
379
					}
380
				} else {
381
					token = tokenizer.nextToken();
382
				}
383
			} else {
384
				token = tokenizer.nextToken();
385
			}
386
		}
387
388
		if (!(nbm.attributes).containsKey(attributeName)) {
389
			(nbm.attributes).put(attributeName, a);
390
		}
391
	}
392
393
	/**
394
	 * Enum class for describing current state of Bugzilla report parser.
395
	 */
396
	private static class ParserState {
397
		/** An instance of the start state */
398
		protected static final ParserState START = new ParserState("start");
399
400
		/** An instance of the state when the parser found an attribute name */
401
		protected static final ParserState ATT_NAME = new ParserState("att_name");
402
403
		/** An instance of the state when the parser found an attribute value */
404
		protected static final ParserState ATT_VALUE = new ParserState("att_value");
405
406
		/** An instance of the state when an error page is found */
407
		protected static final ParserState ERROR = new ParserState("error");
408
409
		/** State's human-readable name */
410
		private String name;
411
412
		/**
413
		 * Constructor
414
		 * 
415
		 * @param description -
416
		 *            The states human readable name
417
		 */
418
		private ParserState(String description) {
419
			this.name = description;
420
		}
421
422
		@Override
423
		public String toString() {
424
			return name;
425
		}
426
	}
427
}
(-)developer/scratch/bugzilla/BugzillaNewBugParserTestGMT.java (+219 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestGMT extends TestCase {
33
34
	public BugzillaNewBugParserTestGMT() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestGMT(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductGMT() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/gmt-page.html"));
45
46
		Reader in = new FileReader(f);
47
48
		NewBugzillaReport nbm = new NewBugzillaReport();
49
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
50
															// **
51
52
		// attributes for this bug model
53
		List<AbstractRepositoryReportAttribute> attributes = nbm.getAttributes();
54
		// printList(attributes);
55
56
		Iterator<AbstractRepositoryReportAttribute> itr = attributes.iterator();
57
		AbstractRepositoryReportAttribute att = itr.next();
58
59
		// Attribute: Severity
60
		assertEquals("Attribute: Severity", "Severity", att.getName());
61
62
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
63
		// options for the
64
		// current
65
		// attribute
66
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
67
		// the options of the
68
		// current attribute
69
		assertEquals("# Severity options", 7, options.length);
70
71
		int i = 0;
72
		while (i < options.length) {
73
			assertEquals("severity options", "blocker", options[i++]);
74
			assertEquals("severity options", "critical", options[i++]);
75
			assertEquals("severity options", "major", options[i++]);
76
			assertEquals("severity options", "normal", options[i++]);
77
			assertEquals("severity options", "minor", options[i++]);
78
			assertEquals("severity options", "trivial", options[i++]);
79
			assertEquals("severity options", "enhancement", options[i++]);
80
		}
81
82
		// Attribute: product
83
		att = itr.next();
84
		assertEquals("Attribute: product", "product", att.getName());
85
86
		attOptions = att.getOptionValues();
87
		options = attOptions.keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		attOptions = att.getOptionValues();
95
		options = attOptions.keySet().toArray();
96
		assertEquals("No AssignedTo options", 0, options.length);
97
98
		// Attribute: OS
99
		att = itr.next();
100
		assertEquals("Attribute: OS", "OS", att.getName());
101
102
		attOptions = att.getOptionValues();
103
		options = attOptions.keySet().toArray();
104
		assertEquals("# of options", 20, options.length);
105
106
		i = 0;
107
		while (i < options.length) {
108
			assertEquals("OS options", "All", options[i++]);
109
			assertEquals("OS options", "AIX Motif", options[i++]);
110
			assertEquals("OS options", "Windows 95", options[i++]);
111
			assertEquals("OS options", "Windows 98", options[i++]);
112
			assertEquals("OS options", "Windows CE", options[i++]);
113
			assertEquals("OS options", "Windows ME", options[i++]);
114
			assertEquals("OS options", "Windows 2000", options[i++]);
115
			assertEquals("OS options", "Windows NT", options[i++]);
116
			assertEquals("OS options", "Windows XP", options[i++]);
117
			assertEquals("OS options", "Windows All", options[i++]);
118
			assertEquals("OS options", "MacOS X", options[i++]);
119
			assertEquals("OS options", "Linux", options[i++]);
120
			assertEquals("OS options", "Linux-GTK", options[i++]);
121
			assertEquals("OS options", "Linux-Motif", options[i++]);
122
			assertEquals("OS options", "HP-UX", options[i++]);
123
			assertEquals("OS options", "Neutrino", options[i++]);
124
			assertEquals("OS options", "QNX-Photon", options[i++]);
125
			assertEquals("OS options", "Solaris", options[i++]);
126
			assertEquals("OS options", "Unix All", options[i++]);
127
			assertEquals("OS options", "other", options[i++]);
128
		}
129
130
		// Attribute: Version
131
		att = itr.next();
132
		assertEquals("Attribute: Version", "Version", att.getName());
133
134
		// attOptions = (HashMap) att.getOptionValues();
135
		options = att.getOptionValues().keySet().toArray();
136
		assertEquals("# Version options", 1, options.length);
137
138
		i = 0;
139
		while (i < options.length) {
140
			assertEquals("Version options", "unspecified", options[i++]);
141
		}
142
143
		// Attribute: Platform
144
		att = itr.next();
145
		assertEquals("Attribute: Platform", "Platform", att.getName());
146
147
		options = att.getOptionValues().keySet().toArray();
148
		assertEquals("# Platform options", 6, options.length);
149
150
		i = 0;
151
		while (i < options.length) {
152
			assertEquals("Platform options", "All", options[i++]);
153
			assertEquals("Platform options", "Macintosh", options[i++]);
154
			assertEquals("Platform options", "PC", options[i++]);
155
			assertEquals("Platform options", "Power PC", options[i++]);
156
			assertEquals("Platform options", "Sun", options[i++]);
157
			assertEquals("Platform options", "Other", options[i++]);
158
		}
159
160
		att = itr.next();
161
		assertEquals("Attribute: Component", "Component", att.getName());
162
163
		options = att.getOptionValues().keySet().toArray();
164
		assertEquals("# Component options", 1, options.length);
165
166
		i = 0;
167
		while (i < options.length) {
168
			assertEquals("Component options", "Core", options[i++]);
169
		}
170
171
		// Attribute: bug_status
172
		att = itr.next();
173
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
174
175
		options = att.getOptionValues().keySet().toArray();
176
		assertEquals("No bug_status options", 0, options.length);
177
178
		// Attribute: form_name
179
		att = itr.next();
180
		assertEquals("Attribute: form_name", "form_name", att.getName());
181
182
		options = att.getOptionValues().keySet().toArray();
183
		assertEquals("No form_name options", 0, options.length);
184
185
		// Attribute: bug_file_loc
186
		att = itr.next();
187
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
188
189
		options = att.getOptionValues().keySet().toArray();
190
		assertEquals("No bug_file_loc options", 0, options.length);
191
192
		// Attribute: priority
193
		att = itr.next();
194
		assertEquals("Attribute: priority", "priority", att.getName());
195
196
		options = att.getOptionValues().keySet().toArray();
197
		assertEquals("No priority options", 0, options.length);
198
199
	}
200
201
	// private void printList(List<Attribute> attributes) {
202
	//
203
	// Iterator<Attribute> itr = attributes.iterator();
204
	// System.out.println("Attributes for this Product:");
205
	// System.out.println("============================");
206
	//
207
	// while (itr.hasNext()) {
208
	// Attribute attr = itr.next();
209
	// System.out.println();
210
	// System.out.println(attr.getName() + ": ");
211
	// System.out.println("-----------");
212
	//
213
	// Map<String, String> options = attr.getOptionValues();
214
	// Object[] it = options.keySet().toArray();
215
	// for (int i = 0; i < it.length; i++)
216
	// System.out.println((String) it[i]);
217
	// }
218
	// }
219
}
(-)developer/scratch/bugzilla/BugParser.java (+1107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.core.internal;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.InputStreamReader;
16
import java.io.Reader;
17
import java.net.URL;
18
import java.net.URLConnection;
19
import java.net.URLEncoder;
20
import java.nio.charset.Charset;
21
import java.text.ParseException;
22
import java.text.SimpleDateFormat;
23
import java.util.Calendar;
24
import java.util.Date;
25
import java.util.Iterator;
26
import java.util.List;
27
28
import javax.security.auth.login.LoginException;
29
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.Status;
32
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
33
import org.eclipse.mylar.bugzilla.core.BugReport;
34
import org.eclipse.mylar.bugzilla.core.Comment;
35
import org.eclipse.mylar.bugzilla.core.Operation;
36
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
37
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
38
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer.Token;
39
40
/**
41
 * @author Shawn Minto
42
 * @author Mik Kersten (hardening of prototype)
43
 * @author Rob Elves (attachments) This class parses bugs so that they can be
44
 *         displayed using the bug editor
45
 */
46
public class BugParser {
47
48
	private static final String VALUE_ATTACHMENT_OBSOLETE = "bz_obsolete";
49
50
	private static final String ATTRIBUTE_CLASS = "class";
51
52
	private static final String TAG_SPAN = "span";
53
54
	private static final String ATTRIBUTE_ID_TITLE = "title";
55
56
	private static final String ATTRIBUTE_ID_HREF = "href";
57
58
	private static final String ATTACHMENT_CGI_ID = "attachment.cgi?id=";
59
60
	private static final String KEY_BUG_NUM = "Bug#";
61
62
	private static final String KEY_RESOLUTION = "resolution";
63
64
	private static final String KEY_VALUE = "value";
65
66
	private static final String KEY_NAME = "name";
67
68
	private static final String ATTR_CHARSET = "charset";
69
70
	/** Parser for dates in the report */
71
	private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
72
73
	private static final String keywordsUrl = "describekeywords.cgi";
74
75
	/**
76
	 * Parse the case where we have found an attribute name
77
	 * 
78
	 * @param in
79
	 *            The input stream for the bug
80
	 * @return The name of the attribute that we are parsing
81
	 * @throws IOException
82
	 */
83
	private static String parseAttributeName(HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
84
		StringBuffer sb = new StringBuffer();
85
86
		parseTableCell(tokenizer, sb);
87
		HtmlStreamTokenizer.unescape(sb);
88
		// remove the colon if there is one
89
		if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ':') {
90
			sb.deleteCharAt(sb.length() - 1);
91
		}
92
		return sb.toString();
93
	}
94
95
	/**
96
	 * Parse the case where we have found attribute values
97
	 * 
98
	 * @param in
99
	 *            The input stream of the bug
100
	 * @param bug
101
	 *            The bug report for the current bug
102
	 * @param attribute
103
	 *            The name of the attribute
104
	 * @throws IOException
105
	 */
106
	private static void parseAttributeValue(BugReport bug, String originalAttributeName, HtmlStreamTokenizer tokenizer,
107
			String serverUrl, String userName, String password) throws IOException, ParseException {
108
109
		// NOTE: special rule to deal with change in 2.20.1
110
		String attributeName = originalAttributeName;
111
		if (attributeName.endsWith(KEY_BUG_NUM) && attributeName.length() > KEY_BUG_NUM.length()) {
112
			attributeName = originalAttributeName.substring(attributeName.length() - KEY_BUG_NUM.length(),
113
					attributeName.length());
114
		}
115
116
		Token token = tokenizer.nextToken();
117
		if (token.getType() == Token.TAG) {
118
			HtmlTag tag = (HtmlTag) token.getValue();
119
120
			// make sure that we are on a tag that we care about, not a label
121
			// fix added so that we can parse the mozilla bug pages
122
			if (tag.getTagType() == HtmlTag.Type.LABEL) {
123
				token = tokenizer.nextToken();
124
				if (token.getType() == Token.TAG)
125
					tag = (HtmlTag) token.getValue();
126
				else {
127
					StringBuffer sb = new StringBuffer();
128
					if (token.getType() == Token.TEXT) {
129
						sb.append((StringBuffer) token.getValue());
130
						parseAttributeValueCell(bug, attributeName, tokenizer, sb);
131
					}
132
				}
133
			}
134
135
			if (tag.getTagType() == HtmlTag.Type.SELECT && !tag.isEndTag()) {
136
				String parameterName = tag.getAttribute(KEY_NAME);
137
				parseSelect(bug, attributeName, parameterName, tokenizer);
138
			} else if (tag.getTagType() == HtmlTag.Type.INPUT && !tag.isEndTag()) {
139
				parseInput(bug, attributeName, tag, serverUrl, userName, password);
140
			} else if (!tag.isEndTag() || attributeName.equalsIgnoreCase(KEY_RESOLUTION)) {
141
				if (tag.isEndTag() && attributeName.equalsIgnoreCase(KEY_RESOLUTION)) {
142
					AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
143
					a.setValue("");
144
					bug.addAttribute(a);
145
				}
146
				parseAttributeValueCell(bug, attributeName, tokenizer);
147
			}
148
		} else {
149
			StringBuffer sb = new StringBuffer();
150
			if (token.getType() == Token.TEXT) {
151
				sb.append((StringBuffer) token.getValue());
152
				parseAttributeValueCell(bug, attributeName, tokenizer, sb);
153
			}
154
		}
155
	}
156
157
	/**
158
	 * Parse the case where the attribute value is just text in a table cell
159
	 * 
160
	 * @param in
161
	 *            The input stream of the bug
162
	 * @param bug
163
	 *            The bug report for the current bug
164
	 * @param attributeName
165
	 *            The name of the attribute that we are parsing
166
	 * @throws IOException
167
	 */
168
	private static void parseAttributeValueCell(BugReport bug, String attributeName, HtmlStreamTokenizer tokenizer)
169
			throws IOException, ParseException {
170
		StringBuffer sb = new StringBuffer();
171
		parseAttributeValueCell(bug, attributeName, tokenizer, sb);
172
	}
173
174
	private static void parseAttributeValueCell(BugReport bug, String attributeName, HtmlStreamTokenizer tokenizer,
175
			StringBuffer sb) throws IOException, ParseException {
176
177
		parseTableCell(tokenizer, sb);
178
		HtmlStreamTokenizer.unescape(sb);
179
180
		// create a new attribute and set its value to the value that we
181
		// retrieved
182
		AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
183
		a.setValue(sb.toString());
184
185
		// if we found an attachment attribute, forget about it, else add the
186
		// attribute to the bug report
187
		if (attributeName.toLowerCase().startsWith("attachments")) {
188
			// do nothing
189
		} else {
190
			if (attributeName.equals(KEY_BUG_NUM))
191
				a.setValue(a.getValue().replaceFirst("alias:", ""));
192
			bug.addAttribute(a);
193
		}
194
	}
195
196
	/**
197
	 * Reads text into a StringBuffer until it encounters a close table cell tag
198
	 * (&lt;/TD&gt;) or start of another cell. The text is appended to the
199
	 * existing value of the buffer. <b>NOTE:</b> Does not handle nested cells!
200
	 * 
201
	 * @param tokenizer
202
	 * @param sb
203
	 * @throws IOException
204
	 * @throws ParseException
205
	 */
206
	private static void parseTableCell(HtmlStreamTokenizer tokenizer, StringBuffer sb) throws IOException,
207
			ParseException {
208
		boolean noWhitespace = false;
209
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
210
			if (token.getType() == Token.TAG) {
211
				HtmlTag tag = (HtmlTag) token.getValue();
212
				if (tag.getTagType() == HtmlTag.Type.TD) {
213
					if (!tag.isEndTag()) {
214
						tokenizer.pushback(token);
215
					}
216
					break;
217
				}
218
				noWhitespace = token.getWhitespace().length() == 0;
219
			} else if (token.getType() == Token.TEXT) {
220
				// if there was no whitespace between the tag and the
221
				// preceding text, don't insert whitespace before this text
222
				// unless it is there in the source
223
				if (!noWhitespace && token.getWhitespace().length() > 0 && sb.length() > 0) {
224
					sb.append(' ');
225
				}
226
				sb.append((StringBuffer) token.getValue());
227
			}
228
		}
229
	}
230
231
	/**
232
	 * Parse the case where the attribute value is an option
233
	 * 
234
	 * @param in
235
	 *            The input stream for the bug
236
	 * @param bug
237
	 *            The bug report for the current bug
238
	 * @param attribute
239
	 *            The name of the attribute that we are parsing
240
	 * @param parameterName
241
	 *            the SELECT tag's name
242
	 * @throws IOException
243
	 */
244
	private static void parseSelect(BugReport bug, String attributeName, String parameterName,
245
			HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
246
247
		boolean first = false;
248
		AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
249
		a.setID(parameterName);
250
251
		Token token = tokenizer.nextToken();
252
		while (token.getType() != Token.EOF) {
253
			if (token.getType() == Token.TAG) {
254
				HtmlTag tag = (HtmlTag) token.getValue();
255
				if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
256
					break;
257
				if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
258
					String optionName = tag.getAttribute(KEY_VALUE);
259
					boolean selected = tag.hasAttribute("selected");
260
					StringBuffer optionText = new StringBuffer();
261
					for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer.nextToken()) {
262
						if (optionText.length() > 0) {
263
							optionText.append(' ');
264
						}
265
						optionText.append((StringBuffer) token.getValue());
266
					}
267
					a.addOptionValue(optionText.toString(), optionName);
268
					if (selected || first) {
269
						a.setValue(optionText.toString());
270
						first = false;
271
					}
272
				} else {
273
					token = tokenizer.nextToken();
274
				}
275
			} else {
276
				token = tokenizer.nextToken();
277
			}
278
		}
279
280
		// if we parsed the cc field add the e-mails to the bug report else add
281
		// the attribute to the bug report
282
		if (attributeName.toLowerCase().startsWith("cc")) {
283
			for (Iterator<String> it = a.getOptionValues().keySet().iterator(); it.hasNext();) {
284
				String email = it.next();
285
				bug.addCC(HtmlStreamTokenizer.unescape(email));
286
			}
287
		} else {
288
			bug.addAttribute(a);
289
		}
290
	}
291
292
	/**
293
	 * Parse the case where the attribute value is an input
294
	 * 
295
	 * @param bug
296
	 *            The bug report for the current bug
297
	 * @param attributeName
298
	 *            The name of the attribute
299
	 * @param tag
300
	 *            The INPUT tag
301
	 * @throws IOException
302
	 */
303
	private static void parseInput(BugReport bug, String attributeName, HtmlTag tag, String serverUrl, String userName,
304
			String password) throws IOException {
305
306
		AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(attributeName);
307
		a.setID(tag.getAttribute(KEY_NAME));
308
		String name = tag.getAttribute(KEY_NAME);
309
		String value = tag.getAttribute(KEY_VALUE);
310
		if (value == null)
311
			value = "";
312
313
		// if we found the summary, add it to the bug report
314
		if (name.equalsIgnoreCase("short_desc")) {
315
			bug.setSummary(value);
316
		} else if (name.equalsIgnoreCase("bug_file_loc")) {
317
			a.setValue(value);
318
			bug.addAttribute(a);
319
		} else if (name.equalsIgnoreCase("newcc")) {
320
			a.setValue(value);
321
			bug.addAttribute(a);
322
		} else {
323
			// otherwise just add the attribute
324
			a.setValue(value);
325
			bug.addAttribute(a);
326
327
			if (attributeName.equalsIgnoreCase("keywords") && serverUrl != null) {
328
329
				BufferedReader input = null;
330
				try {
331
332
					String urlText = "";
333
334
					// if we have a user name, may as well log in just in case
335
					// it is required
336
					if (userName != null && !userName.equals("") && password != null && !password.equals("")) {
337
						/*
338
						 * The UnsupportedEncodingException exception for
339
						 * URLEncoder.encode() should not be thrown, since every
340
						 * implementation of the Java platform is required to
341
						 * support the standard charset "UTF-8"
342
						 */
343
						urlText += "?GoAheadAndLogIn=1&Bugzilla_login=" + URLEncoder.encode(userName, "UTF-8")
344
								+ "&Bugzilla_password=" + URLEncoder.encode(password, "UTF-8");
345
					}
346
347
					// connect to the bugzilla server to get the keyword list
348
					URL url = new URL(serverUrl + "/" + keywordsUrl + urlText);
349
					URLConnection urlConnection = BugzillaPlugin.getDefault().getUrlConnection(url);
350
					input = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
351
352
					// parse the valid keywords and add them to the bug
353
					List<String> keywords = new KeywordParser(input).getKeywords();
354
					bug.setKeywords(keywords);
355
356
				} catch (Exception e) {
357
					// throw an exception if there is a problem reading the bug
358
					// from the server
359
					throw new IOException("Exception while fetching the list of keywords from the server: "
360
							+ e.getMessage());
361
				} finally {
362
					try {
363
						if (input != null)
364
							input.close();
365
					} catch (IOException e) {
366
						BugzillaPlugin.log(new Status(IStatus.ERROR, IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
367
								"Problem closing the stream", e));
368
					}
369
				}
370
			}
371
		}
372
	}
373
374
	/**
375
	 * Parse the case where we are dealing with the description
376
	 * 
377
	 * @param bug
378
	 *            The bug report for the bug
379
	 * @throws IOException
380
	 */
381
	private static void parseDescription(BugReport bug, HtmlStreamTokenizer tokenizer) throws IOException,
382
			ParseException {
383
384
		StringBuffer sb = new StringBuffer();
385
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
386
			if (token.getType() == Token.TAG) {
387
				HtmlTag tag = (HtmlTag) token.getValue();
388
				if (sb.length() > 0) {
389
					sb.append(token.getWhitespace());
390
				}
391
				if (tag.getTagType() == HtmlTag.Type.PRE && tag.isEndTag())
392
					break;
393
			} else if (token.getType() == Token.TEXT) {
394
				if (sb.length() > 0) {
395
					sb.append(token.getWhitespace());
396
				}
397
				sb.append((StringBuffer) token.getValue());
398
			}
399
		}
400
401
		// set the bug to have the description we retrieved
402
		String text = HtmlStreamTokenizer.unescape(sb).toString();
403
		bug.setDescription(text);
404
	}
405
406
	// /**
407
	// * parses the description of an attachment on the report
408
	// */
409
	// private static String parseAttachementDescription(HtmlStreamTokenizer
410
	// tokenizer) throws IOException,
411
	// ParseException {
412
	//
413
	// StringBuffer sb = new StringBuffer();
414
	// for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF;
415
	// token = tokenizer.nextToken()) {
416
	// if (token.getType() == Token.TAG) {
417
	// HtmlTag tag = (HtmlTag) token.getValue();
418
	// if (tag.getTagType() == HtmlTag.Type.A && tag.isEndTag())
419
	// break;
420
	// } else if (token.getType() == Token.TEXT) {
421
	// if (sb.length() > 0) {
422
	// sb.append(token.getWhitespace());
423
	// }
424
	// sb.append((StringBuffer) token.getValue());
425
	// }
426
	// }
427
	//
428
	// // set the bug to have the description we retrieved
429
	// String text = HtmlStreamTokenizer.unescape(sb).toString();
430
	// return text;
431
	// }
432
433
	/**
434
	 * Parse the case where we have found the start of a comment
435
	 * 
436
	 * @param in
437
	 *            The input stream of the bug
438
	 * @param bug
439
	 *            The bug report for the current bug
440
	 * @return The comment that we have created with the information
441
	 * @throws IOException
442
	 * @throws ParseException
443
	 */
444
	private static Comment parseCommentHead(BugReport bug, HtmlStreamTokenizer tokenizer) throws IOException,
445
			ParseException {
446
		int number = 0;
447
		Date date = null;
448
		String author = null;
449
		String authorName = null;
450
451
		// get the comment's number
452
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
453
			if (token.getType() == Token.TAG) {
454
				HtmlTag tag = (HtmlTag) token.getValue();
455
				if (tag.getTagType() == HtmlTag.Type.A) {
456
					String href = tag.getAttribute(ATTRIBUTE_ID_HREF);
457
					if (href != null) {
458
						int index = href.toLowerCase().indexOf("#c");
459
						if (index == -1)
460
							continue;
461
						token = tokenizer.nextToken();
462
						number = Integer.parseInt(((StringBuffer) token.getValue()).toString().substring(1));
463
						break;
464
					}
465
				}
466
			}
467
		}
468
469
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
470
			if (token.getType() == Token.TAG) {
471
				HtmlTag tag = (HtmlTag) token.getValue();
472
				if (tag.getTagType() == HtmlTag.Type.A) {
473
					String href = tag.getAttribute(ATTRIBUTE_ID_HREF);
474
					if (href != null) {
475
						int index = href.toLowerCase().indexOf("mailto");
476
						if (index == -1)
477
							continue;
478
						author = href.substring(index + 7);
479
						break;
480
					}
481
				}
482
			}
483
		}
484
485
		// get the author's real name
486
		StringBuffer sb = new StringBuffer();
487
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
488
			if (token.getType() == Token.TAG) {
489
				HtmlTag tag = (HtmlTag) token.getValue();
490
				if (tag.getTagType() == HtmlTag.Type.A && tag.isEndTag())
491
					break;
492
			} else if (token.getType() == Token.TEXT) {
493
				if (sb.length() > 0) {
494
					sb.append(' ');
495
				}
496
				sb.append((StringBuffer) token.getValue());
497
			}
498
		}
499
		authorName = sb.toString();
500
501
		// get the comment's date
502
		sb.setLength(0);
503
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
504
			if (token.getType() == Token.TAG) {
505
				HtmlTag tag = (HtmlTag) token.getValue();
506
				if (tag.getTagType() == HtmlTag.Type.I && tag.isEndTag())
507
					break;
508
			} else if (token.getType() == Token.TEXT) {
509
				if (sb.length() > 0) {
510
					sb.append(' ');
511
				}
512
				sb.append((StringBuffer) token.getValue());
513
			}
514
		}
515
		try {
516
			if (sb.length() >= 16) {
517
				date = df.parse(sb.substring(0, 16));
518
			}
519
		} catch (Exception e) {
520
			date = Calendar.getInstance().getTime(); // XXX: could not
521
			// determine date
522
		}
523
		return new Comment(bug, number, date, author, authorName);
524
	}
525
526
	/**
527
	 * Parse the case where we have comment text
528
	 * 
529
	 * @param in
530
	 *            The input stream for the bug
531
	 * @param bug
532
	 *            The bug report for the current bug
533
	 * @param comment
534
	 *            The comment to add the text to
535
	 * @throws IOException
536
	 */
537
	private static void parseCommentText(BugReport bug, Comment comment, HtmlStreamTokenizer tokenizer)
538
			throws IOException, ParseException {
539
540
		StringBuffer commentStringBuffer = new StringBuffer();
541
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
542
			if (token.getType() == Token.TAG) {
543
				HtmlTag tag = (HtmlTag) token.getValue();
544
				if (tag.getTagName().equals(TAG_SPAN)) {
545
					if(tag.hasAttribute(ATTRIBUTE_CLASS) && tag.getAttribute(ATTRIBUTE_CLASS).equals("")) {
546
						parseAttachment(commentStringBuffer, comment, tokenizer, false);
547
						continue;
548
					} else if(tag.hasAttribute(ATTRIBUTE_CLASS) && tag.getAttribute(ATTRIBUTE_CLASS).equals(VALUE_ATTACHMENT_OBSOLETE)) {
549
						parseAttachment(commentStringBuffer, comment, tokenizer, true);
550
						continue;
551
					}
552
				}
553
				// added to ensure whitespace is not
554
				// lost if adding a tag within a tag
555
				if (commentStringBuffer.length() > 0) {
556
					commentStringBuffer.append(token.getWhitespace());
557
				}
558
				if (tag.getTagType() == HtmlTag.Type.PRE && tag.isEndTag())
559
					break;
560
			} else if (token.getType() == Token.TEXT) {
561
				if (commentStringBuffer.length() > 0) {
562
					commentStringBuffer.append(token.getWhitespace());
563
				}
564
				commentStringBuffer.append((StringBuffer) token.getValue());
565
			}
566
			// remove attachment description from comment body
567
			if (comment.hasAttachment() && commentStringBuffer.indexOf(comment.getAttachmentDescription()) == 0) {
568
				commentStringBuffer = new StringBuffer();
569
			}
570
		}
571
572
		HtmlStreamTokenizer.unescape(commentStringBuffer);
573
		comment.setText(commentStringBuffer.toString());
574
		bug.addComment(comment);
575
	}
576
577
	private static void parseAttachment(StringBuffer stringBuffer, Comment comment, HtmlStreamTokenizer tokenizer, boolean obsolete)
578
			throws IOException, ParseException {
579
580
		int attachmentID = -1;
581
		String attachmentDescription = "";
582
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
583
			if (token.getType() == Token.TAG) {
584
				HtmlTag tag = (HtmlTag) token.getValue();
585
586
				if (tag.getTagType() == HtmlTag.Type.A && !comment.hasAttachment()) {
587
					if (tag.getAttribute(ATTRIBUTE_ID_HREF) != null) {
588
						String link = tag.getAttribute(ATTRIBUTE_ID_HREF);
589
						if (link.startsWith(ATTACHMENT_CGI_ID)) {
590
							try {
591
								int endIndex = link.indexOf("&");
592
								if (endIndex > 0 && endIndex < link.length()) {
593
									attachmentID = Integer.parseInt(link
594
											.substring(ATTACHMENT_CGI_ID.length(), endIndex));
595
								}
596
							} catch (NumberFormatException e) {
597
								return;
598
							}
599
						}
600
						if (tag.getAttribute(ATTRIBUTE_ID_TITLE) != null) {
601
							attachmentDescription = tag.getAttribute(ATTRIBUTE_ID_TITLE);
602
						}
603
						if (attachmentID > 0) {
604
							comment.setHasAttachment(true);
605
							comment.setAttachmentId(attachmentID);
606
							comment.setAttachmentDescription(attachmentDescription);
607
							comment.setObsolete(obsolete);
608
						}
609
610
					}
611
				}
612
				if (tag.getTagName().equals(TAG_SPAN) && tag.isEndTag())
613
					break;
614
			}
615
		}
616
	}
617
618
	/**
619
	 * Parse the full html version of the bug
620
	 * 
621
	 * @param in -
622
	 *            the input stream for the bug
623
	 * @param id -
624
	 *            the id of the bug that is to be parsed
625
	 * @return A bug report for the bug that was parsed
626
	 * @throws IOException
627
	 * @throws ParseException
628
	 */
629
	public static BugReport parseBug(Reader in, int id, String serverUrl, boolean is218, String userName,
630
			String password, String contentType) throws IOException, ParseException, LoginException {
631
		// create a new bug report and set the parser state to the start state
632
		BugReport bug = new BugReport(id, serverUrl);
633
		boolean contentTypeResolved = false;
634
		if (contentType != null) {
635
			String charsetFromContentType = getCharsetFromString(contentType);
636
			if (charsetFromContentType != null) {
637
				bug.setCharset(charsetFromContentType);
638
				contentTypeResolved = true;
639
			}
640
		}
641
		ParserState state = ParserState.START;
642
		Comment comment = null;
643
		String attribute = null;
644
645
		HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
646
647
		boolean isTitle = false;
648
		boolean possibleBadLogin = false;
649
		boolean checkBody = false;
650
		String title = "";
651
		StringBuffer body = new StringBuffer();
652
653
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
654
655
			// get the charset from the HTML if not specified
656
			if (!contentTypeResolved) {
657
				if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.META
658
						&& !((HtmlTag) (token.getValue())).isEndTag()) {
659
					String charsetFromHtml = getCharsetFromString(token.toString());
660
					if (charsetFromHtml != null)
661
						bug.setCharset(charsetFromHtml);
662
				}
663
			}
664
665
			// make sure that bugzilla doesn't want us to login
666
			if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
667
					&& !((HtmlTag) (token.getValue())).isEndTag()) {
668
				isTitle = true;
669
				continue;
670
			}
671
672
			if (isTitle) {
673
				// get all of the data in the title tag
674
				if (token.getType() != Token.TAG) {
675
					title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
676
					continue;
677
				} else if (token.getType() == Token.TAG
678
						&& ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
679
						&& ((HtmlTag) token.getValue()).isEndTag()) {
680
					// check and see if the title seems as though we have wrong
681
					// login info
682
					if (title.indexOf("login") != -1
683
							|| (title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
684
							|| title.indexOf("check e-mail") != -1)
685
						possibleBadLogin = true; // we possibly have a bad
686
					// login
687
688
					// if the title starts with error, we may have a login
689
					// problem, or
690
					// there is a problem with the bug (doesn't exist), so we
691
					// must do
692
					// some more checks
693
					if (title.startsWith("error"))
694
						checkBody = true;
695
696
					isTitle = false;
697
					title = "";
698
				}
699
				continue;
700
			}
701
702
			// if we have to add all of the text so that we can check it later
703
			// for problems with the username and password
704
			if (checkBody && token.getType() == Token.TEXT) {
705
				body.append((StringBuffer) token.getValue());
706
				body.append(" ");
707
			}
708
709
			// we have found the start of an attribute name
710
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
711
				HtmlTag tag = (HtmlTag) token.getValue();
712
				if (tag.getTagType() == HtmlTag.Type.TD && "right".equalsIgnoreCase(tag.getAttribute("align"))) {
713
					// parse the attribute's name
714
					attribute = parseAttributeName(tokenizer);
715
					if (attribute != null && attribute.contains(IBugzillaConstants.INVALID_2201_ATTRIBUTE_IGNORED)) {
716
						continue;
717
					}
718
					if (attribute.toLowerCase().startsWith("opened")) {
719
						// find the colon so we can get the date
720
						int index = attribute.toLowerCase().indexOf(":");
721
						String date;
722
						if (index != -1)
723
							date = attribute.substring(index + 1).trim();
724
						else
725
							date = attribute.substring(6).trim();
726
727
						// set the bugs opened date to be the date we parsed
728
						bug.setCreated(df.parse(date));
729
						state = ParserState.ATT_NAME;
730
						continue;
731
					}
732
733
					// in 2.18, the last modified looks like the opened so we
734
					// need to parse it differently
735
					if (attribute.toLowerCase().startsWith("last modified") && is218) {
736
						// find the colon so we can get the date
737
						int index = attribute.toLowerCase().indexOf(":");
738
						String date;
739
						if (index != -1)
740
							date = attribute.substring(index + 1).trim();
741
						else
742
							date = attribute.substring(6).trim();
743
744
						// create a new attribute and set the date
745
						AbstractRepositoryReportAttribute t = new AbstractRepositoryReportAttribute("Last Modified");
746
						t.setValue(date);
747
748
						// add the attribute to the bug report
749
						bug.addAttribute(t);
750
						bug.setLastModified(df.parse(date));
751
						state = ParserState.ATT_NAME;
752
						continue;
753
					}
754
755
					state = ParserState.ATT_VALUE;
756
					continue;
757
				} else if (tag.getTagType() == HtmlTag.Type.INPUT && "radio".equalsIgnoreCase(tag.getAttribute("type"))
758
						&& "knob".equalsIgnoreCase(tag.getAttribute(KEY_NAME))) {
759
					// we found a radio button
760
					parseOperations(bug, tokenizer, tag, is218);
761
				}
762
			}
763
764
			// we have found the start of attribute values
765
			if (state == ParserState.ATT_VALUE && token.getType() == Token.TAG) {
766
				HtmlTag tag = (HtmlTag) token.getValue();
767
				if (tag.getTagType() == HtmlTag.Type.TD) {
768
					// parse the attribute values
769
					parseAttributeValue(bug, attribute, tokenizer, serverUrl, userName, password);
770
771
					state = ParserState.ATT_NAME;
772
					attribute = null;
773
					continue;
774
				}
775
			}
776
777
			// we have found the start of a comment
778
			if (state == ParserState.DESC_START && token.getType() == Token.TAG) {
779
				HtmlTag tag = (HtmlTag) token.getValue();
780
				if (tag.getTagType() == HtmlTag.Type.I) {
781
					// parse the comment's start
782
					comment = parseCommentHead(bug, tokenizer);
783
784
					state = ParserState.DESC_VALUE;
785
					continue;
786
				}
787
			}
788
789
			// we have found the start of the comment text
790
			if (state == ParserState.DESC_VALUE && token.getType() == Token.TAG) {
791
				HtmlTag tag = (HtmlTag) token.getValue();
792
				if (tag.getTagType() == HtmlTag.Type.PRE) {
793
					// parse the text of the comment
794
					parseCommentText(bug, comment, tokenizer);
795
796
					comment = null;
797
					state = ParserState.DESC_START;
798
					continue;
799
				}
800
			}
801
			
802
			// last modification date
803
			if (bug.getCreated() == null && (state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
804
				HtmlTag tag = (HtmlTag) token.getValue();
805
				if (tag.getTagType() == HtmlTag.Type.DIV && tag.getAttribute("id") != null && "header".equalsIgnoreCase(tag.getAttribute("id"))) {
806
					StringBuffer sb = new StringBuffer();
807
					parseLastModified(sb, tokenizer);					
808
					if(sb.length() > 0) {
809
						int index = sb.indexOf(":");
810
						String date;
811
						if (index != -1)
812
							date = sb.substring(index + 1).trim();
813
						else
814
							date = sb.substring(6).trim();
815
816
						// create a new attribute and set the date
817
						AbstractRepositoryReportAttribute t = new AbstractRepositoryReportAttribute("Last Modified");
818
						t.setValue(date);
819
820
						// add the attribute to the bug report
821
						bug.setLastModified(df.parse(date));
822
						bug.addAttribute(t);
823
					}
824
					continue;
825
				}
826
			}
827
			
828
829
			// look for date opened field
830
			if (bug.getCreated() == null && (state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
831
				HtmlTag tag = (HtmlTag) token.getValue();
832
				if (tag.getTagType() == HtmlTag.Type.TD && tag.getAttribute("align") != null && "left".equalsIgnoreCase(tag.getAttribute("align")) && tag.getAttribute("width") != null && "30%".equals(tag.getAttribute("width"))) {
833
					StringBuffer sb = new StringBuffer();
834
					parseDateOpened(sb, tokenizer);					
835
					if(sb.length() > 0) {
836
						int index = sb.indexOf(":");
837
						String date;
838
						if (index != -1)
839
							date = sb.substring(index + 1).trim();
840
						else
841
							date = sb.substring(6).trim();
842
843
						// set the bugs opened date to be the date we parsed
844
						bug.setCreated(df.parse(date));
845
					}
846
					continue;
847
				}
848
			}
849
850
			// we have found the description of the bug
851
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
852
				HtmlTag tag = (HtmlTag) token.getValue();
853
				if (tag.getTagType() == HtmlTag.Type.PRE) {
854
					// parse the description for the bug
855
					parseDescription(bug, tokenizer);
856
857
					state = ParserState.DESC_START;
858
					continue;
859
				}
860
			}
861
862
			// parse hidden fields
863
864
			if ((state == ParserState.ATT_NAME || state == ParserState.START) && token.getType() == Token.TAG) {
865
				HtmlTag tag = (HtmlTag) token.getValue();
866
				if (tag.getTagType() == HtmlTag.Type.INPUT && tag.getAttribute("type") != null
867
						&& "hidden".equalsIgnoreCase(tag.getAttribute("type").trim())) {
868
869
					AbstractRepositoryReportAttribute a = new AbstractRepositoryReportAttribute(tag.getAttribute(KEY_NAME));
870
					a.setID(tag.getAttribute(KEY_NAME));
871
					a.setValue(tag.getAttribute(KEY_VALUE));
872
					a.setHidden(true);
873
					bug.addAttribute(a);
874
					continue;
875
				}
876
			}
877
878
			// // parse out attachments
879
			// if(token.getType() == Token.TAG) {
880
			// HtmlTag tag = (HtmlTag) token.getValue();
881
			// if(tag.getTagType() == HtmlTag.Type.A && tag.getAttribute("href")
882
			// != null) {
883
			// String link = tag.getAttribute("href");
884
			// if(link.startsWith("attachment.cgi?id=") &&
885
			// !link.contains("action")) {
886
			// int attachmentID = Integer.parseInt(link.substring(18));
887
			// String description = parseAttachementDescription(tokenizer);
888
			// bug.addAttachment(attachmentID, description);
889
			// }
890
			// }
891
			// }
892
893
		}
894
895
		// if we are to check the body, make sure that there wasn't a bad login
896
		if (checkBody) {
897
			String b = body.toString();
898
			if (b.indexOf("login") != -1
899
					|| ((b.indexOf("invalid") != -1 || b.indexOf("not valid") != -1) && b.indexOf("password") != -1)
900
					|| b.indexOf("check e-mail") != -1)
901
				possibleBadLogin = true; // we possibly have a bad login
902
		}
903
904
		// if there is no summary or created date, we expect that
905
		// the bug doesn't exist, so set it to null
906
907
		// if the bug seems like it doesn't exist, and we suspect a login
908
		// problem, assume that there was a login problem
909
		if (bug.getCreated() == null && bug.getAttributes().isEmpty()) {
910
			if (possibleBadLogin) {
911
				throw new LoginException(IBugzillaConstants.MESSAGE_LOGIN_FAILURE);
912
			} else {
913
				return null;
914
			}
915
		}
916
		// we are done...return the bug
917
		return bug;
918
	}
919
920
	private static void parseDateOpened(StringBuffer sb, HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
921
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
922
			if (token.getType() == Token.TAG) {
923
				HtmlTag tag = (HtmlTag) token.getValue();
924
				if (tag.getTagType() == HtmlTag.Type.TD && tag.isEndTag())
925
					break;
926
			} else if (token.getType() == Token.TEXT) {
927
				if (sb.length() > 0) {
928
					sb.append(' ');
929
				}
930
				sb.append((StringBuffer) token.getValue());
931
			}
932
		}
933
		
934
	}
935
	
936
	private static void parseLastModified(StringBuffer sb, HtmlStreamTokenizer tokenizer) throws IOException, ParseException {
937
		boolean inH3 = false;
938
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
939
			if (token.getType() == Token.TAG) {
940
				HtmlTag tag = (HtmlTag) token.getValue();				
941
				if (tag.getTagType() == HtmlTag.Type.H3 && !tag.isEndTag()) {
942
					inH3 = true;
943
					continue;
944
				} else if (tag.getTagType() == HtmlTag.Type.DIV && tag.isEndTag()) {
945
					break;
946
				}
947
			} else if (token.getType() == Token.TEXT && inH3) {
948
				if (sb.length() > 0) {
949
					sb.append(' ');
950
				}
951
				sb.append((StringBuffer) token.getValue());
952
			}
953
		}
954
		
955
	}
956
957
	public static String getCharsetFromString(String string) {
958
		int charsetStartIndex = string.indexOf(ATTR_CHARSET);
959
		if (charsetStartIndex != -1) {
960
			int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
961
			// could
962
			// be
963
			// space
964
			// after?
965
			if (charsetEndIndex == -1) {
966
				charsetEndIndex = string.length();
967
			}
968
			String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
969
			if (Charset.availableCharsets().containsKey(charsetString)) {
970
				return charsetString;
971
			}
972
		}
973
		return null;
974
	}
975
976
	/**
977
	 * Parse the operations that are allowed on the bug (Assign, Re-open, fix)
978
	 * 
979
	 * @param bug
980
	 *            The bug to add the operations to
981
	 * @param tokenizer
982
	 *            The stream tokenizer for the bug
983
	 * @param tag
984
	 *            The last tag that we were on
985
	 */
986
	private static void parseOperations(BugReport bug, HtmlStreamTokenizer tokenizer, HtmlTag tag, boolean is218)
987
			throws ParseException, IOException {
988
989
		String knobName = tag.getAttribute(KEY_VALUE);
990
		boolean isChecked = false;
991
		if (tag.getAttribute("checked") != null && tag.getAttribute("checked").equals("checked"))
992
			isChecked = true;
993
		StringBuffer sb = new StringBuffer();
994
995
		Token lastTag = null;
996
997
		for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
998
			if (token.getType() == Token.TAG) {
999
				tag = (HtmlTag) token.getValue();
1000
1001
				if (!(tag.getTagType() == HtmlTag.Type.A || tag.getTagType() == HtmlTag.Type.B
1002
						|| tag.getTagType() == HtmlTag.Type.STRONG || tag.getTagType() == HtmlTag.Type.LABEL)) {
1003
					lastTag = token;
1004
					break;
1005
				} else {
1006
1007
					if (is218 && tag.getTagType() == HtmlTag.Type.LABEL) {
1008
						continue;
1009
					} else if (tag.getTagType() == HtmlTag.Type.A || tag.getTagType() == HtmlTag.Type.B
1010
							|| tag.getTagType() == HtmlTag.Type.STRONG) {
1011
						sb.append(tag.toString().trim() + " ");
1012
					} else {
1013
						break;
1014
					}
1015
				}
1016
			} else if (token.getType() == Token.TEXT && !token.toString().trim().equals("\n"))
1017
				sb.append(token.toString().trim() + " ");
1018
		}
1019
1020
		String displayName = HtmlStreamTokenizer.unescape(sb).toString();
1021
		Operation o = new Operation(knobName, displayName);
1022
		o.setChecked(isChecked);
1023
1024
		if (lastTag != null) {
1025
			tag = (HtmlTag) lastTag.getValue();
1026
			if (tag.getTagType() != HtmlTag.Type.SELECT) {
1027
				tokenizer.pushback(lastTag);
1028
				if (tag.getTagType() == HtmlTag.Type.INPUT
1029
						&& !("radio".equalsIgnoreCase(tag.getAttribute("type")) && "knob".equalsIgnoreCase(tag
1030
								.getAttribute(KEY_NAME)))) {
1031
					o.setInputName(((HtmlTag) lastTag.getValue()).getAttribute(KEY_NAME));
1032
					o.setInputValue(((HtmlTag) lastTag.getValue()).getAttribute(KEY_VALUE));
1033
				}
1034
			} else {
1035
				Token token = tokenizer.nextToken();
1036
				// parse the options
1037
1038
				tag = (HtmlTag) token.getValue();
1039
				o.setUpOptions(((HtmlTag) lastTag.getValue()).getAttribute(KEY_NAME));
1040
1041
				while (token.getType() != Token.EOF) {
1042
					if (token.getType() == Token.TAG) {
1043
						tag = (HtmlTag) token.getValue();
1044
						if (tag.getTagType() == HtmlTag.Type.SELECT && tag.isEndTag())
1045
							break;
1046
						if (tag.getTagType() == HtmlTag.Type.OPTION && !tag.isEndTag()) {
1047
							String optionName = tag.getAttribute(KEY_VALUE);
1048
							StringBuffer optionText = new StringBuffer();
1049
							for (token = tokenizer.nextToken(); token.getType() == Token.TEXT; token = tokenizer
1050
									.nextToken()) {
1051
								if (optionText.length() > 0) {
1052
									optionText.append(' ');
1053
								}
1054
								optionText.append((StringBuffer) token.getValue());
1055
							}
1056
							o.addOption(optionText.toString(), optionName);
1057
						} else {
1058
							token = tokenizer.nextToken();
1059
						}
1060
					} else {
1061
						token = tokenizer.nextToken();
1062
					}
1063
				}
1064
			}
1065
		}
1066
1067
		bug.addOperation(o);
1068
	}
1069
1070
	/**
1071
	 * Enum class for describing current state of Bugzilla report parser.
1072
	 */
1073
	private static class ParserState {
1074
		/** An instance of the start state */
1075
		protected static final ParserState START = new ParserState("start");
1076
1077
		/** An instance of the state when the parser found an attribute name */
1078
		protected static final ParserState ATT_NAME = new ParserState("att_name");
1079
1080
		/** An instance of the state when the parser found an attribute value */
1081
		protected static final ParserState ATT_VALUE = new ParserState("att_value");
1082
1083
		/** An instance of the state when the parser found a description */
1084
		protected static final ParserState DESC_START = new ParserState("desc_start");
1085
1086
		/** An instance of the state when the parser found a description value */
1087
		protected static final ParserState DESC_VALUE = new ParserState("desc_value");
1088
1089
		/** State's human-readable name */
1090
		private String name;
1091
1092
		/**
1093
		 * Constructor
1094
		 * 
1095
		 * @param description -
1096
		 *            The states human readable name
1097
		 */
1098
		private ParserState(String description) {
1099
			this.name = description;
1100
		}
1101
1102
		@Override
1103
		public String toString() {
1104
			return name;
1105
		}
1106
	}
1107
}
(-)developer/scratch/bugzilla/BugzillaNewBugParserTestEquinox.java (+219 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestEquinox extends TestCase {
33
34
	public BugzillaNewBugParserTestEquinox() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestEquinox(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductEquinox() throws Exception {
43
44
		File f = FileTool
45
				.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/equinox-page.html"));
46
47
		Reader in = new FileReader(f);
48
49
		NewBugzillaReport nbm = new NewBugzillaReport();
50
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
51
															// **
52
53
		// attributes for this bug model
54
		List<AbstractRepositoryReportAttribute> attributes = nbm.getAttributes();
55
		// printList(attributes);
56
57
		Iterator<AbstractRepositoryReportAttribute> itr = attributes.iterator();
58
		AbstractRepositoryReportAttribute att = itr.next();
59
60
		// Attribute: Severity
61
		assertEquals("Attribute: Severity", "Severity", att.getName());
62
63
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
64
		// options for the
65
		// current
66
		// attribute
67
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
68
		// the options of the
69
		// current attribute
70
		assertEquals("# Severity options", 7, options.length);
71
72
		int i = 0;
73
		while (i < options.length) {
74
			assertEquals("severity options", "blocker", options[i++]);
75
			assertEquals("severity options", "critical", options[i++]);
76
			assertEquals("severity options", "major", options[i++]);
77
			assertEquals("severity options", "normal", options[i++]);
78
			assertEquals("severity options", "minor", options[i++]);
79
			assertEquals("severity options", "trivial", options[i++]);
80
			assertEquals("severity options", "enhancement", options[i++]);
81
		}
82
83
		// Attribute: product
84
		att = itr.next();
85
		assertEquals("Attribute: prodcut", "product", att.getName());
86
87
		options = att.getOptionValues().keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		options = att.getOptionValues().keySet().toArray();
95
		assertEquals("No AssignedTo options", 0, options.length);
96
97
		// Attribute: OS
98
		att = itr.next();
99
		assertEquals("Attribute: OS", "OS", att.getName());
100
101
		options = att.getOptionValues().keySet().toArray();
102
		assertEquals("# OS options", 20, options.length);
103
104
		i = 0;
105
		while (i < options.length) {
106
			assertEquals("OS options", "All", options[i++]);
107
			assertEquals("OS options", "AIX Motif", options[i++]);
108
			assertEquals("OS options", "Windows 95", options[i++]);
109
			assertEquals("OS options", "Windows 98", options[i++]);
110
			assertEquals("OS options", "Windows CE", options[i++]);
111
			assertEquals("OS options", "Windows ME", options[i++]);
112
			assertEquals("OS options", "Windows 2000", options[i++]);
113
			assertEquals("OS options", "Windows NT", options[i++]);
114
			assertEquals("OS options", "Windows XP", options[i++]);
115
			assertEquals("OS options", "Windows All", options[i++]);
116
			assertEquals("OS options", "MacOS X", options[i++]);
117
			assertEquals("OS options", "Linux", options[i++]);
118
			assertEquals("OS options", "Linux-GTK", options[i++]);
119
			assertEquals("OS options", "Linux-Motif", options[i++]);
120
			assertEquals("OS options", "HP-UX", options[i++]);
121
			assertEquals("OS options", "Neutrino", options[i++]);
122
			assertEquals("OS options", "QNX-Photon", options[i++]);
123
			assertEquals("OS options", "Solaris", options[i++]);
124
			assertEquals("OS options", "Unix All", options[i++]);
125
			assertEquals("OS options", "other", options[i++]);
126
		}
127
128
		// Attribute: Version
129
		att = itr.next();
130
		assertEquals("Attribute: Version", "Version", att.getName());
131
132
		options = att.getOptionValues().keySet().toArray();
133
		assertEquals("# Version options", 1, options.length);
134
135
		i = 0;
136
		while (i < options.length) {
137
			assertEquals("Version options", "unspecified", options[i++]);
138
		}
139
140
		// Attribute: Platform
141
		att = itr.next();
142
		assertEquals("Attribute: Platform", "Platform", att.getName());
143
144
		options = att.getOptionValues().keySet().toArray();
145
		assertEquals("# Platform options", 6, options.length);
146
147
		i = 0;
148
		while (i < options.length) {
149
			assertEquals("Platform options", "All", options[i++]);
150
			assertEquals("Platform options", "Macintosh", options[i++]);
151
			assertEquals("Platform options", "PC", options[i++]);
152
			assertEquals("Platform options", "Power PC", options[i++]);
153
			assertEquals("Platform options", "Sun", options[i++]);
154
			assertEquals("Platform options", "Other", options[i++]);
155
		}
156
157
		// Attribute: Component
158
		att = itr.next();
159
		assertEquals("Attribute: Component", "Component", att.getName());
160
161
		options = att.getOptionValues().keySet().toArray();
162
		assertEquals("# Component options", 3, options.length);
163
164
		i = 0;
165
		while (i < options.length) {
166
			assertEquals("Component options", "Dynamic Plugins", options[i++]);
167
			assertEquals("Component options", "General", options[i++]);
168
			assertEquals("Component options", "OSGi", options[i++]);
169
		}
170
171
		// Attribute: bug_status
172
		att = itr.next();
173
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
174
175
		options = att.getOptionValues().keySet().toArray();
176
		assertEquals("No bug_status options", 0, options.length);
177
178
		// Attribute: form_name
179
		att = itr.next();
180
		assertEquals("Attribute: form_name", "form_name", att.getName());
181
182
		options = att.getOptionValues().keySet().toArray();
183
		assertEquals("No form_name options", 0, options.length);
184
185
		// Attribute: bug_file_loc
186
		att = itr.next();
187
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
188
189
		options = att.getOptionValues().keySet().toArray();
190
		assertEquals("No bug_file_loc options", 0, options.length);
191
192
		// Attribute: priority
193
		att = itr.next();
194
		assertEquals("Attribute: priority", "priority", att.getName());
195
196
		options = att.getOptionValues().keySet().toArray();
197
		assertEquals("No priority options", 0, options.length);
198
199
	}
200
201
	// private void printList(List<Attribute> attributes) {
202
	//
203
	// Iterator<Attribute> itr = attributes.iterator();
204
	// System.out.println("Attributes for this Product:");
205
	// System.out.println("============================");
206
	//
207
	// while (itr.hasNext()) {
208
	// Attribute attr = itr.next();
209
	// System.out.println();
210
	// System.out.println(attr.getName() + ": ");
211
	// System.out.println("-----------");
212
	//
213
	// Map<String, String> options = attr.getOptionValues();
214
	// Object[] it = options.keySet().toArray();
215
	// for (int i = 0; i < it.length; i++)
216
	// System.out.println((String) it[i]);
217
	// }
218
	// }
219
}
(-)src/org/eclipse/mylar/tasklist/tests/BugzillaTaskTest.java (-9 / +21 lines)
Lines 11-24 Link Here
11
11
12
package org.eclipse.mylar.tasklist.tests;
12
package org.eclipse.mylar.tasklist.tests;
13
13
14
import java.util.Calendar;
14
import java.util.Date;
15
import java.util.Date;
15
16
16
import junit.framework.TestCase;
17
import junit.framework.TestCase;
17
18
18
import org.eclipse.mylar.bugzilla.core.Attribute;
19
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
19
import org.eclipse.mylar.bugzilla.core.BugReport;
20
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReportAttribute;
20
import org.eclipse.mylar.bugzilla.core.Comment;
22
import org.eclipse.mylar.bugzilla.core.Comment;
21
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
23
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
22
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
25
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
23
26
24
/**
27
/**
Lines 40-57 Link Here
40
43
41
	public void testCompletionDate() {
44
	public void testCompletionDate() {
42
		BugzillaTask task = new BugzillaTask("handle", "description", true);
45
		BugzillaTask task = new BugzillaTask("handle", "description", true);
43
		BugReport report = new BugReport(1, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
46
		BugzillaReport report = new BugzillaReport(1, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
44
		task.setBugReport(report);
47
		task.setBugReport(report);
45
		assertNull(task.getCompletionDate());
48
		assertNull(task.getCompletionDate());
46
49
47
		Date now = new Date();
50
		Calendar calendar = Calendar.getInstance();
48
		report.addComment(new Comment(report, 1, now, "author", "author-name"));
51
		calendar.set(Calendar.MILLISECOND, 0);
52
		calendar.getTimeInMillis();
53
		Date now = new Date(calendar.getTimeInMillis());
54
		
55
		Comment comment = new Comment(report, 1);
56
		AbstractRepositoryReportAttribute attribute = new BugzillaReportAttribute(BugzillaReportElement.CREATION_TS);
57
		attribute.setValue(Comment.creation_ts_date_format.format(now));	
58
		comment.addAttribute(BugzillaReportElement.CREATION_TS, attribute);
59
		report.addComment(comment);
49
		assertNull(task.getCompletionDate());
60
		assertNull(task.getCompletionDate());
50
61
51
		Attribute resolvedAttribute = new Attribute(BugReport.ATTR_STATUS);
62
		AbstractRepositoryReportAttribute resolvedAttribute = new BugzillaReportAttribute(BugzillaReportElement.BUG_STATUS);
52
		resolvedAttribute.setValue(BugReport.VAL_STATUS_RESOLVED);
63
		resolvedAttribute.setValue(BugzillaReport.VAL_STATUS_RESOLVED);
53
		report.addAttribute(resolvedAttribute);
64
		report.addAttribute(BugzillaReportElement.BUG_STATUS, resolvedAttribute);
54
		assertEquals(now, task.getCompletionDate());
65
		assertNotNull(task.getCompletionDate());
66
		assertEquals(Comment.creation_ts_date_format.format(now), Comment.creation_ts_date_format.format(task.getCompletionDate()));
55
67
56
	}
68
	}
57
69
(-)src/org/eclipse/mylar/tasklist/tests/TaskTestUtil.java (-25 / +33 lines)
Lines 21-30 Link Here
21
import java.util.Date;
21
import java.util.Date;
22
22
23
import org.eclipse.core.runtime.FileLocator;
23
import org.eclipse.core.runtime.FileLocator;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
24
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
25
import org.eclipse.mylar.bugzilla.core.BugReport;
25
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
26
import org.eclipse.mylar.bugzilla.core.BugzillaReportAttribute;
26
import org.eclipse.mylar.bugzilla.core.Comment;
27
import org.eclipse.mylar.bugzilla.core.Comment;
27
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
29
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
30
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
29
31
30
/**
32
/**
Lines 41-75 Link Here
41
			return null;
43
			return null;
42
		}
44
		}
43
	}
45
	}
44
	
46
45
	/**
47
	/**
46
	 * Adaptred from Java Developers' almanac
48
	 * Adaptred from Java Developers' almanac
47
	 */
49
	 */
48
    public static void copy(File source, File dest) throws IOException {
50
	public static void copy(File source, File dest) throws IOException {
49
        InputStream in = new FileInputStream(source);
51
		InputStream in = new FileInputStream(source);
50
        OutputStream out = new FileOutputStream(dest);
52
		OutputStream out = new FileOutputStream(dest);
51
        byte[] buf = new byte[1024];
53
		byte[] buf = new byte[1024];
52
        int len;
54
		int len;
53
        while ((len = in.read(buf)) > 0) {
55
		while ((len = in.read(buf)) > 0) {
54
            out.write(buf, 0, len);
56
			out.write(buf, 0, len);
55
        }
57
		}
56
        in.close();
58
		in.close();
57
        out.close();
59
		out.close();
58
    }
60
	}
59
	
61
60
	public static void setBugTaskCompleted(BugzillaTask bugzillaTask, boolean completed) {
62
	public static void setBugTaskCompleted(BugzillaTask bugzillaTask, boolean completed) {
61
		BugReport report = new BugReport(1, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
63
		BugzillaReport report = new BugzillaReport(1, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
62
		bugzillaTask.setBugReport(report);
64
		bugzillaTask.setBugReport(report);
63
		Attribute resolvedAttribute = new Attribute(BugReport.ATTR_STATUS);
65
		AbstractRepositoryReportAttribute resolvedAttribute = new BugzillaReportAttribute(
64
		if (completed) {
66
				BugzillaReportElement.BUG_STATUS);
65
			resolvedAttribute.setValue(BugReport.VAL_STATUS_RESOLVED);
67
		if (completed) {			
68
			resolvedAttribute.setValue(BugzillaReport.VAL_STATUS_RESOLVED);
69
			Comment comment = new Comment(report, 1);
70
			AbstractRepositoryReportAttribute attribute = new BugzillaReportAttribute(BugzillaReportElement.CREATION_TS);
71
			attribute.setValue(Comment.creation_ts_date_format.format(new Date()));	
72
			comment.addAttribute(BugzillaReportElement.CREATION_TS, attribute);
73
			report.addComment(comment);
66
		} else {
74
		} else {
67
			resolvedAttribute.setValue(BugReport.VAL_STATUS_NEW);
75
			resolvedAttribute.setValue(BugzillaReport.VAL_STATUS_NEW);
68
		}
76
		}
69
		
77
70
		report.addAttribute(resolvedAttribute);
78
		report.addAttribute(BugzillaReportElement.BUG_STATUS, resolvedAttribute);
71
		
79
		report.addComment(new Comment(report, 1));
72
		Date now = new Date();
80
		// report.addComment(new Comment(report, 1, now, "author",
73
		report.addComment(new Comment(report, 1, now, "author", "author-name"));
81
		// "author-name"));
74
	}
82
	}
75
}
83
}
(-)src/org/eclipse/mylar/provisional/tasklist/AbstractRepositoryConnector.java (-1 / +3 lines)
Lines 84-90 Link Here
84
	 *            set an exception on queryStatus.getChildren[0] to indicate
84
	 *            set an exception on queryStatus.getChildren[0] to indicate
85
	 *            failure
85
	 *            failure
86
	 */
86
	 */
87
	protected abstract List<AbstractQueryHit> performQuery(AbstractRepositoryQuery query, IProgressMonitor monitor,
87
	public abstract List<AbstractQueryHit> performQuery(AbstractRepositoryQuery query, IProgressMonitor monitor,
88
			MultiStatus queryStatus);
88
			MultiStatus queryStatus);
89
89
90
	protected abstract void updateOfflineState(AbstractRepositoryTask repositoryTask, boolean forceSync);
90
	protected abstract void updateOfflineState(AbstractRepositoryTask repositoryTask, boolean forceSync);
Lines 310-313 Link Here
310
				"Opening JIRA issues not added to task list is not implemented."
310
				"Opening JIRA issues not added to task list is not implemented."
311
		);
311
		);
312
	}
312
	}
313
314
	
313
}
315
}
(-)src/org/eclipse/mylar/internal/bugs/BugzillaContextLabelProvider.java (-2 / +2 lines)
Lines 11-17 Link Here
11
11
12
package org.eclipse.mylar.internal.bugs;
12
package org.eclipse.mylar.internal.bugs;
13
13
14
import org.eclipse.mylar.bugzilla.core.BugReport;
14
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
15
import org.eclipse.mylar.internal.bugs.search.BugzillaReferencesProvider;
15
import org.eclipse.mylar.internal.bugs.search.BugzillaReferencesProvider;
16
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaReportNode;
16
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaReportNode;
17
import org.eclipse.mylar.internal.tasklist.ui.TaskListImages;
17
import org.eclipse.mylar.internal.tasklist.ui.TaskListImages;
Lines 56-62 Link Here
56
		// try to get from the cache before downloading
56
		// try to get from the cache before downloading
57
		Object report;
57
		Object report;
58
		BugzillaReportNode reportNode = MylarBugsPlugin.getReferenceProvider().getCached(node.getHandleIdentifier());
58
		BugzillaReportNode reportNode = MylarBugsPlugin.getReferenceProvider().getCached(node.getHandleIdentifier());
59
		BugReport cachedReport = MylarBugsPlugin.getDefault().getCache().getCached(node.getHandleIdentifier());
59
		BugzillaReport cachedReport = MylarBugsPlugin.getDefault().getCache().getCached(node.getHandleIdentifier());
60
		IMylarStructureBridge bridge = MylarPlugin.getDefault()
60
		IMylarStructureBridge bridge = MylarPlugin.getDefault()
61
				.getStructureBridge(BugzillaStructureBridge.CONTENT_TYPE);
61
				.getStructureBridge(BugzillaStructureBridge.CONTENT_TYPE);
62
62
(-)src/org/eclipse/mylar/internal/bugs/BugzillaStructureBridge.java (-2 / +2 lines)
Lines 19-25 Link Here
19
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
21
import org.eclipse.jface.operation.IRunnableWithProgress;
22
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTools;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTools;
Lines 75-81 Link Here
75
		return null;
75
		return null;
76
	}
76
	}
77
77
78
	private BugReport result;
78
	private BugzillaReport result;
79
79
80
	/**
80
	/**
81
	 * TODO: this will not return a non-cached handle
81
	 * TODO: this will not return a non-cached handle
(-)src/org/eclipse/mylar/internal/bugs/BugzillaReportCache.java (-10 / +9 lines)
Lines 18-25 Link Here
18
18
19
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.Platform;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
22
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTools;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTools;
24
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaCacheFile;
23
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaCacheFile;
25
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
24
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
Lines 29-37 Link Here
29
 */
28
 */
30
public class BugzillaReportCache {
29
public class BugzillaReportCache {
31
30
32
	private Map<String, BugReport> cache = new HashMap<String, BugReport>();
31
	private Map<String, BugzillaReport> cache = new HashMap<String, BugzillaReport>();
33
32
34
	public void cache(String handle, BugReport report) {
33
	public void cache(String handle, BugzillaReport report) {
35
		cache.put(handle, report);
34
		cache.put(handle, report);
36
		cacheFile.add(report);
35
		cacheFile.add(report);
37
	}
36
	}
Lines 41-47 Link Here
41
		cacheFile.removeAll();
40
		cacheFile.removeAll();
42
	}
41
	}
43
42
44
	public BugReport getFromCache(String bugHandle) {
43
	public BugzillaReport getFromCache(String bugHandle) {
45
		return cache.get(bugHandle);
44
		return cache.get(bugHandle);
46
	}
45
	}
47
46
Lines 62-78 Link Here
62
61
63
		try {
62
		try {
64
			cacheFile = new BugzillaCacheFile(cachPath.toFile());
63
			cacheFile = new BugzillaCacheFile(cachPath.toFile());
65
			ArrayList<IBugzillaBug> cached = cacheFile.elements();
64
			ArrayList<BugzillaReport> cached = cacheFile.elements();
66
			for (IBugzillaBug bug : cached) {
65
			for (BugzillaReport bug : cached) {
67
				if (bug instanceof BugReport)
66
				if (bug instanceof BugzillaReport)
68
					cache.put(BugzillaTools.getHandle(bug), (BugReport) bug);
67
					cache.put(BugzillaTools.getHandle(bug), (BugzillaReport) bug);
69
			}
68
			}
70
		} catch (Exception e) {
69
		} catch (Exception e) {
71
			MylarStatusHandler.log(e, "occurred while restoring saved offline Bugzilla reports.");
70
			MylarStatusHandler.log(e, "occurred while restoring saved offline Bugzilla reports.");
72
		}
71
		}
73
	}
72
	}
74
73
75
	public BugReport getCached(String handle) {
74
	public BugzillaReport getCached(String handle) {
76
		return cache.get(handle);
75
		return cache.get(handle);
77
	}
76
	}
78
}
77
}
(-)src/org/eclipse/mylar/internal/bugs/search/BugzillaMylarSearchOperation.java (-4 / +4 lines)
Lines 28-34 Link Here
28
import org.eclipse.jdt.core.IMember;
28
import org.eclipse.jdt.core.IMember;
29
import org.eclipse.jdt.core.IType;
29
import org.eclipse.jdt.core.IType;
30
import org.eclipse.jface.resource.ImageDescriptor;
30
import org.eclipse.jface.resource.ImageDescriptor;
31
import org.eclipse.mylar.bugzilla.core.BugReport;
31
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
32
import org.eclipse.mylar.bugzilla.core.Comment;
32
import org.eclipse.mylar.bugzilla.core.Comment;
33
import org.eclipse.mylar.internal.bugs.MylarBugsPlugin;
33
import org.eclipse.mylar.internal.bugs.MylarBugsPlugin;
34
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
34
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
Lines 220-226 Link Here
220
220
221
				// we have a bugzilla task, so get the bug report
221
				// we have a bugzilla task, so get the bug report
222
				BugzillaTask bugTask = (BugzillaTask) task;
222
				BugzillaTask bugTask = (BugzillaTask) task;
223
				BugReport bug = bugTask.getBugReport();
223
				BugzillaReport bug = bugTask.getBugReport();
224
224
225
				// parse the bug report for the element that we are searching
225
				// parse the bug report for the element that we are searching
226
				// for
226
				// for
Lines 252-258 Link Here
252
	 * @param bug
252
	 * @param bug
253
	 *            The bug to search in
253
	 *            The bug to search in
254
	 */
254
	 */
255
	private boolean search(String elementName, BugReport bug) {
255
	private boolean search(String elementName, BugzillaReport bug) {
256
256
257
		if (bug == null)
257
		if (bug == null)
258
			return false; // MIK: added null check here
258
			return false; // MIK: added null check here
Lines 373-379 Link Here
373
373
374
			// get the bug report so that we have all of the data
374
			// get the bug report so that we have all of the data
375
			// - descriptions, comments, etc
375
			// - descriptions, comments, etc
376
			BugReport b = null;
376
			BugzillaReport b = null;
377
			try {
377
			try {
378
				b = info.getBug();
378
				b = info.getBug();
379
			} catch (Exception e) {
379
			} catch (Exception e) {
(-)src/org/eclipse/mylar/internal/ui/actions/ContextAttachAction.java (-8 / +1 lines)
Lines 13-25 Link Here
13
13
14
import org.eclipse.jface.action.IAction;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.dialogs.Dialog;
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.wizard.WizardDialog;
17
import org.eclipse.jface.wizard.WizardDialog;
19
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
18
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
20
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
19
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
21
import org.eclipse.mylar.internal.tasklist.ui.wizards.ContextAttachWizard;
20
import org.eclipse.mylar.internal.tasklist.ui.wizards.ContextAttachWizard;
22
import org.eclipse.mylar.provisional.core.MylarPlugin;
23
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
21
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
24
import org.eclipse.mylar.provisional.tasklist.ITask;
22
import org.eclipse.mylar.provisional.tasklist.ITask;
25
import org.eclipse.swt.widgets.Shell;
23
import org.eclipse.swt.widgets.Shell;
Lines 44-55 Link Here
44
	public void run(IAction action) {
42
	public void run(IAction action) {
45
		ITask task = TaskListView.getDefault().getSelectedTask();
43
		ITask task = TaskListView.getDefault().getSelectedTask();
46
		if (task instanceof AbstractRepositoryTask) {
44
		if (task instanceof AbstractRepositoryTask) {
47
			try {
45
			try {	
48
				if (!MylarPlugin.getContextManager().hasContext(task.getHandleIdentifier())) {
49
					MessageDialog.openInformation(null, "Attach Context", "No context exists for selected task.");
50
					return;
51
				}
52
				
53
				ContextAttachWizard wizard = new ContextAttachWizard((AbstractRepositoryTask)task);
46
				ContextAttachWizard wizard = new ContextAttachWizard((AbstractRepositoryTask)task);
54
				Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
47
				Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
55
				if (wizard != null && shell != null && !shell.isDisposed()) {
48
				if (wizard != null && shell != null && !shell.isDisposed()) {
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaNewBugParserTestCDT.java (-213 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes for new bug reports
31
 */
32
public class BugzillaNewBugParserTestCDT extends TestCase {
33
34
	public BugzillaNewBugParserTestCDT() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestCDT(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductCDT() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/cdt-page.html"));
45
46
		Reader in = new FileReader(f);
47
48
		NewBugModel nbm = new NewBugModel();
49
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
50
															// **
51
52
		// attributes for this bug model
53
		List<Attribute> attributes = nbm.getAttributes();
54
		// printList(attributes);
55
56
		Iterator<Attribute> itr = attributes.iterator();
57
		Attribute att = itr.next();
58
59
		// Attribute: Severity
60
		assertEquals("Attribute: Severity", "Severity", att.getName());
61
62
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
63
		// options for the
64
		// current
65
		// attribute
66
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
67
		// the options of the
68
		// current attribute
69
		assertEquals("# Severity options", 7, options.length);
70
71
		int i = 0;
72
		while (i < options.length) {
73
			assertEquals("severity options", "blocker", options[i++]);
74
			assertEquals("severity options", "critical", options[i++]);
75
			assertEquals("severity options", "major", options[i++]);
76
			assertEquals("severity options", "normal", options[i++]);
77
			assertEquals("severity options", "minor", options[i++]);
78
			assertEquals("severity options", "trivial", options[i++]);
79
			assertEquals("severity options", "enhancement", options[i++]);
80
		}
81
82
		// Attribute: product
83
		att = itr.next();
84
		assertEquals("Attribute: product", "product", att.getName());
85
86
		attOptions = att.getOptionValues();
87
		options = attOptions.keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		attOptions = att.getOptionValues();
95
		options = attOptions.keySet().toArray();
96
		assertEquals("No AssignedTo options", 0, options.length);
97
98
		// Attribute: OS
99
		att = itr.next();
100
		assertEquals("Attribute: OS", "OS", att.getName());
101
102
		attOptions = att.getOptionValues();
103
		options = attOptions.keySet().toArray();
104
		assertEquals("# of options", 20, options.length);
105
106
		i = 0;
107
		while (i < options.length) {
108
			assertEquals("OS options", "All", options[i++]);
109
			assertEquals("OS options", "AIX Motif", options[i++]);
110
			assertEquals("OS options", "Windows 95", options[i++]);
111
			assertEquals("OS options", "Windows 98", options[i++]);
112
			assertEquals("OS options", "Windows CE", options[i++]);
113
			assertEquals("OS options", "Windows ME", options[i++]);
114
			assertEquals("OS options", "Windows 2000", options[i++]);
115
			assertEquals("OS options", "Windows NT", options[i++]);
116
			assertEquals("OS options", "Windows XP", options[i++]);
117
			assertEquals("OS options", "Windows All", options[i++]);
118
			assertEquals("OS options", "MacOS X", options[i++]);
119
			assertEquals("OS options", "Linux", options[i++]);
120
			assertEquals("OS options", "Linux-GTK", options[i++]);
121
			assertEquals("OS options", "Linux-Motif", options[i++]);
122
			assertEquals("OS options", "HP-UX", options[i++]);
123
			assertEquals("OS options", "Neutrino", options[i++]);
124
			assertEquals("OS options", "QNX-Photon", options[i++]);
125
			assertEquals("OS options", "Solaris", options[i++]);
126
			assertEquals("OS options", "Unix All", options[i++]);
127
			assertEquals("OS options", "other", options[i++]);
128
		}
129
130
		// Attribute: Version
131
		att = itr.next();
132
		assertEquals("Attribute: Version", "Version", att.getName());
133
134
		// attOptions = (HashMap) att.getOptionValues();
135
		options = att.getOptionValues().keySet().toArray();
136
		assertEquals("# Version options", 5, options.length);
137
138
		i = 0;
139
		while (i < options.length) {
140
			assertEquals("Version options", "1.0", options[i++]);
141
			assertEquals("Version options", "1.0.1", options[i++]);
142
			assertEquals("Version options", "1.1", options[i++]);
143
			assertEquals("Version options", "1.2", options[i++]);
144
			assertEquals("Version options", "2.0", options[i++]);
145
		}
146
147
		// Attribute: Platform
148
		att = itr.next();
149
		assertEquals("Attribute: Platform", "Platform", att.getName());
150
151
		options = att.getOptionValues().keySet().toArray();
152
		assertEquals("# Platform options", 6, options.length);
153
154
		i = 0;
155
		while (i < options.length) {
156
			assertEquals("Platform options", "All", options[i++]);
157
			assertEquals("Platform options", "Macintosh", options[i++]);
158
			assertEquals("Platform options", "PC", options[i++]);
159
			assertEquals("Platform options", "Power PC", options[i++]);
160
			assertEquals("Platform options", "Sun", options[i++]);
161
			assertEquals("Platform options", "Other", options[i++]);
162
		}
163
164
		// Attribute: Component
165
		att = itr.next();
166
		assertEquals("Attribute: Component", "Component", att.getName());
167
168
		options = att.getOptionValues().keySet().toArray();
169
		assertEquals("# Component options", 9, options.length);
170
171
		i = 0;
172
		while (i < options.length) {
173
			assertEquals("Component options", "CDT-parser", options[i++]);
174
			assertEquals("Component options", "Core", options[i++]);
175
			assertEquals("Component options", "Cpp-Extensions", options[i++]);
176
			assertEquals("Component options", "Debug", options[i++]);
177
			assertEquals("Component options", "Debug-MI", options[i++]);
178
			assertEquals("Component options", "Doc", options[i++]);
179
			assertEquals("Component options", "Generic-Extensions", options[i++]);
180
			assertEquals("Component options", "Launcher", options[i++]);
181
			assertEquals("Component options", "UI", options[i++]);
182
		}
183
184
		// Attribute: bug_status
185
		att = itr.next();
186
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
187
188
		options = att.getOptionValues().keySet().toArray();
189
		assertEquals("# bug_status options [none]", 0, options.length);
190
191
		// Attribute: form_name
192
		att = itr.next();
193
		assertEquals("Attribute: form_name", "form_name", att.getName());
194
195
		options = att.getOptionValues().keySet().toArray();
196
		assertEquals("No form_name options", 0, options.length);
197
198
		// Attribute: bug_file_loc
199
		att = itr.next();
200
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
201
202
		options = att.getOptionValues().keySet().toArray();
203
		assertEquals("No bug_file_loc options", 0, options.length);
204
205
		// Attribute: priority
206
		att = itr.next();
207
		assertEquals("Attribute: priority", "priority", att.getName());
208
209
		options = att.getOptionValues().keySet().toArray();
210
		assertEquals("No priority options", 0, options.length);
211
212
	}
213
}
(-)src/org/eclipse/mylar/bugzilla/tests/Bugzilla220ParserTest.java (-92 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
18
import junit.framework.TestCase;
19
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.core.tests.support.FileTool;
23
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
27
28
/**
29
 * @author Mik Kersten
30
 * @author Rob Elves
31
 */
32
public class Bugzilla220ParserTest extends TestCase {
33
34
	public static final String TEST_SERVER = IBugzillaConstants.ECLIPSE_BUGZILLA_URL;
35
	
36
	private static final String PRODUCT_MYLAR = "Mylar";
37
38
	private static final String PRODUCT_TEST = "TestProduct";
39
40
	public void testId220() throws Exception {
41
42
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
43
				"testdata/pages/test-report-220.html"));
44
		Reader in = new FileReader(f);
45
46
		BugReport bug = BugParser.parseBug(in, 7, TEST_SERVER, false, null, null, null);
47
48
		assertEquals(7, bug.getId());
49
		assertEquals("summary", bug.getSummary());
50
		assertEquals("7", bug.getAttribute("Bug#").getValue());
51
		assertEquals("7", bug.getAttribute("id").getValue());
52
	}
53
54
	public void testId2201() throws Exception {
55
56
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
57
				"testdata/pages/test-report-2201.html"));
58
		Reader in = new FileReader(f);
59
60
		BugReport bug = BugParser.parseBug(in, 125527, TEST_SERVER, false, null, null, null);
61
62
		assertEquals(125527, bug.getId());
63
		assertEquals("bugzilla refresh incorrect for new reports and newly opened hits", bug.getSummary());
64
		assertEquals("125527", bug.getAttribute("Bug#").getValue());
65
		assertEquals("125527", bug.getAttribute("id").getValue());
66
	}
67
68
	public void testNewBugProduct220() throws Exception {
69
70
		NewBugModel nbm = new NewBugModel();
71
72
		File f = FileTool
73
				.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/enter-bug220.html"));
74
		Reader in = new FileReader(f);
75
76
		new NewBugParser(in).parseBugAttributes(nbm, true);
77
		assertEquals(PRODUCT_TEST, nbm.getAttribute("product").getValue());
78
	}
79
80
	public void testNewBugProduct2201() throws Exception {
81
82
		NewBugModel nbm = new NewBugModel();
83
84
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(),
85
				new Path("testdata/pages/enter-bug2201.html"));
86
		Reader in = new FileReader(f);
87
88
		new NewBugParser(in).parseBugAttributes(nbm, true);
89
		assertEquals(PRODUCT_MYLAR, nbm.getAttribute("product").getValue());
90
	}
91
92
}
(-)src/org/eclipse/mylar/bugzilla/tests/ReportAttachmentTest.java (-77 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.net.URL;
18
19
import junit.framework.TestCase;
20
21
import org.eclipse.core.runtime.FileLocator;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.mylar.bugzilla.core.BugReport;
24
import org.eclipse.mylar.core.tests.support.FileTool;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
27
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
29
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
30
31
/**
32
 * @author Rob Elves
33
 */
34
public class ReportAttachmentTest extends TestCase {
35
36
	public void testExistingBugWithAttachment() throws Exception {
37
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
38
				"testdata/pages/test-report-222attachment.html"));
39
		Reader in = new FileReader(f);
40
41
		BugReport bug = BugParser.parseBug(in, 4, IBugzillaConstants.ECLIPSE_BUGZILLA_URL, false, null, null, null);
42
		
43
		assertEquals(4, bug.getId());
44
		assertEquals("4", bug.getAttribute("Bug#").getValue());
45
		assertEquals("4", bug.getAttribute("id").getValue());
46
		
47
		assertNotNull(bug.getComments());
48
		assertEquals(1, bug.getComments().size());
49
		assertTrue(bug.getComments().get(0).hasAttachment());
50
		assertEquals("Testing upload", bug.getComments().get(0).getAttachmentDescription());
51
//		System.err.println(bug.getComments().get(0).getText());
52
//		assertEquals(1, bug.getAttachements().size());
53
//		assertEquals("Testing upload", bug.getAttachements().get(1));
54
	}
55
	
56
	public void testAttachementDownload() throws Exception {
57
		URL localURL = null;
58
		URL installURL = BugzillaTestPlugin.getDefault().getBundle().getEntry("testdata/contexts/");
59
//		File destinationFile = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/contexts/"));
60
		localURL = FileLocator.toFileURL(installURL); 
61
		File destinationFile = new File(localURL.getPath()+"downloadedContext.xml");
62
		
63
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
64
		boolean result = BugzillaRepositoryUtil.downloadAttachment(repository, 2, destinationFile, true);
65
		assertTrue(result);
66
	}
67
	
68
//	public void testAttachementUpload() throws Exception {
69
//		File sourceFile = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
70
//		"testdata/contexts/downloadedContext.xml"));
71
//		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
72
//		repository.setAuthenticationCredentials("relves@cs.ubc.ca", "***");
73
//		boolean result = BugzillaRepositoryUtil.uploadAttachment(repository, 4, "Upload Comment 2", "Upload Description 2", sourceFile, "application/xml", false);		
74
//		assertTrue(result);
75
//	}
76
	
77
}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaNewBugParserTestGMT.java (-219 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestGMT extends TestCase {
33
34
	public BugzillaNewBugParserTestGMT() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestGMT(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductGMT() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/gmt-page.html"));
45
46
		Reader in = new FileReader(f);
47
48
		NewBugModel nbm = new NewBugModel();
49
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
50
															// **
51
52
		// attributes for this bug model
53
		List<Attribute> attributes = nbm.getAttributes();
54
		// printList(attributes);
55
56
		Iterator<Attribute> itr = attributes.iterator();
57
		Attribute att = itr.next();
58
59
		// Attribute: Severity
60
		assertEquals("Attribute: Severity", "Severity", att.getName());
61
62
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
63
		// options for the
64
		// current
65
		// attribute
66
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
67
		// the options of the
68
		// current attribute
69
		assertEquals("# Severity options", 7, options.length);
70
71
		int i = 0;
72
		while (i < options.length) {
73
			assertEquals("severity options", "blocker", options[i++]);
74
			assertEquals("severity options", "critical", options[i++]);
75
			assertEquals("severity options", "major", options[i++]);
76
			assertEquals("severity options", "normal", options[i++]);
77
			assertEquals("severity options", "minor", options[i++]);
78
			assertEquals("severity options", "trivial", options[i++]);
79
			assertEquals("severity options", "enhancement", options[i++]);
80
		}
81
82
		// Attribute: product
83
		att = itr.next();
84
		assertEquals("Attribute: product", "product", att.getName());
85
86
		attOptions = att.getOptionValues();
87
		options = attOptions.keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		attOptions = att.getOptionValues();
95
		options = attOptions.keySet().toArray();
96
		assertEquals("No AssignedTo options", 0, options.length);
97
98
		// Attribute: OS
99
		att = itr.next();
100
		assertEquals("Attribute: OS", "OS", att.getName());
101
102
		attOptions = att.getOptionValues();
103
		options = attOptions.keySet().toArray();
104
		assertEquals("# of options", 20, options.length);
105
106
		i = 0;
107
		while (i < options.length) {
108
			assertEquals("OS options", "All", options[i++]);
109
			assertEquals("OS options", "AIX Motif", options[i++]);
110
			assertEquals("OS options", "Windows 95", options[i++]);
111
			assertEquals("OS options", "Windows 98", options[i++]);
112
			assertEquals("OS options", "Windows CE", options[i++]);
113
			assertEquals("OS options", "Windows ME", options[i++]);
114
			assertEquals("OS options", "Windows 2000", options[i++]);
115
			assertEquals("OS options", "Windows NT", options[i++]);
116
			assertEquals("OS options", "Windows XP", options[i++]);
117
			assertEquals("OS options", "Windows All", options[i++]);
118
			assertEquals("OS options", "MacOS X", options[i++]);
119
			assertEquals("OS options", "Linux", options[i++]);
120
			assertEquals("OS options", "Linux-GTK", options[i++]);
121
			assertEquals("OS options", "Linux-Motif", options[i++]);
122
			assertEquals("OS options", "HP-UX", options[i++]);
123
			assertEquals("OS options", "Neutrino", options[i++]);
124
			assertEquals("OS options", "QNX-Photon", options[i++]);
125
			assertEquals("OS options", "Solaris", options[i++]);
126
			assertEquals("OS options", "Unix All", options[i++]);
127
			assertEquals("OS options", "other", options[i++]);
128
		}
129
130
		// Attribute: Version
131
		att = itr.next();
132
		assertEquals("Attribute: Version", "Version", att.getName());
133
134
		// attOptions = (HashMap) att.getOptionValues();
135
		options = att.getOptionValues().keySet().toArray();
136
		assertEquals("# Version options", 1, options.length);
137
138
		i = 0;
139
		while (i < options.length) {
140
			assertEquals("Version options", "unspecified", options[i++]);
141
		}
142
143
		// Attribute: Platform
144
		att = itr.next();
145
		assertEquals("Attribute: Platform", "Platform", att.getName());
146
147
		options = att.getOptionValues().keySet().toArray();
148
		assertEquals("# Platform options", 6, options.length);
149
150
		i = 0;
151
		while (i < options.length) {
152
			assertEquals("Platform options", "All", options[i++]);
153
			assertEquals("Platform options", "Macintosh", options[i++]);
154
			assertEquals("Platform options", "PC", options[i++]);
155
			assertEquals("Platform options", "Power PC", options[i++]);
156
			assertEquals("Platform options", "Sun", options[i++]);
157
			assertEquals("Platform options", "Other", options[i++]);
158
		}
159
160
		att = itr.next();
161
		assertEquals("Attribute: Component", "Component", att.getName());
162
163
		options = att.getOptionValues().keySet().toArray();
164
		assertEquals("# Component options", 1, options.length);
165
166
		i = 0;
167
		while (i < options.length) {
168
			assertEquals("Component options", "Core", options[i++]);
169
		}
170
171
		// Attribute: bug_status
172
		att = itr.next();
173
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
174
175
		options = att.getOptionValues().keySet().toArray();
176
		assertEquals("No bug_status options", 0, options.length);
177
178
		// Attribute: form_name
179
		att = itr.next();
180
		assertEquals("Attribute: form_name", "form_name", att.getName());
181
182
		options = att.getOptionValues().keySet().toArray();
183
		assertEquals("No form_name options", 0, options.length);
184
185
		// Attribute: bug_file_loc
186
		att = itr.next();
187
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
188
189
		options = att.getOptionValues().keySet().toArray();
190
		assertEquals("No bug_file_loc options", 0, options.length);
191
192
		// Attribute: priority
193
		att = itr.next();
194
		assertEquals("Attribute: priority", "priority", att.getName());
195
196
		options = att.getOptionValues().keySet().toArray();
197
		assertEquals("No priority options", 0, options.length);
198
199
	}
200
201
	// private void printList(List<Attribute> attributes) {
202
	//
203
	// Iterator<Attribute> itr = attributes.iterator();
204
	// System.out.println("Attributes for this Product:");
205
	// System.out.println("============================");
206
	//
207
	// while (itr.hasNext()) {
208
	// Attribute attr = itr.next();
209
	// System.out.println();
210
	// System.out.println(attr.getName() + ": ");
211
	// System.out.println("-----------");
212
	//
213
	// Map<String, String> options = attr.getOptionValues();
214
	// Object[] it = options.keySet().toArray();
215
	// for (int i = 0; i < it.length; i++)
216
	// System.out.println((String) it[i]);
217
	// }
218
	// }
219
}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaConfigurationTest.java (-19 / +27 lines)
Lines 15-23 Link Here
15
15
16
import junit.framework.TestCase;
16
import junit.framework.TestCase;
17
17
18
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
18
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
19
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
19
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
20
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfiguration;
20
import org.eclipse.mylar.internal.bugzilla.core.internal.ServerConfigurationFactory;
21
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryConfigurationFactory;
22
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
21
23
22
public class BugzillaConfigurationTest extends TestCase {
24
public class BugzillaConfigurationTest extends TestCase {
23
25
Lines 31-38 Link Here
31
33
32
	
34
	
33
	public void test222RDFProductConfig() throws IOException {
35
	public void test222RDFProductConfig() throws IOException {
34
		ServerConfigurationFactory factory = ServerConfigurationFactory.getInstance();
36
		RepositoryConfigurationFactory factory = RepositoryConfigurationFactory.getInstance();
35
		RepositoryConfiguration config = factory.getConfiguration(IBugzillaConstants.TEST_BUGZILLA_222_URL);
37
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
38
		RepositoryConfiguration config = factory.getConfiguration(repository);
36
		assertNotNull(config);
39
		assertNotNull(config);
37
		assertEquals("2.22rc1", config.getInstallVersion());
40
		assertEquals("2.22rc1", config.getInstallVersion());
38
		assertEquals(7, config.getStatusValues().size());
41
		assertEquals(7, config.getStatusValues().size());
Lines 47-56 Link Here
47
		assertEquals(1, config.getVersions("TestProduct").size());
50
		assertEquals(1, config.getVersions("TestProduct").size());
48
		assertEquals(1, config.getTargetMilestones("TestProduct").size());
51
		assertEquals(1, config.getTargetMilestones("TestProduct").size());
49
	}
52
	}
50
	
53
		
51
	public void test2201RDFProductConfig() throws IOException {
54
	public void test2201RDFProductConfig() throws IOException {
52
		ServerConfigurationFactory factory = ServerConfigurationFactory.getInstance();
55
		RepositoryConfigurationFactory factory = RepositoryConfigurationFactory.getInstance();
53
		RepositoryConfiguration config = factory.getConfiguration(IBugzillaConstants.TEST_BUGZILLA_2201_URL);
56
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_2201_URL);
57
		RepositoryConfiguration config = factory.getConfiguration(repository);
54
		assertNotNull(config);
58
		assertNotNull(config);
55
		assertEquals("2.20.1", config.getInstallVersion());
59
		assertEquals("2.20.1", config.getInstallVersion());
56
		assertEquals(7, config.getStatusValues().size());
60
		assertEquals(7, config.getStatusValues().size());
Lines 63-74 Link Here
63
		assertEquals(4, config.getOpenStatusValues().size());
67
		assertEquals(4, config.getOpenStatusValues().size());
64
		assertEquals(2, config.getComponents("TestProduct").size());
68
		assertEquals(2, config.getComponents("TestProduct").size());
65
		assertEquals(1, config.getVersions("TestProduct").size());	
69
		assertEquals(1, config.getVersions("TestProduct").size());	
66
		//assertEquals(1, config.getTargetMilestones("TestProduct").size());
70
		// assertEquals(1, config.getTargetMilestones("TestProduct").size());
67
	}
71
	}
68
	
72
	
69
	public void test220RDFProductConfig() throws IOException {
73
	public void test220RDFProductConfig() throws IOException {
70
		ServerConfigurationFactory factory = ServerConfigurationFactory.getInstance();
74
		RepositoryConfigurationFactory factory = RepositoryConfigurationFactory.getInstance();
71
		RepositoryConfiguration config = factory.getConfiguration(IBugzillaConstants.TEST_BUGZILLA_220_URL);
75
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_220_URL);
76
		RepositoryConfiguration config = factory.getConfiguration(repository);
72
		assertNotNull(config);
77
		assertNotNull(config);
73
		assertEquals("2.20", config.getInstallVersion());
78
		assertEquals("2.20", config.getInstallVersion());
74
		assertEquals(7, config.getStatusValues().size());
79
		assertEquals(7, config.getStatusValues().size());
Lines 81-110 Link Here
81
		assertEquals(4, config.getOpenStatusValues().size());
86
		assertEquals(4, config.getOpenStatusValues().size());
82
		assertEquals(2, config.getComponents("TestProduct").size());
87
		assertEquals(2, config.getComponents("TestProduct").size());
83
		assertEquals(1, config.getVersions("TestProduct").size());
88
		assertEquals(1, config.getVersions("TestProduct").size());
84
		//assertEquals(1, config.getTargetMilestones("TestProduct").size());
89
		// assertEquals(1, config.getTargetMilestones("TestProduct").size());
85
	}
90
	}
86
	
91
	
87
	public void test218RDFProductConfig() throws IOException {
92
	public void test218RDFProductConfig() throws IOException {
88
		ServerConfigurationFactory factory = ServerConfigurationFactory.getInstance();
93
		RepositoryConfigurationFactory factory = RepositoryConfigurationFactory.getInstance();
89
		RepositoryConfiguration config = factory.getConfiguration(IBugzillaConstants.TEST_BUGZILLA_218_URL);
94
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_218_URL);
95
		RepositoryConfiguration config = factory.getConfiguration(repository);
90
		assertNotNull(config);
96
		assertNotNull(config);
91
		assertEquals("2.18.5", config.getInstallVersion());
97
		assertEquals("2.18.5", config.getInstallVersion());
92
		assertEquals(7, config.getStatusValues().size());
98
		assertEquals(7, config.getStatusValues().size());
93
		assertEquals(8, config.getResolutions().size());
99
		assertEquals(8, config.getResolutions().size());
94
		assertEquals(8, config.getPlatforms().size());
100
		assertEquals(8, config.getPlatforms().size());
95
		assertEquals(37, config.getOSs().size());
101
		assertEquals(36, config.getOSs().size());
96
		assertEquals(5, config.getPriorities().size());
102
		assertEquals(5, config.getPriorities().size());
97
		assertEquals(7, config.getSeverities().size());
103
		assertEquals(7, config.getSeverities().size());
98
		assertEquals(1, config.getProducts().size());
104
		assertEquals(1, config.getProducts().size());
99
		assertEquals(4, config.getOpenStatusValues().size());
105
		assertEquals(4, config.getOpenStatusValues().size());
100
		assertEquals(1, config.getComponents("TestProduct").size());
106
		assertEquals(1, config.getComponents("TestProduct").size());
101
		assertEquals(1, config.getVersions("TestProduct").size());
107
		assertEquals(1, config.getVersions("TestProduct").size());
102
		//assertEquals(1, config.getTargetMilestones("TestProduct").size());
108
		// assertEquals(1, config.getTargetMilestones("TestProduct").size());
103
	}
109
	}
104
	
110
	
105
	public void testEclipseRDFProductConfig() throws IOException {
111
	public void testEclipseRDFProductConfig() throws IOException {
106
		ServerConfigurationFactory factory = ServerConfigurationFactory.getInstance();
112
		RepositoryConfigurationFactory factory = RepositoryConfigurationFactory.getInstance();
107
		RepositoryConfiguration config = factory.getConfiguration(IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
113
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
114
		RepositoryConfiguration config = factory.getConfiguration(repository);
108
		assertNotNull(config);
115
		assertNotNull(config);
109
		assertEquals("2.20.1", config.getInstallVersion());
116
		assertEquals("2.20.1", config.getInstallVersion());
110
		assertEquals(7, config.getStatusValues().size());
117
		assertEquals(7, config.getStatusValues().size());
Lines 113-122 Link Here
113
		assertEquals(27, config.getOSs().size());
120
		assertEquals(27, config.getOSs().size());
114
		assertEquals(5, config.getPriorities().size());
121
		assertEquals(5, config.getPriorities().size());
115
		assertEquals(7, config.getSeverities().size());
122
		assertEquals(7, config.getSeverities().size());
116
		assertEquals(53, config.getProducts().size());
123
		assertEquals(52, config.getProducts().size());
117
		assertEquals(4, config.getOpenStatusValues().size());
124
		assertEquals(4, config.getOpenStatusValues().size());
118
		assertEquals(10, config.getComponents("Mylar").size());
125
		assertEquals(10, config.getComponents("Mylar").size());
119
		//assertEquals(10, config.getComponents("Hyades").size());
126
		assertEquals(21, config.getKeywords().size());
120
		//assertEquals(1, config.getTargetMilestones("TestProduct").size());
127
		// assertEquals(10, config.getComponents("Hyades").size());
128
		// assertEquals(1, config.getTargetMilestones("TestProduct").size());
121
	}
129
	}
122
}
130
}
(-)src/org/eclipse/mylar/bugzilla/tests/AllBugzillaTests.java (-5 / +5 lines)
Lines 21-41 Link Here
21
	public static Test suite() {
21
	public static Test suite() {
22
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.bugzilla.tests");
22
		TestSuite suite = new TestSuite("Test for org.eclipse.mylar.bugzilla.tests");
23
		// $JUnit-BEGIN$
23
		// $JUnit-BEGIN$
24
		suite.addTestSuite(RepositoryReportFactoryTest.class);
24
		suite.addTestSuite(BugzillaConfigurationTest.class);
25
		suite.addTestSuite(BugzillaConfigurationTest.class);
25
		suite.addTestSuite(BugzillaTaskHyperlinkDetectorTest.class);
26
		suite.addTestSuite(BugzillaTaskHyperlinkDetectorTest.class);		
26
		suite.addTestSuite(ReportAttachmentTest.class);
27
		suite.addTestSuite(BugzillaSearchEngineTest.class);
27
		suite.addTestSuite(BugzillaSearchEngineTest.class);
28
		suite.addTestSuite(Bugzilla220ParserTest.class);
28
		//suite.addTestSuite(Bugzilla220ParserTest.class);
29
		suite.addTestSuite(BugzillaRepositoryConnectorTest.class);
29
		suite.addTestSuite(BugzillaRepositoryConnectorTest.class);
30
		suite.addTestSuite(EncodingTest.class);
30
		suite.addTestSuite(EncodingTest.class);
31
		suite.addTestSuite(NewBugWizardTest.class);
31
		//suite.addTestSuite(NewBugWizardTest.class);
32
		suite.addTestSuite(RegularExpressionMatchTest.class);
32
		suite.addTestSuite(RegularExpressionMatchTest.class);
33
		// suite.addTestSuite(BugzillaNewBugParserTestCDT.class);
33
		// suite.addTestSuite(BugzillaNewBugParserTestCDT.class);
34
		// suite.addTestSuite(BugzillaNewBugParserTestEquinox.class);
34
		// suite.addTestSuite(BugzillaNewBugParserTestEquinox.class);
35
		// suite.addTestSuite(BugzillaNewBugParserTestGMT.class);
35
		// suite.addTestSuite(BugzillaNewBugParserTestGMT.class);
36
		// suite.addTestSuite(BugzillaNewBugParserTestPlatform.class);
36
		// suite.addTestSuite(BugzillaNewBugParserTestPlatform.class);
37
		// suite.addTestSuite(BugzillaNewBugParserTestVE.class);
37
		// suite.addTestSuite(BugzillaNewBugParserTestVE.class);
38
		suite.addTestSuite(BugzillaParserTestNoBug.class);
38
		//suite.addTestSuite(BugzillaParserTestNoBug.class);
39
		suite.addTestSuite(BugzillaProductParserTest.class);
39
		suite.addTestSuite(BugzillaProductParserTest.class);
40
		// TODO: enable
40
		// TODO: enable
41
		// suite.addTest(new TestSuite(BugzillaParserTest.class));
41
		// suite.addTest(new TestSuite(BugzillaParserTest.class));
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaNewBugParserTestPlatform.java (-246 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestPlatform extends TestCase {
33
34
	public BugzillaNewBugParserTestPlatform() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestPlatform(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductPlatform() throws Exception {
43
44
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(),
45
				new Path("testdata/pages/platform-page.html"));
46
47
		Reader in = new FileReader(f);
48
49
		NewBugModel nbm = new NewBugModel();
50
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
51
															// **
52
53
		// attributes for this bug model
54
		List<Attribute> attributes = nbm.getAttributes();
55
		// printList(attributes);
56
57
		// to iterator over the ArrayList of attributes
58
		Iterator<Attribute> itr = attributes.iterator();
59
60
		// Attribute: Severity
61
		Attribute att = itr.next(); // current attribute
62
63
		// Attribute: Severity
64
		assertEquals("Attribute: Severity", "Severity", att.getName());
65
66
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
67
		// options for the
68
		// current
69
		// attribute
70
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
71
		// the options of the
72
		// current attribute
73
		assertEquals("# Severity options", 7, options.length);
74
75
		int i = 0;
76
		while (i < options.length) {
77
			assertEquals("severity options", "blocker", options[i++]);
78
			assertEquals("severity options", "critical", options[i++]);
79
			assertEquals("severity options", "major", options[i++]);
80
			assertEquals("severity options", "normal", options[i++]);
81
			assertEquals("severity options", "minor", options[i++]);
82
			assertEquals("severity options", "trivial", options[i++]);
83
			assertEquals("severity options", "enhancement", options[i++]);
84
		}
85
86
		// Attribute: product
87
		att = itr.next();
88
		assertEquals("Attribute: product", "product", att.getName());
89
90
		attOptions = att.getOptionValues();
91
		options = attOptions.keySet().toArray();
92
		assertEquals("No product optins", 0, options.length);
93
94
		// Attribute: AssignedTo
95
		att = itr.next();
96
		assertEquals("Attribute: Assigned To", "Assigned To", att.getName());
97
98
		options = att.getOptionValues().keySet().toArray();
99
		assertEquals("No AssingedTo options", 0, options.length);
100
101
		// Attribute: OS
102
		att = itr.next();
103
		assertEquals("Attribute: OS", "OS", att.getName());
104
105
		attOptions = att.getOptionValues();
106
		options = attOptions.keySet().toArray();
107
		assertEquals("# OS options", 20, options.length);
108
109
		i = 0;
110
		while (i < options.length) {
111
			assertEquals("OS options", "All", options[i++]);
112
			assertEquals("OS options", "AIX Motif", options[i++]);
113
			assertEquals("OS options", "Windows 95", options[i++]);
114
			assertEquals("OS options", "Windows 98", options[i++]);
115
			assertEquals("OS options", "Windows CE", options[i++]);
116
			assertEquals("OS options", "Windows ME", options[i++]);
117
			assertEquals("OS options", "Windows 2000", options[i++]);
118
			assertEquals("OS options", "Windows NT", options[i++]);
119
			assertEquals("OS options", "Windows XP", options[i++]);
120
			assertEquals("OS options", "Windows All", options[i++]);
121
			assertEquals("OS options", "MacOS X", options[i++]);
122
			assertEquals("OS options", "Linux", options[i++]);
123
			assertEquals("OS options", "Linux-GTK", options[i++]);
124
			assertEquals("OS options", "Linux-Motif", options[i++]);
125
			assertEquals("OS options", "HP-UX", options[i++]);
126
			assertEquals("OS options", "Neutrino", options[i++]);
127
			assertEquals("OS options", "QNX-Photon", options[i++]);
128
			assertEquals("OS options", "Solaris", options[i++]);
129
			assertEquals("OS options", "Unix All", options[i++]);
130
			assertEquals("OS options", "other", options[i++]);
131
		}
132
133
		// Attribute: Version
134
		att = itr.next();
135
		assertEquals("Attribute: Version", "Version", att.getName());
136
137
		attOptions = att.getOptionValues();
138
		options = attOptions.keySet().toArray();
139
		assertEquals("# Version options", 8, options.length);
140
141
		i = 0;
142
		while (i < options.length) {
143
			assertEquals("Version options", "1.0", options[i++]);
144
			assertEquals("Version options", "2.0", options[i++]);
145
			assertEquals("Version options", "2.0.1", options[i++]);
146
			assertEquals("Version options", "2.0.2", options[i++]);
147
			assertEquals("Version options", "2.1", options[i++]);
148
			assertEquals("Version options", "2.1.1", options[i++]);
149
			assertEquals("Version options", "2.1.2", options[i++]);
150
			assertEquals("Version options", "3.0", options[i++]);
151
		}
152
153
		// Attribute: Platform
154
		att = itr.next();
155
		assertEquals("Attribute: Platform", "Platform", att.getName());
156
157
		options = att.getOptionValues().keySet().toArray();
158
		assertEquals("# Platform options", 6, options.length);
159
160
		i = 0;
161
		while (i < options.length) {
162
			assertEquals("Platform options", "All", options[i++]);
163
			assertEquals("Platform options", "Macintosh", options[i++]);
164
			assertEquals("Platform options", "PC", options[i++]);
165
			assertEquals("Platform options", "Power PC", options[i++]);
166
			assertEquals("Platform options", "Sun", options[i++]);
167
			assertEquals("Platform options", "Other", options[i++]);
168
		}
169
170
		// Attribute: Component
171
		att = itr.next();
172
		assertEquals("Attribute: Component", "Component", att.getName());
173
174
		attOptions = att.getOptionValues();
175
		options = attOptions.keySet().toArray();
176
		assertEquals("# Component options", 16, options.length);
177
178
		i = 0;
179
		while (i < options.length) {
180
			assertEquals("Component options", "Ant", options[i++]);
181
			assertEquals("Component options", "Compare", options[i++]);
182
			assertEquals("Component options", "Core", options[i++]);
183
			assertEquals("Component options", "CVS", options[i++]);
184
			assertEquals("Component options", "Debug", options[i++]);
185
			assertEquals("Component options", "Doc", options[i++]);
186
			assertEquals("Component options", "Help", options[i++]);
187
			assertEquals("Component options", "Releng", options[i++]);
188
			assertEquals("Component options", "Scripting", options[i++]);
189
			assertEquals("Component options", "Search", options[i++]);
190
			assertEquals("Component options", "SWT", options[i++]);
191
			assertEquals("Component options", "Team", options[i++]);
192
			assertEquals("Component options", "Text", options[i++]);
193
			assertEquals("Component options", "UI", options[i++]);
194
			assertEquals("Component options", "Update", options[i++]);
195
			assertEquals("Component options", "WebDAV", options[i++]);
196
		}
197
198
		// Attribute: bug_status
199
		att = itr.next();
200
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
201
202
		attOptions = att.getOptionValues();
203
		options = attOptions.keySet().toArray();
204
		assertEquals("No bug_status options", 0, options.length);
205
206
		// Attribute: form_name
207
		att = itr.next();
208
		assertEquals("Attribute: form_name", "form_name", att.getName());
209
210
		options = att.getOptionValues().keySet().toArray();
211
		assertEquals("No form_name options", 0, options.length);
212
213
		// Attribute: bug_file_loc
214
		att = itr.next();
215
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
216
217
		options = att.getOptionValues().keySet().toArray();
218
		assertEquals("No bug_file_loc options", 0, options.length);
219
220
		// Attribute: priority
221
		att = itr.next();
222
		assertEquals("Attribute: priority", "priority", att.getName());
223
224
		options = att.getOptionValues().keySet().toArray();
225
		assertEquals("No priority options", 0, options.length);
226
	}
227
228
	// private void printList(List<Attribute> attributes) {
229
	//
230
	// Iterator<Attribute> itr = attributes.iterator();
231
	// System.out.println("Attributes for this Product:");
232
	// System.out.println("============================");
233
	//
234
	// while (itr.hasNext()) {
235
	// Attribute attr = itr.next();
236
	// System.out.println();
237
	// System.out.println(attr.getName() + ": ");
238
	// System.out.println("-----------");
239
	//
240
	// Map<String, String> options = attr.getOptionValues();
241
	// Object[] it = options.keySet().toArray();
242
	// for (int i = 0; i < it.length; i++)
243
	// System.out.println((String) it[i]);
244
	// }
245
	// }
246
}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaNewBugParserTestVE.java (-225 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestVE extends TestCase {
33
34
	public BugzillaNewBugParserTestVE() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestVE(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductVE() throws Exception {
43
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/ve-page.html"));
44
45
		Reader in = new FileReader(f);
46
47
		NewBugModel nbm = new NewBugModel();
48
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
49
															// **
50
51
		// attributes for this but model
52
		List<Attribute> attributes = nbm.getAttributes();
53
		// printList(attributes);
54
55
		Iterator<Attribute> itr = attributes.iterator();
56
		Attribute att = itr.next();
57
58
		// Attribute: Severity
59
		assertEquals("Attribute: Severity", "Severity", att.getName());
60
61
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
62
		// options for the
63
		// current
64
		// attribute
65
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
66
		// the options of the
67
		// current attribute
68
		assertEquals("# Severity options", 7, options.length);
69
70
		int i = 0;
71
		while (i < options.length) {
72
			assertEquals("severity options", "blocker", options[i++]);
73
			assertEquals("severity options", "critical", options[i++]);
74
			assertEquals("severity options", "major", options[i++]);
75
			assertEquals("severity options", "normal", options[i++]);
76
			assertEquals("severity options", "minor", options[i++]);
77
			assertEquals("severity options", "trivial", options[i++]);
78
			assertEquals("severity options", "enhancement", options[i++]);
79
		}
80
81
		// Attribute: product
82
		att = itr.next();
83
		assertEquals("Attribute: product", "product", att.getName());
84
85
		attOptions = att.getOptionValues();
86
		options = attOptions.keySet().toArray();
87
		assertEquals("No product options", 0, options.length);
88
89
		// Attribute: AssignedTo
90
		att = itr.next();
91
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
92
93
		attOptions = att.getOptionValues();
94
		options = attOptions.keySet().toArray();
95
		assertEquals("No AssignedTo options", 0, options.length);
96
97
		// Attribute: OS
98
		att = itr.next();
99
		assertEquals("Attribute: OS", "OS", att.getName());
100
101
		attOptions = att.getOptionValues();
102
		options = attOptions.keySet().toArray();
103
		assertEquals("# of options", 20, options.length);
104
105
		i = 0;
106
		while (i < options.length) {
107
			assertEquals("OS options", "All", options[i++]);
108
			assertEquals("OS options", "AIX Motif", options[i++]);
109
			assertEquals("OS options", "Windows 95", options[i++]);
110
			assertEquals("OS options", "Windows 98", options[i++]);
111
			assertEquals("OS options", "Windows CE", options[i++]);
112
			assertEquals("OS options", "Windows ME", options[i++]);
113
			assertEquals("OS options", "Windows 2000", options[i++]);
114
			assertEquals("OS options", "Windows NT", options[i++]);
115
			assertEquals("OS options", "Windows XP", options[i++]);
116
			assertEquals("OS options", "Windows All", options[i++]);
117
			assertEquals("OS options", "MacOS X", options[i++]);
118
			assertEquals("OS options", "Linux", options[i++]);
119
			assertEquals("OS options", "Linux-GTK", options[i++]);
120
			assertEquals("OS options", "Linux-Motif", options[i++]);
121
			assertEquals("OS options", "HP-UX", options[i++]);
122
			assertEquals("OS options", "Neutrino", options[i++]);
123
			assertEquals("OS options", "QNX-Photon", options[i++]);
124
			assertEquals("OS options", "Solaris", options[i++]);
125
			assertEquals("OS options", "Unix All", options[i++]);
126
			assertEquals("OS options", "other", options[i++]);
127
		}
128
129
		// Attribute: Version
130
		att = itr.next();
131
		assertEquals("Attribute: Version", "Version", att.getName());
132
133
		// attOptions = (HashMap) att.getOptionValues();
134
		options = att.getOptionValues().keySet().toArray();
135
		assertEquals("# Version options", 3, options.length);
136
137
		i = 0;
138
		while (i < options.length) {
139
			assertEquals("Version options", "0.5.0", options[i++]);
140
			assertEquals("Version options", "1.0.0", options[i++]);
141
			assertEquals("Version options", "unspecified", options[i++]);
142
		}
143
144
		// Attribute: Platform
145
		att = itr.next();
146
		assertEquals("Attribute: Platform", "Platform", att.getName());
147
148
		options = att.getOptionValues().keySet().toArray();
149
		assertEquals("# Platform options", 6, options.length);
150
151
		i = 0;
152
		while (i < options.length) {
153
			assertEquals("Platform options", "All", options[i++]);
154
			assertEquals("Platform options", "Macintosh", options[i++]);
155
			assertEquals("Platform options", "PC", options[i++]);
156
			assertEquals("Platform options", "Power PC", options[i++]);
157
			assertEquals("Platform options", "Sun", options[i++]);
158
			assertEquals("Platform options", "Other", options[i++]);
159
		}
160
161
		att = itr.next();
162
		assertEquals("Attribute: Component", "Component", att.getName());
163
164
		options = att.getOptionValues().keySet().toArray();
165
		assertEquals("# Component options", 6, options.length);
166
167
		i = 0;
168
		while (i < options.length) {
169
			assertEquals("Component options", "CDE", options[i++]);
170
			assertEquals("Component options", "Doc", options[i++]);
171
			assertEquals("Component options", "Java Core", options[i++]);
172
			assertEquals("Component options", "Java Model (JEM)", options[i++]);
173
			assertEquals("Component options", "JFC/Swing", options[i++]);
174
			assertEquals("Component options", "SWT", options[i++]);
175
		}
176
177
		// Attribute: bug_status
178
		att = itr.next();
179
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
180
181
		options = att.getOptionValues().keySet().toArray();
182
		assertEquals("No bug_status options", 0, options.length);
183
184
		// Attribute: form_name
185
		att = itr.next();
186
		assertEquals("Attribute: form_name", "form_name", att.getName());
187
188
		options = att.getOptionValues().keySet().toArray();
189
		assertEquals("No form_name options", 0, options.length);
190
191
		// Attribute: bug_file_loc
192
		att = itr.next();
193
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
194
195
		options = att.getOptionValues().keySet().toArray();
196
		assertEquals("No bug_file_loc options", 0, options.length);
197
198
		// Attribute: priority
199
		att = itr.next();
200
		assertEquals("Attribute: priority", "priority", att.getName());
201
202
		options = att.getOptionValues().keySet().toArray();
203
		assertEquals("No priority options", 0, options.length);
204
205
	}
206
207
	// private void printList(List<Attribute> attributes) {
208
	//
209
	// Iterator<Attribute> itr = attributes.iterator();
210
	// System.out.println("Attributes for this Product:");
211
	// System.out.println("============================");
212
	//
213
	// while (itr.hasNext()) {
214
	// Attribute attr = itr.next();
215
	// System.out.println();
216
	// System.out.println(attr.getName() + ": ");
217
	// System.out.println("-----------");
218
	//
219
	// Map<String, String> options = attr.getOptionValues();
220
	// Object[] it = options.keySet().toArray();
221
	// for (int i = 0; i < it.length; i++)
222
	// System.out.println((String) it[i]);
223
	// }
224
	// }
225
}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaParserTestNoBug.java (-47 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.tests;
12
13
import java.io.File;
14
import java.io.FileReader;
15
import java.io.Reader;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.core.runtime.Path;
20
import org.eclipse.mylar.bugzilla.core.BugReport;
21
import org.eclipse.mylar.core.tests.support.FileTool;
22
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
23
24
/**
25
 * Tests for parsing Bugzilla reports
26
 */
27
public class BugzillaParserTestNoBug extends TestCase {
28
29
	public BugzillaParserTestNoBug() {
30
		super();
31
	}
32
33
	public BugzillaParserTestNoBug(String arg0) {
34
		super(arg0);
35
	}
36
37
	public void testBugNotFound() throws Exception {
38
39
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path(
40
				"testdata/pages/bug-not-found-eclipse.html"));
41
42
		Reader in = new FileReader(f);
43
44
		BugReport bug = BugParser.parseBug(in, 666, "<server>", false, null, null, null);
45
		assertNull(bug);
46
	}
47
}
(-)src/org/eclipse/mylar/bugzilla/tests/NewBugWizardTest.java (-29 / +25 lines)
Lines 11-29 Link Here
11
11
12
package org.eclipse.mylar.bugzilla.tests;
12
package org.eclipse.mylar.bugzilla.tests;
13
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
18
import junit.framework.TestCase;
14
import junit.framework.TestCase;
19
15
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Platform;
16
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.mylar.bugzilla.core.BugReport;
17
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.core.tests.support.FileTool;
18
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
19
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
20
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
21
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
26
import org.eclipse.mylar.internal.bugzilla.ui.wizard.AbstractBugzillaWizardPage;
22
import org.eclipse.mylar.internal.bugzilla.ui.wizard.AbstractBugzillaWizardPage;
23
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
27
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.ui.PlatformUI;
28
25
29
/**
26
/**
Lines 34-77 Link Here
34
31
35
	public void testPlatformOptions() throws Exception {
32
	public void testPlatformOptions() throws Exception {
36
33
37
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/cdt-page.html"));
34
		NewBugzillaReport newReport = new NewBugzillaReport(IBugzillaConstants.TEST_BUGZILLA_220_URL);
38
		Reader in = new FileReader(f);
39
40
		NewBugModel model = new NewBugModel();
41
		AbstractBugzillaWizardPage page = new TestWizardDataPage();
35
		AbstractBugzillaWizardPage page = new TestWizardDataPage();
42
		new NewBugParser(in).parseBugAttributes(model, true); // ** TRUE vs
36
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
43
																// FALSE **
37
				IBugzillaConstants.TEST_BUGZILLA_220_URL);
44
		page.setPlatformOptions(model);
38
		BugzillaRepositoryUtil.setupNewBugAttributes(repository, newReport); // FALSE
39
																				// **
40
		page.setPlatformOptions(newReport);
45
41
46
		String os = Platform.getOS();
42
		String os = Platform.getOS();
47
		if (os.equals("win32"))
43
		if (os.equals("win32"))
48
			assertEquals("Windows All", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
44
			assertEquals("Windows", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
49
		else if (os.equals("solaris"))
45
		else if (os.equals("solaris"))
50
			assertEquals("Solaris", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
46
			assertEquals("Solaris", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
51
		else if (os.equals("qnx"))
47
		else if (os.equals("qnx"))
52
			assertEquals("QNX-Photon", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
48
			assertEquals("QNX-Photon", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
53
		else if (os.equals("macosx"))
49
		else if (os.equals("macosx"))
54
			assertEquals("MacOS X", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
50
			assertEquals("Mac OS", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
55
		else if (os.equals("linux"))
51
		else if (os.equals("linux"))
56
			assertEquals("Linux", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
52
			assertEquals("Linux", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
57
		else if (os.equals("hpux"))
53
		else if (os.equals("hpux"))
58
			assertEquals("HP-UX", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
54
			assertEquals("HP-UX", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
59
		else if (os.equals("aix"))
55
		else if (os.equals("aix"))
60
			assertEquals("AIX", model.getAttribute(BugReport.ATTRIBUTE_OS).getValue());
56
			assertEquals("AIX", newReport.getAttribute(BugzillaReportElement.OP_SYS).getValue());
61
57
62
		String platform = Platform.getOSArch();
58
		String platform = Platform.getOSArch();
63
		if (platform.equals("x86"))
59
		if (platform.equals("x86"))
64
			assertEquals("PC", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
60
			assertEquals("PC", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
65
		else if (platform.equals("x86_64"))
61
		else if (platform.equals("x86_64"))
66
			assertEquals("PC", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
62
			assertEquals("PC", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
67
		else if (platform.equals("ia64"))
63
		else if (platform.equals("ia64"))
68
			assertEquals("PC", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
64
			assertEquals("PC", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
69
		else if (platform.equals("ia64_32"))
65
		else if (platform.equals("ia64_32"))
70
			assertEquals("PC", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
66
			assertEquals("PC", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
71
		else if (platform.equals("sparc"))
67
		else if (platform.equals("sparc"))
72
			assertEquals("Sun", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
68
			assertEquals("Sun", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
73
		else if (platform.equals("ppc"))
69
		else if (platform.equals("ppc"))
74
			assertEquals("Power", model.getAttribute(BugReport.ATTRIBUTE_PLATFORM).getValue());
70
			assertEquals("Power", newReport.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
75
71
76
	}
72
	}
77
73
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaNewBugParserTestEquinox.java (-219 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.File;
15
import java.io.FileReader;
16
import java.io.Reader;
17
import java.util.Iterator;
18
import java.util.List;
19
import java.util.Map;
20
21
import junit.framework.TestCase;
22
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.mylar.bugzilla.core.Attribute;
25
import org.eclipse.mylar.core.tests.support.FileTool;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
27
import org.eclipse.mylar.internal.bugzilla.core.internal.NewBugParser;
28
29
/**
30
 * Tests NewBugParser -- parses product attributes
31
 */
32
public class BugzillaNewBugParserTestEquinox extends TestCase {
33
34
	public BugzillaNewBugParserTestEquinox() {
35
		super();
36
	}
37
38
	public BugzillaNewBugParserTestEquinox(String arg0) {
39
		super(arg0);
40
	}
41
42
	public void testProductEquinox() throws Exception {
43
44
		File f = FileTool
45
				.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/equinox-page.html"));
46
47
		Reader in = new FileReader(f);
48
49
		NewBugModel nbm = new NewBugModel();
50
		new NewBugParser(in).parseBugAttributes(nbm, true); // ** TRUE vs FALSE
51
															// **
52
53
		// attributes for this bug model
54
		List<Attribute> attributes = nbm.getAttributes();
55
		// printList(attributes);
56
57
		Iterator<Attribute> itr = attributes.iterator();
58
		Attribute att = itr.next();
59
60
		// Attribute: Severity
61
		assertEquals("Attribute: Severity", "Severity", att.getName());
62
63
		Map<String, String> attOptions = att.getOptionValues(); // HashMap of
64
		// options for the
65
		// current
66
		// attribute
67
		Object[] options = attOptions.keySet().toArray(); // Array of keys for
68
		// the options of the
69
		// current attribute
70
		assertEquals("# Severity options", 7, options.length);
71
72
		int i = 0;
73
		while (i < options.length) {
74
			assertEquals("severity options", "blocker", options[i++]);
75
			assertEquals("severity options", "critical", options[i++]);
76
			assertEquals("severity options", "major", options[i++]);
77
			assertEquals("severity options", "normal", options[i++]);
78
			assertEquals("severity options", "minor", options[i++]);
79
			assertEquals("severity options", "trivial", options[i++]);
80
			assertEquals("severity options", "enhancement", options[i++]);
81
		}
82
83
		// Attribute: product
84
		att = itr.next();
85
		assertEquals("Attribute: prodcut", "product", att.getName());
86
87
		options = att.getOptionValues().keySet().toArray();
88
		assertEquals("No product options", 0, options.length);
89
90
		// Attribute: AssignedTo
91
		att = itr.next();
92
		assertEquals("Attribute: AssignedTo", "AssignedTo", att.getName());
93
94
		options = att.getOptionValues().keySet().toArray();
95
		assertEquals("No AssignedTo options", 0, options.length);
96
97
		// Attribute: OS
98
		att = itr.next();
99
		assertEquals("Attribute: OS", "OS", att.getName());
100
101
		options = att.getOptionValues().keySet().toArray();
102
		assertEquals("# OS options", 20, options.length);
103
104
		i = 0;
105
		while (i < options.length) {
106
			assertEquals("OS options", "All", options[i++]);
107
			assertEquals("OS options", "AIX Motif", options[i++]);
108
			assertEquals("OS options", "Windows 95", options[i++]);
109
			assertEquals("OS options", "Windows 98", options[i++]);
110
			assertEquals("OS options", "Windows CE", options[i++]);
111
			assertEquals("OS options", "Windows ME", options[i++]);
112
			assertEquals("OS options", "Windows 2000", options[i++]);
113
			assertEquals("OS options", "Windows NT", options[i++]);
114
			assertEquals("OS options", "Windows XP", options[i++]);
115
			assertEquals("OS options", "Windows All", options[i++]);
116
			assertEquals("OS options", "MacOS X", options[i++]);
117
			assertEquals("OS options", "Linux", options[i++]);
118
			assertEquals("OS options", "Linux-GTK", options[i++]);
119
			assertEquals("OS options", "Linux-Motif", options[i++]);
120
			assertEquals("OS options", "HP-UX", options[i++]);
121
			assertEquals("OS options", "Neutrino", options[i++]);
122
			assertEquals("OS options", "QNX-Photon", options[i++]);
123
			assertEquals("OS options", "Solaris", options[i++]);
124
			assertEquals("OS options", "Unix All", options[i++]);
125
			assertEquals("OS options", "other", options[i++]);
126
		}
127
128
		// Attribute: Version
129
		att = itr.next();
130
		assertEquals("Attribute: Version", "Version", att.getName());
131
132
		options = att.getOptionValues().keySet().toArray();
133
		assertEquals("# Version options", 1, options.length);
134
135
		i = 0;
136
		while (i < options.length) {
137
			assertEquals("Version options", "unspecified", options[i++]);
138
		}
139
140
		// Attribute: Platform
141
		att = itr.next();
142
		assertEquals("Attribute: Platform", "Platform", att.getName());
143
144
		options = att.getOptionValues().keySet().toArray();
145
		assertEquals("# Platform options", 6, options.length);
146
147
		i = 0;
148
		while (i < options.length) {
149
			assertEquals("Platform options", "All", options[i++]);
150
			assertEquals("Platform options", "Macintosh", options[i++]);
151
			assertEquals("Platform options", "PC", options[i++]);
152
			assertEquals("Platform options", "Power PC", options[i++]);
153
			assertEquals("Platform options", "Sun", options[i++]);
154
			assertEquals("Platform options", "Other", options[i++]);
155
		}
156
157
		// Attribute: Component
158
		att = itr.next();
159
		assertEquals("Attribute: Component", "Component", att.getName());
160
161
		options = att.getOptionValues().keySet().toArray();
162
		assertEquals("# Component options", 3, options.length);
163
164
		i = 0;
165
		while (i < options.length) {
166
			assertEquals("Component options", "Dynamic Plugins", options[i++]);
167
			assertEquals("Component options", "General", options[i++]);
168
			assertEquals("Component options", "OSGi", options[i++]);
169
		}
170
171
		// Attribute: bug_status
172
		att = itr.next();
173
		assertEquals("Attribute: bug_status", "bug_status", att.getName());
174
175
		options = att.getOptionValues().keySet().toArray();
176
		assertEquals("No bug_status options", 0, options.length);
177
178
		// Attribute: form_name
179
		att = itr.next();
180
		assertEquals("Attribute: form_name", "form_name", att.getName());
181
182
		options = att.getOptionValues().keySet().toArray();
183
		assertEquals("No form_name options", 0, options.length);
184
185
		// Attribute: bug_file_loc
186
		att = itr.next();
187
		assertEquals("Attribute: bug_file_loc", "bug_file_loc", att.getName());
188
189
		options = att.getOptionValues().keySet().toArray();
190
		assertEquals("No bug_file_loc options", 0, options.length);
191
192
		// Attribute: priority
193
		att = itr.next();
194
		assertEquals("Attribute: priority", "priority", att.getName());
195
196
		options = att.getOptionValues().keySet().toArray();
197
		assertEquals("No priority options", 0, options.length);
198
199
	}
200
201
	// private void printList(List<Attribute> attributes) {
202
	//
203
	// Iterator<Attribute> itr = attributes.iterator();
204
	// System.out.println("Attributes for this Product:");
205
	// System.out.println("============================");
206
	//
207
	// while (itr.hasNext()) {
208
	// Attribute attr = itr.next();
209
	// System.out.println();
210
	// System.out.println(attr.getName() + ": ");
211
	// System.out.println("-----------");
212
	//
213
	// Map<String, String> options = attr.getOptionValues();
214
	// Object[] it = options.keySet().toArray();
215
	// for (int i = 0; i < it.length; i++)
216
	// System.out.println((String) it[i]);
217
	// }
218
	// }
219
}
(-)src/org/eclipse/mylar/bugzilla/tests/EncodingTest.java (-5 / +5 lines)
Lines 18-24 Link Here
18
18
19
import junit.framework.TestCase;
19
import junit.framework.TestCase;
20
20
21
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
21
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
22
22
23
/**
23
/**
24
 * @author Mik Kersten
24
 * @author Mik Kersten
Lines 27-43 Link Here
27
27
28
	public void testEncodingSetting() throws LoginException, IOException, ParseException {
28
	public void testEncodingSetting() throws LoginException, IOException, ParseException {
29
29
30
		String charset = BugParser.getCharsetFromString("text/html; charset=UTF-8");
30
		String charset = BugzillaRepositoryUtil.getCharsetFromString("text/html; charset=UTF-8");
31
		assertEquals("UTF-8", charset);
31
		assertEquals("UTF-8", charset);
32
32
33
		charset = BugParser.getCharsetFromString("text/html");
33
		charset = BugzillaRepositoryUtil.getCharsetFromString("text/html");
34
		assertEquals(null, charset);
34
		assertEquals(null, charset);
35
35
36
		charset = BugParser
36
		charset = BugzillaRepositoryUtil
37
				.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">>");
37
				.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">>");
38
		assertEquals("iso-8859-2", charset);
38
		assertEquals("iso-8859-2", charset);
39
39
40
		charset = BugParser.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html\">>");
40
		charset = BugzillaRepositoryUtil.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html\">>");
41
		assertEquals(null, charset);
41
		assertEquals(null, charset);
42
	}
42
	}
43
43
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaSearchEngineTest.java (-2 / +2 lines)
Lines 22-30 Link Here
22
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
24
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
24
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
26
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryQuery;
25
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryQuery;
27
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
26
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
27
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
28
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
28
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
29
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
29
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
30
30
Lines 99-105 Link Here
99
				QUERY_NAME, 
99
				QUERY_NAME, 
100
				MAX_HITS, MylarTaskListPlugin.getTaskListManager().getTaskList());
100
				MAX_HITS, MylarTaskListPlugin.getTaskListManager().getTaskList());
101
		
101
		
102
		BugzillaRepositoryConnector connector = (BugzillaRepositoryConnector) MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
102
		AbstractRepositoryConnector connector = (AbstractRepositoryConnector) MylarTaskListPlugin.getRepositoryManager().getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
103
		results.addAll(connector.performQuery(repositoryQuery, new NullProgressMonitor(), new MultiStatus(MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, "Query result", null)));
103
		results.addAll(connector.performQuery(repositoryQuery, new NullProgressMonitor(), new MultiStatus(MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, "Query result", null)));
104
		return results;	
104
		return results;	
105
	}
105
	}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaParserTest.java (-196 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.mylar.bugzilla.tests;
12
13
import java.io.File;
14
import java.io.FileReader;
15
import java.io.Reader;
16
import java.util.Iterator;
17
18
import junit.framework.TestCase;
19
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
22
import org.eclipse.mylar.bugzilla.core.Comment;
23
import org.eclipse.mylar.core.tests.support.FileTool;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.BugParser;
25
26
/**
27
 * Tests for parsing Bugzilla reports
28
 */
29
public class BugzillaParserTest extends TestCase {
30
31
	public BugzillaParserTest() {
32
		super();
33
	}
34
35
	public BugzillaParserTest(String arg0) {
36
		super(arg0);
37
	}
38
39
	public void testFullReportBug1() throws Exception {
40
41
		File f = FileTool.getFileInPlugin(BugzillaTestPlugin.getDefault(), new Path("testdata/pages/bug-1-full.html"));
42
43
		Reader in = new FileReader(f);
44
45
		BugReport bug = BugParser.parseBug(in, 1, "<server>", false, null, null, null);
46
47
		// displayBug(bug);
48
		assertEquals("Bug id", 1, bug.getId());
49
		assertEquals("Bug summary", "Usability issue with external editors (1GE6IRL)", bug.getSummary());
50
		assertEquals("Reporter", "andre_weinand@ch.ibm.com (Andre Weinand)", bug.getReporter());
51
		assertEquals("Reporter", "andre_weinand@ch.ibm.com (Andre Weinand)", bug.getAttribute("Reporter").getValue());
52
		assertEquals("Summary", "Usability issue with external editors (1GE6IRL)", bug.getSummary());
53
		assertEquals("Status", "VERIFIED", bug.getStatus());
54
		assertEquals("Resolution", "FIXED", bug.getResolution());
55
		assertEquals("Keywords", null, bug.getKeywords());
56
		assertEquals("Assigned To", "James_Moody@ca.ibm.com (James Moody)", bug.getAssignedTo());
57
		assertEquals("Priority", "P3", bug.getAttribute("Priority").getValue());
58
		assertEquals("OS", "All", bug.getAttribute("OS").getValue());
59
		assertEquals("Version", "2.0", bug.getAttribute("Version").getValue());
60
		assertEquals("Target Milestone", "---", bug.getAttribute("Target Milestone").getValue());
61
		assertEquals("Keywords", "", bug.getAttribute("Keywords").getValue());
62
		assertEquals("Severity", "normal", bug.getAttribute("Severity").getValue());
63
		assertEquals("Component", "VCM", bug.getAttribute("Component").getValue());
64
		assertEquals("CC", "Kevin_McGuire@oti.com", bug.getCC().iterator().next());
65
		assertEquals("Platform", "All", bug.getAttribute("Platform").getValue());
66
		assertEquals("Product", "Platform", bug.getAttribute("Product").getValue());
67
		assertEquals("URL", "", bug.getAttribute("URL").getValue());
68
		assertEquals("Bug#", "1", bug.getAttribute("Bug#").getValue());
69
70
		// Description
71
		String description = "- Setup a project that contains a *.gif resource\n"
72
				+ "\t- release project to CVS\n"
73
				+ "\t- edit the *.gif resource with an external editor, e.g. PaintShop\n"
74
				+ "\t- save and close external editor\n"
75
				+ "\t- in Navigator open the icon resource and verify that your changes are there\n"
76
				+ "\t- release project\n"
77
				+ "\t\t-> nothing to release!\n"
78
				+ "\t- in Navigator open the icon resource and verify that your changes are still there\n\n"
79
				+
80
81
				"\tProblem: because I never \"Refreshed from local\", the workspace hasn't changed so \"Release\" didn't find anything.\n"
82
				+ "\tHowever opening the resource with an external editor found the modified file on disk and showed the changes.\n\n"
83
				+
84
85
				"\tThe real problem occurs if \"Release\" actually finds something to release but you don't spot that some resources are missing.\n"
86
				+ "\tThis is extremely error prone: one of my changes didn't made it into build 110 because of this!\n\n"
87
				+
88
89
				"NOTES:\n"
90
				+ "EG (5/23/01 3:00:33 PM)\n"
91
				+ "\tRelease should do a refresh from local before doing the release.\n"
92
				+ "\tMoving to VCM\n\n\n"
93
				+
94
95
				"KM (05/27/01 5:10:19 PM)\n"
96
				+ "\tComments from JM in related email:\n\n"
97
				+
98
99
				"\tShould not do this for free.  Could have a setting which made it optoinal but should nt be mandatory.  Default setting could be to have it on.\n"
100
				+ "\tConsider the SWT team who keep their workspaces on network drives.  This will be slow.  \n\n"
101
				+
102
103
				"\tSide effects will be that a build runs when the refresh is completed unless you somehow do it in a workspace runnable and don't end the\n"
104
				+ "\trunnable until after the release.  This would be less than optimal as some builders may be responsible for maintaining some invariants and deriving resources which are releasable.  If you don't run the builders before releasing, the invariants will not be maintained and you will release inconsistent state.\n\n"
105
				+
106
107
				"\tSummary:  Offer to \"ensure local consistency\" before releasing.\n\n" +
108
109
				"KM (5/31/01 1:30:35 PM)\n"
110
				+ "\tSee also 1GEAG1A: ITPVCM:WINNT - Internal error comparing with a document\n"
111
				+ "\twhich failed with an error.  Never got log from Tod though.";
112
113
		assert (description.length() == bug.getDescription().length());
114
		assertEquals("Description", description, bug.getDescription());
115
116
		// Comments:
117
		Iterator<Comment> it = bug.getComments().iterator();
118
		while (it.hasNext()) {
119
			// COMMENT #1
120
			Comment comment = it.next();
121
			assertEquals("Author1", "James_Moody@ca.ibm.com", comment.getAuthor());
122
			assertEquals("Name1", "James Moody", comment.getAuthorName());
123
			assertEquals("Text1", "*** Bug 183 has been marked as a duplicate of this bug. ***", comment.getText());
124
125
			// COMMENT #2
126
			comment = it.next();
127
			assertEquals("Author2", "James_Moody@ca.ibm.com", comment.getAuthor());
128
			assertEquals("Name2", "James Moody", comment.getAuthorName());
129
			assertEquals("Text2", "Implemented 'auto refresh' option. Default value is off.", comment.getText());
130
131
			// COMMENT 3
132
			comment = it.next();
133
			assertEquals("Author3", "dj_houghton@ca.ibm.com", comment.getAuthor());
134
			assertEquals("Name3", "DJ Houghton", comment.getAuthorName());
135
			assertEquals("Text3", "PRODUCT VERSION:\n\t109\n\n", comment.getText());
136
137
			// COMMENT 4
138
			comment = it.next();
139
			assertEquals("Author4", "James_Moody@ca.ibm.com", comment.getAuthor());
140
			assertEquals("Name4", "James Moody", comment.getAuthorName());
141
			assertEquals("Text4", "Fixed in v206", comment.getText());
142
		}
143
	}
144
145
	// private static void displayBug(BugReport bug) {
146
	// System.out.println("Bug " + bug.getId() + ": " + bug.getSummary());
147
	// System.out.println("Opened: " + bug.getCreated());
148
	// for (Iterator<Attribute> it = bug.getAttributes().iterator();
149
	// it.hasNext();) {
150
	// Attribute attribute = it.next();
151
	// String key = attribute.getName();
152
	// System.out.println(key + ": " + attribute.getValue()
153
	// + (attribute.isEditable() ? " [OK]" : " %%"));
154
	// }
155
	//
156
	// System.out.print("CC: ");
157
	// for (Iterator<String> it = bug.getCC().iterator(); it.hasNext();) {
158
	// String email = it.next();
159
	// System.out.print(email + " ");
160
	// }
161
	// System.out.println();
162
	//
163
	// System.out.println(bug.getDescription());
164
	// for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();)
165
	// {
166
	// Comment comment = it.next();
167
	// System.out.println(comment.getAuthorName() + " <"
168
	// + comment.getAuthor() + "> (" + comment.getCreated() + ")");
169
	// System.out.print(comment.getText());
170
	// System.out.println();
171
	// }
172
	// }
173
	//
174
	// private static void printComments(BugReport bug) {
175
	// for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();)
176
	// {
177
	// Comment comment = it.next();
178
	// System.out.println("Author: " + comment.getAuthor());
179
	// System.out.println("Name: " + comment.getAuthorName());
180
	// System.out.println("Date: " + comment.getCreated());
181
	// System.out.println("Bug ID: " + comment.getBug().getId());
182
	// System.out.println("Comment: " + comment.getText());
183
	// System.out.println();
184
	// }
185
	// }
186
	//
187
	// /** prints names of attributes */
188
	// private static void printAttributes(BugReport bug) {
189
	// System.out.println("ATTRIBUTE KEYS:");
190
	// for (Iterator<Attribute> it = bug.getAttributes().iterator();
191
	// it.hasNext();) {
192
	// Attribute att = it.next();
193
	// System.out.println(att.getName());
194
	// }
195
	// }
196
}
(-)src/org/eclipse/mylar/bugzilla/tests/BugzillaRepositoryConnectorTest.java (-21 / +21 lines)
Lines 13-29 Link Here
13
13
14
import java.net.MalformedURLException;
14
import java.net.MalformedURLException;
15
import java.util.Date;
15
import java.util.Date;
16
import java.util.Iterator;
17
16
18
import javax.security.auth.login.LoginException;
17
import javax.security.auth.login.LoginException;
19
18
20
import junit.framework.TestCase;
19
import junit.framework.TestCase;
21
20
22
import org.eclipse.mylar.bugzilla.core.Attribute;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
23
import org.eclipse.mylar.bugzilla.core.BugReport;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
27
import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException;
26
import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaQueryHit;
27
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaQueryHit;
29
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
Lines 45-51 Link Here
45
44
46
	private static final String DEFAULT_KIND = BugzillaPlugin.REPOSITORY_KIND;
45
	private static final String DEFAULT_KIND = BugzillaPlugin.REPOSITORY_KIND;
47
46
48
	private static final String TEST_REPOSITORY_URL = "https://bugs.eclipse.org/bugs";
47
	//private static final String TEST_REPOSITORY_URL = "https://bugs.eclipse.org/bugs";
49
48
50
	private BugzillaRepositoryConnector client;
49
	private BugzillaRepositoryConnector client;
51
50
Lines 60-66 Link Here
60
		super.setUp();
59
		super.setUp();
61
		manager = MylarTaskListPlugin.getRepositoryManager();
60
		manager = MylarTaskListPlugin.getRepositoryManager();
62
		manager.clearRepositories();
61
		manager.clearRepositories();
63
		repository = new TaskRepository(DEFAULT_KIND, TEST_REPOSITORY_URL);
62
		repository = new TaskRepository(DEFAULT_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
64
		// repository.setAuthenticationCredentials("userid", "password");
63
		// repository.setAuthenticationCredentials("userid", "password");
65
		manager.addRepository(repository);
64
		manager.addRepository(repository);
66
		assertNotNull(manager);
65
		assertNotNull(manager);
Lines 113-122 Link Here
113
112
114
		// Modify it
113
		// Modify it
115
		String newCommentText = "BugzillaRepositoryClientTest.testSynchronize(): " + (new Date()).toString();
114
		String newCommentText = "BugzillaRepositoryClientTest.testSynchronize(): " + (new Date()).toString();
116
		task.getBugReport().setNewNewComment(newCommentText);
115
		task.getBugReport().setNewComment(newCommentText);
117
		// overwrites old fields/attributes with new content (ususually done by
116
		// overwrites old fields/attributes with new content (ususually done by
118
		// BugEditor)
117
		// BugEditor)
119
		updateBug(task.getBugReport());
118
		task.getBugReport().setHasChanged(true);
119
//		updateBug(task.getBugReport());
120
		assertEquals(task.getSyncState(), RepositoryTaskSyncState.SYNCHRONIZED);
120
		assertEquals(task.getSyncState(), RepositoryTaskSyncState.SYNCHRONIZED);
121
		client.saveBugReport(task.getBugReport());
121
		client.saveBugReport(task.getBugReport());
122
		assertEquals(RepositoryTaskSyncState.OUTGOING, task.getSyncState());
122
		assertEquals(RepositoryTaskSyncState.OUTGOING, task.getSyncState());
Lines 155-161 Link Here
155
		// because task doesn't have bug report (new query hit)
155
		// because task doesn't have bug report (new query hit)
156
		// Result: retrieved with no incoming status
156
		// Result: retrieved with no incoming status
157
		task.setSyncState(RepositoryTaskSyncState.SYNCHRONIZED);
157
		task.setSyncState(RepositoryTaskSyncState.SYNCHRONIZED);
158
		BugReport bugReport = task.getBugReport();
158
		BugzillaReport bugReport = task.getBugReport();
159
		task.setBugReport(null);
159
		task.setBugReport(null);
160
		client.synchronize(task, false, null);
160
		client.synchronize(task, false, null);
161
		assertEquals(RepositoryTaskSyncState.SYNCHRONIZED, task.getSyncState());
161
		assertEquals(RepositoryTaskSyncState.SYNCHRONIZED, task.getSyncState());
Lines 186-209 Link Here
186
186
187
	}
187
	}
188
188
189
	protected void updateBug(BugReport bug) {
189
	protected void updateBug(BugzillaReport bug) {
190
190
191
		// go through all of the attributes and update the main values to the
191
		// go through all of the attributes and update the main values to the
192
		// new ones
192
		// new ones
193
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
193
//		for (Iterator<AbstractRepositoryReportAttribute> it = bug.getAttributes().iterator(); it.hasNext();) {
194
			Attribute attribute = it.next();
194
//			AbstractRepositoryReportAttribute attribute = it.next();
195
			if (attribute.getNewValue() != null && attribute.getNewValue().compareTo(attribute.getValue()) != 0) {
195
//			if (attribute.getValue() != null && attribute.getValue().compareTo(attribute.getValue()) != 0) {
196
				bug.setHasChanged(true);
196
//				bug.setHasChanged(true);
197
			}
197
//			}
198
			attribute.setValue(attribute.getNewValue());
198
//			attribute.setValue(attribute.getNewValue());
199
199
//
200
		}
200
//		}
201
		if (bug.getNewComment().compareTo(bug.getNewNewComment()) != 0) {
201
//		if (bug.getNewComment().compareTo(bug.getNewNewComment()) != 0) {
202
			bug.setHasChanged(true);
202
//			bug.setHasChanged(true);
203
		}
203
//		}
204
204
205
		// Update some other fields as well.
205
		// Update some other fields as well.
206
		bug.setNewComment(bug.getNewNewComment());
206
		//bug.setNewComment(bug.getNewNewComment());
207
207
208
	}
208
	}
209
209
(-)src/org/eclipse/mylar/bugzilla/tests/RepositoryReportFactoryTest.java (+310 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests;
13
14
import java.io.IOException;
15
16
import javax.security.auth.login.LoginException;
17
18
import junit.framework.TestCase;
19
20
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
24
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.RepositoryReportFactory;
27
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
28
29
public class RepositoryReportFactoryTest extends TestCase {
30
31
	RepositoryReportFactory factory = RepositoryReportFactory.getInstance();
32
33
	public void testBugNoFound222() {
34
		int bugid = -1;
35
		String errorMessage = "";
36
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
37
				IBugzillaConstants.TEST_BUGZILLA_222_URL);
38
		try {
39
			BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
40
			factory.populateReport(report, repository);
41
		} catch (LoginException e) {
42
			//
43
		} catch (IOException e) {
44
			errorMessage = e.getMessage();
45
		}
46
		assertEquals(IBugzillaConstants.ERROR_INVALID_BUG_ID, errorMessage);
47
	}
48
49
	public void testInvalidCredentials222() {
50
		int bugid = 1;
51
		String errorMessage = "";
52
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
53
				IBugzillaConstants.TEST_BUGZILLA_222_URL);
54
		repository.setAuthenticationCredentials("invalid", "invalid");
55
		try {
56
			BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
57
			factory.populateReport(report, repository);
58
		} catch (LoginException e) {
59
			errorMessage = e.getMessage();
60
		} catch (IOException e) {
61
			errorMessage = e.getMessage();
62
		}
63
		assertEquals(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD, errorMessage);
64
		repository.flushAuthenticationCredentials();
65
	}
66
67
	public void testReadingReport() throws Exception {
68
		int bugid = 4;
69
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
70
				IBugzillaConstants.TEST_BUGZILLA_222_URL);
71
72
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
73
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
74
		factory.populateReport(report, repository);
75
76
		assertNotNull(report);
77
		assertEquals("Another Test", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
78
		assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
79
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
80
		assertEquals("Other", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
81
		assertEquals(37, report.getComments().size());
82
		assertEquals("Testing new 2.22 version capability", report.getComments().get(0).getAttribute(
83
				BugzillaReportElement.THETEXT).getValue());
84
		assertEquals(15, report.getAttachments().size());
85
		assertEquals("1", report.getAttachments().get(0).getAttribute(BugzillaReportElement.ATTACHID).getValue());
86
		assertEquals("2006-03-10 14:11", report.getAttachments().get(0).getAttribute(BugzillaReportElement.DATE)
87
				.getValue());
88
		assertEquals("Testing upload", report.getAttachments().get(0).getAttribute(BugzillaReportElement.DESC)
89
				.getValue());
90
		assertEquals("patch130217.txt", report.getAttachments().get(0).getAttribute(BugzillaReportElement.FILENAME)
91
				.getValue());
92
		assertEquals("text/plain", report.getAttachments().get(0).getAttribute(BugzillaReportElement.TYPE).getValue());
93
	}
94
95
	public void testReadingReport222() throws Exception {
96
		int bugid = 1;
97
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
98
				IBugzillaConstants.TEST_BUGZILLA_222_URL);
99
100
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
101
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
102
		factory.populateReport(report, repository);
103
104
		assertNotNull(report);
105
		assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
106
		assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
107
		assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT).getValue());
108
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
109
		assertEquals("Windows", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
110
		assertEquals("other", report.getAttribute(BugzillaReportElement.VERSION).getValue());
111
		assertEquals("P1", report.getAttribute(BugzillaReportElement.PRIORITY).getValue());
112
		assertEquals("blocker", report.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue());
113
		assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID).getValue());
114
		assertEquals("NEW", report.getAttribute(BugzillaReportElement.BUG_STATUS).getValue());
115
		assertEquals("2006-03-08 19:59", report.getAttribute(BugzillaReportElement.CREATION_TS).getValue());
116
		assertEquals("2006-03-08 19:59:15", report.getAttribute(BugzillaReportElement.DELTA_TS).getValue());
117
		assertEquals("---", report.getAttribute(BugzillaReportElement.TARGET_MILESTONE).getValue());
118
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.REPORTER).getValue());
119
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.ASSIGNED_TO).getValue());
120
		assertEquals(1, report.getComments().size());
121
		assertEquals("relves@cs.ubc.ca", report.getComments().get(0).getAttribute(BugzillaReportElement.WHO).getValue());
122
		assertEquals("2006-03-08 19:59:15", report.getComments().get(0).getAttribute(BugzillaReportElement.BUG_WHEN)
123
				.getValue());
124
		assertEquals("search-match-test 1", report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT)
125
				.getValue());
126
		assertEquals(0, report.getAttachments().size());
127
	}
128
129
	public void testReadingReport2201() throws Exception {
130
		int bugid = 1;
131
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
132
				IBugzillaConstants.TEST_BUGZILLA_2201_URL);
133
134
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
135
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
136
		factory.populateReport(report, repository);
137
138
		assertNotNull(report);
139
		assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID).getValue());
140
		assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
141
		assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
142
		assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT).getValue());
143
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
144
		assertEquals("Windows", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
145
		assertEquals("other", report.getAttribute(BugzillaReportElement.VERSION).getValue());
146
		assertEquals("P2", report.getAttribute(BugzillaReportElement.PRIORITY).getValue());
147
		assertEquals("normal", report.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue());
148
		assertEquals("NEW", report.getAttribute(BugzillaReportElement.BUG_STATUS).getValue());
149
		assertEquals("2006-03-02 18:13", report.getAttribute(BugzillaReportElement.CREATION_TS).getValue());
150
		assertEquals("2006-05-03 13:06:11", report.getAttribute(BugzillaReportElement.DELTA_TS).getValue());
151
		assertEquals("---", report.getAttribute(BugzillaReportElement.TARGET_MILESTONE).getValue());
152
		AbstractRepositoryReportAttribute attribute = report.getAttribute(BugzillaReportElement.BLOCKED);
153
		assertEquals(2, attribute.getValues().size());
154
		assertEquals("2", attribute.getValues().get(0));
155
		assertEquals("9", attribute.getValues().get(1));
156
		attribute = report.getAttribute(BugzillaReportElement.CC);
157
		assertEquals(2, attribute.getValues().size());
158
		assertEquals("relves@cs.ubc.ca", attribute.getValues().get(0));
159
		assertEquals("relves@gmail.com", attribute.getValues().get(1));
160
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.REPORTER).getValue());
161
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.ASSIGNED_TO).getValue());
162
		assertEquals(1, report.getComments().size());
163
		assertEquals("relves@cs.ubc.ca", report.getComments().get(0).getAttribute(BugzillaReportElement.WHO).getValue());
164
		assertEquals("2006-03-02 18:13", report.getComments().get(0).getAttribute(BugzillaReportElement.BUG_WHEN)
165
				.getValue());
166
		assertEquals("search-match-test 1", report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT)
167
				.getValue());
168
		assertEquals(0, report.getAttachments().size());
169
	}
170
171
	public void testReadingReport2201Eclipse() throws Exception {
172
		int bugid = 24448;
173
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
174
				IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
175
176
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
177
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
178
		factory.populateReport(report, repository);
179
180
		assertNotNull(report);
181
		assertEquals("24448", report.getAttribute(BugzillaReportElement.BUG_ID).getValue());
182
		assertEquals("Ant causing Out of Memory", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
183
		assertEquals("Platform", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
184
		assertEquals("Ant", report.getAttribute(BugzillaReportElement.COMPONENT).getValue());
185
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
186
		assertEquals("other", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
187
		assertEquals("2.0", report.getAttribute(BugzillaReportElement.VERSION).getValue());
188
		assertEquals("P2", report.getAttribute(BugzillaReportElement.PRIORITY).getValue());
189
		assertEquals("normal", report.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue());
190
		assertEquals("RESOLVED", report.getAttribute(BugzillaReportElement.BUG_STATUS).getValue());
191
		assertEquals("WONTFIX", report.getAttribute(BugzillaReportElement.RESOLUTION).getValue());
192
		assertEquals("2002-10-07 09:32", report.getAttribute(BugzillaReportElement.CREATION_TS).getValue());
193
		assertEquals("2006-02-03 12:03:57", report.getAttribute(BugzillaReportElement.DELTA_TS).getValue());
194
		assertEquals("core, performance, ui", report.getAttribute(BugzillaReportElement.KEYWORDS).getValue());
195
		// AbstractRepositoryReportAttribute attribute =
196
		// report.getAttribute(BugzillaReportElement.CC);
197
		// assertEquals(30, attribute.getValues().size());
198
		// assertEquals("relves@cs.ubc.ca", attribute.getValues().get(0));
199
		// assertEquals("relves@gmail.com", attribute.getValues().get(1));
200
		// assertEquals("relves@cs.ubc.ca",
201
		// report.getAttribute(BugzillaReportElement.REPORTER).getValue());
202
		// assertEquals("relves@cs.ubc.ca",
203
		// report.getAttribute(BugzillaReportElement.ASSIGNED_TO).getValue());
204
		// assertEquals(1, report.getComments().size());
205
		// assertEquals("relves@cs.ubc.ca",
206
		// report.getComments().get(0).getAttribute(BugzillaReportElement.WHO).getValue());
207
		// assertEquals("2006-03-02 18:13",
208
		// report.getComments().get(0).getAttribute(BugzillaReportElement.BUG_WHEN)
209
		// .getValue());
210
		// assertEquals("search-match-test 1",
211
		// report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT)
212
		// .getValue());
213
		// assertEquals(0, report.getAttachments().size());
214
	}
215
216
	public void testReadingReport220() throws Exception {
217
		int bugid = 1;
218
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
219
				IBugzillaConstants.TEST_BUGZILLA_220_URL);
220
221
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
222
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
223
		factory.populateReport(report, repository);
224
225
		assertNotNull(report);
226
		assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID).getValue());
227
		assertEquals("search-match-test", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
228
		assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
229
		assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT).getValue());
230
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
231
		assertEquals("Windows", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
232
		assertEquals("other", report.getAttribute(BugzillaReportElement.VERSION).getValue());
233
		assertEquals("P2", report.getAttribute(BugzillaReportElement.PRIORITY).getValue());
234
		assertEquals("normal", report.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue());
235
		assertEquals("NEW", report.getAttribute(BugzillaReportElement.BUG_STATUS).getValue());
236
		assertEquals("2006-03-02 17:30", report.getAttribute(BugzillaReportElement.CREATION_TS).getValue());
237
		assertEquals("2006-04-20 15:13:43", report.getAttribute(BugzillaReportElement.DELTA_TS).getValue());
238
		assertEquals("---", report.getAttribute(BugzillaReportElement.TARGET_MILESTONE).getValue());
239
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.REPORTER).getValue());
240
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.ASSIGNED_TO).getValue());
241
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.CC).getValue());
242
		assertEquals(3, report.getComments().size());
243
		assertEquals("relves@cs.ubc.ca", report.getComments().get(0).getAttribute(BugzillaReportElement.WHO).getValue());
244
		assertEquals("2006-03-02 17:30", report.getComments().get(0).getAttribute(BugzillaReportElement.BUG_WHEN)
245
				.getValue());
246
		assertEquals("search-match-test", report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT)
247
				.getValue());
248
		assertEquals(0, report.getAttachments().size());
249
	}
250
251
	public void testReadingReport218() throws Exception {
252
		int bugid = 1;
253
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
254
				IBugzillaConstants.TEST_BUGZILLA_218_URL);
255
256
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
257
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
258
		factory.populateReport(report, repository);
259
260
		assertNotNull(report);
261
		assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID).getValue());
262
		assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC).getValue());
263
		assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT).getValue());
264
		assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT).getValue());
265
		assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM).getValue());
266
		assertEquals("Windows XP", report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
267
		assertEquals("other", report.getAttribute(BugzillaReportElement.VERSION).getValue());
268
		assertEquals("P2", report.getAttribute(BugzillaReportElement.PRIORITY).getValue());
269
		assertEquals("normal", report.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue());
270
		assertEquals("NEW", report.getAttribute(BugzillaReportElement.BUG_STATUS).getValue());
271
		assertEquals("2006-03-02 18:09", report.getAttribute(BugzillaReportElement.CREATION_TS).getValue());
272
		assertEquals("2006-05-05 17:45:24", report.getAttribute(BugzillaReportElement.DELTA_TS).getValue());
273
		assertEquals("---", report.getAttribute(BugzillaReportElement.TARGET_MILESTONE).getValue());
274
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.REPORTER).getValue());
275
		assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.ASSIGNED_TO).getValue());
276
		assertEquals(1, report.getComments().size());
277
		assertEquals("relves@cs.ubc.ca", report.getComments().get(0).getAttribute(BugzillaReportElement.WHO).getValue());
278
		assertEquals("2006-03-02 18:09", report.getComments().get(0).getAttribute(BugzillaReportElement.BUG_WHEN)
279
				.getValue());
280
		assertEquals("search-match-test 1", report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT)
281
				.getValue());
282
		assertEquals(0, report.getAttachments().size());
283
	}
284
285
	public void testBugReportAPI() throws Exception {
286
		int bugid = 4;
287
		TaskRepository repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
288
				IBugzillaConstants.TEST_BUGZILLA_222_URL);
289
290
		BugzillaReport report = new BugzillaReport(bugid, repository.getUrl());
291
		BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(), report);
292
		factory.populateReport(report, repository);
293
294
		assertNotNull(report);
295
		assertTrue(report instanceof BugzillaReport);
296
		BugzillaReport bugReport = (BugzillaReport) report;
297
		assertEquals("Another Test", bugReport.getSummary());
298
		assertEquals("Testing new 2.22 version capability", bugReport.getDescription());
299
		assertEquals("TestProduct", bugReport.getProduct());
300
		assertEquals("relves@cs.ubc.ca", bugReport.getAssignedTo());
301
		// assertEquals("Other",
302
		// report.getAttribute(BugzillaReportElement.OP_SYS).getValue());
303
		// assertEquals(37, report.getComments().size());
304
		// assertEquals("Testing new 2.22 version capability",
305
		// report.getComments().get(0).getAttribute(BugzillaReportElement.THETEXT).getValue());
306
		// assertEquals(15, report.getAttachments().size());
307
		// assertEquals("1",
308
		// report.getAttachments().get(0).getAttribute(BugzillaReportElement.ATTACHID).getValue());
309
	}
310
}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaReportNode.java (-4 / +4 lines)
Lines 18-24 Link Here
18
18
19
import javax.security.auth.login.LoginException;
19
import javax.security.auth.login.LoginException;
20
20
21
import org.eclipse.mylar.bugzilla.core.BugReport;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
23
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchHit;
23
import org.eclipse.mylar.internal.bugzilla.core.search.BugzillaSearchHit;
24
24
Lines 43-49 Link Here
43
	private List<StackTrace> stackTraces;
43
	private List<StackTrace> stackTraces;
44
44
45
	/** The bug report associated with this DoiInfo */
45
	/** The bug report associated with this DoiInfo */
46
	private BugReport bug;
46
	private BugzillaReport bug;
47
47
48
	/**
48
	/**
49
	 * Constructor
49
	 * Constructor
Lines 107-113 Link Here
107
	 * @throws LoginException
107
	 * @throws LoginException
108
	 * @throws MalformedURLException
108
	 * @throws MalformedURLException
109
	 */
109
	 */
110
	public BugReport getBug() throws MalformedURLException, LoginException, IOException {
110
	public BugzillaReport getBug() throws MalformedURLException, LoginException, IOException {
111
		if (bug == null) {
111
		if (bug == null) {
112
			// get the bug report
112
			// get the bug report
113
			bug = BugzillaRepositoryUtil.getBug(hit.getRepository(), hit.getId());
113
			bug = BugzillaRepositoryUtil.getBug(hit.getRepository(), hit.getId());
Lines 121-127 Link Here
121
	 * @param bug -
121
	 * @param bug -
122
	 *            BugReport that this is associated with
122
	 *            BugReport that this is associated with
123
	 */
123
	 */
124
	public void setBug(BugReport bug) {
124
	public void setBug(BugzillaReport bug) {
125
		this.bug = bug;
125
		this.bug = bug;
126
	}
126
	}
127
127
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaTask.java (-9 / +10 lines)
Lines 16-26 Link Here
16
import java.util.Date;
16
import java.util.Date;
17
import java.util.List;
17
import java.util.List;
18
18
19
import org.eclipse.mylar.bugzilla.core.BugReport;
19
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
20
import org.eclipse.mylar.bugzilla.core.Comment;
20
import org.eclipse.mylar.bugzilla.core.Comment;
21
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
21
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
24
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
26
import org.eclipse.mylar.internal.bugzilla.core.internal.OfflineReportsFile;
26
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
27
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
Lines 34-40 Link Here
34
	 * The bug report for this BugzillaTask. This is <code>null</code> if the
35
	 * The bug report for this BugzillaTask. This is <code>null</code> if the
35
	 * bug report with the specified ID was unable to download.
36
	 * bug report with the specified ID was unable to download.
36
	 */
37
	 */
37
	protected transient BugReport bugReport = null;
38
	protected transient BugzillaReport bugReport = null;
38
39
39
	public BugzillaTask(String handle, String label, boolean newTask) {
40
	public BugzillaTask(String handle, String label, boolean newTask) {
40
		super(handle, label, newTask);
41
		super(handle, label, newTask);
Lines 70-76 Link Here
70
			bugReport = null;
71
			bugReport = null;
71
			return true;
72
			return true;
72
		}
73
		}
73
		bugReport = (BugReport) tempBug;
74
		bugReport = (BugzillaReport) tempBug;
74
75
75
		if (bugReport.hasChanges())
76
		if (bugReport.hasChanges())
76
			syncState = RepositoryTaskSyncState.OUTGOING;
77
			syncState = RepositoryTaskSyncState.OUTGOING;
Lines 90-102 Link Here
90
		}
91
		}
91
	}
92
	}
92
93
93
	public BugReport getBugReport() {
94
	public BugzillaReport getBugReport() {
94
		return bugReport;
95
		return bugReport;
95
	}
96
	}
96
	
97
	
97
	public String getTaskType() {
98
	public String getTaskType() {
98
		if (bugReport != null && bugReport.getAttribute(BugReport.ATTRIBUTE_SEVERITY) != null) {
99
		if (bugReport != null && bugReport.getAttribute(BugzillaReportElement.BUG_SEVERITY) != null) {
99
			return bugReport.getAttribute(BugReport.ATTRIBUTE_SEVERITY).getValue();
100
			return bugReport.getAttribute(BugzillaReportElement.BUG_SEVERITY).getValue();
100
		} else {
101
		} else {
101
			return null;
102
			return null;
102
		}
103
		}
Lines 106-112 Link Here
106
	 * @param bugReport
107
	 * @param bugReport
107
	 *            The bugReport to set.
108
	 *            The bugReport to set.
108
	 */
109
	 */
109
	public void setBugReport(BugReport bugReport) {
110
	public void setBugReport(BugzillaReport bugReport) {
110
		this.bugReport = bugReport;
111
		this.bugReport = bugReport;
111
		
112
		
112
		// TODO: remove?
113
		// TODO: remove?
Lines 162-169 Link Here
162
163
163
	@Override
164
	@Override
164
	public String getPriority() {
165
	public String getPriority() {
165
		if (bugReport != null && bugReport.getAttribute(BugReport.ATTR_PRIORITY) != null) {
166
		if (bugReport != null && bugReport.getAttribute(BugzillaReportElement.PRIORITY) != null) {
166
			return bugReport.getAttribute(BugReport.ATTR_PRIORITY).getValue();
167
			return bugReport.getAttribute(BugzillaReportElement.PRIORITY).getValue();
167
		} else {
168
		} else {
168
			return super.getPriority();
169
			return super.getPriority();
169
		}
170
		}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaCacheFile.java (-7 / +7 lines)
Lines 21-27 Link Here
21
import java.util.List;
21
import java.util.List;
22
22
23
import org.eclipse.jface.dialogs.MessageDialog;
23
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
24
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
25
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
26
26
27
/**
27
/**
Lines 35-41 Link Here
35
35
36
	private File file;
36
	private File file;
37
37
38
	private ArrayList<IBugzillaBug> list = new ArrayList<IBugzillaBug>();
38
	private ArrayList<BugzillaReport> list = new ArrayList<BugzillaReport>();
39
39
40
	protected int latestNewBugId = 0;
40
	protected int latestNewBugId = 0;
41
41
Lines 46-52 Link Here
46
		}
46
		}
47
	}
47
	}
48
48
49
	public void add(IBugzillaBug entry) {
49
	public void add(BugzillaReport entry) {
50
		// add the entry to the list and write the file to disk
50
		// add the entry to the list and write the file to disk
51
		list.add(entry);
51
		list.add(entry);
52
		writeFile();
52
		writeFile();
Lines 63-76 Link Here
63
63
64
	public int find(int id) {
64
	public int find(int id) {
65
		for (int i = 0; i < list.size(); i++) {
65
		for (int i = 0; i < list.size(); i++) {
66
			IBugzillaBug currBug = list.get(i);
66
			BugzillaReport currBug = list.get(i);
67
			if (currBug != null && (currBug.getId() == id) && !currBug.isLocallyCreated())
67
			if (currBug != null && (currBug.getId() == id) && !currBug.isLocallyCreated())
68
				return i;
68
				return i;
69
		}
69
		}
70
		return -1;
70
		return -1;
71
	}
71
	}
72
72
73
	public ArrayList<IBugzillaBug> elements() {
73
	public ArrayList<BugzillaReport> elements() {
74
		return list;
74
		return list;
75
	}
75
	}
76
76
Lines 108-121 Link Here
108
108
109
		// read in each of the offline reports in the file
109
		// read in each of the offline reports in the file
110
		for (int nX = 0; nX < size; nX++) {
110
		for (int nX = 0; nX < size; nX++) {
111
			IBugzillaBug item = (IBugzillaBug) in.readObject();
111
			BugzillaReport item = (BugzillaReport) in.readObject();
112
			// add the offline report to the offlineReports list
112
			// add the offline report to the offlineReports list
113
			list.add(item);
113
			list.add(item);
114
		}
114
		}
115
		in.close();
115
		in.close();
116
	}
116
	}
117
117
118
	public void remove(List<IBugzillaBug> sel) {
118
	public void remove(List<BugzillaReport> sel) {
119
		list.removeAll(sel);
119
		list.removeAll(sel);
120
120
121
		// rewrite the file so that the data is persistant
121
		// rewrite the file so that the data is persistant
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositoryConnector.java (-26 / +40 lines)
Lines 34-43 Link Here
34
import org.eclipse.jface.window.ApplicationWindow;
34
import org.eclipse.jface.window.ApplicationWindow;
35
import org.eclipse.jface.wizard.IWizard;
35
import org.eclipse.jface.wizard.IWizard;
36
import org.eclipse.jface.wizard.WizardDialog;
36
import org.eclipse.jface.wizard.WizardDialog;
37
import org.eclipse.mylar.bugzilla.core.BugReport;
37
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReport;
38
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
38
import org.eclipse.mylar.bugzilla.core.BugzillaRemoteContextDelegate;
39
import org.eclipse.mylar.bugzilla.core.BugzillaRemoteContextDelegate;
39
import org.eclipse.mylar.bugzilla.core.Comment;
40
import org.eclipse.mylar.bugzilla.core.ReportAttachment;
40
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
41
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
41
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
42
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
42
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
43
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
43
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
Lines 147-158 Link Here
147
		return BugzillaPlugin.REPOSITORY_KIND;
147
		return BugzillaPlugin.REPOSITORY_KIND;
148
	}
148
	}
149
149
150
	public void saveBugReport(IBugzillaBug bugzillaBug) {
150
	public void saveBugReport(BugzillaReport bugzillaBug) {
151
		String handle = AbstractRepositoryTask.getHandle(bugzillaBug.getRepositoryUrl(), bugzillaBug.getId());
151
		String handle = AbstractRepositoryTask.getHandle(bugzillaBug.getRepositoryUrl(), bugzillaBug.getId());
152
		ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
152
		ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
153
		if (task instanceof BugzillaTask) {
153
		if (task instanceof BugzillaTask) {
154
			BugzillaTask bugzillaTask = (BugzillaTask) task;
154
			BugzillaTask bugzillaTask = (BugzillaTask) task;
155
			bugzillaTask.setBugReport((BugReport) bugzillaBug);
155
			bugzillaTask.setBugReport((BugzillaReport) bugzillaBug);
156
156
157
			if (bugzillaBug.hasChanges()) {
157
			if (bugzillaBug.hasChanges()) {
158
				bugzillaTask.setSyncState(RepositoryTaskSyncState.OUTGOING);
158
				bugzillaTask.setSyncState(RepositoryTaskSyncState.OUTGOING);
Lines 164-170 Link Here
164
164
165
	}
165
	}
166
166
167
	private BugReport downloadReport(final BugzillaTask bugzillaTask) {
167
	private BugzillaReport downloadReport(final BugzillaTask bugzillaTask) {
168
		try {
168
		try {
169
			return BugzillaRepositoryUtil.getBug(bugzillaTask.getRepositoryUrl(), AbstractRepositoryTask
169
			return BugzillaRepositoryUtil.getBug(bugzillaTask.getRepositoryUrl(), AbstractRepositoryTask
170
					.getTaskIdAsInt(bugzillaTask.getHandleIdentifier()));
170
					.getTaskIdAsInt(bugzillaTask.getHandleIdentifier()));
Lines 325-331 Link Here
325
		}
325
		}
326
	}
326
	}
327
327
328
	private static void offlineStatusChange(IBugzillaBug bug, BugzillaOfflineStatus status, boolean forceSynch) {
328
	private static void offlineStatusChange(AbstractRepositoryReport report, BugzillaOfflineStatus status,
329
			boolean forceSynch) {
329
330
330
		RepositoryTaskSyncState state = null;
331
		RepositoryTaskSyncState state = null;
331
		if (status == BugzillaOfflineStatus.SAVED_WITH_OUTGOING_CHANGES) {
332
		if (status == BugzillaOfflineStatus.SAVED_WITH_OUTGOING_CHANGES) {
Lines 350-356 Link Here
350
			return;
351
			return;
351
		}
352
		}
352
353
353
		String handle = AbstractRepositoryTask.getHandle(bug.getRepositoryUrl(), bug.getId());
354
		String handle = AbstractRepositoryTask.getHandle(report.getRepositoryUrl(), report.getId());
354
		ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
355
		ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
355
		if (task != null && task instanceof BugzillaTask) {
356
		if (task != null && task instanceof BugzillaTask) {
356
			BugzillaTask bugTask = (BugzillaTask) task;
357
			BugzillaTask bugTask = (BugzillaTask) task;
Lines 359-365 Link Here
359
		}
360
		}
360
	}
361
	}
361
362
362
	public void submitBugReport(final IBugzillaBug bugReport, final BugzillaReportSubmitForm form,
363
	public void submitBugReport(final BugzillaReport bugReport, final BugzillaReportSubmitForm form,
363
			IJobChangeListener listener) {
364
			IJobChangeListener listener) {
364
365
365
		if (forceSyncExecForTesting) {
366
		if (forceSyncExecForTesting) {
Lines 412-418 Link Here
412
		}
413
		}
413
	}
414
	}
414
415
415
	private void internalSubmitBugReport(IBugzillaBug bugReport, BugzillaReportSubmitForm form) {
416
	private void internalSubmitBugReport(BugzillaReport bugReport, BugzillaReportSubmitForm form) {
416
		try {
417
		try {
417
			form.submitReportToRepository();
418
			form.submitReportToRepository();
418
			removeReport(bugReport);
419
			removeReport(bugReport);
Lines 420-428 Link Here
420
			// TODO: avoid getting archive tasks?
421
			// TODO: avoid getting archive tasks?
421
			ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
422
			ITask task = MylarTaskListPlugin.getTaskListManager().getTaskList().getTask(handle);
422
423
423
			Set<AbstractRepositoryQuery> queriesWithHandle = MylarTaskListPlugin.getTaskListManager().getTaskList()
424
			// TODO: re-enable synchronization of queries with task. Redundant?
424
					.getQueriesForHandle(task.getHandleIdentifier());
425
			// Set<AbstractRepositoryQuery> queriesWithHandle =
425
			synchronize(queriesWithHandle, null, Job.INTERACTIVE, 0);
426
			// MylarTaskListPlugin.getTaskListManager().getTaskList()
427
			// .getQueriesForHandle(task.getHandleIdentifier());
428
			// synchronize(queriesWithHandle, null, Job.INTERACTIVE, 0);
429
426
			// for (AbstractRepositoryQuery query : queriesWithHandle) {
430
			// for (AbstractRepositoryQuery query : queriesWithHandle) {
427
			// synchronize(query, null);
431
			// synchronize(query, null);
428
			// }
432
			// }
Lines 444-450 Link Here
444
	 * @param saveChosen
448
	 * @param saveChosen
445
	 *            This is used to determine a refresh from a user save
449
	 *            This is used to determine a refresh from a user save
446
	 */
450
	 */
447
	public BugzillaOfflineStatus saveOffline(final IBugzillaBug bug, final boolean forceSynch) {
451
	public BugzillaOfflineStatus saveOffline(final BugzillaReport bug, final boolean forceSynch) {
448
452
449
		BugzillaOfflineStatus status = BugzillaOfflineStatus.ERROR;
453
		BugzillaOfflineStatus status = BugzillaOfflineStatus.ERROR;
450
454
Lines 460-468 Link Here
460
		return status;
464
		return status;
461
	}
465
	}
462
466
463
	private void internalSaveOffline(final IBugzillaBug bug, final boolean forceSynch) {
467
	// TODO: pull up
468
	private void internalSaveOffline(final BugzillaReport report, final boolean forceSynch) {
464
		// If there is already an offline report for this bug, update the file.
469
		// If there is already an offline report for this bug, update the file.
465
		if (bug.isSavedOffline()) {
470
		if (((AbstractRepositoryReport) report).isSavedOffline()) {
466
			offlineReportsFile.update();
471
			offlineReportsFile.update();
467
		} else {
472
		} else {
468
			try {
473
			try {
Lines 479-488 Link Here
479
				// // identical id.");
484
				// // identical id.");
480
				// // return;
485
				// // return;
481
				// }
486
				// }
482
				BugzillaOfflineStatus offlineStatus = offlineReportsFile.add(bug, false);
487
				BugzillaOfflineStatus offlineStatus = offlineReportsFile.add(report, false);
483
				bug.setOfflineState(true);
488
				((AbstractRepositoryReport) report).setOfflineState(true);
484
				// saveForced forced to false (hack)
489
				// saveForced forced to false (hack)
485
				offlineStatusChange(bug, offlineStatus, forceSynch);
490
				offlineStatusChange(report, offlineStatus, forceSynch);
486
491
487
			} catch (CoreException e) {
492
			} catch (CoreException e) {
488
				MylarStatusHandler.fail(e, e.getMessage(), false);
493
				MylarStatusHandler.fail(e, e.getMessage(), false);
Lines 491-505 Link Here
491
		}
496
		}
492
	}
497
	}
493
498
494
	public static List<IBugzillaBug> getOfflineBugs() {
499
	public static List<BugzillaReport> getOfflineBugs() {
495
		OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
500
		OfflineReportsFile file = BugzillaPlugin.getDefault().getOfflineReports();
496
		return file.elements();
501
		return file.elements();
497
	}
502
	}
498
503
499
	public static void removeReport(IBugzillaBug bug) {
504
	public static void removeReport(BugzillaReport bug) {
500
		bug.setOfflineState(false);
505
		bug.setOfflineState(false);
501
		offlineStatusChange(bug, BugzillaOfflineStatus.DELETED, false);
506
		offlineStatusChange(bug, BugzillaOfflineStatus.DELETED, false);
502
		ArrayList<IBugzillaBug> bugList = new ArrayList<IBugzillaBug>();
507
		ArrayList<BugzillaReport> bugList = new ArrayList<BugzillaReport>();
503
		bugList.add(bug);
508
		bugList.add(bug);
504
		BugzillaPlugin.getDefault().getOfflineReports().remove(bugList);
509
		BugzillaPlugin.getDefault().getOfflineReports().remove(bugList);
505
	}
510
	}
Lines 574-580 Link Here
574
	protected void updateOfflineState(AbstractRepositoryTask repositoryTask, boolean forceSync) {
579
	protected void updateOfflineState(AbstractRepositoryTask repositoryTask, boolean forceSync) {
575
		if (repositoryTask instanceof BugzillaTask) {
580
		if (repositoryTask instanceof BugzillaTask) {
576
			BugzillaTask bugzillaTask = (BugzillaTask) repositoryTask;
581
			BugzillaTask bugzillaTask = (BugzillaTask) repositoryTask;
577
			BugReport downloadedReport = downloadReport(bugzillaTask);
582
			BugzillaReport downloadedReport = downloadReport(bugzillaTask);
578
			if (downloadedReport != null) {
583
			if (downloadedReport != null) {
579
				bugzillaTask.setBugReport(downloadedReport);
584
				bugzillaTask.setBugReport(downloadedReport);
580
				saveOffline(downloadedReport, forceSync);
585
				saveOffline(downloadedReport, forceSync);
Lines 649-659 Link Here
649
		if (task instanceof BugzillaTask) {
654
		if (task instanceof BugzillaTask) {
650
			BugzillaTask bugzillaTask = (BugzillaTask) task;
655
			BugzillaTask bugzillaTask = (BugzillaTask) task;
651
			if (bugzillaTask.getBugReport() != null) {
656
			if (bugzillaTask.getBugReport() != null) {
652
				for (Comment comment : bugzillaTask.getBugReport().getComments()) {
657
				for (ReportAttachment attachment : bugzillaTask.getBugReport().getAttachments()) {
653
					if (comment.hasAttachment() && comment.getAttachmentDescription().equals(MYLAR_CONTEXT_DESCRIPTION)) {
658
					if (attachment.getDescription().equals(MYLAR_CONTEXT_DESCRIPTION)) {
654
						contextDelegates.add(new BugzillaRemoteContextDelegate(comment));
659
						contextDelegates.add(new BugzillaRemoteContextDelegate(attachment));
655
					}
660
					}
656
				}
661
				}
662
				// for (Comment comment :
663
				// bugzillaTask.getBugReport().getComments()) {
664
				// if (comment.hasAttachment() &&
665
				// comment.getAttachmentDescription().equals(MYLAR_CONTEXT_DESCRIPTION))
666
				// {
667
				// contextDelegates.add(new
668
				// BugzillaRemoteContextDelegate(comment));
669
				// }
670
				// }
657
			}
671
			}
658
		}
672
		}
659
		return contextDelegates;
673
		return contextDelegates;
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java (-4 / +4 lines)
Lines 18-24 Link Here
18
import javax.security.auth.login.LoginException;
18
import javax.security.auth.login.LoginException;
19
19
20
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.mylar.bugzilla.core.BugReport;
21
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
22
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditorInput;
22
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditorInput;
23
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
23
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask;
24
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask.RepositoryTaskSyncState;
24
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryTask.RepositoryTaskSyncState;
Lines 32-38 Link Here
32
32
33
	private String bugTitle;
33
	private String bugTitle;
34
34
35
	private BugReport offlineBug;
35
	private BugzillaReport offlineBug;
36
36
37
	private BugzillaTask bugTask;
37
	private BugzillaTask bugTask;
38
38
Lines 99-105 Link Here
99
	/**
99
	/**
100
	 * Returns the offline bug for this input's Bugzilla task
100
	 * Returns the offline bug for this input's Bugzilla task
101
	 */
101
	 */
102
	public BugReport getOfflineBug() {
102
	public BugzillaReport getOfflineBug() {
103
		if (offline || bugTask.getSyncState() == RepositoryTaskSyncState.OUTGOING
103
		if (offline || bugTask.getSyncState() == RepositoryTaskSyncState.OUTGOING
104
				|| bugTask.getSyncState() == RepositoryTaskSyncState.CONFLICT)
104
				|| bugTask.getSyncState() == RepositoryTaskSyncState.CONFLICT)
105
			return offlineBug;
105
			return offlineBug;
Lines 107-113 Link Here
107
			return super.getBug();
107
			return super.getBug();
108
	}
108
	}
109
109
110
	public void setOfflineBug(BugReport offlineBug) {
110
	public void setOfflineBug(BugzillaReport offlineBug) {
111
		this.offlineBug = offlineBug;
111
		this.offlineBug = offlineBug;
112
	}
112
	}
113
113
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java (-2 / +3 lines)
Lines 24-29 Link Here
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
26
import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
26
import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
27
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
27
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
28
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.events.SelectionEvent;
Lines 40-49 Link Here
40
	private static final String TITLE = "Bugzilla Repository Settings";
41
	private static final String TITLE = "Bugzilla Repository Settings";
41
42
42
	private static final String DESCRIPTION = "Example: https://bugs.eclipse.org/bugs (do not include index.cgi)";
43
	private static final String DESCRIPTION = "Example: https://bugs.eclipse.org/bugs (do not include index.cgi)";
43
	private BugzillaRepositoryConnector connector;
44
	private AbstractRepositoryConnector connector;
44
	protected Combo repositoryVersionCombo;
45
	protected Combo repositoryVersionCombo;
45
	
46
	
46
	public BugzillaRepositorySettingsPage(BugzillaRepositoryConnector connector) {
47
	public BugzillaRepositorySettingsPage(AbstractRepositoryConnector connector) {
47
		super(TITLE, DESCRIPTION);
48
		super(TITLE, DESCRIPTION);
48
		this.connector = connector;
49
		this.connector = connector;
49
	}
50
	}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/tasklist/BugzillaTaskEditor.java (-4 / +4 lines)
Lines 16-22 Link Here
16
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.resources.IMarker;
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.jface.dialogs.MessageDialog;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.mylar.bugzilla.core.BugReport;
19
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
20
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaAttributeListener;
20
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaAttributeListener;
21
import org.eclipse.mylar.internal.bugzilla.ui.editor.AbstractBugEditor;
21
import org.eclipse.mylar.internal.bugzilla.ui.editor.AbstractBugEditor;
22
import org.eclipse.mylar.internal.bugzilla.ui.editor.BugzillaOutlineNode;
22
import org.eclipse.mylar.internal.bugzilla.ui.editor.BugzillaOutlineNode;
Lines 42-48 Link Here
42
	protected BugzillaTask bugTask;
42
	protected BugzillaTask bugTask;
43
43
44
	/** This bug report can be modified by the user and saved offline. */
44
	/** This bug report can be modified by the user and saved offline. */
45
	protected BugReport offlineBug;
45
	protected BugzillaReport offlineBug;
46
46
47
	private ExistingBugEditor bugzillaEditor;
47
	private ExistingBugEditor bugzillaEditor;
48
48
Lines 189-195 Link Here
189
	/**
189
	/**
190
	 * @return Returns the offlineBug.
190
	 * @return Returns the offlineBug.
191
	 */
191
	 */
192
	public BugReport getOfflineBug() {
192
	public BugzillaReport getOfflineBug() {
193
		return offlineBug;
193
		return offlineBug;
194
	}
194
	}
195
195
Lines 270-276 Link Here
270
	// }
270
	// }
271
	// }
271
	// }
272
272
273
	public void makeNewPage(BugReport serverBug, String newCommentText) {
273
	public void makeNewPage(BugzillaReport serverBug, String newCommentText) {
274
		if (serverBug == null) {
274
		if (serverBug == null) {
275
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
275
			MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
276
					"Could not open bug.", "Bug #" + offlineBug.getId()
276
					"Could not open bug.", "Bug #" + offlineBug.getId()
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/ExistingBugEditor.java (-98 / +110 lines)
Lines 34-41 Link Here
34
import org.eclipse.jface.text.TextViewer;
34
import org.eclipse.jface.text.TextViewer;
35
import org.eclipse.jface.viewers.SelectionChangedEvent;
35
import org.eclipse.jface.viewers.SelectionChangedEvent;
36
import org.eclipse.jface.viewers.StructuredSelection;
36
import org.eclipse.jface.viewers.StructuredSelection;
37
import org.eclipse.mylar.bugzilla.core.Attribute;
37
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
38
import org.eclipse.mylar.bugzilla.core.BugReport;
38
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
39
import org.eclipse.mylar.bugzilla.core.Comment;
39
import org.eclipse.mylar.bugzilla.core.Comment;
40
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
40
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
41
import org.eclipse.mylar.bugzilla.core.Operation;
41
import org.eclipse.mylar.bugzilla.core.Operation;
Lines 44-59 Link Here
44
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
44
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
45
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
45
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
46
import org.eclipse.mylar.internal.bugzilla.core.compare.BugzillaCompareInput;
46
import org.eclipse.mylar.internal.bugzilla.core.compare.BugzillaCompareInput;
47
import org.eclipse.mylar.internal.bugzilla.core.internal.HtmlStreamTokenizer;
47
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
48
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
48
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
49
import org.eclipse.mylar.internal.tasklist.ui.TaskUiUtil;
50
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
49
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
51
import org.eclipse.swt.SWT;
50
import org.eclipse.swt.SWT;
52
import org.eclipse.swt.custom.CCombo;
51
import org.eclipse.swt.custom.CCombo;
53
import org.eclipse.swt.custom.StyledText;
52
import org.eclipse.swt.custom.StyledText;
54
import org.eclipse.swt.events.ModifyEvent;
53
import org.eclipse.swt.events.ModifyEvent;
55
import org.eclipse.swt.events.ModifyListener;
54
import org.eclipse.swt.events.ModifyListener;
56
import org.eclipse.swt.events.SelectionAdapter;
57
import org.eclipse.swt.events.SelectionEvent;
55
import org.eclipse.swt.events.SelectionEvent;
58
import org.eclipse.swt.events.SelectionListener;
56
import org.eclipse.swt.events.SelectionListener;
59
import org.eclipse.swt.layout.GridData;
57
import org.eclipse.swt.layout.GridData;
Lines 62-68 Link Here
62
import org.eclipse.swt.widgets.Composite;
60
import org.eclipse.swt.widgets.Composite;
63
import org.eclipse.swt.widgets.Control;
61
import org.eclipse.swt.widgets.Control;
64
import org.eclipse.swt.widgets.Event;
62
import org.eclipse.swt.widgets.Event;
65
import org.eclipse.swt.widgets.Link;
66
import org.eclipse.swt.widgets.List;
63
import org.eclipse.swt.widgets.List;
67
import org.eclipse.swt.widgets.Listener;
64
import org.eclipse.swt.widgets.Listener;
68
import org.eclipse.swt.widgets.Text;
65
import org.eclipse.swt.widgets.Text;
Lines 95-101 Link Here
95
92
96
	private static final String LABEL_COMPARE_BUTTON = "Compare";
93
	private static final String LABEL_COMPARE_BUTTON = "Compare";
97
94
98
	private static final String ATTR_SUMMARY = "Summary";
95
	// private static final String ATTR_SUMMARY = "Summary";
99
96
100
	protected Set<String> removeCC = new HashSet<String>();
97
	protected Set<String> removeCC = new HashSet<String>();
101
98
Lines 117-123 Link Here
117
114
118
	protected Text addCommentsText;
115
	protected Text addCommentsText;
119
116
120
	protected BugReport bug;
117
	protected BugzillaReport bug;
121
118
122
	public String getNewCommentText() {
119
	public String getNewCommentText() {
123
		return addCommentsTextBox.getText();
120
		return addCommentsTextBox.getText();
Lines 246-255 Link Here
246
				radioData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
243
				radioData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
247
				radioData.horizontalSpan = 1;
244
				radioData.horizontalSpan = 1;
248
				radioData.widthHint = 120;
245
				radioData.widthHint = 120;
249
				
246
250
				// TODO: add condition for if opName = reassign to...
247
				// TODO: add condition for if opName = reassign to...
251
				String assignmentValue = "";
248
				String assignmentValue = "";
252
				if(opName.equals(REASSIGN_BUG_TO)) {
249
				if (opName.equals(REASSIGN_BUG_TO)) {
253
					assignmentValue = repository.getUserName();
250
					assignmentValue = repository.getUserName();
254
				}
251
				}
255
				radioOptions[i] = toolkit.createText(buttonComposite, assignmentValue);// ,
252
				radioOptions[i] = toolkit.createText(buttonComposite, assignmentValue);// ,
Lines 289-299 Link Here
289
		super.addActionButtons(buttonComposite);
286
		super.addActionButtons(buttonComposite);
290
287
291
		compareButton = toolkit.createButton(buttonComposite, LABEL_COMPARE_BUTTON, SWT.NONE);
288
		compareButton = toolkit.createButton(buttonComposite, LABEL_COMPARE_BUTTON, SWT.NONE);
292
//		compareButton.setFont(TEXT_FONT);
289
		// compareButton.setFont(TEXT_FONT);
293
		GridData compareButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
290
		GridData compareButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
294
//		compareButtonData.widthHint = 100;
291
		// compareButtonData.widthHint = 100;
295
//		compareButtonData.heightHint = 20;
292
		// compareButtonData.heightHint = 20;
296
//		// compareButton.setText("Compare");
293
		// // compareButton.setText("Compare");
297
		compareButton.setLayoutData(compareButtonData);
294
		compareButton.setLayoutData(compareButtonData);
298
		compareButton.addListener(SWT.Selection, new Listener() {
295
		compareButton.addListener(SWT.Selection, new Listener() {
299
			public void handleEvent(Event e) {
296
			public void handleEvent(Event e) {
Lines 317-324 Link Here
317
314
318
			}
315
			}
319
		});
316
		});
320
		
317
321
		
322
		// TODO used for spell checking. Add back when we want to support this
318
		// TODO used for spell checking. Add back when we want to support this
323
		// checkSpellingButton = new Button(buttonComposite, SWT.NONE);
319
		// checkSpellingButton = new Button(buttonComposite, SWT.NONE);
324
		// checkSpellingButton.setFont(TEXT_FONT);
320
		// checkSpellingButton.setFont(TEXT_FONT);
Lines 350-357 Link Here
350
346
351
	@Override
347
	@Override
352
	protected String getTitleString() {
348
	protected String getTitleString() {
353
//		Attribute summary = bug.getAttribute(ATTR_SUMMARY);
349
		// Attribute summary = bug.getAttribute(ATTR_SUMMARY);
354
//		String summaryVal = ((null != summary) ? summary.getNewValue() : null);
350
		// String summaryVal = ((null != summary) ? summary.getNewValue() :
351
		// null);
355
		return bug.getLabel();// + ": " + checkText(summaryVal);
352
		return bug.getLabel();// + ": " + checkText(summaryVal);
356
	}
353
	}
357
354
Lines 430-438 Link Here
430
		descriptionLayout.numColumns = 1;
427
		descriptionLayout.numColumns = 1;
431
		descriptionComposite.setLayout(descriptionLayout);
428
		descriptionComposite.setLayout(descriptionLayout);
432
		// descriptionComposite.setBackground(background);
429
		// descriptionComposite.setBackground(background);
433
		//GridData descriptionData = new GridData(GridData.FILL_HORIZONTAL);
430
		// GridData descriptionData = new GridData(GridData.FILL_HORIZONTAL);
434
		//descriptionData.horizontalSpan = 1;
431
		// descriptionData.horizontalSpan = 1;
435
		//descriptionData.grabExcessVerticalSpace = false;
432
		// descriptionData.grabExcessVerticalSpace = false;
436
		// descriptionComposite.setLayoutData(descriptionData);
433
		// descriptionComposite.setLayoutData(descriptionData);
437
		// End Description Area
434
		// End Description Area
438
435
Lines 442-450 Link Here
442
		// HEADER);
439
		// HEADER);
443
440
444
		// t.addListener(SWT.FocusIn, new DescriptionListener());
441
		// t.addListener(SWT.FocusIn, new DescriptionListener());
445
		//StyledText t = newLayout(descriptionComposite, 4, bug.getDescription(), VALUE);
442
		// StyledText t = newLayout(descriptionComposite, 4,
443
		// bug.getDescription(), VALUE);
446
		// t.setFont(COMMENT_FONT);
444
		// t.setFont(COMMENT_FONT);
447
		
445
448
		TextViewer viewer = addRepositoryText(repository, descriptionComposite, bug.getDescription());
446
		TextViewer viewer = addRepositoryText(repository, descriptionComposite, bug.getDescription());
449
		StyledText styledText = viewer.getTextWidget();
447
		StyledText styledText = viewer.getTextWidget();
450
		styledText.addListener(SWT.FocusIn, new DescriptionListener());
448
		styledText.addListener(SWT.FocusIn, new DescriptionListener());
Lines 489-510 Link Here
489
		addCommentsData.heightHint = DESCRIPTION_HEIGHT;
487
		addCommentsData.heightHint = DESCRIPTION_HEIGHT;
490
		addCommentsData.grabExcessVerticalSpace = false;
488
		addCommentsData.grabExcessVerticalSpace = false;
491
		addCommentsComposite.setLayoutData(addCommentsData);
489
		addCommentsComposite.setLayoutData(addCommentsData);
492
	 // End Additional (read-only) Comments Area
490
		// End Additional (read-only) Comments Area
493
494
		
495
491
496
		StyledText styledText = null;
492
		StyledText styledText = null;
497
		for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();) {
493
		for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();) {
498
			final Comment comment = it.next();
494
			final Comment comment = it.next();
499
495
			
496
			// skip comment 0 as it is the description
497
			if(comment.getNumber() == 0) continue;
498
			
500
			ExpandableComposite ec = toolkit.createExpandableComposite(addCommentsComposite,
499
			ExpandableComposite ec = toolkit.createExpandableComposite(addCommentsComposite,
501
					ExpandableComposite.TREE_NODE);
500
					ExpandableComposite.TREE_NODE);
502
501
503
			if (!it.hasNext()) {
502
			if (!it.hasNext()) {
504
				ec.setExpanded(true);
503
				ec.setExpanded(true);
505
			}
504
			}
506
			
505
507
			ec.setText(comment.getNumber() + ": " +comment.getAuthorName() + ", " + simpleDateFormat.format(comment.getCreated()));
506
			ec.setText(comment.getNumber() + ": " + comment.getAuthorName() + ", "
507
					+ simpleDateFormat.format(comment.getCreated()));
508
508
509
			ec.addExpansionListener(new ExpansionAdapter() {
509
			ec.addExpansionListener(new ExpansionAdapter() {
510
				public void expansionStateChanged(ExpansionEvent e) {
510
				public void expansionStateChanged(ExpansionEvent e) {
Lines 519-562 Link Here
519
			ec.setClient(ecComposite);
519
			ec.setClient(ecComposite);
520
			toolkit.paintBordersFor(ec);
520
			toolkit.paintBordersFor(ec);
521
521
522
			if (comment.hasAttachment()) {
522
			
523
523
			// TODO: Attachments are no longer 'attached' to Comments
524
				Link attachmentLink = new Link(ecComposite, SWT.NONE);
524
			
525
525
//			if (comment.hasAttachment()) {
526
				String attachmentHeader;
526
//
527
				
527
//				Link attachmentLink = new Link(ecComposite, SWT.NONE);
528
				if(!comment.isObsolete()) {
528
//
529
					attachmentHeader = " Attached: " + comment.getAttachmentDescription() + " [<a>view</a>]";
529
//				String attachmentHeader;
530
				} else {
530
//
531
					attachmentHeader = " Deprecated: " + comment.getAttachmentDescription(); 
531
//				if (!comment.isObsolete()) {
532
				}
532
//					attachmentHeader = " Attached: " + comment.getAttachmentDescription() + " [<a>view</a>]";
533
				// String result = MessageFormat.format(attachmentHeader, new
533
//				} else {
534
				// String[] { node
534
//					attachmentHeader = " Deprecated: " + comment.getAttachmentDescription();
535
				// .getLabelText() });
535
//				}
536
536
//				// String result = MessageFormat.format(attachmentHeader, new
537
				attachmentLink.addSelectionListener(new SelectionAdapter() {
537
//				// String[] { node
538
					/*
538
//				// .getLabelText() });
539
					 * (non-Javadoc)
539
//
540
					 * 
540
//				attachmentLink.addSelectionListener(new SelectionAdapter() {
541
					 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
541
//					/*
542
					 */
542
//					 * (non-Javadoc)
543
					public void widgetSelected(SelectionEvent e) {
543
//					 * 
544
						String address = repository.getUrl() + "/attachment.cgi?id=" + comment.getAttachmentId()
544
//					 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
545
								+ "&amp;action=view";
545
//					 */
546
						TaskUiUtil.openUrl(address, address, address);
546
//					public void widgetSelected(SelectionEvent e) {
547
547
//						String address = repository.getUrl() + "/attachment.cgi?id=" + comment.getAttachmentId()
548
					}
548
//								+ "&amp;action=view";
549
				});
549
//						TaskUiUtil.openUrl(address, address, address);
550
550
//
551
				attachmentLink.setText(attachmentHeader);
551
//					}
552
552
//				});
553
			}
553
//
554
//				attachmentLink.setText(attachmentHeader);
555
//
556
//			}
554
557
555
			// styledText = newLayout(ecComposite, 1, comment.getText(), VALUE);
558
			// styledText = newLayout(ecComposite, 1, comment.getText(), VALUE);
556
			// styledText.addListener(SWT.FocusIn, new
559
			// styledText.addListener(SWT.FocusIn, new
557
			// CommentListener(comment));
560
			// CommentListener(comment));
558
			// styledText.setFont(COMMENT_FONT);
561
			// styledText.setFont(COMMENT_FONT);
559
562
			//System.err.println(comment.getNumber()+"   "+comment.getText());
560
			TextViewer viewer = addRepositoryText(repository, ecComposite, comment.getText());
563
			TextViewer viewer = addRepositoryText(repository, ecComposite, comment.getText());
561
			styledText = viewer.getTextWidget();
564
			styledText = viewer.getTextWidget();
562
565
Lines 593-599 Link Here
593
		addCommentsText.setFont(COMMENT_FONT);
596
		addCommentsText.setFont(COMMENT_FONT);
594
		toolkit.paintBordersFor(newCommentsComposite);
597
		toolkit.paintBordersFor(newCommentsComposite);
595
		GridData addCommentsTextData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
598
		GridData addCommentsTextData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
596
		//addCommentsTextData.horizontalSpan = 4;
599
		// addCommentsTextData.horizontalSpan = 4;
597
		addCommentsTextData.widthHint = DESCRIPTION_WIDTH;
600
		addCommentsTextData.widthHint = DESCRIPTION_WIDTH;
598
		addCommentsTextData.heightHint = DESCRIPTION_HEIGHT;
601
		addCommentsTextData.heightHint = DESCRIPTION_HEIGHT;
599
		addCommentsTextData.grabExcessHorizontalSpace = true;
602
		addCommentsTextData.grabExcessHorizontalSpace = true;
Lines 604-611 Link Here
604
607
605
			public void handleEvent(Event event) {
608
			public void handleEvent(Event event) {
606
				String sel = addCommentsText.getText();
609
				String sel = addCommentsText.getText();
607
				if (!(bug.getNewNewComment().equals(sel))) {
610
				if (!(bug.getNewComment().equals(sel))) {
608
					bug.setNewNewComment(sel);
611
					bug.setNewComment(sel);					
609
					changeDirtyStatus(true);
612
					changeDirtyStatus(true);
610
				}
613
				}
611
				validateInput();
614
				validateInput();
Lines 645-653 Link Here
645
		keyWordsList.setLayoutData(keyWordsTextData);
648
		keyWordsList.setLayoutData(keyWordsTextData);
646
649
647
		// initialize the keywords list with valid values
650
		// initialize the keywords list with valid values
648
		java.util.List<String> keywordList = bug.getKeywords();
651
		
649
		if (keywordList != null) {
652
		
650
			for (Iterator<String> it = keywordList.iterator(); it.hasNext();) {
653
		
654
		java.util.List<String> validKeywords = BugzillaPlugin.getDefault().getProductConfiguration(repository).getKeywords();
655
		
656
		if (validKeywords != null) {
657
			for (Iterator<String> it = validKeywords.iterator(); it.hasNext();) {
651
				String keyword = it.next();
658
				String keyword = it.next();
652
				keyWordsList.add(keyword);
659
				keyWordsList.add(keyword);
653
			}
660
			}
Lines 674-680 Link Here
674
		keyWordsList.addSelectionListener(new KeywordListener());
681
		keyWordsList.addSelectionListener(new KeywordListener());
675
		keyWordsList.addListener(SWT.FocusIn, new GenericListener());
682
		keyWordsList.addListener(SWT.FocusIn, new GenericListener());
676
	}
683
	}
677
684
	
678
	@Override
685
	@Override
679
	protected void addCCList(FormToolkit toolkit, String ccValue, Composite attributesComposite) {
686
	protected void addCCList(FormToolkit toolkit, String ccValue, Composite attributesComposite) {
680
		newLayout(attributesComposite, 1, "Add CC:", PROPERTY);
687
		newLayout(attributesComposite, 1, "Add CC:", PROPERTY);
Lines 693-701 Link Here
693
700
694
			public void modifyText(ModifyEvent e) {
701
			public void modifyText(ModifyEvent e) {
695
				changeDirtyStatus(true);
702
				changeDirtyStatus(true);
696
				Attribute a = bug.getAttributeForKnobName("newcc");
703
				AbstractRepositoryReportAttribute a = bug.getAttribute(BugzillaReportElement.NEWCC);
697
				if (a != null) {
704
				if (a != null) {
698
					a.setNewValue(ccText.getText());
705
					a.setValue(ccText.getText());
699
				}
706
				}
700
			}
707
			}
701
708
Lines 713-724 Link Here
713
		ccListData.heightHint = 40;
720
		ccListData.heightHint = 40;
714
		ccList.setLayoutData(ccListData);
721
		ccList.setLayoutData(ccListData);
715
722
716
		// initialize the keywords list with valid values
723
		java.util.List<String> ccs = bug.getCC();
717
		Set<String> ccs = bug.getCC();
718
		if (ccs != null) {
724
		if (ccs != null) {
719
			for (Iterator<String> it = ccs.iterator(); it.hasNext();) {
725
			for (Iterator<String> it = ccs.iterator(); it.hasNext();) {
720
				String cc = it.next();
726
				String cc = it.next();
721
				ccList.add(HtmlStreamTokenizer.unescape(cc));
727
				ccList.add(cc);//HtmlStreamTokenizer.unescape(cc));
722
			}
728
			}
723
		}
729
		}
724
730
Lines 745-767 Link Here
745
751
746
	@Override
752
	@Override
747
	protected void updateBug() {
753
	protected void updateBug() {
748
754
		bug.setHasChanged(true);
749
		// go through all of the attributes and update the main values to the
755
		// go through all of the attributes and update the main values to the
750
		// new ones
756
		// new ones
751
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
757
		// for (Iterator<AbstractRepositoryReportAttribute> it =
752
			Attribute a = it.next();
758
		// bug.getAttributes().iterator(); it.hasNext();) {
753
			if (a.getNewValue() != null && a.getNewValue().compareTo(a.getValue()) != 0) {
759
		// AbstractRepositoryReportAttribute a = it.next();
754
				bug.setHasChanged(true);
760
		// if (a.getNewValue() != null &&
755
			}
761
		// a.getNewValue().compareTo(a.getValue()) != 0) {
756
			a.setValue(a.getNewValue());
762
		// bug.setHasChanged(true);
757
763
		// }
758
		}
764
		// a.setValue(a.getNewValue());
759
		if (bug.getNewComment().compareTo(bug.getNewNewComment()) != 0) {
765
		//
760
			bug.setHasChanged(true);
766
		// }
761
		}
767
		// if (bug.getNewComment().compareTo(bug.getNewNewComment()) != 0) {
768
		// // TODO: Ask offline reports if this is true?
769
		// bug.setHasChanged(true);
770
		//		}
762
771
763
		// Update some other fields as well.
772
		// Update some other fields as well.
764
		bug.setNewComment(bug.getNewNewComment());
773
		// bug.setNewComment(bug.getNewNewComment());
765
774
766
	}
775
	}
767
776
Lines 773-785 Link Here
773
782
774
		// go through all of the attributes and restore the new values to the
783
		// go through all of the attributes and restore the new values to the
775
		// main ones
784
		// main ones
776
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
785
		// for (Iterator<AbstractRepositoryReportAttribute> it =
777
			Attribute a = it.next();
786
		// bug.getAttributes().iterator(); it.hasNext();) {
778
			a.setNewValue(a.getValue());
787
		// AbstractRepositoryReportAttribute a = it.next();
779
		}
788
		// a.setNewValue(a.getValue());
789
		// }
780
790
781
		// Restore some other fields as well.
791
		// Restore some other fields as well.
782
		bug.setNewNewComment(bug.getNewComment());
792
		// bug.setNewNewComment(bug.getNewComment());
783
	}
793
	}
784
794
785
	/**
795
	/**
Lines 794-800 Link Here
794
804
795
		@Override
805
		@Override
796
		protected IStatus run(IProgressMonitor monitor) {
806
		protected IStatus run(IProgressMonitor monitor) {
797
			final BugReport serverBug;
807
			final BugzillaReport serverBug;
798
			try {
808
			try {
799
				serverBug = BugzillaRepositoryUtil.getBug(bug.getRepositoryUrl(), bug.getId());
809
				serverBug = BugzillaRepositoryUtil.getBug(bug.getRepositoryUrl(), bug.getId());
800
				// If no bug was found on the server, throw an exception so that
810
				// If no bug was found on the server, throw an exception so that
Lines 845-851 Link Here
845
			if (keyWordsList.getSelectionCount() == 1) {
855
			if (keyWordsList.getSelectionCount() == 1) {
846
				int index = keyWordsList.getSelectionIndex();
856
				int index = keyWordsList.getSelectionIndex();
847
				String keyword = keyWordsList.getItem(index);
857
				String keyword = keyWordsList.getItem(index);
848
				if (bug.getAttribute("Keywords").getNewValue().equals(keyword))
858
				if (getReport().getAttributeValue(BugzillaReportElement.KEYWORDS).equals(keyword))
849
					keyWordsList.deselectAll();
859
					keyWordsList.deselectAll();
850
			}
860
			}
851
861
Lines 855-861 Link Here
855
					keywords.append(",");
865
					keywords.append(",");
856
				}
866
				}
857
			}
867
			}
858
			bug.getAttribute("Keywords").setNewValue(keywords.toString());
868
			
869
			bug.setAttributeValue(BugzillaReportElement.KEYWORDS, keywords.toString());
859
870
860
			// update the keywords text field
871
			// update the keywords text field
861
			keywordsText.setText(keywords.toString());
872
			keywordsText.setText(keywords.toString());
Lines 1003-1008 Link Here
1003
		Operation o = bug.getSelectedOperation();
1014
		Operation o = bug.getSelectedOperation();
1004
		if (o != null && o.getKnobName().compareTo("resolve") == 0
1015
		if (o != null && o.getKnobName().compareTo("resolve") == 0
1005
				&& (addCommentsText.getText() == null || addCommentsText.getText().equals(""))) {
1016
				&& (addCommentsText.getText() == null || addCommentsText.getText().equals(""))) {
1017
			// TODO: Highlight (change to light red?) New Comment area to indicate need for message
1006
			submitButton.setEnabled(false);
1018
			submitButton.setEnabled(false);
1007
		} else {
1019
		} else {
1008
			submitButton.setEnabled(true);
1020
			submitButton.setEnabled(true);
Lines 1012-1020 Link Here
1012
	@Override
1024
	@Override
1013
	public void handleSummaryEvent() {
1025
	public void handleSummaryEvent() {
1014
		String sel = summaryText.getText();
1026
		String sel = summaryText.getText();
1015
		Attribute a = getBug().getAttribute(ATTR_SUMMARY);
1027
		AbstractRepositoryReportAttribute a = getReport().getAttribute(BugzillaReportElement.SHORT_DESC);
1016
		if (!(a.getNewValue().equals(sel))) {
1028
		if (!(a.getValue().equals(sel))) {
1017
			a.setNewValue(sel);
1029
			a.setValue(sel);
1018
			changeDirtyStatus(true);
1030
			changeDirtyStatus(true);
1019
		}
1031
		}
1020
	}
1032
	}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/NewBugEditor.java (-14 / +11 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.ui.editor;
11
package org.eclipse.mylar.internal.bugzilla.ui.editor;
12
12
13
import java.util.Iterator;
14
15
import org.eclipse.core.runtime.Status;
13
import org.eclipse.core.runtime.Status;
16
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
14
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
17
import org.eclipse.core.runtime.jobs.IJobChangeListener;
15
import org.eclipse.core.runtime.jobs.IJobChangeListener;
18
import org.eclipse.jface.viewers.SelectionChangedEvent;
16
import org.eclipse.jface.viewers.SelectionChangedEvent;
19
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.mylar.bugzilla.core.Attribute;
21
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
18
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
22
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
19
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
20
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
21
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
25
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
22
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
26
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
23
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
27
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
24
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
Lines 48-54 Link Here
48
 */
45
 */
49
public class NewBugEditor extends AbstractBugEditor {
46
public class NewBugEditor extends AbstractBugEditor {
50
47
51
	protected NewBugModel bug;
48
	protected NewBugzillaReport bug;
52
49
53
	protected Text descriptionText;
50
	protected Text descriptionText;
54
51
Lines 270-279 Link Here
270
	protected void updateBug() {
267
	protected void updateBug() {
271
		// go through all of the attributes and update the main values to the
268
		// go through all of the attributes and update the main values to the
272
		// new ones
269
		// new ones
273
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
270
//		for (Iterator<AbstractRepositoryReportAttribute> it = bug.getAttributes().iterator(); it.hasNext();) {
274
			Attribute a = it.next();
271
//			AbstractRepositoryReportAttribute a = it.next();
275
			a.setValue(a.getNewValue());
272
//			a.setValue(a.getNewValue());
276
		}
273
//		}
277
274
278
		// Update some other fields as well.
275
		// Update some other fields as well.
279
		bug.setSummary(newSummary);
276
		bug.setSummary(newSummary);
Lines 284-293 Link Here
284
	protected void restoreBug() {
281
	protected void restoreBug() {
285
		// go through all of the attributes and restore the new values to the
282
		// go through all of the attributes and restore the new values to the
286
		// main ones
283
		// main ones
287
		for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();) {
284
//		for (Iterator<AbstractRepositoryReportAttribute> it = bug.getAttributes().iterator(); it.hasNext();) {
288
			Attribute a = it.next();
285
//			AbstractRepositoryReportAttribute a = it.next();
289
			a.setNewValue(a.getValue());
286
//			a.setNewValue(a.getValue());
290
		}
287
//		}
291
	}
288
	}
292
289
293
	@SuppressWarnings("deprecation")
290
	@SuppressWarnings("deprecation")
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/AbstractBugEditor.java (-264 / +458 lines)
Lines 14-20 Link Here
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Arrays;
15
import java.util.Arrays;
16
import java.util.HashMap;
16
import java.util.HashMap;
17
import java.util.Iterator;
18
import java.util.List;
17
import java.util.List;
19
import java.util.Map;
18
import java.util.Map;
20
import java.util.Set;
19
import java.util.Set;
Lines 35-41 Link Here
35
import org.eclipse.jface.viewers.ISelectionProvider;
34
import org.eclipse.jface.viewers.ISelectionProvider;
36
import org.eclipse.jface.viewers.SelectionChangedEvent;
35
import org.eclipse.jface.viewers.SelectionChangedEvent;
37
import org.eclipse.jface.viewers.StructuredSelection;
36
import org.eclipse.jface.viewers.StructuredSelection;
38
import org.eclipse.mylar.bugzilla.core.Attribute;
37
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReport;
38
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
39
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
39
import org.eclipse.mylar.bugzilla.core.Comment;
40
import org.eclipse.mylar.bugzilla.core.Comment;
40
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
41
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
41
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
42
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
Lines 43-48 Link Here
43
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaAttributeListener;
44
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaAttributeListener;
44
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
45
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
45
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaReportSelection;
46
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaReportSelection;
47
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
46
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
48
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
47
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
49
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
48
import org.eclipse.mylar.internal.tasklist.ui.editors.MylarTaskEditor;
50
import org.eclipse.mylar.internal.tasklist.ui.editors.MylarTaskEditor;
Lines 170-176 Link Here
170
172
171
	protected final int HORZ_INDENT = 0;
173
	protected final int HORZ_INDENT = 0;
172
174
173
	protected CCombo oSCombo;
175
	protected CCombo attributeCombo;
174
176
175
	protected CCombo versionCombo;
177
	protected CCombo versionCombo;
176
178
Lines 257-263 Link Here
257
259
258
	protected List<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>();
260
	protected List<ISelectionChangedListener> selectionChangedListeners = new ArrayList<ISelectionChangedListener>();
259
261
260
	protected HashMap<CCombo, String> comboListenerMap = new HashMap<CCombo, String>();
262
	protected HashMap<CCombo, AbstractRepositoryReportAttribute> comboListenerMap = new HashMap<CCombo, AbstractRepositoryReportAttribute>();
261
263
262
	private IBugzillaReportSelection lastSelected = null;
264
	private IBugzillaReportSelection lastSelected = null;
263
265
Lines 309-317 Link Here
309
			if (comboListenerMap.containsKey(combo)) {
311
			if (comboListenerMap.containsKey(combo)) {
310
				if (combo.getSelectionIndex() > -1) {
312
				if (combo.getSelectionIndex() > -1) {
311
					String sel = combo.getItem(combo.getSelectionIndex());
313
					String sel = combo.getItem(combo.getSelectionIndex());
312
					Attribute attribute = getBug().getAttribute(comboListenerMap.get(combo));
314
					AbstractRepositoryReportAttribute attribute = comboListenerMap.get(combo);
313
					if (sel != null && !(sel.equals(attribute.getNewValue()))) {
315
					if (sel != null && !(sel.equals(attribute.getValue()))) {
314
						attribute.setNewValue(sel);
316
						attribute.setValue(sel);
315
						for (IBugzillaAttributeListener client : attributesListeners) {
317
						for (IBugzillaAttributeListener client : attributesListeners) {
316
							client.attributeChanged(attribute.getName(), sel);
318
							client.attributeChanged(attribute.getName(), sel);
317
						}
319
						}
Lines 382-387 Link Here
382
	 */
384
	 */
383
	public abstract IBugzillaBug getBug();
385
	public abstract IBugzillaBug getBug();
384
386
387
	// TODO: temporary as part of conversion to xml
388
	public AbstractRepositoryReport getReport() {
389
		return (AbstractRepositoryReport) getBug();
390
	}
391
385
	/**
392
	/**
386
	 * @return Any currently selected text.
393
	 * @return Any currently selected text.
387
	 */
394
	 */
Lines 429-435 Link Here
429
		Composite headerInfoComposite = toolkit.createComposite(editorComposite);
436
		Composite headerInfoComposite = toolkit.createComposite(editorComposite);
430
		headerInfoComposite.setLayout(new GridLayout(6, false));
437
		headerInfoComposite.setLayout(new GridLayout(6, false));
431
		toolkit.createLabel(headerInfoComposite, "Bug# ").setFont(TITLE_FONT);
438
		toolkit.createLabel(headerInfoComposite, "Bug# ").setFont(TITLE_FONT);
432
		toolkit.createText(headerInfoComposite, "" + getBug().getId());
439
		toolkit.createText(headerInfoComposite, "" + getReport().getId());
433
440
434
		toolkit.createLabel(headerInfoComposite, " Opened: ").setFont(TITLE_FONT);
441
		toolkit.createLabel(headerInfoComposite, " Opened: ").setFont(TITLE_FONT);
435
		String openedDateString = "";
442
		String openedDateString = "";
Lines 490-495 Link Here
490
		getSite().registerContextMenu("#BugEditor", contextMenuManager, getSite().getSelectionProvider());
497
		getSite().registerContextMenu("#BugEditor", contextMenuManager, getSite().getSelectionProvider());
491
	}
498
	}
492
499
500
	// /**
501
	// * Creates the attribute layout, which contains most of the basic
502
	// attributes
503
	// * of the bug (some of which are editable).
504
	// */
505
	// protected void createAttributeLayout() {
506
	//
507
	// String title = getTitleString();
508
	// String keywords = "";
509
	// String url = "";
510
	//
511
	// Section section = toolkit.createSection(form.getBody(),
512
	// ExpandableComposite.TITLE_BAR | Section.TWISTIE);
513
	// section.setText(LABEL_SECTION_ATTRIBUTES);
514
	// section.setExpanded(true);
515
	// section.setLayout(new GridLayout());
516
	// section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
517
	//
518
	// section.addExpansionListener(new IExpansionListener() {
519
	// public void expansionStateChanging(ExpansionEvent e) {
520
	// form.reflow(true);
521
	// }
522
	//
523
	// public void expansionStateChanged(ExpansionEvent e) {
524
	// form.reflow(true);
525
	// }
526
	// });
527
	//
528
	// // Attributes Composite- this holds all the combo fiels and text fields
529
	// Composite attributesComposite = toolkit.createComposite(section);
530
	// GridLayout attributesLayout = new GridLayout();
531
	// attributesLayout.numColumns = 4;
532
	// attributesLayout.horizontalSpacing = 14;
533
	// attributesLayout.verticalSpacing = 6;
534
	// attributesComposite.setLayout(attributesLayout);
535
	// GridData attributesData = new GridData(GridData.FILL_BOTH);
536
	// attributesData.horizontalSpan = 1;
537
	// attributesData.grabExcessVerticalSpace = false;
538
	// attributesComposite.setLayoutData(attributesData);
539
	// // attributesComposite.setBackground(background);
540
	// // End Attributes Composite
541
	//
542
	// section.setClient(attributesComposite);
543
	//
544
	// // Attributes Title Area
545
	// // Composite attributesTitleComposite = new
546
	// // Composite(attributesComposite, SWT.NONE);
547
	// // GridLayout attributesTitleLayout = new GridLayout();
548
	// // attributesTitleLayout.horizontalSpacing = 0;
549
	// // attributesTitleLayout.marginWidth = 0;
550
	// // attributesTitleComposite.setLayout(attributesTitleLayout);
551
	// // attributesTitleComposite.setBackground(background);
552
	// // GridData attributesTitleData = new
553
	// // GridData(GridData.HORIZONTAL_ALIGN_FILL);
554
	// // attributesTitleData.horizontalSpan = 4;
555
	// // attributesTitleData.grabExcessVerticalSpace = false;
556
	// // attributesTitleComposite.setLayoutData(attributesTitleData);
557
	// // End Attributes Title
558
	//
559
	// // Set the Attributes Title
560
	// // newAttributesLayout(attributesTitleComposite);
561
	// // titleLabel.setText(title);
562
	// bugzillaInput.setToolTipText(title);
563
	// int currentCol = 1;
564
	//
565
	// // String ccValue = null;
566
	//
567
	// // Populate Attributes
568
	// for (Iterator<AbstractRepositoryReportAttribute> it =
569
	// getReport().getAttributes().iterator(); it.hasNext();) {
570
	// AbstractRepositoryReportAttribute attribute = it.next();
571
	// String key = attribute.getID();
572
	// String name = attribute.getName();
573
	// String value = checkText(attribute.getValue());
574
	// System.err.println(">>> AbstractBugEditor>> name: "+name+" key: "+key+"
575
	// value:"+value);
576
	// Map<String, String> values = attribute.getOptionValues();
577
	//
578
	// // make sure we don't try to display a hidden field
579
	// if (attribute.isHidden() || (key != null &&
580
	// key.equals("status_whiteboard")))
581
	// continue;
582
	//
583
	// if (values == null)
584
	// values = new HashMap<String, String>();
585
	//
586
	// if (key == null)
587
	// key = "";
588
	//
589
	// GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
590
	// data.horizontalSpan = 1;
591
	// data.horizontalIndent = HORZ_INDENT;
592
	//
593
	// if (key.equals(BugzillaReportElement.KEYWORDS.getKeyString())) {
594
	// keywords = attribute.getValue();
595
	// } else if (key.equals(BugzillaReportElement.CC.getKeyString())) {
596
	// continue;
597
	// } else if (key.equals(BugzillaReportElement.NEWCC.getKeyString())) {
598
	// // force move to first column
599
	// if (currentCol > 1) {
600
	// while (currentCol <= attributesLayout.numColumns) {
601
	// newLayout(attributesComposite, 1, "", PROPERTY);
602
	// currentCol++;
603
	// }
604
	// }
605
	// addCCList(toolkit, "", attributesComposite);
606
	// } else if (key.equals(BugzillaReportElement.DEPENDSON.getKeyString())) {
607
	// // Dependson and blocked are multi valued so need to explicitly
608
	// // be parsed and shown in the AbstractBugEditor
609
	// continue;
610
	// } else if (key.equals(BugzillaReportElement.BLOCKED.getKeyString())) {
611
	// // Dependson and blocked are multi valued so need to explicitly
612
	// // be parsed and shown in the AbstractBugEditor
613
	// continue;
614
	// } else if (key.equals("bug_file_loc")) {
615
	// url = value;
616
	// } else if (key.equals("op_sys")) {
617
	// // newLayout(attributesComposite, 1, name, PROPERTY);
618
	// toolkit.createLabel(attributesComposite, name);
619
	// // oSCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND |
620
	// // SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);//SWT.NONE
621
	// oSCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY);
622
	// // oSCombo = new Combo(attributesComposite, SWT.FLAT |
623
	// // SWT.READ_ONLY);
624
	// toolkit.adapt(oSCombo, true, true);
625
	// oSCombo.setFont(TEXT_FONT);
626
	// oSCombo.setLayoutData(data);
627
	// // oSCombo.setBackground(background);
628
	// Set<String> s = values.keySet();
629
	// String[] a = s.toArray(new String[s.size()]);
630
	// Arrays.sort(a);
631
	// for (int i = 0; i < a.length; i++) {
632
	// oSCombo.add(a[i]);
633
	// }
634
	// if (oSCombo.indexOf(value) != -1) {
635
	// oSCombo.select(oSCombo.indexOf(value));
636
	// } else {
637
	// oSCombo.select(oSCombo.indexOf("All"));
638
	// }
639
	// // oSCombo.addListener(SWT.Modify, this);
640
	// oSCombo.addSelectionListener(new ComboSelectionListener(oSCombo));
641
	// comboListenerMap.put(oSCombo, attribute);
642
	// oSCombo.addListener(SWT.FocusIn, new GenericListener());
643
	// currentCol += 2;
644
	// } else if (key.equals("version")) {
645
	// // newLayout(attributesComposite, 1, name, PROPERTY);
646
	// toolkit.createLabel(attributesComposite, name);
647
	// versionCombo = new CCombo(attributesComposite, SWT.FLAT |
648
	// SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
649
	// | SWT.READ_ONLY);
650
	// toolkit.adapt(versionCombo, true, true);
651
	// versionCombo.setFont(TEXT_FONT);
652
	// versionCombo.setLayoutData(data);
653
	// // versionCombo.setBackground(background);
654
	// Set<String> s = values.keySet();
655
	// String[] a = s.toArray(new String[s.size()]);
656
	// Arrays.sort(a);
657
	// for (int i = 0; i < a.length; i++) {
658
	// versionCombo.add(a[i]);
659
	// }
660
	// versionCombo.select(versionCombo.indexOf(value));
661
	// // versionCombo.addListener(SWT.Modify, this);
662
	// versionCombo.addSelectionListener(new
663
	// ComboSelectionListener(versionCombo));
664
	// versionCombo.addListener(SWT.FocusIn, new GenericListener());
665
	// comboListenerMap.put(versionCombo, attribute);
666
	// currentCol += 2;
667
	// } else if (key.equals("priority")) {
668
	// // newLayout(attributesComposite, 1, "Priority", PROPERTY);
669
	// toolkit.createLabel(attributesComposite, name);
670
	// priorityCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.V_SCROLL |
671
	// SWT.READ_ONLY);
672
	// toolkit.adapt(priorityCombo, true, true);
673
	// priorityCombo.setFont(TEXT_FONT);
674
	// priorityCombo.setLayoutData(data);
675
	// // priorityCombo.setBackground(background);
676
	// Set<String> s = values.keySet();
677
	// String[] a = s.toArray(new String[s.size()]);
678
	// Arrays.sort(a);
679
	// for (int i = 0; i < a.length; i++) {
680
	// priorityCombo.add(a[i]);
681
	// }
682
	// priorityCombo.select(priorityCombo.indexOf(value));
683
	// // priorityCombo.addListener(SWT.Modify, this);
684
	// priorityCombo.addSelectionListener(new
685
	// ComboSelectionListener(priorityCombo));
686
	// priorityCombo.addListener(SWT.FocusIn, new GenericListener());
687
	// comboListenerMap.put(priorityCombo, attribute);
688
	// currentCol += 2;
689
	// } else if (key.equals("bug_severity")) {
690
	// // newLayout(attributesComposite, 1, name, PROPERTY);
691
	// toolkit.createLabel(attributesComposite, name);
692
	// severityCombo = new CCombo(attributesComposite, SWT.FLAT |
693
	// SWT.READ_ONLY);
694
	// toolkit.adapt(severityCombo, true, true);
695
	// severityCombo.setFont(TEXT_FONT);
696
	// severityCombo.setLayoutData(data);
697
	// // severityCombo.setBackground(background);
698
	// Set<String> s = values.keySet();
699
	// String[] a = s.toArray(new String[s.size()]);
700
	// Arrays.sort(a);
701
	// for (int i = 0; i < a.length; i++) {
702
	// severityCombo.add(a[i]);
703
	// }
704
	// severityCombo.select(severityCombo.indexOf(value));
705
	// severityCombo.addSelectionListener(new
706
	// ComboSelectionListener(severityCombo));
707
	// // severityCombo.addListener(SWT.Modify, this);
708
	// severityCombo.addListener(SWT.FocusIn, new GenericListener());
709
	// comboListenerMap.put(severityCombo, attribute);
710
	// currentCol += 2;
711
	// } else if (key.equals("target_milestone")) {
712
	// // newLayout(attributesComposite, 1, name, PROPERTY);
713
	// toolkit.createLabel(attributesComposite, name);
714
	// milestoneCombo = new CCombo(attributesComposite, SWT.FLAT |
715
	// SWT.NO_BACKGROUND | SWT.MULTI
716
	// | SWT.V_SCROLL | SWT.READ_ONLY);
717
	// toolkit.adapt(milestoneCombo, true, true);
718
	// milestoneCombo.setFont(TEXT_FONT);
719
	// milestoneCombo.setLayoutData(data);
720
	// // milestoneCombo.setBackground(background);
721
	// Set<String> s = values.keySet();
722
	// String[] a = s.toArray(new String[s.size()]);
723
	// Arrays.sort(a);
724
	// for (int i = 0; i < a.length; i++) {
725
	// milestoneCombo.add(a[i]);
726
	// }
727
	// milestoneCombo.select(milestoneCombo.indexOf(value));
728
	// // milestoneCombo.addListener(SWT.Modify, this);
729
	// milestoneCombo.addSelectionListener(new
730
	// ComboSelectionListener(milestoneCombo));
731
	// milestoneCombo.addListener(SWT.FocusIn, new GenericListener());
732
	// comboListenerMap.put(milestoneCombo, attribute);
733
	// currentCol += 2;
734
	// } else if (key.equals("rep_platform")) {
735
	// // newLayout(attributesComposite, 1, name, PROPERTY);
736
	// toolkit.createLabel(attributesComposite, name);
737
	// platformCombo = new CCombo(attributesComposite, SWT.FLAT |
738
	// SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
739
	// | SWT.READ_ONLY);
740
	// toolkit.adapt(platformCombo, true, true);
741
	// platformCombo.setFont(TEXT_FONT);
742
	// platformCombo.setLayoutData(data);
743
	// // platformCombo.setBackground(background);
744
	// Set<String> s = values.keySet();
745
	// String[] a = s.toArray(new String[s.size()]);
746
	// Arrays.sort(a);
747
	// for (int i = 0; i < a.length; i++) {
748
	// platformCombo.add(a[i]);
749
	// }
750
	// platformCombo.select(platformCombo.indexOf(value));
751
	// // platformCombo.addListener(SWT.Modify, this);
752
	// platformCombo.addSelectionListener(new
753
	// ComboSelectionListener(platformCombo));
754
	// platformCombo.addListener(SWT.FocusIn, new GenericListener());
755
	// comboListenerMap.put(platformCombo, attribute);
756
	// currentCol += 2;
757
	// } else if (key.equals("product")) {
758
	// // newLayout(attributesComposite, 1, name, PROPERTY);
759
	// toolkit.createLabel(attributesComposite, name);
760
	// // toolkit.createLabel(attributesComposite, value);
761
	// Composite uneditableComp = toolkit.createComposite(attributesComposite);
762
	// GridLayout textLayout = new GridLayout();
763
	// textLayout.marginWidth = 1;
764
	// uneditableComp.setLayout(textLayout);
765
	// toolkit.createText(uneditableComp, value, SWT.READ_ONLY);//
766
	// Label(attributesComposite,
767
	// // value);
768
	// // newLayout(attributesComposite, 1, value,
769
	// // VALUE).addListener(SWT.FocusIn, new GenericListener());
770
	// currentCol += 2;
771
	// } else if (key.equals("assigned_to")) {
772
	// // newLayout(attributesComposite, 1, name, PROPERTY);
773
	// toolkit.createLabel(attributesComposite, name);
774
	// assignedTo = new Text(attributesComposite, SWT.SINGLE | SWT.WRAP);
775
	// assignedTo.setFont(TEXT_FONT);
776
	// assignedTo.setText(value);
777
	// data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
778
	// data.horizontalSpan = 1;
779
	// assignedTo.setLayoutData(data);
780
	//
781
	// assignedTo.addListener(SWT.KeyUp, new Listener() {
782
	// public void handleEvent(Event event) {
783
	// String sel = assignedTo.getText();
784
	// AbstractRepositoryReportAttribute a = getReport().getAttribute(
785
	// BugzillaReportElement.ASSIGNED_TO);
786
	// if (!(a.getValue().equals(sel))) {
787
	// a.setValue(sel);
788
	// changeDirtyStatus(true);
789
	// }
790
	// }
791
	// });
792
	// assignedTo.addListener(SWT.FocusIn, new GenericListener());
793
	//
794
	// currentCol += 2;
795
	// } else if (key.equals("component")) {
796
	// // newLayout(attributesComposite, 1, name, PROPERTY);
797
	// toolkit.createLabel(attributesComposite, name);
798
	// componentCombo = new CCombo(attributesComposite, SWT.FLAT |
799
	// SWT.NO_BACKGROUND | SWT.MULTI
800
	// | SWT.V_SCROLL | SWT.READ_ONLY);
801
	// toolkit.adapt(componentCombo, true, true);
802
	// componentCombo.setFont(TEXT_FONT);
803
	// componentCombo.setLayoutData(data);
804
	// // componentCombo.setBackground(background);
805
	// Set<String> s = values.keySet();
806
	// String[] a = s.toArray(new String[s.size()]);
807
	// Arrays.sort(a);
808
	// for (int i = 0; i < a.length; i++) {
809
	// componentCombo.add(a[i]);
810
	// }
811
	// componentCombo.select(componentCombo.indexOf(value));
812
	// // componentCombo.addListener(SWT.Modify, this);
813
	// componentCombo.addSelectionListener(new
814
	// ComboSelectionListener(componentCombo));
815
	// componentCombo.addListener(SWT.FocusIn, new GenericListener());
816
	// comboListenerMap.put(componentCombo, attribute);
817
	// currentCol += 2;
818
	// } else if (name.equals("Summary")) {
819
	// // Don't show the summary here.
820
	// continue;
821
	// } else if (name.equals("Last Modified")) {
822
	// // Don't show last modified here.
823
	// continue;
824
	// } else if (name.equals("Bug#")) {
825
	// // Don't show bug number here
826
	// continue;
827
	// } else if (key.equals("bug_status")) {
828
	// // newLayout(attributesComposite, 1, name, PROPERTY);
829
	// toolkit.createLabel(attributesComposite, name);
830
	// Composite uneditableComp = toolkit.createComposite(attributesComposite);
831
	// GridLayout textLayout = new GridLayout();
832
	// textLayout.marginWidth = 1;
833
	// uneditableComp.setLayout(textLayout);
834
	// toolkit.createText(uneditableComp, value, SWT.READ_ONLY);//
835
	// Label(attributesComposite,
836
	// // value);
837
	// // newLayout(attributesComposite, 1, value,
838
	// // VALUE).addListener(SWT.FocusIn, new GenericListener());
839
	// currentCol += 2;
840
	// } else if (values.isEmpty()) {
841
	// // newLayout(attributesComposite, 1, name, PROPERTY);
842
	// toolkit.createLabel(attributesComposite, name);
843
	// Composite uneditableComp = toolkit.createComposite(attributesComposite);
844
	// GridLayout textLayout = new GridLayout();
845
	// textLayout.marginWidth = 1;
846
	// uneditableComp.setLayout(textLayout);
847
	// toolkit.createText(uneditableComp, value, SWT.READ_ONLY);//
848
	// Label(attributesComposite,
849
	// // value);
850
	// // newLayout(attributesComposite, 1, value,
851
	// // VALUE).addListener(SWT.FocusIn, new GenericListener());
852
	// currentCol += 2;
853
	// }
854
	// if (currentCol > attributesLayout.numColumns) {
855
	// currentCol -= attributesLayout.numColumns;
856
	// }
857
	// }
858
	// // End Populate Attributes
859
	//
860
	// // make sure that we are in the first column
861
	// if (currentCol > 1) {
862
	// while (currentCol <= attributesLayout.numColumns) {
863
	// newLayout(attributesComposite, 1, "", PROPERTY);
864
	// currentCol++;
865
	// }
866
	// }
867
	//
868
	// // URL field
869
	// addUrlText(url, attributesComposite);
870
	//
871
	// // keywords text field (not editable)
872
	// addKeywordsList(toolkit, keywords, attributesComposite);
873
	// // if (ccValue != null) {
874
	// // addCCList(toolkit, ccValue, attributesComposite);
875
	// // }
876
	// addSummaryText(attributesComposite);
877
	// // End URL, Keywords, Summary Text Fields
878
	// toolkit.paintBordersFor(attributesComposite);
879
	// }
880
493
	/**
881
	/**
494
	 * Creates the attribute layout, which contains most of the basic attributes
882
	 * Creates the attribute layout, which contains most of the basic attributes
495
	 * of the bug (some of which are editable).
883
	 * of the bug (some of which are editable).
Lines 497-505 Link Here
497
	protected void createAttributeLayout() {
885
	protected void createAttributeLayout() {
498
886
499
		String title = getTitleString();
887
		String title = getTitleString();
500
		String keywords = "";
501
		String url = "";
502
503
		Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | Section.TWISTIE);
888
		Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | Section.TWISTIE);
504
		section.setText(LABEL_SECTION_ATTRIBUTES);
889
		section.setText(LABEL_SECTION_ATTRIBUTES);
505
		section.setExpanded(true);
890
		section.setExpanded(true);
Lines 516-522 Link Here
516
			}
901
			}
517
		});
902
		});
518
903
519
		// Attributes Composite- this holds all the combo fiels and text fields
904
		// Attributes Composite- this holds all the combo fields and text fields
520
		Composite attributesComposite = toolkit.createComposite(section);
905
		Composite attributesComposite = toolkit.createComposite(section);
521
		GridLayout attributesLayout = new GridLayout();
906
		GridLayout attributesLayout = new GridLayout();
522
		attributesLayout.numColumns = 4;
907
		attributesLayout.numColumns = 4;
Lines 527-822 Link Here
527
		attributesData.horizontalSpan = 1;
912
		attributesData.horizontalSpan = 1;
528
		attributesData.grabExcessVerticalSpace = false;
913
		attributesData.grabExcessVerticalSpace = false;
529
		attributesComposite.setLayoutData(attributesData);
914
		attributesComposite.setLayoutData(attributesData);
530
		// attributesComposite.setBackground(background);
531
		// End Attributes Composite
532
533
		section.setClient(attributesComposite);
915
		section.setClient(attributesComposite);
534
535
		// Attributes Title Area
536
		// Composite attributesTitleComposite = new
537
		// Composite(attributesComposite, SWT.NONE);
538
		// GridLayout attributesTitleLayout = new GridLayout();
539
		// attributesTitleLayout.horizontalSpacing = 0;
540
		// attributesTitleLayout.marginWidth = 0;
541
		// attributesTitleComposite.setLayout(attributesTitleLayout);
542
		// attributesTitleComposite.setBackground(background);
543
		// GridData attributesTitleData = new
544
		// GridData(GridData.HORIZONTAL_ALIGN_FILL);
545
		// attributesTitleData.horizontalSpan = 4;
546
		// attributesTitleData.grabExcessVerticalSpace = false;
547
		// attributesTitleComposite.setLayoutData(attributesTitleData);
548
		// End Attributes Title
549
550
		// Set the Attributes Title
551
		// newAttributesLayout(attributesTitleComposite);
552
		// titleLabel.setText(title);
553
		bugzillaInput.setToolTipText(title);
916
		bugzillaInput.setToolTipText(title);
917
554
		int currentCol = 1;
918
		int currentCol = 1;
555
919
556
		String ccValue = null;
920
		for (AbstractRepositoryReportAttribute attribute : getReport().getAttributes()) {
557
921
558
		// Populate Attributes
922
			// String key = attribute.getID();
559
		for (Iterator<Attribute> it = getBug().getAttributes().iterator(); it.hasNext();) {
560
			Attribute attribute = it.next();
561
			String key = attribute.getParameterName();
562
			String name = attribute.getName();
923
			String name = attribute.getName();
563
			String value = checkText(attribute.getValue());
924
			String value = checkText(attribute.getValue());
564
			Map<String, String> values = attribute.getOptionValues();
925
			// System.err.println(">>> AbstractBugEditor>> name: "+name+"
565
926
			// key:"+key+" value:"+value+" is hidden"+attribute.isHidden());
566
			// make sure we don't try to display a hidden field
927
			if (attribute.isHidden())
567
			if (attribute.isHidden() || (key != null && key.equals("status_whiteboard")))
568
				continue;
928
				continue;
569
929
			Map<String, String> values = attribute.getOptionValues();
570
			if (values == null)
930
			if (values == null)
571
				values = new HashMap<String, String>();
931
				values = new HashMap<String, String>();
572
932
573
			if (key == null)
574
				key = "";
575
576
			GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
933
			GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
577
			data.horizontalSpan = 1;
934
			data.horizontalSpan = 1;
578
			data.horizontalIndent = HORZ_INDENT;
935
			data.horizontalIndent = HORZ_INDENT;
579
936
580
			if (key.equals("short_desc") || key.equals("keywords")) {
937
			if (attribute.hasOptions() && !attribute.isReadOnly()) {
581
				keywords = value;
582
			} else if (key.equals("newcc")) {
583
				ccValue = value;
584
				if (value == null)
585
					ccValue = "";
586
			} else if (key.equals("bug_file_loc")) {
587
				url = value;
588
			} else if (key.equals("op_sys")) {
589
				// newLayout(attributesComposite, 1, name, PROPERTY);
590
				toolkit.createLabel(attributesComposite, name);
591
				// oSCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND |
592
				// SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);//SWT.NONE
593
				oSCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY);
594
				// oSCombo = new Combo(attributesComposite, SWT.FLAT |
595
				// SWT.READ_ONLY);
596
				toolkit.adapt(oSCombo, true, true);
597
				oSCombo.setFont(TEXT_FONT);
598
				oSCombo.setLayoutData(data);
599
				// oSCombo.setBackground(background);
600
				Set<String> s = values.keySet();
601
				String[] a = s.toArray(new String[s.size()]);
602
				Arrays.sort(a);
603
				for (int i = 0; i < a.length; i++) {
604
					oSCombo.add(a[i]);
605
				}
606
				if (oSCombo.indexOf(value) != -1) {
607
					oSCombo.select(oSCombo.indexOf(value));
608
				} else {
609
					oSCombo.select(oSCombo.indexOf("All"));
610
				}
611
				// oSCombo.addListener(SWT.Modify, this);
612
				oSCombo.addSelectionListener(new ComboSelectionListener(oSCombo));
613
				comboListenerMap.put(oSCombo, name);
614
				oSCombo.addListener(SWT.FocusIn, new GenericListener());
615
				currentCol += 2;
616
			} else if (key.equals("version")) {
617
				// newLayout(attributesComposite, 1, name, PROPERTY);
618
				toolkit.createLabel(attributesComposite, name);
619
				versionCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
620
						| SWT.READ_ONLY);
621
				toolkit.adapt(versionCombo, true, true);
622
				versionCombo.setFont(TEXT_FONT);
623
				versionCombo.setLayoutData(data);
624
				// versionCombo.setBackground(background);
625
				Set<String> s = values.keySet();
626
				String[] a = s.toArray(new String[s.size()]);
627
				Arrays.sort(a);
628
				for (int i = 0; i < a.length; i++) {
629
					versionCombo.add(a[i]);
630
				}
631
				versionCombo.select(versionCombo.indexOf(value));
632
				// versionCombo.addListener(SWT.Modify, this);
633
				versionCombo.addSelectionListener(new ComboSelectionListener(versionCombo));
634
				versionCombo.addListener(SWT.FocusIn, new GenericListener());
635
				comboListenerMap.put(versionCombo, name);
636
				currentCol += 2;
637
			} else if (key.equals("priority")) {
638
				// newLayout(attributesComposite, 1, "Priority", PROPERTY);
639
				toolkit.createLabel(attributesComposite, name);
938
				toolkit.createLabel(attributesComposite, name);
640
				priorityCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.V_SCROLL | SWT.READ_ONLY);
939
				attributeCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY);
641
				toolkit.adapt(priorityCombo, true, true);
940
				toolkit.adapt(attributeCombo, true, true);
642
				priorityCombo.setFont(TEXT_FONT);
941
				attributeCombo.setFont(TEXT_FONT);
643
				priorityCombo.setLayoutData(data);
942
				attributeCombo.setLayoutData(data);
644
				// priorityCombo.setBackground(background);
645
				Set<String> s = values.keySet();
943
				Set<String> s = values.keySet();
646
				String[] a = s.toArray(new String[s.size()]);
944
				String[] a = s.toArray(new String[s.size()]);
647
				Arrays.sort(a);
945
				Arrays.sort(a);
648
				for (int i = 0; i < a.length; i++) {
946
				for (int i = 0; i < a.length; i++) {
649
					priorityCombo.add(a[i]);
947
					attributeCombo.add(a[i]);
650
				}
948
				}
651
				priorityCombo.select(priorityCombo.indexOf(value));
949
				if (attributeCombo.indexOf(value) != -1) {
652
				// priorityCombo.addListener(SWT.Modify, this);
950
					attributeCombo.select(attributeCombo.indexOf(value));
653
				priorityCombo.addSelectionListener(new ComboSelectionListener(priorityCombo));
654
				priorityCombo.addListener(SWT.FocusIn, new GenericListener());
655
				comboListenerMap.put(priorityCombo, name);
656
				currentCol += 2;
657
			} else if (key.equals("bug_severity")) {
658
				// newLayout(attributesComposite, 1, name, PROPERTY);
659
				toolkit.createLabel(attributesComposite, name);
660
				severityCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.READ_ONLY);
661
				toolkit.adapt(severityCombo, true, true);
662
				severityCombo.setFont(TEXT_FONT);
663
				severityCombo.setLayoutData(data);
664
				// severityCombo.setBackground(background);
665
				Set<String> s = values.keySet();
666
				String[] a = s.toArray(new String[s.size()]);
667
				Arrays.sort(a);
668
				for (int i = 0; i < a.length; i++) {
669
					severityCombo.add(a[i]);
670
				}
951
				}
671
				severityCombo.select(severityCombo.indexOf(value));
952
				attributeCombo.addSelectionListener(new ComboSelectionListener(attributeCombo));
672
				severityCombo.addSelectionListener(new ComboSelectionListener(severityCombo));
953
				comboListenerMap.put(attributeCombo, attribute);
673
				// severityCombo.addListener(SWT.Modify, this);
954
				attributeCombo.addListener(SWT.FocusIn, new GenericListener());
674
				severityCombo.addListener(SWT.FocusIn, new GenericListener());
675
				comboListenerMap.put(severityCombo, name);
676
				currentCol += 2;
955
				currentCol += 2;
677
			} else if (key.equals("target_milestone")) {
956
			} else {
678
				// newLayout(attributesComposite, 1, name, PROPERTY);
679
				toolkit.createLabel(attributesComposite, name);
957
				toolkit.createLabel(attributesComposite, name);
680
				milestoneCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.NO_BACKGROUND | SWT.MULTI
958
				Composite textFieldComposite = toolkit.createComposite(attributesComposite);
681
						| SWT.V_SCROLL | SWT.READ_ONLY);
682
				toolkit.adapt(milestoneCombo, true, true);
683
				milestoneCombo.setFont(TEXT_FONT);
684
				milestoneCombo.setLayoutData(data);
685
				// milestoneCombo.setBackground(background);
686
				Set<String> s = values.keySet();
687
				String[] a = s.toArray(new String[s.size()]);
688
				Arrays.sort(a);
689
				for (int i = 0; i < a.length; i++) {
690
					milestoneCombo.add(a[i]);
691
				}
692
				milestoneCombo.select(milestoneCombo.indexOf(value));
693
				// milestoneCombo.addListener(SWT.Modify, this);
694
				milestoneCombo.addSelectionListener(new ComboSelectionListener(milestoneCombo));
695
				milestoneCombo.addListener(SWT.FocusIn, new GenericListener());
696
				comboListenerMap.put(milestoneCombo, name);
697
				currentCol += 2;
698
			} else if (key.equals("rep_platform")) {
699
				// newLayout(attributesComposite, 1, name, PROPERTY);
700
				toolkit.createLabel(attributesComposite, name);
701
				platformCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
702
						| SWT.READ_ONLY);
703
				toolkit.adapt(platformCombo, true, true);
704
				platformCombo.setFont(TEXT_FONT);
705
				platformCombo.setLayoutData(data);
706
				// platformCombo.setBackground(background);
707
				Set<String> s = values.keySet();
708
				String[] a = s.toArray(new String[s.size()]);
709
				Arrays.sort(a);
710
				for (int i = 0; i < a.length; i++) {
711
					platformCombo.add(a[i]);
712
				}
713
				platformCombo.select(platformCombo.indexOf(value));
714
				// platformCombo.addListener(SWT.Modify, this);
715
				platformCombo.addSelectionListener(new ComboSelectionListener(platformCombo));
716
				platformCombo.addListener(SWT.FocusIn, new GenericListener());
717
				comboListenerMap.put(platformCombo, name);
718
				currentCol += 2;
719
			} else if (key.equals("product")) {
720
				// newLayout(attributesComposite, 1, name, PROPERTY);
721
				toolkit.createLabel(attributesComposite, name);
722
				// toolkit.createLabel(attributesComposite, value);
723
				Composite uneditableComp = toolkit.createComposite(attributesComposite);
724
				GridLayout textLayout = new GridLayout();
959
				GridLayout textLayout = new GridLayout();
725
				textLayout.marginWidth = 1;
960
				textLayout.marginWidth = 1;
726
				uneditableComp.setLayout(textLayout);
961
				textFieldComposite.setLayout(textLayout);
727
				toolkit.createText(uneditableComp, value, SWT.READ_ONLY);// Label(attributesComposite,
962
				GridData textData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
728
				// value);
963
				textData.horizontalSpan = 1;
729
				// newLayout(attributesComposite, 1, value,
964
				textData.widthHint = 135;
730
				// VALUE).addListener(SWT.FocusIn, new GenericListener());
965
731
				currentCol += 2;
966
				if (attribute.isReadOnly()) {
732
			} else if (key.equals("assigned_to")) {
967
					final Text text = toolkit.createText(textFieldComposite, value, SWT.FLAT | SWT.READ_ONLY);
733
				// newLayout(attributesComposite, 1, name, PROPERTY);
968
					text.setLayoutData(textData);
734
				toolkit.createLabel(attributesComposite, name);
969
				} else {
735
				assignedTo = new Text(attributesComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
970
					final Text text = toolkit.createText(textFieldComposite, value, SWT.FLAT);
736
				assignedTo.setFont(TEXT_FONT);
971
					text.setLayoutData(textData);
737
				assignedTo.setText(value);
972
					toolkit.paintBordersFor(textFieldComposite);
738
				data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
973
					text.setData(attribute);
739
				data.horizontalSpan = 1;
974
					text.addListener(SWT.KeyUp, new Listener() {
740
				assignedTo.setLayoutData(data);
975
						public void handleEvent(Event event) {
741
976
							String sel = text.getText();
742
				assignedTo.addListener(SWT.KeyUp, new Listener() {
977
							AbstractRepositoryReportAttribute a = (AbstractRepositoryReportAttribute) text.getData();
743
					public void handleEvent(Event event) {
978
							if (!(a.getValue().equals(sel))) {
744
						String sel = assignedTo.getText();
979
								a.setValue(sel);
745
						Attribute a = getBug().getAttribute("Assign To");
980
								changeDirtyStatus(true);
746
						if (!(a.getNewValue().equals(sel))) {
981
							}
747
							a.setNewValue(sel);
748
							changeDirtyStatus(true);
749
						}
982
						}
750
					}
983
					});
751
				});
984
					text.addListener(SWT.FocusIn, new GenericListener());
752
				assignedTo.addListener(SWT.FocusIn, new GenericListener());
753
754
				currentCol += 2;
755
			} else if (key.equals("component")) {
756
				// newLayout(attributesComposite, 1, name, PROPERTY);
757
				toolkit.createLabel(attributesComposite, name);
758
				componentCombo = new CCombo(attributesComposite, SWT.FLAT | SWT.NO_BACKGROUND | SWT.MULTI
759
						| SWT.V_SCROLL | SWT.READ_ONLY);
760
				toolkit.adapt(componentCombo, true, true);
761
				componentCombo.setFont(TEXT_FONT);
762
				componentCombo.setLayoutData(data);
763
				// componentCombo.setBackground(background);
764
				Set<String> s = values.keySet();
765
				String[] a = s.toArray(new String[s.size()]);
766
				Arrays.sort(a);
767
				for (int i = 0; i < a.length; i++) {
768
					componentCombo.add(a[i]);
769
				}
985
				}
770
				componentCombo.select(componentCombo.indexOf(value));
986
771
				// componentCombo.addListener(SWT.Modify, this);
772
				componentCombo.addSelectionListener(new ComboSelectionListener(componentCombo));
773
				componentCombo.addListener(SWT.FocusIn, new GenericListener());
774
				comboListenerMap.put(componentCombo, name);
775
				currentCol += 2;
776
			} else if (name.equals("Summary")) {
777
				// Don't show the summary here.
778
				continue;
779
			} else if (name.equals("Last Modified")) {
780
				// Don't show last modified here.
781
				continue;
782
			} else if (name.equals("Bug#")) {
783
				// Don't show bug number here
784
				continue;
785
			} else if (values.isEmpty()) {
786
				// newLayout(attributesComposite, 1, name, PROPERTY);
787
				toolkit.createLabel(attributesComposite, name);
788
				Composite uneditableComp = toolkit.createComposite(attributesComposite);
789
				GridLayout textLayout = new GridLayout();
790
				textLayout.marginWidth = 1;
791
				uneditableComp.setLayout(textLayout);
792
				toolkit.createText(uneditableComp, value, SWT.READ_ONLY);// Label(attributesComposite,
793
				// value);
794
				// newLayout(attributesComposite, 1, value,
795
				// VALUE).addListener(SWT.FocusIn, new GenericListener());
796
				currentCol += 2;
987
				currentCol += 2;
797
			}
988
			}
798
			if (currentCol > attributesLayout.numColumns) {
989
			if (currentCol > attributesLayout.numColumns) {
799
				currentCol -= attributesLayout.numColumns;
990
				currentCol -= attributesLayout.numColumns;
800
			}
991
			}
992
801
		}
993
		}
802
		// End Populate Attributes
803
994
804
		// make sure that we are in the first column
995
		// make sure that we are in the first column
805
		if (currentCol > 1) {
996
		if (currentCol > 1) {
806
			while (currentCol <= attributesLayout.numColumns) {
997
			while (currentCol <= attributesLayout.numColumns) {
807
				newLayout(attributesComposite, 1, "", PROPERTY);
998
				toolkit.createLabel(attributesComposite, "");
999
				// newLayout(attributesComposite, 1, "", PROPERTY);
808
				currentCol++;
1000
				currentCol++;
809
			}
1001
			}
810
		}
1002
		}
811
1003
812
		// URL, Keywords, Summary Text Fields
1004
		// Perhaps these should be performed in subclass eventually
813
		addUrlText(url, attributesComposite);
1005
1006
		addCCList(toolkit, "", attributesComposite);
1007
1008
		// URL field
1009
		addUrlText(getReport().getAttributeValue(BugzillaReportElement.BUG_FILE_LOC), attributesComposite);
814
1010
815
		// keywords text field (not editable)
1011
		// keywords text field (not editable)
816
		addKeywordsList(toolkit, keywords, attributesComposite);
1012
		addKeywordsList(toolkit, getReport().getAttributeValue(BugzillaReportElement.KEYWORDS), attributesComposite);
817
		if (ccValue != null) {
1013
818
			addCCList(toolkit, ccValue, attributesComposite);
819
		}
820
		addSummaryText(attributesComposite);
1014
		addSummaryText(attributesComposite);
821
		// End URL, Keywords, Summary Text Fields
1015
		// End URL, Keywords, Summary Text Fields
822
		toolkit.paintBordersFor(attributesComposite);
1016
		toolkit.paintBordersFor(attributesComposite);
Lines 843-851 Link Here
843
		urlText.addListener(SWT.KeyUp, new Listener() {
1037
		urlText.addListener(SWT.KeyUp, new Listener() {
844
			public void handleEvent(Event event) {
1038
			public void handleEvent(Event event) {
845
				String sel = urlText.getText();
1039
				String sel = urlText.getText();
846
				Attribute a = getBug().getAttribute("URL");
1040
				AbstractRepositoryReportAttribute a = getReport().getAttribute(BugzillaReportElement.BUG_FILE_LOC);
847
				if (!(a.getNewValue().equals(sel))) {
1041
				if (!(a.getValue().equals(sel))) {
848
					a.setNewValue(sel);
1042
					a.setValue(sel);
849
					changeDirtyStatus(true);
1043
					changeDirtyStatus(true);
850
				}
1044
				}
851
			}
1045
			}
Lines 1187-1198 Link Here
1187
	public void saveBug() {
1381
	public void saveBug() {
1188
		try {
1382
		try {
1189
			updateBug();
1383
			updateBug();
1190
			IBugzillaBug bug = getBug();
1384
			// IBugzillaBug bug = getBug();
1191
1385
1192
			final BugzillaRepositoryConnector bugzillaRepositoryClient = (BugzillaRepositoryConnector) MylarTaskListPlugin
1386
			final BugzillaRepositoryConnector bugzillaRepositoryClient = (BugzillaRepositoryConnector) MylarTaskListPlugin
1193
					.getRepositoryManager().getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
1387
					.getRepositoryManager().getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
1194
			changeDirtyStatus(false);
1388
			changeDirtyStatus(false);
1195
			bugzillaRepositoryClient.saveBugReport(bug);
1389
			bugzillaRepositoryClient.saveBugReport((BugzillaReport) getReport());
1196
		} catch (Exception e) {
1390
		} catch (Exception e) {
1197
			MylarStatusHandler.fail(e, "bug save offline failed", true);
1391
			MylarStatusHandler.fail(e, "bug save offline failed", true);
1198
		}
1392
		}
Lines 1336-1342 Link Here
1336
	 */
1530
	 */
1337
	protected class GenericListener implements Listener {
1531
	protected class GenericListener implements Listener {
1338
		public void handleEvent(Event event) {
1532
		public void handleEvent(Event event) {
1339
			IBugzillaBug bug = getBug();
1533
			BugzillaReport bug = (BugzillaReport) getReport();
1340
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(
1534
			fireSelectionChanged(new SelectionChangedEvent(selectionProvider, new StructuredSelection(
1341
					new BugzillaReportSelection(bug.getId(), bug.getRepositoryUrl(), bug.getLabel(), false, bug
1535
					new BugzillaReportSelection(bug.getId(), bug.getRepositoryUrl(), bug.getLabel(), false, bug
1342
							.getSummary()))));
1536
							.getSummary()))));
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/NewBugEditorInput.java (-4 / +4 lines)
Lines 11-24 Link Here
11
11
12
package org.eclipse.mylar.internal.bugzilla.ui.editor;
12
package org.eclipse.mylar.internal.bugzilla.ui.editor;
13
13
14
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
14
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
15
15
16
/**
16
/**
17
 * The <code>IEditorInput</code> implementation for <code>NewBugEditor</code>.
17
 * The <code>IEditorInput</code> implementation for <code>NewBugEditor</code>.
18
 */
18
 */
19
public class NewBugEditorInput extends AbstractBugEditorInput {
19
public class NewBugEditorInput extends AbstractBugEditorInput {
20
20
21
	protected NewBugModel bug;
21
	protected NewBugzillaReport bug;
22
22
23
	/**
23
	/**
24
	 * Creates a new <code>NewBugEditorInput</code>.
24
	 * Creates a new <code>NewBugEditorInput</code>.
Lines 26-32 Link Here
26
	 * @param bug
26
	 * @param bug
27
	 *            The bug for this editor input.
27
	 *            The bug for this editor input.
28
	 */
28
	 */
29
	public NewBugEditorInput(NewBugModel bug) {
29
	public NewBugEditorInput(NewBugzillaReport bug) {
30
		this.bug = bug;
30
		this.bug = bug;
31
	}
31
	}
32
32
Lines 35-41 Link Here
35
	}
35
	}
36
36
37
	@Override
37
	@Override
38
	public NewBugModel getBug() {
38
	public NewBugzillaReport getBug() {
39
		return bug;
39
		return bug;
40
	}
40
	}
41
41
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/BugzillaOutlineNode.java (-9 / +10 lines)
Lines 13-23 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.Iterator;
14
import java.util.Iterator;
15
15
16
import org.eclipse.mylar.bugzilla.core.BugReport;
16
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
17
import org.eclipse.mylar.bugzilla.core.Comment;
17
import org.eclipse.mylar.bugzilla.core.Comment;
18
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
18
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
19
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaReportSelection;
19
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaReportSelection;
20
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
20
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
21
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaImages;
21
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaImages;
22
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Image;
23
23
Lines 196-205 Link Here
196
	public static BugzillaOutlineNode parseBugReport(IBugzillaBug bug) {
196
	public static BugzillaOutlineNode parseBugReport(IBugzillaBug bug) {
197
		// Choose the appropriate parsing function based on
197
		// Choose the appropriate parsing function based on
198
		// the type of IBugzillaBug.
198
		// the type of IBugzillaBug.
199
		if (bug instanceof NewBugModel) {
199
		if (bug instanceof NewBugzillaReport) {
200
			return parseBugReport((NewBugModel) bug);
200
			return parseBugReport((NewBugzillaReport) bug);
201
		} else if (bug instanceof BugReport) {
201
		} else if (bug instanceof BugzillaReport) {
202
			return parseBugReport((BugReport) bug);
202
			return parseBugReport((BugzillaReport) bug);
203
		} else {
203
		} else {
204
			return null;
204
			return null;
205
		}
205
		}
Lines 214-220 Link Here
214
	 *            The <code>NewBugModel</code> that needs parsing.
214
	 *            The <code>NewBugModel</code> that needs parsing.
215
	 * @return The tree of <code>BugzillaOutlineNode</code>'s.
215
	 * @return The tree of <code>BugzillaOutlineNode</code>'s.
216
	 */
216
	 */
217
	protected static BugzillaOutlineNode parseBugReport(NewBugModel bug) {
217
	protected static BugzillaOutlineNode parseBugReport(NewBugzillaReport bug) {
218
		int bugId = bug.getId();
218
		int bugId = bug.getId();
219
		String bugServer = bug.getRepositoryUrl();
219
		String bugServer = bug.getRepositoryUrl();
220
		Image bugImage = BugzillaImages.getImage(BugzillaImages.BUG);
220
		Image bugImage = BugzillaImages.getImage(BugzillaImages.BUG);
Lines 241-247 Link Here
241
	 *            The <code>BugReport</code> that needs parsing.
241
	 *            The <code>BugReport</code> that needs parsing.
242
	 * @return The tree of <code>BugzillaOutlineNode</code>'s.
242
	 * @return The tree of <code>BugzillaOutlineNode</code>'s.
243
	 */
243
	 */
244
	protected static BugzillaOutlineNode parseBugReport(BugReport bug) {
244
	protected static BugzillaOutlineNode parseBugReport(BugzillaReport bug) {
245
245
246
		int bugId = bug.getId();
246
		int bugId = bug.getId();
247
		String bugServer = bug.getRepositoryUrl();
247
		String bugServer = bug.getRepositoryUrl();
Lines 259-265 Link Here
259
		BugzillaOutlineNode comments = null;
259
		BugzillaOutlineNode comments = null;
260
		for (Iterator<Comment> iter = bug.getComments().iterator(); iter.hasNext();) {
260
		for (Iterator<Comment> iter = bug.getComments().iterator(); iter.hasNext();) {
261
			Comment comment = iter.next();
261
			Comment comment = iter.next();
262
262
			// first comment is the bug description
263
			if(comment.getNumber() == 0) continue;
263
			if (comments == null) {
264
			if (comments == null) {
264
				comments = new BugzillaOutlineNode(bugId, bugServer, "Comments", defaultImage, comment, bug
265
				comments = new BugzillaOutlineNode(bugId, bugServer, "Comments", defaultImage, comment, bug
265
						.getSummary());
266
						.getSummary());
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/ExistingBugEditorInput.java (-4 / +4 lines)
Lines 14-20 Link Here
14
14
15
import javax.security.auth.login.LoginException;
15
import javax.security.auth.login.LoginException;
16
16
17
import org.eclipse.mylar.bugzilla.core.BugReport;
17
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
18
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
18
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
19
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
19
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
20
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
20
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
Lines 32-38 Link Here
32
32
33
	protected int bugId;
33
	protected int bugId;
34
34
35
	protected BugReport bug;
35
	protected BugzillaReport bug;
36
36
37
	/**
37
	/**
38
	 * Creates a new <code>ExistingBugEditorInput</code>.
38
	 * Creates a new <code>ExistingBugEditorInput</code>.
Lines 40-46 Link Here
40
	 * @param bug
40
	 * @param bug
41
	 *            The bug for this editor input.
41
	 *            The bug for this editor input.
42
	 */
42
	 */
43
	public ExistingBugEditorInput(BugReport bug) {
43
	public ExistingBugEditorInput(BugzillaReport bug) {
44
		this.bug = bug;
44
		this.bug = bug;
45
		this.bugId = bug.getId();
45
		this.bugId = bug.getId();
46
		repository = MylarTaskListPlugin.getRepositoryManager().getRepository(BugzillaPlugin.REPOSITORY_KIND,
46
		repository = MylarTaskListPlugin.getRepositoryManager().getRepository(BugzillaPlugin.REPOSITORY_KIND,
Lines 101-107 Link Here
101
	}
101
	}
102
102
103
	@Override
103
	@Override
104
	public BugReport getBug() {
104
	public BugzillaReport getBug() {
105
		return bug;
105
		return bug;
106
	}
106
	}
107
107
(-)src/org/eclipse/mylar/internal/bugzilla/ui/BugzillaUITools.java (-6 / +6 lines)
Lines 25-35 Link Here
25
import org.eclipse.jface.text.IRegion;
25
import org.eclipse.jface.text.IRegion;
26
import org.eclipse.jface.text.Region;
26
import org.eclipse.jface.text.Region;
27
import org.eclipse.jface.text.hyperlink.IHyperlink;
27
import org.eclipse.jface.text.hyperlink.IHyperlink;
28
import org.eclipse.mylar.bugzilla.core.BugReport;
28
import org.eclipse.mylar.bugzilla.core.BugzillaReport;
29
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
29
import org.eclipse.mylar.bugzilla.core.IBugzillaBug;
30
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
30
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
31
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
31
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
32
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
32
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
33
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditor;
33
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditor;
34
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditorInput;
34
import org.eclipse.mylar.internal.bugzilla.ui.editor.ExistingBugEditorInput;
35
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditorInput;
35
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditorInput;
Lines 227-240 Link Here
227
	}
227
	}
228
228
229
	public static void closeEditor(IWorkbenchPage page, IBugzillaBug bug) {
229
	public static void closeEditor(IWorkbenchPage page, IBugzillaBug bug) {
230
		if (bug instanceof NewBugModel) {
230
		if (bug instanceof NewBugzillaReport) {
231
			IEditorInput input = new NewBugEditorInput((NewBugModel) bug);
231
			IEditorInput input = new NewBugEditorInput((NewBugzillaReport) bug);
232
			IEditorPart bugEditor = page.findEditor(input);
232
			IEditorPart bugEditor = page.findEditor(input);
233
			if (bugEditor != null) {
233
			if (bugEditor != null) {
234
				page.closeEditor(bugEditor, false);
234
				page.closeEditor(bugEditor, false);
235
			}
235
			}
236
		} else if (bug instanceof BugReport) {
236
		} else if (bug instanceof BugzillaReport) {
237
			IEditorInput input = new ExistingBugEditorInput((BugReport) bug);
237
			IEditorInput input = new ExistingBugEditorInput((BugzillaReport) bug);
238
			IEditorPart bugEditor = page.findEditor(input);
238
			IEditorPart bugEditor = page.findEditor(input);
239
			if (bugEditor != null) {
239
			if (bugEditor != null) {
240
				page.closeEditor(bugEditor, false);
240
				page.closeEditor(bugEditor, false);
(-)src/org/eclipse/mylar/internal/bugzilla/ui/wizard/AbstractBugWizard.java (-3 / +3 lines)
Lines 23-29 Link Here
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
23
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
26
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
27
import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException;
27
import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException;
28
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
28
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
29
import org.eclipse.mylar.internal.bugzilla.ui.WebBrowserDialog;
29
import org.eclipse.mylar.internal.bugzilla.ui.WebBrowserDialog;
Lines 54-60 Link Here
54
	protected boolean fromDialog = false;
54
	protected boolean fromDialog = false;
55
55
56
	/** The model used to store all of the data for the wizard */
56
	/** The model used to store all of the data for the wizard */
57
	protected NewBugModel model;
57
	protected NewBugzillaReport model;
58
58
59
	/**
59
	/**
60
	 * Flag to indicate if the wizard can be completed based on the attributes
60
	 * Flag to indicate if the wizard can be completed based on the attributes
Lines 70-76 Link Here
70
	public AbstractBugWizard(TaskRepository repository) {
70
	public AbstractBugWizard(TaskRepository repository) {
71
		super();
71
		super();
72
		this.repository = repository;
72
		this.repository = repository;
73
		model = new NewBugModel();
73
		model = new NewBugzillaReport(repository.getUrl());
74
		id = null; // Since there is no bug posted yet.
74
		id = null; // Since there is no bug posted yet.
75
		super.setDefaultPageImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin(
75
		super.setDefaultPageImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin(
76
				"org.eclipse.mylar.internal.bugzilla.ui", "icons/wizban/bug-wizard.gif"));
76
				"org.eclipse.mylar.internal.bugzilla.ui", "icons/wizban/bug-wizard.gif"));
(-)src/org/eclipse/mylar/internal/bugzilla/ui/wizard/AbstractBugzillaWizardPage.java (-38 / +40 lines)
Lines 20-28 Link Here
20
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jface.wizard.IWizardPage;
21
import org.eclipse.jface.wizard.IWizardPage;
22
import org.eclipse.jface.wizard.WizardPage;
22
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.mylar.bugzilla.core.Attribute;
23
import org.eclipse.mylar.bugzilla.core.AbstractRepositoryReportAttribute;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
24
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.BugReportElement;
25
import org.eclipse.mylar.internal.bugzilla.core.internal.BugzillaReportElement;
26
import org.eclipse.mylar.internal.bugzilla.ui.editor.AbstractBugEditor;
26
import org.eclipse.mylar.internal.bugzilla.ui.editor.AbstractBugEditor;
27
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
27
import org.eclipse.mylar.internal.core.util.MylarStatusHandler;
28
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.SWT;
Lines 303-353 Link Here
303
	public void saveDataToModel() {
303
	public void saveDataToModel() {
304
		// get the model that we are using
304
		// get the model that we are using
305
		AbstractBugWizard wizard = (AbstractBugWizard) getWizard();
305
		AbstractBugWizard wizard = (AbstractBugWizard) getWizard();
306
		NewBugModel nbm = wizard.model;
306
		NewBugzillaReport nbm = wizard.model;
307
307
308
		nbm.setDescription(descriptionText.getText());
308
		nbm.setDescription(descriptionText.getText());
309
		nbm.setSummary(summaryText.getText());
309
		nbm.setSummary(summaryText.getText());
310
310
311
		// go through each of the attributes and sync their values with the
311
		// go through each of the attributes and sync their values with the
312
		// combo boxes
312
		// combo boxes
313
		for (Iterator<Attribute> it = nbm.getAttributes().iterator(); it.hasNext();) {
313
		for (Iterator<AbstractRepositoryReportAttribute> it = nbm.getAttributes().iterator(); it.hasNext();) {
314
			Attribute attribute = it.next();
314
			AbstractRepositoryReportAttribute attribute = it.next();
315
			String key = attribute.getName();
315
			String key = attribute.getName();
316
			Map<String, String> values = attribute.getOptionValues();
316
			Map<String, String> values = attribute.getOptionValues();
317
317
318
			try {
318
			try {
319
				if (values == null)
319
				if (values == null)
320
					values = new HashMap<String, String>();
320
					values = new HashMap<String, String>();
321
				if (key.equals(BugReportElement.OP_SYS.toString())) {
321
				if (key.equals(BugzillaReportElement.OP_SYS.toString())) {
322
					String os = oSCombo.getItem(oSCombo.getSelectionIndex());
322
					String os = oSCombo.getItem(oSCombo.getSelectionIndex());
323
					attribute.setValue(os);
323
					attribute.setValue(os);
324
				} else if (key.equals(BugReportElement.VERSION.toString())) {
324
				} else if (key.equals(BugzillaReportElement.VERSION.toString())) {
325
					String version = versionCombo.getItem(versionCombo.getSelectionIndex());
325
					String version = versionCombo.getItem(versionCombo.getSelectionIndex());
326
					attribute.setValue(version);
326
					attribute.setValue(version);
327
				} else if (key.equals(BugReportElement.BUG_SEVERITY.toString())) {
327
				} else if (key.equals(BugzillaReportElement.BUG_SEVERITY.toString())) {
328
					String severity = severityCombo.getItem(severityCombo.getSelectionIndex());
328
					String severity = severityCombo.getItem(severityCombo.getSelectionIndex());
329
					attribute.setValue(severity);
329
					attribute.setValue(severity);
330
				} else if (key.equals(BugReportElement.REP_PLATFORM.toString())) {
330
				} else if (key.equals(BugzillaReportElement.REP_PLATFORM.toString())) {
331
					String platform = platformCombo.getItem(platformCombo.getSelectionIndex());
331
					String platform = platformCombo.getItem(platformCombo.getSelectionIndex());
332
					attribute.setValue(platform);
332
					attribute.setValue(platform);
333
				} else if (key.equals(BugReportElement.TARGET_MILESTONE.toString())) {
333
				} else if (key.equals(BugzillaReportElement.TARGET_MILESTONE.toString())) {
334
					int index = milestoneCombo.getSelectionIndex();
334
					int index = milestoneCombo.getSelectionIndex();
335
					if(index >= 0) {
335
					if(index >= 0) {
336
						String milestone = milestoneCombo.getItem(milestoneCombo.getSelectionIndex());
336
						String milestone = milestoneCombo.getItem(milestoneCombo.getSelectionIndex());
337
						attribute.setValue(milestone);
337
						attribute.setValue(milestone);
338
					}
338
					}
339
				} else if (key.equals(BugReportElement.COMPONENT.toString())) {
339
				} else if (key.equals(BugzillaReportElement.COMPONENT.toString())) {
340
					String component = componentCombo.getItem(componentCombo.getSelectionIndex());
340
					String component = componentCombo.getItem(componentCombo.getSelectionIndex());
341
					attribute.setValue(component);
341
					attribute.setValue(component);
342
				} else if (key.equals(BugReportElement.PRIORITY.toString())) {
342
				} else if (key.equals(BugzillaReportElement.PRIORITY.toString())) {
343
					String priority = priorityCombo.getItem(priorityCombo.getSelectionIndex());
343
					String priority = priorityCombo.getItem(priorityCombo.getSelectionIndex());
344
					attribute.setValue(priority);
344
					attribute.setValue(priority);
345
				} else if (key.equals(BugReportElement.BUG_FILE_LOC.toString())) {
345
				} else if (key.equals(BugzillaReportElement.BUG_FILE_LOC.toString())) {
346
					String url = urlText.getText();
346
					if (urlText != null) {
347
					if (url.equalsIgnoreCase("http://"))
347
						String url = urlText.getText();
348
						url = "";
348
						if (url.equalsIgnoreCase("http://"))
349
					attribute.setValue(url);
349
							url = "";
350
				} else if (key.equals(BugReportElement.ASSIGNED_TO.toString())) {
350
						attribute.setValue(url);
351
					}					
352
				} else if (key.equals(BugzillaReportElement.ASSIGNED_TO.toString())) {
351
					String assignTo = assignedToText.getText();
353
					String assignTo = assignedToText.getText();
352
					attribute.setValue(assignTo);
354
					attribute.setValue(assignTo);
353
				} else {
355
				} else {
Lines 379-385 Link Here
379
381
380
		// get the model for the new bug
382
		// get the model for the new bug
381
		AbstractBugWizard wizard = (AbstractBugWizard) getWizard();
383
		AbstractBugWizard wizard = (AbstractBugWizard) getWizard();
382
		NewBugModel nbm = wizard.model;
384
		NewBugzillaReport nbm = wizard.model;
383
385
384
		// Set the current platform and OS on the model
386
		// Set the current platform and OS on the model
385
		setPlatformOptions(nbm);
387
		setPlatformOptions(nbm);
Lines 414-422 Link Here
414
		newLayout(attributesComposite, 1, nbm.getProduct(), VALUE);
416
		newLayout(attributesComposite, 1, nbm.getProduct(), VALUE);
415
417
416
		// Populate Attributes
418
		// Populate Attributes
417
		for (Iterator<Attribute> it = nbm.getAttributes().iterator(); it.hasNext();) {
419
		for (Iterator<AbstractRepositoryReportAttribute> it = nbm.getAttributes().iterator(); it.hasNext();) {
418
			Attribute attribute = it.next();
420
			AbstractRepositoryReportAttribute attribute = it.next();
419
			String key = attribute.getParameterName();
421
			String key = attribute.getID();
420
			String name = attribute.getName();
422
			String name = attribute.getName();
421
			String value = checkText(attribute.getValue());
423
			String value = checkText(attribute.getValue());
422
			Map<String, String> values = attribute.getOptionValues();
424
			Map<String, String> values = attribute.getOptionValues();
Lines 436-442 Link Here
436
			data.horizontalIndent = HORZ_INDENT;
438
			data.horizontalIndent = HORZ_INDENT;
437
			data.widthHint = 150;
439
			data.widthHint = 150;
438
			// create and populate the combo fields for the attributes
440
			// create and populate the combo fields for the attributes
439
			if (key.equals(BugReportElement.OP_SYS.getKeyString())) {
441
			if (key.equals(BugzillaReportElement.OP_SYS.getKeyString())) {
440
				newLayout(attributesComposite, 1, name, PROPERTY);
442
				newLayout(attributesComposite, 1, name, PROPERTY);
441
				oSCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);
443
				oSCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL | SWT.READ_ONLY);
442
444
Lines 451-457 Link Here
451
					index = 0;
453
					index = 0;
452
				oSCombo.select(index);
454
				oSCombo.select(index);
453
				oSCombo.addListener(SWT.Modify, this);
455
				oSCombo.addListener(SWT.Modify, this);
454
			} else if (key.equals(BugReportElement.VERSION.getKeyString())) {
456
			} else if (key.equals(BugzillaReportElement.VERSION.getKeyString())) {
455
				newLayout(attributesComposite, 1, name, PROPERTY);
457
				newLayout(attributesComposite, 1, name, PROPERTY);
456
458
457
				versionCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
459
				versionCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
Lines 468-474 Link Here
468
					index = 0;
470
					index = 0;
469
				versionCombo.select(index);
471
				versionCombo.select(index);
470
				versionCombo.addListener(SWT.Modify, this);
472
				versionCombo.addListener(SWT.Modify, this);
471
			} else if (key.equals(BugReportElement.BUG_SEVERITY.getKeyString())) {
473
			} else if (key.equals(BugzillaReportElement.BUG_SEVERITY.getKeyString())) {
472
				newLayout(attributesComposite, 1, name, PROPERTY);
474
				newLayout(attributesComposite, 1, name, PROPERTY);
473
				severityCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
475
				severityCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
474
						| SWT.READ_ONLY);
476
						| SWT.READ_ONLY);
Lines 485-491 Link Here
485
				severityCombo.select(index);
487
				severityCombo.select(index);
486
				severityCombo.addListener(SWT.Modify, this);
488
				severityCombo.addListener(SWT.Modify, this);
487
489
488
			} else if (key.equals(BugReportElement.REP_PLATFORM.getKeyString())) {
490
			} else if (key.equals(BugzillaReportElement.REP_PLATFORM.getKeyString())) {
489
				newLayout(attributesComposite, 1, name, PROPERTY);
491
				newLayout(attributesComposite, 1, name, PROPERTY);
490
				platformCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
492
				platformCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
491
						| SWT.READ_ONLY);
493
						| SWT.READ_ONLY);
Lines 501-507 Link Here
501
					index = 0;
503
					index = 0;
502
				platformCombo.select(index);
504
				platformCombo.select(index);
503
				platformCombo.addListener(SWT.Modify, this);
505
				platformCombo.addListener(SWT.Modify, this);
504
			} else if (key.equals(BugReportElement.TARGET_MILESTONE.getKeyString())) {
506
			} else if (key.equals(BugzillaReportElement.TARGET_MILESTONE.getKeyString())) {
505
				newLayout(attributesComposite, 1, name, PROPERTY);
507
				newLayout(attributesComposite, 1, name, PROPERTY);
506
				milestoneCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
508
				milestoneCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
507
						| SWT.READ_ONLY);
509
						| SWT.READ_ONLY);
Lines 518-524 Link Here
518
				milestoneCombo.addListener(SWT.Modify, this);
520
				milestoneCombo.addListener(SWT.Modify, this);
519
				//if(s.isEmpty()) milestoneCombo.setEnabled(false);
521
				//if(s.isEmpty()) milestoneCombo.setEnabled(false);
520
				mileExist = true;
522
				mileExist = true;
521
			} else if (key.equals(BugReportElement.COMPONENT.getKeyString())) {
523
			} else if (key.equals(BugzillaReportElement.COMPONENT.getKeyString())) {
522
				newLayout(attributesComposite, 1, name, PROPERTY);
524
				newLayout(attributesComposite, 1, name, PROPERTY);
523
				componentCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
525
				componentCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
524
						| SWT.READ_ONLY);
526
						| SWT.READ_ONLY);
Lines 534-540 Link Here
534
					index = 0;
536
					index = 0;
535
				componentCombo.select(index);
537
				componentCombo.select(index);
536
				componentCombo.addListener(SWT.Modify, this);
538
				componentCombo.addListener(SWT.Modify, this);
537
			} else if (key.equals(BugReportElement.PRIORITY.getKeyString())) {
539
			} else if (key.equals(BugzillaReportElement.PRIORITY.getKeyString())) {
538
				newLayout(attributesComposite, 1, name, PROPERTY);
540
				newLayout(attributesComposite, 1, name, PROPERTY);
539
				priorityCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
541
				priorityCombo = new Combo(attributesComposite, SWT.NO_BACKGROUND | SWT.MULTI | SWT.V_SCROLL
540
						| SWT.READ_ONLY);
542
						| SWT.READ_ONLY);
Lines 551-557 Link Here
551
				priorityCombo.select(index);
553
				priorityCombo.select(index);
552
				priorityCombo.addListener(SWT.Modify, this);
554
				priorityCombo.addListener(SWT.Modify, this);
553
				priExist = true;
555
				priExist = true;
554
			} else if (key.equals(BugReportElement.BUG_FILE_LOC.getKeyString())) {
556
			} else if (key.equals(BugzillaReportElement.BUG_FILE_LOC.getKeyString())) {
555
				url = value;
557
				url = value;
556
			} else {
558
			} else {
557
				// do nothing if it isn't a standard value to change
559
				// do nothing if it isn't a standard value to change
Lines 573-579 Link Here
573
	
575
	
574
		GridData urlTextData;
576
		GridData urlTextData;
575
		if (url != null) {			
577
		if (url != null) {			
576
			newLayout(textComposite, 1, BugReportElement.BUG_FILE_LOC.toString(), PROPERTY);
578
			newLayout(textComposite, 1, BugzillaReportElement.BUG_FILE_LOC.toString(), PROPERTY);
577
			urlText = new Text(textComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
579
			urlText = new Text(textComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
578
			urlTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
580
			urlTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
579
581
Lines 585-591 Link Here
585
		}
587
		}
586
588
587
		GridData summaryTextData;
589
		GridData summaryTextData;
588
		newLayout(textComposite, 1, BugReportElement.ASSIGNED_TO.toString(), PROPERTY);
590
		newLayout(textComposite, 1, BugzillaReportElement.ASSIGNED_TO.toString(), PROPERTY);
589
		Label l = new Label(textComposite, SWT.NONE);
591
		Label l = new Label(textComposite, SWT.NONE);
590
		l.setText("(if email is incorrect submit will not proceed)");
592
		l.setText("(if email is incorrect submit will not proceed)");
591
		summaryTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
593
		summaryTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
Lines 600-606 Link Here
600
		assignedToText.setText("");
602
		assignedToText.setText("");
601
603
602
		// add the summary text field
604
		// add the summary text field
603
		newLayout(textComposite, 1, BugReportElement.SHORT_DESC.toString(), PROPERTY);
605
		newLayout(textComposite, 1, BugzillaReportElement.SHORT_DESC.toString(), PROPERTY);
604
		summaryText = new Text(textComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
606
		summaryText = new Text(textComposite, SWT.BORDER | SWT.SINGLE | SWT.WRAP);
605
		summaryTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
607
		summaryTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
606
608
Lines 693-699 Link Here
693
	 * @param newBugModel
695
	 * @param newBugModel
694
	 *            The bug to set the options for
696
	 *            The bug to set the options for
695
	 */
697
	 */
696
	public void setPlatformOptions(NewBugModel newBugModel) {
698
	public void setPlatformOptions(NewBugzillaReport newBugModel) {
697
		try {
699
		try {
698
			// A Map from Java's OS and Platform to Buzilla's
700
			// A Map from Java's OS and Platform to Buzilla's
699
			Map<String, String> java2buzillaOSMap = new HashMap<String, String>();
701
			Map<String, String> java2buzillaOSMap = new HashMap<String, String>();
Lines 712-723 Link Here
712
			java2buzillaOSMap.put("macosx", "MacOS X");
714
			java2buzillaOSMap.put("macosx", "MacOS X");
713
			java2buzillaOSMap.put("qnx", "QNX-Photon");
715
			java2buzillaOSMap.put("qnx", "QNX-Photon");
714
			java2buzillaOSMap.put("solaris", "Solaris");
716
			java2buzillaOSMap.put("solaris", "Solaris");
715
			java2buzillaOSMap.put("win32", "Windows All");
717
			java2buzillaOSMap.put("win32", "Windows");
716
718
717
			// Get OS Lookup Map
719
			// Get OS Lookup Map
718
			// Check that the result is in Values, if it is not, set it to other
720
			// Check that the result is in Values, if it is not, set it to other
719
			Attribute opSysAttribute = newBugModel.getAttribute(BugReportElement.OP_SYS.toString());
721
			AbstractRepositoryReportAttribute opSysAttribute = newBugModel.getAttribute(BugzillaReportElement.OP_SYS);
720
			Attribute platformAttribute = newBugModel.getAttribute(BugReportElement.REP_PLATFORM.toString());
722
			AbstractRepositoryReportAttribute platformAttribute = newBugModel.getAttribute(BugzillaReportElement.REP_PLATFORM);
721
723
722
			String OS = Platform.getOS();
724
			String OS = Platform.getOS();
723
			String platform = Platform.getOSArch();
725
			String platform = Platform.getOSArch();
(-)src/org/eclipse/mylar/internal/bugzilla/ui/wizard/BugzillaProductPage.java (-34 / +30 lines)
Lines 26-32 Link Here
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
27
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
27
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryUtil;
28
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
29
import org.eclipse.mylar.internal.bugzilla.core.NewBugModel;
29
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
30
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
30
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
31
import org.eclipse.mylar.internal.tasklist.ui.views.TaskRepositoriesView;
31
import org.eclipse.mylar.internal.tasklist.ui.views.TaskRepositoriesView;
32
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
32
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
Lines 87-93 Link Here
87
		this.bugWizard = bugWiz;
87
		this.bugWizard = bugWiz;
88
		this.repository = repository;
88
		this.repository = repository;
89
		setImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui",
89
		setImageDescriptor(BugzillaUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui",
90
			"icons/wizban/bug-wizard.gif"));
90
				"icons/wizban/bug-wizard.gif"));
91
	}
91
	}
92
92
93
	protected ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(BugzillaPlugin.getDefault()
93
	protected ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(BugzillaPlugin.getDefault()
Lines 131-140 Link Here
131
									"Bugzilla could not log you in to get the information you requested since login name or password is incorrect.\nPlease check your settings in the bugzilla preferences. ");
131
									"Bugzilla could not log you in to get the information you requested since login name or password is incorrect.\nPlease check your settings in the bugzilla preferences. ");
132
					BugzillaPlugin.log(exception);
132
					BugzillaPlugin.log(exception);
133
				} catch (IOException exception) {
133
				} catch (IOException exception) {
134
					MessageDialog
134
					MessageDialog.openError(null, "Connection Error",
135
					.openError(
135
							"\nPlease check your settings in the bugzilla preferences. ");
136
							null,
137
							"Connection Error","\nPlease check your settings in the bugzilla preferences. ");
138
				} finally {
136
				} finally {
139
					monitor.done();
137
					monitor.done();
140
					monitorDialog.close();
138
					monitorDialog.close();
Lines 159-170 Link Here
159
				bugWizard.model.setParsedProductsStatus(true);
157
				bugWizard.model.setParsedProductsStatus(true);
160
158
161
			} catch (Exception e) {
159
			} catch (Exception e) {
162
				bugWizard.model.setConnected(false);						
160
				bugWizard.model.setConnected(false);
163
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
161
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
164
					public void run() {					
162
					public void run() {
165
						MessageDialog
163
						MessageDialog.openError(Display.getDefault().getActiveShell(), NEW_BUGZILLA_TASK_ERROR_TITLE,
166
								.openError(Display.getDefault().getActiveShell(), NEW_BUGZILLA_TASK_ERROR_TITLE,
164
								"Unable to get products. Ensure proper repository configuration in "
167
										"Unable to get products. Ensure proper repository configuration in "+TaskRepositoriesView.NAME+".");
165
										+ TaskRepositoriesView.NAME + ".");
168
					}
166
					}
169
				});
167
				});
170
			}
168
			}
Lines 204-232 Link Here
204
		// save the product information to the model
202
		// save the product information to the model
205
		saveDataToModel();
203
		saveDataToModel();
206
		NewBugzillaReportWizard wizard = (NewBugzillaReportWizard) getWizard();
204
		NewBugzillaReportWizard wizard = (NewBugzillaReportWizard) getWizard();
207
		NewBugModel model = wizard.model;
205
		NewBugzillaReport model = wizard.model;
208
206
209
		// try to get the attributes from the bugzilla server
207
		// try to get the attributes from the bugzilla server
210
		try {
208
		try {
211
			//if (prevProduct != null && !prevProduct.equals(model.getProduct())) {
209
			if (!model.hasParsedAttributes()) {
212
				//!model.hasParsedAttributes() || 
210
				BugzillaRepositoryUtil.setupNewBugAttributes(repository, model);
213
				String serverUrl = repository.getUrl();
214
//				if (model.isConnected()) {
215
//					BugzillaRepositoryUtil.setupNewBugAttributes(serverUrl, model, false);
216
//				} else {
217
				
218
					BugzillaRepositoryUtil.setupBugAttributes(serverUrl, model);
219
//				}
220
				model.setParsedAttributesStatus(true);
211
				model.setParsedAttributesStatus(true);
221
				if (prevProduct == null) {
212
			}
222
					bugWizard.setAttributePage(new WizardAttributesPage(workbench));
213
223
					bugWizard.addPage(bugWizard.getAttributePage());
214
			if (prevProduct == null) {
224
				} else {
215
				bugWizard.setAttributePage(new WizardAttributesPage(workbench));
225
					// selected product has changed
216
				bugWizard.addPage(bugWizard.getAttributePage());
226
					// will createControl again with new attributes in model
217
			} else {
227
					bugWizard.getAttributePage().setControl(null);
218
				// selected product has changed
228
				}
219
				// will createControl again with new attributes in model
229
			//}
220
				bugWizard.getAttributePage().setControl(null);
221
			}
222
			// }
230
		} catch (final Exception e) {
223
		} catch (final Exception e) {
231
			e.printStackTrace();
224
			e.printStackTrace();
232
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
225
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
Lines 235-243 Link Here
235
							.getLocalizedMessage()
228
							.getLocalizedMessage()
236
							+ " Ensure proper repository configuration in " + TaskRepositoriesView.NAME + ".");
229
							+ " Ensure proper repository configuration in " + TaskRepositoriesView.NAME + ".");
237
				}
230
				}
238
			});			
231
			});
239
//			MylarStatusHandler.fail(e, e.getLocalizedMessage()+" Ensure proper repository configuration in "+TaskRepositoriesView.NAME+".", true);			
232
			// MylarStatusHandler.fail(e, e.getLocalizedMessage()+" Ensure
240
//			BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e, "occurred.", "Bugzilla Error");
233
			// proper repository configuration in
234
			// "+TaskRepositoriesView.NAME+".", true);
235
			// BugzillaPlugin.getDefault().logAndShowExceptionDetailsDialog(e,
236
			// "occurred.", "Bugzilla Error");
241
		}
237
		}
242
		return super.getNextPage();
238
		return super.getNextPage();
243
	}
239
	}
Lines 247-253 Link Here
247
	 */
243
	 */
248
	private void saveDataToModel() {
244
	private void saveDataToModel() {
249
		// Gets the model
245
		// Gets the model
250
		NewBugModel model = bugWizard.model;
246
		NewBugzillaReport model = bugWizard.model;
251
247
252
		prevProduct = model.getProduct();
248
		prevProduct = model.getProduct();
253
		model.setProduct((listBox.getSelection())[0]);
249
		model.setProduct((listBox.getSelection())[0]);

Return to bug 136219