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

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/sandbox/web/WebQueryWizardPage.java (-65 / +27 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.runtime.MultiStatus;
16
import org.eclipse.core.runtime.MultiStatus;
17
import org.eclipse.core.runtime.Status;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.jface.bindings.keys.KeyStroke;
20
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
21
import org.eclipse.jface.fieldassist.IContentProposal;
22
import org.eclipse.jface.fieldassist.IContentProposalProvider;
23
import org.eclipse.jface.fieldassist.TextContentAdapter;
24
import org.eclipse.jface.wizard.WizardPage;
19
import org.eclipse.jface.wizard.WizardPage;
25
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
20
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
26
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
21
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
Lines 32-40 Link Here
32
import org.eclipse.swt.events.ModifyListener;
27
import org.eclipse.swt.events.ModifyListener;
33
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionAdapter;
34
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.events.SelectionEvent;
30
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.layout.GridData;
31
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridLayout;
32
import org.eclipse.swt.layout.GridLayout;
37
import org.eclipse.swt.widgets.Button;
33
import org.eclipse.swt.widgets.Button;
34
import org.eclipse.swt.widgets.Combo;
38
import org.eclipse.swt.widgets.Composite;
35
import org.eclipse.swt.widgets.Composite;
39
import org.eclipse.swt.widgets.Display;
36
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.Label;
Lines 44-65 Link Here
44
import org.eclipse.swt.widgets.Text;
41
import org.eclipse.swt.widgets.Text;
45
42
46
/**
43
/**
47
 * 
44
 * Wizard page for configuring and preview web query
48
 * Subclipse (IssueZilla)
49
 *   url: http://subclipse.tigris.org/issues/buglist.cgi?issue_status=NEW;issue_status=STARTED;issue_status=REOPENED&order=issues.issue_id
50
 *   regexp: <a href="show_bug.cgi\?id\=(.+?)">.+?<span class="summary">(.+?)</span>
51
 *   task prefix: http://subclipse.tigris.org/issues/show_bug.cgi?id=
52
 * 
53
 * ASM (GForge)
54
 *   url: http://forge.objectweb.org/tracker/?group_id=23&atid=350023
55
 *   regexp: <a class="tracker" href="/tracker/index.php\?func=detail&aid=(.+?)&group_id=23&atid=350023">(.+?)</a></td>
56
 *   task prefix: http://forge.objectweb.org/tracker/index.php?func=detail&group_id=23&atid=350023&aid=
57
 * 
45
 * 
58
 * @author Eugene Kuleshov
46
 * @author Eugene Kuleshov
59
 */
47
 */
60
public class WebQueryWizardPage extends WizardPage {
48
public class WebQueryWizardPage extends WizardPage {
61
	private Text taskPrefixText;
49
	private Text taskPrefixText;
62
	private Text descriptionText;
50
	private Combo descriptionText;
63
	private Text queryUrlText;
51
	private Text queryUrlText;
64
	private Text regexpText;
52
	private Text regexpText;
65
	private Table previewTable;
53
	private Table previewTable;
Lines 96-103 Link Here
96
		descriptionLabel.setLayoutData(new GridData());
84
		descriptionLabel.setLayoutData(new GridData());
97
		descriptionLabel.setText("Description:");
85
		descriptionLabel.setText("Description:");
98
86
99
		descriptionText = new Text(composite, SWT.BORDER);
87
		descriptionText = new Combo(composite, SWT.NONE);
100
		descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
88
		descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
89
		descriptionText.addSelectionListener(new SelectionListener() {
90
91
				public void widgetDefaultSelected(SelectionEvent e) {
92
					// ignore
93
				}
94
	
95
				public void widgetSelected(SelectionEvent e) {
96
					WebRepositoryTemplate template = WebRepositoryConnector.getTemplate(descriptionText.getText());
97
					if(template!=null) {
98
						queryUrlText.setText(template.query);
99
						regexpText.setText(template.regexp);
100
						taskPrefixText.setText(template.prefix);
101
					}
102
				}
103
104
			});
105
		
106
		for (WebRepositoryTemplate template : WebRepositoryConnector.REPOSITORY_TEMPLATES) {
107
			descriptionText.add(template.label);
108
		}
109
		
101
		new Label(composite, SWT.NONE);
110
		new Label(composite, SWT.NONE);
102
111
103
		Label queryUrlLabel = new Label(composite, SWT.NONE);
112
		Label queryUrlLabel = new Label(composite, SWT.NONE);
Lines 129-137 Link Here
129
				}
138
				}
130
			});
