Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2006-11-01 01:33:04 +0000
committerrelves2006-11-01 01:33:04 +0000
commitdc841c630afff6eea9fa48a58143d396d272fead (patch)
tree08ea931884873a5c3cab941da3342efdd2e6e0d7
parent73c53ca524c7b66c4a719271f75428656ad910d6 (diff)
downloadorg.eclipse.mylyn.tasks-dc841c630afff6eea9fa48a58143d396d272fead.tar.gz
org.eclipse.mylyn.tasks-dc841c630afff6eea9fa48a58143d396d272fead.tar.xz
org.eclipse.mylyn.tasks-dc841c630afff6eea9fa48a58143d396d272fead.zip
NEW - bug 161443: Improve support for sites protected by http authentication
https://bugs.eclipse.org/bugs/show_bug.cgi?id=161443
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java233
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentHandler.java499
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java991
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java61
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java63
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java58
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java234
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportElement.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java485
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java527
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java717
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTask.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java18
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java15
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryReportFactory.java20
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java32
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java7
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaConfigurationTest.java38
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaProductParserTest.java40
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java51
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchDialogTest.java2
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskTest.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/EncodingTest.java11
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryEditorWizardTest.java68
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryReportFactoryTest.java234
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java108
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaUiPlugin.java5
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugSubmissionHandler.java61
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java5
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java79
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositoryUi.java4
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java7
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java19
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java186
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java32
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java7
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java22
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java2
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java4
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotification.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/OpenRemoteTaskJob.java7
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationIncoming.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationQueryIncoming.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationReminder.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractRepositoryTaskEditor.java136
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryAttachmentEditorInput.java47
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java2
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractRepositorySettingsPage.java132
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java6
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/RepositorySynchronizationManager.java1
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeTaskJob.java5
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java13
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java2
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java3
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java2
65 files changed, 3393 insertions, 1963 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
index 473db55d3..021c3b918 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
@@ -13,19 +13,14 @@ package org.eclipse.mylar.internal.bugzilla.core;
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URL;
import java.security.GeneralSecurityException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
import javax.security.auth.login.LoginException;
-import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
+import org.xml.sax.EntityResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -39,106 +34,158 @@ import org.xml.sax.helpers.XMLReaderFactory;
*/
public class AbstractReportFactory {
- private static final String CONTENT_TYPE_TEXT_HTML = "text/html";
-
- private static final String CONTENT_TYPE_APP_RDF_XML = "application/rdf+xml";
+// private static final String CONTENT_TYPE_TEXT_HTML = "text/html";
+//
+// private static final String CONTENT_TYPE_APP_RDF_XML = "application/rdf+xml";
+//
+// private static final String CONTENT_TYPE_APP_XML = "application/xml";
+//
+// private static final String CONTENT_TYPE_APP_XCGI = "application/x-cgi";
+//
+// private static final String CONTENT_TYPE_TEXT_XML = "text/xml";
+//
+// private static final String[] VALID_CONFIG_CONTENT_TYPES = { CONTENT_TYPE_APP_RDF_XML, CONTENT_TYPE_APP_XML,
+// CONTENT_TYPE_TEXT_XML };
+//
+// private static final List<String> VALID_TYPES = Arrays.asList(VALID_CONFIG_CONTENT_TYPES);
- private static final String CONTENT_TYPE_APP_XML = "application/xml";
-
- private static final String CONTENT_TYPE_APP_XCGI = "application/x-cgi";
+ public static final int RETURN_ALL_HITS = -1;
- private static final String CONTENT_TYPE_TEXT_XML = "text/xml";
+ private InputStream inStream;
- private static final String[] VALID_CONFIG_CONTENT_TYPES = {CONTENT_TYPE_APP_RDF_XML, CONTENT_TYPE_APP_XML, CONTENT_TYPE_TEXT_XML};
-
- private static final List<String> VALID_TYPES = Arrays.asList(VALID_CONFIG_CONTENT_TYPES);
-
- public static final int RETURN_ALL_HITS = -1;
+ private String characterEncoding;
+
+ public AbstractReportFactory(InputStream inStream, String encoding) {
+ this.inStream = inStream;
+ this.characterEncoding = encoding;
+ }
+
+ /**
+ * expects rdf returned from repository (ctype=rdf in url)
+ *
+ * @throws GeneralSecurityException
+ */
+ protected void collectResults(DefaultHandler contentHandler, boolean clean) throws IOException, BugzillaException,
+ GeneralSecurityException {
+
+ // HttpURLConnection connection = null;
+ // try {
+ // connection = WebClientUtil.openUrlConnection(url, proxySettings,
+ // false, null, null);
+ //
+ // int responseCode = connection.getResponseCode();
+ //
+ // if (responseCode != HttpURLConnection.HTTP_OK) {
+ // String msg;
+ // if (responseCode == -1 || responseCode ==
+ // HttpURLConnection.HTTP_FORBIDDEN)
+ // msg = "Repository does not seem to be a valid Bugzilla server: " +
+ // url.toExternalForm();
+ // else
+ // msg = "HTTP Error " + responseCode + " (" +
+ // connection.getResponseMessage()
+ // + ") while querying Bugzilla server: " + url.toExternalForm();
+ //
+ // throw new IOException(msg);
+ // }
+ //
+ // BufferedReader in = null;
+ //
+ // String contentEncoding = connection.getContentEncoding();
+ // boolean gzipped = contentEncoding != null &&
+ // WebClientUtil.ENCODING_GZIP.equals(contentEncoding);
+ // if (characterEncoding != null) {
+ // if (gzipped) {
+ // in = new BufferedReader(new InputStreamReader(new
+ // GZIPInputStream(connection.getInputStream()),
+ // characterEncoding));
+ // } else {
+ // in = new BufferedReader(new
+ // InputStreamReader(connection.getInputStream(), characterEncoding));
+ // }
+ // } else {
+ // if (gzipped) {
+ // in = new BufferedReader(new InputStreamReader(new
+ // GZIPInputStream(connection.getInputStream())));
+ // } else {
+ // in = new BufferedReader(new
+ // InputStreamReader(connection.getInputStream()));
+ // }
+ // }
+
+ BufferedReader in;
+ if (characterEncoding != null) {
+ in = new BufferedReader(new InputStreamReader(inStream, characterEncoding));
+ } else {
+ in = new BufferedReader(new InputStreamReader(inStream));
+ }
+ // String line = in.readLine();
+ // while(line != null) {
+ // System.err.println(line);
+ // line = in.readLine();
+ // }
+ if (in != null && clean) {
+ StringBuffer result = XmlCleaner.clean(in);
+ StringReader strReader = new StringReader(result.toString());
+ in = new BufferedReader(strReader);
+ }
+
+ // if (VALID_TYPES.contains(connection.getContentType().toLowerCase()))
+ // {
- /** expects rdf returned from repository (ctype=rdf in url)
- * @throws GeneralSecurityException */
- protected void collectResults(URL url, Proxy proxySettings, String characterEncoding,
- DefaultHandler contentHandler, boolean clean) throws IOException, BugzillaException, GeneralSecurityException {
-
- HttpURLConnection connection = null;
try {
- connection = WebClientUtil.openUrlConnection(url, proxySettings, false);
+ final XMLReader reader = XMLReaderFactory.createXMLReader();
+ reader.setContentHandler(contentHandler);
- int responseCode = connection.getResponseCode();
+ EntityResolver resolver = new EntityResolver() {
+
+ public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+ // The default resolver will try to resolve the dtd via URLConnection. We would need to implement
+ // via httpclient to handle authorization properly. Since we don't have need of entity resolving
+ // currently, we just supply a dummy (empty) resource for each request...
+ InputSource source = new InputSource();
+ source.setCharacterStream(new StringReader(""));
+ return source;
+ }};
- if (responseCode != HttpURLConnection.HTTP_OK) {
- String msg;
- if (responseCode == -1 || responseCode == HttpURLConnection.HTTP_FORBIDDEN)
- msg = "Repository does not seem to be a valid Bugzilla server: " + url.toExternalForm();
- else
- msg = "HTTP Error " + responseCode + " (" + connection.getResponseMessage()
- + ") while querying Bugzilla server: " + url.toExternalForm();
-
- throw new IOException(msg);
- }
-
- BufferedReader in = null;
+ reader.setEntityResolver(resolver);
+ reader.setErrorHandler(new ErrorHandler() {
- String contentEncoding = connection.getContentEncoding();
- boolean gzipped = contentEncoding != null && WebClientUtil.ENCODING_GZIP.equals(contentEncoding);
- if (characterEncoding != null) {
- if (gzipped) {
- in = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream()),
- characterEncoding));
- } else {
- in = new BufferedReader(new InputStreamReader(connection.getInputStream(), characterEncoding));
- }
- } else {
- if (gzipped) {
- in = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream())));
- } else {
- in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ public void error(SAXParseException exception) throws SAXException {
+ throw exception;
}
- }
- if (clean) {
- StringBuffer result = XmlCleaner.clean(in);
- StringReader strReader = new StringReader(result.toString());
- in = new BufferedReader(strReader);
- }
+ public void fatalError(SAXParseException exception) throws SAXException {
+ throw exception;
+ }
- if (VALID_TYPES.contains(connection.getContentType().toLowerCase())) {
- try {
- final XMLReader reader = XMLReaderFactory.createXMLReader();
- reader.setContentHandler(contentHandler);
- reader.setErrorHandler(new ErrorHandler() {
-
- public void error(SAXParseException exception) throws SAXException {
- throw exception;
- }
-
- public void fatalError(SAXParseException exception) throws SAXException {
- throw exception;
- }
-
- public void warning(SAXParseException exception) throws SAXException {
- throw exception;
- }
- });
- reader.parse(new InputSource(in));
- } catch (SAXException e) {
- if (e.getMessage().equals(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD)) {
- throw new LoginException(e.getMessage());
- } else {
- throw new IOException(e.getMessage());
- }
+ public void warning(SAXParseException exception) throws SAXException {
+ throw exception;
}
- } else if (connection.getContentType().contains(CONTENT_TYPE_TEXT_HTML)) {
- BugzillaServerFacade.parseHtmlError(in);
- } else if (connection.getContentType().toLowerCase().contains(CONTENT_TYPE_APP_XCGI)) {
- // ignore
+ });
+ reader.parse(new InputSource(in));
+ } catch (SAXException e) {
+ if (e.getMessage().equals(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD)) {
+ throw new LoginException(e.getMessage());
} else {
- throw new IOException("Unrecognized content type: " + connection.getContentType());
- }
- } finally {
- if (connection != null) {
- connection.disconnect();
+ throw new IOException(e.getMessage());
}
}
+ // } else if
+ // (connection.getContentType().contains(CONTENT_TYPE_TEXT_HTML)) {
+ // BugzillaClient.parseHtmlError(in);
+ // } else if
+ // (connection.getContentType().toLowerCase().contains(CONTENT_TYPE_APP_XCGI))
+ // {
+ // // ignore
+ // } else {
+ // throw new IOException("Unrecognized content type: " +
+ // connection.getContentType());
+ // }
+ // } finally {
+ // if (connection != null) {
+ // connection.disconnect();
+ // }
+ // }
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentHandler.java
index aa77ae2e5..402967e03 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentHandler.java
@@ -11,42 +11,22 @@
package org.eclipse.mylar.internal.bugzilla.core;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Proxy;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.GeneralSecurityException;
-import java.util.ArrayList;
-import java.util.List;
import javax.security.auth.login.LoginException;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.multipart.FilePart;
-import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
-import org.apache.commons.httpclient.methods.multipart.Part;
-import org.apache.commons.httpclient.methods.multipart.PartBase;
-import org.apache.commons.httpclient.methods.multipart.StringPart;
-import org.apache.commons.httpclient.params.HttpMethodParams;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException;
-import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.IAttachmentHandler;
-import org.eclipse.mylar.tasks.core.LocalAttachment;
import org.eclipse.mylar.tasks.core.RepositoryAttachment;
+import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.TaskRepository;
/**
@@ -55,217 +35,245 @@ import org.eclipse.mylar.tasks.core.TaskRepository;
*/
public class BugzillaAttachmentHandler implements IAttachmentHandler {
- private static final int CONNECT_TIMEOUT = 5000;
-
- private static final String CHANGES_SUBMITTED = "Changes Submitted";
-
- public static final String POST_ARGS_ATTACHMENT_DOWNLOAD = "/attachment.cgi?id=";
-
- public static final String POST_ARGS_ATTACHMENT_UPLOAD = "/attachment.cgi";// ?action=insert";//&bugid=";
-
- private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual";
-
- private static final String VALUE_ISPATCH = "1";
-
- private static final String VALUE_ACTION_INSERT = "insert";
-
- private static final String ATTRIBUTE_CONTENTTYPEENTRY = "contenttypeentry";
-
- private static final String ATTRIBUTE_CONTENTTYPEMETHOD = "contenttypemethod";
-
- private static final String ATTRIBUTE_ISPATCH = "ispatch";
-
- private static final String ATTRIBUTE_DATA = "data";
-
- private static final String ATTRIBUTE_COMMENT = "comment";
-
- private static final String ATTRIBUTE_DESCRIPTION = "description";
-
- private static final String ATTRIBUTE_BUGID = "bugid";
-
- private static final String ATTRIBUTE_BUGZILLA_PASSWORD = "Bugzilla_password";
-
- private static final String ATTRIBUTE_BUGZILLA_LOGIN = "Bugzilla_login";
+ // private static final String CHANGES_SUBMITTED = "Changes Submitted";
+
+ // public static final String POST_ARGS_ATTACHMENT_DOWNLOAD =
+ // "/attachment.cgi?id=";
+ //
+ // public static final String POST_ARGS_ATTACHMENT_UPLOAD =
+ // "/attachment.cgi";// ?action=insert";//&bugid=";
+
+ // private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual";
+ //
+ // private static final String VALUE_ISPATCH = "1";
+ //
+ // private static final String VALUE_ACTION_INSERT = "insert";
+ //
+ // private static final String ATTRIBUTE_CONTENTTYPEENTRY =
+ // "contenttypeentry";
+ //
+ // private static final String ATTRIBUTE_CONTENTTYPEMETHOD =
+ // "contenttypemethod";
+ //
+ // private static final String ATTRIBUTE_ISPATCH = "ispatch";
+ //
+ // private static final String ATTRIBUTE_DATA = "data";
+ //
+ // private static final String ATTRIBUTE_COMMENT = "comment";
+ //
+ // private static final String ATTRIBUTE_DESCRIPTION = "description";
+ //
+ // private static final String ATTRIBUTE_BUGID = "bugid";
+ //
+ // private static final String ATTRIBUTE_BUGZILLA_PASSWORD =
+ // "Bugzilla_password";
+ //
+ // private static final String ATTRIBUTE_BUGZILLA_LOGIN = "Bugzilla_login";
+ //
+ // private static final String ATTRIBUTE_ACTION = "action";
+
+ private BugzillaRepositoryConnector connector;
+
+ public BugzillaAttachmentHandler(BugzillaRepositoryConnector connector) {
+ this.connector = connector;
+ }
- private static final String ATTRIBUTE_ACTION = "action";
+ public byte[] getAttachmentData(TaskRepository repository, String taskId) throws CoreException {
+ try {
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ byte[] data = client.getAttachmentData(taskId);
+ return data;
+ } catch (Exception e) {
+ throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
+ "Download of attachment "+taskId+" from " + repository.getUrl() + " failed.", e));
+ }
+ }
+
+// public InputStream getAttachmentInputStream(TaskRepository repository, String taskId) throws CoreException {
+// try {
+// BugzillaClient client = connector.getClientManager().getClient(repository);
+// return client.getAttachmentInputStream(taskId);
+// } catch (Exception e) {
+// throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
+// "Download of attachment "+taskId+" from " + repository.getUrl() + " failed.", e));
+// }
+// }
+
+ public void downloadAttachment(TaskRepository repository, String taskData, RepositoryAttachment attachment, File file) throws CoreException {
+ String filename = attachment.getAttributeValue(RepositoryTaskAttribute.ATTACHMENT_FILENAME);
+ if (filename == null) {
+ throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
+ "Attachment download from " + repository.getUrl() + " failed, missing attachment filename.",
+ null));
+ }
- public void downloadAttachment(TaskRepository repository, AbstractRepositoryTask task,
- RepositoryAttachment attachment, File file, Proxy proxySettings) throws CoreException {
try {
- downloadAttachment(repository.getUrl(), repository.getUserName(), repository.getPassword(), proxySettings,
- repository.getCharacterEncoding(), attachment.getId(), file, true);
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ byte[] data = client.getAttachmentData("" + attachment.getId());
+ writeData(file, data);
} catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0, "could not download", e));
+ throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
+ "Attachment download from " + repository.getUrl() + " failed.", e));
+ }
+ }
+
+ private void writeData(File file, byte[] data) throws IOException {
+ OutputStream out = new FileOutputStream(file);
+ try {
+ out.write(data);
+ } finally {
+ out.close();
}
}
public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment,
String description, File file, String contentType, boolean isPatch, Proxy proxySettings)
throws CoreException {
- // try {
- int bugId = Integer.parseInt(AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()));
- uploadAttachment(repository.getUrl(), repository.getUserName(), repository.getPassword(), bugId, comment,
- description, file, contentType, isPatch, proxySettings);
- // } catch (Exception e) {
- // throw new CoreException(new Status(IStatus.ERROR,
- // BugzillaCorePlugin.PLUGIN_ID, 0, "could not upload", e));
- // }
- }
-
- private boolean uploadAttachment(String repositoryUrl, String userName, String password, int bugReportID,
- String comment, String description, File sourceFile, String contentType, boolean isPatch,
- Proxy proxySettings) throws CoreException {
-
- // Note: The following debug code requires http commons-logging and
- // commons-logging-api jars
- // System.setProperty("org.apache.commons.logging.Log",
- // "org.apache.commons.logging.impl.SimpleLog");
- // System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
- // "true");
- // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
- // "debug");
- // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
- // "debug");
-
- boolean uploadResult = true;
-
- // Protocol.registerProtocol("https", new Protocol("https", new
- // TrustAllSslProtocolSocketFactory(), 443));
- HttpClient client = new HttpClient();
- WebClientUtil.setupHttpClient(client, proxySettings, repositoryUrl, userName, password);
- PostMethod postMethod = new PostMethod(WebClientUtil.getRequestPath(repositoryUrl)
- + POST_ARGS_ATTACHMENT_UPLOAD);
-
- // My understanding is that this option causes the client to first check
- // with the server to see if it will in fact recieve the post before
- // actually sending the contents.
- postMethod.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
-
try {
- List<PartBase> parts = new ArrayList<PartBase>();
- parts.add(new StringPart(ATTRIBUTE_ACTION, VALUE_ACTION_INSERT));
- parts.add(new StringPart(ATTRIBUTE_BUGZILLA_LOGIN, userName));
- parts.add(new StringPart(ATTRIBUTE_BUGZILLA_PASSWORD, password));
- parts.add(new StringPart(ATTRIBUTE_BUGID, String.valueOf(bugReportID)));
- parts.add(new StringPart(ATTRIBUTE_DESCRIPTION, description));
- parts.add(new StringPart(ATTRIBUTE_COMMENT, comment));
- parts.add(new FilePart(ATTRIBUTE_DATA, sourceFile));
-
- if (isPatch) {
- parts.add(new StringPart(ATTRIBUTE_ISPATCH, VALUE_ISPATCH));
- } else {
- parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEMETHOD, VALUE_CONTENTTYPEMETHOD_MANUAL));
- parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEENTRY, contentType));
- }
-
- postMethod.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[1]), postMethod.getParams()));
- postMethod.setDoAuthentication(true);
- client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT);
- int status = client.executeMethod(postMethod);
- if (status == HttpStatus.SC_OK) {
- InputStreamReader reader = new InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod
- .getResponseCharSet());
- BufferedReader bufferedReader = new BufferedReader(reader);
-
- BugzillaServerFacade.parseHtmlError(bufferedReader);
-
- } else {
- uploadResult = false;
- throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
- "Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status), null));
- }
-
+ String bugId = AbstractRepositoryTask.getTaskId(task.getHandleIdentifier());
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ client.uploadAttachment(bugId, comment, description, file, contentType, isPatch);
} catch (LoginException e) {
throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
"Your login name or password is incorrect. Ensure proper repository configuration.", e));
- } catch (UnrecognizedReponseException e) {
- if (e.getMessage().indexOf(CHANGES_SUBMITTED) > -1) {
- return true;
- }
+ } catch (UnrecognizedReponseException e) {
throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.INFO,
"Response from server", e));
} catch (IOException e) {
throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
"Check repository credentials and connectivity.", e));
-
+
} catch (BugzillaException e) {
String message = e.getMessage();
throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
"Bugzilla could not post your bug. \n\n" + message, e));
- } finally {
- postMethod.releaseConnection();
- }
-
- return uploadResult;
- }
-
- public boolean uploadAttachment(LocalAttachment attachment, String uname, String password, Proxy proxySettings)
- throws CoreException {
-
- File file = new File(attachment.getFilePath());
- if (!file.exists() || file.length() <= 0) {
- return false;
- }
-
- return uploadAttachment(attachment.getReport().getRepositoryUrl(), uname, password, Integer.parseInt(attachment
- .getReport().getId()), attachment.getComment(), attachment.getDescription(), file, attachment
- .getContentType(), attachment.isPatch(), proxySettings);
- }
-
- private boolean downloadAttachment(String repositoryUrl, String userName, String password, Proxy proxySettings,
- String encoding, int id, File destinationFile, boolean overwrite) throws IOException,
- GeneralSecurityException {
- BufferedInputStream in = null;
- FileOutputStream outStream = null;
- try {
- String url = repositoryUrl + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
- url = BugzillaServerFacade.addCredentials(url, encoding, userName, password);
- URL downloadUrl = new URL(url);
- URLConnection connection = WebClientUtil.openUrlConnection(downloadUrl, proxySettings, false);
- if (connection != null) {
- InputStream input = connection.getInputStream();
- outStream = new FileOutputStream(destinationFile);
- copyByteStream(input, outStream);
- return true;
-
- }
- } finally {
- try {
- if (in != null)
- in.close();
- if (outStream != null)
- outStream.close();
- } catch (IOException e) {
- BugzillaCorePlugin.log(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR,
- "Problem closing the stream", e));
- }
}
- return false;
+ // uploadAttachment(repository.getUrl(), repository.getUserName(),
+ // repository.getPassword(), bugId, comment,
+ // description, file, contentType, isPatch, proxySettings);
+ // } catch (Exception e) {
+ // throw new CoreException(new Status(IStatus.ERROR,
+ // BugzillaCorePlugin.PLUGIN_ID, 0, "could not upload", e));
+ // }
}
- private void copyByteStream(InputStream in, OutputStream out) throws IOException {
- if (in != null && out != null) {
- BufferedInputStream inBuffered = new BufferedInputStream(in);
-
- int bufferSize = 1000;
- byte[] buffer = new byte[bufferSize];
-
- int readCount;
-
- BufferedOutputStream fout = new BufferedOutputStream(out);
-
- while ((readCount = inBuffered.read(buffer)) != -1) {
- if (readCount < bufferSize) {
- fout.write(buffer, 0, readCount);
- } else {
- fout.write(buffer);
- }
- }
- fout.flush();
- fout.close();
- in.close();
- }
- }
+ // private boolean uploadAttachment(String repositoryUrl, String userName,
+ // String password, int bugReportID,
+ // String comment, String description, File sourceFile, String contentType,
+ // boolean isPatch,
+ // Proxy proxySettings) throws CoreException {
+ //
+ // // Note: The following debug code requires http commons-logging and
+ // // commons-logging-api jars
+ // // System.setProperty("org.apache.commons.logging.Log",
+ // // "org.apache.commons.logging.impl.SimpleLog");
+ // //
+ // System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
+ // // "true");
+ // //
+ // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
+ // // "debug");
+ // //
+ // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
+ // // "debug");
+ //
+ // boolean uploadResult = true;
+ //
+ // // Protocol.registerProtocol("https", new Protocol("https", new
+ // // TrustAllSslProtocolSocketFactory(), 443));
+ // HttpClient client = new HttpClient();
+ // WebClientUtil.setupHttpClient(client, proxySettings, repositoryUrl,
+ // userName, password);
+ // PostMethod postMethod = new
+ // PostMethod(WebClientUtil.getRequestPath(repositoryUrl)
+ // + POST_ARGS_ATTACHMENT_UPLOAD);
+ //
+ // // My understanding is that this option causes the client to first check
+ // // with the server to see if it will in fact recieve the post before
+ // // actually sending the contents.
+ // postMethod.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
+ // true);
+ //
+ // try {
+ // List<PartBase> parts = new ArrayList<PartBase>();
+ // parts.add(new StringPart(ATTRIBUTE_ACTION, VALUE_ACTION_INSERT));
+ // parts.add(new StringPart(ATTRIBUTE_BUGZILLA_LOGIN, userName));
+ // parts.add(new StringPart(ATTRIBUTE_BUGZILLA_PASSWORD, password));
+ // parts.add(new StringPart(ATTRIBUTE_BUGID, String.valueOf(bugReportID)));
+ // parts.add(new StringPart(ATTRIBUTE_DESCRIPTION, description));
+ // parts.add(new StringPart(ATTRIBUTE_COMMENT, comment));
+ // parts.add(new FilePart(ATTRIBUTE_DATA, sourceFile));
+ //
+ // if (isPatch) {
+ // parts.add(new StringPart(ATTRIBUTE_ISPATCH, VALUE_ISPATCH));
+ // } else {
+ // parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEMETHOD,
+ // VALUE_CONTENTTYPEMETHOD_MANUAL));
+ // parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEENTRY, contentType));
+ // }
+ //
+ // postMethod.setRequestEntity(new MultipartRequestEntity(parts.toArray(new
+ // Part[1]), postMethod.getParams()));
+ // postMethod.setDoAuthentication(true);
+ // client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT);
+ // int status = client.executeMethod(postMethod);
+ // if (status == HttpStatus.SC_OK) {
+ // InputStreamReader reader = new
+ // InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod
+ // .getResponseCharSet());
+ // BufferedReader bufferedReader = new BufferedReader(reader);
+ //
+ // BugzillaClient.parseHtmlError(bufferedReader);
+ //
+ // } else {
+ // uploadResult = false;
+ // throw new CoreException(new Status(Status.OK,
+ // BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
+ // "Communication error occurred during upload. \n\n" +
+ // HttpStatus.getStatusText(status), null));
+ // }
+ //
+ // } catch (LoginException e) {
+ // throw new CoreException(new Status(Status.OK,
+ // BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
+ // "Your login name or password is incorrect. Ensure proper repository
+ // configuration.", e));
+ // } catch (UnrecognizedReponseException e) {
+ // if (e.getMessage().indexOf(CHANGES_SUBMITTED) > -1) {
+ // return true;
+ // }
+ // throw new CoreException(new Status(Status.OK,
+ // BugzillaCorePlugin.PLUGIN_ID, Status.INFO,
+ // "Response from server", e));
+ // } catch (IOException e) {
+ // throw new CoreException(new Status(Status.OK,
+ // BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
+ // "Check repository credentials and connectivity.", e));
+ //
+ // } catch (BugzillaException e) {
+ // String message = e.getMessage();
+ // throw new CoreException(new Status(Status.OK,
+ // BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
+ // "Bugzilla could not post your bug. \n\n" + message, e));
+ // } finally {
+ // postMethod.releaseConnection();
+ // }
+ //
+ // return uploadResult;
+ // }
+
+// public boolean uploadAttachment(LocalAttachment attachment, String uname, String password, Proxy proxySettings)
+// throws CoreException {
+//
+// File file = new File(attachment.getFilePath());
+// if (!file.exists() || file.length() <= 0) {
+// return false;
+// }
+//
+// uploadAttachment(attachment.getReport().getRepositoryUrl(), uname, password, Integer.parseInt(attachment
+// .getReport().getId()), attachment.getComment(), attachment.getDescription(), file, attachment
+// .getContentType(), attachment.isPatch(), proxySettings);
+// }
public boolean canDownloadAttachment(TaskRepository repository, AbstractRepositoryTask task) {
return true;
@@ -283,3 +291,82 @@ public class BugzillaAttachmentHandler implements IAttachmentHandler {
// implement
}
}
+
+// public void downloadAttachment(TaskRepository repository,
+// AbstractRepositoryTask task,
+// RepositoryAttachment attachment, File file, Proxy proxySettings) throws
+// CoreException {
+// try {
+// BugzillaClient client =
+// BugzillaCorePlugin.getDefault().getConnector().getClientManager().getClient(repository);
+//
+// client.downloadAttachment(attachment.getId(), file, true);
+//
+// downloadAttachment(repository.getUrl(), repository.getUserName(),
+// repository.getPassword(), proxySettings,
+// repository.getCharacterEncoding(), attachment.getId(), file, true);
+// } catch (Exception e) {
+// throw new CoreException(new Status(IStatus.ERROR,
+// BugzillaCorePlugin.PLUGIN_ID, 0, "could not download", e));
+// }
+// }
+
+// private boolean downloadAttachment(String repositoryUrl, String userName,
+// String password, Proxy proxySettings,
+// String encoding, int id, File destinationFile, boolean overwrite) throws
+// IOException,
+// GeneralSecurityException {
+// BufferedInputStream in = null;
+// FileOutputStream outStream = null;
+// try {
+// String url = repositoryUrl + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
+// url = BugzillaClient.addCredentials(url, encoding, userName, password);
+// URL downloadUrl = new URL(url);
+// URLConnection connection = WebClientUtil.openUrlConnection(downloadUrl,
+// proxySettings, false, null, null);
+// if (connection != null) {
+// InputStream input = connection.getInputStream();
+// outStream = new FileOutputStream(destinationFile);
+// copyByteStream(input, outStream);
+// return true;
+//
+// }
+// } finally {
+// try {
+// if (in != null)
+// in.close();
+// if (outStream != null)
+// outStream.close();
+// } catch (IOException e) {
+// BugzillaCorePlugin.log(new Status(IStatus.ERROR,
+// BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR,
+// "Problem closing the stream", e));
+// }
+// }
+// return false;
+// }
+//
+// private void copyByteStream(InputStream in, OutputStream out) throws
+// IOException {
+// if (in != null && out != null) {
+// BufferedInputStream inBuffered = new BufferedInputStream(in);
+//
+// int bufferSize = 1000;
+// byte[] buffer = new byte[bufferSize];
+//
+// int readCount;
+//
+// BufferedOutputStream fout = new BufferedOutputStream(out);
+//
+// while ((readCount = inBuffered.read(buffer)) != -1) {
+// if (readCount < bufferSize) {
+// fout.write(buffer, 0, readCount);
+// } else {
+// fout.write(buffer);
+// }
+// }
+// fout.flush();
+// fout.close();
+// in.close();
+// }
+// }
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
new file mode 100644
index 000000000..b4ee020a7
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java
@@ -0,0 +1,991 @@
+/*******************************************************************************
+ * Copyright (c) 2003 - 2006 University Of British Columbia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylar.internal.bugzilla.core;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.security.GeneralSecurityException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.security.auth.login.LoginException;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.PartBase;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylar.context.core.MylarStatusHandler;
+import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer;
+import org.eclipse.mylar.internal.tasks.core.HtmlTag;
+import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException;
+import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
+import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token;
+import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery;
+import org.eclipse.mylar.tasks.core.QueryHitCollector;
+import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
+import org.eclipse.mylar.tasks.core.RepositoryTaskData;
+import org.eclipse.mylar.tasks.core.TaskList;
+
+/**
+ * @author Mik Kersten
+ * @author Rob Elves
+ * @author Steffen Pingel
+ */
+public class BugzillaClient {
+
+ private static final int CONNECT_TIMEOUT = 30000;
+
+ private static final String CHANGES_SUBMITTED = "Changes Submitted";
+
+ private static final String VALUE_CONTENTTYPEMETHOD_MANUAL = "manual";
+
+ private static final String VALUE_ISPATCH = "1";
+
+ private static final String VALUE_ACTION_INSERT = "insert";
+
+ private static final String ATTRIBUTE_CONTENTTYPEENTRY = "contenttypeentry";
+
+ private static final String ATTRIBUTE_CONTENTTYPEMETHOD = "contenttypemethod";
+
+ private static final String ATTRIBUTE_ISPATCH = "ispatch";
+
+ private static final String ATTRIBUTE_DATA = "data";
+
+ private static final String ATTRIBUTE_COMMENT = "comment";
+
+ private static final String ATTRIBUTE_DESCRIPTION = "description";
+
+ private static final String ATTRIBUTE_BUGID = "bugid";
+
+ private static final String ATTRIBUTE_BUGZILLA_PASSWORD = "Bugzilla_password";
+
+ private static final String ATTRIBUTE_BUGZILLA_LOGIN = "Bugzilla_login";
+
+ private static final String ATTRIBUTE_ACTION = "action";
+
+ public static final String POST_ARGS_ATTACHMENT_DOWNLOAD = "/attachment.cgi?id=";
+
+ public static final String POST_ARGS_ATTACHMENT_UPLOAD = "/attachment.cgi";// ?action=insert";//&bugid=";
+
+ // private static final String CONTENT_TYPE_TEXT_HTML = "text/html";
+
+ // private static final String CONTENT_TYPE_APP_XCGI = "application/x-cgi";
+
+ private static final String CONTENT_TYPE_APP_RDF_XML = "application/rdf+xml";
+
+ private static final String CONTENT_TYPE_APP_XML = "application/xml";
+
+ private static final String CONTENT_TYPE_TEXT_XML = "text/xml";
+
+ private static final String[] VALID_CONFIG_CONTENT_TYPES = { CONTENT_TYPE_APP_RDF_XML, CONTENT_TYPE_APP_XML,
+ CONTENT_TYPE_TEXT_XML };
+
+ private static final String ATTR_CHARSET = "charset";
+
+ private static final BugzillaAttributeFactory attributeFactory = new BugzillaAttributeFactory();
+
+ protected Proxy proxy = Proxy.NO_PROXY;
+
+ protected String username;
+
+ protected String password;
+
+ protected URL repositoryUrl;
+
+ protected String characterEncoding;
+
+ private boolean authenticated;
+
+ private HttpClient httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
+
+ private String htAuthUser;
+
+ private String htAuthPass;
+
+ public BugzillaClient(URL url, String username, String password, String htAuthUser, String htAuthPass,
+ String characterEncoding) {
+ this.username = username;
+ this.password = password;
+ this.repositoryUrl = url;
+ this.htAuthUser = htAuthUser;
+ this.htAuthPass = htAuthPass;
+ this.characterEncoding = characterEncoding;
+ }
+
+ public void validate() throws IOException, LoginException, BugzillaException {
+ logout();
+ connect(repositoryUrl + "/");
+ }
+
+ protected boolean hasAuthenticationCredentials() {
+ return username != null && username.length() > 0;
+ }
+
+ private GetMethod connect(String serverURL) throws LoginException, IOException, BugzillaException {
+
+ return connectInternal(serverURL);
+
+ }
+
+ private GetMethod connectInternal(String serverURL) throws LoginException, IOException, BugzillaException {
+ WebClientUtil.setupHttpClient(httpClient, proxy, serverURL, htAuthUser, htAuthPass);
+ //httpClient.getParams().setParameter("http.socket.timeout", new Integer(CONNECT_TIMEOUT));
+ for (int attempt = 0; attempt < 2; attempt++) {
+ // force authentication
+ if (!authenticated && hasAuthenticationCredentials()) {
+ authenticate();
+ }
+
+ GetMethod method = new GetMethod(WebClientUtil.getRequestPath(serverURL));
+ method.getParams().setSoTimeout(CONNECT_TIMEOUT);
+ // NOTE! Setting browser compatability breaks Bugzilla
+ // authentication
+ // method.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
+
+ int code;
+ try {
+ code = httpClient.executeMethod(method);
+ } catch (IOException e) {
+ method.releaseConnection();
+ throw e;
+ }
+
+ if (code == HttpURLConnection.HTTP_OK) {
+ return method;
+ } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
+ // login or reauthenticate due to an expired session
+ method.releaseConnection();
+ authenticated = false;
+ authenticate();
+ } else {
+ MylarStatusHandler.log("Connection http code returned: " + code, this);
+ throw new BugzillaException();
+ }
+ }
+
+ throw new LoginException(
+ "All attempts to connect failed. Please verify connection and authentication information.");
+ }
+
+ public void logout() throws LoginException, IOException, BugzillaException {
+ authenticated = true;
+ String loginUrl = repositoryUrl + "/relogin.cgi";
+ GetMethod method = connect(loginUrl);
+ method.setFollowRedirects(false);
+ try {
+ // httpClient.getParams().setAuthenticationPreemptive(true);
+ int code = httpClient.executeMethod(method);
+ if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
+ throw new LoginException();
+ }
+ BufferedReader responseReader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(),
+ characterEncoding));
+
+ HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(responseReader, null);
+ for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
+
+ if (token.getType() == Token.TAG) {
+ HtmlTag tag = (HtmlTag) token.getValue();
+ if (tag.getTagType() == HtmlTag.Type.A) {
+ if (tag.hasAttribute("href")) {
+ String id = tag.getAttribute("href");
+ if (id != null && id.toLowerCase().contains("goaheadandlogin=1")) {
+ authenticated = false;
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ throw new LoginException("Logout procedure failed.");
+
+ } catch (IOException e) {
+ throw new BugzillaException(e);
+ } catch (ParseException e) {
+ throw new BugzillaException(e);
+ } finally {
+ method.releaseConnection();
+ // httpClient.getParams().setAuthenticationPreemptive(false);
+ }
+ }
+
+ private void authenticate() throws LoginException, IOException, BugzillaException {
+ if (!hasAuthenticationCredentials()) {
+ throw new LoginException();
+ }
+
+ String loginUrl = repositoryUrl.toString();
+ if (hasAuthenticationCredentials()) {
+ loginUrl = repositoryUrl + "/query.cgi?" + IBugzillaConstants.POST_ARGS_LOGIN
+ + URLEncoder.encode(username, characterEncoding) + IBugzillaConstants.POST_ARGS_PASSWORD
+ + URLEncoder.encode(password, characterEncoding);
+ } else {
+ loginUrl = repositoryUrl + "/index.cgi";
+ }
+
+ GetMethod method = new GetMethod(WebClientUtil.getRequestPath(loginUrl));
+ method.setFollowRedirects(false);
+
+ try {
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ int code = httpClient.executeMethod(method);
+ if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) {
+ throw new LoginException("HTTP authentication failed. Invalid username or password.");
+ // final InetAddress addr =
+ // InetAddress.getByName(repositoryUrl.getHost());
+ // PasswordAuthentication pw =
+ // Authenticator.requestPasswordAuthentication(repositoryUrl.getHost(),
+ // addr,
+ // WebClientUtil.getPort(repositoryUrl.getHost()), "HTTP", "Http
+ // Authentication!", null);
+ // credentials = new
+ // UsernamePasswordCredentials(pw.getUserName(), new
+ // String(pw.getPassword()));
+ // httpClient.getState().setCredentials(
+ // new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT,
+ // AuthScope.ANY_REALM), credentials);
+ //
+ // code = httpClient.executeMethod(method);
+ // if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code ==
+ // HttpURLConnection.HTTP_FORBIDDEN) {
+ // throw new LoginException("HTTP authentication failed. Invalid
+ // username or password.");
+ // }
+ }
+ if (hasAuthenticationCredentials()) {
+ BufferedReader responseReader = new BufferedReader(new InputStreamReader(method
+ .getResponseBodyAsStream(), characterEncoding));
+
+ HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(responseReader, null);
+ for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
+ if (token.getType() == Token.TAG) {
+ HtmlTag tag = (HtmlTag) token.getValue();
+ if (tag.getTagType() == HtmlTag.Type.A) {
+ String id = tag.getAttribute("href");
+ if (id != null && id.toLowerCase().contains("goaheadandlogin=1")) {
+ throw new LoginException("Invalid credentials.");
+ }
+ }
+ }
+ }
+ }
+ authenticated = true;
+
+ // try {
+ // parseHtmlError(responseReader);
+ // authenticated = true;
+ // } catch (UnrecognizedReponseException e) {
+ //
+ // }
+ } catch (IOException e) {
+ throw new BugzillaException(e);
+ } catch (ParseException e) {
+ throw new BugzillaException(e);
+ } finally {
+ method.releaseConnection();
+ httpClient.getParams().setAuthenticationPreemptive(false);
+ }
+ }
+
+ public RepositoryTaskData getTaskData(int id) throws IOException, MalformedURLException, LoginException,
+ GeneralSecurityException, BugzillaException {
+ GetMethod method = null;
+ try {
+ // System.err.println("Retrieving: "+repositoryUrl +
+ // IBugzillaConstants.SHOW_BUG_CGI_XML + id);
+ method = connect(repositoryUrl + IBugzillaConstants.SHOW_BUG_CGI_XML + id);
+ // method.addRequestHeader("Content-Type", characterEncoding);
+ RepositoryTaskData taskData = null;
+ if (method.getResponseHeader("Content-Type") != null) {
+ Header responseTypeHeader = method.getResponseHeader("Content-Type");
+ for (String type : VALID_CONFIG_CONTENT_TYPES) {
+ if (responseTypeHeader.getValue().toLowerCase().contains(type)) {
+ taskData = new RepositoryTaskData(new BugzillaAttributeFactory(),
+ BugzillaCorePlugin.REPOSITORY_KIND, repositoryUrl.toString(), "" + id);
+ setupExistingBugAttributes(repositoryUrl.toString(), taskData);
+ RepositoryReportFactory reportFactory = new RepositoryReportFactory(method
+ .getResponseBodyAsStream(), characterEncoding);
+ method.getResponseCharSet();
+ reportFactory.populateReport(taskData);
+ return taskData;
+ }
+ }
+ }
+
+ parseHtmlError(new BufferedReader(
+ new InputStreamReader(method.getResponseBodyAsStream(), characterEncoding)));
+
+ return null;
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+
+ public static String addCredentials(String url, String encoding, String userName, String password)
+ throws UnsupportedEncodingException {
+ if ((userName != null && userName.length() > 0) && (password != null && password.length() > 0)) {
+ if (encoding == null) {
+ encoding = IBugzillaConstants.ENCODING_UTF_8;
+ }
+ url += "&" + IBugzillaConstants.POST_ARGS_LOGIN + URLEncoder.encode(userName, encoding)
+ + IBugzillaConstants.POST_ARGS_PASSWORD + URLEncoder.encode(password, encoding);
+ }
+ return url;
+ }
+
+ /**
+ * Utility method for determining what potential error has occurred from a
+ * bugzilla html reponse page
+ *
+ * @throws CoreException
+ */
+ public static void parseHtmlError(BufferedReader in) throws IOException, LoginException, BugzillaException {
+ HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
+
+ boolean isTitle = false;
+ String title = "";
+ String body = "";
+
+ try {
+
+ for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
+ body += token.toString();
+ if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
+ && !((HtmlTag) (token.getValue())).isEndTag()) {
+ isTitle = true;
+ continue;
+ }
+
+ if (isTitle) {
+ // get all of the data in the title tag
+ if (token.getType() != Token.TAG) {
+ title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
+ continue;
+ } else if (token.getType() == Token.TAG
+ && ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
+ && ((HtmlTag) token.getValue()).isEndTag()) {
+
+ if (title.indexOf("login") != -1 || title.indexOf("log in") != -1
+ || (title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
+ || title.indexOf("check e-mail") != -1) {
+ // MylarStatusHandler.log("Login Error: "+body,
+ // BugzillaServerFacade.class);
+ throw new LoginException(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD);
+ } else if (title.indexOf(IBugzillaConstants.ERROR_MIDAIR_COLLISION) != -1) {
+ throw new BugzillaException(IBugzillaConstants.ERROR_MSG_MIDAIR_COLLISION);
+ } else if (title.indexOf(IBugzillaConstants.ERROR_COMMENT_REQUIRED) != -1) {
+ throw new BugzillaException(IBugzillaConstants.ERROR_MSG_COMMENT_REQUIRED);
+ } else if (title.indexOf(IBugzillaConstants.LOGGED_OUT) != -1) {
+ throw new BugzillaException(IBugzillaConstants.LOGGED_OUT);
+ }
+ }
+ }
+ }
+
+ throw new UnrecognizedReponseException(body);
+
+ } catch (ParseException e) {
+ throw new IOException("Unable to parse result from repository:\n" + e.getMessage());
+ }
+ }
+
+ public void search(AbstractRepositoryQuery query, QueryHitCollector collector, TaskList taskList)
+ throws IOException, BugzillaException, GeneralSecurityException {
+ String queryUrl = query.getUrl();
+ // Test that we don't specify content type twice.
+ // Should only be specified here (not in passed in url if possible
+ if(!queryUrl.contains("ctype=rdf")) {
+ queryUrl = queryUrl.concat(IBugzillaConstants.CONTENT_TYPE_RDF);
+ }
+ GetMethod method = connect(queryUrl);
+
+
+ if (method.getResponseHeader("Content-Type") != null) {
+ Header responseTypeHeader = method.getResponseHeader("Content-Type");
+ for (String type : VALID_CONFIG_CONTENT_TYPES) {
+ if (responseTypeHeader.getValue().toLowerCase().contains(type)) {
+ RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory(
+ method.getResponseBodyAsStream(), characterEncoding);
+ queryFactory.performQuery(taskList, repositoryUrl.toString(), collector, query.getMaxHits());
+ return;
+ }
+ }
+ }
+ parseHtmlError(new BufferedReader(
+ new InputStreamReader(method.getResponseBodyAsStream(), characterEncoding)));
+ }
+
+ public static void setupExistingBugAttributes(String serverUrl, RepositoryTaskData existingReport) {
+ // ordered list of elements as they appear in UI
+ // and additional elements that may not appear in the incoming xml
+ // stream but need to be present for bug submission
+ BugzillaReportElement[] reportElements = { BugzillaReportElement.BUG_STATUS, BugzillaReportElement.RESOLUTION,
+ BugzillaReportElement.BUG_ID, BugzillaReportElement.REP_PLATFORM, BugzillaReportElement.PRODUCT,
+ BugzillaReportElement.OP_SYS, BugzillaReportElement.COMPONENT, BugzillaReportElement.VERSION,
+ BugzillaReportElement.PRIORITY, BugzillaReportElement.BUG_SEVERITY, BugzillaReportElement.ASSIGNED_TO,
+ BugzillaReportElement.TARGET_MILESTONE, BugzillaReportElement.REPORTER,
+ BugzillaReportElement.DEPENDSON, BugzillaReportElement.BLOCKED, BugzillaReportElement.BUG_FILE_LOC,
+ BugzillaReportElement.NEWCC, BugzillaReportElement.KEYWORDS }; // BugzillaReportElement.VOTES,
+
+ for (BugzillaReportElement element : reportElements) {
+ RepositoryTaskAttribute reportAttribute = BugzillaClient.makeNewAttribute(element);
+ existingReport.addAttribute(element.getKeyString(), reportAttribute);
+ }
+ }
+
+ public static String getBugUrlWithoutLogin(String repositoryUrl, int id) {
+ String url = repositoryUrl + IBugzillaConstants.POST_ARGS_SHOW_BUG + id;
+ return url;
+ }
+
+ public static String getCharsetFromString(String string) {
+ int charsetStartIndex = string.indexOf(ATTR_CHARSET);
+ if (charsetStartIndex != -1) {
+ int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
+ // could
+ // be
+ // space
+ // after?
+ if (charsetEndIndex == -1) {
+ charsetEndIndex = string.length();
+ }
+ String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
+ if (Charset.availableCharsets().containsKey(charsetString)) {
+ return charsetString;
+ }
+ }
+ return null;
+ }
+
+ protected static RepositoryTaskAttribute makeNewAttribute(
+ org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement tag) {
+ return attributeFactory.createAttribute(tag.getKeyString());
+ }
+
+ public void setProxy(Proxy proxy) {
+ this.proxy = proxy;
+ }
+
+ public Proxy getProxy() {
+ return proxy;
+ }
+
+ public RepositoryConfiguration getRepositoryConfiguration() throws IOException, BugzillaException,
+ GeneralSecurityException {
+ GetMethod method = null;
+ try {
+ method = connect(repositoryUrl + IBugzillaConstants.POST_CONFIG_RDF_URL);
+ RepositoryConfigurationFactory configFactory = new RepositoryConfigurationFactory(method
+ .getResponseBodyAsStream(), characterEncoding);
+ RepositoryConfiguration configuration = configFactory.getConfiguration();
+ if (configuration != null) {
+ configuration.setRepositoryUrl(repositoryUrl.toString());
+ return configuration;
+ }
+ return null;
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+
+ public byte[] getAttachmentData(String id) throws LoginException, IOException, BugzillaException {
+ GetMethod method = null;
+ try {
+ String url = repositoryUrl + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
+ method = connect(url);
+ return method.getResponseBody();
+
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+
+ public InputStream getAttachmentInputStream(String id) throws LoginException, IOException, BugzillaException {
+ GetMethod method = null;
+ try {
+ String url = repositoryUrl + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
+ method = connect(url);
+ return method.getResponseBodyAsStream();
+
+ } finally {
+ if (method != null) {
+ method.releaseConnection();
+ }
+ }
+ }
+
+ public void uploadAttachment(String bugReportID, String comment, String description, File sourceFile,
+ String contentType, boolean isPatch) throws HttpException, IOException, LoginException, BugzillaException {
+ PostMethod postMethod = null;
+ // Note: The following debug code requires http commons-logging and
+ // commons-logging-api jars
+ // System.setProperty("org.apache.commons.logging.Log",
+ // "org.apache.commons.logging.impl.SimpleLog");
+ // System.setProperty("org.apache.commons.logging.simplelog.showdatetime",
+ // "true");
+ // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire",
+ // "debug");
+ // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient",
+ // "debug");
+
+ // Protocol.registerProtocol("https", new Protocol("https", new
+ // TrustAllSslProtocolSocketFactory(), 443));
+
+ try {
+ postMethod = new PostMethod(WebClientUtil.getRequestPath(repositoryUrl.toString())
+ + POST_ARGS_ATTACHMENT_UPLOAD);
+ // My understanding is that this option causes the client to first
+ // check
+ // with the server to see if it will in fact receive the post before
+ // actually sending the contents.
+ postMethod.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
+ List<PartBase> parts = new ArrayList<PartBase>();
+ parts.add(new StringPart(ATTRIBUTE_ACTION, VALUE_ACTION_INSERT));
+ parts.add(new StringPart(ATTRIBUTE_BUGZILLA_LOGIN, username));
+ parts.add(new StringPart(ATTRIBUTE_BUGZILLA_PASSWORD, password));
+ parts.add(new StringPart(ATTRIBUTE_BUGID, bugReportID));
+ parts.add(new StringPart(ATTRIBUTE_DESCRIPTION, description));
+ parts.add(new StringPart(ATTRIBUTE_COMMENT, comment));
+ parts.add(new FilePart(ATTRIBUTE_DATA, sourceFile));
+
+ if (isPatch) {
+ parts.add(new StringPart(ATTRIBUTE_ISPATCH, VALUE_ISPATCH));
+ } else {
+ parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEMETHOD, VALUE_CONTENTTYPEMETHOD_MANUAL));
+ parts.add(new StringPart(ATTRIBUTE_CONTENTTYPEENTRY, contentType));
+ }
+
+ postMethod.setRequestEntity(new MultipartRequestEntity(parts.toArray(new Part[1]), postMethod.getParams()));
+ postMethod.setDoAuthentication(true);
+ // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT);
+ int status = httpClient.executeMethod(postMethod);
+ if (status == HttpStatus.SC_OK) {
+ InputStreamReader reader = new InputStreamReader(postMethod.getResponseBodyAsStream(), postMethod
+ .getResponseCharSet());
+ BufferedReader bufferedReader = new BufferedReader(reader);
+
+ BugzillaClient.parseHtmlError(bufferedReader);
+
+ } else {
+ throw new IOException("Communication error occurred during upload. \n\n"
+ + HttpStatus.getStatusText(status));
+ }
+ } catch (UnrecognizedReponseException e) {
+ if (e.getMessage().indexOf(CHANGES_SUBMITTED) > -1) {
+ return;
+ }
+ throw e;
+ } finally {
+ if (postMethod != null) {
+ postMethod.releaseConnection();
+ }
+ }
+
+ }
+
+ public InputStream postFormData(String formUrl, NameValuePair[] formData) throws LoginException, IOException,
+ BugzillaException {
+ WebClientUtil.setupHttpClient(httpClient, proxy, repositoryUrl.toString(), htAuthUser, htAuthPass);
+ if (!authenticated && hasAuthenticationCredentials()) {
+ authenticate();
+ }
+ PostMethod postMethod = new PostMethod(WebClientUtil.getRequestPath(repositoryUrl.toString() + formUrl));
+
+ postMethod.setRequestBody(formData);
+ postMethod.setDoAuthentication(true);
+ // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT);
+ int status = httpClient.executeMethod(postMethod);
+ if (status == HttpStatus.SC_OK) {
+ return postMethod.getResponseBodyAsStream();
+ } else {
+ throw new IOException("Communication error occurred during upload. \n\n" + HttpStatus.getStatusText(status));
+ }
+ }
+
+}
+
+// /**
+// * Adds bug attributes to new bug model and sets defaults
+// * TODO: Make generic and move TaskRepositoryManager
+// */
+// public static void setupNewBugAttributes(String repositoryUrl, Proxy
+// proxySettings, String userName,
+// String password, NewBugzillaReport newReport, String characterEncoding)
+// throws IOException,
+// KeyManagementException, GeneralSecurityException,
+// NoSuchAlgorithmException, BugzillaException {
+//
+// newReport.removeAllAttributes();
+//
+// RepositoryConfiguration repositoryConfiguration =
+// this.getRepositoryConfiguration();
+// // BugzillaCorePlugin.getRepositoryConfiguration(false,
+// // repositoryUrl, proxySettings, userName, password, characterEncoding);
+//
+// RepositoryTaskAttribute a =
+// BugzillaClient.makeNewAttribute(BugzillaReportElement.PRODUCT);
+// List<String> optionValues = repositoryConfiguration.getProducts();
+// Collections.sort(optionValues);
+// // for (String option : optionValues) {
+// // a.addOptionValue(option, option);
+// // }
+// a.setValue(newReport.getProduct());
+// a.setReadOnly(true);
+// newReport.addAttribute(BugzillaReportElement.PRODUCT.getKeyString(), a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_STATUS);
+// optionValues = repositoryConfiguration.getStatusValues();
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// a.setValue(IBugzillaConstants.VALUE_STATUS_NEW);
+// newReport.addAttribute(BugzillaReportElement.BUG_STATUS.getKeyString(),
+// a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.VERSION);
+// optionValues =
+// repositoryConfiguration.getVersions(newReport.getProduct());
+// Collections.sort(optionValues);
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// if (optionValues != null && optionValues.size() > 0) {
+// a.setValue(optionValues.get(optionValues.size() - 1));
+// }
+// newReport.addAttribute(BugzillaReportElement.VERSION.getKeyString(), a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.COMPONENT);
+// optionValues =
+// repositoryConfiguration.getComponents(newReport.getProduct());
+// Collections.sort(optionValues);
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// if (optionValues != null && optionValues.size() > 0) {
+// a.setValue(optionValues.get(0));
+// }
+// newReport.addAttribute(BugzillaReportElement.COMPONENT.getKeyString(),
+// a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.REP_PLATFORM);
+// optionValues = repositoryConfiguration.getPlatforms();
+// Collections.sort(optionValues);
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// if (optionValues != null && optionValues.size() > 0) {
+// a.setValue(optionValues.get(0));
+// }
+// newReport.addAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString(),
+// a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.OP_SYS);
+// optionValues = repositoryConfiguration.getOSs();
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// if (optionValues != null && optionValues.size() > 0) {
+// a.setValue(optionValues.get(optionValues.size() - 1));
+// }
+// newReport.addAttribute(BugzillaReportElement.OP_SYS.getKeyString(), a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.PRIORITY);
+// optionValues = repositoryConfiguration.getPriorities();
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// a.setValue(optionValues.get((optionValues.size() / 2)));
+// newReport.addAttribute(BugzillaReportElement.PRIORITY.getKeyString(), a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_SEVERITY);
+// optionValues = repositoryConfiguration.getSeverities();
+// for (String option : optionValues) {
+// a.addOptionValue(option, option);
+// }
+// a.setValue(optionValues.get((optionValues.size() / 2)));
+// newReport.addAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString(),
+// a);
+// // attributes.put(a.getName(), a);
+//
+// // a = new
+// // RepositoryTaskAttribute(BugzillaReportElement.TARGET_MILESTONE);
+// // optionValues =
+// //
+// BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(
+// // newReport.getProduct());
+// // for (String option : optionValues) {
+// // a.addOptionValue(option, option);
+// // }
+// // if(optionValues.size() > 0) {
+// // // new bug posts will fail if target_milestone element is included
+// // // and there are no milestones on the server
+// // newReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE, a);
+// // }
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.ASSIGNED_TO);
+// a.setValue("");
+// a.setReadOnly(false);
+// newReport.addAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString(),
+// a);
+// // attributes.put(a.getName(), a);
+//
+// a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_FILE_LOC);
+// a.setValue("http://");
+// a.setHidden(false);
+// newReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC.getKeyString(),
+// a);
+// // attributes.put(a.getName(), a);
+//
+// // newReport.attributes = attributes;
+// }
+
+// public static void updateBugAttributeOptions(RepositoryTaskData
+// existingReport) throws IOException,
+// KeyManagementException, GeneralSecurityException, BugzillaException {
+// String product =
+// existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
+// for (RepositoryTaskAttribute attribute : existingReport.getAttributes())
+// {
+// BugzillaReportElement element =
+// BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
+// attribute.clearOptions();
+// List<String> optionValues =
+// BugzillaCorePlugin.getRepositoryConfiguration(false, repositoryUrl,
+// proxySettings, userName, password,
+// characterEncoding).getOptionValues(element, product);
+// if (element != BugzillaReportElement.OP_SYS && element !=
+// BugzillaReportElement.BUG_SEVERITY
+// && element != BugzillaReportElement.PRIORITY && element !=
+// BugzillaReportElement.BUG_STATUS) {
+// Collections.sort(optionValues);
+// }
+// if (element == BugzillaReportElement.TARGET_MILESTONE &&
+// optionValues.isEmpty()) {
+// existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
+// continue;
+// }
+// for (String option : optionValues) {
+// attribute.addOptionValue(option, option);
+// }
+// }
+//
+// }
+
+// public static void addValidOperations(RepositoryTaskData bugReport,
+// String userName) {
+// BUGZILLA_REPORT_STATUS status =
+// BUGZILLA_REPORT_STATUS.valueOf(bugReport.getStatus());
+// switch (status) {
+// case UNCONFIRMED:
+// case REOPENED:
+// case NEW:
+// addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.accept, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent,
+// userName);
+// break;
+// case ASSIGNED:
+// addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent,
+// userName);
+// break;
+// case RESOLVED:
+// addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.verify, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
+// break;
+// case CLOSED:
+// addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+// break;
+// case VERIFIED:
+// addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+// addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
+// }
+// }
+
+// public static void addOperation(RepositoryTaskData bugReport,
+// BUGZILLA_OPERATION opcode, String userName) {
+// RepositoryOperation newOperation = null;
+// switch (opcode) {
+// case none:
+// newOperation = new RepositoryOperation(opcode.toString(), "Leave as " +
+// bugReport.getStatus() + " "
+// + bugReport.getResolution());
+// newOperation.setChecked(true);
+// break;
+// case accept:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_ACCEPT);
+// break;
+// case resolve:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_RESOLVE);
+// newOperation.setUpOptions(OPERATION_OPTION_RESOLUTION);
+// for (BUGZILLA_RESOLUTION resolution : BUGZILLA_RESOLUTION.values()) {
+// newOperation.addOption(resolution.toString(), resolution.toString());
+// }
+// break;
+// case duplicate:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_DUPLICATE);
+// newOperation.setInputName(OPERATION_INPUT_DUP_ID);
+// newOperation.setInputValue("");
+// break;
+// case reassign:
+// String localUser = userName;
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_REASSIGN);
+// newOperation.setInputName(OPERATION_INPUT_ASSIGNED_TO);
+// newOperation.setInputValue(localUser);
+// break;
+// case reassignbycomponent:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_REASSIGN_DEFAULT);
+// break;
+// case reopen:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_REOPEN);
+// break;
+// case verify:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_VERIFY);
+// break;
+// case close:
+// newOperation = new RepositoryOperation(opcode.toString(),
+// OPERATION_LABEL_CLOSE);
+// break;
+// default:
+// break;
+// // MylarStatusHandler.log("Unknown bugzilla operation code recieved",
+// // BugzillaRepositoryUtil.class);
+// }
+// if (newOperation != null) {
+// bugReport.addOperation(newOperation);
+// }
+// }
+
+// public static String getBugUrl(String repositoryUrl, int id, String
+// userName, String password) {
+//
+// String url = repositoryUrl + IBugzillaConstants.POST_ARGS_SHOW_BUG + id;
+// try {
+// url = addCredentials(url, userName, password);
+// } catch (UnsupportedEncodingException e) {
+// return "";
+// }
+// return url;
+// }
+
+// /**
+// * Get the list of products
+// *
+// * @param proxySettings
+// * TODO
+// * @param encoding
+// * TODO
+// *
+// * @return The list of valid products a bug can be logged against
+// * @throws IOException
+// * LoginException Exception
+// */
+// public static List<String> getProductList(String repositoryUrl, Proxy
+// proxySettings, String userName,
+// String password, String encoding) throws IOException, LoginException,
+// Exception {
+//
+// return BugzillaCorePlugin.getRepositoryConfiguration(false,
+// repositoryUrl, proxySettings, userName, password,
+// encoding).getProducts();
+//
+// // BugzillaQueryPageParser parser = new
+// // BugzillaQueryPageParser(repository, new NullProgressMonitor());
+// // if (!parser.wasSuccessful()) {
+// // throw new RuntimeException("Couldn't get products");
+// // } else {
+// // return Arrays.asList(parser.getProductValues());
+// // }
+//
+// }
+
+// // TODO: improve and move to repository connector?
+// public static void validateCredentials(Proxy proxySettings, String
+// repositoryUrl, String encoding, String userid,
+// String password) throws IOException, BugzillaException,
+// KeyManagementException, GeneralSecurityException {
+//
+// proxySettings = proxySettings == null ? Proxy.NO_PROXY : proxySettings;
+//
+// String url = repositoryUrl + "/index.cgi?" +
+// IBugzillaConstants.POST_ARGS_LOGIN
+// + URLEncoder.encode(userid, encoding) +
+// IBugzillaConstants.POST_ARGS_PASSWORD
+// + URLEncoder.encode(password, encoding);
+//
+// // For bug#160360
+// // MylarStatusHandler.log("VALIDATING: " + url,
+// // BugzillaServerFacade.class);
+//
+// URL serverURL = new URL(url);
+// HttpURLConnection serverConnection =
+// WebClientUtil.openUrlConnection(serverURL, proxySettings, false, null,
+// null);
+// BufferedReader in = new BufferedReader(new
+// InputStreamReader(serverConnection.getInputStream()));
+// try {
+// parseHtmlError(in);
+// } catch (UnrecognizedReponseException e) {
+// return;
+// }
+// }
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java
new file mode 100644
index 000000000..fdbd6f354
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientFactory.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2006 - 2006 Mylar eclipse.org project and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mylar project committers - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylar.internal.bugzilla.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
+
+/**
+ * @author Steffen Pingel
+ * @author Robert Elves (adaption for Bugzilla)
+ */
+public class BugzillaClientFactory {
+
+ public static BugzillaClient createClient(String hostUrl, String username, String password, String htAuthUser, String htAuthPass, String encoding)
+ throws MalformedURLException {
+ URL url = new URL(hostUrl);
+
+ BugzillaClient client = new BugzillaClient(url, username, password, htAuthUser, htAuthPass, encoding);// pass authenticator?
+ client.setProxy(WebClientUtil.getProxySettings());
+ return client;
+ }
+
+// /**
+// * Tries all supported access types for <code>location</code> and returns
+// * the corresponding version if successful; throws an exception otherwise.
+// *
+// * <p>
+// * Order of the tried access types: XML-RPC, Trac 0.9
+// */
+// public static Version probeClient(String location, String username, String password) throws MalformedURLException,
+// TracException {
+// URL url = new URL(location);
+// try {
+// ITracClient repository = new TracXmlRpcClient(url, Version.XML_RPC, username, password);
+// repository.validate();
+// return Version.XML_RPC;
+// } catch (TracException e) {
+// try {
+// ITracClient repository = new Trac09Client(url, Version.TRAC_0_9, username, password);
+// repository.validate();
+// return Version.TRAC_0_9;
+// } catch (TracLoginException e2) {
+// throw e;
+// } catch (TracException e2) {
+// }
+// }
+//
+// throw new TracException();
+// }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java
new file mode 100644
index 000000000..0c9b1c225
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClientManager.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2004 - 2006 University Of British Columbia and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * University Of British Columbia - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylar.internal.bugzilla.core;
+
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.mylar.tasks.core.ITaskRepositoryListener;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+
+/**
+ * @author Steffen Pingel
+ * @author Robert Elves (adaption for Bugzilla)
+ */
+public class BugzillaClientManager implements ITaskRepositoryListener {
+
+ private Map<String, BugzillaClient> clientByUrl = new HashMap<String, BugzillaClient>();
+
+ public BugzillaClientManager() {
+ }
+
+ public synchronized BugzillaClient getClient(TaskRepository taskRepository) throws MalformedURLException {
+ BugzillaClient client = clientByUrl.get(taskRepository.getUrl());
+ if (client == null) {
+
+ String htUser = taskRepository.getProperty(TaskRepository.AUTH_HTTP_USERNAME) != null ? taskRepository.getProperty(TaskRepository.AUTH_HTTP_USERNAME): "";
+ String htPass = taskRepository.getProperty(TaskRepository.AUTH_HTTP_PASSWORD) != null ? taskRepository.getProperty(TaskRepository.AUTH_HTTP_PASSWORD): "";
+
+
+ client = BugzillaClientFactory.createClient(taskRepository.getUrl(), taskRepository.getUserName(),
+ taskRepository.getPassword(), htUser, htPass, taskRepository.getCharacterEncoding());
+ clientByUrl.put(taskRepository.getUrl(), client);
+ }
+ return client;
+ }
+
+ public void repositoriesRead() {
+ // ignore
+ }
+
+ public synchronized void repositoryAdded(TaskRepository repository) {
+ // make sure there is no stale client still in the cache, bug #149939
+ clientByUrl.remove(repository.getUrl());
+ }
+
+ public synchronized void repositoryRemoved(TaskRepository repository) {
+ clientByUrl.remove(repository.getUrl());
+ }
+
+ public synchronized void repositorySettingsChanged(TaskRepository repository) {
+ clientByUrl.remove(repository.getUrl());
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java
index cbbf690dd..fcc9a1d04 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCorePlugin.java
@@ -16,16 +16,17 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.net.Proxy;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylar.tasks.core.TaskRepository;
import org.osgi.framework.BundleContext;
/**
@@ -46,6 +47,8 @@ public class BugzillaCorePlugin extends Plugin {
private static boolean cacheFileRead = false;
private static File repositoryConfigurationFile = null;
+
+ private BugzillaRepositoryConnector connector;
/** Product configuration for the current server */
private static Map<String, RepositoryConfiguration> repositoryConfigurations = new HashMap<String, RepositoryConfiguration>();
@@ -73,37 +76,62 @@ public class BugzillaCorePlugin extends Plugin {
super.stop(context);
}
- /**
- * for testing purposes
- */
- public static RepositoryConfiguration getRepositoryConfiguration(String repositoryUrl) {
- return repositoryConfigurations.get(repositoryUrl);
+ public BugzillaRepositoryConnector getConnector() {
+ return connector;
+ }
+
+ void setConnector(BugzillaRepositoryConnector connector) {
+ this.connector = connector;
}
+
+ public static Map<String, RepositoryConfiguration> getConfigurations() {
+ if (!cacheFileRead) {
+ readRepositoryConfigurationFile();
+ cacheFileRead = true;
+ }
+ return repositoryConfigurations;
+ }
+
public static void setConfigurationCacheFile(File file) {
repositoryConfigurationFile = file;
}
/**
+ * for testing purposes
+ */
+ public static RepositoryConfiguration getRepositoryConfiguration(String repositoryUrl) {
+ return repositoryConfigurations.get(repositoryUrl);
+ }
+
+ /**
* Retrieves the latest repository configuration from the server
- *
+ * @throws CoreException
+ * @throws GeneralSecurityException
+ * @throws BugzillaException
+ * @throws IOException
* @throws BugzillaException
* @throws GeneralSecurityException
* @throws
*/
- public static RepositoryConfiguration getRepositoryConfiguration(boolean forceRefresh, String repositoryUrl,
- Proxy proxySettings, String userName, String password, String encoding) throws IOException,
- BugzillaException, GeneralSecurityException {
+ public RepositoryConfiguration getRepositoryConfiguration(TaskRepository repository, boolean forceRefresh) throws CoreException {
+ try {
if (!cacheFileRead) {
readRepositoryConfigurationFile();
cacheFileRead = true;
}
- if (repositoryConfigurations.get(repositoryUrl) == null || forceRefresh) {
- RepositoryConfigurationFactory configFactory = new RepositoryConfigurationFactory();
- addRepositoryConfiguration(configFactory.getConfiguration(repositoryUrl, proxySettings, userName, password,
- encoding));
+ if (repositoryConfigurations.get(repository.getUrl()) == null || forceRefresh) {
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
+ if(config != null) {
+ addRepositoryConfiguration(config);
+ }
+
+ }
+ return repositoryConfigurations.get(repository.getUrl());
+ } catch (Exception e){
+ throw new CoreException(new Status(Status.ERROR, BugzillaCorePlugin.PLUGIN_ID, 1, "Error updating attributes.\n\n"+e.getMessage(), e));
}
- return repositoryConfigurations.get(repositoryUrl);
}
/** public for testing */
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java
index 884122d8f..7433eb89a 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaOfflineTaskHandler.java
@@ -24,6 +24,9 @@ import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_OPERATION;
+import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_REPORT_STATUS;
+import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_RESOLUTION;
import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException;
import org.eclipse.mylar.tasks.core.AbstractAttributeFactory;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
@@ -31,6 +34,7 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.IOfflineTaskHandler;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
+import org.eclipse.mylar.tasks.core.RepositoryOperation;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskList;
import org.eclipse.mylar.tasks.core.TaskRepository;
@@ -41,6 +45,28 @@ import org.eclipse.mylar.tasks.core.TaskRepository;
*/
public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler {
+ private static final String OPERATION_INPUT_ASSIGNED_TO = "assigned_to";
+
+ private static final String OPERATION_INPUT_DUP_ID = "dup_id";
+
+ private static final String OPERATION_OPTION_RESOLUTION = "resolution";
+
+ private static final String OPERATION_LABEL_CLOSE = "Mark as CLOSED";
+
+ private static final String OPERATION_LABEL_VERIFY = "Mark as VERIFIED";
+
+ private static final String OPERATION_LABEL_REOPEN = "Reopen bug";
+
+ private static final String OPERATION_LABEL_REASSIGN_DEFAULT = "Reassign to default assignee";
+
+ private static final String OPERATION_LABEL_REASSIGN = "Reassign to";
+
+ private static final String OPERATION_LABEL_DUPLICATE = "Mark as duplicate of #";
+
+ private static final String OPERATION_LABEL_RESOLVE = "Resolve as";
+
+ private static final String OPERATION_LABEL_ACCEPT = "Accept (change status to ASSIGNED)";
+
private static final String BUG_ID = "&bug_id=";
private static final int MAX_URL_LENGTH = 2000;
@@ -69,17 +95,28 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler {
private TaskList taskList;
- public BugzillaOfflineTaskHandler(TaskList taskList) {
+ private BugzillaRepositoryConnector connector;
+
+ public BugzillaOfflineTaskHandler(BugzillaRepositoryConnector connector, TaskList taskList) {
this.taskList = taskList;
+ this.connector = connector;
}
- public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId,
- Proxy proxySettings) throws CoreException {
+ public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId, Proxy proxySettings)
+ throws CoreException {
try {
+
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ client.setProxy(proxySettings);
int bugId = Integer.parseInt(taskId);
+ RepositoryTaskData taskData = client.getTaskData(bugId);
+ if (taskData != null) {
+ connector.updateAttributeOptions(repository, taskData);
+ addValidOperations(taskData, repository.getUserName());
+ return taskData;
+ }
+ return null;
- return BugzillaServerFacade.getBug(repository.getUrl(), repository.getUserName(), repository.getPassword(),
- proxySettings, repository.getCharacterEncoding(), bugId);
} catch (final UnrecognizedReponseException e) {
throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
"Report download failed. Unrecognized response from " + repository.getUrl() + ".", e));
@@ -130,7 +167,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler {
return tasks;
}
- String dateString = repository.getSyncTimeStamp();
+ String dateString = repository.getSyncTimeStamp();
if (dateString == null) {
dateString = "";
}
@@ -156,55 +193,200 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler {
String newurlQueryString = URLEncoder.encode(AbstractRepositoryTask.getTaskId(task.getHandleIdentifier())
+ ",", repository.getCharacterEncoding());
if ((urlQueryString.length() + newurlQueryString.length() + IBugzillaConstants.CONTENT_TYPE_RDF.length()) > MAX_URL_LENGTH) {
- urlQueryString += IBugzillaConstants.CONTENT_TYPE_RDF;
queryForChanged(repository, changedTasks, urlQueryString, proxySettings);
queryCounter = 0;
urlQueryString = new String(urlQueryBase + BUG_ID);
urlQueryString += newurlQueryString;
} else if (!itr.hasNext()) {
- urlQueryString += newurlQueryString;
- urlQueryString += IBugzillaConstants.CONTENT_TYPE_RDF;
+ urlQueryString += newurlQueryString;
queryForChanged(repository, changedTasks, urlQueryString, proxySettings);
} else {
urlQueryString += newurlQueryString;
}
- }
+ }
return changedTasks;
}
private void queryForChanged(TaskRepository repository, Set<AbstractRepositoryTask> changedTasks,
String urlQueryString, Proxy proxySettings) throws UnsupportedEncodingException, CoreException {
- RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory();
+
QueryHitCollector collector = new QueryHitCollector(taskList);
- if (repository.hasCredentials()) {
- urlQueryString = BugzillaServerFacade.addCredentials(urlQueryString, repository.getCharacterEncoding(), repository.getUserName(), repository
- .getPassword());
- }
+ BugzillaRepositoryQuery query = new BugzillaRepositoryQuery(repository.getUrl(), urlQueryString, "", "-1",
+ taskList);
try {
- queryFactory.performQuery(taskList, repository.getUrl(), collector, urlQueryString, proxySettings,
- AbstractReportFactory.RETURN_ALL_HITS, repository.getCharacterEncoding());
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ client.search(query, collector, taskList);
} catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, "failed to perform query", e));
+ throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
+ "failed to perform query", e));
}
+ // if (repository.hasCredentials()) {
+ // urlQueryString = BugzillaClient.addCredentials(urlQueryString,
+ // repository.getCharacterEncoding(),
+ // repository.getUserName(), repository.getPassword());
+ // }
+ // try {
+ // queryFactory.performQuery(taskList, repository.getUrl(), collector,
+ // AbstractReportFactory.RETURN_ALL_HITS);
+ // } catch (Exception e) {
+ // throw new CoreException(new Status(IStatus.ERROR,
+ // BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
+ // "failed to perform query", e));
+ // }
+
for (AbstractQueryHit hit : collector.getHits()) {
String handle = AbstractRepositoryTask.getHandle(repository.getUrl(), hit.getId());
ITask correspondingTask = taskList.getTask(handle);
if (correspondingTask != null && correspondingTask instanceof AbstractRepositoryTask) {
- AbstractRepositoryTask repositoryTask = (AbstractRepositoryTask)correspondingTask;
- // Hack to avoid re-syncing last task from previous synchronization
- // This can be removed once we are getting a query timestamp from the repository rather than
- // using the last modified stamp of the last task modified in the return hits.
- // (or the changeddate field in the hit rdf becomes consistent, currently it doesn't return a proper modified date string)
- if(repositoryTask.getTaskData() != null && repositoryTask.getTaskData().getLastModified().equals(repository.getSyncTimeStamp())) {
+ AbstractRepositoryTask repositoryTask = (AbstractRepositoryTask) correspondingTask;
+ // Hack to avoid re-syncing last task from previous
+ // synchronization
+ // This can be removed once we are getting a query timestamp
+ // from the repository rather than
+ // using the last modified stamp of the last task modified in
+ // the return hits.
+ // (or the changeddate field in the hit rdf becomes consistent,
+ // currently it doesn't return a proper modified date string)
+ if (repositoryTask.getTaskData() != null
+ && repositoryTask.getTaskData().getLastModified().equals(repository.getSyncTimeStamp())) {
String taskId = AbstractRepositoryTask.getTaskId(repositoryTask.getHandleIdentifier());
RepositoryTaskData taskData = downloadTaskData(repository, taskId, proxySettings);
- if(taskData != null && taskData.getLastModified().equals(repository.getSyncTimeStamp())) {
+ if (taskData != null && taskData.getLastModified().equals(repository.getSyncTimeStamp())) {
continue;
}
- }
+ }
changedTasks.add(repositoryTask);
}
}
}
+
+ public static void addValidOperations(RepositoryTaskData bugReport, String userName) {
+ BUGZILLA_REPORT_STATUS status = BUGZILLA_REPORT_STATUS.valueOf(bugReport.getStatus());
+ switch (status) {
+ case UNCONFIRMED:
+ case REOPENED:
+ case NEW:
+ addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.accept, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent, userName);
+ break;
+ case ASSIGNED:
+ addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent, userName);
+ break;
+ case RESOLVED:
+ addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.verify, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
+ break;
+ case CLOSED:
+ addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+ break;
+ case VERIFIED:
+ addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
+ addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
+ }
+ }
+
+ public static void addOperation(RepositoryTaskData bugReport, BUGZILLA_OPERATION opcode, String userName) {
+ RepositoryOperation newOperation = null;
+ switch (opcode) {
+ case none:
+ newOperation = new RepositoryOperation(opcode.toString(), "Leave as " + bugReport.getStatus() + " "
+ + bugReport.getResolution());
+ newOperation.setChecked(true);
+ break;
+ case accept:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_ACCEPT);
+ break;
+ case resolve:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_RESOLVE);
+ newOperation.setUpOptions(OPERATION_OPTION_RESOLUTION);
+ for (BUGZILLA_RESOLUTION resolution : BUGZILLA_RESOLUTION.values()) {
+ newOperation.addOption(resolution.toString(), resolution.toString());
+ }
+ break;
+ case duplicate:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_DUPLICATE);
+ newOperation.setInputName(OPERATION_INPUT_DUP_ID);
+ newOperation.setInputValue("");
+ break;
+ case reassign:
+ String localUser = userName;
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REASSIGN);
+ newOperation.setInputName(OPERATION_INPUT_ASSIGNED_TO);
+ newOperation.setInputValue(localUser);
+ break;
+ case reassignbycomponent:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REASSIGN_DEFAULT);
+ break;
+ case reopen:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REOPEN);
+ break;
+ case verify:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_VERIFY);
+ break;
+ case close:
+ newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_CLOSE);
+ break;
+ default:
+ break;
+ // MylarStatusHandler.log("Unknown bugzilla operation code recieved",
+ // BugzillaRepositoryUtil.class);
+ }
+ if (newOperation != null) {
+ bugReport.addOperation(newOperation);
+ }
+ }
+
+
+// // TODO: getAttributeOptions()
+// public void updateAttributeOptions(TaskRepository taskRepository, RepositoryTaskData existingReport)
+// throws IOException, KeyManagementException, GeneralSecurityException, BugzillaException, CoreException {
+//
+// RepositoryConfiguration configuration = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(taskRepository, false);
+// if (configuration == null)
+// return;
+// String product = existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
+// for (RepositoryTaskAttribute attribute : existingReport.getAttributes()) {
+// BugzillaReportElement element = BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
+// attribute.clearOptions();
+// String key = attribute.getID();
+// if (!product.equals("")) {
+// switch (element) {
+// case TARGET_MILESTONE:
+// case VERSION:
+// case COMPONENT:
+// key = product + "." + key;
+// }
+// }
+//
+// List<String> optionValues = configuration.getAttributeValues(key);
+// if(optionValues.size() == 0) {
+// optionValues = configuration.getAttributeValues(attribute.getID());
+// }
+//
+// if (element != BugzillaReportElement.OP_SYS && element != BugzillaReportElement.BUG_SEVERITY
+// && element != BugzillaReportElement.PRIORITY && element != BugzillaReportElement.BUG_STATUS) {
+// Collections.sort(optionValues);
+// }
+// if (element == BugzillaReportElement.TARGET_MILESTONE && optionValues.isEmpty()) {
+// existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
+// continue;
+// }
+// for (String option : optionValues) {
+// attribute.addOptionValue(option, option);
+// }
+// }
+// }
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
index ff09e82f7..f0c673123 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
@@ -66,7 +66,7 @@ public class BugzillaQueryHit extends AbstractQueryHit {
public String getUrl() {
Integer idInt = new Integer(id);
- return BugzillaServerFacade.getBugUrlWithoutLogin(repositoryUrl, idInt);
+ return BugzillaClient.getBugUrlWithoutLogin(repositoryUrl, idInt);
}
public AbstractRepositoryTask getOrCreateCorrespondingTask() {
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportElement.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportElement.java
index aa53580b2..9dc963ec5 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportElement.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportElement.java
@@ -69,6 +69,7 @@ public enum BugzillaReportElement {
TYPE ("type", "type"),
UNKNOWN ("UNKNOWN", "UNKNOWN"),
VERSION ("Version:", "version", false),
+ INSTALL_VERSION ("version of bugzilla installed", "install_version", true),
VOTES ("Votes:", "votes", true, true),
WORK_TIME("Add Time:", "work_time", true, false),
WHO ("who", "who"),
@@ -82,7 +83,8 @@ public enum BugzillaReportElement {
RESULT ("used by search engine", "result", false),
RDF ("used by search engine", "rdf", false),
INSTALLATION ("used by search engine", "installation", false),
- BUGS ("used by search engine", "bugs", false);
+ BUGS ("used by search engine", "bugs", false),
+ STATUS_OPEN ("open status values", "status_open", true, true);
private final boolean isHidden;
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java
index fb4d92308..f2d203961 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java
@@ -10,31 +10,25 @@
*******************************************************************************/
package org.eclipse.mylar.internal.bugzilla.core;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
import java.net.Proxy;
-import java.net.URL;
-import java.net.URLEncoder;
import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.Iterator;
-import java.util.Map;
+import java.util.List;
import java.util.Set;
+import org.apache.commons.httpclient.NameValuePair;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer;
import org.eclipse.mylar.internal.tasks.core.HtmlTag;
-import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token;
import org.eclipse.mylar.tasks.core.RepositoryOperation;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
@@ -58,21 +52,27 @@ public class BugzillaReportSubmitForm {
private static final String KEY_CC = "cc";
- private static final String POST_CONTENT_TYPE = "application/x-www-form-urlencoded";
-
- private static final String REQUEST_PROPERTY_CONTENT_TYPE = "Content-Type";
-
- private static final String REQUEST_PROPERTY_CONTENT_LENGTH = "Content-Length";
-
- private static final String METHOD_POST = "POST";
-
- private static final String KEY_BUGZILLA_PASSWORD = "Bugzilla_password";
-
- private static final String KEY_BUGZILLA_LOGIN = "Bugzilla_login";
+ // private static final String POST_CONTENT_TYPE =
+ // "application/x-www-form-urlencoded";
+ //
+ // private static final String REQUEST_PROPERTY_CONTENT_TYPE =
+ // "Content-Type";
+ //
+ // private static final String REQUEST_PROPERTY_CONTENT_LENGTH =
+ // "Content-Length";
+ //
+ // private static final String METHOD_POST = "POST";
+ //
+ // private static final String KEY_BUGZILLA_PASSWORD = "Bugzilla_password";
+ //
+ // private static final String KEY_BUGZILLA_LOGIN = "Bugzilla_login";
+ // private URL postUrl;
+ // private Proxy proxySettings = Proxy.NO_PROXY;
+ // private String charset;
private static final String POST_BUG_CGI = "post_bug.cgi";
- private static final String PROCESS_BUG_CGI = "process_bug.cgi";
+ private static final String PROCESS_BUG_CGI = "/process_bug.cgi";
public static final int WRAP_LENGTH = 90;
@@ -98,13 +98,7 @@ public class BugzillaReportSubmitForm {
public static final String FORM_PREFIX_BUG_220 = "Issue ";
/** The fields that are to be changed/maintained */
- private Map<String, String> fields = new HashMap<String, String>();
-
- private URL postUrl;
-
- private Proxy proxySettings = Proxy.NO_PROXY;
-
- private String charset;
+ private List<NameValuePair> fields = new ArrayList<NameValuePair>();
/** The prefix for how to find the bug number from the return */
private String prefix;
@@ -118,36 +112,38 @@ public class BugzillaReportSubmitForm {
private String postfix2;
private String error = null;
-
+
private RepositoryTaskData taskData = null;
-
- private boolean isNewBugPost = false;
- public BugzillaReportSubmitForm(String charEncoding) {
- charset = charEncoding;
+ public boolean isNewBugPost = false;
+
+ public BugzillaReportSubmitForm() {
+ // charset = charEncoding;
}
public static BugzillaReportSubmitForm makeNewBugPost(String repositoryUrl, String userName, String password,
Proxy proxySettings, String characterEncoding, RepositoryTaskData model, boolean wrapDescription)
throws UnsupportedEncodingException {
- BugzillaReportSubmitForm form;
+ BugzillaReportSubmitForm form = new BugzillaReportSubmitForm();
- if (characterEncoding != null) {
- form = new BugzillaReportSubmitForm(characterEncoding);
- } else {
- form = new BugzillaReportSubmitForm(IBugzillaConstants.ENCODING_UTF_8);
- }
+ // if (characterEncoding != null) {
+ // form = new BugzillaReportSubmitForm(characterEncoding);
+ // } else {
+ // form = new
+ // BugzillaReportSubmitForm(IBugzillaConstants.ENCODING_UTF_8);
+ // }
form.setTaskData(model);
-
+
form.setPrefix(BugzillaReportSubmitForm.FORM_PREFIX_BUG_218);
form.setPrefix2(BugzillaReportSubmitForm.FORM_PREFIX_BUG_220);
form.setPostfix(BugzillaReportSubmitForm.FORM_POSTFIX_216);
form.setPostfix2(BugzillaReportSubmitForm.FORM_POSTFIX_218);
- setConnectionsSettings(form, repositoryUrl, userName, password, proxySettings, POST_BUG_CGI);
+ // setConnectionsSettings(form, repositoryUrl, userName, password,
+ // proxySettings, POST_BUG_CGI);
// go through all of the attributes and add them to
// the bug post
@@ -199,18 +195,20 @@ public class BugzillaReportSubmitForm {
String userName, String password, Proxy proxySettings, Set<String> removeCC, String characterEncoding)
throws UnsupportedEncodingException {
- BugzillaReportSubmitForm form;
+ BugzillaReportSubmitForm form = new BugzillaReportSubmitForm();
- if (characterEncoding != null) {
- form = new BugzillaReportSubmitForm(characterEncoding);
- } else {
- form = new BugzillaReportSubmitForm(IBugzillaConstants.ENCODING_UTF_8);
- }
+ // if (characterEncoding != null) {
+ // form = new BugzillaReportSubmitForm(characterEncoding);
+ // } else {
+ // form = new
+ // BugzillaReportSubmitForm(IBugzillaConstants.ENCODING_UTF_8);
+ // }
form.setTaskData(model);
-
+
// setDefaultCCValue(bug, userName);
- setConnectionsSettings(form, repositoryUrl, userName, password, proxySettings, PROCESS_BUG_CGI);
+ // setConnectionsSettings(form, repositoryUrl, userName, password,
+ // proxySettings, PROCESS_BUG_CGI);
// go through all of the attributes and add them to the bug post
for (Iterator<RepositoryTaskAttribute> it = model.getAttributes().iterator(); it.hasNext();) {
@@ -229,11 +227,11 @@ public class BugzillaReportSubmitForm {
} else if (a != null && a.getID() != null && a.getID().compareTo("") != 0 && a.isHidden()) {
// we have a hidden attribute and we should send it back.
// System.err.println(a.getID()+" "+a.getValue());
- String value = a.getValue();
+ String value = a.getValue();
// Strip off timezone information
// 149513: Constant bugzilla mid-air collisions
- if (a.getID().equals(BugzillaReportElement.DELTA_TS.getKeyString()) && value != null) {
+ if (a.getID().equals(BugzillaReportElement.DELTA_TS.getKeyString()) && value != null) {
value = stripTimeZone(value);
}
form.add(a.getID(), value);
@@ -260,8 +258,7 @@ public class BugzillaReportSubmitForm {
form.add(KEY_FORM_NAME, VAL_PROCESS_BUG);
if (model.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString()) != null) {
- form.add(KEY_SHORT_DESC, model.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString())
- .getValue());
+ form.add(KEY_SHORT_DESC, model.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString()).getValue());
}
if (model.getNewComment().length() != 0) {
@@ -277,7 +274,6 @@ public class BugzillaReportSubmitForm {
return form;
}
-
public static String stripTimeZone(String longTime) {
String result = longTime;
if (longTime != null) {
@@ -288,7 +284,7 @@ public class BugzillaReportSubmitForm {
}
return result;
}
-
+
private static String toCommaSeparatedList(String[] strings) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < strings.length; i++) {
@@ -311,7 +307,9 @@ public class BugzillaReportSubmitForm {
*/
private void add(String key, String value) throws UnsupportedEncodingException {
// try {
- fields.put(key, URLEncoder.encode(value == null ? "" : value, charset));
+ // fields.add(new NameValuePair(key, URLEncoder.encode(value == null ?
+ // "" : value, charset)));
+ fields.add(new NameValuePair(key, value));
// BugzillaPlugin.ENCODING_UTF_8
// } catch (UnsupportedEncodingException e) {
// // ignore
@@ -319,48 +317,20 @@ public class BugzillaReportSubmitForm {
}
/**
- * Post the bug to the bugzilla server
- *
- * @return The result of the responses
- * @throws GeneralSecurityException
+ * Post the bug to the bugzilla server TODO: fix this mess
*/
- public String submitReportToRepository() throws IOException, BugzillaException, PossibleBugzillaFailureException, GeneralSecurityException {
- BufferedOutputStream out = null;
- BufferedReader in = null;
+ public String submitReportToRepository(BugzillaClient client) throws IOException, BugzillaException,
+ PossibleBugzillaFailureException, GeneralSecurityException {
+ NameValuePair[] formData = fields.toArray(new NameValuePair[fields.size()]);
+ InputStream inputStream = null;
String result = null;
try {
- // connect to the bugzilla server
- HttpURLConnection postConnection = WebClientUtil.getUrlConnection(postUrl, proxySettings, false);
-
- // set the connection method
- postConnection.setRequestMethod(METHOD_POST);
- String contentTypeString = POST_CONTENT_TYPE;
- if (charset != null) {
- contentTypeString += ";charset=" + charset;
+ if (isNewBugPost()) {
+ inputStream = client.postFormData(POST_BUG_CGI, formData);
+ } else {
+ inputStream = client.postFormData(PROCESS_BUG_CGI, formData);
}
- postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE, contentTypeString);
- // get the url for the update with all of the changed values
-
- byte[] body = getPostBody().getBytes();
- postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_LENGTH, String.valueOf(body.length));
-
- // allow outgoing streams and open a stream to post to
- postConnection.setDoOutput(true);
-
- out = new BufferedOutputStream(postConnection.getOutputStream());
-
- // write the data and close the stream
- out.write(body);
- out.flush();
-
- int responseCode = postConnection.getResponseCode();
- if (responseCode != HttpURLConnection.HTTP_OK && responseCode != HttpURLConnection.HTTP_CREATED) {
- throw new BugzillaException("Server returned HTTP error: " + responseCode + " - "
- + postConnection.getResponseMessage());
- }
-
- // open a stream to receive response from bugzilla
- in = new BufferedReader(new InputStreamReader(postConnection.getInputStream()));
+ BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
in.mark(10);
HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
@@ -414,20 +384,15 @@ public class BugzillaReportSubmitForm {
if ((!isNewBugPost && existingBugPosted != true) || (isNewBugPost && result == null)) {
in.reset();
- BugzillaServerFacade.parseHtmlError(in);
+ BugzillaClient.parseHtmlError(in);
}
- } catch (KeyManagementException e) {
- throw new BugzillaException("Could not POST form. Communications error: " + e.getMessage(), e);
- } catch (NoSuchAlgorithmException e) {
- throw new BugzillaException("Could not POST form. Communications error: " + e.getMessage(), e);
} catch (ParseException e) {
throw new IOException("Could not parse response from server.");
} finally {
try {
- if (in != null)
- in.close();
- if (out != null)
- out.close();
+ if (inputStream != null) {
+ inputStream.close();
+ }
} catch (IOException e) {
BugzillaCorePlugin.log(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR,
@@ -438,25 +403,6 @@ public class BugzillaReportSubmitForm {
return result;
}
- /**
- * Get the url that contains the attributes to be posted
- *
- * @return The url for posting
- */
- private String getPostBody() {
- String postBody = "";
-
- // go through all of the attributes and add them to the body of the post
- Iterator<Map.Entry<String, String>> anIterator = fields.entrySet().iterator();
- while (anIterator.hasNext()) {
- Map.Entry<String, String> entry = anIterator.next();
- postBody = postBody + entry.getKey() + "=" + entry.getValue();
- if (anIterator.hasNext())
- postBody = postBody + "&";
- }
- return postBody;
- }
-
private void setPrefix(String prefix) {
this.prefix = prefix;
}
@@ -510,68 +456,6 @@ public class BugzillaReportSubmitForm {
this.prefix2 = prefix2;
}
- // private void setCharset(String charset) {
- // this.charset = charset;
- // }
-
- private static void setConnectionsSettings(BugzillaReportSubmitForm form, String repositoryUrl, String userName,
- String password, Proxy proxySettings, String formName) throws UnsupportedEncodingException {
-
- String baseURL = repositoryUrl;
-
- if (!baseURL.endsWith("/"))
- baseURL += "/";
- try {
- form.postUrl = new URL(baseURL + formName);
- if (proxySettings != null) {
- form.proxySettings = proxySettings;
- }
- } catch (MalformedURLException e) {
- // we should be ok here
- }
-
- // add the login information to the bug post
- form.add(KEY_BUGZILLA_LOGIN, userName);
- form.add(KEY_BUGZILLA_PASSWORD, password);
- }
-
- // /**
- // * Sets the cc field to the user's address if a cc has not been specified
- // to
- // * ensure that commenters are on the cc list. TODO: Review this mechanism
- // *
- // * @author Wesley Coelho
- // */
- // private static void setDefaultCCValue(BugzillaReport bug, String
- // userName) {
- // // RepositoryTaskAttribute newCCattr =
- // // bug.getAttributeForKnobName(KEY_NEWCC);
- // RepositoryTaskAttribute owner =
- // bug.getAttribute(BugzillaReportElement.ASSIGNED_TO);
- //
- // // Don't add the cc if the user is the bug owner
- // if (userName == null || (owner != null &&
- // owner.getValue().indexOf(userName) != -1)) {
- // // MylarStatusHandler.log("Could not determine CC value for
- // // repository: " + repository, null);
- // return;
- // }
- // // Don't add cc if already there
- // RepositoryTaskAttribute ccAttribute =
- // bug.getAttribute(BugzillaReportElement.CC);
- // if (ccAttribute != null && ccAttribute.getValues().contains(userName)) {
- // return;
- // }
- // RepositoryTaskAttribute newCCattr =
- // bug.getAttribute(BugzillaReportElement.NEWCC);
- // if (newCCattr == null) {
- // newCCattr = new RepositoryTaskAttribute(BugzillaReportElement.NEWCC);
- // bug.addAttribute(BugzillaReportElement.NEWCC, newCCattr);
- // }
- // // Add the user to the cc list
- // newCCattr.setValue(userName);
- // }
-
/**
* Break text up into lines of about 80 characters so that it is displayed
* properly in bugzilla
@@ -628,9 +512,228 @@ public class BugzillaReportSubmitForm {
public void setTaskData(RepositoryTaskData taskData) {
this.taskData = taskData;
}
-
-
- public void setProxySettings(Proxy proxySettings) {
- this.proxySettings = proxySettings;
- }
-} \ No newline at end of file
+}
+// public void setProxySettings(Proxy proxySettings) {
+// this.proxySettings = proxySettings;
+// }
+
+// /**
+// * Post the bug to the bugzilla server
+// *
+// * @return The result of the responses
+// * @throws GeneralSecurityException
+// */
+// public String submitReportToRepository() throws IOException,
+// BugzillaException, PossibleBugzillaFailureException, GeneralSecurityException
+// {
+// BufferedOutputStream out = null;
+// BufferedReader in = null;
+// String result = null;
+// try {
+// // connect to the bugzilla server
+// HttpURLConnection postConnection = WebClientUtil.getUrlConnection(postUrl,
+// proxySettings, false, null, null);
+//
+// // set the connection method
+// postConnection.setRequestMethod(METHOD_POST);
+// String contentTypeString = POST_CONTENT_TYPE;
+// if (charset != null) {
+// contentTypeString += ";charset=" + charset;
+// }
+// postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_TYPE,
+// contentTypeString);
+// // get the url for the update with all of the changed values
+//
+// byte[] body = getPostBody().getBytes();
+// postConnection.setRequestProperty(REQUEST_PROPERTY_CONTENT_LENGTH,
+// String.valueOf(body.length));
+//
+// // allow outgoing streams and open a stream to post to
+// postConnection.setDoOutput(true);
+//
+// out = new BufferedOutputStream(postConnection.getOutputStream());
+//
+// // write the data and close the stream
+// out.write(body);
+// out.flush();
+//
+// int responseCode = postConnection.getResponseCode();
+// if (responseCode != HttpURLConnection.HTTP_OK && responseCode !=
+// HttpURLConnection.HTTP_CREATED) {
+// throw new BugzillaException("Server returned HTTP error: " + responseCode + "
+// - "
+// + postConnection.getResponseMessage());
+// }
+//
+// // open a stream to receive response from bugzilla
+// in = new BufferedReader(new
+// InputStreamReader(postConnection.getInputStream()));
+// in.mark(10);
+// HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
+//
+// boolean existingBugPosted = false;
+// boolean isTitle = false;
+// String title = "";
+// for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token
+// = tokenizer.nextToken()) {
+//
+// if (token.getType() == Token.TAG && ((HtmlTag)
+// (token.getValue())).getTagType() == HtmlTag.Type.TITLE
+// && !((HtmlTag) (token.getValue())).isEndTag()) {
+// isTitle = true;
+// continue;
+// }
+//
+// if (isTitle) {
+// // get all of the data in the title tag
+// if (token.getType() != Token.TAG) {
+// title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
+// continue;
+// } else if (token.getType() == Token.TAG
+// && ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
+// && ((HtmlTag) token.getValue()).isEndTag()) {
+// if (!isNewBugPost
+// && (title.toLowerCase().matches(".*bug\\s+processed.*") ||
+// title.toLowerCase().matches(
+// ".*defect\\s+processed.*"))) {
+// existingBugPosted = true;
+// } else if (isNewBugPost && prefix != null && prefix2 != null && postfix !=
+// null
+// && postfix2 != null && result == null) {
+// int startIndex = -1;
+// int startIndexPrefix = title.toLowerCase().indexOf(prefix.toLowerCase());
+// int startIndexPrefix2 = title.toLowerCase().indexOf(prefix2.toLowerCase());
+//
+// if (startIndexPrefix != -1 || startIndexPrefix2 != -1) {
+// if (startIndexPrefix != -1) {
+// startIndex = startIndexPrefix + prefix.length();
+// } else {
+// startIndex = startIndexPrefix2 + prefix2.length();
+// }
+// int stopIndex = title.toLowerCase().indexOf(postfix.toLowerCase(),
+// startIndex);
+// if (stopIndex == -1)
+// stopIndex = title.toLowerCase().indexOf(postfix2.toLowerCase(), startIndex);
+// if (stopIndex > -1) {
+// result = (title.substring(startIndex, stopIndex)).trim();
+// }
+// }
+// }
+// break;
+// }
+// }
+// }
+//
+// if ((!isNewBugPost && existingBugPosted != true) || (isNewBugPost && result
+// == null)) {
+// in.reset();
+// BugzillaClient.parseHtmlError(in);
+// }
+// } catch (KeyManagementException e) {
+// throw new BugzillaException("Could not POST form. Communications error: " +
+// e.getMessage(), e);
+// } catch (NoSuchAlgorithmException e) {
+// throw new BugzillaException("Could not POST form. Communications error: " +
+// e.getMessage(), e);
+// } catch (ParseException e) {
+// throw new IOException("Could not parse response from server.");
+// } finally {
+// try {
+// if (in != null)
+// in.close();
+// if (out != null)
+// out.close();
+//
+// } catch (IOException e) {
+// BugzillaCorePlugin.log(new Status(IStatus.ERROR,
+// BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR,
+// "Problem posting the bug", e));
+// }
+// }
+// // return the bug number
+// return result;
+// }
+
+// /**
+// * Get the url that contains the attributes to be posted
+// *
+// * @return The url for posting
+// */
+// private String getPostBody() {
+// String postBody = "";
+//
+// // go through all of the attributes and add them to the body of the post
+// Iterator<Map.Entry<String, String>> anIterator =
+// fields.entrySet().iterator();
+// while (anIterator.hasNext()) {
+// Map.Entry<String, String> entry = anIterator.next();
+// postBody = postBody + entry.getKey() + "=" + entry.getValue();
+// if (anIterator.hasNext())
+// postBody = postBody + "&";
+// }
+// return postBody;
+// }
+
+// private void setCharset(String charset) {
+// this.charset = charset;
+// }
+
+// private static void setConnectionsSettings(BugzillaReportSubmitForm form,
+// String repositoryUrl, String userName,
+// String password, Proxy proxySettings, String formName) throws
+// UnsupportedEncodingException {
+//
+// String baseURL = repositoryUrl;
+//
+// if (!baseURL.endsWith("/"))
+// baseURL += "/";
+// try {
+// form.postUrl = new URL(baseURL + formName);
+// if (proxySettings != null) {
+// form.proxySettings = proxySettings;
+// }
+// } catch (MalformedURLException e) {
+// // we should be ok here
+// }
+//
+// // add the login information to the bug post
+// //form.add(KEY_BUGZILLA_LOGIN, userName);
+// //form.add(KEY_BUGZILLA_PASSWORD, password);
+// }
+
+// /**
+// * Sets the cc field to the user's address if a cc has not been specified
+// to
+// * ensure that commenters are on the cc list. TODO: Review this mechanism
+// *
+// * @author Wesley Coelho
+// */
+// private static void setDefaultCCValue(BugzillaReport bug, String
+// userName) {
+// // RepositoryTaskAttribute newCCattr =
+// // bug.getAttributeForKnobName(KEY_NEWCC);
+// RepositoryTaskAttribute owner =
+// bug.getAttribute(BugzillaReportElement.ASSIGNED_TO);
+//
+// // Don't add the cc if the user is the bug owner
+// if (userName == null || (owner != null &&
+// owner.getValue().indexOf(userName) != -1)) {
+// // MylarStatusHandler.log("Could not determine CC value for
+// // repository: " + repository, null);
+// return;
+// }
+// // Don't add cc if already there
+// RepositoryTaskAttribute ccAttribute =
+// bug.getAttribute(BugzillaReportElement.CC);
+// if (ccAttribute != null && ccAttribute.getValues().contains(userName)) {
+// return;
+// }
+// RepositoryTaskAttribute newCCattr =
+// bug.getAttribute(BugzillaReportElement.NEWCC);
+// if (newCCattr == null) {
+// newCCattr = new RepositoryTaskAttribute(BugzillaReportElement.NEWCC);
+// bug.addAttribute(BugzillaReportElement.NEWCC, newCCattr);
+// }
+// // Add the user to the cc list
+// newCCattr.setValue(userName);
+// }
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
index ad78ab06d..6a01c0fc1 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java
@@ -11,12 +11,12 @@
package org.eclipse.mylar.internal.bugzilla.core;
-import java.io.FileNotFoundException;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.net.Proxy;
import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -32,6 +32,7 @@ import org.eclipse.mylar.tasks.core.IAttachmentHandler;
import org.eclipse.mylar.tasks.core.IOfflineTaskHandler;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
+import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskList;
import org.eclipse.mylar.tasks.core.TaskRepository;
@@ -44,15 +45,19 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
private static final String CLIENT_LABEL = "Bugzilla (supports uncustomized 2.18-2.22)";
- private BugzillaAttachmentHandler attachmentHandler = new BugzillaAttachmentHandler();
+ private BugzillaAttachmentHandler attachmentHandler;
private BugzillaOfflineTaskHandler offlineHandler;
private boolean forceSynchExecForTesting = false;
+ private BugzillaClientManager clientManager;
+
public void init(TaskList taskList) {
super.init(taskList);
- this.offlineHandler = new BugzillaOfflineTaskHandler(taskList);
+ this.offlineHandler = new BugzillaOfflineTaskHandler(this, taskList);
+ BugzillaCorePlugin.getDefault().setConnector(this);
+ attachmentHandler = new BugzillaAttachmentHandler(this);
}
public String getLabel() {
@@ -79,7 +84,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
try {
if (id != null) {
bugId = Integer.parseInt(id);
- } else {
+ } else {
throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
"invalid report id: null", new Exception("Invalid report id: null")));
}
@@ -98,26 +103,32 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
if (task == null) {
RepositoryTaskData taskData = null;
- try {
- taskData = BugzillaServerFacade.getBug(repository.getUrl(), repository.getUserName(), repository
- .getPassword(), proxySettings, repository.getCharacterEncoding(), bugId);
-
- if (taskData != null) {
- task = new BugzillaTask(handle, taskData.getId() + ": " + taskData.getDescription(), true);
- ((BugzillaTask) task).setTaskData(taskData);
- taskList.addTask(task);
- }
- } catch (final UnrecognizedReponseException e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
- "Report retrieval failed. Unrecognized response from " + repository.getUrl() + ".", e));
- } catch (final FileNotFoundException e) {
- throw new CoreException(
- new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0, "Report download from "
- + repository.getUrl() + " failed. File not found: " + e.getMessage(), e));
- } catch (final Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
- "Report download from " + repository.getUrl() + " failed, please see details.", e));
+ // try {
+ taskData = offlineHandler.downloadTaskData(repository, id, proxySettings);
+ // BugzillaClient client = getClientManager().getClient(repository);
+ // taskData = client.getTaskData(Integer.parseInt(id));
+ if (taskData != null) {
+ task = new BugzillaTask(handle, taskData.getId() + ": " + taskData.getDescription(), true);
+ ((BugzillaTask) task).setTaskData(taskData);
+ taskList.addTask(task);
}
+ // } catch (final UnrecognizedReponseException e) {
+ // throw new CoreException(new Status(IStatus.ERROR,
+ // BugzillaCorePlugin.PLUGIN_ID, 0,
+ // "Report retrieval failed. Unrecognized response from " +
+ // repository.getUrl() + ".", e));
+ // } catch (final FileNotFoundException e) {
+ // throw new CoreException(
+ // new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, 0,
+ // "Report download from "
+ // + repository.getUrl() + " failed. File not found: " +
+ // e.getMessage(), e));
+ // } catch (final Exception e) {
+ // throw new CoreException(new Status(IStatus.ERROR,
+ // BugzillaCorePlugin.PLUGIN_ID, 0,
+ // "Report download from " + repository.getUrl() + " failed, please
+ // see details.", e));
+ // }
}
return task;
}
@@ -147,29 +158,18 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
IProgressMonitor monitor, QueryHitCollector resultCollector) {
IStatus queryStatus = Status.OK_STATUS;
- RepositoryQueryResultsFactory queryFactory = new RepositoryQueryResultsFactory();
try {
- String queryUrl = query.getUrl();
- queryUrl = queryUrl.concat(IBugzillaConstants.CONTENT_TYPE_RDF);
- if (repository.hasCredentials()) {
- try {
- queryUrl = BugzillaServerFacade.addCredentials(queryUrl, repository.getCharacterEncoding(),
- repository.getUserName(), repository.getPassword());
- } catch (UnsupportedEncodingException e) {
- // ignore
- }
- }
- queryFactory.performQuery(taskList, repository.getUrl(), resultCollector, queryUrl, proxySettings, query
- .getMaxHits(), repository.getCharacterEncoding());
+ BugzillaClient client = getClientManager().getClient(repository);
+ client.search(query, resultCollector, taskList);
} catch (UnrecognizedReponseException e) {
queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, Status.INFO,
"Unrecognized response from server", e);
- } catch (IOException e) {
+ } catch (IOException e) {
queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR,
"Check repository credentials and connectivity.", e);
- } catch (BugzillaException e) {
- queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
- "Unable to perform query due to Bugzilla error", e);
+ } catch (BugzillaException e) {
+ queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
+ "Unable to perform query due to Bugzilla error", e);
} catch (GeneralSecurityException e) {
queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
"Unable to perform query due to repository configuration error", e);
@@ -191,17 +191,57 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
}
}
- @Override
- public void updateAttributes(final TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor)
- throws CoreException {
- try {
- BugzillaCorePlugin.getRepositoryConfiguration(true, repository.getUrl(), proxySettings, repository
- .getUserName(), repository.getPassword(), repository.getCharacterEncoding());
- } catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
- "could not update repository configuration", e));
- }
- }
+ // @Override
+ // public void updateAttributes(final TaskRepository repository, Proxy
+ // proxySettings, IProgressMonitor monitor)
+ // throws CoreException {
+ // try {
+ // BugzillaCorePlugin.getRepositoryConfiguration(true, repository.getUrl(),
+ // proxySettings, repository
+ // .getUserName(), repository.getPassword(),
+ // repository.getCharacterEncoding());
+ // } catch (Exception e) {
+ // throw new CoreException(new Status(IStatus.ERROR,
+ // BugzillaCorePlugin.PLUGIN_ID, IStatus.OK,
+ // "could not update repository configuration", e));
+ // }
+ // }
+
+ // public void updateBugAttributeOptions(TaskRepository taskRepository,
+ // RepositoryTaskData existingReport) throws IOException,
+ // KeyManagementException, GeneralSecurityException, BugzillaException,
+ // CoreException {
+ // String product =
+ // existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
+ // for (RepositoryTaskAttribute attribute : existingReport.getAttributes())
+ // {
+ // BugzillaReportElement element =
+ // BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
+ // attribute.clearOptions();
+ // // List<String> optionValues =
+ // BugzillaCorePlugin.getRepositoryConfiguration(false, repositoryUrl,
+ // // proxySettings, userName, password,
+ // characterEncoding).getOptionValues(element, product);
+ // List<String> optionValues =
+ // this.getRepositoryConfiguration(taskRepository,
+ // false).getOptionValues(element.getKeyString(), product);
+ // if (element != BugzillaReportElement.OP_SYS && element !=
+ // BugzillaReportElement.BUG_SEVERITY
+ // && element != BugzillaReportElement.PRIORITY && element !=
+ // BugzillaReportElement.BUG_STATUS) {
+ // Collections.sort(optionValues);
+ // }
+ // if (element == BugzillaReportElement.TARGET_MILESTONE &&
+ // optionValues.isEmpty()) {
+ // existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
+ // continue;
+ // }
+ // for (String option : optionValues) {
+ // attribute.addOptionValue(option, option);
+ // }
+ // }
+ //
+ // }
@Override
public void updateTaskState(AbstractRepositoryTask repositoryTask) {
@@ -211,9 +251,390 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
public void setForceSynchExecForTesting(boolean forceSynchExecForTesting) {
this.forceSynchExecForTesting = forceSynchExecForTesting;
}
-
+
@Override
public String getTaskIdPrefix() {
return "bug";
}
+
+ public BugzillaClientManager getClientManager() {
+ if (clientManager == null) {
+ clientManager = new BugzillaClientManager();
+ }
+ return clientManager;
+ }
+
+ @Override
+ public void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
+
+ BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, true);
+
+ }
+
+ public void updateAttributeOptions(TaskRepository taskRepository, RepositoryTaskData existingReport)
+ throws CoreException {
+ String product = existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
+ for (RepositoryTaskAttribute attribute : existingReport.getAttributes()) {
+ BugzillaReportElement element = BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
+ attribute.clearOptions();
+ List<String> optionValues = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(taskRepository,
+ false).getOptionValues(element, product);
+ if (element != BugzillaReportElement.OP_SYS && element != BugzillaReportElement.BUG_SEVERITY
+ && element != BugzillaReportElement.PRIORITY && element != BugzillaReportElement.BUG_STATUS) {
+ Collections.sort(optionValues);
+ }
+ if (element == BugzillaReportElement.TARGET_MILESTONE && optionValues.isEmpty()) {
+
+ existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
+ continue;
+ }
+ for (String option : optionValues) {
+ attribute.addOptionValue(option, option);
+ }
+ }
+
+ }
+
+ /**
+ * Adds bug attributes to new bug model and sets defaults
+ *
+ * @param proxySettings
+ * TODO
+ * @param characterEncoding
+ * TODO
+ *
+ * @throws IOException
+ * @throws NoSuchAlgorithmException
+ * @throws LoginException
+ * @throws KeyManagementException
+ * @throws BugzillaException
+ */
+ public static void setupNewBugAttributes(TaskRepository taskRepository, NewBugzillaReport newReport)
+ throws CoreException {
+
+ newReport.removeAllAttributes();
+
+ RepositoryConfiguration repositoryConfiguration = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(
+ taskRepository, false);
+
+ RepositoryTaskAttribute a = BugzillaClient.makeNewAttribute(BugzillaReportElement.PRODUCT);
+ List<String> optionValues = repositoryConfiguration.getProducts();
+ Collections.sort(optionValues);
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ a.setValue(newReport.getProduct());
+ a.setReadOnly(true);
+
+ newReport.addAttribute(BugzillaReportElement.PRODUCT.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_STATUS);
+ optionValues = repositoryConfiguration.getStatusValues();
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ a.setValue(IBugzillaConstants.VALUE_STATUS_NEW);
+
+ newReport.addAttribute(BugzillaReportElement.BUG_STATUS.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.VERSION);
+ optionValues = repositoryConfiguration.getVersions(newReport.getProduct());
+ Collections.sort(optionValues);
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ if (optionValues != null && optionValues.size() > 0) {
+ a.setValue(optionValues.get(optionValues.size() - 1));
+ }
+
+ newReport.addAttribute(BugzillaReportElement.VERSION.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.COMPONENT);
+ optionValues = repositoryConfiguration.getComponents(newReport.getProduct());
+ Collections.sort(optionValues);
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ if (optionValues != null && optionValues.size() > 0) {
+ a.setValue(optionValues.get(0));
+ }
+
+ newReport.addAttribute(BugzillaReportElement.COMPONENT.getKeyString(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.REP_PLATFORM);
+ optionValues = repositoryConfiguration.getPlatforms();
+ Collections.sort(optionValues);
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ if (optionValues != null && optionValues.size() > 0) {
+ a.setValue(optionValues.get(0));
+ }
+
+ newReport.addAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.OP_SYS);
+ optionValues = repositoryConfiguration.getOSs();
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ if (optionValues != null && optionValues.size() > 0) {
+ a.setValue(optionValues.get(optionValues.size() - 1));
+ }
+
+ newReport.addAttribute(BugzillaReportElement.OP_SYS.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.PRIORITY);
+ optionValues = repositoryConfiguration.getPriorities();
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ a.setValue(optionValues.get((optionValues.size() / 2)));
+
+ newReport.addAttribute(BugzillaReportElement.PRIORITY.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_SEVERITY);
+ optionValues = repositoryConfiguration.getSeverities();
+ for (String option : optionValues) {
+ a.addOptionValue(option, option);
+ }
+ a.setValue(optionValues.get((optionValues.size() / 2)));
+
+ newReport.addAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ // a = new
+ // RepositoryTaskAttribute(BugzillaReportElement.TARGET_MILESTONE);
+ // optionValues =
+ // BugzillaCorePlugin.getDefault().getgetProductConfiguration(serverUrl).getTargetMilestones(
+ // newReport.getProduct());
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // if(optionValues.size() > 0) {
+ // // new bug posts will fail if target_milestone element is
+ // included
+ // // and there are no milestones on the server
+ // newReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE, a);
+ // }
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.ASSIGNED_TO);
+ a.setValue("");
+ a.setReadOnly(false);
+
+ newReport.addAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_FILE_LOC);
+ a.setValue("http://");
+ a.setHidden(false);
+
+ newReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC.getKeyString(), a);
+ // attributes.put(a.getName(), a);
+
+ // newReport.attributes = attributes;
+ }
+
+
+ // // TODO: change to getAttributeOptions() and use whereever attribute
+ // options are required.
+ // public void updateAttributeOptions(TaskRepository taskRepository,
+ // RepositoryTaskData existingReport)
+ // throws IOException, KeyManagementException, GeneralSecurityException,
+ // BugzillaException, CoreException {
+ //
+ // RepositoryConfiguration configuration =
+ // BugzillaCorePlugin.getDefault().getRepositoryConfiguration(taskRepository,
+ // false);
+ // if (configuration == null)
+ // return;
+ // String product =
+ // existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
+ // for (RepositoryTaskAttribute attribute : existingReport.getAttributes())
+ // {
+ // BugzillaReportElement element =
+ // BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
+ // attribute.clearOptions();
+ // String key = attribute.getID();
+ // if (!product.equals("")) {
+ // switch (element) {
+ // case TARGET_MILESTONE:
+ // case VERSION:
+ // case COMPONENT:
+ // key = product + "." + key;
+ // }
+ // }
+ //
+ // List<String> optionValues = configuration.getAttributeValues(key);
+ // if(optionValues.size() == 0) {
+ // optionValues = configuration.getAttributeValues(attribute.getID());
+ // }
+ //
+ // if (element != BugzillaReportElement.OP_SYS && element !=
+ // BugzillaReportElement.BUG_SEVERITY
+ // && element != BugzillaReportElement.PRIORITY && element !=
+ // BugzillaReportElement.BUG_STATUS) {
+ // Collections.sort(optionValues);
+ // }
+ // if (element == BugzillaReportElement.TARGET_MILESTONE &&
+ // optionValues.isEmpty()) {
+ // existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
+ // continue;
+ // }
+ // for (String option : optionValues) {
+ // attribute.addOptionValue(option, option);
+ // }
+ // }
+ // }
+
+ // /**
+ // * Adds bug attributes to new bug model and sets defaults TODO: Make
+ // generic
+ // * and move TaskRepositoryManager
+ // */
+ // public void setupNewBugAttributes(TaskRepository taskRepository,
+ // NewBugzillaReport newReport) throws CoreException {
+ //
+ // newReport.removeAllAttributes();
+ //
+ // RepositoryConfiguration repositoryConfiguration =
+ // BugzillaCorePlugin.getDefault().getRepositoryConfiguration(
+ // taskRepository, false);
+ //
+ // RepositoryTaskAttribute a =
+ // BugzillaClient.makeNewAttribute(BugzillaReportElement.PRODUCT);
+ // List<String> optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.PRODUCT
+ // .getKeyString());
+ // Collections.sort(optionValues);
+ // // for (String option : optionValues) {
+ // // a.addOptionValue(option, option);
+ // // }
+ // a.setValue(newReport.getProduct());
+ // a.setReadOnly(true);
+ // newReport.addAttribute(BugzillaReportElement.PRODUCT.getKeyString(), a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_STATUS);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.BUG_STATUS.getKeyString());
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // a.setValue(IBugzillaConstants.VALUE_STATUS_NEW);
+ // newReport.addAttribute(BugzillaReportElement.BUG_STATUS.getKeyString(),
+ // a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.VERSION);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.VERSION.getKeyString());
+ // Collections.sort(optionValues);
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // if (optionValues != null && optionValues.size() > 0) {
+ // a.setValue(optionValues.get(optionValues.size() - 1));
+ // }
+ // newReport.addAttribute(BugzillaReportElement.VERSION.getKeyString(), a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.COMPONENT);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.COMPONENT.getKeyString());
+ // Collections.sort(optionValues);
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // if (optionValues != null && optionValues.size() > 0) {
+ // a.setValue(optionValues.get(0));
+ // }
+ // newReport.addAttribute(BugzillaReportElement.COMPONENT.getKeyString(),
+ // a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.REP_PLATFORM);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.REP_PLATFORM.getKeyString());
+ // Collections.sort(optionValues);
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // if (optionValues != null && optionValues.size() > 0) {
+ // a.setValue(optionValues.get(0));
+ // }
+ // newReport.addAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString(),
+ // a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.OP_SYS);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.OP_SYS.getKeyString());
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // if (optionValues != null && optionValues.size() > 0) {
+ // a.setValue(optionValues.get(optionValues.size() - 1));
+ // }
+ // newReport.addAttribute(BugzillaReportElement.OP_SYS.getKeyString(), a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.PRIORITY);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.PRIORITY.getKeyString());
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // a.setValue(optionValues.get((optionValues.size() / 2)));
+ // newReport.addAttribute(BugzillaReportElement.PRIORITY.getKeyString(), a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_SEVERITY);
+ // optionValues =
+ // repositoryConfiguration.getAttributeValues(BugzillaReportElement.BUG_SEVERITY.getKeyString());
+ // for (String option : optionValues) {
+ // a.addOptionValue(option, option);
+ // }
+ // a.setValue(optionValues.get((optionValues.size() / 2)));
+ // newReport.addAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString(),
+ // a);
+ // // attributes.put(a.getName(), a);
+ //
+ // // a = new
+ // // RepositoryTaskAttribute(BugzillaReportElement.TARGET_MILESTONE);
+ // // optionValues =
+ // //
+ // BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(
+ // // newReport.getProduct());
+ // // for (String option : optionValues) {
+ // // a.addOptionValue(option, option);
+ // // }
+ // // if(optionValues.size() > 0) {
+ // // // new bug posts will fail if target_milestone element is included
+ // // // and there are no milestones on the server
+ // // newReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE, a);
+ // // }
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.ASSIGNED_TO);
+ // a.setValue("");
+ // a.setReadOnly(false);
+ // newReport.addAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString(),
+ // a);
+ // // attributes.put(a.getName(), a);
+ //
+ // a = BugzillaClient.makeNewAttribute(BugzillaReportElement.BUG_FILE_LOC);
+ // a.setValue("http://");
+ // a.setHidden(false);
+ // newReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC.getKeyString(),
+ // a);
+ // // attributes.put(a.getName(), a);
+ //
+ // // newReport.attributes = attributes;
+ // }
+
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java
deleted file mode 100644
index bdb797ce5..000000000
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaServerFacade.java
+++ /dev/null
@@ -1,717 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003 - 2006 University Of British Columbia and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * University Of British Columbia - initial API and implementation
- *******************************************************************************/
-package org.eclipse.mylar.internal.bugzilla.core;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.Proxy;
-import java.net.URL;
-import java.net.URLEncoder;
-import java.nio.charset.Charset;
-import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-import java.text.ParseException;
-import java.util.Collections;
-import java.util.List;
-
-import javax.security.auth.login.LoginException;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_OPERATION;
-import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_REPORT_STATUS;
-import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants.BUGZILLA_RESOLUTION;
-import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer;
-import org.eclipse.mylar.internal.tasks.core.HtmlTag;
-import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException;
-import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
-import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer.Token;
-import org.eclipse.mylar.tasks.core.RepositoryOperation;
-import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
-import org.eclipse.mylar.tasks.core.RepositoryTaskData;
-
-/**
- * @author Mik Kersten
- * @author Rob Elves
- */
-public class BugzillaServerFacade {
-
- private static final String ATTR_CHARSET = "charset";
-
- private static final String OPERATION_INPUT_ASSIGNED_TO = "assigned_to";
-
- private static final String OPERATION_INPUT_DUP_ID = "dup_id";
-
- private static final String OPERATION_OPTION_RESOLUTION = "resolution";
-
- private static final String OPERATION_LABEL_CLOSE = "Mark as CLOSED";
-
- private static final String OPERATION_LABEL_VERIFY = "Mark as VERIFIED";
-
- private static final String OPERATION_LABEL_REOPEN = "Reopen bug";
-
- private static final String OPERATION_LABEL_REASSIGN_DEFAULT = "Reassign to default assignee";
-
- private static final String OPERATION_LABEL_REASSIGN = "Reassign to";
-
- private static final String OPERATION_LABEL_DUPLICATE = "Mark as duplicate of #";
-
- private static final String OPERATION_LABEL_RESOLVE = "Resolve as";
-
- private static final String OPERATION_LABEL_ACCEPT = "Accept (change status to ASSIGNED)";
-
- private static final BugzillaAttributeFactory attributeFactory = new BugzillaAttributeFactory();
-
- public static RepositoryTaskData getBug(String repositoryUrl, String userName, String password,
- Proxy proxySettings, String characterEncoding, int id) throws IOException, MalformedURLException,
- LoginException, GeneralSecurityException, BugzillaException {
-
- // bug 154729
- // MylarStatusHandler.log("Retrieving task data from: " + repositoryUrl,
- // BugzillaServerFacade.class);
-
- RepositoryTaskData bugReport = new RepositoryTaskData(new BugzillaAttributeFactory(),
- BugzillaCorePlugin.REPOSITORY_KIND, repositoryUrl, "" + id);
- setupExistingBugAttributes(repositoryUrl, bugReport);
-
- RepositoryReportFactory reportFactory = new RepositoryReportFactory();
- reportFactory.populateReport(bugReport, repositoryUrl, proxySettings, userName, password, characterEncoding);
- updateBugAttributeOptions(repositoryUrl, proxySettings, userName, password, bugReport, characterEncoding);
- addValidOperations(bugReport, userName);
-
- return bugReport;
- }
-
- public static String addCredentials(String url, String encoding, String userName, String password)
- throws UnsupportedEncodingException {
- if ((userName != null && userName.length() > 0) && (password != null && password.length() > 0)) {
- if(encoding == null) {
- encoding = IBugzillaConstants.ENCODING_UTF_8;
- }
- url += "&" + IBugzillaConstants.POST_ARGS_LOGIN + URLEncoder.encode(userName, encoding)
- + IBugzillaConstants.POST_ARGS_PASSWORD + URLEncoder.encode(password, encoding);
- }
- return url;
- }
-
- /**
- * Get the list of products
- *
- * @param proxySettings
- * TODO
- * @param encoding
- * TODO
- *
- * @return The list of valid products a bug can be logged against
- * @throws IOException
- * LoginException Exception
- */
- public static List<String> getProductList(String repositoryUrl, Proxy proxySettings, String userName,
- String password, String encoding) throws IOException, LoginException, Exception {
-
- return BugzillaCorePlugin.getRepositoryConfiguration(false, repositoryUrl, proxySettings, userName, password,
- encoding).getProducts();
-
- // BugzillaQueryPageParser parser = new
- // BugzillaQueryPageParser(repository, new NullProgressMonitor());
- // if (!parser.wasSuccessful()) {
- // throw new RuntimeException("Couldn't get products");
- // } else {
- // return Arrays.asList(parser.getProductValues());
- // }
-
- }
-
- // TODO: improve and move to repository connector?
- public static void validateCredentials(Proxy proxySettings, String repositoryUrl, String encoding, String userid,
- String password) throws IOException, BugzillaException, KeyManagementException, GeneralSecurityException {
-
- proxySettings = proxySettings == null ? Proxy.NO_PROXY : proxySettings;
-
- String url = repositoryUrl + "/index.cgi?" + IBugzillaConstants.POST_ARGS_LOGIN
- + URLEncoder.encode(userid, encoding) + IBugzillaConstants.POST_ARGS_PASSWORD
- + URLEncoder.encode(password, encoding);
-
- // For bug#160360
- // MylarStatusHandler.log("VALIDATING: " + url, BugzillaServerFacade.class);
-
- URL serverURL = new URL(url);
- HttpURLConnection serverConnection = WebClientUtil.openUrlConnection(serverURL, proxySettings, false);
- BufferedReader in = new BufferedReader(new InputStreamReader(serverConnection.getInputStream()));
- try {
- parseHtmlError(in);
- } catch (UnrecognizedReponseException e) {
- return;
- }
- }
-
- /**
- * Utility method for determining what potential error has occurred from a
- * bugzilla html reponse page
- *
- * @throws CoreException
- */
- public static void parseHtmlError(BufferedReader in) throws IOException, LoginException, BugzillaException {
- HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(in, null);
-
- boolean isTitle = false;
- String title = "";
- String body = "";
-
- try {
-
- for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) {
- body += token.toString();
- if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.TITLE
- && !((HtmlTag) (token.getValue())).isEndTag()) {
- isTitle = true;
- continue;
- }
-
- if (isTitle) {
- // get all of the data in the title tag
- if (token.getType() != Token.TAG) {
- title += ((StringBuffer) token.getValue()).toString().toLowerCase() + " ";
- continue;
- } else if (token.getType() == Token.TAG
- && ((HtmlTag) token.getValue()).getTagType() == HtmlTag.Type.TITLE
- && ((HtmlTag) token.getValue()).isEndTag()) {
-
- if (title.indexOf("login") != -1 || title.indexOf("log in") != -1
- || (title.indexOf("invalid") != -1 && title.indexOf("password") != -1)
- || title.indexOf("check e-mail") != -1) {
- // MylarStatusHandler.log("Login Error: "+body,
- // BugzillaServerFacade.class);
- throw new LoginException(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD);
- } else if (title.indexOf(IBugzillaConstants.ERROR_MIDAIR_COLLISION) != -1) {
- throw new BugzillaException(IBugzillaConstants.ERROR_MSG_MIDAIR_COLLISION);
- } else if (title.indexOf(IBugzillaConstants.ERROR_COMMENT_REQUIRED) != -1) {
- throw new BugzillaException(IBugzillaConstants.ERROR_MSG_COMMENT_REQUIRED);
- }
- }
- }
- }
-
- throw new UnrecognizedReponseException(body);
-
- } catch (ParseException e) {
- throw new IOException("Unable to parse result from repository:\n" + e.getMessage());
- }
- }
-
- /**
- * Adds bug attributes to new bug model and sets defaults
- *
- * @param proxySettings
- * TODO
- * @param characterEncoding
- * TODO
- *
- * @throws IOException
- * @throws NoSuchAlgorithmException
- * @throws LoginException
- * @throws KeyManagementException
- * @throws BugzillaException
- */
- public static void setupNewBugAttributes(String repositoryUrl, Proxy proxySettings, String userName,
- String password, NewBugzillaReport newReport, String characterEncoding) throws IOException,
- KeyManagementException, GeneralSecurityException, NoSuchAlgorithmException, BugzillaException {
-
- newReport.removeAllAttributes();
-
- RepositoryConfiguration repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration(false,
- repositoryUrl, proxySettings, userName, password, characterEncoding);
-
- RepositoryTaskAttribute a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.PRODUCT);
- List<String> optionValues = repositoryConfiguration.getProducts();
- Collections.sort(optionValues);
- // for (String option : optionValues) {
- // a.addOptionValue(option, option);
- // }
- a.setValue(newReport.getProduct());
- a.setReadOnly(true);
- newReport.addAttribute(BugzillaReportElement.PRODUCT.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.BUG_STATUS);
- optionValues = repositoryConfiguration.getStatusValues();
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- a.setValue(IBugzillaConstants.VALUE_STATUS_NEW);
- newReport.addAttribute(BugzillaReportElement.BUG_STATUS.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.VERSION);
- optionValues = repositoryConfiguration.getVersions(newReport.getProduct());
- Collections.sort(optionValues);
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- if (optionValues != null && optionValues.size() > 0) {
- a.setValue(optionValues.get(optionValues.size() - 1));
- }
- newReport.addAttribute(BugzillaReportElement.VERSION.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.COMPONENT);
- optionValues = repositoryConfiguration.getComponents(newReport.getProduct());
- Collections.sort(optionValues);
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- if (optionValues != null && optionValues.size() > 0) {
- a.setValue(optionValues.get(0));
- }
- newReport.addAttribute(BugzillaReportElement.COMPONENT.getKeyString(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.REP_PLATFORM);
- optionValues = repositoryConfiguration.getPlatforms();
- Collections.sort(optionValues);
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- if (optionValues != null && optionValues.size() > 0) {
- a.setValue(optionValues.get(0));
- }
- newReport.addAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.OP_SYS);
- optionValues = repositoryConfiguration.getOSs();
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- if (optionValues != null && optionValues.size() > 0) {
- a.setValue(optionValues.get(optionValues.size() - 1));
- }
- newReport.addAttribute(BugzillaReportElement.OP_SYS.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.PRIORITY);
- optionValues = repositoryConfiguration.getPriorities();
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- a.setValue(optionValues.get((optionValues.size() / 2)));
- newReport.addAttribute(BugzillaReportElement.PRIORITY.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.BUG_SEVERITY);
- optionValues = repositoryConfiguration.getSeverities();
- for (String option : optionValues) {
- a.addOptionValue(option, option);
- }
- a.setValue(optionValues.get((optionValues.size() / 2)));
- newReport.addAttribute(BugzillaReportElement.BUG_SEVERITY.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- // a = new
- // RepositoryTaskAttribute(BugzillaReportElement.TARGET_MILESTONE);
- // optionValues =
- // BugzillaPlugin.getDefault().getProductConfiguration(serverUrl).getTargetMilestones(
- // newReport.getProduct());
- // for (String option : optionValues) {
- // a.addOptionValue(option, option);
- // }
- // if(optionValues.size() > 0) {
- // // new bug posts will fail if target_milestone element is included
- // // and there are no milestones on the server
- // newReport.addAttribute(BugzillaReportElement.TARGET_MILESTONE, a);
- // }
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.ASSIGNED_TO);
- a.setValue("");
- a.setReadOnly(false);
- newReport.addAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- a = BugzillaServerFacade.makeNewAttribute(BugzillaReportElement.BUG_FILE_LOC);
- a.setValue("http://");
- a.setHidden(false);
- newReport.addAttribute(BugzillaReportElement.BUG_FILE_LOC.getKeyString(), a);
- // attributes.put(a.getName(), a);
-
- // newReport.attributes = attributes;
- }
-
- public static void setupExistingBugAttributes(String serverUrl, RepositoryTaskData existingReport) {
- // ordered list of elements as they appear in UI
- // and additional elements that may not appear in the incoming xml
- // stream but need to be present for bug submission
- BugzillaReportElement[] reportElements = { BugzillaReportElement.BUG_STATUS, BugzillaReportElement.RESOLUTION,
- BugzillaReportElement.BUG_ID, BugzillaReportElement.REP_PLATFORM, BugzillaReportElement.PRODUCT,
- BugzillaReportElement.OP_SYS, BugzillaReportElement.COMPONENT, BugzillaReportElement.VERSION,
- BugzillaReportElement.PRIORITY, BugzillaReportElement.BUG_SEVERITY, BugzillaReportElement.ASSIGNED_TO,
- BugzillaReportElement.TARGET_MILESTONE, BugzillaReportElement.REPORTER,
- BugzillaReportElement.DEPENDSON, BugzillaReportElement.BLOCKED, BugzillaReportElement.BUG_FILE_LOC,
- BugzillaReportElement.NEWCC, BugzillaReportElement.KEYWORDS }; // BugzillaReportElement.VOTES,
-
- for (BugzillaReportElement element : reportElements) {
- RepositoryTaskAttribute reportAttribute = BugzillaServerFacade.makeNewAttribute(element);
- existingReport.addAttribute(element.getKeyString(), reportAttribute);
- }
- }
-
- public static void updateBugAttributeOptions(String repositoryUrl, Proxy proxySettings, String userName,
- String password, RepositoryTaskData existingReport, String characterEncoding) throws IOException,
- KeyManagementException, GeneralSecurityException, BugzillaException {
- String product = existingReport.getAttributeValue(BugzillaReportElement.PRODUCT.getKeyString());
- for (RepositoryTaskAttribute attribute : existingReport.getAttributes()) {
- BugzillaReportElement element = BugzillaReportElement.valueOf(attribute.getID().trim().toUpperCase());
- attribute.clearOptions();
- List<String> optionValues = BugzillaCorePlugin.getRepositoryConfiguration(false, repositoryUrl,
- proxySettings, userName, password, characterEncoding).getOptionValues(element, product);
- if (element != BugzillaReportElement.OP_SYS && element != BugzillaReportElement.BUG_SEVERITY
- && element != BugzillaReportElement.PRIORITY && element != BugzillaReportElement.BUG_STATUS) {
- Collections.sort(optionValues);
- }
- if (element == BugzillaReportElement.TARGET_MILESTONE && optionValues.isEmpty()) {
- existingReport.removeAttribute(BugzillaReportElement.TARGET_MILESTONE);
- continue;
- }
- for (String option : optionValues) {
- attribute.addOptionValue(option, option);
- }
- }
-
- }
-
- public static void addValidOperations(RepositoryTaskData bugReport, String userName) {
- BUGZILLA_REPORT_STATUS status = BUGZILLA_REPORT_STATUS.valueOf(bugReport.getStatus());
- switch (status) {
- case UNCONFIRMED:
- case REOPENED:
- case NEW:
- addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.accept, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent, userName);
- break;
- case ASSIGNED:
- addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.resolve, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.duplicate, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reassign, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reassignbycomponent, userName);
- break;
- case RESOLVED:
- addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.verify, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
- break;
- case CLOSED:
- addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
- break;
- case VERIFIED:
- addOperation(bugReport, BUGZILLA_OPERATION.none, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.reopen, userName);
- addOperation(bugReport, BUGZILLA_OPERATION.close, userName);
- }
- }
-
- public static void addOperation(RepositoryTaskData bugReport, BUGZILLA_OPERATION opcode, String userName) {
- RepositoryOperation newOperation = null;
- switch (opcode) {
- case none:
- newOperation = new RepositoryOperation(opcode.toString(), "Leave as " + bugReport.getStatus() + " "
- + bugReport.getResolution());
- newOperation.setChecked(true);
- break;
- case accept:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_ACCEPT);
- break;
- case resolve:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_RESOLVE);
- newOperation.setUpOptions(OPERATION_OPTION_RESOLUTION);
- for (BUGZILLA_RESOLUTION resolution : BUGZILLA_RESOLUTION.values()) {
- newOperation.addOption(resolution.toString(), resolution.toString());
- }
- break;
- case duplicate:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_DUPLICATE);
- newOperation.setInputName(OPERATION_INPUT_DUP_ID);
- newOperation.setInputValue("");
- break;
- case reassign:
- String localUser = userName;
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REASSIGN);
- newOperation.setInputName(OPERATION_INPUT_ASSIGNED_TO);
- newOperation.setInputValue(localUser);
- break;
- case reassignbycomponent:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REASSIGN_DEFAULT);
- break;
- case reopen:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_REOPEN);
- break;
- case verify:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_VERIFY);
- break;
- case close:
- newOperation = new RepositoryOperation(opcode.toString(), OPERATION_LABEL_CLOSE);
- break;
- default:
- break;
- // MylarStatusHandler.log("Unknown bugzilla operation code recieved",
- // BugzillaRepositoryUtil.class);
- }
- if (newOperation != null) {
- bugReport.addOperation(newOperation);
- }
- }
-
- // public static String getBugUrl(String repositoryUrl, int id, String
- // userName, String password) {
- //
- // String url = repositoryUrl + IBugzillaConstants.POST_ARGS_SHOW_BUG + id;
- // try {
- // url = addCredentials(url, userName, password);
- // } catch (UnsupportedEncodingException e) {
- // return "";
- // }
- // return url;
- // }
-
- public static String getBugUrlWithoutLogin(String repositoryUrl, int id) {
- String url = repositoryUrl + IBugzillaConstants.POST_ARGS_SHOW_BUG + id;
- return url;
- }
-
- public static String getCharsetFromString(String string) {
- int charsetStartIndex = string.indexOf(ATTR_CHARSET);
- if (charsetStartIndex != -1) {
- int charsetEndIndex = string.indexOf("\"", charsetStartIndex); // TODO:
- // could
- // be
- // space
- // after?
- if (charsetEndIndex == -1) {
- charsetEndIndex = string.length();
- }
- String charsetString = string.substring(charsetStartIndex + 8, charsetEndIndex);
- if (Charset.availableCharsets().containsKey(charsetString)) {
- return charsetString;
- }
- }
- return null;
- }
-
- protected static RepositoryTaskAttribute makeNewAttribute(
- org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement tag) {
- return attributeFactory.createAttribute(tag.getKeyString());
- }
-
-}
-
-// public static String decodeStringFromCharset(String string, String
-// charset) throws UnsupportedEncodingException {
-// String decoded = string;
-// if (charset != null && string != null &&
-// Charset.availableCharsets().containsKey(charset)) {
-// decoded = new String(string.getBytes(), charset);
-// }
-// return decoded;
-// }
-
-// public synchronized static BugzillaRepositoryUtil getInstance() {
-// if (instance == null) {
-// // if the instance hasn't been created yet, create one
-// instance = new
-// BugzillaRepositoryUtil(BugzillaPlugin.getDefault().getServerName());
-// }
-//
-// if
-// (!BugzillaRepositoryUtil.bugzillaUrl.equals(BugzillaPlugin.getDefault().getServerName()))
-// {
-// BugzillaRepositoryUtil.bugzillaUrl =
-// BugzillaPlugin.getDefault().getServerName();
-// }
-// return INSTANCE;
-// }
-// /**
-// * Test method.
-// */
-// public static void main(String[] args) throws Exception {
-// instance = new
-// BugzillaRepositoryUtil(BugzillaPlugin.getDefault().getServerName() +
-// "/long_list.cgi?buglist=");
-// BugReport bug = instance.getBug(16161);
-// System.out.println("Bug " + bug.getId() + ": " + bug.getSummary());
-// for (Iterator<Attribute> it = bug.getAttributes().iterator(); it.hasNext();)
-// {
-// Attribute attribute = it.next();
-// System.out.println(attribute.getName() + ": " + attribute.getValue());
-// }
-// System.out.println(bug.getDescription());
-// for (Iterator<Comment> it = bug.getComments().iterator(); it.hasNext();) {
-// Comment comment = it.next();
-// System.out
-// .println(comment.getAuthorName() + "<" + comment.getAuthor() + "> (" +
-// comment.getCreated() + ")");
-// System.out.print(comment.getText());
-// System.out.println();
-// }
-// }
-// /** URL of the Bugzilla server */
-// private static String bugzillaUrl;
-// private static BugzillaRepositoryUtil INSTANCE = new
-// BugzillaRepositoryUtil();
-// public static List<String> getValidKeywords(String repositoryURL) {
-// return
-// BugzillaPlugin.getDefault().getProductConfiguration(repositoryURL).getKeywords();
-// }
-// /**
-// * Get the attribute values for a new bug
-// *
-// * @param nbm
-// * A reference to a NewBugModel to store all of the data
-// * @throws Exception
-// */
-// public static void setupNewBugAttributes(String serverUrl, NewBugModel
-// nbm, boolean getProd) throws Exception {
-// BufferedReader in = null;
-// try {
-// // create a new input stream for getting the bug
-// String prodname = URLEncoder.encode(nbm.getProduct(),
-// BugzillaPlugin.ENCODING_UTF_8);
-//
-// TaskRepository repository =
-// MylarTaskListPlugin.getRepositoryManager().getRepository(
-// BugzillaPlugin.REPOSITORY_KIND, serverUrl);
-//
-// if (repository == null) {
-// throw new LoginException("Repository configuration error.");
-// }
-// if (repository.getUserName() == null ||
-// repository.getUserName().trim().equals("")
-// || repository.getPassword() == null) {
-// throw new LoginException("Login credentials missing.");
-// }
-//
-// String url = repository.getUrl() + "/enter_bug.cgi";
-//
-// // use the proper url if we dont know the product yet
-// if (!getProd)
-// url += "?product=" + prodname + "&";
-// else
-// url += "?";
-//
-// url += POST_ARGS_LOGIN + URLEncoder.encode(repository.getUserName(),
-// BugzillaPlugin.ENCODING_UTF_8)
-// + POST_ARGS_PASSWORD + URLEncoder.encode(repository.getPassword(),
-// BugzillaPlugin.ENCODING_UTF_8);
-//
-// URL bugUrl = new URL(url);
-// URLConnection cntx =
-// BugzillaPlugin.getDefault().getUrlConnection(bugUrl);
-// if (cntx != null) {
-// InputStream input = cntx.getInputStream();
-// if (input != null) {
-// in = new BufferedReader(new InputStreamReader(input));
-//
-// new NewBugParser(in).parseBugAttributes(nbm, getProd);
-// }
-// }
-//
-// } catch (Exception e) {
-//
-// if (e instanceof KeyManagementException || e instanceof
-// NoSuchAlgorithmException
-// || e instanceof IOException) {
-// if (MessageDialog.openQuestion(null, "Bugzilla Connect Error",
-// "Unable to connect to Bugzilla server.\n"
-// + "Bug report will be created offline and saved for submission later."))
-// {
-// nbm.setConnected(false);
-// setupBugAttributes(serverUrl, nbm);
-// } else
-// throw new Exception("Bug report will not be created.");
-// } else
-// throw e;
-// } finally {
-// try {
-// if (in != null)
-// in.close();
-// } catch (IOException e) {
-// BugzillaPlugin.log(new Status(IStatus.ERROR,
-// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
-// "Problem closing the stream", e));
-// }
-// }
-// }
-// public static boolean downloadAttachment(TaskRepository repository, int
-// id, File destinationFile, boolean overwrite)
-// throws IOException {
-// BufferedReader in = null;
-// try {
-// String url = repository.getUrl() + POST_ARGS_ATTACHMENT_DOWNLOAD + id;
-// if (repository.hasCredentials()) {
-// url += "&" + POST_ARGS_LOGIN
-// + URLEncoder.encode(repository.getUserName(),
-// BugzillaPlugin.ENCODING_UTF_8)
-// + POST_ARGS_PASSWORD
-// + URLEncoder.encode(repository.getPassword(),
-// BugzillaPlugin.ENCODING_UTF_8);
-// }
-// URL downloadUrl = new URL(url);
-// URLConnection connection =
-// BugzillaPlugin.getDefault().getUrlConnection(downloadUrl);
-// if (connection != null) {
-// InputStream input = connection.getInputStream();
-// if (input != null) {
-// in = new BufferedReader(new InputStreamReader(input));
-// if (destinationFile.exists() && !overwrite) {
-// return false;
-// }
-// destinationFile.createNewFile();
-// OutputStreamWriter outputStream = new OutputStreamWriter(new
-// FileOutputStream(destinationFile));
-// BufferedWriter out = new BufferedWriter(outputStream);
-// char[] buf = new char[1024];
-// int len;
-// while ((len = in.read(buf)) > 0) {
-// out.write(buf, 0, len);
-// }
-// in.close();
-// out.close();
-// return true;
-// }
-// }
-// } catch (MalformedURLException e) {
-// throw e;
-// } catch (IOException e) {
-// throw e;
-// } catch (Exception e) {
-// BugzillaPlugin.log(new Status(IStatus.ERROR,
-// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
-// "Problem retrieving attachment", e));
-// return false;
-// } finally {
-// try {
-// if (in != null)
-// in.close();
-// } catch (IOException e) {
-// BugzillaPlugin.log(new Status(IStatus.ERROR,
-// IBugzillaConstants.PLUGIN_ID, IStatus.ERROR,
-// "Problem closing the stream", e));
-// }
-// }
-// return false;
-// }
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTask.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTask.java
index d1a8afeb7..8b4be4ede 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTask.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaTask.java
@@ -49,7 +49,7 @@ public class BugzillaTask extends AbstractRepositoryTask {
String id = AbstractRepositoryTask.getTaskId(getHandleIdentifier());
String repositoryUrl = getRepositoryUrl();
try {
- String url = BugzillaServerFacade.getBugUrlWithoutLogin(repositoryUrl, Integer.parseInt(id));
+ String url = BugzillaClient.getBugUrlWithoutLogin(repositoryUrl, Integer.parseInt(id));
if (url != null) {
super.setUrl(url);
}
@@ -92,7 +92,7 @@ public class BugzillaTask extends AbstractRepositoryTask {
// fix for bug 103537 - should login automatically, but dont want to
// show the login info in the query string
try {
- return BugzillaServerFacade.getBugUrlWithoutLogin(getRepositoryUrl(), Integer
+ return BugzillaClient.getBugUrlWithoutLogin(getRepositoryUrl(), Integer
.parseInt(AbstractRepositoryTask.getTaskId(handle)));
} catch (NumberFormatException nfe) {
return super.getUrl();
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java
index 68b2c340c..b021f58f8 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/IBugzillaConstants.java
@@ -24,6 +24,8 @@ public interface IBugzillaConstants {
static final String ERROR_MSG_COMMENT_REQUIRED = "You have to specify a new comment when making this change. Please comment on the reason for this change.";
static final String ERROR_INVALID_USERNAME_OR_PASSWORD = "Invalid Username or Password";
+
+ static final String LOGGED_OUT = "logged out";
static final String MOST_RECENT_QUERY = "org.eclipse.mylar.bugzilla.query.last";
@@ -51,6 +53,8 @@ public interface IBugzillaConstants {
public static final String POST_ARGS_LOGIN = "GoAheadAndLogIn=1&Bugzilla_login=";
+ public static final String POST_CONFIG_RDF_URL = "/config.cgi?ctype=rdf";
+
public static final String XML_ERROR_INVALIDBUGID = "invalidbugid";
public static final String XML_ERROR_NOTFOUND = "notfound";
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
index 7c0ccd02b..0c5c73384 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfigurationFactory.java
@@ -12,8 +12,7 @@
package org.eclipse.mylar.internal.bugzilla.core;
import java.io.IOException;
-import java.net.Proxy;
-import java.net.URL;
+import java.io.InputStream;
import java.security.GeneralSecurityException;
import org.xml.sax.ErrorHandler;
@@ -27,19 +26,14 @@ import org.xml.sax.SAXParseException;
*/
public class RepositoryConfigurationFactory extends AbstractReportFactory {
- private static final String CONFIG_RDF_URL = "/config.cgi?ctype=rdf";
+ public RepositoryConfigurationFactory(InputStream inStream, String encoding) {
+ super(inStream, encoding);
+ }
- public RepositoryConfiguration getConfiguration(String repositoryUrl, Proxy proxySettings, String userName,
- String password, String encoding) throws IOException, BugzillaException, GeneralSecurityException {
- String configUrlStr = repositoryUrl + CONFIG_RDF_URL;
- configUrlStr = BugzillaServerFacade.addCredentials(configUrlStr, encoding, userName, password);
- URL url = new URL(configUrlStr);
+ public RepositoryConfiguration getConfiguration() throws IOException, BugzillaException, GeneralSecurityException {
SaxConfigurationContentHandler contentHandler = new SaxConfigurationContentHandler();
- collectResults(url, proxySettings, encoding, contentHandler, true);
+ collectResults(contentHandler, true);
RepositoryConfiguration config = contentHandler.getConfiguration();
- if (config != null) {
- config.setRepositoryUrl(repositoryUrl);
- }
return config;
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java
index b3015a601..4a7f65999 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryQueryResultsFactory.java
@@ -12,8 +12,7 @@
package org.eclipse.mylar.internal.bugzilla.core;
import java.io.IOException;
-import java.net.Proxy;
-import java.net.URL;
+import java.io.InputStream;
import java.security.GeneralSecurityException;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
@@ -25,14 +24,16 @@ import org.eclipse.mylar.tasks.core.TaskList;
*/
public class RepositoryQueryResultsFactory extends AbstractReportFactory {
+ public RepositoryQueryResultsFactory(InputStream inStream, String encoding) {
+ super(inStream, encoding);
+ }
+
/** expects rdf returned from repository (ctype=rdf in url)
* @throws GeneralSecurityException */
- public void performQuery(TaskList taskList, String repositoryUrl, QueryHitCollector collector, String queryUrlString,
- Proxy proxySettings, int maxHits, String characterEncoding) throws IOException, BugzillaException, GeneralSecurityException {
+ public void performQuery(TaskList taskList, String repositoryUrl, QueryHitCollector collector, int maxHits) throws IOException, BugzillaException, GeneralSecurityException {
SaxBugzillaQueryContentHandler contentHandler = new SaxBugzillaQueryContentHandler(taskList, repositoryUrl,
- collector, maxHits);
- URL url = new URL(queryUrlString);
- collectResults(url, proxySettings, characterEncoding, contentHandler, false);
+ collector, maxHits);
+ collectResults(contentHandler, false);
}
}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryReportFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryReportFactory.java
index 87319d915..af4948dff 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryReportFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryReportFactory.java
@@ -12,8 +12,7 @@
package org.eclipse.mylar.internal.bugzilla.core;
import java.io.IOException;
-import java.net.Proxy;
-import java.net.URL;
+import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -27,19 +26,24 @@ import org.eclipse.mylar.tasks.core.RepositoryTaskData;
*/
public class RepositoryReportFactory extends AbstractReportFactory {
+ public RepositoryReportFactory(InputStream inStream, String encoding) {
+ super(inStream, encoding);
+ }
+
private static BugzillaAttributeFactory bugzillaAttributeFactory = new BugzillaAttributeFactory();
- public void populateReport(RepositoryTaskData bugReport, String repositoryUrl, Proxy proxySettings,
- String userName, String password, String characterEncoding) throws GeneralSecurityException,
+ public void populateReport(RepositoryTaskData bugReport) throws GeneralSecurityException,
KeyManagementException, NoSuchAlgorithmException, IOException, BugzillaException {
SaxBugReportContentHandler contentHandler = new SaxBugReportContentHandler(bugzillaAttributeFactory, bugReport);
- String xmlBugReportUrl = repositoryUrl + IBugzillaConstants.SHOW_BUG_CGI_XML + bugReport.getId();
- xmlBugReportUrl = BugzillaServerFacade.addCredentials(xmlBugReportUrl, characterEncoding, userName, password);
- URL serverURL = new URL(xmlBugReportUrl);
+// String xmlBugReportUrl = repositoryUrl + IBugzillaConstants.SHOW_BUG_CGI_XML + bugReport.getId();
+// xmlBugReportUrl = BugzillaClient.addCredentials(xmlBugReportUrl, characterEncoding, userName, password);
+// URL serverURL = new URL(xmlBugReportUrl);
- collectResults(serverURL, proxySettings, characterEncoding, contentHandler, false);
+
+
+ collectResults(contentHandler, false);
if (contentHandler.errorOccurred()) {
String errorResponse = contentHandler.getErrorMessage().toLowerCase();
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java
index 5497ac5e7..305663c10 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxBugReportContentHandler.java
@@ -68,7 +68,7 @@ public class SaxBugReportContentHandler extends DefaultHandler {
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
- characters.append(ch, start, length);
+ characters.append(ch, start, length);
// if (monitor.isCanceled()) {
// throw new OperationCanceledException("Search cancelled");
// }
@@ -251,7 +251,7 @@ public class SaxBugReportContentHandler extends DefaultHandler {
}
break;
// All others added as report attribute
- default:
+ default:
RepositoryTaskAttribute attribute = report.getAttribute(tag.getKeyString());
if (attribute == null) {
attribute = attributeFactory.createAttribute(tag.getKeyString());
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
index 7729a5af5..d65aae6e1 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java
@@ -143,54 +143,67 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
case IN_PRODUCTS | IN_LI | IN_NAME:
configuration.addProduct(String.copyValueOf(ch, start, length));
+ //configuration.addAttributeValue(BugzillaReportElement.PRODUCT.getKeyString(), String.copyValueOf(ch, start, length));
currentProduct = String.copyValueOf(ch, start, length);
break;
case IN_COMPONENTS | IN_LI | IN_COMPONENT | IN_NAME:
+ String comp = String.copyValueOf(ch, start, length);
if (about != null) {
- String name = String.copyValueOf(ch, start, length);
- componentNames.put(about, name);
+ componentNames.put(about, comp);
// System.err.println("Component: "+about+" ---> "+name);
- }
+ }
+ //configuration.addAttributeValue(BugzillaReportElement.COMPONENT.getKeyString(), comp);
break;
case IN_VERSIONS | IN_LI | IN_VERSION | IN_NAME:
- if (about != null) {
- String name = String.copyValueOf(ch, start, length);
- versionNames.put(about, name);
+ String ver = String.copyValueOf(ch, start, length);
+ if (about != null) {
+ versionNames.put(about, ver);
// System.err.println("Version: "+about+" ---> "+name);
}
+ //configuration.addAttributeValue(BugzillaReportElement.VERSION.getKeyString(), ver);
break;
case IN_TARGET_MILESTONES | IN_LI | IN_TARGET_MILESTONE | IN_NAME:
+ String target = String.copyValueOf(ch, start, length);
if (about != null) {
- String name = String.copyValueOf(ch, start, length);
- milestoneNames.put(about, name);
+ milestoneNames.put(about, target);
// System.err.println("Version: "+about+" ---> "+name);
}
+ //configuration.addAttributeValue(BugzillaReportElement.TARGET_MILESTONE.getKeyString(), target);
break;
case IN_PLATFORM | IN_LI:
configuration.addPlatform(String.copyValueOf(ch, start, length));
+ //configuration.addAttributeValue(BugzillaReportElement.REP_PLATFORM.getKeyString(), String.copyValueOf(ch, start, length));
break;
case IN_OP_SYS | IN_LI:
configuration.addOS(String.copyValueOf(ch, start, length));
+ //configuration.addAttributeValue(BugzillaReportElement.OP_SYS.getKeyString(), String.copyValueOf(ch, start, length));
break;
case IN_PRIORITY | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.PRIORITY.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addPriority(String.copyValueOf(ch, start, length));
break;
case IN_SEVERITY | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.BUG_SEVERITY.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addSeverity(String.copyValueOf(ch, start, length));
break;
case IN_INSTALL_VERSION:
+ //configuration.addAttributeValue(BugzillaReportElement.INSTALL_VERSION.getKeyString(), String.copyValueOf(ch, start, length));
configuration.setInstallVersion(String.copyValueOf(ch, start, length));
break;
case IN_STATUS | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.BUG_STATUS.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addStatus(String.copyValueOf(ch, start, length));
break;
case IN_RESOLUTION | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.RESOLUTION.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addResolution(String.copyValueOf(ch, start, length));
break;
case IN_KEYWORD | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.KEYWORDS.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addKeyword(String.copyValueOf(ch, start, length));
break;
case IN_STATUS_OPEN | IN_LI:
+ //configuration.addAttributeValue(BugzillaReportElement.STATUS_OPEN.getKeyString(), String.copyValueOf(ch, start, length));
configuration.addOpenStatusValue(String.copyValueOf(ch, start, length));
break;
}
@@ -368,6 +381,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
for (String uri : componentURIs) {
String realName = componentNames.get(uri);
if (realName != null) {
+ //configuration.addAttributeValue(product+"."+BugzillaReportElement.COMPONENT.getKeyString(), realName);
configuration.addComponent(product, realName);
}
}
@@ -378,6 +392,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
for (String uri : versionURIs) {
String realName = versionNames.get(uri);
if (realName != null) {
+ //configuration.addAttributeValue(product+"."+BugzillaReportElement.VERSION.getKeyString(), realName);
configuration.addVersion(product, realName);
}
}
@@ -389,6 +404,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler {
for (String uri : milestoneURIs) {
String realName = milestoneNames.get(uri);
if (realName != null) {
+ //configuration.addAttributeValue(product+"."+BugzillaReportElement.TARGET_MILESTONE.getKeyString(), realName);
configuration.addTargetMilestone(product, realName);
}
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java
index 4897c1451..bbd2c2ffc 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AbstractBugzillaTest.java
@@ -21,6 +21,7 @@ import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylar.context.tests.support.MylarTestUtils;
import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
@@ -133,12 +134,12 @@ public abstract class AbstractBugzillaTest extends TestCase {
class MockBugzillaReportSubmitForm extends BugzillaReportSubmitForm {
- public MockBugzillaReportSubmitForm(String encoding_utf_8) {
- super(encoding_utf_8);
+ public MockBugzillaReportSubmitForm() {
+ super();
}
@Override
- public String submitReportToRepository() throws BugzillaException, LoginException,
+ public String submitReportToRepository(BugzillaClient client) throws BugzillaException, LoginException,
PossibleBugzillaFailureException {
return "test-submit";
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaConfigurationTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaConfigurationTest.java
index 34a91aeaf..8d92eb681 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaConfigurationTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaConfigurationTest.java
@@ -20,13 +20,12 @@ import java.net.URL;
import junit.framework.TestCase;
import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.core.RepositoryConfiguration;
-import org.eclipse.mylar.internal.bugzilla.core.RepositoryConfigurationFactory;
import org.eclipse.mylar.internal.bugzilla.core.SaxConfigurationContentHandler;
import org.eclipse.mylar.internal.bugzilla.core.XmlCleaner;
-import org.eclipse.mylar.tasks.core.TaskRepository;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -45,11 +44,8 @@ public class BugzillaConfigurationTest extends TestCase {
}
public void test222RDFProductConfig() throws Exception {
- RepositoryConfigurationFactory factory = new RepositoryConfigurationFactory();
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_222_URL);
- RepositoryConfiguration config = factory.getConfiguration(repository.getUrl(), null, repository.getUserName(),
- repository.getPassword(), null);
+ BugzillaClient client = new BugzillaClient(new URL(IBugzillaConstants.TEST_BUGZILLA_222_URL), "","","","", "UTF-8");
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
assertNotNull(config);
assertEquals("2.22.1", config.getInstallVersion());
assertEquals(7, config.getStatusValues().size());
@@ -66,11 +62,8 @@ public class BugzillaConfigurationTest extends TestCase {
}
public void test2201RDFProductConfig() throws Exception {
- RepositoryConfigurationFactory factory = new RepositoryConfigurationFactory();
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_2201_URL);
- RepositoryConfiguration config = factory.getConfiguration(repository.getUrl(), null, repository.getUserName(),
- repository.getPassword(), null);
+ BugzillaClient client = new BugzillaClient(new URL(IBugzillaConstants.TEST_BUGZILLA_2201_URL), "","","","", "UTF-8");
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
assertNotNull(config);
assertEquals("2.20.1", config.getInstallVersion());
assertEquals(7, config.getStatusValues().size());
@@ -87,11 +80,8 @@ public class BugzillaConfigurationTest extends TestCase {
}
public void test220RDFProductConfig() throws Exception {
- RepositoryConfigurationFactory factory = new RepositoryConfigurationFactory();
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_220_URL);
- RepositoryConfiguration config = factory.getConfiguration(repository.getUrl(), null, repository.getUserName(),
- repository.getPassword(), null);
+ BugzillaClient client = new BugzillaClient(new URL(IBugzillaConstants.TEST_BUGZILLA_220_URL), "","","","", "UTF-8");
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
assertNotNull(config);
assertEquals("2.20.3", config.getInstallVersion());
assertEquals(7, config.getStatusValues().size());
@@ -108,11 +98,8 @@ public class BugzillaConfigurationTest extends TestCase {
}
public void test218RDFProductConfig() throws Exception {
- RepositoryConfigurationFactory factory = new RepositoryConfigurationFactory();
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_218_URL);
- RepositoryConfiguration config = factory.getConfiguration(repository.getUrl(), null, repository.getUserName(),
- repository.getPassword(), null);
+ BugzillaClient client = new BugzillaClient(new URL(IBugzillaConstants.TEST_BUGZILLA_218_URL), "","","","", "UTF-8");
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
assertNotNull(config);
assertEquals("2.18.6", config.getInstallVersion());
assertEquals(7, config.getStatusValues().size());
@@ -129,11 +116,8 @@ public class BugzillaConfigurationTest extends TestCase {
}
public void testEclipseRDFProductConfig() throws Exception {
- RepositoryConfigurationFactory factory = new RepositoryConfigurationFactory();
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.ECLIPSE_BUGZILLA_URL);
- RepositoryConfiguration config = factory.getConfiguration(repository.getUrl(), null, repository.getUserName(),
- repository.getPassword(), null);
+ BugzillaClient client = new BugzillaClient(new URL(IBugzillaConstants.ECLIPSE_BUGZILLA_URL), "","","","", "UTF-8");
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
assertNotNull(config);
assertEquals("2.20.1", config.getInstallVersion());
assertEquals(7, config.getStatusValues().size());
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaProductParserTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaProductParserTest.java
index 00adc24d0..1a136d6b5 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaProductParserTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaProductParserTest.java
@@ -15,8 +15,9 @@ import java.util.List;
import junit.framework.TestCase;
+import org.eclipse.mylar.context.tests.support.MylarTestUtils;
+import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.tasks.core.TaskRepository;
@@ -48,24 +49,24 @@ public class BugzillaProductParserTest extends TestCase {
super(arg0);
}
+ private TaskRepository setRepository(String url) {
+ repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, url);
+ Credentials credentials = MylarTestUtils.readCredentials();
+ repository.setAuthenticationCredentials(credentials.username, credentials.password);
+ return repository;
+ }
+
public void test222Products() throws Exception {
-
- repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL,
- IBugzillaConstants.BugzillaServerVersion.SERVER_220.toString());
-
- List<String> productList = BugzillaServerFacade.getProductList(repository.getUrl(), null, repository.getUserName(), repository.getPassword(), IBugzillaConstants.ENCODING_UTF_8);
+ setRepository(IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ List<String> productList = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getProducts();
Iterator<String> itr = productList.iterator();
assertTrue(itr.hasNext());
assertEquals("Read Only Test Cases", itr.next());
-
}
public void test2201Products() throws Exception {
-
- repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_2201_URL,
- IBugzillaConstants.BugzillaServerVersion.SERVER_220.toString());
-
- List<String> productList = BugzillaServerFacade.getProductList(repository.getUrl(), null, repository.getUserName(), repository.getPassword(), IBugzillaConstants.ENCODING_UTF_8);
+ setRepository(IBugzillaConstants.TEST_BUGZILLA_2201_URL);
+ List<String> productList = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getProducts();
Iterator<String> itr = productList.iterator();
assertTrue(itr.hasNext());
assertEquals("TestProduct", "TestProduct", itr.next());
@@ -73,11 +74,8 @@ public class BugzillaProductParserTest extends TestCase {
}
public void test220Products() throws Exception {
-
- repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_220_URL,
- IBugzillaConstants.BugzillaServerVersion.SERVER_220.toString());
-
- List<String> productList = BugzillaServerFacade.getProductList(repository.getUrl(), null, repository.getUserName(), repository.getPassword(), IBugzillaConstants.ENCODING_UTF_8);
+ setRepository(IBugzillaConstants.TEST_BUGZILLA_220_URL);
+ List<String> productList = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getProducts();
assertEquals(2, productList.size());
assertTrue(productList.contains("TestProduct"));
assertTrue(productList.contains("Widget"));
@@ -85,14 +83,10 @@ public class BugzillaProductParserTest extends TestCase {
}
public void test218Products() throws Exception {
-
- repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_218_URL,
- IBugzillaConstants.BugzillaServerVersion.SERVER_218.toString());
-
- List<String> productList = BugzillaServerFacade.getProductList(repository.getUrl(), null, repository.getUserName(), repository.getPassword(), IBugzillaConstants.ENCODING_UTF_8);
+ setRepository(IBugzillaConstants.TEST_BUGZILLA_218_URL);
+ List<String> productList = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getProducts();
assertEquals(1, productList.size());
assertTrue(productList.contains("TestProduct"));
-
}
// No longer supporting 216
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java
index 6a94ddbbc..24567b208 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java
@@ -15,7 +15,6 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.net.InetAddress;
-import java.net.Proxy;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Date;
@@ -29,7 +28,7 @@ import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.context.core.ContextCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttachmentHandler;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaQueryHit;
@@ -59,7 +58,7 @@ import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
*/
public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
- private BugzillaAttachmentHandler attachmentHandler = new BugzillaAttachmentHandler();
+// private BugzillaAttachmentHandler attachmentHandler = new BugzillaAttachmentHandler();
public void testCreateTaskFromExistingId() throws Exception {
init222();
@@ -115,9 +114,7 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
}
// test anonymous update of configuration
- RepositoryConfiguration config = BugzillaCorePlugin.getRepositoryConfiguration(true, repository.getUrl(),
- TasksUiPlugin.getDefault().getProxySettings(), repository.getUserName(), repository.getPassword(),
- repository.getCharacterEncoding());
+ RepositoryConfiguration config = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false);
assertNotNull(config);
assertTrue(config.getComponents().size() > 0);
}
@@ -168,7 +165,7 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
assertEquals(RepositoryTaskSyncState.OUTGOING, task.getSyncState());
// Submit changes
- MockBugzillaReportSubmitForm form = new MockBugzillaReportSubmitForm(IBugzillaConstants.ENCODING_UTF_8);
+ MockBugzillaReportSubmitForm form = new MockBugzillaReportSubmitForm();
form.setTaskData(task.getTaskData());
new BugSubmissionHandler(connector).submitBugReport(form, null, true, true);
// submit casuses a synch which should result in
@@ -302,10 +299,20 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
attachment.setReport(task.getTaskData());
attachment.setComment("Automated JUnit attachment test"); // optional
+
+
/* Test attempt to upload a non-existent file */
attachment.setFilePath("/this/is/not/a/real-file");
- assertFalse(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
- Proxy.NO_PROXY));
+ //IAttachmentHandler attachmentHandler = connector.getAttachmentHandler();
+ BugzillaClient client = connector.getClientManager().getClient(repository);
+ try {
+ client.uploadAttachment(attachment.getReport().getId(), attachment.getComment(), attachment.getDescription(), new File(attachment.getFilePath()), attachment.getContentType(), attachment.isPatch());
+ fail();
+ } catch (Exception e) {
+ }
+// attachmentHandler.uploadAttachment(repository, task, comment, description, file, contentType, isPatch, proxySettings)
+// assertFalse(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
+// Proxy.NO_PROXY));
assertEquals(RepositoryTaskSyncState.SYNCHRONIZED, task.getSyncState());
task = (BugzillaTask) connector.createTaskFromExistingKey(repository, taskNumber, null);
TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
@@ -316,8 +323,13 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
File attachFile = new File(fileName);
attachment.setFilePath(attachFile.getAbsolutePath());
BufferedWriter write = new BufferedWriter(new FileWriter(attachFile));
- assertFalse(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
- Proxy.NO_PROXY));
+// assertFalse(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
+// Proxy.NO_PROXY));
+ try {
+ client.uploadAttachment(attachment.getReport().getId(), attachment.getComment(), attachment.getDescription(), new File(attachment.getFilePath()), attachment.getContentType(), attachment.isPatch());
+ fail();
+ } catch (Exception e) {
+ }
task = (BugzillaTask) connector.createTaskFromExistingKey(repository, taskNumber, null);
TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
@@ -327,8 +339,13 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
write.write("test file");
write.close();
attachment.setFilePath(attachFile.getAbsolutePath());
- assertTrue(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
- Proxy.NO_PROXY));
+// assertTrue(attachmentHandler.uploadAttachment(attachment, repository.getUserName(), repository.getPassword(),
+// Proxy.NO_PROXY));
+ try {
+ client.uploadAttachment(attachment.getReport().getId(), attachment.getComment(), attachment.getDescription(), new File(attachment.getFilePath()), attachment.getContentType(), attachment.isPatch());
+ } catch (Exception e) {
+ fail();
+ }
task = (BugzillaTask) connector.createTaskFromExistingKey(repository, taskNumber, null);
TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
assertEquals(numAttached + 1, task.getTaskData().getAttachments().size());
@@ -384,9 +401,9 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
BugzillaReportSubmitForm bugzillaReportSubmitForm;
bugzillaReportSubmitForm = makeExistingBugPost(task4.getTaskData());
- bugzillaReportSubmitForm.submitReportToRepository();
+ bugzillaReportSubmitForm.submitReportToRepository(connector.getClientManager().getClient(repository));
bugzillaReportSubmitForm = makeExistingBugPost(task5.getTaskData());
- bugzillaReportSubmitForm.submitReportToRepository();
+ bugzillaReportSubmitForm.submitReportToRepository(connector.getClientManager().getClient(repository));
changedTasks = connector.getOfflineTaskHandler().getChangedSinceLastSync(repository, tasks, null);
assertEquals("Changed reports expected ", 2, changedTasks.size());
@@ -445,7 +462,7 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
BugzillaReportSubmitForm bugzillaReportSubmitForm;
bugzillaReportSubmitForm = makeExistingBugPost(recentTaskData);
- bugzillaReportSubmitForm.submitReportToRepository();
+ bugzillaReportSubmitForm.submitReportToRepository(connector.getClientManager().getClient(repository));
TasksUiPlugin.getSynchronizationManager().synchronizeChanged(connector, repository);
assertEquals(RepositoryTaskSyncState.INCOMING, task7.getSyncState());
}
@@ -528,7 +545,7 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest {
task.getTaskData().setAttributeValue(BugzillaReportElement.ADD_COMMENT.getKeyString(),
"New Estimate: " + estimatedTime + "\nNew Remaining: " + remainingTime + "\nAdd: " + addTime);
bugzillaReportSubmitForm = makeExistingBugPost(task.getTaskData());
- bugzillaReportSubmitForm.submitReportToRepository();
+ bugzillaReportSubmitForm.submitReportToRepository(connector.getClientManager().getClient(repository));
}
// assertEquals("Changed reports expected ", 1,
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchDialogTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchDialogTest.java
index d6e7825ef..1589263fe 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchDialogTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaSearchDialogTest.java
@@ -67,6 +67,6 @@ public class BugzillaSearchDialogTest extends TestCase {
* not retrieved properly, throw an exception if the page is not
* initialized properly, or pass otherwise.
*/
- assertFalse(page.getProductCount() == 0);
+ assertFalse(page.getProductCount() == 0);
}
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskTest.java
index a7b95ea9c..45e8f104f 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskTest.java
@@ -19,12 +19,14 @@ import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttributeFactory;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaOfflineTaskHandler;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskComment;
import org.eclipse.mylar.tasks.core.TaskList;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
* @author Mik Kersten
@@ -38,7 +40,7 @@ public class BugzillaTaskTest extends TestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
- offlineHandler = new BugzillaOfflineTaskHandler(new TaskList());
+ offlineHandler = new BugzillaOfflineTaskHandler((BugzillaRepositoryConnector)TasksUiPlugin.getRepositoryManager().getRepositoryConnector(BugzillaCorePlugin.REPOSITORY_KIND), new TaskList());
}
@Override
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/EncodingTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/EncodingTest.java
index 4101fc7af..4f673422e 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/EncodingTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/EncodingTest.java
@@ -17,7 +17,7 @@ import java.text.ParseException;
import javax.security.auth.login.LoginException;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
@@ -28,17 +28,17 @@ public class EncodingTest extends AbstractBugzillaTest {
public void testEncodingSetting() throws LoginException, IOException, ParseException {
- String charset = BugzillaServerFacade.getCharsetFromString("text/html; charset=UTF-8");
+ String charset = BugzillaClient.getCharsetFromString("text/html; charset=UTF-8");
assertEquals("UTF-8", charset);
- charset = BugzillaServerFacade.getCharsetFromString("text/html");
+ charset = BugzillaClient.getCharsetFromString("text/html");
assertEquals(null, charset);
- charset = BugzillaServerFacade
+ charset = BugzillaClient
.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\">>");
assertEquals("iso-8859-2", charset);
- charset = BugzillaServerFacade
+ charset = BugzillaClient
.getCharsetFromString("<<meta http-equiv=\"Content-Type\" content=\"text/html\">>");
assertEquals(null, charset);
}
@@ -56,6 +56,7 @@ public class EncodingTest extends AbstractBugzillaTest {
TasksUiPlugin.getSynchronizationManager().synchronize(connector, task, true, null);
assertTrue(task.getDescription().equals("\u05D0"));
taskList.deleteTask(task);
+ connector.getClientManager().repositoryRemoved(repository);
repository.setCharacterEncoding("ISO-8859-1");
task = (BugzillaTask) connector.createTaskFromExistingKey(repository, "57", null);
assertNotNull(task);
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java
index 3495b7b79..45a137c46 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/NewBugWizardTest.java
@@ -16,7 +16,7 @@ import junit.framework.TestCase;
import org.eclipse.core.runtime.Platform;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
import org.eclipse.mylar.internal.bugzilla.ui.wizard.BugzillaProductPage;
@@ -34,7 +34,7 @@ public class NewBugWizardTest extends TestCase {
NewBugzillaReport newReport = new NewBugzillaReport(IBugzillaConstants.TEST_BUGZILLA_220_URL, "1");
TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
IBugzillaConstants.TEST_BUGZILLA_220_URL);
- BugzillaServerFacade.setupNewBugAttributes(repository.getUrl(), null, repository.getUserName(), repository.getPassword(), newReport, null);
+ BugzillaRepositoryConnector.setupNewBugAttributes(repository, newReport);
BugzillaProductPage page = new BugzillaProductPage(PlatformUI.getWorkbench(), null, repository);
page.setPlatformOptions(newReport);
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryEditorWizardTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryEditorWizardTest.java
index 929f94594..56b18dc9f 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryEditorWizardTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryEditorWizardTest.java
@@ -20,8 +20,9 @@ import junit.framework.TestCase;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.mylar.context.tests.support.MylarTestUtils;
import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClientFactory;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositorySettingsPage;
import org.eclipse.mylar.internal.tasks.ui.wizards.EditRepositoryWizard;
@@ -58,12 +59,15 @@ public class RepositoryEditorWizardTest extends TestCase {
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
dialog.create();
BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ // BugzillaClient client =
+ // BugzillaClientFactory.createClient(page.getServerUrl(),
+ // page.getUserName(), page.getPassword(), page.getHttpAuthUserId(),
+ // page.getHttpAuthPassword(), page.getCharacterEncoding());
page.setPassword("bogus");
try {
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ BugzillaClient client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page
+ .getPassword(), page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
} catch (LoginException e) {
return;
}
@@ -75,12 +79,11 @@ public class RepositoryEditorWizardTest extends TestCase {
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
dialog.create();
BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
page.setUserId("bogus");
try {
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ BugzillaClient client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page
+ .getPassword(), page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
} catch (LoginException e) {
return;
}
@@ -92,18 +95,30 @@ public class RepositoryEditorWizardTest extends TestCase {
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
dialog.create();
BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
page.setUrl("http://invalid");
try {
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ BugzillaClient client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page
+ .getPassword(), page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
} catch (UnknownHostException e) {
return;
}
fail("UnknownHostException didn't occur!");
}
+ // TODO: Test locking up?
+// public void testAutoVersion() throws Exception {
+// repository.setVersion(BugzillaRepositorySettingsPage.LABEL_AUTOMATIC_VERSION);
+// EditRepositoryWizard wizard = new EditRepositoryWizard(repository);
+// WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
+// dialog.create();
+// BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
+// page.setTesting(true);
+// assertEquals(BugzillaRepositorySettingsPage.LABEL_AUTOMATIC_VERSION, page.getVersion());
+// page.validateSettings();
+// assertEquals("2.22", page.getVersion());
+// }
+
public void testPersistChangeOfUrl() throws Exception {
assertEquals(1, manager.getAllRepositories().size());
String tempUid = repository.getUserName();
@@ -112,8 +127,9 @@ public class RepositoryEditorWizardTest extends TestCase {
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
dialog.create();
BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ BugzillaClient client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page
+ .getPassword(), page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
page.setUrl(IBugzillaConstants.TEST_BUGZILLA_218_URL);
wizard.performFinish();
assertEquals(1, manager.getAllRepositories().size());
@@ -130,8 +146,9 @@ public class RepositoryEditorWizardTest extends TestCase {
WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
dialog.create();
BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ BugzillaClient client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page
+ .getPassword(), page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
page.setUserId("bogus");
wizard.performFinish();
assertEquals(1, manager.getAllRepositories().size());
@@ -143,24 +160,13 @@ public class RepositoryEditorWizardTest extends TestCase {
dialog.create();
page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
try {
- BugzillaServerFacade.validateCredentials(null, page.getServerUrl(), page.getCharacterEncoding(), page
- .getUserName(), page.getPassword());
+ client = BugzillaClientFactory.createClient(page.getServerUrl(), page.getUserName(), page.getPassword(),
+ page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
+ client.validate();
} catch (LoginException e) {
return;
}
fail("LoginException didn't occur!");
}
- public void testAutoVersion() throws Exception {
- repository.setVersion(BugzillaRepositorySettingsPage.LABEL_AUTOMATIC_VERSION);
- EditRepositoryWizard wizard = new EditRepositoryWizard(repository);
- WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
- dialog.create();
- BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- page.setTesting(true);
- assertEquals(BugzillaRepositorySettingsPage.LABEL_AUTOMATIC_VERSION, page.getVersion());
- page.validateSettings();
- assertEquals("2.22", page.getVersion());
- }
-
}
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryReportFactoryTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryReportFactoryTest.java
index 94b89888c..8ef30d981 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryReportFactoryTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/RepositoryReportFactoryTest.java
@@ -11,25 +11,24 @@
package org.eclipse.mylar.bugzilla.tests;
-import java.io.IOException;
-
-import javax.security.auth.login.LoginException;
+import java.net.Proxy;
import junit.framework.TestCase;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.mylar.context.tests.support.MylarTestUtils;
import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaAttributeFactory;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
-import org.eclipse.mylar.internal.bugzilla.core.RepositoryReportFactory;
+import org.eclipse.mylar.tasks.core.IOfflineTaskHandler;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
* @author Rob Elves
@@ -37,119 +36,107 @@ import org.eclipse.mylar.tasks.core.TaskRepository;
*/
public class RepositoryReportFactoryTest extends TestCase {
- RepositoryReportFactory factory = new RepositoryReportFactory();
-
BugzillaAttributeFactory attributeFactory = new BugzillaAttributeFactory();
- private RepositoryTaskData init(String URL, int bugid) throws Exception {
- TaskRepository repository = getRepository(BugzillaCorePlugin.REPOSITORY_KIND, URL);
+ TaskRepository repository;
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), "" + bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- IBugzillaConstants.ENCODING_UTF_8);
+ BugzillaRepositoryConnector connector;
- return report;
+ private RepositoryTaskData init(String taskId) throws CoreException {
+ IOfflineTaskHandler handler = connector.getOfflineTaskHandler();
+ RepositoryTaskData taskData = handler.downloadTaskData(repository, taskId, Proxy.NO_PROXY);
+ return taskData;
}
- private TaskRepository getRepository(String kind, String url) {
- TaskRepository repository = new TaskRepository(kind, url);
+ private TaskRepository setRepository(String kind, String url) {
+ connector = (BugzillaRepositoryConnector) TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
+ BugzillaCorePlugin.REPOSITORY_KIND);
+ repository = new TaskRepository(kind, url);
Credentials credentials = MylarTestUtils.readCredentials();
repository.setAuthenticationCredentials(credentials.username, credentials.password);
return repository;
}
- public void testBugNotFound222() throws Exception {
- String bugid = "-1";
- String errorMessage = "";
- TaskRepository repository = getRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_222_URL);
- try {
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, repository.getKind(), repository
- .getUrl(), bugid);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository
- .getPassword(), null);
- } catch (LoginException e) {
- //
- } catch (BugzillaException e) {
- errorMessage = e.getMessage();
- }
- assertEquals(IBugzillaConstants.ERROR_MSG_INVALID_BUG_ID, errorMessage);
- }
-
public void testInvalidCredentials222() throws Exception {
String bugid = "1";
String errorMessage = "";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_222_URL);
- repository.setAuthenticationCredentials("invalid", "invalid");
try {
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository
- .getPassword(), null);
- } catch (LoginException e) {
- errorMessage = e.getMessage();
- } catch (IOException e) {
- errorMessage = e.getMessage();
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ repository.setAuthenticationCredentials("invalid", "invalid");
+ init(bugid);
+ } catch (CoreException e) {
+ errorMessage = e.getStatus().getException().getMessage();
}
- assertEquals(IBugzillaConstants.ERROR_INVALID_USERNAME_OR_PASSWORD, errorMessage);
+ assertEquals("Invalid credentials.", errorMessage);
repository.flushAuthenticationCredentials();
}
- public void testReadingReport() throws Exception {
- String bugid = "2";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_222_URL);
-
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- null);
+ public void testBugNotFound222() {
- assertNotNull(report);
- assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString())
- .getValue());
- assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT.getKeyString()).getValue());
- assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString()).getValue());
- assertEquals("Windows", report.getAttribute(BugzillaReportElement.OP_SYS.getKeyString()).getValue());
- // first comment (#0) is the description so this value is always 1
- // greater
- // than what is shown on the report ui
- assertEquals(3, report.getComments().size());
- assertEquals("search-match-test 1", report.getComments().get(0).getAttribute(
- BugzillaReportElement.THETEXT.getKeyString()).getValue());
- // assertEquals(15, report.getAttachments().size());
- // assertEquals("1",
- // report.getAttachments().get(0).getAttribute(BugzillaReportElement.ATTACHID).getValue());
- // assertEquals("2006-03-10 14:11",
- // report.getAttachments().get(0).getAttribute(BugzillaReportElement.DATE)
- // .getValue());
- // assertEquals("Testing upload",
- // report.getAttachments().get(0).getAttribute(BugzillaReportElement.DESC)
- // .getValue());
- // assertEquals("patch130217.txt",
- // report.getAttachments().get(0).getAttribute(BugzillaReportElement.FILENAME)
- // .getValue());
- // assertEquals("text/plain",
- // report.getAttachments().get(0).getAttribute(BugzillaReportElement.TYPE).getValue());
+ String bugid = "-1";
+ String errorMessage = "";
+ try {
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ // If this isn't called the BugzillaClient will be reused (with old
+ // credentials) so
+ // force drop of old client connection.
+ // Note that this is usually called by notification
+ connector.getClientManager().repositoryAdded(repository);
+ init(bugid);
+ } catch (CoreException e) {
+ errorMessage = e.getStatus().getException().getMessage();
+ }
+ assertEquals(IBugzillaConstants.ERROR_MSG_INVALID_BUG_ID, errorMessage);
}
+ // public void testReadingReport() throws Exception {
+ // String bugid = "2";
+ // setRepository(BugzillaCorePlugin.REPOSITORY_KIND,
+ // IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ // RepositoryTaskData report = init(bugid);
+ //
+ // assertNotNull(report);
+ // assertEquals("search-match-test 1",
+ // report.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString())
+ // .getValue());
+ // assertEquals("TestProduct",
+ // report.getAttribute(BugzillaReportElement.PRODUCT.getKeyString()).getValue());
+ // assertEquals("PC",
+ // report.getAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString()).getValue());
+ // assertEquals("Windows",
+ // report.getAttribute(BugzillaReportElement.OP_SYS.getKeyString()).getValue());
+ // // first comment (#0) is the description so this value is always 1
+ // // greater
+ // // than what is shown on the report ui
+ // assertEquals(3, report.getComments().size());
+ // assertEquals("search-match-test 1",
+ // report.getComments().get(0).getAttribute(
+ // BugzillaReportElement.THETEXT.getKeyString()).getValue());
+ // // assertEquals(15, report.getAttachments().size());
+ // // assertEquals("1",
+ // //
+ // report.getAttachments().get(0).getAttribute(BugzillaReportElement.ATTACHID).getValue());
+ // // assertEquals("2006-03-10 14:11",
+ // //
+ // report.getAttachments().get(0).getAttribute(BugzillaReportElement.DATE)
+ // // .getValue());
+ // // assertEquals("Testing upload",
+ // //
+ // report.getAttachments().get(0).getAttribute(BugzillaReportElement.DESC)
+ // // .getValue());
+ // // assertEquals("patch130217.txt",
+ // //
+ // report.getAttachments().get(0).getAttribute(BugzillaReportElement.FILENAME)
+ // // .getValue());
+ // // assertEquals("text/plain",
+ // //
+ // report.getAttachments().get(0).getAttribute(BugzillaReportElement.TYPE).getValue());
+ // }
+
public void testReadingReport222() throws Exception {
- int bugid = 2;
- // TaskRepository repository = new
- // TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
- // IBugzillaConstants.TEST_BUGZILLA_222_URL);
- //
- // RepositoryTaskData report = new RepositoryTaskData(attributeFactory,
- // BugzillaPlugin.REPOSITORY_KIND, repository.getUrl(), bugid);
- // BugzillaRepositoryUtil.setupExistingBugAttributes(repository.getUrl(),
- // report);
- // factory.populateReport(report, repository.getUrl(), null,
- // repository.getUserName(), repository.getPassword(), null);
- RepositoryTaskData report = init(IBugzillaConstants.TEST_BUGZILLA_222_URL, bugid);
+ String bugid = "2";
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ RepositoryTaskData report = init(bugid);
assertNotNull(report);
assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString())
@@ -158,7 +145,7 @@ public class RepositoryReportFactoryTest extends TestCase {
assertEquals("search-match-test 1", report.getDescription());
assertEquals("TestProduct", report.getAttribute(BugzillaReportElement.PRODUCT.getKeyString()).getValue());
assertEquals("TestProduct", report.getProduct());
- assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT.getKeyString()).getValue());
+ assertEquals("TestComponent", report.getAttribute(BugzillaReportElement.COMPONENT.getKeyString()).getValue());
assertEquals("PC", report.getAttribute(BugzillaReportElement.REP_PLATFORM.getKeyString()).getValue());
assertEquals("Windows", report.getAttribute(BugzillaReportElement.OP_SYS.getKeyString()).getValue());
assertEquals("other", report.getAttribute(BugzillaReportElement.VERSION.getKeyString()).getValue());
@@ -173,7 +160,7 @@ public class RepositoryReportFactoryTest extends TestCase {
assertEquals("---", report.getAttribute(BugzillaReportElement.TARGET_MILESTONE.getKeyString()).getValue());
assertEquals("relves@cs.ubc.ca", report.getAttribute(BugzillaReportElement.REPORTER.getKeyString()).getValue());
assertEquals("nhapke@cs.ubc.ca", report.getAttribute(BugzillaReportElement.ASSIGNED_TO.getKeyString())
- .getValue());
+ .getValue());
assertEquals(3, report.getComments().size());
assertEquals("relves@cs.ubc.ca", report.getComments().get(0).getAttribute(
BugzillaReportElement.WHO.getKeyString()).getValue());
@@ -186,14 +173,8 @@ public class RepositoryReportFactoryTest extends TestCase {
public void testReadingReport2201() throws Exception {
String bugid = "1";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_2201_URL);
-
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- null);
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_2201_URL);
+ RepositoryTaskData report = init(bugid);
assertNotNull(report);
assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID.getKeyString()).getValue());
@@ -370,15 +351,8 @@ public class RepositoryReportFactoryTest extends TestCase {
public void testReadingReport218() throws Exception {
String bugid = "1";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_218_URL);
-
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- null);
-
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_218_URL);
+ RepositoryTaskData report = init(bugid);
assertNotNull(report);
assertEquals("1", report.getAttribute(BugzillaReportElement.BUG_ID.getKeyString()).getValue());
assertEquals("search-match-test 1", report.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString())
@@ -410,8 +384,8 @@ public class RepositoryReportFactoryTest extends TestCase {
}
public void testTimeTracking222() throws Exception {
- RepositoryTaskData report = init(IBugzillaConstants.TEST_BUGZILLA_222_URL, 11);
-
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ RepositoryTaskData report = init("11");
assertEquals("7.50", report.getAttribute(BugzillaReportElement.ESTIMATED_TIME.getKeyString()).getValue());
assertEquals("4.00", report.getAttribute(BugzillaReportElement.ACTUAL_TIME.getKeyString()).getValue());
assertEquals("3.00", report.getAttribute(BugzillaReportElement.REMAINING_TIME.getKeyString()).getValue());
@@ -447,8 +421,8 @@ public class RepositoryReportFactoryTest extends TestCase {
// }
public void testTimeTracking218() throws Exception {
- RepositoryTaskData report = init(IBugzillaConstants.TEST_BUGZILLA_218_URL, 19);
-
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_218_URL);
+ RepositoryTaskData report = init("19");
assertEquals("7.50", report.getAttribute(BugzillaReportElement.ESTIMATED_TIME.getKeyString()).getValue());
assertEquals("1.00", report.getAttribute(BugzillaReportElement.ACTUAL_TIME.getKeyString()).getValue());
assertEquals("3.00", report.getAttribute(BugzillaReportElement.REMAINING_TIME.getKeyString()).getValue());
@@ -456,15 +430,8 @@ public class RepositoryReportFactoryTest extends TestCase {
public void testMultipleDepensOn() throws Exception {
String bugid = "5";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_218_URL);
-
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- null);
-
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_218_URL);
+ RepositoryTaskData report = init(bugid);
assertNotNull(report);
assertEquals("5", report.getAttribute(BugzillaReportElement.BUG_ID.getKeyString()).getValue());
assertEquals("6, 7", report.getAttribute(BugzillaReportElement.DEPENDSON.getKeyString()).getValue());
@@ -473,15 +440,8 @@ public class RepositoryReportFactoryTest extends TestCase {
public void testBugReportAPI() throws Exception {
String bugid = "3";
- TaskRepository repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND,
- IBugzillaConstants.TEST_BUGZILLA_222_URL);
-
- RepositoryTaskData report = new RepositoryTaskData(attributeFactory, BugzillaCorePlugin.REPOSITORY_KIND,
- repository.getUrl(), bugid);
- BugzillaServerFacade.setupExistingBugAttributes(repository.getUrl(), report);
- factory.populateReport(report, repository.getUrl(), null, repository.getUserName(), repository.getPassword(),
- null);
-
+ setRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ RepositoryTaskData report = init(bugid);
assertNotNull(report);
assertTrue(report instanceof RepositoryTaskData);
RepositoryTaskData bugReport = (RepositoryTaskData) report;
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java
index db3e41c3f..889510c33 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/headless/BugzillaQueryTest.java
@@ -11,12 +11,7 @@
package org.eclipse.mylar.bugzilla.tests.headless;
-import java.io.IOException;
-import java.net.InetSocketAddress;
import java.net.Proxy;
-import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-import java.util.List;
import junit.framework.TestCase;
@@ -24,17 +19,17 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.context.tests.support.MylarTestUtils;
import org.eclipse.mylar.context.tests.support.MylarTestUtils.Credentials;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
+import org.eclipse.mylar.tasks.core.IOfflineTaskHandler;
import org.eclipse.mylar.tasks.core.QueryHitCollector;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskList;
import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
/**
*
@@ -47,13 +42,23 @@ import org.eclipse.mylar.tasks.core.TaskRepository;
public class BugzillaQueryTest extends TestCase {
private TaskRepository repository;
-
+ private BugzillaRepositoryConnector connector;
+ private IOfflineTaskHandler handler;
+ private Proxy proxy = Proxy.NO_PROXY;
+
@Override
protected void setUp() throws Exception {
super.setUp();
+
+ connector = (BugzillaRepositoryConnector) TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
+ BugzillaCorePlugin.REPOSITORY_KIND);
+ handler = connector.getOfflineTaskHandler();
repository = new TaskRepository(BugzillaCorePlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
+ Credentials credentials = MylarTestUtils.readCredentials();
+ repository.setAuthenticationCredentials(credentials.username, credentials.password);
}
-
+
+
/**
* This is the first test so that the repository credentials are correctly
* set for the other tests
@@ -67,33 +72,32 @@ public class BugzillaQueryTest extends TestCase {
}
}
- public void testValidateCredentials() throws IOException, BugzillaException, KeyManagementException,
- GeneralSecurityException {
- BugzillaServerFacade.validateCredentials(null, repository.getUrl(), repository.getCharacterEncoding(),
- repository.getUserName(), repository.getPassword());
- }
-
- public void testValidateCredentialsInvalidProxy() throws IOException, BugzillaException, KeyManagementException,
- GeneralSecurityException {
- BugzillaServerFacade.validateCredentials(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 12356)),
- repository.getUrl(), repository.getCharacterEncoding(), repository.getUserName(), repository
- .getPassword());
- }
-
- public void testCredentialsEncoding() throws IOException, BugzillaException, KeyManagementException,
- GeneralSecurityException {
- String poundSignUTF8 = BugzillaServerFacade.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL, "UTF-8",
- "testUser", "\u00A3");
- assertTrue(poundSignUTF8.endsWith("password=%C2%A3"));
- String poundSignISO = BugzillaServerFacade.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL,
- "ISO-8859-1", "testUser", "\u00A3");
- assertFalse(poundSignISO.contains("%C2%A3"));
- assertTrue(poundSignISO.endsWith("password=%A3"));
- }
+// public void testValidateCredentials() throws IOException, BugzillaException, KeyManagementException,
+// GeneralSecurityException {
+// BugzillaClient.validateCredentials(null, repository.getUrl(), repository.getCharacterEncoding(),
+// repository.getUserName(), repository.getPassword());
+// }
+//
+// public void testValidateCredentialsInvalidProxy() throws IOException, BugzillaException, KeyManagementException,
+// GeneralSecurityException {
+// BugzillaClient.validateCredentials(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 12356)),
+// repository.getUrl(), repository.getCharacterEncoding(), repository.getUserName(), repository
+// .getPassword());
+// }
+
+// public void testCredentialsEncoding() throws IOException, BugzillaException, KeyManagementException,
+// GeneralSecurityException {
+// String poundSignUTF8 = BugzillaClient.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL, "UTF-8",
+// "testUser", "\u00A3");
+// assertTrue(poundSignUTF8.endsWith("password=%C2%A3"));
+// String poundSignISO = BugzillaClient.addCredentials(IBugzillaConstants.TEST_BUGZILLA_222_URL,
+// "ISO-8859-1", "testUser", "\u00A3");
+// assertFalse(poundSignISO.contains("%C2%A3"));
+// assertTrue(poundSignISO.endsWith("password=%A3"));
+// }
public void testGetBug() throws Exception {
- RepositoryTaskData taskData = BugzillaServerFacade.getBug(repository.getUrl(), repository.getUserName(),
- repository.getPassword(), null, repository.getCharacterEncoding(), 1);
+ RepositoryTaskData taskData = handler.downloadTaskData(repository, "1", proxy);
assertNotNull(taskData);
assertEquals("user@mylar.eclipse.org", taskData.getAssignedTo());
@@ -106,19 +110,9 @@ public class BugzillaQueryTest extends TestCase {
assertEquals("P1", taskData.getAttributeValue(BugzillaReportElement.PRIORITY.getKeyString()));
}
- public void testGetProductList() throws Exception {
- List<String> products = BugzillaServerFacade.getProductList(repository.getUrl(), null,
- repository.getUserName(), repository.getPassword(), repository.getCharacterEncoding());
-
- assertEquals(3, products.size());
- assertTrue(products.contains("Read Only Test Cases"));
- assertTrue(products.contains("Read Write Test Cases"));
- assertTrue(products.contains("TestProduct"));
- }
-
public void testQueryViaConnector() throws Exception {
String queryUrlString = repository.getUrl()
- + "/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=";
+ + "/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=";
// holds onto actual hit objects
TaskList taskList = new TaskList();
@@ -133,26 +127,4 @@ public class BugzillaQueryTest extends TestCase {
assertTrue(hit.getDescription().contains("search-match-test"));
}
}
-}
-
-// public void testQueryBugs() throws Exception {
-//
-// QueryHitCollector collector = new QueryHitCollector(new TaskList());
-//
-// // Note need for ctype=rdf in query url
-// String urlString =
-// "http://mylar.eclipse.org/bugs222/buglist.cgi?ctype=rdf&query_format=advanced&short_desc_type=allwordssubstr&short_desc=search-match-test&product=TestProduct&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&deadlinefrom=&deadlineto=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=";
-// RepositoryQueryResultsFactory queryFactory = new
-// RepositoryQueryResultsFactory();
-//
-// // Tasklist can be null but calls to hit.getOrCreateCorrespondingTask() will
-// return null.
-// queryFactory.performQuery(null, repository.getUrl(), collector, urlString,
-// null, -1, repository
-// .getCharacterEncoding());
-//
-// assertEquals(2, collector.getHits().size());
-// for (AbstractQueryHit hit : collector.getHits()) {
-// assertTrue(hit.getDescription().contains("search-match-test"));
-// }
-// }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaUiPlugin.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaUiPlugin.java
index da7249f98..c89a0b432 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaUiPlugin.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/BugzillaUiPlugin.java
@@ -105,6 +105,8 @@ public class BugzillaUiPlugin extends AbstractUIPlugin {
authenticator = new BugzillaAuthenticator();
}
Authenticator.setDefault(authenticator);
+
+ TasksUiPlugin.getRepositoryManager().addListener(BugzillaCorePlugin.getDefault().getConnector().getClientManager());
// migrateOldAuthenticationData();
}
@@ -126,6 +128,7 @@ public class BugzillaUiPlugin extends AbstractUIPlugin {
* This method is called when the plug-in is stopped
*/
public void stop(BundleContext context) throws Exception {
+ TasksUiPlugin.getRepositoryManager().removeListener(BugzillaCorePlugin.getDefault().getConnector().getClientManager());
super.stop(context);
plugin = null;
}
@@ -229,7 +232,7 @@ public class BugzillaUiPlugin extends AbstractUIPlugin {
// TODO: pass monitor along since it is this call that does the work and can hang due to network IO
RepositoryConfiguration config = null;
try {
- config = BugzillaCorePlugin.getRepositoryConfiguration(false, repository.getUrl(), TasksUiPlugin.getDefault().getProxySettings(), repository.getUserName(), repository.getPassword(), repository.getCharacterEncoding());
+ config = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false);
} catch (Exception e) {
MylarStatusHandler.fail(e, "Could not retrieve repository configuration for: " + repository, true);
return;
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugSubmissionHandler.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugSubmissionHandler.java
index 407cb133a..5f5eb1447 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugSubmissionHandler.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugSubmissionHandler.java
@@ -12,8 +12,6 @@
package org.eclipse.mylar.internal.bugzilla.ui.editor;
import java.io.IOException;
-import java.net.ConnectException;
-import java.net.Proxy;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Set;
@@ -23,8 +21,10 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.internal.bugzilla.core.PossibleBugzillaFailureException;
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
@@ -51,14 +51,21 @@ public class BugSubmissionHandler {
this.connector = connector;
}
- public void submitBugReport(final BugzillaReportSubmitForm form, IJobChangeListener listener, boolean synchExec, final boolean addToTaskListRoot) {
+ public void submitBugReport(final BugzillaReportSubmitForm form, IJobChangeListener listener, boolean synchExec,
+ final boolean addToTaskListRoot) {
if (synchExec) {
try {
- String submittedBugId = form.submitReportToRepository();
- if (form.isNewBugPost()) {
- handleNewBugPost(form.getTaskData(), submittedBugId, addToTaskListRoot);
- } else {
- handleExistingBugPost(form.getTaskData(), submittedBugId);
+ TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
+ form.getTaskData().getRepositoryKind(), form.getTaskData().getRepositoryUrl());
+ if (repository != null) {
+ BugzillaClient client = ((BugzillaRepositoryConnector) connector).getClientManager().getClient(
+ repository);
+ String submittedBugId = form.submitReportToRepository(client);
+ if (form.isNewBugPost()) {
+ handleNewBugPost(form.getTaskData(), submittedBugId, addToTaskListRoot);
+ } else {
+ handleExistingBugPost(form.getTaskData(), submittedBugId);
+ }
}
} catch (Exception e) {
throw new RuntimeException(e);
@@ -70,12 +77,17 @@ public class BugSubmissionHandler {
protected IStatus run(IProgressMonitor monitor) {
try {
String submittedBugId = "";
- try {
- submittedBugId = form.submitReportToRepository();
- } catch (ConnectException e) {
- form.setProxySettings(Proxy.NO_PROXY);
- submittedBugId = form.submitReportToRepository();
- }
+ TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
+ form.getTaskData().getRepositoryKind(), form.getTaskData().getRepositoryUrl());
+ BugzillaClient client = ((BugzillaRepositoryConnector) connector).getClientManager().getClient(
+ repository);
+ // try {
+ submittedBugId = form.submitReportToRepository(client);
+ // } catch (ConnectException e) {
+ // form.setProxySettings(Proxy.NO_PROXY);
+ // submittedBugId =
+ // form.submitReportToRepository(client);
+ // }
if (form.isNewBugPost()) {
handleNewBugPost(form.getTaskData(), submittedBugId, addToTaskListRoot);
@@ -94,7 +106,7 @@ public class BugSubmissionHandler {
} catch (UnrecognizedReponseException e) {
return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.INFO,
"Unrecognized response from server", e);
- } catch (IOException e) {
+ } catch (IOException e) {
return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.ERROR,
"Check repository credentials and connectivity.", e);
} catch (BugzillaException e) {
@@ -115,7 +127,8 @@ public class BugSubmissionHandler {
}
}
- private void handleNewBugPost(RepositoryTaskData taskData, String resultId, boolean addToRoot) throws BugzillaException {
+ private void handleNewBugPost(RepositoryTaskData taskData, String resultId, boolean addToRoot)
+ throws BugzillaException {
int bugId = -1;
try {
bugId = Integer.parseInt(resultId);
@@ -135,7 +148,7 @@ public class BugSubmissionHandler {
} else {
TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask);
}
-
+
java.util.List<TaskRepository> repositoriesToSync = new ArrayList<TaskRepository>();
repositoriesToSync.add(repository);
TasksUiPlugin.getSynchronizationScheduler().synchNow(0, repositoriesToSync);
@@ -148,13 +161,6 @@ public class BugSubmissionHandler {
.getId());
ITask task = TasksUiPlugin.getTaskListManager().getTaskList().getTask(handle);
if (task != null) {
- Set<AbstractRepositoryQuery> queriesWithHandle = TasksUiPlugin.getTaskListManager().getTaskList()
- .getQueriesForHandle(task.getHandleIdentifier());
- TasksUiPlugin.getSynchronizationManager().synchronize(connector, queriesWithHandle, null, Job.SHORT, 0,
- false);
- TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
- repositoryTaskData.getRepositoryKind(), repositoryTaskData.getRepositoryUrl());
- TasksUiPlugin.getSynchronizationManager().synchronizeChanged(connector, repository);
if (task instanceof AbstractRepositoryTask) {
AbstractRepositoryTask repositoryTask = (AbstractRepositoryTask) task;
// TODO: This is set to null in order for update to bypass
@@ -163,6 +169,13 @@ public class BugSubmissionHandler {
repositoryTask.setTaskData(null);
TasksUiPlugin.getSynchronizationManager().synchronize(connector, repositoryTask, true, null);
}
+ Set<AbstractRepositoryQuery> queriesWithHandle = TasksUiPlugin.getTaskListManager().getTaskList()
+ .getQueriesForHandle(task.getHandleIdentifier());
+ TasksUiPlugin.getSynchronizationManager().synchronize(connector, queriesWithHandle, null, Job.SHORT, 0,
+ false);
+ TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
+ repositoryTaskData.getRepositoryKind(), repositoryTaskData.getRepositoryUrl());
+ TasksUiPlugin.getSynchronizationManager().synchronizeChanged(connector, repository);
}
} catch (Exception e) {
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java
index 3d9f697b6..c6a375840 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java
@@ -665,9 +665,7 @@ public class BugzillaTaskEditor extends AbstractRepositoryTaskEditor {
java.util.List<String> validKeywords = new ArrayList<String>();
try {
- validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(false, repository.getUrl(),
- TasksUiPlugin.getDefault().getProxySettings(), repository.getUserName(), repository.getPassword(),
- repository.getCharacterEncoding()).getKeywords();
+ validKeywords = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getKeywords();
} catch (Exception e) {
// ignore
}
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java
index 9e104bc65..369b08b75 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/search/BugzillaSearchPage.java
@@ -24,7 +24,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.mylar.context.core.MylarStatusHandler;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
@@ -102,7 +101,7 @@ public class BugzillaSearchPage extends AbstractRepositoryQueryPage implements L
private static final String[] emailRoleValues = { "emailassigned_to1", "emailreporter1", "emailcc1",
"emaillongdesc1" };
- protected IPreferenceStore prefs = BugzillaUiPlugin.getDefault().getPreferenceStore();
+ //protected IPreferenceStore prefs = BugzillaUiPlugin.getDefault().getPreferenceStore();
protected String maxHits;
@@ -1359,7 +1358,7 @@ public class BugzillaSearchPage extends AbstractRepositoryQueryPage implements L
monitor.beginTask("Updating search options...", IProgressMonitor.UNKNOWN);
try {
- connector.updateAttributes(repository, TasksUiPlugin.getDefault().getProxySettings(), monitor);
+ connector.updateAttributes(repository, monitor);
} catch (CoreException ce) {
if (ce.getStatus().getException() instanceof GeneralSecurityException) {
MylarStatusHandler.fail(ce,
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java
index 01810ea64..db45c4b10 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositorySettingsPage.java
@@ -14,7 +14,6 @@ package org.eclipse.mylar.internal.bugzilla.ui.tasklist;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
-import java.net.Proxy;
import java.net.URL;
import javax.security.auth.login.LoginException;
@@ -23,15 +22,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.mylar.context.core.MylarStatusHandler;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClientFactory;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.core.RepositoryConfiguration;
-import org.eclipse.mylar.internal.tasks.core.WebClientUtil;
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractRepositorySettingsPage;
import org.eclipse.mylar.tasks.core.RepositoryTemplate;
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnectorUi;
-import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -62,6 +59,7 @@ public class BugzillaRepositorySettingsPage extends AbstractRepositorySettingsPa
setNeedsAnonymousLogin(true);
setNeedsEncoding(true);
setNeedsTimeZone(false);
+ setNeedsHttpAuth(true);
}
protected void createAdditionalControls(Composite parent) {
@@ -167,35 +165,27 @@ public class BugzillaRepositorySettingsPage extends AbstractRepositorySettingsPa
public void validateSettings() {
try {
- final URL serverURL = new URL(super.getServerUrl());
final String serverUrl = getServerUrl();
final String newUserId = getUserName();
final String newPassword = getPassword();
final boolean isAnonymous = isAnonymousAccess();
final String newEncoding = getCharacterEncoding();
+ final String httpAuthUser = getHttpAuthUserId();
+ final String httpAuthPass = getHttpAuthPassword();
final boolean checkVersion = repositoryVersionCombo.getSelectionIndex() == 0;
final String[] version = new String[1];
getWizard().getContainer().run(true, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Validating server settings", IProgressMonitor.UNKNOWN);
try {
-
- // Check that the server exists and we can connect
- // (proxy or not)
- Proxy proxySettings = TasksUiPlugin.getDefault().getProxySettings();
- WebClientUtil.openUrlConnection(serverURL, proxySettings, false);
-
- if (!isAnonymous) {
- // Server exists, connect to service and validate
- // credentials
- BugzillaServerFacade.validateCredentials(proxySettings, serverUrl, newEncoding, newUserId,
- newPassword);
+ BugzillaClient client = null;
+ if (!isAnonymous && version != null) {
+ client = BugzillaClientFactory.createClient(serverUrl, newUserId, newPassword,
+ httpAuthUser, httpAuthPass, newEncoding);
+ client.validate();
}
-
- if (checkVersion) {
- RepositoryConfiguration config = BugzillaCorePlugin.getRepositoryConfiguration(true,
- serverUrl, proxySettings, newUserId, newPassword, newEncoding);
-
+ if (checkVersion && client != null) {
+ RepositoryConfiguration config = client.getRepositoryConfiguration();
if (config != null) {
version[0] = config.getInstallVersion();
}
@@ -209,6 +199,47 @@ public class BugzillaRepositorySettingsPage extends AbstractRepositorySettingsPa
}
});
+ // getWizard().getContainer().run(true, false, new
+ // IRunnableWithProgress() {
+ // public void run(IProgressMonitor monitor) throws
+ // InvocationTargetException, InterruptedException {
+ // monitor.beginTask("Validating server settings",
+ // IProgressMonitor.UNKNOWN);
+ // try {
+ //
+ // // Check that the server exists and we can connect
+ // // (proxy or not)
+ // Proxy proxySettings =
+ // TasksUiPlugin.getDefault().getProxySettings();
+ // WebClientUtil.openUrlConnection(serverURL, proxySettings, false,
+ // httpAuthUser, httpAuthPass);
+ //
+ // if (!isAnonymous) {
+ // // Server exists, connect to service and validate
+ // // credentials
+ // BugzillaClient.validateCredentials(proxySettings, serverUrl,
+ // newEncoding, newUserId,
+ // newPassword);
+ // }
+ //
+ // if (checkVersion) {
+ // RepositoryConfiguration config =
+ // BugzillaCorePlugin.getRepositoryConfiguration(true,
+ // serverUrl, proxySettings, newUserId, newPassword, newEncoding);
+ //
+ // if (config != null) {
+ // version[0] = config.getInstallVersion();
+ // }
+ // }
+ //
+ // } catch (Exception e) {
+ // throw new InvocationTargetException(e);
+ // } finally {
+ // monitor.done();
+ // }
+ // }
+ // });
+
if (version[0] != null) {
setBugzillaVersion(version[0]);
}
@@ -222,15 +253,13 @@ public class BugzillaRepositorySettingsPage extends AbstractRepositorySettingsPa
MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG, "Server URL is invalid.");
} else if (e.getCause() instanceof LoginException) {
MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG,
- "Unable to authenticate with server. Login credentials invalid.");
+ "Unable to authenticate with server.\n\n" + e.getCause().getMessage());
} else if (e.getCause() instanceof IOException) {
MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG,
"No Bugzilla server found at url");
} else {
MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG, MESSAGE_FAILURE_UNKNOWN);
}
- } catch (MalformedURLException e) {
- MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG, "Server URL is invalid.");
} catch (InterruptedException e) {
MessageDialog.openWarning(null, IBugzillaConstants.TITLE_MESSAGE_DIALOG, MESSAGE_FAILURE_UNKNOWN);
}
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositoryUi.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositoryUi.java
index 726cec5bb..4a273c41a 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositoryUi.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaRepositoryUi.java
@@ -15,7 +15,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaClient;
import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchPage;
import org.eclipse.mylar.internal.bugzilla.ui.wizard.NewBugzillaTaskWizard;
import org.eclipse.mylar.internal.tasks.ui.OpenRemoteTaskJob;
@@ -77,7 +77,7 @@ public class BugzillaRepositoryUi extends AbstractRepositoryConnectorUi {
} catch (NumberFormatException e) {
return;
}
- String bugUrl = BugzillaServerFacade.getBugUrlWithoutLogin(repositoryUrl, id);
+ String bugUrl = BugzillaClient.getBugUrlWithoutLogin(repositoryUrl, id);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
OpenRemoteTaskJob job = new OpenRemoteTaskJob(BugzillaCorePlugin.REPOSITORY_KIND, repositoryUrl, idString,
bugUrl, page);
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java
index 5d5e9c0dc..9d7c7de66 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskEditorInput.java
@@ -17,14 +17,13 @@ import java.io.IOException;
import java.security.GeneralSecurityException;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.internal.tasks.ui.editors.ExistingBugEditorInput;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
import org.eclipse.mylar.tasks.core.TaskRepository;
-import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.ui.IPersistableElement;
/**
@@ -104,9 +103,7 @@ public class BugzillaTaskEditorInput extends ExistingBugEditorInput {
private void updateOptions(RepositoryTaskData taskData) {
try {
if (taskData != null) {
- BugzillaServerFacade.updateBugAttributeOptions(taskData.getRepositoryUrl(), TasksUiPlugin.getDefault()
- .getProxySettings(), repository.getUserName(), repository.getPassword(), taskData, repository
- .getCharacterEncoding());
+ BugzillaCorePlugin.getDefault().getConnector().updateAttributeOptions(repository, taskData);
}
} catch (Exception e) {
// ignore
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java
index c02732522..a8ae28340 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/wizard/BugzillaProductPage.java
@@ -38,11 +38,12 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.mylar.context.core.MylarStatusHandler;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaException;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaQueryHit;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportElement;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryConnector;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
-import org.eclipse.mylar.internal.bugzilla.core.BugzillaServerFacade;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
@@ -115,7 +116,7 @@ public class BugzillaProductPage extends WizardPage implements Listener {
private String prevProduct;
private final TaskRepository repository;
-
+
protected IPreferenceStore prefs = BugzillaUiPlugin.getDefault().getPreferenceStore();
@@ -211,8 +212,7 @@ public class BugzillaProductPage extends WizardPage implements Listener {
InterruptedException {
monitor.beginTask("Updating repository report options...", IProgressMonitor.UNKNOWN);
try {
- connector.updateAttributes(repository, TasksUiPlugin.getDefault().getProxySettings(),
- monitor);
+ connector.updateAttributes(repository, monitor);
} catch (CoreException ce) {
if (ce.getStatus().getException() instanceof GeneralSecurityException) {
MylarStatusHandler.fail(ce,
@@ -265,9 +265,7 @@ public class BugzillaProductPage extends WizardPage implements Listener {
if (storedProducts.length > 0) {
products = Arrays.asList(storedProducts);
} else {
- products = BugzillaServerFacade.getProductList(repository.getUrl(), TasksUiPlugin.getDefault()
- .getProxySettings(), repository.getUserName(), repository.getPassword(), repository
- .getCharacterEncoding());
+ products = BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, false).getProducts();
}
bugWizard.model.setConnected(true);
bugWizard.model.setParsedProductsStatus(true);
@@ -435,16 +433,13 @@ public class BugzillaProductPage extends WizardPage implements Listener {
* @throws KeyManagementException
* @throws BugzillaException
*/
- public void saveDataToModel() throws KeyManagementException, GeneralSecurityException, IOException,
- BugzillaException {
+ public void saveDataToModel() throws CoreException {
NewBugzillaReport model = bugWizard.model;
prevProduct = model.getProduct();
model.setProduct((listBox.getSelection())[0]);
if (!model.hasParsedAttributes() || !model.getProduct().equals(prevProduct)) {
- BugzillaServerFacade.setupNewBugAttributes(repository.getUrl(), TasksUiPlugin.getDefault()
- .getProxySettings(), repository.getUserName(), repository.getPassword(), model, repository
- .getCharacterEncoding());
+ BugzillaRepositoryConnector.setupNewBugAttributes(repository, model);
model.setParsedAttributesStatus(true);
}
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index c1ae1abcf..bd18f1cc2 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Eclipse-AutoStart: true
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.mylar.context.core
+ org.eclipse.mylar.context.core,
+ org.eclipse.update.core
Export-Package: org.eclipse.mylar.internal.tasks.core,
org.eclipse.mylar.tasks.core
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
index 619e5d79c..8ce2a497e 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
@@ -11,24 +11,15 @@
package org.eclipse.mylar.internal.tasks.core;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
import java.net.Proxy;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
+import java.net.Proxy.Type;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.protocol.Protocol;
+import org.eclipse.update.internal.core.UpdateCore;
/**
* @author Mik Kersten
@@ -40,7 +31,7 @@ public class WebClientUtil {
private static final int HTTPS_PORT = 443;
- private static final int COM_TIME_OUT = 30000;
+ // private static final int COM_TIME_OUT = 30000;
public static final String ENCODING_GZIP = "gzip";
@@ -51,68 +42,94 @@ public class WebClientUtil {
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "off");
}
- /**
- * Returns an opened HttpURLConnection. If the proxy fails a direct connection
- * is attempted.
- */
- public static HttpURLConnection openUrlConnection(URL url, Proxy proxy, boolean useTls) throws IOException,
- KeyManagementException, GeneralSecurityException {
-
- if (proxy == null) {
- proxy = Proxy.NO_PROXY;
- }
-
- HttpURLConnection remoteConnection = getUrlConnection(url, proxy, useTls);
- try {
- remoteConnection = openConnection(url, proxy);
- } catch (ConnectException e) {
- remoteConnection = openConnection(url, Proxy.NO_PROXY);
- }
-
- return remoteConnection;
- }
-
- /**
- * Returns connection that has yet to be opened (can still set connection parameters).
- * Catch ConnectException and retry with Proxy.NO_PROXY if necessary.
- */
- public static HttpURLConnection getUrlConnection(URL url, Proxy proxy, boolean useTls) throws IOException,
- KeyManagementException, GeneralSecurityException {
- SSLContext ctx;
- if (useTls) {
- ctx = SSLContext.getInstance("TLS");
- } else {
- ctx = SSLContext.getInstance("SSL");
- }
-
- javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new RepositoryTrustManager() };
- ctx.init(null, tm, null);
- HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
-
- if (proxy == null) {
- proxy = Proxy.NO_PROXY;
- }
-
- URLConnection connection = url.openConnection(proxy);
-
- if (connection == null || !(connection instanceof HttpURLConnection)) {
- throw new MalformedURLException();
- }
- return (HttpURLConnection)connection;
- }
-
- private static HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException {
- URLConnection connection = url.openConnection(proxy);
- if (connection == null || !(connection instanceof HttpURLConnection)) {
- throw new MalformedURLException();
- }
- HttpURLConnection remoteConnection = (HttpURLConnection) connection;
- remoteConnection.addRequestProperty("Accept-Encoding", ENCODING_GZIP);
- remoteConnection.setConnectTimeout(COM_TIME_OUT);
- remoteConnection.setReadTimeout(COM_TIME_OUT);
- remoteConnection.connect();
- return remoteConnection;
- }
+ // /**
+ // * Returns an opened HttpURLConnection. If the proxy fails a direct
+ // * connection is attempted.
+ // */
+ // public static HttpURLConnection openUrlConnection(URL url, Proxy proxy,
+ // boolean useTls, String htAuthUser,
+ // String htAuthPass) throws IOException, KeyManagementException,
+ // GeneralSecurityException {
+ //
+ // if (proxy == null) {
+ // proxy = Proxy.NO_PROXY;
+ // }
+ //
+ // HttpURLConnection remoteConnection = getUrlConnection(url, proxy, useTls,
+ // htAuthUser, htAuthPass);
+ // try {
+ // remoteConnection = openConnection(url, proxy);
+ // } catch (ConnectException e) {
+ // remoteConnection = openConnection(url, Proxy.NO_PROXY);
+ // }
+ //
+ // return remoteConnection;
+ // }
+
+ // /**
+ // * Returns connection that has yet to be opened (can still set connection
+ // * parameters). Catch ConnectException and retry with Proxy.NO_PROXY if
+ // * necessary.
+ // */
+ // public static HttpURLConnection getUrlConnection(URL url, Proxy proxy,
+ // boolean useTls, String htAuthUser,
+ // String htAuthPass) throws IOException, KeyManagementException,
+ // GeneralSecurityException {
+ // SSLContext ctx;
+ // if (useTls) {
+ // ctx = SSLContext.getInstance("TLS");
+ // } else {
+ // ctx = SSLContext.getInstance("SSL");
+ // }
+ //
+ // javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new
+ // RepositoryTrustManager() };
+ // ctx.init(null, tm, null);
+ // HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
+ //
+ // if (proxy == null) {
+ // proxy = Proxy.NO_PROXY;
+ // }
+ //
+ // URLConnection connection = url.openConnection(proxy);
+ //
+ // // Add http basic authentication credentials if supplied
+ // // Ref: http://www.javaworld.com/javaworld/javatips/jw-javatip47.html
+ // if (htAuthUser != null && htAuthPass != null && !htAuthUser.equals("")) {
+ // String authenticationString = htAuthUser + ":" + htAuthPass;
+ // String encodedAuthenticationString = null;
+ // try {
+ // sun.misc.BASE64Encoder encoder = (sun.misc.BASE64Encoder)
+ // Class.forName("sun.misc.BASE64Encoder")
+ // .newInstance();
+ // encodedAuthenticationString =
+ // encoder.encode(authenticationString.getBytes());
+ // connection.setRequestProperty("Authorization", "Basic " +
+ // encodedAuthenticationString);
+ // } catch (Exception ex) {
+ // // ignore, encoder not available
+ // }
+ // }
+ //
+ // if (connection == null || !(connection instanceof HttpURLConnection)) {
+ // throw new MalformedURLException();
+ // }
+ // return (HttpURLConnection) connection;
+ // }
+
+ // private static HttpURLConnection openConnection(URL url, Proxy proxy)
+ // throws IOException {
+ // URLConnection connection = url.openConnection(proxy);
+ // if (connection == null || !(connection instanceof HttpURLConnection)) {
+ // throw new MalformedURLException();
+ // }
+ // HttpURLConnection remoteConnection = (HttpURLConnection) connection;
+ // remoteConnection.addRequestProperty("Accept-Encoding", ENCODING_GZIP);
+ // remoteConnection.setConnectTimeout(COM_TIME_OUT);
+ // remoteConnection.setReadTimeout(COM_TIME_OUT);
+ // remoteConnection.connect();
+ // return remoteConnection;
+ // }
/**
* public for testing
@@ -169,14 +186,16 @@ public class WebClientUtil {
return repositoryUrl.substring(requestPath);
}
- public static void setupHttpClient(HttpClient client, Proxy proxySettings, String repositoryUrl, String user, String password) {
+ public static void setupHttpClient(HttpClient client, Proxy proxySettings, String repositoryUrl, String user,
+ String password) {
if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) proxySettings.address();
client.getHostConfiguration().setProxy(address.getHostName(), address.getPort());
}
-
- if(user!=null && password!=null) {
- AuthScope authScope = new AuthScope(WebClientUtil.getDomain(repositoryUrl), WebClientUtil.getPort(repositoryUrl), AuthScope.ANY_REALM);
+
+ if (user != null && password != null) {
+ AuthScope authScope = new AuthScope(WebClientUtil.getDomain(repositoryUrl), WebClientUtil
+ .getPort(repositoryUrl), AuthScope.ANY_REALM);
client.getState().setCredentials(authScope, new UsernamePasswordCredentials(user, password));
}
@@ -191,4 +210,15 @@ public class WebClientUtil {
}
}
+ public static Proxy getProxySettings() {
+ Proxy proxy = Proxy.NO_PROXY;
+ if (UpdateCore.getPlugin().getPluginPreferences().getBoolean(UpdateCore.HTTP_PROXY_ENABLE)) {
+ String proxyHost = UpdateCore.getPlugin().getPluginPreferences().getString(UpdateCore.HTTP_PROXY_HOST);
+ int proxyPort = UpdateCore.getPlugin().getPluginPreferences().getInt(UpdateCore.HTTP_PROXY_PORT);
+
+ InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort);
+ proxy = new Proxy(Type.HTTP, sockAddr);
+ }
+ return proxy;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
index 70db45265..5bf7b5390 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
@@ -25,7 +25,7 @@ import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask.RepositoryTaskSyncState;
/**
- * Encapsulates synchronization policy.
+ * Operations on a task repository
*
* @author Mik Kersten
* @author Rob Elves
@@ -45,7 +45,7 @@ public abstract class AbstractRepositoryConnector {
protected TaskList taskList;
public void init(TaskList taskList) {
- this.taskList = taskList;
+ this.taskList = taskList;
}
/**
@@ -65,18 +65,6 @@ public abstract class AbstractRepositoryConnector {
public abstract boolean canCreateNewTask(TaskRepository repository);
/**
- * Reset and update the repository attributes from the server (e.g.
- * products, components)
- *
- * @param proxySettings
- * TODO
- * @throws CoreException
- * TODO
- */
- public abstract void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor)
- throws CoreException;
-
- /**
* @param id
* identifier, e.g. "123" bug Bugzilla bug 123
* @param proxySettings
@@ -193,14 +181,14 @@ public abstract class AbstractRepositoryConnector {
File destinationContextFile = ContextCorePlugin.getContextManager().getFileForContext(
task.getHandleIdentifier());
-
+
// TODO: add functionality for not overwriting previous context
- if(destinationContextFile.exists()) {
- if(!destinationContextFile.delete()) {
+ if (destinationContextFile.exists()) {
+ if (!destinationContextFile.delete()) {
return false;
}
}
- attachmentHandler.downloadAttachment(repository, task, attachment, destinationContextFile, proxySettings);
+ attachmentHandler.downloadAttachment(repository, AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()), attachment, destinationContextFile);
return true;
}
@@ -226,4 +214,12 @@ public abstract class AbstractRepositoryConnector {
return "task";
}
+ /**
+ * Reset and update the repository attributes from the server (e.g.
+ * products, components)
+ *
+ * TODO: remove?
+ */
+ public abstract void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException;
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
index d3e45c63a..4e15ffb5f 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
@@ -25,9 +25,12 @@ public interface IAttachmentHandler {
public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment,
String description, File file, String contentType, boolean isPatch, Proxy proxySettings) throws CoreException;
- public void downloadAttachment(TaskRepository taskRepository, AbstractRepositoryTask task,
- RepositoryAttachment attachment, File file, Proxy proxySettings) throws CoreException;
+ public void downloadAttachment(TaskRepository taskRepository, String taskId, RepositoryAttachment attachment, File file) throws CoreException;
+ public byte[] getAttachmentData(TaskRepository repository, String taskId) throws CoreException;
+
+ //public InputStream getAttachmentInputStream(TaskRepository repository, String taskId) throws CoreException;
+
public boolean canUploadAttachment(TaskRepository repository, AbstractRepositoryTask task);
public boolean canDownloadAttachment(TaskRepository repository, AbstractRepositoryTask task);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
index 8faf2e69d..d9bf5810b 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
@@ -16,8 +16,6 @@ import java.net.Proxy;
import java.util.Date;
import java.util.Set;
-import javax.security.auth.login.LoginException;
-
import org.eclipse.core.runtime.CoreException;
/**
@@ -33,7 +31,8 @@ public interface IOfflineTaskHandler {
public AbstractAttributeFactory getAttributeFactory();
- public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId, Proxy proxySettings) throws CoreException, LoginException;
+ // TODO: remove proxy parameter
+ public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId, Proxy proxySettings) throws CoreException;
/**
* returns all tasks if date is null or an error occurs
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
index 0bfdeff63..2b04e8a06 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
@@ -46,6 +46,10 @@ public class TaskRepository {
public static final String AUTH_USERNAME = "org.eclipse.mylar.tasklist.repositories.username"; //$NON-NLS-1$
+ public static final String AUTH_HTTP_PASSWORD = "org.eclipse.mylar.tasklist.repositories.httpauth.password"; //$NON-NLS-1$
+
+ public static final String AUTH_HTTP_USERNAME = "org.eclipse.mylar.tasklist.repositories.httpauth.username"; //$NON-NLS-1$
+
public static final String NO_VERSION_SPECIFIED = "unknown";
private static final String AUTH_SCHEME = "Basic";
@@ -270,5 +274,4 @@ public class TaskRepository {
String value = getProperty(name);
return value != null && value.trim().length() > 0;
}
-
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
index d9544d126..7380d2f08 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
@@ -34,7 +34,7 @@ public class TaskRepositoryManager {
public static final String OLD_REPOSITORIES_FILE = "repositories.xml";
public static final String DEFAULT_REPOSITORIES_FILE = "repositories.xml.zip";
-
+
public static final String PREF_REPOSITORIES = "org.eclipse.mylar.tasklist.repositories.";
private Map<String, AbstractRepositoryConnector> repositoryConnectors = new HashMap<String, AbstractRepositoryConnector>();
@@ -52,7 +52,7 @@ public class TaskRepositoryManager {
private TaskRepositoriesExternalizer externalizer = new TaskRepositoriesExternalizer();
private TaskList taskList;
-
+
public TaskRepositoryManager(TaskList taskList) {
this.taskList = taskList;
}
@@ -64,7 +64,7 @@ public class TaskRepositoryManager {
public AbstractRepositoryConnector getRepositoryConnector(String kind) {
return repositoryConnectors.get(kind);
}
-
+
public AbstractRepositoryConnector getRepositoryConnector(AbstractRepositoryTask task) {
return getRepositoryConnector(task.getRepositoryKind());
}
@@ -121,18 +121,18 @@ public class TaskRepositoryManager {
}
return null;
}
-
+
/**
* @return first repository that matches the given url
*/
public TaskRepository getRepository(String urlString) {
- for (String kind: repositoryMap.keySet()) {
+ for (String kind : repositoryMap.keySet()) {
for (TaskRepository repository : repositoryMap.get(kind)) {
if (repository.getUrl().equals(urlString)) {
return repository;
}
}
- }
+ }
return null;
}
@@ -215,7 +215,8 @@ public class TaskRepositoryManager {
private void loadRepositories(String repositoriesFilePath) {
try {
-// String dataDirectory = TasksUiPlugin.getDefault().getDataDirectory();
+ // String dataDirectory =
+ // TasksUiPlugin.getDefault().getDataDirectory();
File repositoriesFile = new File(repositoriesFilePath);
// Will only load repositories for which a connector exists
@@ -289,8 +290,10 @@ public class TaskRepositoryManager {
}
try {
-// String dataDirectory = TasksUiPlugin.getDefault().getDataDirectory();
-// File repositoriesFile = new File(dataDirectory + File.separator + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
+ // String dataDirectory =
+ // TasksUiPlugin.getDefault().getDataDirectory();
+ // File repositoriesFile = new File(dataDirectory + File.separator +
+ // TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
File repositoriesFile = new File(destinationPath);
externalizer.writeRepositoriesToXML(repositoriesToWrite, repositoriesFile);
} catch (Throwable t) {
@@ -320,4 +323,5 @@ public class TaskRepositoryManager {
listener.repositorySettingsChanged(repository);
}
}
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
index 939ab1973..965f1bc1c 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositorySettingsPageTest.java
@@ -158,7 +158,7 @@ public class RepositorySettingsPageTest extends TestCase {
}
StringFieldEditor getPasswordEditor() {
- return passwordEditor;
+ return repositoryPasswordEditor;
}
Composite getParent() {
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java
index fcd97e39a..b85639b73 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/RepositoryTaskSynchronizationTest.java
@@ -15,8 +15,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
-import javax.security.auth.login.LoginException;
-
import junit.framework.TestCase;
import org.eclipse.core.runtime.CoreException;
@@ -317,7 +315,7 @@ public class RepositoryTaskSynchronizationTest extends TestCase {
}
public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId,
- Proxy proxySettings) throws CoreException, LoginException {
+ Proxy proxySettings) throws CoreException {
return null;
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
index 8e04d95a4..47c1a295f 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryConnector.java
@@ -87,7 +87,7 @@ public class MockRepositoryConnector extends AbstractRepositoryConnector {
}
@Override
- public void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor) throws CoreException {
+ public void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
// ignore
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotification.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotification.java
index a1101b8eb..124069f3e 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotification.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/ITaskListNotification.java
@@ -18,7 +18,7 @@ import org.eclipse.swt.graphics.Image;
/**
* @author Rob Elves
*/
-public interface ITaskListNotification {
+public interface ITaskListNotification extends Comparable<ITaskListNotification> {
public void openTask();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/OpenRemoteTaskJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/OpenRemoteTaskJob.java
index 984f3f9c5..832eb8eb6 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/OpenRemoteTaskJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/OpenRemoteTaskJob.java
@@ -87,12 +87,7 @@ public class OpenRemoteTaskJob extends Job {
RepositoryTaskData downloadedTaskData = null;
try {
downloadedTaskData = offlineHandler.downloadTaskData(repository, taskId, TasksUiPlugin.getDefault().getProxySettings());
- openEditor(repository, downloadedTaskData);
- } catch (final LoginException e) {
- MylarStatusHandler.fail(e,
- "Report download failed. Ensure proper repository configuration of "
- + repository.getUrl() + " in " + TaskRepositoriesView.NAME
- + ".", true);
+ openEditor(repository, downloadedTaskData);
} catch (final CoreException e) {
// TODO generalize exception handling
if (e.getStatus().getException() instanceof UnrecognizedReponseException) {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationIncoming.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationIncoming.java
index 01fb8776a..a2743bcba 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationIncoming.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationIncoming.java
@@ -100,7 +100,7 @@ public class TaskListNotificationIncoming implements ITaskListNotification {
this.date = date;
}
- public int compareTo(Object anotherNotification) throws ClassCastException {
+ public int compareTo(ITaskListNotification anotherNotification) throws ClassCastException {
if (!(anotherNotification instanceof ITaskListNotification))
throw new ClassCastException("A ITaskListNotification object expected.");
Date anotherDate = ((ITaskListNotification) anotherNotification).getDate();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java
index ef4309803..1ec330b0f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationManager.java
@@ -69,7 +69,7 @@ public class TaskListNotificationManager implements IPropertyChangeListener {
if (currentlyNotifying.size() > 0) {
popup = new TaskListNotificationPopup(new Shell(PlatformUI.getWorkbench()
.getDisplay()));
- ArrayList toDisplay = new ArrayList<ITaskListNotification>(currentlyNotifying);
+ List<ITaskListNotification> toDisplay = new ArrayList<ITaskListNotification>(currentlyNotifying);
Collections.sort(toDisplay);
popup.setContents(toDisplay);
cleanNotified();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationQueryIncoming.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationQueryIncoming.java
index 23b45ca82..3eabb5c90 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationQueryIncoming.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationQueryIncoming.java
@@ -85,7 +85,7 @@ public class TaskListNotificationQueryIncoming implements ITaskListNotification
this.date = date;
}
- public int compareTo(Object anotherNotification) throws ClassCastException {
+ public int compareTo(ITaskListNotification anotherNotification) throws ClassCastException {
if (!(anotherNotification instanceof ITaskListNotification))
throw new ClassCastException("A ITaskListNotification object expected.");
Date anotherDate = ((ITaskListNotification) anotherNotification).getDate();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationReminder.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationReminder.java
index bb5620655..24cc8450d 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationReminder.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/TaskListNotificationReminder.java
@@ -89,7 +89,7 @@ public class TaskListNotificationReminder implements ITaskListNotification {
this.date = date;
}
- public int compareTo(Object anotherNotification) throws ClassCastException {
+ public int compareTo(ITaskListNotification anotherNotification) throws ClassCastException {
if (!(anotherNotification instanceof ITaskListNotification))
throw new ClassCastException("A ITaskListNotification object expected.");
Date anotherDate = ((ITaskListNotification) anotherNotification).getDate();
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractRepositoryTaskEditor.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractRepositoryTaskEditor.java
index f5525c229..a066bac31 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractRepositoryTaskEditor.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractRepositoryTaskEditor.java
@@ -10,13 +10,10 @@
*******************************************************************************/
package org.eclipse.mylar.internal.tasks.ui.editors;
-import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -27,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
@@ -66,6 +64,7 @@ import org.eclipse.mylar.internal.tasks.ui.wizards.NewAttachmentWizard;
import org.eclipse.mylar.internal.tasks.ui.wizards.NewAttachmentWizardDialog;
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
+import org.eclipse.mylar.tasks.core.IAttachmentHandler;
import org.eclipse.mylar.tasks.core.IOfflineTaskHandler;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.RepositoryAttachment;
@@ -209,7 +208,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
protected RepositoryTaskOutlineNode taskOutlineModel = null;
protected boolean expandedStateAttributes = false;
-
+
/**
* Style option for function <code>newLayout</code>. This will create a
* plain-styled, selectable text label.
@@ -444,7 +443,8 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
protected abstract void validateInput();
protected String getTitleString() {
- return getRepositoryTaskData().getLabel();// + ": " + checkText(summaryVal);
+ return getRepositoryTaskData().getLabel();// + ": " +
+ // checkText(summaryVal);
}
protected abstract void submitBug();
@@ -533,28 +533,33 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
String statusValue = this.getRepositoryTaskData().getAttributeValue(RepositoryTaskAttribute.STATUS);
toolkit.createText(headerInfoComposite, statusValue, SWT.FLAT | SWT.READ_ONLY);
toolkit.createLabel(headerInfoComposite, " Priority: ").setFont(TITLE_FONT);
- toolkit.createText(headerInfoComposite, getRepositoryTaskData().getAttributeValue(RepositoryTaskAttribute.PRIORITY), SWT.FLAT | SWT.READ_ONLY);
-// RepositoryTaskAttribute attribute = getRepositoryTaskData().getAttribute(RepositoryTaskAttribute.PRIORITY);
-// if (attribute != null) {
-// String value = attribute.getValue() != null ? attribute.getValue() : "";
-// attributeCombo = new CCombo(headerInfoComposite, SWT.FLAT | SWT.READ_ONLY);
-// toolkit.adapt(attributeCombo, true, true);
-// attributeCombo.setFont(TEXT_FONT);
-// if (attribute.getValues() != null) {
-//
-// Set<String> s = attribute.getOptionValues().keySet();
-// String[] a = s.toArray(new String[s.size()]);
-// for (int i = 0; i < a.length; i++) {
-// attributeCombo.add(a[i]);
-// }
-// if (attributeCombo.indexOf(value) != -1) {
-// attributeCombo.select(attributeCombo.indexOf(value));
-// }
-// }
-// attributeCombo.addSelectionListener(new ComboSelectionListener(attributeCombo));
-// comboListenerMap.put(attributeCombo, attribute);
-// attributeCombo.addListener(SWT.FocusIn, new GenericListener());
-// }
+ toolkit.createText(headerInfoComposite, getRepositoryTaskData().getAttributeValue(
+ RepositoryTaskAttribute.PRIORITY), SWT.FLAT | SWT.READ_ONLY);
+ // RepositoryTaskAttribute attribute =
+ // getRepositoryTaskData().getAttribute(RepositoryTaskAttribute.PRIORITY);
+ // if (attribute != null) {
+ // String value = attribute.getValue() != null ? attribute.getValue() :
+ // "";
+ // attributeCombo = new CCombo(headerInfoComposite, SWT.FLAT |
+ // SWT.READ_ONLY);
+ // toolkit.adapt(attributeCombo, true, true);
+ // attributeCombo.setFont(TEXT_FONT);
+ // if (attribute.getValues() != null) {
+ //
+ // Set<String> s = attribute.getOptionValues().keySet();
+ // String[] a = s.toArray(new String[s.size()]);
+ // for (int i = 0; i < a.length; i++) {
+ // attributeCombo.add(a[i]);
+ // }
+ // if (attributeCombo.indexOf(value) != -1) {
+ // attributeCombo.select(attributeCombo.indexOf(value));
+ // }
+ // }
+ // attributeCombo.addSelectionListener(new
+ // ComboSelectionListener(attributeCombo));
+ // comboListenerMap.put(attributeCombo, attribute);
+ // attributeCombo.addListener(SWT.FocusIn, new GenericListener());
+ // }
toolkit.createLabel(headerInfoComposite, " ID: ").setFont(TITLE_FONT);
toolkit.createText(headerInfoComposite, "" + getRepositoryTaskData().getId(), SWT.FLAT | SWT.READ_ONLY);
@@ -611,7 +616,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
continue;
Map<String, String> values = attribute.getOptionValues();
-
+
if (values == null)
values = new HashMap<String, String>();
@@ -868,7 +873,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
return;
}
- IStorageEditorInput input = new RepositoryAttachmentEditorInput(attachment);
+ IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page == null) {
return;
@@ -887,7 +892,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
public void run() {
RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
.getSelection()).getFirstElement());
- IStorageEditorInput input = new RepositoryAttachmentEditorInput(attachment);
+ IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, attachment);
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page == null) {
return;
@@ -932,10 +937,19 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
}
// TODO: Use IAttachmentHandler instead
+
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
+ .getRepositoryConnector(repository.getKind());
+ IAttachmentHandler handler = connector.getAttachmentHandler();
+
SaveRemoteFileAction save = new SaveRemoteFileAction();
- save.setDestinationFilePath(filePath);
- save.setInputStream(getAttachmentInputStream(attachment.getUrl()));
- save.run();
+ try {
+ save.setInputStream(new ByteArrayInputStream(handler.getAttachmentData(repository, "" + attachment.getId())));
+ save.setDestinationFilePath(filePath);
+ save.run();
+ } catch (CoreException e) {
+ MylarStatusHandler.fail(e.getStatus().getException(), "Attachment save failed", false);
+ }
}
};
@@ -944,7 +958,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
RepositoryAttachment attachment = (RepositoryAttachment) (((StructuredSelection) attachmentsTableViewer
.getSelection()).getFirstElement());
CopyToClipboardAction copyToClip = new CopyToClipboardAction();
- copyToClip.setContents(getAttachmentContents(attachment.getUrl()));
+ copyToClip.setContents(getAttachmentContents(attachment));
copyToClip.setControl(attachmentsTable.getParent());
copyToClip.run();
}
@@ -970,7 +984,7 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
popupMenu.add(openMenu);
openMenu.removeAll();
- IStorageEditorInput input = new RepositoryAttachmentEditorInput(att);
+ IStorageEditorInput input = new RepositoryAttachmentEditorInput(repository, att);
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(
input.getName());
if (desc != null) {
@@ -1152,39 +1166,43 @@ public abstract class AbstractRepositoryTaskEditor extends TaskFormPage {
});
}
- public static InputStream getAttachmentInputStream(String url) {
- URLConnection urlConnect;
- InputStream stream = null;
- try {
- urlConnect = (new URL(url)).openConnection();
- urlConnect.connect();
- stream = urlConnect.getInputStream();
-
- } catch (MalformedURLException e) {
- MylarStatusHandler.fail(e, "Attachment url was malformed.", false);
- } catch (IOException e) {
- MylarStatusHandler.fail(e, "I/O Error occurred reading attachment.", false);
- }
- return stream;
- }
+ // public static InputStream getAttachmentInputStream(String url) {
+ // URLConnection urlConnect;
+ // InputStream stream = null;
+ // try {
+ // urlConnect = (new URL(url)).openConnection();
+ // urlConnect.connect();
+ // stream = urlConnect.getInputStream();
+ //
+ // } catch (MalformedURLException e) {
+ // MylarStatusHandler.fail(e, "Attachment url was malformed.", false);
+ // } catch (IOException e) {
+ // MylarStatusHandler.fail(e, "I/O Error occurred reading attachment.",
+ // false);
+ // }
+ // return stream;
+ // }
- public static String getAttachmentContents(String url) {
- URLConnection urlConnect;
+ public String getAttachmentContents(RepositoryAttachment attachment) {
StringBuffer contents = new StringBuffer();
try {
- urlConnect = (new URL(url)).openConnection();
- urlConnect.connect();
- BufferedInputStream stream = new BufferedInputStream(urlConnect.getInputStream());
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
+ repository.getKind());
+ IAttachmentHandler handler = connector.getAttachmentHandler();
+ InputStream stream;
+
+ stream = new ByteArrayInputStream(handler.getAttachmentData(repository, "" + attachment.getId()));
+
int c;
while ((c = stream.read()) != -1) {
/* TODO jpound - handle non-text */
contents.append((char) c);
}
stream.close();
- } catch (MalformedURLException e) {
- MylarStatusHandler.fail(e, "Attachment url was malformed.", false);
+ } catch (CoreException e) {
+ MylarStatusHandler.fail(e.getStatus().getException(), "Retrieval of attachment data failed.", false);
} catch (IOException e) {
- MylarStatusHandler.fail(e, "I/O Error occurred reading attachment.", false);
+ MylarStatusHandler.fail(e, "Retrieval of attachment data failed.", false);
}
return contents.toString();
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryAttachmentEditorInput.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryAttachmentEditorInput.java
index a226c6ce1..be0f21018 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryAttachmentEditorInput.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/RepositoryAttachmentEditorInput.java
@@ -8,18 +8,19 @@
package org.eclipse.mylar.internal.tasks.ui.editors;
-import java.io.IOException;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLConnection;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylar.tasks.core.IAttachmentHandler;
import org.eclipse.mylar.tasks.core.RepositoryAttachment;
+import org.eclipse.mylar.tasks.core.TaskRepository;
+import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.IStorageEditorInput;
@@ -30,10 +31,12 @@ public class RepositoryAttachmentEditorInput extends PlatformObject implements I
private RepositoryAttachment attachment;
private RepositoryAttachmentStorage storage;
+ private TaskRepository repository;
- public RepositoryAttachmentEditorInput(RepositoryAttachment att) {
+ public RepositoryAttachmentEditorInput(TaskRepository repository, RepositoryAttachment att) {
this.attachment = att;
this.storage = new RepositoryAttachmentStorage();
+ this.repository = repository;
}
public IStorage getStorage() throws CoreException {
@@ -77,21 +80,25 @@ public class RepositoryAttachmentEditorInput extends PlatformObject implements I
public InputStream getContents() throws CoreException {
- URLConnection urlConnect;
- InputStream stream = null;
- try {
- urlConnect = (new URL(attachment.getUrl())).openConnection();
- urlConnect.connect();
- stream = urlConnect.getInputStream();
-
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return stream;
+// URLConnection urlConnect;
+// InputStream stream = null;
+// try {
+
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(repository.getKind());
+ IAttachmentHandler handler = connector.getAttachmentHandler();
+ return new ByteArrayInputStream(handler.getAttachmentData(repository, ""+attachment.getId()));
+// urlConnect = (new URL(attachment.getUrl())).openConnection();
+// urlConnect.connect();
+// stream = urlConnect.getInputStream();
+
+// } catch (MalformedURLException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+// return stream;
}
public IPath getFullPath() {
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
index 8827bf8f9..b2630c73f 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/ResetRepositoryConfigurationAction.java
@@ -61,7 +61,7 @@ public class ResetRepositoryConfigurationAction extends Action {
monitor.beginTask(jobName,
IProgressMonitor.UNKNOWN);
try {
- connector.updateAttributes(repository, TasksUiPlugin.getDefault().getProxySettings(), monitor);
+ connector.updateAttributes(repository, monitor);
} catch (CoreException ce) {
MylarStatusHandler.fail(ce, ce.getStatus().getMessage(), true);
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractRepositorySettingsPage.java
index 39e4cfde8..3c3d8af64 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/AbstractRepositorySettingsPage.java
@@ -69,7 +69,11 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
private String serverVersion = TaskRepository.NO_VERSION_SPECIFIED;
- protected StringFieldEditor passwordEditor;
+ protected StringFieldEditor repositoryPasswordEditor;
+
+ protected StringFieldEditor httpAuthUserNameEditor;
+
+ protected StringFieldEditor httpAuthPasswordEditor;
protected TaskRepository repository;
@@ -87,12 +91,18 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
private String oldPassword;
+ private String oldHttpAuthUserId;
+
+ private String oldHttpAuthPassword;
+
private boolean needsAnonymousLogin;
private boolean needsTimeZone;
private boolean needsEncoding;
+ private boolean needsHttpAuth;
+
private Composite container;
private Set<String> repositoryUrls;
@@ -101,6 +111,8 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
private Button otherEncoding;
+ private Button httpAuthButton;
+
public AbstractRepositorySettingsPage(String title, String description, AbstractRepositoryConnectorUi repositoryUi) {
super(title);
super.setTitle(title);
@@ -186,11 +198,20 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
}
userNameEditor = new StringFieldEditor("", LABEL_USER, StringFieldEditor.UNLIMITED, container);
- passwordEditor = new RepositoryStringFieldEditor("", LABEL_PASSWORD, StringFieldEditor.UNLIMITED, container);
+ repositoryPasswordEditor = new RepositoryStringFieldEditor("", LABEL_PASSWORD, StringFieldEditor.UNLIMITED,
+ container);
if (repository != null) {
originalUrl = repository.getUrl();
oldUsername = repository.getUserName();
oldPassword = repository.getPassword();
+ if (repository.hasProperty(TaskRepository.AUTH_HTTP_USERNAME)
+ && repository.hasProperty(TaskRepository.AUTH_HTTP_PASSWORD)) {
+ oldHttpAuthUserId = repository.getProperty(TaskRepository.AUTH_HTTP_USERNAME);
+ oldHttpAuthPassword = repository.getProperty(TaskRepository.AUTH_HTTP_PASSWORD);
+ } else {
+ oldHttpAuthPassword = "";
+ oldHttpAuthUserId = "";
+ }
try {
String repositoryLabel = repository.getRepositoryLabel();
if (repositoryLabel != null && repositoryLabel.length() > 0) {
@@ -200,16 +221,18 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
}
serverUrlCombo.setText(repository.getUrl());
userNameEditor.setStringValue(repository.getUserName());
- passwordEditor.setStringValue(repository.getPassword());
+ repositoryPasswordEditor.setStringValue(repository.getPassword());
} catch (Throwable t) {
MylarStatusHandler.fail(t, "could not set field value for: " + repository, false);
}
} else {
oldUsername = "";
oldPassword = "";
+ oldHttpAuthPassword = "";
+ oldHttpAuthUserId = "";
}
// bug 131656: must set echo char after setting value on Mac
- ((RepositoryStringFieldEditor) passwordEditor).getTextControl().setEchoChar('*');
+ ((RepositoryStringFieldEditor) repositoryPasswordEditor).getTextControl().setEchoChar('*');
if (needsAnonymousLogin()) {
// do this after username and password widgets have been intialized
@@ -304,6 +327,49 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
}
}
+ if (needsHttpAuth()) {
+ httpAuthButton = new Button(container, SWT.CHECK);
+ GridDataFactory.fillDefaults().align(SWT.TOP, SWT.DEFAULT).span(2, SWT.DEFAULT).applyTo(httpAuthButton);
+
+ httpAuthButton.setText("Http Authentication");
+ httpAuthButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ setHttpAuth(httpAuthButton.getSelection());
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // ignore
+ }
+ });
+
+ httpAuthUserNameEditor = new StringFieldEditor("", "User ID: ", StringFieldEditor.UNLIMITED, container) {
+
+ @Override
+ protected boolean doCheckState() {
+ return true;
+ }
+
+ @Override
+ protected void valueChanged() {
+ super.valueChanged();
+ if (getWizard() != null) {
+ getWizard().getContainer().updateButtons();
+ }
+ }
+ };
+ httpAuthPasswordEditor = new RepositoryStringFieldEditor("", "Password: ", StringFieldEditor.UNLIMITED,
+ container);
+ ((RepositoryStringFieldEditor) httpAuthPasswordEditor).getTextControl().setEchoChar('*');
+
+ // httpAuthGroup.setEnabled(httpAuthButton.getSelection());
+ httpAuthUserNameEditor.setEnabled(httpAuthButton.getSelection(), container);
+ ((StringFieldEditor) httpAuthPasswordEditor).setEnabled(httpAuthButton.getSelection(), container);
+
+ setHttpAuth(oldHttpAuthPassword != null && oldHttpAuthUserId != null && !oldHttpAuthPassword.equals("")
+ && !oldHttpAuthUserId.equals(""));
+
+ }
+
validateServerButton = new Button(container, SWT.PUSH);
GridDataFactory.swtDefaults().span(2, SWT.DEFAULT).grab(false, false).applyTo(validateServerButton);
validateServerButton.setText("Validate Settings");
@@ -351,16 +417,34 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
if (selected) {
oldUsername = userNameEditor.getStringValue();
- oldPassword = ((StringFieldEditor) passwordEditor).getStringValue();
+ oldPassword = ((StringFieldEditor) repositoryPasswordEditor).getStringValue();
userNameEditor.setStringValue(null);
- ((StringFieldEditor) passwordEditor).setStringValue(null);
+ ((StringFieldEditor) repositoryPasswordEditor).setStringValue(null);
} else {
userNameEditor.setStringValue(oldUsername);
- ((StringFieldEditor) passwordEditor).setStringValue(oldPassword);
+ ((StringFieldEditor) repositoryPasswordEditor).setStringValue(oldPassword);
}
userNameEditor.setEnabled(!selected, container);
- ((StringFieldEditor) passwordEditor).setEnabled(!selected, container);
+ ((StringFieldEditor) repositoryPasswordEditor).setEnabled(!selected, container);
+ }
+
+ public void setHttpAuth(boolean selected) {
+ if (!needsHttpAuth) {
+ return;
+ }
+ httpAuthButton.setSelection(selected);
+ if (!selected) {
+ oldHttpAuthUserId = httpAuthUserNameEditor.getStringValue();
+ oldHttpAuthPassword = ((StringFieldEditor) httpAuthPasswordEditor).getStringValue();
+ httpAuthUserNameEditor.setStringValue(null);
+ ((StringFieldEditor) httpAuthPasswordEditor).setStringValue(null);
+ } else {
+ httpAuthUserNameEditor.setStringValue(oldHttpAuthUserId);
+ ((StringFieldEditor) httpAuthPasswordEditor).setStringValue(oldHttpAuthPassword);
+ }
+ httpAuthUserNameEditor.setEnabled(selected, container);
+ ((StringFieldEditor) httpAuthPasswordEditor).setEnabled(selected, container);
}
protected abstract void createAdditionalControls(Composite parent);
@@ -391,7 +475,23 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
}
public String getPassword() {
- return passwordEditor.getStringValue();
+ return repositoryPasswordEditor.getStringValue();
+ }
+
+ public String getHttpAuthUserId() {
+ if (needsHttpAuth()) {
+ return httpAuthUserNameEditor.getStringValue();
+ } else {
+ return "";
+ }
+ }
+
+ public String getHttpAuthPassword() {
+ if (needsHttpAuth()) {
+ return httpAuthPasswordEditor.getStringValue();
+ } else {
+ return "";
+ }
}
public void init(IWorkbench workbench) {
@@ -504,6 +604,10 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
getCharacterEncoding(), "");
repository.setRepositoryLabel(getRepositoryLabel());
repository.setAuthenticationCredentials(getUserName(), getPassword());
+
+ repository.setProperty(TaskRepository.AUTH_HTTP_USERNAME, getHttpAuthUserId());
+ repository.setProperty(TaskRepository.AUTH_HTTP_PASSWORD, getHttpAuthPassword());
+
updateProperties(repository);
return repository;
}
@@ -532,6 +636,14 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
this.needsTimeZone = needsTimeZone;
}
+ public boolean needsHttpAuth() {
+ return this.needsHttpAuth;
+ }
+
+ public void setNeedsHttpAuth(boolean needsHttpAuth) {
+ this.needsHttpAuth = needsHttpAuth;
+ }
+
public void setNeedsAnonymousLogin(boolean needsAnonymousLogin) {
this.needsAnonymousLogin = needsAnonymousLogin;
}
@@ -552,7 +664,7 @@ public abstract class AbstractRepositorySettingsPage extends WizardPage {
/** for testing */
public void setPassword(String pass) {
- passwordEditor.setStringValue(pass);
+ repositoryPasswordEditor.setStringValue(pass);
}
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
index 174ee642f..3f78d8fad 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/EditRepositoryWizard.java
@@ -59,8 +59,12 @@ public class EditRepositoryWizard extends Wizard implements INewWizard {
repository.setUrl(newUrl);
repository.setVersion(abstractRepositorySettingsPage.getVersion());
repository.setCharacterEncoding(abstractRepositorySettingsPage.getCharacterEncoding());
- repository.setAuthenticationCredentials(abstractRepositorySettingsPage.getUserName(), abstractRepositorySettingsPage.getPassword());
+ repository.setAuthenticationCredentials(abstractRepositorySettingsPage.getUserName(), abstractRepositorySettingsPage.getPassword());
repository.setRepositoryLabel(abstractRepositorySettingsPage.getRepositoryLabel());
+
+ repository.setProperty(TaskRepository.AUTH_HTTP_USERNAME, abstractRepositorySettingsPage.getHttpAuthUserId());
+ repository.setProperty(TaskRepository.AUTH_HTTP_PASSWORD, abstractRepositorySettingsPage.getHttpAuthPassword());
+
abstractRepositorySettingsPage.updateProperties(repository);
TasksUiPlugin.getRepositoryManager().notifyRepositorySettingsChagned(repository);
TasksUiPlugin.getRepositoryManager().saveRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/RepositorySynchronizationManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/RepositorySynchronizationManager.java
index d9017ac28..facae6112 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/RepositorySynchronizationManager.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/RepositorySynchronizationManager.java
@@ -42,6 +42,7 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryTask.RepositoryTaskSyncSta
import org.eclipse.ui.PlatformUI;
/**
+ * Encapsulates synchronization policy
* TODO: move into core?
*
* @author Mik Kersten
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeTaskJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeTaskJob.java
index 4ba9092ba..16f3b1387 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeTaskJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/SynchronizeTaskJob.java
@@ -102,11 +102,6 @@ class SynchronizeTaskJob extends Job {
downloadedTaskData = offlineHandler.downloadTaskData(repository, taskId,
TasksUiPlugin.getDefault().getProxySettings());
}
- } catch (final LoginException e) {
- MylarStatusHandler.fail(e,
- "Report download failed. Ensure proper repository configuration of "
- + repositoryTask.getRepositoryUrl() + " in " + TaskRepositoriesView.NAME
- + ".", true);
} catch (final CoreException e) {
if (e.getStatus().getException() instanceof UnrecognizedReponseException) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
index 968264d32..4965ca33e 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java
@@ -40,19 +40,19 @@ public class TracAttachmentHandler implements IAttachmentHandler {
this.connector = connector;
}
- public void downloadAttachment(TaskRepository repository, AbstractRepositoryTask task, RepositoryAttachment attachment, File file, Proxy proxySettings) throws CoreException {
+ public void downloadAttachment(TaskRepository repository, String taskId, RepositoryAttachment attachment, File file) throws CoreException {
String filename = attachment.getAttributeValue(RepositoryTaskAttribute.ATTACHMENT_FILENAME);
if (filename == null) {
- throw new CoreException(new Status(IStatus.ERROR, TracCorePlugin.PLUGIN_ID, IStatus.OK, "Attachment download from " + task.getRepositoryUrl() + " failed, missing attachment filename.", null));
+ throw new CoreException(new Status(IStatus.ERROR, TracCorePlugin.PLUGIN_ID, IStatus.OK, "Attachment download from " + repository.getUrl() + " failed, missing attachment filename.", null));
}
try {
ITracClient client = connector.getClientManager().getRepository(repository);
- int id = Integer.parseInt(AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()));
+ int id = Integer.parseInt(taskId);
byte[] data = client.getAttachmentData(id, filename);
writeData(file, data);
} catch (Exception e) {
- throw new CoreException(new Status(IStatus.ERROR, TracCorePlugin.PLUGIN_ID, 0, "Attachment download from " + task.getRepositoryUrl() + " failed, please see details.", e ));
+ throw new CoreException(new Status(IStatus.ERROR, TracCorePlugin.PLUGIN_ID, 0, "Attachment download from " +repository.getUrl() + " failed, please see details.", e ));
}
}
@@ -114,5 +114,10 @@ public class TracAttachmentHandler implements IAttachmentHandler {
public void updateAttachment(TaskRepository repository, RepositoryAttachment attachment) throws CoreException {
// ignore
}
+
+ public byte[] getAttachmentData(TaskRepository repository, String taskId) throws CoreException {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
index bda71efce..3b829b317 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracRepositoryConnector.java
@@ -254,7 +254,7 @@ public class TracRepositoryConnector extends AbstractRepositoryConnector {
}
@Override
- public void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor) throws CoreException {
+ public void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
try {
ITracClient client = getClientManager().getRepository(repository);
client.updateAttributes(monitor, true);
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java
index c2a32a74e..8ac944739 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracAttachmentHandlerTest.java
@@ -30,6 +30,7 @@ import org.eclipse.mylar.internal.trac.core.TracRepositoryConnector;
import org.eclipse.mylar.internal.trac.core.TracTask;
import org.eclipse.mylar.internal.trac.core.ITracClient.Version;
import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.IAttachmentHandler;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.core.TaskRepositoryManager;
@@ -95,7 +96,7 @@ public class TracAttachmentHandlerTest extends TestCase {
assertTrue(task.getTaskData().getAttachments().size() > 0);
File file = File.createTempFile("attachment", null);
file.deleteOnExit();
- attachmentHandler.downloadAttachment(repository, task, task.getTaskData().getAttachments().get(0), file, proxySettings);
+ attachmentHandler.downloadAttachment(repository, AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()), task.getTaskData().getAttachments().get(0), file);
byte[] result = new byte[6];
InputStream in = new FileInputStream(file);
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
index 78b830d04..3251d5115 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/TracRepositoryConnectorTest.java
@@ -258,7 +258,7 @@ public class TracRepositoryConnectorTest extends TestCase {
}
protected void updateAttributes() throws Exception {
- connector.updateAttributes(repository, null, new NullProgressMonitor());
+ connector.updateAttributes(repository, new NullProgressMonitor());
ITracClient server = connector.getClientManager().getRepository(repository);
TracVersion[] versions = server.getVersions();

Back to the top