diff options
author | relves | 2006-11-28 23:12:57 +0000 |
---|---|---|
committer | relves | 2006-11-28 23:12:57 +0000 |
commit | 764175789411dbaaee6f125d60c412b846d9a649 (patch) | |
tree | 3f5b1859f976895018a70766c8b7a165c0d1f1a0 /org.eclipse.mylyn.bugzilla.core | |
parent | 86fd512f03cb464919976a309df1331712162678 (diff) | |
download | org.eclipse.mylyn.tasks-764175789411dbaaee6f125d60c412b846d9a649.tar.gz org.eclipse.mylyn.tasks-764175789411dbaaee6f125d60c412b846d9a649.tar.xz org.eclipse.mylyn.tasks-764175789411dbaaee6f125d60c412b846d9a649.zip |
NEW - bug 165498: Create unified abstract support for task submission to repository
https://bugs.eclipse.org/bugs/show_bug.cgi?id=165498
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
10 files changed, 624 insertions, 907 deletions
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 69cd9d342..24bd25115 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 @@ -21,6 +21,7 @@ import javax.security.auth.login.LoginException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.mylar.context.core.MylarStatusHandler; import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException; import org.eclipse.mylar.tasks.core.AbstractRepositoryTask; import org.eclipse.mylar.tasks.core.IAttachmentHandler; @@ -34,76 +35,48 @@ import org.eclipse.mylar.tasks.core.TaskRepository; */ public class BugzillaAttachmentHandler implements IAttachmentHandler { - // 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; } - public byte[] getAttachmentData(TaskRepository repository, String taskId) throws CoreException { + public byte[] getAttachmentData(TaskRepository repository, RepositoryAttachment attachment) throws CoreException { try { BugzillaClient client = connector.getClientManager().getClient(repository); - byte[] data = client.getAttachmentData(taskId); + byte[] data = client.getAttachmentData(attachment.getId()); 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)); + "Download of attachment " + attachment.getId() + " 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 { + + // 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, RepositoryAttachment attachment, File file) + throws CoreException { + if (repository == null || attachment == null || file == null) { + MylarStatusHandler.log("Unable to download. Null argument.", this); + throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR, + "Unable to download attachment", null)); + } 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)); + throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR, + "Attachment download from " + repository.getUrl() + " failed, missing attachment filename.", null)); } try { @@ -126,8 +99,7 @@ public class BugzillaAttachmentHandler implements IAttachmentHandler { } public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment, - String description, File file, String contentType, boolean isPatch) - throws CoreException { + String description, File file, String contentType, boolean isPatch) throws CoreException { try { String bugId = AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()); BugzillaClient client = connector.getClientManager().getClient(repository); @@ -135,7 +107,7 @@ public class BugzillaAttachmentHandler implements IAttachmentHandler { } 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) { + } catch (UnrecognizedReponseException e) { throw new CoreException(new Status(Status.OK, BugzillaCorePlugin.PLUGIN_ID, Status.INFO, "Response from server", e)); } catch (IOException e) { @@ -261,18 +233,21 @@ public class BugzillaAttachmentHandler implements IAttachmentHandler { // 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 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; 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 index 4df2485a3..054098719 100644 --- 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 @@ -13,6 +13,7 @@ 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.net.HttpURLConnection; import java.net.MalformedURLException; @@ -23,7 +24,10 @@ import java.nio.charset.Charset; import java.security.GeneralSecurityException; import java.text.ParseException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.security.auth.login.LoginException; @@ -54,10 +58,10 @@ 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.RepositoryOperation; 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; /** * @author Mik Kersten @@ -66,6 +70,36 @@ import org.eclipse.mylar.tasks.core.TaskRepository; */ public class BugzillaClient { + private static final String KEY_ID = "id"; + + private static final String VAL_TRUE = "true"; + + private static final String KEY_REMOVECC = "removecc"; + + private static final String KEY_CC = "cc"; + + private static final String POST_BUG_CGI = "/post_bug.cgi"; + + private static final String PROCESS_BUG_CGI = "/process_bug.cgi"; + + public static final int WRAP_LENGTH = 90; + + private static final String VAL_PROCESS_BUG = "process_bug"; + + private static final String KEY_FORM_NAME = "form_name"; + + private static final String VAL_NONE = "none"; + + private static final String KEY_KNOB = "knob"; + + // TODO change to BugzillaReportElement.ADD_COMMENT + private static final String KEY_COMMENT = "comment"; + + private static final String KEY_SHORT_DESC = "short_desc"; + + // ///////////////////// + + // Pages with this string in the html occurr when login is required private static final String LOGIN_REQUIRED = "goaheadandlogin=1"; private static final int MAX_RETRY = 2; @@ -234,10 +268,11 @@ public class BugzillaClient { public void logout() throws LoginException, IOException, BugzillaException { authenticated = true; String loginUrl = repositoryUrl + "/relogin.cgi"; - GetMethod method = getConnect(loginUrl); - method.setFollowRedirects(false); + GetMethod method = null; try { // httpClient.getParams().setAuthenticationPreemptive(true); + method = getConnect(loginUrl); + method.setFollowRedirects(false); int code = httpClient.executeMethod(method); if (code == HttpURLConnection.HTTP_UNAUTHORIZED || code == HttpURLConnection.HTTP_FORBIDDEN) { throw new LoginException(); @@ -264,8 +299,6 @@ public class BugzillaClient { throw new LoginException("Logout procedure failed."); - } catch (IOException e) { - throw new BugzillaException(e); } catch (ParseException e) { throw new BugzillaException(e); } finally { @@ -292,7 +325,7 @@ public class BugzillaClient { method.setRequestBody(formData); method.setDoAuthentication(true); method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); - // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); + httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); method.setFollowRedirects(false); try { @@ -349,8 +382,8 @@ public class BugzillaClient { } } - public RepositoryTaskData getTaskData(TaskRepository repository, int id) throws IOException, MalformedURLException, - LoginException, GeneralSecurityException, BugzillaException { + public RepositoryTaskData getTaskData(int id) throws IOException, MalformedURLException, LoginException, + GeneralSecurityException, BugzillaException { GetMethod method = null; try { method = getConnect(repositoryUrl + IBugzillaConstants.URL_GET_SHOW_BUG_XML + id); @@ -367,7 +400,7 @@ public class BugzillaClient { RepositoryReportFactory reportFactory = new RepositoryReportFactory(method .getResponseBodyAsStream(), characterEncoding); method.getResponseCharSet(); - reportFactory.populateReport(taskData, repository); + reportFactory.populateReport(taskData); return taskData; } } @@ -514,10 +547,10 @@ public class BugzillaClient { } } - public byte[] getAttachmentData(String id) throws LoginException, IOException, BugzillaException { + public byte[] getAttachmentData(String attachmentId) throws LoginException, IOException, BugzillaException { GetMethod method = null; try { - String url = repositoryUrl + IBugzillaConstants.URL_GET_ATTACHMENT_DOWNLOAD + id; + String url = repositoryUrl + IBugzillaConstants.URL_GET_ATTACHMENT_DOWNLOAD + attachmentId; method = getConnect(url); return method.getResponseBody(); @@ -614,18 +647,12 @@ public class BugzillaClient { authenticate(); } PostMethod postMethod = new PostMethod(WebClientUtil.getRequestPath(repositoryUrl.toString() + formUrl)); + postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + characterEncoding); httpClient.getHttpConnectionManager().getParams().setSoTimeout(CONNECT_TIMEOUT); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); postMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryHandler); - // DEBUG - // for (NameValuePair nameValuePair : formData) { - // System.err.println(nameValuePair.getName()+", - // "+nameValuePair.getValue()); - // } - postMethod.setRequestBody(formData); postMethod.setDoAuthentication(true); - postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + characterEncoding); // httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECT_TIMEOUT); int status = httpClient.executeMethod(postMethod); if (status == HttpStatus.SC_OK) { @@ -636,6 +663,277 @@ public class BugzillaClient { } } + public String postTaskData(RepositoryTaskData taskData) throws LoginException, IOException, BugzillaException { + NameValuePair[] formData = null; + String prefix = null; + String prefix2 = null; + String postfix = null; + String postfix2 = null; + + if (taskData == null) { + return null; + } else if (taskData.isNew()) { + formData = getPairsForNew(taskData); + prefix = IBugzillaConstants.FORM_PREFIX_BUG_218; + prefix2 = IBugzillaConstants.FORM_PREFIX_BUG_220; + postfix = IBugzillaConstants.FORM_POSTFIX_216; + postfix2 = IBugzillaConstants.FORM_POSTFIX_218; + } else { + formData = getPairsForExisting(taskData); + } + + InputStream inputStream = null; + String result = null; + PostMethod method = null; + try { + if (taskData.isNew()) { + method = postFormData(POST_BUG_CGI, formData); + } else { + method = postFormData(PROCESS_BUG_CGI, formData); + } + + if (method == null) { + throw new IOException("Could not post form, client returned null method."); + } + + BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); + 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 (!taskData.isNew() + && (title.toLowerCase().matches(".*bug\\s+processed.*") || title.toLowerCase().matches( + ".*defect\\s+processed.*"))) { + existingBugPosted = true; + } else if (taskData.isNew() && 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 ((!taskData.isNew() && existingBugPosted != true) || (taskData.isNew() && result == null)) { + in.reset(); + BugzillaClient.parseHtmlError(in); + } + + return result; + } catch (ParseException e) { + throw new IOException("Could not parse response from server."); + } finally { + if (inputStream != null) { + inputStream.close(); + } + if (method != null) { + method.releaseConnection(); + } + } + + } + + private NameValuePair[] getPairsForNew(RepositoryTaskData taskData) { + Map<String, NameValuePair> fields = new HashMap<String, NameValuePair>(); + + // go through all of the attributes and add them to + // the bug post + Iterator<RepositoryTaskAttribute> itr = taskData.getAttributes().iterator(); + while (itr.hasNext()) { + RepositoryTaskAttribute a = itr.next(); + if (a != null && a.getID() != null && a.getID().compareTo("") != 0) { + String value = null; + value = a.getValue(); + if (value == null) + continue; + fields.put(a.getID(), new NameValuePair(a.getID(), value)); + } + } + + // form.add(KEY_BUG_FILE_LOC, ""); + + // specify the product + fields.put(BugzillaReportElement.PRODUCT.getKeyString(), new NameValuePair(BugzillaReportElement.PRODUCT + .getKeyString(), taskData.getProduct())); + + // add the summary to the bug post + fields.put(BugzillaReportElement.SHORT_DESC.getKeyString(), new NameValuePair(BugzillaReportElement.SHORT_DESC + .getKeyString(), taskData.getSummary())); + + String formattedDescription = formatTextToLineWrap(taskData.getDescription(), true); + taskData.setDescription(formattedDescription); + + if (taskData.getDescription().length() != 0) { + // add the new comment to the bug post if there + // is some text in + // it + fields.put(KEY_COMMENT, new NameValuePair(KEY_COMMENT, taskData.getDescription())); + } + + return fields.values().toArray(new NameValuePair[fields.size()]); + + } + + private NameValuePair[] getPairsForExisting(RepositoryTaskData model) { + + Map<String, NameValuePair> fields = new HashMap<String, NameValuePair>(); + fields.put(KEY_FORM_NAME, new NameValuePair(KEY_FORM_NAME, VAL_PROCESS_BUG)); + // go through all of the attributes and add them to the bug post + for (Iterator<RepositoryTaskAttribute> it = model.getAttributes().iterator(); it.hasNext();) { + RepositoryTaskAttribute a = it.next(); + if (a == null) { + continue; + } else if (a.getID().equals(BugzillaReportElement.CC.getKeyString()) + || a.getID().equals(RepositoryTaskAttribute.REMOVE_CC) + || a.getID().equals(BugzillaReportElement.REPORTER.getKeyString()) + || a.getID().equals(BugzillaReportElement.ASSIGNED_TO.getKeyString()) + || a.getID().equals(BugzillaReportElement.CREATION_TS.getKeyString())) { + continue; + } else if (a.getID() != null && a.getID().compareTo("") != 0) { + String value = a.getValue(); + if (value != null && value.equals(BugzillaReportElement.DELTA_TS.getKeyString())) { + value = stripTimeZone(value); + } + fields.put(a.getID(), new NameValuePair(a.getID(), value != null ? value : "")); + } + } + + // when posting the bug id is encoded in a hidden field named 'id' + fields.put(KEY_ID, new NameValuePair(KEY_ID, model.getAttributeValue(BugzillaReportElement.BUG_ID + .getKeyString()))); + + // add the operation to the bug post + RepositoryOperation o = model.getSelectedOperation(); + if (o == null) + fields.put(KEY_KNOB, new NameValuePair(KEY_KNOB, VAL_NONE)); + else { + fields.put(KEY_KNOB, new NameValuePair(KEY_KNOB, o.getKnobName())); + if (o.hasOptions()) { + String sel = o.getOptionValue(o.getOptionSelection()); + fields.put(o.getOptionName(), new NameValuePair(o.getOperationName(), sel)); + } else if (o.isInput()) { + String sel = o.getInputValue(); + fields.put(o.getInputName(), new NameValuePair(o.getInputName(), sel)); + } + } + + if (model.getAttribute(BugzillaReportElement.SHORT_DESC.getKeyString()) != null) { + fields.put(KEY_SHORT_DESC, new NameValuePair(KEY_SHORT_DESC, model.getAttribute( + BugzillaReportElement.SHORT_DESC.getKeyString()).getValue())); + } + + if (model.getNewComment().length() != 0) { + fields.put(KEY_COMMENT, new NameValuePair(KEY_COMMENT, model.getNewComment())); + } + + List<String> removeCC = model.getAttributeValues(RepositoryTaskAttribute.REMOVE_CC); + if (removeCC != null && removeCC.size() > 0) { + String[] s = new String[removeCC.size()]; + fields.put(KEY_CC, new NameValuePair(KEY_CC, toCommaSeparatedList(removeCC.toArray(s)))); + fields.put(KEY_REMOVECC, new NameValuePair(KEY_REMOVECC, VAL_TRUE)); + } + + return fields.values().toArray(new NameValuePair[fields.size()]); + + } + + /** + * Break text up into lines of about 80 characters so that it is displayed + * properly in bugzilla + */ + private static String formatTextToLineWrap(String origText, boolean hardWrap) { + // BugzillaServerVersion bugzillaServerVersion = + // IBugzillaConstants.BugzillaServerVersion.fromString(repository + // .getVersion()); + // if (bugzillaServerVersion != null && + // bugzillaServerVersion.compareTo(BugzillaServerVersion.SERVER_220) >= + // 0) { + // return origText; + if (!hardWrap) { + return origText; + } else { + String[] textArray = new String[(origText.length() / WRAP_LENGTH + 1) * 2]; + for (int i = 0; i < textArray.length; i++) + textArray[i] = null; + int j = 0; + while (true) { + int spaceIndex = origText.indexOf(" ", WRAP_LENGTH - 5); + if (spaceIndex == origText.length() || spaceIndex == -1) { + textArray[j] = origText; + break; + } + textArray[j] = origText.substring(0, spaceIndex); + origText = origText.substring(spaceIndex + 1, origText.length()); + j++; + } + + String newText = ""; + + for (int i = 0; i < textArray.length; i++) { + if (textArray[i] == null) + break; + newText += textArray[i] + "\n"; + } + return newText; + } + } + + public static String stripTimeZone(String longTime) { + String result = longTime; + if (longTime != null) { + String[] values = longTime.split(" "); + if (values != null && values.length > 2) { + result = values[0] + " " + values[1]; + } + } + return result; + } + + private static String toCommaSeparatedList(String[] strings) { + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < strings.length; i++) { + buffer.append(strings[i]); + if (i != strings.length - 1) { + buffer.append(","); + } + } + return buffer.toString(); + } + /** * Utility method for determining what potential error has occurred from a * bugzilla html reponse page 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 deleted file mode 100644 index 5141a78f0..000000000 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaReportSubmitForm.java +++ /dev/null @@ -1,740 +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.InputStream; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.io.UnsupportedEncodingException; -import java.security.GeneralSecurityException; -import java.text.ParseException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.methods.PostMethod; -import org.eclipse.mylar.internal.tasks.core.HtmlStreamTokenizer; -import org.eclipse.mylar.internal.tasks.core.HtmlTag; -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 Shawn Minto - * @author Mik Kersten (hardening of prototype) - * @author Rob Elves - * - * Class to handle the positing of a bug - */ -public class BugzillaReportSubmitForm { - - private static final String KEY_ID = "id"; - - private static final String VAL_TRUE = "true"; - - private static final String KEY_REMOVECC = "removecc"; - - 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 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"; - - public static final int WRAP_LENGTH = 90; - - private static final String VAL_PROCESS_BUG = "process_bug"; - - private static final String KEY_FORM_NAME = "form_name"; - - private static final String VAL_NONE = "none"; - - private static final String KEY_KNOB = "knob"; - - // TODO change to BugzillaReportElement.ADD_COMMENT - private static final String KEY_COMMENT = "comment"; - - private static final String KEY_SHORT_DESC = "short_desc"; - - public static final String FORM_POSTFIX_218 = " Submitted"; - - public static final String FORM_POSTFIX_216 = " posted"; - - public static final String FORM_PREFIX_BUG_218 = "Bug "; - - public static final String FORM_PREFIX_BUG_220 = "Issue "; - - /** The fields that are to be changed/maintained */ - // private List<NameValuePair> fields = new ArrayList<NameValuePair>(); - private Map<String, NameValuePair> fields = new HashMap<String, NameValuePair>(); - - /** The prefix for how to find the bug number from the return */ - private String prefix; - - private String prefix2; - - /** The postfix for how to find the bug number from the return */ - private String postfix; - - /** An alternate postfix for how to find the bug number from the return */ - private String postfix2; - - private String error = null; - - private RepositoryTaskData taskData = null; - - public boolean isNewBugPost = false; - - public BugzillaReportSubmitForm() { - // charset = charEncoding; - } - - public static BugzillaReportSubmitForm makeNewBugPost(String repositoryUrl, String userName, String password, - String characterEncoding, RepositoryTaskData model, boolean wrapDescription) - throws UnsupportedEncodingException { - - BugzillaReportSubmitForm form = new BugzillaReportSubmitForm(); - - // 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); - - // go through all of the attributes and add them to - // the bug post - Iterator<RepositoryTaskAttribute> itr = model.getAttributes().iterator(); - while (itr.hasNext()) { - RepositoryTaskAttribute a = itr.next(); - if (a != null && a.getID() != null && a.getID().compareTo("") != 0) { - String value = null; - value = a.getValue(); - if (value == null) - continue; - form.add(a.getID(), value); - } - } - - // form.add(KEY_BUG_FILE_LOC, ""); - - // specify the product - form.add(BugzillaReportElement.PRODUCT.getKeyString(), model.getProduct()); - - // add the summary to the bug post - form.add(BugzillaReportElement.SHORT_DESC.getKeyString(), model.getSummary()); - - String formattedDescription = formatTextToLineWrap(model.getDescription(), wrapDescription); - model.setDescription(formattedDescription); - - if (model.getDescription().length() != 0) { - // add the new comment to the bug post if there - // is some text in - // it - form.add(KEY_COMMENT, model.getDescription()); - } - - form.setNewBugPost(true); - - return form; - } - - /** - * TODO: refactor common stuff with new bug post - * - * @param characterEncoding - * TODO - * - * @throws UnsupportedEncodingException - */ - public static BugzillaReportSubmitForm makeExistingBugPost(RepositoryTaskData model, String repositoryUrl, - String userName, String password, String characterEncoding) throws UnsupportedEncodingException { - - BugzillaReportSubmitForm form = new BugzillaReportSubmitForm(); - - // 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); - - // go through all of the attributes and add them to the bug post - for (Iterator<RepositoryTaskAttribute> it = model.getAttributes().iterator(); it.hasNext();) { - RepositoryTaskAttribute a = it.next(); - if (a.getID().equals(BugzillaReportElement.CC.getKeyString()) - || a.getID().equals(RepositoryTaskAttribute.REMOVE_CC) - || a.getID().equals(BugzillaReportElement.REPORTER.getKeyString()) - || a.getID().equals(BugzillaReportElement.ASSIGNED_TO.getKeyString()) - || a.getID().equals(BugzillaReportElement.CREATION_TS.getKeyString())) { - continue; - } - if (a != null && a.getID() != null && a.getID().compareTo("") != 0 && !a.isHidden()) { - String value = a.getValue(); - // System.err.println(a.getID()+" "+a.getValue()); - // add the attribute to the bug post - form.add(a.getID(), value != null ? value : ""); - } 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(); - - // Strip off timezone information - // 149513: Constant bugzilla mid-air collisions - if (a.getID().equals(BugzillaReportElement.DELTA_TS.getKeyString()) && value != null) { - value = stripTimeZone(value); - } - form.add(a.getID(), value); - } - } - - // when posting the bug id is encoded in a hidden field named 'id' - form.add(KEY_ID, model.getAttributeValue(BugzillaReportElement.BUG_ID.getKeyString())); - - // add the operation to the bug post - RepositoryOperation o = model.getSelectedOperation(); - if (o == null) - form.add(KEY_KNOB, VAL_NONE); - else { - form.add(KEY_KNOB, o.getKnobName()); - if (o.hasOptions()) { - String sel = o.getOptionValue(o.getOptionSelection()); - form.add(o.getOptionName(), sel); - } else if (o.isInput()) { - String sel = o.getInputValue(); - form.add(o.getInputName(), sel); - } - } - 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()); - } - - if (model.getNewComment().length() != 0) { - form.add(KEY_COMMENT, model.getNewComment()); - } - - List<String> removeCC = model.getAttributeValues(RepositoryTaskAttribute.REMOVE_CC); - if (removeCC != null && removeCC.size() > 0) { - String[] s = new String[removeCC.size()]; - form.add(KEY_CC, toCommaSeparatedList(removeCC.toArray(s))); - form.add(KEY_REMOVECC, VAL_TRUE); - } - - return form; - } - - public static String stripTimeZone(String longTime) { - String result = longTime; - if (longTime != null) { - String[] values = longTime.split(" "); - if (values != null && values.length > 2) { - result = values[0] + " " + values[1]; - } - } - return result; - } - - private static String toCommaSeparatedList(String[] strings) { - StringBuffer buffer = new StringBuffer(); - for (int i = 0; i < strings.length; i++) { - buffer.append(strings[i]); - if (i != strings.length - 1) { - buffer.append(","); - } - } - return buffer.toString(); - } - - /** - * Add a value to be posted to the bug - * - * @param key - * The key for the value to be added - * @param value - * The value to be added - * @throws UnsupportedEncodingException - */ - private void add(String key, String value) throws UnsupportedEncodingException { - // try { - // fields.add(new NameValuePair(key, URLEncoder.encode(value == null ? - // "" : value, charset))); - fields.put(key, new NameValuePair(key, value)); - // BugzillaPlugin.ENCODING_UTF_8 - // } catch (UnsupportedEncodingException e) { - // // ignore - // } - } - - /** - * Post the bug to the bugzilla server TODO: fix this mess - */ - public String submitReportToRepository(BugzillaClient client) throws IOException, BugzillaException, - PossibleBugzillaFailureException, GeneralSecurityException { - NameValuePair[] formData = fields.values().toArray(new NameValuePair[fields.size()]); - InputStream inputStream = null; - String result = null; - PostMethod method = null; - try { - if (isNewBugPost()) { - method = client.postFormData(POST_BUG_CGI, formData); - } else { - method = client.postFormData(PROCESS_BUG_CGI, formData); - } - - if (method == null) - throw new BugzillaException("Could not post form"); - - BufferedReader in = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream())); - 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 (ParseException e) { - throw new IOException("Could not parse response from server."); - } finally { - if (inputStream != null) { - inputStream.close(); - } - if (method != null) { - method.releaseConnection(); - } - } - // return the bug number - return result; - } - - private void setPrefix(String prefix) { - this.prefix = prefix; - } - - private void setPostfix(String postfix) { - this.postfix = postfix; - } - - private void setPostfix2(String postfix) { - this.postfix2 = postfix; - } - - public String getError() { - return parseError(); - } - - /** - * remove all of the hyperlinks and erroneous info - * - * @return - */ - private String parseError() { - String newError = ""; - try { - HtmlStreamTokenizer tokenizer = new HtmlStreamTokenizer(new StringReader(error), null); - for (Token token = tokenizer.nextToken(); token.getType() != Token.EOF; token = tokenizer.nextToken()) { - if (token.getType() == Token.TAG && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.A) { - - } else if (token.getType() == Token.TAG - && ((HtmlTag) (token.getValue())).getTagType() == HtmlTag.Type.FORM) { - for (Token token2 = tokenizer.nextToken(); token2.getType() != Token.EOF; token2 = tokenizer - .nextToken()) { - if (token2.getType() == Token.TAG) { - HtmlTag tag = (HtmlTag) token2.getValue(); - if (tag.getTagType() == HtmlTag.Type.FORM && tag.isEndTag()) - break; - - } - } - } else { - newError += token.getWhitespace().toString() + token.getValue(); - } - } - } catch (Exception e) { - newError = error; - } - return newError; - } - - private void setPrefix2(String prefix2) { - this.prefix2 = prefix2; - } - - /** - * Break text up into lines of about 80 characters so that it is displayed - * properly in bugzilla - */ - private static String formatTextToLineWrap(String origText, boolean hardWrap) { - // BugzillaServerVersion bugzillaServerVersion = - // IBugzillaConstants.BugzillaServerVersion.fromString(repository - // .getVersion()); - // if (bugzillaServerVersion != null && - // bugzillaServerVersion.compareTo(BugzillaServerVersion.SERVER_220) >= - // 0) { - // return origText; - if (!hardWrap) { - return origText; - } else { - String[] textArray = new String[(origText.length() / WRAP_LENGTH + 1) * 2]; - for (int i = 0; i < textArray.length; i++) - textArray[i] = null; - int j = 0; - while (true) { - int spaceIndex = origText.indexOf(" ", WRAP_LENGTH - 5); - if (spaceIndex == origText.length() || spaceIndex == -1) { - textArray[j] = origText; - break; - } - textArray[j] = origText.substring(0, spaceIndex); - origText = origText.substring(spaceIndex + 1, origText.length()); - j++; - } - - String newText = ""; - - for (int i = 0; i < textArray.length; i++) { - if (textArray[i] == null) - break; - newText += textArray[i] + "\n"; - } - return newText; - } - } - - public boolean isNewBugPost() { - return isNewBugPost; - } - - public void setNewBugPost(boolean isNewBugPost) { - this.isNewBugPost = isNewBugPost; - } - - public RepositoryTaskData getTaskData() { - return taskData; - } - - public void setTaskData(RepositoryTaskData taskData) { - this.taskData = taskData; - } -} -// 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 8214d249e..5a31972f6 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 @@ -12,13 +12,15 @@ package org.eclipse.mylar.internal.bugzilla.core; import java.io.IOException; -import java.net.Proxy; import java.security.GeneralSecurityException; import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.security.auth.login.LoginException; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -29,8 +31,8 @@ import org.eclipse.mylar.tasks.core.AbstractRepositoryConnector; import org.eclipse.mylar.tasks.core.AbstractRepositoryQuery; 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.ITaskDataHandler; import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute; import org.eclipse.mylar.tasks.core.RepositoryTaskData; @@ -47,7 +49,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { private BugzillaAttachmentHandler attachmentHandler; - private BugzillaOfflineTaskHandler offlineHandler; + private BugzillaTaskDataHandler taskDataHandler; private boolean forceSynchExecForTesting = false; @@ -56,7 +58,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { @Override public void init(TaskList taskList) { super.init(taskList); - this.offlineHandler = new BugzillaOfflineTaskHandler(this, taskList); + this.taskDataHandler = new BugzillaTaskDataHandler(this, taskList); BugzillaCorePlugin.getDefault().setConnector(this); attachmentHandler = new BugzillaAttachmentHandler(this); } @@ -72,8 +74,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { } @Override - public IOfflineTaskHandler getOfflineTaskHandler() { - return offlineHandler; + public ITaskDataHandler getTaskDataHandler() { + return taskDataHandler; } @Override @@ -82,8 +84,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { } @Override - public ITask createTaskFromExistingKey(TaskRepository repository, String id, Proxy proxySettings) - throws CoreException { + public AbstractRepositoryTask createTaskFromExistingKey(TaskRepository repository, String id) throws CoreException { int bugId = -1; try { if (id != null) { @@ -108,12 +109,13 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { if (task == null) { RepositoryTaskData taskData = null; // try { - taskData = offlineHandler.downloadTaskData(repository, id); + taskData = taskDataHandler.getTaskData(repository, id); // 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); + // ((BugzillaTask) task).setLastSyncDateStamp(lastSyncDateStamp) taskList.addTask(task); } // } catch (final UnrecognizedReponseException e) { @@ -134,7 +136,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { // see details.", e)); // } } - return task; + return (AbstractRepositoryTask) task; } @Override @@ -159,8 +161,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { } @Override - public IStatus performQuery(final AbstractRepositoryQuery query, TaskRepository repository, IProgressMonitor monitor, - QueryHitCollector resultCollector) { + public IStatus performQuery(final AbstractRepositoryQuery query, TaskRepository repository, + IProgressMonitor monitor, QueryHitCollector resultCollector) { IStatus queryStatus = Status.OK_STATUS; try { @@ -168,7 +170,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { client.getSearchHits(query, resultCollector, taskList); // XXX: HACK in case of ip change bugzilla can return 0 hits // due to invalid authorization token, forcing relogin fixes - if(resultCollector.getHits().size() == 0) { + if (resultCollector.getHits().size() == 0) { client.logout(); client.getSearchHits(query, resultCollector, taskList); } @@ -177,13 +179,13 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { "Unrecognized response from server", e); } catch (IOException e) { queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, Status.ERROR, - "Check repository configuration: "+e.getMessage(), e); + "Check repository configuration: " + e.getMessage(), e); } catch (BugzillaException e) { - queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, - "Bugzilla error: "+e.getMessage(), e); + queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, "Bugzilla error: " + + e.getMessage(), e); } catch (GeneralSecurityException e) { queryStatus = new Status(IStatus.ERROR, BugzillaCorePlugin.PLUGIN_ID, IStatus.OK, - "Check repository configuration: "+e.getMessage(), e); + "Check repository configuration: " + e.getMessage(), e); } return queryStatus; @@ -278,9 +280,9 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { @Override public void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException { - - BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, true); - + if (repository != null) { + BugzillaCorePlugin.getDefault().getRepositoryConfiguration(repository, true); + } } public void updateAttributeOptions(TaskRepository taskRepository, RepositoryTaskData existingReport) @@ -304,7 +306,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { for (String option : optionValues) { attribute.addOption(option, option); } - + // TODO: bug#162428, bug#150680 - something along the lines of... // but must think about the case of multiple values selected etc. // if(attribute.hasOptions()) { @@ -312,7 +314,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { // { // // updateAttributes() // } - //} + // } } } @@ -462,8 +464,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { // newReport.attributes = attributes; } - - + // // TODO: change to getAttributeOptions() and use whereever attribute // options are required. // public void updateAttributeOptions(TaskRepository taskRepository, 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/BugzillaTaskDataHandler.java index 338e09a93..0d4f3778f 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/BugzillaTaskDataHandler.java @@ -31,8 +31,8 @@ import org.eclipse.mylar.internal.tasks.core.UnrecognizedReponseException; import org.eclipse.mylar.tasks.core.AbstractAttributeFactory; import org.eclipse.mylar.tasks.core.AbstractQueryHit; 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.ITaskDataHandler; import org.eclipse.mylar.tasks.core.QueryHitCollector; import org.eclipse.mylar.tasks.core.RepositoryOperation; import org.eclipse.mylar.tasks.core.RepositoryTaskData; @@ -43,7 +43,7 @@ import org.eclipse.mylar.tasks.core.TaskRepository; * @author Mik Kersten * @author Rob Elves */ -public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { +public class BugzillaTaskDataHandler implements ITaskDataHandler { private static final String OPERATION_INPUT_ASSIGNED_TO = "assigned_to"; @@ -79,17 +79,17 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { private static final String DATE_FORMAT_2 = "yyyy-MM-dd HH:mm:ss"; - private static SimpleDateFormat delta_ts_format = new SimpleDateFormat(DATE_FORMAT_2); + private static final SimpleDateFormat delta_ts_format = new SimpleDateFormat(DATE_FORMAT_2); - private static SimpleDateFormat creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); + private static final SimpleDateFormat creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); /** * public for testing Bugzilla 2.18 uses DATE_FORMAT_1 but later versions * use DATE_FORMAT_2 Using lowest common denominator DATE_FORMAT_1 */ - public static SimpleDateFormat comment_creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); + public static final SimpleDateFormat comment_creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); - private static SimpleDateFormat attachment_creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); + private static final SimpleDateFormat attachment_creation_ts_format = new SimpleDateFormat(DATE_FORMAT_1); private AbstractAttributeFactory attributeFactory = new BugzillaAttributeFactory(); @@ -97,20 +97,27 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { private BugzillaRepositoryConnector connector; - public BugzillaOfflineTaskHandler(BugzillaRepositoryConnector connector, TaskList taskList) { + public BugzillaTaskDataHandler(BugzillaRepositoryConnector connector, TaskList taskList) { this.taskList = taskList; this.connector = connector; } - public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId) throws CoreException { + public RepositoryTaskData getTaskData(TaskRepository repository, String taskId) throws CoreException { try { BugzillaClient client = connector.getClientManager().getClient(repository); int bugId = Integer.parseInt(taskId); - RepositoryTaskData taskData = client.getTaskData(repository, bugId); + RepositoryTaskData taskData = client.getTaskData(bugId); if (taskData != null) { - connector.updateAttributeOptions(repository, taskData); - addValidOperations(taskData, repository.getUserName()); + try { + configureTaskData(repository, taskData); + } catch (CoreException ce) { + // retry since data retrieved may be corrupt + taskData = client.getTaskData(bugId); + if (taskData != null) { + configureTaskData(repository, taskData); + } + } return taskData; } return null; @@ -127,6 +134,21 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { } } + private void configureTaskData(TaskRepository repository, RepositoryTaskData taskData) throws CoreException { + connector.updateAttributeOptions(repository, taskData); + addValidOperations(taskData, repository.getUserName()); + } + + public String postTaskData(TaskRepository repository, RepositoryTaskData taskData) throws CoreException { + try { + BugzillaClient client = connector.getClientManager().getClient(repository); + return client.postTaskData(taskData); + } catch (Throwable e) { + throw new CoreException(new Status(IStatus.OK, BugzillaCorePlugin.PLUGIN_ID, IStatus.ERROR, "Posting to " + + repository.getUrl() + " failed: " + e.getMessage(), e)); + } + } + public AbstractAttributeFactory getAttributeFactory() { return attributeFactory; } @@ -175,7 +197,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { urlQueryBase = repository.getUrl() + CHANGED_BUGS_CGI_QUERY + URLEncoder.encode(dateString, repository.getCharacterEncoding()) + CHANGED_BUGS_CGI_ENDDATE; - urlQueryString = new String(urlQueryBase + BUG_ID); + urlQueryString = urlQueryBase + BUG_ID; int queryCounter = -1; Iterator<AbstractRepositoryTask> itr = tasks.iterator(); @@ -187,7 +209,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { if ((urlQueryString.length() + newurlQueryString.length() + IBugzillaConstants.CONTENT_TYPE_RDF.length()) > MAX_URL_LENGTH) { queryForChanged(repository, changedTasks, urlQueryString); queryCounter = 0; - urlQueryString = new String(urlQueryBase + BUG_ID); + urlQueryString = urlQueryBase + BUG_ID; urlQueryString += newurlQueryString; } else if (!itr.hasNext()) { urlQueryString += newurlQueryString; @@ -201,7 +223,6 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { private void queryForChanged(TaskRepository repository, Set<AbstractRepositoryTask> changedTasks, String urlQueryString) throws UnsupportedEncodingException, CoreException { - QueryHitCollector collector = new QueryHitCollector(taskList); BugzillaRepositoryQuery query = new BugzillaRepositoryQuery(repository.getUrl(), urlQueryString, "", "-1", taskList); @@ -243,7 +264,7 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { if (repositoryTask.getTaskData() != null && repositoryTask.getTaskData().getLastModified().equals(repository.getSyncTimeStamp())) { String taskId = AbstractRepositoryTask.getTaskId(repositoryTask.getHandleIdentifier()); - RepositoryTaskData taskData = downloadTaskData(repository, taskId); + RepositoryTaskData taskData = getTaskData(repository, taskId); if (taskData != null && taskData.getLastModified().equals(repository.getSyncTimeStamp())) { continue; } @@ -253,13 +274,13 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { } } - public static void addValidOperations(RepositoryTaskData bugReport, String userName) { + public static void addValidOperations(RepositoryTaskData bugReport, String userName) throws CoreException { BUGZILLA_REPORT_STATUS status; try { status = BUGZILLA_REPORT_STATUS.valueOf(bugReport.getStatus()); - } catch (IllegalArgumentException e) { + } catch (RuntimeException e) { MylarStatusHandler.log(e, "Unable to get status object for: " + bugReport.getStatus()); - return; + throw new CoreException(Status.CANCEL_STATUS); } switch (status) { case UNCONFIRMED: @@ -346,6 +367,165 @@ public class BugzillaOfflineTaskHandler implements IOfflineTaskHandler { bugReport.addOperation(newOperation); } } + // + // public void submitBugReport(BugzillaReportSubmitForm form, + // IJobChangeListener listener, boolean synchExec, + // boolean addToTaskListRoot) { + // submitBugReport(form, listener, synchExec, addToTaskListRoot ? + // TasksUiPlugin.getTaskListManager().getTaskList() + // .getRootCategory() : null); + // } + // + // public void submitBugReport(final BugzillaReportSubmitForm form, + // IJobChangeListener listener, boolean synchExec, + // final AbstractTaskContainer container) { + // if (synchExec) { + // try { + // 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, container); + // } else { + // handleExistingBugPost(form.getTaskData(), submittedBugId); + // } + // } + // } catch (Exception e) { + // throw new RuntimeException(e); + // } + // } else { + // Job submitJob = new Job(LABEL_JOB_SUBMIT) { + // + // @Override + // protected IStatus run(IProgressMonitor monitor) { + // try { + // String submittedBugId = ""; + // TaskRepository repository = + // TasksUiPlugin.getRepositoryManager().getRepository( + // form.getTaskData().getRepositoryKind(), + // form.getTaskData().getRepositoryUrl()); + // BugzillaClient client = ((BugzillaRepositoryConnector) + // connector).getClientManager().getClient( + // repository); + // + // submittedBugId = form.submitReportToRepository(client); + // + // if (form.isNewBugPost()) { + // handleNewBugPost(form.getTaskData(), submittedBugId, container); + // return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.OK, + // submittedBugId, null); + // } else { + // // NOTE: sync now handled by editor + // //handleExistingBugPost(form.getTaskData(), submittedBugId); + // return Status.OK_STATUS; + // } + // } catch (GeneralSecurityException e) { + // return new Status( + // Status.OK, + // BugzillaUiPlugin.PLUGIN_ID, + // Status.ERROR, + // "Bugzilla could not post your bug, probably because your credentials are + // incorrect. Ensure proper repository configuration in " + // + TaskRepositoriesView.NAME + ".", e); + // } catch (UnrecognizedReponseException e) { + // return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.INFO, + // "Unrecognized response from server", e); + // } catch (IOException e) { + // return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.ERROR, + // "IO Error: \n\n" + // + e.getMessage(), e); + // } catch (BugzillaException e) { + // // MylarStatusHandler.fail(e, "Failed to submit", + // // false); + // String message = e.getMessage(); + // return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.ERROR, + // "Bugzilla could not post your bug. \n\n" + message, e); + // } catch (PossibleBugzillaFailureException e) { + // return new Status(Status.OK, BugzillaUiPlugin.PLUGIN_ID, Status.INFO, + // "Possible bugzilla failure", e); + // } + // } + // }; + // + // submitJob.addJobChangeListener(listener); + // submitJob.schedule(); + // } + // } + // + // private void handleNewBugPost(RepositoryTaskData taskData, String + // resultId, AbstractTaskContainer category) + // throws BugzillaException { + // int bugId = -1; + // try { + // bugId = Integer.parseInt(resultId); + // } catch (NumberFormatException e) { + // throw new BugzillaException("Invalid bug id returned by repository."); + // } + // + // TaskRepository repository = + // TasksUiPlugin.getRepositoryManager().getRepository(taskData.getRepositoryKind(), + // taskData.getRepositoryUrl()); + // + // BugzillaTask newTask = new + // BugzillaTask(AbstractRepositoryTask.getHandle(repository.getUrl(), + // bugId), + // "<bugzilla info>", true); + // + // if (category != null) { + // TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask, + // category); + // } else { + // TasksUiPlugin.getTaskListManager().getTaskList().addTask(newTask); + // } + // TasksUiPlugin.getSynchronizationScheduler().synchNow(0, + // Collections.singletonList(repository)); + // + // } + // + // // Used when run in forced sync mode for testing + // private void handleExistingBugPost(RepositoryTaskData repositoryTaskData, + // String resultId) { + // try { + // String handle = + // AbstractRepositoryTask.getHandle(repositoryTaskData.getRepositoryUrl(), + // repositoryTaskData + // .getId()); + // final 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 + // // ui override check with user + // // Need to change how this is achieved. + // repositoryTask.setTaskData(null); + // TasksUiPlugin.getSynchronizationManager().synchronize(connector, + // repositoryTask, true, null); + // } + // } + // + // } catch (Exception e) { + // throw new RuntimeException(e); + // } + // } // // TODO: getAttributeOptions() // public void updateAttributeOptions(TaskRepository taskRepository, 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 9d92597d1..f3ba14cee 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 @@ -228,4 +228,12 @@ public interface IBugzillaConstants { public static final String ERROR_MSG_INVALID_BUG_ID = "Invalid Bug ID. The requested bug id does not exist."; + public static final String FORM_PREFIX_BUG_218 = "Bug "; + + public static final String FORM_PREFIX_BUG_220 = "Issue "; + + public static final String FORM_POSTFIX_216 = " posted"; + + public static final String FORM_POSTFIX_218 = " Submitted"; + } diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/NewBugzillaReport.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/NewBugzillaReport.java index cae1c5411..f193d3297 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/NewBugzillaReport.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/NewBugzillaReport.java @@ -39,9 +39,6 @@ public class NewBugzillaReport extends RepositoryTaskData implements Serializabl /** The summary for the bug */ protected String summary = ""; - /** The description for the bug */ - protected String description = ""; - /** * Flag to indicate status of connection to Bugzilla server to identify * whether ProductConfiguration should be used instead @@ -160,7 +157,7 @@ public class NewBugzillaReport extends RepositoryTaskData implements Serializabl } @Override - public boolean isLocallyCreated() { + public boolean isNew() { return true; } 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 a28419722..a0a39efac 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 @@ -18,7 +18,6 @@ import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import org.eclipse.mylar.tasks.core.RepositoryTaskData; -import org.eclipse.mylar.tasks.core.TaskRepository; /** * Reads bug reports from repository. @@ -33,10 +32,10 @@ public class RepositoryReportFactory extends AbstractReportFactory { private static BugzillaAttributeFactory bugzillaAttributeFactory = new BugzillaAttributeFactory(); - public void populateReport(RepositoryTaskData bugReport, TaskRepository repository) throws GeneralSecurityException, + public void populateReport(RepositoryTaskData bugReport) throws GeneralSecurityException, KeyManagementException, NoSuchAlgorithmException, IOException, BugzillaException { - SaxBugReportContentHandler contentHandler = new SaxBugReportContentHandler(bugzillaAttributeFactory, bugReport, repository); + SaxBugReportContentHandler contentHandler = new SaxBugReportContentHandler(bugzillaAttributeFactory, bugReport); collectResults(contentHandler, false); if (contentHandler.errorOccurred()) { 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 326e69ed4..ee0063f56 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 @@ -20,7 +20,6 @@ import org.eclipse.mylar.tasks.core.RepositoryAttachment; 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.TaskRepository; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; @@ -44,18 +43,15 @@ public class SaxBugReportContentHandler extends DefaultHandler { private RepositoryAttachment attachment; - private RepositoryTaskData report; + private RepositoryTaskData repositoryTaskData; private String errorMessage = null; private AbstractAttributeFactory attributeFactory; - - private TaskRepository repository; - public SaxBugReportContentHandler(AbstractAttributeFactory factory, RepositoryTaskData rpt, TaskRepository repository) { + public SaxBugReportContentHandler(AbstractAttributeFactory factory, RepositoryTaskData taskData) { this.attributeFactory = factory; - this.report = rpt; - this.repository = repository; + this.repositoryTaskData = taskData; } public boolean errorOccurred() { @@ -67,7 +63,7 @@ public class SaxBugReportContentHandler extends DefaultHandler { } public RepositoryTaskData getReport() { - return report; + return repositoryTaskData; } @Override @@ -104,7 +100,7 @@ public class SaxBugReportContentHandler extends DefaultHandler { taskComment = new TaskComment(attributeFactory, commentNum++); break; case ATTACHMENT: - attachment = new RepositoryAttachment(repository, attributeFactory); + attachment = new RepositoryAttachment(attributeFactory); if (attributes != null) { if ("1".equals(attributes.getValue(BugzillaReportElement.IS_OBSOLETE.getKeyString()))) { attachment.addAttribute(BugzillaReportElement.IS_OBSOLETE.getKeyString(), attributeFactory @@ -138,17 +134,17 @@ public class SaxBugReportContentHandler extends DefaultHandler { switch (tag) { case BUG_ID: { try { - if (!report.getId().equals(parsedText)) { + if (!repositoryTaskData.getId().equals(parsedText)) { errorMessage = "Requested report number does not match returned report number."; } } catch (Exception e) { errorMessage = "Bug id from server did not match requested id."; } - RepositoryTaskAttribute attr = report.getAttribute(tag.getKeyString()); + RepositoryTaskAttribute attr = repositoryTaskData.getAttribute(tag.getKeyString()); if (attr == null) { attr = attributeFactory.createAttribute(tag.getKeyString()); - report.addAttribute(tag.getKeyString(), attr); + repositoryTaskData.addAttribute(tag.getKeyString(), attr); } attr.setValue(parsedText); break; @@ -176,10 +172,10 @@ public class SaxBugReportContentHandler extends DefaultHandler { case LONG_DESC: if (taskComment != null) { if(taskComment.getNumber() == 0) { - report.setAttributeValue(RepositoryTaskAttribute.DESCRIPTION, taskComment.getText()); + repositoryTaskData.setAttributeValue(RepositoryTaskAttribute.DESCRIPTION, taskComment.getText()); break; } - report.addComment(taskComment); + repositoryTaskData.addComment(taskComment); } break; @@ -207,7 +203,7 @@ public class SaxBugReportContentHandler extends DefaultHandler { break; case ATTACHMENT: if (attachment != null) { - report.addAttachment(attachment); + repositoryTaskData.addAttachment(attachment); } break; @@ -222,34 +218,37 @@ public class SaxBugReportContentHandler extends DefaultHandler { case BUG: // Reached end of bug. Need to set LONGDESCLENGTH to number of // comments - RepositoryTaskAttribute numCommentsAttribute = report.getAttribute(BugzillaReportElement.LONGDESCLENGTH + RepositoryTaskAttribute numCommentsAttribute = repositoryTaskData.getAttribute(BugzillaReportElement.LONGDESCLENGTH .getKeyString()); if (numCommentsAttribute == null) { numCommentsAttribute = attributeFactory.createAttribute(BugzillaReportElement.LONGDESCLENGTH .getKeyString()); - numCommentsAttribute.setValue("" + report.getComments().size()); - report.addAttribute(BugzillaReportElement.LONGDESCLENGTH.getKeyString(), numCommentsAttribute); + numCommentsAttribute.setValue("" + repositoryTaskData.getComments().size()); + repositoryTaskData.addAttribute(BugzillaReportElement.LONGDESCLENGTH.getKeyString(), numCommentsAttribute); } else { - numCommentsAttribute.setValue("" + report.getComments().size()); + numCommentsAttribute.setValue("" + repositoryTaskData.getComments().size()); } // Set the creator name on all attachments - for (RepositoryAttachment attachment : report.getAttachments()) { + for (RepositoryAttachment attachment : repositoryTaskData.getAttachments()) { TaskComment taskComment = attachIdToComment.get(attachment.getId()); if (taskComment != null) { attachment.setCreator(taskComment.getAuthor()); } - attachment.setAttributeValue(RepositoryTaskAttribute.ATTACHMENT_URL, report.getRepositoryUrl()+IBugzillaConstants.URL_GET_ATTACHMENT_SUFFIX+attachment.getId()); + attachment.setAttributeValue(RepositoryTaskAttribute.ATTACHMENT_URL, repositoryTaskData.getRepositoryUrl()+IBugzillaConstants.URL_GET_ATTACHMENT_SUFFIX+attachment.getId()); + attachment.setRepositoryKind(repositoryTaskData.getRepositoryKind()); + attachment.setRepositoryUrl(repositoryTaskData.getRepositoryUrl()); + attachment.setTaskId(repositoryTaskData.getId()); } break; case BLOCKED: case DEPENDSON: - RepositoryTaskAttribute dependancyAttribute = report.getAttribute(tag.getKeyString()); + RepositoryTaskAttribute dependancyAttribute = repositoryTaskData.getAttribute(tag.getKeyString()); if (dependancyAttribute == null) { dependancyAttribute = attributeFactory.createAttribute(tag.getKeyString()); dependancyAttribute.setValue(parsedText); - report.addAttribute(tag.getKeyString(), dependancyAttribute); + repositoryTaskData.addAttribute(tag.getKeyString(), dependancyAttribute); } else { if(dependancyAttribute.getValue().equals("")) { dependancyAttribute.setValue(parsedText); @@ -260,11 +259,11 @@ public class SaxBugReportContentHandler extends DefaultHandler { break; // All others added as report attribute default: - RepositoryTaskAttribute attribute = report.getAttribute(tag.getKeyString()); + RepositoryTaskAttribute attribute = repositoryTaskData.getAttribute(tag.getKeyString()); if (attribute == null) { attribute = attributeFactory.createAttribute(tag.getKeyString()); attribute.setValue(parsedText); - report.addAttribute(tag.getKeyString(), attribute); + repositoryTaskData.addAttribute(tag.getKeyString(), attribute); } else { attribute.addValue(parsedText); } 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 f38517c0e..ec4981a3a 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 @@ -299,7 +299,7 @@ public class SaxConfigurationContentHandler extends DefaultHandler { if (attributes != null) { String compURI = attributes.getValue(ATTRIBUTE_RESOURCE); if (compURI != null && currentProduct.length() > 0) { - List<String> compURIs = components.get(currentProduct.toString()); + List<String> compURIs = components.get(currentProduct); if (compURIs == null) { compURIs = new ArrayList<String>(); components.put(currentProduct, compURIs); @@ -312,10 +312,10 @@ public class SaxConfigurationContentHandler extends DefaultHandler { if (attributes != null) { String resourceURI = attributes.getValue(ATTRIBUTE_RESOURCE); if (resourceURI != null && currentProduct.length() > 0) { - List<String> versionUris = versions.get(currentProduct.toString()); + List<String> versionUris = versions.get(currentProduct); if (versionUris == null) { versionUris = new ArrayList<String>(); - versions.put(currentProduct.toString(), versionUris); + versions.put(currentProduct, versionUris); } versionUris.add(resourceURI); } @@ -325,10 +325,10 @@ public class SaxConfigurationContentHandler extends DefaultHandler { if (attributes != null) { String resourceURI = attributes.getValue(ATTRIBUTE_RESOURCE); if (resourceURI != null) { - List<String> milestoneUris = milestones.get(currentProduct.toString()); + List<String> milestoneUris = milestones.get(currentProduct); if (milestoneUris == null) { milestoneUris = new ArrayList<String>(); - milestones.put(currentProduct.toString(), milestoneUris); + milestones.put(currentProduct, milestoneUris); } milestoneUris.add(resourceURI); } |