139
			});
131
140
132
		new ContentProposalAdapter(regexpText, new TextContentAdapter(),
133
				new RegExpProposalProvider(), KeyStroke.getInstance(SWT.CTRL, ' '), null);
134
135
		Button preview = new Button(composite, SWT.NONE);
141
		Button preview = new Button(composite, SWT.NONE);
136
		preview.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, true));
142
		preview.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, true));
137
		preview.setText("Preview");
143
		preview.setText("Preview");
Lines 170-176 Link Here
170
			regexpText.setText(query.getRegexp());
176
			regexpText.setText(query.getRegexp());
171
			taskPrefixText.setText(query.getTaskPrefix());
177
			taskPrefixText.setText(query.getTaskPrefix());
172
		}
178
		}
173
		sashForm.setWeights(new int[] {141, 172 });
179
		sashForm.setWeights(new int[] {145, 107 });
174
	}
180
	}
175
181
176
	public AbstractRepositoryQuery getQuery() {
182
	public AbstractRepositoryQuery getQuery() {
Lines 277-326 Link Here
277
			return Status.OK_STATUS;
283
			return Status.OK_STATUS;
278
		}
284
		}
279
	}
285
	}
280
281
282
	/**
283
	 * Simple proposal provider for regexps  
284
	 */
285
	private static final class RegExpProposalProvider implements IContentProposalProvider {
286
		private static final String[] LABELS = {
287
				"IssueZilla",
288
				"GForge",
289
				"Trac",
290
				"Jira",
291
				"vBulletin"
292
			};
293
		private static final String[] PROPOSALS = {
294
				"<a href=\"show_bug.cgi\\?id\\=(.+?)\">.+?<span class=\"summary\">(.+?)</span>",
295
				"<a class=\"tracker\" href=\"/tracker/index.php\\?func=detail&aid=(.+?)&group_id=GROUP&atid=ATID\">(.+?)</a></td>",
296
				"<td class=\"summary\"><a title=\"View ticket\" href=\"/project/ticket/(.+?)\">(.+?)</a></td>",
297
				"<td class=\"nav summary\">\\s+?<a href=\"/browse/(.+?)\".+?>(.+?)</a>",
298
				"<a href=\"showthread.php\\?.+?t=(\\d+?)\" id=\"thread_title_\\1\">(.+?)</a>"
299
			};
300
301
		public IContentProposal[] getProposals(String contents, int position) {
302
			IContentProposal[] res = new IContentProposal[LABELS.length]; 
303
			for (int i = 0; i < LABELS.length; i++) {
304
				final String label = LABELS[i];
305
				final String content = PROPOSALS[i];
306
				res[i] = new IContentProposal() {
307
						public String getContent() {
308
							return content;
309
						}
310
						public int getCursorPosition() {
311
							return content.length();
312
						}
313
						public String getDescription() {
314
							return content;
315
						}
316
						public String getLabel() {
317
							return label;
318
						}
319
					};
320
			}
321
			return res;
322
		}
323
	}
324
	
286
	
325
}
287
}
326
288
(-)src/org/eclipse/mylar/internal/sandbox/web/WebRepositoryConnector.java (-1 / +58 lines)
Lines 59-64 Link Here
59
	
59
	
60
	public static final String PROPERTY_TASK_PREFIX_URL = "taskprefixurl";
60
	public static final String PROPERTY_TASK_PREFIX_URL = "taskprefixurl";
