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 143567 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/bugzilla/tests/AllBugzillaTests.java (+1 lines)
Lines 51-56 Link Here
51
		// TODO: enable
51
		// TODO: enable
52
		// suite.addTest(new TestSuite(BugzillaParserTest.class));
52
		// suite.addTest(new TestSuite(BugzillaParserTest.class));
53
		suite.addTestSuite(BugzillaSearchDialogTest.class);
53
		suite.addTestSuite(BugzillaSearchDialogTest.class);
54
		suite.addTestSuite(DuplicateDetetionTest.class);
54
		// $JUnit-END$
55
		// $JUnit-END$
55
		return suite;
56
		return suite;
56
	}
57
	}
(-)src/org/eclipse/mylar/bugzilla/tests/DuplicateDetetionTest.java (+74 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 junit.framework.TestCase;
15
16
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
17
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
18
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
19
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
20
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditor;
21
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditorInput;
22
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
23
import org.eclipse.mylar.tasks.core.TaskRepository;
24
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
25
import org.eclipse.ui.IWorkbenchPage;
26
import org.eclipse.ui.PlatformUI;
27
28
public class DuplicateDetetionTest extends TestCase {
29
30
	private TaskRepository repository;
31
32
	@Override
33
	protected void setUp() throws Exception {
34
		super.setUp();
35
		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
36
37
	}
38
39
	public void testDuplicateDetection() throws Exception {
40
41
		String stackTrace = "java.lang.NullPointerException\nat jeff.testing.stack.trace.functionality(jeff.java:481)";
42
43
		NewBugzillaReport model = new NewBugzillaReport(repository.getUrl(), TasksUiPlugin.getDefault()
44
				.getOfflineReportsFile().getNextOfflineBugId());
45
		model.setNewComment(stackTrace);
46
		model.setHasLocalChanges(true);
47
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
48
		NewBugEditorInput input = new NewBugEditorInput(repository, model);
49
		TaskUiUtil.openEditor(input, BugzillaUiPlugin.NEW_BUG_EDITOR_ID, page);
50
51
		NewBugEditor editor = (NewBugEditor) page.getActiveEditor();
52
		assertTrue(editor.searchForDuplicates());
53
54
		editor.changeDirtyStatus(false);
55
		editor.close();
56
	}
57
58
	public void testNoStackTrace() throws Exception {
59
		String fakeStackTrace = "this is not really a stacktrace";
60
		NewBugzillaReport model = new NewBugzillaReport(repository.getUrl(), TasksUiPlugin.getDefault()
61
				.getOfflineReportsFile().getNextOfflineBugId());
62
		model.setNewComment(fakeStackTrace);
63
		model.setHasLocalChanges(true);
64
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
65
		NewBugEditorInput input = new NewBugEditorInput(repository, model);
66
		TaskUiUtil.openEditor(input, BugzillaUiPlugin.NEW_BUG_EDITOR_ID, page);
67
68
		NewBugEditor editor = (NewBugEditor) page.getActiveEditor();
69
		assertNull(editor.getStackTraceFromDescription());
70
71
		editor.changeDirtyStatus(false);
72
		editor.close();
73
	}
74
}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/NewBugEditor.java (-10 / +39 lines)
Lines 15-20 Link Here
15
import java.net.URLEncoder;
15
import java.net.URLEncoder;
16
import java.util.Calendar;
16
import java.util.Calendar;
17
import java.util.GregorianCalendar;
17
import java.util.GregorianCalendar;
18
import java.util.StringTokenizer;
18
19
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
21
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
Lines 186-203 Link Here
186
		return taskData.getLabel();
187
		return taskData.getLabel();
187
	}
188
	}
188
189
189
	protected void searchForDuplicates() {
190
	public boolean searchForDuplicates() {
190
191
191
		String stackTrace = getStackTraceFromDescription();
192
		String stackTrace = getStackTraceFromDescription();
192
		if (stackTrace == null) {
193
		if (stackTrace == null) {
193
			MessageDialog.openWarning(null, "No Stack Trace Found", NO_STACK_MESSAGE);
194
			MessageDialog.openWarning(null, "No Stack Trace Found", NO_STACK_MESSAGE);
194
			return;
195
			return false;
195
		}
196
		}
196
197
197
		String queryUrl = "";
198
		String queryUrl = "";
198
		try {
199
		try {
199
			queryUrl = repository.getUrl() + "/buglist.cgi?long_desc_type=allwordssubstr&long_desc="
200
			queryUrl = repository.getUrl() + "/buglist.cgi?long_desc_type=allwordssubstr&long_desc="
200
					+ URLEncoder.encode("Stack Trace:\n" + stackTrace, BugzillaPlugin.ENCODING_UTF_8);
201
					+ URLEncoder.encode(stackTrace, BugzillaPlugin.ENCODING_UTF_8);
201
		} catch (UnsupportedEncodingException e) {
202
		} catch (UnsupportedEncodingException e) {
202
			// This should never happen
203
			// This should never happen
203
		}
204
		}
Lines 210-228 Link Here
210
		BugzillaSearchQuery query = new BugzillaSearchQuery(operation);
211
		BugzillaSearchQuery query = new BugzillaSearchQuery(operation);
211
212
212
		NewSearchUI.runQueryInBackground(query);
213
		NewSearchUI.runQueryInBackground(query);
214
		return true;
213
	}
215
	}
214
216
215
	private String getStackTraceFromDescription() {
217
	public String getStackTraceFromDescription() {
216
		String description = newDescriptionTextViewer.getTextWidget().getText().trim();
218
		String description = newDescriptionTextViewer.getTextWidget().getText().trim();
217
		// TODO: improve stack trace detection
219
		String stackTrace = null;
218
		int index;
220
219
		String stackIdentifier = "Stack Trace:\n";
221
		if (description == null) {
220
		if (description == null || (index = description.indexOf(stackIdentifier)) < 0) {
221
			return null;
222
			return null;
222
		}
223
		}
223
224
224
		description = description.substring(index + stackIdentifier.length());
225
		// Temporary stack trace identifying until a better regex based method
225
		return description;
226
		// can be implemented
227
		// Find a sequence of lines containing "at " and ".java" as well as the
228
		// line that precedes the sequence
229
		StringTokenizer tok = new StringTokenizer(description, "\n");
230
		StringBuffer stackBuffer = new StringBuffer();
231
		String prevLine = "";
232
		boolean hit = false;
233
		while (tok.hasMoreTokens() && stackBuffer.length() == 0) {
234
			String line = tok.nextToken().trim();
235
			while (line.indexOf("at ") < 0 && line.indexOf(".java:") < 0 && tok.hasMoreTokens()) {
236
				prevLine = line;
237
				line = tok.nextToken();
238
				hit = true;
239
			}
240
241
			if (!hit) {
242
				return null;
243
			}
244
			stackBuffer.append(prevLine + "\n" + line + "\n");
245
			while (line.indexOf(".java:") > 0 && line.indexOf("at ") == 0 && tok.hasMoreTokens()) {
246
				line = tok.nextToken();
247
				stackBuffer.append(line + "\n");
248
			}
249
		}
250
		if (stackBuffer.length() > 0) {
251
			stackTrace = stackBuffer.toString();
252
		}
253
254
		return stackTrace;
226
	}
255
	}
227
256
228
	@Override
257
	@Override

Return to bug 143567