Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java186
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java32
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java7
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java22
7 files changed, 148 insertions, 112 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index c1ae1abcf..bd18f1cc2 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -8,6 +8,7 @@ Eclipse-AutoStart: true
Bundle-Vendor: Eclipse.org
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.mylar.context.core
+ org.eclipse.mylar.context.core,
+ org.eclipse.update.core
Export-Package: org.eclipse.mylar.internal.tasks.core,
org.eclipse.mylar.tasks.core
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
index 619e5d79c..8ce2a497e 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/WebClientUtil.java
@@ -11,24 +11,15 @@
package org.eclipse.mylar.internal.tasks.core;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
-import java.net.MalformedURLException;
import java.net.Proxy;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.GeneralSecurityException;
-import java.security.KeyManagementException;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
+import java.net.Proxy.Type;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.protocol.Protocol;
+import org.eclipse.update.internal.core.UpdateCore;
/**
* @author Mik Kersten
@@ -40,7 +31,7 @@ public class WebClientUtil {
private static final int HTTPS_PORT = 443;
- private static final int COM_TIME_OUT = 30000;
+ // private static final int COM_TIME_OUT = 30000;
public static final String ENCODING_GZIP = "gzip";
@@ -51,68 +42,94 @@ public class WebClientUtil {
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "off");
}
- /**
- * Returns an opened HttpURLConnection. If the proxy fails a direct connection
- * is attempted.
- */
- public static HttpURLConnection openUrlConnection(URL url, Proxy proxy, boolean useTls) throws IOException,
- KeyManagementException, GeneralSecurityException {
-
- if (proxy == null) {
- proxy = Proxy.NO_PROXY;
- }
-
- HttpURLConnection remoteConnection = getUrlConnection(url, proxy, useTls);
- try {
- remoteConnection = openConnection(url, proxy);
- } catch (ConnectException e) {
- remoteConnection = openConnection(url, Proxy.NO_PROXY);
- }
-
- return remoteConnection;
- }
-
- /**
- * Returns connection that has yet to be opened (can still set connection parameters).
- * Catch ConnectException and retry with Proxy.NO_PROXY if necessary.
- */
- public static HttpURLConnection getUrlConnection(URL url, Proxy proxy, boolean useTls) throws IOException,
- KeyManagementException, GeneralSecurityException {
- SSLContext ctx;
- if (useTls) {
- ctx = SSLContext.getInstance("TLS");
- } else {
- ctx = SSLContext.getInstance("SSL");
- }
-
- javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new RepositoryTrustManager() };
- ctx.init(null, tm, null);
- HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
-
- if (proxy == null) {
- proxy = Proxy.NO_PROXY;
- }
-
- URLConnection connection = url.openConnection(proxy);
-
- if (connection == null || !(connection instanceof HttpURLConnection)) {
- throw new MalformedURLException();
- }
- return (HttpURLConnection)connection;
- }
-
- private static HttpURLConnection openConnection(URL url, Proxy proxy) throws IOException {
- URLConnection connection = url.openConnection(proxy);
- if (connection == null || !(connection instanceof HttpURLConnection)) {
- throw new MalformedURLException();
- }
- HttpURLConnection remoteConnection = (HttpURLConnection) connection;
- remoteConnection.addRequestProperty("Accept-Encoding", ENCODING_GZIP);
- remoteConnection.setConnectTimeout(COM_TIME_OUT);
- remoteConnection.setReadTimeout(COM_TIME_OUT);
- remoteConnection.connect();
- return remoteConnection;
- }
+ // /**
+ // * Returns an opened HttpURLConnection. If the proxy fails a direct
+ // * connection is attempted.
+ // */
+ // public static HttpURLConnection openUrlConnection(URL url, Proxy proxy,
+ // boolean useTls, String htAuthUser,
+ // String htAuthPass) throws IOException, KeyManagementException,
+ // GeneralSecurityException {
+ //
+ // if (proxy == null) {
+ // proxy = Proxy.NO_PROXY;
+ // }
+ //
+ // HttpURLConnection remoteConnection = getUrlConnection(url, proxy, useTls,
+ // htAuthUser, htAuthPass);
+ // try {
+ // remoteConnection = openConnection(url, proxy);
+ // } catch (ConnectException e) {
+ // remoteConnection = openConnection(url, Proxy.NO_PROXY);
+ // }
+ //
+ // return remoteConnection;
+ // }
+
+ // /**
+ // * Returns connection that has yet to be opened (can still set connection
+ // * parameters). Catch ConnectException and retry with Proxy.NO_PROXY if
+ // * necessary.
+ // */
+ // public static HttpURLConnection getUrlConnection(URL url, Proxy proxy,
+ // boolean useTls, String htAuthUser,
+ // String htAuthPass) throws IOException, KeyManagementException,
+ // GeneralSecurityException {
+ // SSLContext ctx;
+ // if (useTls) {
+ // ctx = SSLContext.getInstance("TLS");
+ // } else {
+ // ctx = SSLContext.getInstance("SSL");
+ // }
+ //
+ // javax.net.ssl.TrustManager[] tm = new javax.net.ssl.TrustManager[] { new
+ // RepositoryTrustManager() };
+ // ctx.init(null, tm, null);
+ // HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
+ //
+ // if (proxy == null) {
+ // proxy = Proxy.NO_PROXY;
+ // }
+ //
+ // URLConnection connection = url.openConnection(proxy);
+ //
+ // // Add http basic authentication credentials if supplied
+ // // Ref: http://www.javaworld.com/javaworld/javatips/jw-javatip47.html
+ // if (htAuthUser != null && htAuthPass != null && !htAuthUser.equals("")) {
+ // String authenticationString = htAuthUser + ":" + htAuthPass;
+ // String encodedAuthenticationString = null;
+ // try {
+ // sun.misc.BASE64Encoder encoder = (sun.misc.BASE64Encoder)
+ // Class.forName("sun.misc.BASE64Encoder")
+ // .newInstance();
+ // encodedAuthenticationString =
+ // encoder.encode(authenticationString.getBytes());
+ // connection.setRequestProperty("Authorization", "Basic " +
+ // encodedAuthenticationString);
+ // } catch (Exception ex) {
+ // // ignore, encoder not available
+ // }
+ // }
+ //
+ // if (connection == null || !(connection instanceof HttpURLConnection)) {
+ // throw new MalformedURLException();
+ // }
+ // return (HttpURLConnection) connection;
+ // }
+
+ // private static HttpURLConnection openConnection(URL url, Proxy proxy)
+ // throws IOException {
+ // URLConnection connection = url.openConnection(proxy);
+ // if (connection == null || !(connection instanceof HttpURLConnection)) {
+ // throw new MalformedURLException();
+ // }
+ // HttpURLConnection remoteConnection = (HttpURLConnection) connection;
+ // remoteConnection.addRequestProperty("Accept-Encoding", ENCODING_GZIP);
+ // remoteConnection.setConnectTimeout(COM_TIME_OUT);
+ // remoteConnection.setReadTimeout(COM_TIME_OUT);
+ // remoteConnection.connect();
+ // return remoteConnection;
+ // }
/**
* public for testing
@@ -169,14 +186,16 @@ public class WebClientUtil {
return repositoryUrl.substring(requestPath);
}
- public static void setupHttpClient(HttpClient client, Proxy proxySettings, String repositoryUrl, String user, String password) {
+ public static void setupHttpClient(HttpClient client, Proxy proxySettings, String repositoryUrl, String user,
+ String password) {
if (proxySettings != null && proxySettings.address() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) proxySettings.address();
client.getHostConfiguration().setProxy(address.getHostName(), address.getPort());
}
-
- if(user!=null && password!=null) {
- AuthScope authScope = new AuthScope(WebClientUtil.getDomain(repositoryUrl), WebClientUtil.getPort(repositoryUrl), AuthScope.ANY_REALM);
+
+ if (user != null && password != null) {
+ AuthScope authScope = new AuthScope(WebClientUtil.getDomain(repositoryUrl), WebClientUtil
+ .getPort(repositoryUrl), AuthScope.ANY_REALM);
client.getState().setCredentials(authScope, new UsernamePasswordCredentials(user, password));
}
@@ -191,4 +210,15 @@ public class WebClientUtil {
}
}
+ public static Proxy getProxySettings() {
+ Proxy proxy = Proxy.NO_PROXY;
+ if (UpdateCore.getPlugin().getPluginPreferences().getBoolean(UpdateCore.HTTP_PROXY_ENABLE)) {
+ String proxyHost = UpdateCore.getPlugin().getPluginPreferences().getString(UpdateCore.HTTP_PROXY_HOST);
+ int proxyPort = UpdateCore.getPlugin().getPluginPreferences().getInt(UpdateCore.HTTP_PROXY_PORT);
+
+ InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort);
+ proxy = new Proxy(Type.HTTP, sockAddr);
+ }
+ return proxy;
+ }
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
index 70db45265..5bf7b5390 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
@@ -25,7 +25,7 @@ import org.eclipse.mylar.context.core.ContextCorePlugin;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask.RepositoryTaskSyncState;
/**
- * Encapsulates synchronization policy.
+ * Operations on a task repository
*
* @author Mik Kersten
* @author Rob Elves
@@ -45,7 +45,7 @@ public abstract class AbstractRepositoryConnector {
protected TaskList taskList;
public void init(TaskList taskList) {
- this.taskList = taskList;
+ this.taskList = taskList;
}
/**
@@ -65,18 +65,6 @@ public abstract class AbstractRepositoryConnector {
public abstract boolean canCreateNewTask(TaskRepository repository);
/**
- * Reset and update the repository attributes from the server (e.g.
- * products, components)
- *
- * @param proxySettings
- * TODO
- * @throws CoreException
- * TODO
- */
- public abstract void updateAttributes(TaskRepository repository, Proxy proxySettings, IProgressMonitor monitor)
- throws CoreException;
-
- /**
* @param id
* identifier, e.g. "123" bug Bugzilla bug 123
* @param proxySettings
@@ -193,14 +181,14 @@ public abstract class AbstractRepositoryConnector {
File destinationContextFile = ContextCorePlugin.getContextManager().getFileForContext(
task.getHandleIdentifier());
-
+
// TODO: add functionality for not overwriting previous context
- if(destinationContextFile.exists()) {
- if(!destinationContextFile.delete()) {
+ if (destinationContextFile.exists()) {
+ if (!destinationContextFile.delete()) {
return false;
}
}
- attachmentHandler.downloadAttachment(repository, task, attachment, destinationContextFile, proxySettings);
+ attachmentHandler.downloadAttachment(repository, AbstractRepositoryTask.getTaskId(task.getHandleIdentifier()), attachment, destinationContextFile);
return true;
}
@@ -226,4 +214,12 @@ public abstract class AbstractRepositoryConnector {
return "task";
}
+ /**
+ * Reset and update the repository attributes from the server (e.g.
+ * products, components)
+ *
+ * TODO: remove?
+ */
+ public abstract void updateAttributes(TaskRepository repository, IProgressMonitor monitor) throws CoreException;
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
index d3e45c63a..4e15ffb5f 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IAttachmentHandler.java
@@ -25,9 +25,12 @@ public interface IAttachmentHandler {
public void uploadAttachment(TaskRepository repository, AbstractRepositoryTask task, String comment,
String description, File file, String contentType, boolean isPatch, Proxy proxySettings) throws CoreException;
- public void downloadAttachment(TaskRepository taskRepository, AbstractRepositoryTask task,
- RepositoryAttachment attachment, File file, Proxy proxySettings) throws CoreException;
+ public void downloadAttachment(TaskRepository taskRepository, String taskId, RepositoryAttachment attachment, File file) throws CoreException;
+ public byte[] getAttachmentData(TaskRepository repository, String taskId) throws CoreException;
+
+ //public InputStream getAttachmentInputStream(TaskRepository repository, String taskId) throws CoreException;
+
public boolean canUploadAttachment(TaskRepository repository, AbstractRepositoryTask task);
public boolean canDownloadAttachment(TaskRepository repository, AbstractRepositoryTask task);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
index 8faf2e69d..d9bf5810b 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/IOfflineTaskHandler.java
@@ -16,8 +16,6 @@ import java.net.Proxy;
import java.util.Date;
import java.util.Set;
-import javax.security.auth.login.LoginException;
-
import org.eclipse.core.runtime.CoreException;
/**
@@ -33,7 +31,8 @@ public interface IOfflineTaskHandler {
public AbstractAttributeFactory getAttributeFactory();
- public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId, Proxy proxySettings) throws CoreException, LoginException;
+ // TODO: remove proxy parameter
+ public RepositoryTaskData downloadTaskData(TaskRepository repository, String taskId, Proxy proxySettings) throws CoreException;
/**
* returns all tasks if date is null or an error occurs
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
index 0bfdeff63..2b04e8a06 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepository.java
@@ -46,6 +46,10 @@ public class TaskRepository {
public static final String AUTH_USERNAME = "org.eclipse.mylar.tasklist.repositories.username"; //$NON-NLS-1$
+ public static final String AUTH_HTTP_PASSWORD = "org.eclipse.mylar.tasklist.repositories.httpauth.password"; //$NON-NLS-1$
+
+ public static final String AUTH_HTTP_USERNAME = "org.eclipse.mylar.tasklist.repositories.httpauth.username"; //$NON-NLS-1$
+
public static final String NO_VERSION_SPECIFIED = "unknown";
private static final String AUTH_SCHEME = "Basic";
@@ -270,5 +274,4 @@ public class TaskRepository {
String value = getProperty(name);
return value != null && value.trim().length() > 0;
}
-
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
index d9544d126..7380d2f08 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskRepositoryManager.java
@@ -34,7 +34,7 @@ public class TaskRepositoryManager {
public static final String OLD_REPOSITORIES_FILE = "repositories.xml";
public static final String DEFAULT_REPOSITORIES_FILE = "repositories.xml.zip";
-
+
public static final String PREF_REPOSITORIES = "org.eclipse.mylar.tasklist.repositories.";
private Map<String, AbstractRepositoryConnector> repositoryConnectors = new HashMap<String, AbstractRepositoryConnector>();
@@ -52,7 +52,7 @@ public class TaskRepositoryManager {
private TaskRepositoriesExternalizer externalizer = new TaskRepositoriesExternalizer();
private TaskList taskList;
-
+
public TaskRepositoryManager(TaskList taskList) {
this.taskList = taskList;
}
@@ -64,7 +64,7 @@ public class TaskRepositoryManager {
public AbstractRepositoryConnector getRepositoryConnector(String kind) {
return repositoryConnectors.get(kind);
}
-
+
public AbstractRepositoryConnector getRepositoryConnector(AbstractRepositoryTask task) {
return getRepositoryConnector(task.getRepositoryKind());
}
@@ -121,18 +121,18 @@ public class TaskRepositoryManager {
}
return null;
}
-
+
/**
* @return first repository that matches the given url
*/
public TaskRepository getRepository(String urlString) {
- for (String kind: repositoryMap.keySet()) {
+ for (String kind : repositoryMap.keySet()) {
for (TaskRepository repository : repositoryMap.get(kind)) {
if (repository.getUrl().equals(urlString)) {
return repository;
}
}
- }
+ }
return null;
}
@@ -215,7 +215,8 @@ public class TaskRepositoryManager {
private void loadRepositories(String repositoriesFilePath) {
try {
-// String dataDirectory = TasksUiPlugin.getDefault().getDataDirectory();
+ // String dataDirectory =
+ // TasksUiPlugin.getDefault().getDataDirectory();
File repositoriesFile = new File(repositoriesFilePath);
// Will only load repositories for which a connector exists
@@ -289,8 +290,10 @@ public class TaskRepositoryManager {
}
try {
-// String dataDirectory = TasksUiPlugin.getDefault().getDataDirectory();
-// File repositoriesFile = new File(dataDirectory + File.separator + TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
+ // String dataDirectory =
+ // TasksUiPlugin.getDefault().getDataDirectory();
+ // File repositoriesFile = new File(dataDirectory + File.separator +
+ // TasksUiPlugin.DEFAULT_REPOSITORIES_FILE);
File repositoriesFile = new File(destinationPath);
externalizer.writeRepositoriesToXML(repositoriesToWrite, repositoriesFile);
} catch (Throwable t) {
@@ -320,4 +323,5 @@ public class TaskRepositoryManager {
listener.repositorySettingsChanged(repository);
}
}
+
}

Back to the top