61
61
62
	public static WebRepositoryTemplate[] REPOSITORY_TEMPLATES = {
63
		new WebRepositoryTemplate(
64
			"Subclipse (IssueZilla)",
65
			"http://subclipse.tigris.org/issues/",
66
			"http://subclipse.tigris.org/issues/enter_bug.cgi?component=subclipse",
67
			"http://subclipse.tigris.org/issues/show_bug.cgi?id=",
68
			"http://subclipse.tigris.org/issues/buglist.cgi?issue_status=NEW&issue_status=STARTED&issue_status=REOPENED&order=Issue+Number",
69
			"<a href=\"show_bug.cgi\\?id\\=(.+?)\">.+?<span class=\"summary\">(.+?)</span>"),
70
		new WebRepositoryTemplate(
71
			"GlasFish (IssueZilla)",
72
			"https://glassfish.dev.java.net/servlets/ProjectIssues",
73
			"https://glassfish.dev.java.net/issues/enter_bug.cgi?issue_type=DEFECT",
74
			"https://glassfish.dev.java.net/issues/show_bug.cgi?id=",
75
			"https://glassfish.dev.java.net/issues/buglist.cgi?component=glassfish&issue_status=NEW&issue_status=STARTED&issue_status=REOPENED&order=Issue+Number",
76
			"<a href=\"show_bug.cgi\\?id\\=(.+?)\">.+?<span class=\"summary\">(.+?)</span>"),
77
		new WebRepositoryTemplate("Spring Framework (Jira)", 
78
			"http://opensource.atlassian.com/projects/spring/browse/SPR",
79
			"http://opensource.atlassian.com/projects/spring/secure/CreateIssue!default.jspa",
80
			"http://opensource.atlassian.com/projects/spring/browse/",
81
			"http://opensource.atlassian.com/projects/spring/secure/IssueNavigator.jspa?reset=true&mode=hide&pid=10000&resolution=-1&sorter/field=updated&sorter/order=DESC",
82
			"<td class=\"nav summary\">\\s+?<a href=\"/projects/spring/browse/(.+?)\".+?>(.+?)</a>"),
83
		new WebRepositoryTemplate("SpringIDE (Trac)",
84
			"http://springide.org/project/",
85
			"http://springide.org/project/newticket",
86
			"http://springide.org/project/ticket/", 
87
			"http://springide.org/project/query?status=new&status=assigned&status=reopened&order=id",
88
			"<td class=\"summary\"><a href=\"/project/ticket/(.+?)\" title=\"View ticket\">(.+?)</a></td>"), 
89
		new WebRepositoryTemplate("edgewall.org (Trac)",
90
			"http://trac.edgewall.org/",
91
			"http://trac.edgewall.org/newticket",
92
			"http://trac.edgewall.org/ticket/",
93
			"http://trac.edgewall.org/query?status=new&status=assigned&status=reopened&order=id",
94
			"<td class=\"summary\"><a href=\"/ticket/(.+?)\" title=\"View ticket\">(.+?)</a></td>"),
95
		new WebRepositoryTemplate("ASM (GForge)", 
96
			"http://forge.objectweb.org/tracker/?atid=100023&group_id=23",
97
			"http://forge.objectweb.org/tracker/?func=add&group_id=23&atid=100023",
98
			"http://forge.objectweb.org/tracker/index.php?func=detail&group_id=23&atid=100023&aid=",
99
			"http://forge.objectweb.org/tracker/?atid=100023&group_id=23",
100
			"<a class=\"tracker\" href=\"/tracker/index.php\\?func=detail&aid=(.+?)&group_id=23&atid=100023\">(.+?)</a></td>"),
101
		new WebRepositoryTemplate("Azureus (SourceForge)", 
102
			"http://sourceforge.net/tracker/?atid=575154&group_id=84122",
103
			"http://sourceforge.net/tracker/?func=add&group_id=84122&atid=575154",
104
			"http://sourceforge.net/tracker/index.php?func=detail&group_id=84122&atid=575154&aid=",
105
			"http://sourceforge.net/tracker/?atid=575154&group_id=84122",
106
		    "<a href=\"/tracker/index.php\\?func=detail&amp;aid=(.+?)&amp;group_id=84122&amp;atid=575154\">(.+?)</a>"),
107
	};
108
	
62
	
109
	
