Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java106
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaClient.java20
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java69
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java38
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java14
-rw-r--r--org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java6
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java5
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java19
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java17
-rw-r--r--org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java14
10 files changed, 135 insertions, 173 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
index 813942f5d..d73ae6e0c 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/bugzilla/rest/core/tests/BugzillaRestClientTest.java
@@ -412,8 +412,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
taskData.getRoot()
.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
.setValue("M2");
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskData, null, null);
assertEquals(ResponseKind.TASK_CREATED, reposonse.getReposonseKind());
}
@@ -461,8 +461,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
TaskMapper mapper1 = new TaskMapper(taskData);
connector.getTaskMapping(taskDataSubmit).merge(mapper1);
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataSubmit,
- null, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataSubmit, null, null);
assertEquals(ResponseKind.TASK_CREATED, reposonse.getReposonseKind());
}
@@ -563,7 +563,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
assertEquals(
IOUtils.toString(
CommonTestUtil.getResource(this, actualFixture.getTestDataFolder() + "/taskDataFlags.txt")),
- flags.toString()); }
+ flags.toString());
+ }
@Test
public void testUpdateTaskData() throws Exception {
@@ -597,8 +598,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(attribute);
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -636,8 +637,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(attribute);
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -700,18 +701,13 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
BugzillaRestTaskAttachmentHandler attachmentHandler = new BugzillaRestTaskAttachmentHandler(connector);
ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
actualFixture.repository().getRepositoryUrl(), taskId);
-
- InputStream in = CommonTestUtil.getResource(this, "testdata/icons/bugzilla-logo.gif");
File file = File.createTempFile("attachment", null);
file.deleteOnExit();
- OutputStream out = new FileOutputStream(file);
- try {
+
+ try (OutputStream out = new FileOutputStream(file);
+ InputStream in = CommonTestUtil.getResource(this, "testdata/icons/bugzilla-logo.gif")) {
IOUtils.copy(in, out);
- } finally {
- in.close();
- out.close();
}
-
FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
attachment.setContentType("image/gif");
attachment.setDescription("My Attachment 2");
@@ -774,16 +770,11 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
BugzillaRestTaskAttachmentHandler attachmentHandler = new BugzillaRestTaskAttachmentHandler(connector);
ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
actualFixture.repository().getRepositoryUrl(), taskId);
-
- InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt");
File file = File.createTempFile("attachment", null);
file.deleteOnExit();
- OutputStream out = new FileOutputStream(file);
- try {
+ try (OutputStream out = new FileOutputStream(file);
+ InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt")) {
IOUtils.copy(in, out);
- } finally {
- in.close();
- out.close();
}
FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
@@ -861,10 +852,11 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
taskData.getRoot()
.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
.setValue("M2");
- taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey()).setValue(
- "admin@mylyn.eclipse.org, tests@mylyn.eclipse.org");
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
+ taskData.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().CC.getKey())
+ .setValue("admin@mylyn.eclipse.org, tests@mylyn.eclipse.org");
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskData, null, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -914,10 +906,11 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
taskData.getRoot()
.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
.setValue("M2");
- taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().BLOCKS.getKey()).setValue(
- taskIdRel[0] + ", " + taskIdRel[1]);
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
+ taskData.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().BLOCKS.getKey())
+ .setValue(taskIdRel[0] + ", " + taskIdRel[1]);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskData, null, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -967,10 +960,11 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
taskData.getRoot()
.getAttribute(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())
.setValue("M2");
- taskData.getRoot().getAttribute(BugzillaRestCreateTaskSchema.getDefault().DEPENDS_ON.getKey()).setValue(
- taskIdRel[0] + ", " + taskIdRel[1]);
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskData, null,
- null);
+ taskData.getRoot()
+ .getAttribute(BugzillaRestCreateTaskSchema.getDefault().DEPENDS_ON.getKey())
+ .setValue(taskIdRel[0] + ", " + taskIdRel[1]);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskData, null, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_CREATED));
@@ -995,8 +989,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(attribute);
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1045,8 +1039,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey()));
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1093,8 +1087,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().BLOCKS.getKey()));
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1142,8 +1136,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey()));
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1191,8 +1185,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
changed.add(taskDataOld.getRoot().getAttribute(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey()));
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1268,8 +1262,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
}
//Act
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1385,8 +1379,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
}
}
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1575,8 +1569,8 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
}
}
- RepositoryResponse reposonse = connector.getClient(actualFixture.repository()).postTaskData(taskDataGet,
- changed, null);
+ RepositoryResponse reposonse = connector.getClient(actualFixture.repository())
+ .postTaskData(taskDataGet, changed, null);
assertNotNull(reposonse);
assertNotNull(reposonse.getReposonseKind());
assertThat(reposonse.getReposonseKind(), is(ResponseKind.TASK_UPDATED));
@@ -1781,15 +1775,11 @@ public class BugzillaRestClientTest implements IFixtureJUnitClass {
ITask task = new TaskTask(actualFixture.repository().getConnectorKind(),
actualFixture.repository().getRepositoryUrl(), taskId);
- InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt");
File file = File.createTempFile("attachment", null);
file.deleteOnExit();
- OutputStream out = new FileOutputStream(file);
- try {
+ try (OutputStream out = new FileOutputStream(file);
+ InputStream in = CommonTestUtil.getResource(this, "testdata/AttachmentTest.txt")) {
IOUtils.copy(in, out);
- } finally {
- in.close();
- out.close();
}
FileTaskAttachmentSource attachment = new FileTaskAttachmentSource(file);
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 fca6135f5..911e1709e 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.mylyn.internal.bugzilla.core;
+import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -1654,9 +1655,8 @@ public class BugzillaClient {
value = a.getValue();
if (value.equals("?") && requestee != null) { //$NON-NLS-1$
fields.put("requestee_type-" + flagTypeNumber, //$NON-NLS-1$
- new NameValuePair(
- "requestee_type-" //$NON-NLS-1$
- + flagTypeNumber,
+ new NameValuePair("requestee_type-" //$NON-NLS-1$
+ + flagTypeNumber,
requestee.getValue() != null ? requestee.getValue() : "")); //$NON-NLS-1$
}
}
@@ -1671,9 +1671,8 @@ public class BugzillaClient {
}
if (value.equals("?") && requestee != null) { //$NON-NLS-1$
fields.put("requestee-" + flagnumber.getValue(), //$NON-NLS-1$
- new NameValuePair(
- "requestee-" //$NON-NLS-1$
- + flagnumber.getValue(),
+ new NameValuePair("requestee-" //$NON-NLS-1$
+ + flagnumber.getValue(),
requestee.getValue() != null ? requestee.getValue() : "")); //$NON-NLS-1$
}
} else if (id.startsWith(TaskAttribute.PREFIX_COMMENT)) {
@@ -2687,14 +2686,14 @@ public class BugzillaClient {
GzipGetMethod method = null;
try {
method = getConnect(loginUrl, monitor);
- InputStream input = null;
File file = new File(changeSeparator(transFile, '/', File.separatorChar));
file.getParentFile().mkdirs();
- FileOutputStream output = new FileOutputStream(transFile);
- input = getResponseStream(method, monitor);
- transferData(input, output);
+ try (InputStream input = getResponseStream(method, monitor);
+ BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(transFile))) {
+ transferData(input, output);
+ }
} finally {
if (method != null) {
WebUtil.releaseConnection(method, monitor);
@@ -2706,6 +2705,7 @@ public class BugzillaClient {
return connector;
}
+ @SuppressWarnings("restriction")
public TaskRepository getTaskRepository() {
if (location instanceof TaskRepositoryLocation) {
return ((TaskRepositoryLocation) location).getTaskRepository();
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 7148fd468..714bd8e84 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,6 +11,7 @@
package org.eclipse.mylyn.internal.bugzilla.core;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -206,15 +207,16 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
if (isComplete) {
Date completionDate = null;
- List<TaskAttribute> taskComments = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_COMMENT);
+ List<TaskAttribute> taskComments = taskData.getAttributeMapper()
+ .getAttributesByType(taskData, TaskAttribute.TYPE_COMMENT);
if (taskComments != null && taskComments.size() > 0) {
TaskAttribute lastComment = taskComments.get(taskComments.size() - 1);
if (lastComment != null) {
TaskAttribute attributeCommentDate = lastComment.getMappedAttribute(TaskAttribute.COMMENT_DATE);
if (attributeCommentDate != null) {
try {
- completionDate = new SimpleDateFormat(COMMENT_FORMAT).parse(attributeCommentDate.getValue());
+ completionDate = new SimpleDateFormat(COMMENT_FORMAT)
+ .parse(attributeCommentDate.getValue());
} catch (ParseException e) {
// ignore
}
@@ -224,8 +226,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
if (completionDate == null) {
// Use last modified date
- TaskAttribute attributeLastModified = taskData.getRoot().getMappedAttribute(
- TaskAttribute.DATE_MODIFICATION);
+ TaskAttribute attributeLastModified = taskData.getRoot()
+ .getMappedAttribute(TaskAttribute.DATE_MODIFICATION);
if (attributeLastModified != null && attributeLastModified.getValue().length() > 0) {
completionDate = taskData.getAttributeMapper().getDateValue(attributeLastModified);
}
@@ -277,8 +279,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
monitor = Policy.monitorFor(monitor);
try {
- monitor.beginTask(Messages.BugzillaRepositoryConnector_checking_for_changed_tasks, session.getTasks()
- .size());
+ monitor.beginTask(Messages.BugzillaRepositoryConnector_checking_for_changed_tasks,
+ session.getTasks().size());
if (repository.getSynchronizationTimeStamp() == null) {
for (ITask task : session.getTasks()) {
@@ -331,15 +333,16 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
} catch (UnsupportedEncodingException e) {
throw new CoreException(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
"Repository configured with unsupported encoding: " + repository.getCharacterEncoding() //$NON-NLS-1$
- + "\n\n Unable to determine changed tasks.", e)); //$NON-NLS-1$
+ + "\n\n Unable to determine changed tasks.", //$NON-NLS-1$
+ e));
} finally {
monitor.done();
}
}
private void queryForChanged(final TaskRepository repository, Set<ITask> changedTasks, String urlQueryString,
- ISynchronizationSession syncSession, IProgressMonitor monitor) throws UnsupportedEncodingException,
- CoreException {
+ ISynchronizationSession syncSession, IProgressMonitor monitor)
+ throws UnsupportedEncodingException, CoreException {
HashMap<String, ITask> taskById = new HashMap<String, ITask>();
for (ITask task : syncSession.getTasks()) {
@@ -403,8 +406,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.INFO,
Messages.BugzillaRepositoryConnector_Unrecognized_response_from_server, e);
} catch (IOException e) {
- return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.ERROR, MessageFormat.format(
- Messages.BugzillaRepositoryConnector_Check_repository_configuration, e.getMessage()), e);
+ return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.ERROR, MessageFormat
+ .format(Messages.BugzillaRepositoryConnector_Check_repository_configuration, e.getMessage()), e);
} catch (CoreException e) {
return e.getStatus();
} finally {
@@ -460,7 +463,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
}
@Override
- public void updateRepositoryConfiguration(TaskRepository repository, IProgressMonitor monitor) throws CoreException {
+ public void updateRepositoryConfiguration(TaskRepository repository, IProgressMonitor monitor)
+ throws CoreException {
if (repository != null) {
getRepositoryConfiguration(repository, true, monitor);
}
@@ -663,7 +667,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
@Override
public PriorityLevel getPriorityLevel() {
- RepositoryConfiguration repositoryConfiguration = BugzillaRepositoryConnector.this.getRepositoryConfiguration(taskData.getRepositoryUrl());
+ RepositoryConfiguration repositoryConfiguration = BugzillaRepositoryConnector.this
+ .getRepositoryConfiguration(taskData.getRepositoryUrl());
String priority = getPriority();
if (repositoryConfiguration == null) {
// When we did not have the configuration we only can use the standard Priorities
@@ -694,8 +699,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
}
}
} catch (Exception e) {
- StatusHandler.log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN,
- ERROR_INCOMPATIBLE_CONFIGURATION));
+ StatusHandler
+ .log(new Status(IStatus.INFO, BugzillaCorePlugin.ID_PLUGIN, ERROR_INCOMPATIBLE_CONFIGURATION));
try {
if (in != null) {
in.close();
@@ -779,7 +784,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
if (configuration == null) {
throw new CoreException(new BugzillaStatus(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN,
RepositoryStatus.ERROR_INTERNAL, "Failed to retrieve repository configuration for " //$NON-NLS-1$
- + repository.getRepositoryUrl().toString()));
+ + repository.getRepositoryUrl().toString()));
}
return configuration;
@@ -818,32 +823,26 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
/** public for testing */
public void writeRepositoryConfigFile() {
if (repositoryConfigurationFile != null) {
- ObjectOutputStream out = null;
try {
Set<RepositoryConfiguration> tempConfigs;
synchronized (repositoryConfigurations) {
tempConfigs = new HashSet<RepositoryConfiguration>(repositoryConfigurations.values());
}
+
if (tempConfigs.size() > 0) {
- out = new ObjectOutputStream(new FileOutputStream(repositoryConfigurationFile));
- out.writeInt(tempConfigs.size());
- for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
- if (repositoryConfiguration != null) {
- out.writeObject(repositoryConfiguration);
+ try (ObjectOutputStream out = new ObjectOutputStream(
+ new BufferedOutputStream(new FileOutputStream(repositoryConfigurationFile)))) {
+ out.writeInt(tempConfigs.size());
+ for (RepositoryConfiguration repositoryConfiguration : tempConfigs) {
+ if (repositoryConfiguration != null) {
+ out.writeObject(repositoryConfiguration);
+ }
}
}
}
} catch (IOException e) {
StatusHandler.log(new Status(IStatus.WARNING, BugzillaCorePlugin.ID_PLUGIN, 0,
"Failed to write repository configuration cache", e)); //$NON-NLS-1$
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
}
}
}
@@ -860,8 +859,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
// set both or none
if (null != os && null != platform) {
TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
- TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
- BugzillaAttribute.REP_PLATFORM.getKey());
+ TaskAttribute platformAttribute = newBugModel.getRoot()
+ .getAttribute(BugzillaAttribute.REP_PLATFORM.getKey());
// TODO something can still go wrong when the allowed values on the repository change...
opSysAttribute.setValue(os);
@@ -879,8 +878,8 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector {
// Check that the result is in Values, if it is not, set it to other
// Defaults to the first of each (sorted) list All, All
TaskAttribute opSysAttribute = newBugModel.getRoot().getAttribute(BugzillaAttribute.OP_SYS.getKey());
- TaskAttribute platformAttribute = newBugModel.getRoot().getAttribute(
- BugzillaAttribute.REP_PLATFORM.getKey());
+ TaskAttribute platformAttribute = newBugModel.getRoot()
+ .getAttribute(BugzillaAttribute.REP_PLATFORM.getKey());
String OS = Platform.getOS();
String platform = Platform.getOSArch();
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
index a9a1ec3b6..743945e6b 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaAttachmentHandlerTest.java
@@ -58,8 +58,9 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
@SuppressWarnings("null")
public void testUpdateAttachmentFlags() throws Exception {
- TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
- "description for testUpdateAttachmentFlags");
+ TaskData taskData = BugzillaFixture.current()
+ .createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+ "description for testUpdateAttachmentFlags");
assertNotNull(taskData);
int numAttached = taskData.getAttributeMapper()
.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -349,8 +350,8 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
taskData = BugzillaFixture.current().getTask(taskData.getTaskId(), client);
assertNotNull(taskData);
- List<TaskAttribute> attachmentAttrs = taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_ATTACHMENT);
+ List<TaskAttribute> attachmentAttrs = taskData.getAttributeMapper()
+ .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT);
assertEquals(1, attachmentAttrs.size());
attachmentMapper = TaskAttachmentMapper.createFrom(attachmentAttrs.get(0));
@@ -506,8 +507,8 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
boolean isObsolete[] = { false, true, false, true };
int index = 0;
- for (TaskAttribute attribute : taskData.getAttributeMapper().getAttributesByType(taskData,
- TaskAttribute.TYPE_ATTACHMENT)) {
+ for (TaskAttribute attribute : taskData.getAttributeMapper()
+ .getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)) {
assertTrue(validateAttachmentAttributes(taskData, attribute, isPatch[index], isObsolete[index], task));
index++;
}
@@ -551,8 +552,9 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
attachmentMapper.setComment("Context attachment failure Test");
attachmentMapper.applyTo(attrAttachment);
- connector.getTaskAttachmentHandler().postContent(repository, task, attachment,
- attachmentMapper.getComment(), attrAttachment, new NullProgressMonitor());
+ connector.getTaskAttachmentHandler()
+ .postContent(repository, task, attachment, attachmentMapper.getComment(), attrAttachment,
+ new NullProgressMonitor());
} catch (CoreException e) {
assertTrue(BugzillaTestSupportUtil.isInvalidLogon(e));
assertEquals(SynchronizationState.SYNCHRONIZED, task.getSynchronizationState());
@@ -562,8 +564,9 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
}
public void testDownloadAttachmentFile() throws Exception {
- TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
- "description for testUpdateAttachmentFlags");
+ TaskData taskData = BugzillaFixture.current()
+ .createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+ "description for testUpdateAttachmentFlags");
assertNotNull(taskData);
int numAttached = taskData.getAttributeMapper()
.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -609,11 +612,8 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
ITaskAttachment taskAttachment;
taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute);
- OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
AttachmentUtil.downloadAttachment(taskAttachment, out, new NullProgressMonitor());
- } finally {
- out.close();
}
FileInputStream raf = new FileInputStream(file);
@@ -630,8 +630,9 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
}
public void testDownloadNonExsistingAttachmentFile() throws Exception {
- TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, "update of Attachment Flags",
- "description for testUpdateAttachmentFlags");
+ TaskData taskData = BugzillaFixture.current()
+ .createTask(PrivilegeLevel.USER, "update of Attachment Flags",
+ "description for testUpdateAttachmentFlags");
assertNotNull(taskData);
int numAttached = taskData.getAttributeMapper()
.getAttributesByType(taskData, TaskAttribute.TYPE_ATTACHMENT)
@@ -678,14 +679,11 @@ public class BugzillaAttachmentHandlerTest extends AbstractBugzillaTest {
ITaskAttachment taskAttachment;
taskAttachment = new TaskAttachment(repository, iTask, attachmentAttribute);
- OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
- try {
+ try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
AttachmentUtil.downloadAttachment(taskAttachment, out, new NullProgressMonitor());
} catch (CoreException e) {
String message = e.getMessage();
assertTrue(message.startsWith("invalid attachment id: "));
- } finally {
- out.close();
}
}
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
index 252373c80..428a1df0d 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/RepositoryClientManager.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.mylyn.tasks.core;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -160,9 +161,8 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
return;
}
- ObjectOutputStream out = null;
- try {
- out = new ObjectOutputStream(new FileOutputStream(cacheFile));
+ try (ObjectOutputStream out = new ObjectOutputStream(
+ new BufferedOutputStream(new FileOutputStream(cacheFile)))) {
out.writeInt(respoitoryConfigurationByUrl.size());
for (String url : respoitoryConfigurationByUrl.keySet()) {
out.writeObject(url);
@@ -170,14 +170,6 @@ public abstract class RepositoryClientManager<T, C extends Serializable> impleme
}
} catch (IOException e) {
handleError("The respository configuration cache could not be written", e); //$NON-NLS-1$
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
}
}
diff --git a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
index c1317331e..b8bd0baeb 100644
--- a/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
+++ b/org.eclipse.mylyn.tasks.index.tests/src/org/eclipse/mylyn/internal/tasks/index/tests/TaskListIndexCorruptTest.java
@@ -13,6 +13,7 @@ package org.eclipse.mylyn.internal.tasks.index.tests;
import static org.junit.Assert.assertTrue;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -50,15 +51,12 @@ public class TaskListIndexCorruptTest extends AbstractTaskListIndexTest {
private void corruptFile(File file) throws IOException {
Random random = new Random(123);
long length = file.length();
- OutputStream stream = new FileOutputStream(file);
- try {
+ try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) {
byte[] bytes = new byte[1];
for (long i = 0; i < length; ++i) {
random.nextBytes(bytes);
stream.write(bytes[0]);
}
- } finally {
- stream.close();
}
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
index 51b5f9865..b30562fce 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/DownloadAndOpenTaskAttachmentJob.java
@@ -11,6 +11,7 @@
package org.eclipse.mylyn.internal.tasks.ui;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -82,9 +83,9 @@ class DownloadAndOpenTaskAttachmentJob implements ICoreRunnable {
file.deleteOnExit();
boolean ok = false;
- FileOutputStream fos = null;
+ BufferedOutputStream fos = null;
try {
- fos = new FileOutputStream(file);
+ fos = new BufferedOutputStream(new FileOutputStream(file));
AttachmentUtil.downloadAttachment(attachment, fos, monitor);
ok = true;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
index a0e72cd87..7aed65c07 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/wizards/TaskAttachmentWizard.java
@@ -11,6 +11,7 @@
package org.eclipse.mylyn.internal.tasks.ui.wizards;
+import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -67,7 +68,7 @@ import org.eclipse.ui.statushandlers.StatusManager;
/**
* A wizard to add a new attachment to a task report.
- *
+ *
* @since 3.0
* @author Steffen Pingel
*/
@@ -216,11 +217,8 @@ public class TaskAttachmentWizard extends Wizard {
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { image.getImageData() };
// TODO create image in memory?
- FileOutputStream out = new FileOutputStream(file);
- try {
+ try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
loader.save(out, SWT.IMAGE_PNG);
- } finally {
- out.close();
}
} finally {
image.dispose();
@@ -314,8 +312,8 @@ public class TaskAttachmentWizard extends Wizard {
previewPage = new AttachmentPreviewPage(model);
addPage(previewPage);
- AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getConnectorUi(model.getTaskRepository()
- .getConnectorKind());
+ AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin
+ .getConnectorUi(model.getTaskRepository().getConnectorKind());
editPage = connectorUi.getTaskAttachmentPage(model);
addPage(editPage);
@@ -352,8 +350,8 @@ public class TaskAttachmentWizard extends Wizard {
@Override
public boolean performFinish() {
SubmitJob job = TasksUiInternal.getJobFactory()
- .createSubmitTaskAttachmentJob(connector, model.getTaskRepository(), model.getTask(),
- model.getSource(), model.getComment(), model.getAttribute());
+ .createSubmitTaskAttachmentJob(connector, model.getTaskRepository(), model.getTask(), model.getSource(),
+ model.getComment(), model.getAttribute());
final boolean attachContext = model.getAttachContext();
job.addSubmitJobListener(new SubmitJobListener() {
@Override
@@ -420,7 +418,8 @@ public class TaskAttachmentWizard extends Wizard {
return job.getStatus() == null;
} catch (InvocationTargetException e) {
StatusManager.getManager()
- .handle(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unexpected error", e), StatusManager.SHOW | StatusManager.LOG); //$NON-NLS-1$
+ .handle(new Status(IStatus.ERROR, TasksUiPlugin.ID_PLUGIN, "Unexpected error", e), //$NON-NLS-1$
+ StatusManager.SHOW | StatusManager.LOG);
return false;
} catch (InterruptedException e) {
// canceled
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
index 99af02c4f..e6c22b11a 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracClientManager.java
@@ -11,6 +11,7 @@
package org.eclipse.mylyn.internal.trac.core;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -33,7 +34,7 @@ import org.eclipse.mylyn.tasks.core.TaskRepositoryLocationFactory;
/**
* Caches {@link ITracClient} objects.
- *
+ *
* @author Steffen Pingel
*/
public class TracClientManager implements IRepositoryListener {
@@ -134,10 +135,8 @@ public class TracClientManager implements IRepositoryListener {
if (cacheFile == null) {
return;
}
-
- ObjectOutputStream out = null;
- try {
- out = new ObjectOutputStream(new FileOutputStream(cacheFile));
+ try (ObjectOutputStream out = new ObjectOutputStream(
+ new BufferedOutputStream(new FileOutputStream(cacheFile)))) {
out.writeInt(clientDataByUrl.size());
for (String url : clientDataByUrl.keySet()) {
out.writeObject(url);
@@ -146,14 +145,6 @@ public class TracClientManager implements IRepositoryListener {
} catch (IOException e) {
StatusHandler.log(new Status(IStatus.WARNING, TracCorePlugin.ID_PLUGIN,
"The Trac respository configuration cache could not be written", e)); //$NON-NLS-1$
- } finally {
- if (out != null) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
}
}
diff --git a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
index fe3ea5e94..f268ffaa7 100644
--- a/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
+++ b/org.eclipse.mylyn.trac.tests/src/org/eclipse/mylyn/trac/tests/core/TracAttachmentHandlerTest.java
@@ -17,8 +17,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
-import junit.framework.TestCase;
-
import org.eclipse.mylyn.internal.tasks.core.data.FileTaskAttachmentSource;
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
import org.eclipse.mylyn.internal.trac.core.client.ITracClient;
@@ -31,6 +29,8 @@ import org.eclipse.mylyn.trac.tests.support.TracFixture;
import org.eclipse.mylyn.trac.tests.support.TracHarness;
import org.eclipse.mylyn.trac.tests.support.TracTestUtil;
+import junit.framework.TestCase;
+
/**
* @author Steffen Pingel
*/
@@ -79,22 +79,16 @@ public class TracAttachmentHandlerTest extends TestCase {
ITask task = harness.createTask("GetContent");
File file = File.createTempFile("attachment", null);
file.deleteOnExit();
- OutputStream out = new FileOutputStream(file);
- try {
+ try (OutputStream out = new FileOutputStream(file)) {
out.write("Mylar".getBytes());
- } finally {
- out.close();
}
attachmentHandler.postContent(repository, task, new FileTaskAttachmentSource(file), "comment", null, null);
ITracClient client = connector.getClientManager().getTracClient(repository);
- InputStream in = client.getAttachmentData(Integer.parseInt(task.getTaskId()), file.getName(), null);
- try {
+ try (InputStream in = client.getAttachmentData(Integer.parseInt(task.getTaskId()), file.getName(), null)) {
byte[] result = new byte[5];
in.read(result);
assertEquals("Mylar", new String(result));
- } finally {
- in.close();
}
}

Back to the top