63
	public String getRepositoryType() {
110
	public String getRepositoryType() {
64
		return REPOSITORY_TYPE;
111
		return REPOSITORY_TYPE;
Lines 221-227 Link Here
221
268
222
		if(!matcher.find()) {
269
		if(!matcher.find()) {
223
			queryStatus.add(new Status(IStatus.ERROR, MylarTaskListPlugin.PLUGIN_ID, IStatus.ERROR,
270
			queryStatus.add(new Status(IStatus.ERROR, MylarTaskListPlugin.PLUGIN_ID, IStatus.ERROR,
224
					"Unable to parse fetched resource. Check query regexp", null));
271
					"Unable to parse resource. Check query regexp", null));
225
		} else {
272
		} else {
226
			boolean isCorrect = true;
273
			boolean isCorrect = true;
227
	    	do {
274
	    	do {
Lines 246-251 Link Here
246
		return hits;
293
		return hits;
247
	}
294
	}
248
295
296
	// TODO use commons http client
249
	public static StringBuffer fetchResource(String url) throws IOException {
297
	public static StringBuffer fetchResource(String url) throws IOException {
250
		URL u = new URL(url);
298
		URL u = new URL(url);
251
		InputStream is = null;
299
		InputStream is = null;
Lines 282-286 Link Here
282
		}
330
		}
283
		
331
		
284
	}
332
	}
333
334
	public static WebRepositoryTemplate getTemplate(String label) {
335
		for (WebRepositoryTemplate template : REPOSITORY_TEMPLATES) {
336
			if(label.equals(template.label)) {
337
				return template;
338
			}
339
		}
340
		return null;
341
	}
285
}
342
}
286
343
(-)src/org/eclipse/mylar/internal/sandbox/web/WebRepositorySettingsPage.java (-7 / +30 lines)
Lines 11-25 Link Here
11
11
12
package org.eclipse.mylar.internal.sandbox.web;
12
package org.eclipse.mylar.internal.sandbox.web;
13
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.jface.preference.StringFieldEditor;
14
import org.eclipse.jface.preference.StringFieldEditor;
18
import org.eclipse.jface.util.IPropertyChangeListener;
15
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
16
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
17
import org.eclipse.mylar.internal.tasklist.ui.wizards.AbstractRepositorySettingsPage;
21
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
18
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryConnector;
22
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
19
import org.eclipse.mylar.provisional.tasklist.TaskRepository;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.events.SelectionListener;
23
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Composite;
24
23
25
/**
24
/**
Lines 39-45 Link Here
39
		super(TITLE, DESCRIPTION, connector);
38
		super(TITLE, DESCRIPTION, connector);
40
	}
39
	}
41
40
41
	@Override
42
	protected void createAdditionalControls(Composite parent) {
42
	protected void createAdditionalControls(Composite parent) {
43
		for (WebRepositoryTemplate template : WebRepositoryConnector.REPOSITORY_TEMPLATES) {
44
			if(repositoryLabelCombo.indexOf(template.label)==-1) { 
45
				repositoryLabelCombo.add(template.label);
46
			}
47
		}
48
		
49
		repositoryLabelCombo.addSelectionListener(new SelectionListener() {
50
51
				public void widgetSelected(SelectionEvent e) {
52
					WebRepositoryTemplate template = WebRepositoryConnector.getTemplate(repositoryLabelCombo.getText());
53
					if(template!=null) {
54
						serverUrlEditor.setStringValue(template.url);
55
						taskPrefixUrlEditor.setStringValue(template.prefix);
56
						newTaskUrlEditor.setStringValue(template.newTask);
57
					}
58
				}
59
60
				public void widgetDefaultSelected(SelectionEvent e) {
61
					// ignore
62
				}
63
				
64
			});
65
		
43
		taskPrefixUrlEditor = new StringFieldEditor("taskPrefixUrl", "Task prefix URL:", StringFieldEditor.UNLIMITED, parent);
66
		taskPrefixUrlEditor = new StringFieldEditor("taskPrefixUrl", "Task prefix URL:", StringFieldEditor.UNLIMITED, parent);
44
		taskPrefixUrlEditor.setPropertyChangeListener(this);
67
		taskPrefixUrlEditor.setPropertyChangeListener(this);
45
		
68
		
Lines 72-81 Link Here
72
95
73
	@Override
96
	@Override
74
	public TaskRepository createTaskRepository() {
97
	public TaskRepository createTaskRepository() {
75
		Map<String, String> properties = new HashMap<String, String>();
98
		TaskRepository repository = super.createTaskRepository();
76
		properties.put(WebRepositoryConnector.PROPERTY_TASK_PREFIX_URL, taskPrefixUrlEditor.getStringValue()); 
99
		repository.setProperty(WebRepositoryConnector.PROPERTY_TASK_PREFIX_URL, taskPrefixUrlEditor.getStringValue()); 
77
		properties.put(WebRepositoryConnector.PROPERTY_NEW_TASK_URL, newTaskUrlEditor.getStringValue());
100
		repository.setProperty(WebRepositoryConnector.PROPERTY_NEW_TASK_URL, newTaskUrlEditor.getStringValue()); 
78
		return new TaskRepository(getConnector().getRepositoryType(), getServerUrl(), properties);
101
		return repository;
79
	}
102
	}
80
	
103
	
81
}
104
}
(-)src/org/eclipse/mylar/internal/sandbox/web/WebRepositoryConnectorTest.java (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 - 2006 Mylar eclipse.org project 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
 *     Mylar project committers - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.sandbox.web;
13
14
import java.util.Arrays;
15
import java.util.List;
16
17
import junit.extensions.ActiveTestSuite;
18
import junit.framework.TestCase;
19
import junit.framework.TestSuite;
20
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.IStatus;
23
import org.eclipse.core.runtime.MultiStatus;
24
import org.eclipse.core.runtime.NullProgressMonitor;
25
import org.eclipse.mylar.provisional.tasklist.AbstractQueryHit;
26
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
27
28
/**
29
 * @author Eugene Kuleshov 
30
 */
31
public class WebRepositoryConnectorTest extends TestCase {
32
33
	private final WebRepositoryTemplate template;
34
35
	
36
	public WebRepositoryConnectorTest(WebRepositoryTemplate template) {
37
		super("testRepositoryTemplate");
38
		this.template = template;
39
	}
40
41
	public void testRepositoryTemplate() throws Exception {
42
		StringBuffer buffer = WebRepositoryConnector.fetchResource(template.query);
43
		
44
		IProgressMonitor monitor = new NullProgressMonitor();
45
		MultiStatus queryStatus = new MultiStatus(MylarTaskListPlugin.PLUGIN_ID, IStatus.OK, "Query result", null);
46
		
47
		List<AbstractQueryHit> hits = WebRepositoryConnector.performQuery(buffer, template.regexp, template.prefix, template.url, monitor, queryStatus);
48
		
49
		assertTrue(Arrays.asList(queryStatus.getChildren()).toString(), queryStatus.isOK());
50
		assertTrue("Expected non-empty query result", hits.size()>0);
51
		
52
	}
53
54
	public String getName() {
55
		return template.label;
56
	}
57
	
58
	public static TestSuite suite() {
59
		TestSuite suite = new ActiveTestSuite(WebRepositoryConnectorTest.class.getName());
60
		// TestSuite suite = new TestSuite(WebRepositoryConnectorTest.class.getName());
61
		
62
		for (WebRepositoryTemplate template : WebRepositoryConnector.REPOSITORY_TEMPLATES) {
63
			suite.addTest(new WebRepositoryConnectorTest(template));
64
		}
65
		
66
		
67
		return suite;
68
	}
69
70
}
(-)src/org/eclipse/mylar/internal/sandbox/web/WebRepositoryTemplate.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar committers 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
9
package org.eclipse.mylar.internal.sandbox.web;
10
11
class WebRepositoryTemplate {
12
	public final String label;
13
	public final String url;
14
	public final String newTask;
15
	public final String prefix;
16
	public final String query;
17
	public final String regexp;
18
19
	public WebRepositoryTemplate(String label, String url, String newTask, String prefix, String query, String regexp) {
20
		this.label = label;
21
		this.url = url;
22
		this.newTask = newTask;
23
		this.prefix = prefix;
24
		this.query = query;
25
		this.regexp = regexp;
26
	}
27
	
28
}

Return to bug 145123