summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2011-12-22 11:36:59 (EST)
committer Steffen Pingel2011-12-22 11:39:16 (EST)
commit47ad0a68f6d5fefdf69104255c57cffc13d066b1 (patch)
tree507581080707ff032a116ebad73c444a67e1df02
parent406a9ba2d43289ad8f4f39d82e287c16d1696e9c (diff)
downloadorg.eclipse.mylyn.commons-47ad0a68f6d5fefdf69104255c57cffc13d066b1.zip
org.eclipse.mylyn.commons-47ad0a68f6d5fefdf69104255c57cffc13d066b1.tar.gz
org.eclipse.mylyn.commons-47ad0a68f6d5fefdf69104255c57cffc13d066b1.tar.bz2
NEW - bug 335254: [api] add o.e.m.commons.http bundle based on
HttpClient 4.1 https://bugs.eclipse.org/bugs/show_bug.cgi?id=335254 Change-Id: If572b67444f38a2fb7bec4af9f9779b9613f6189
-rw-r--r--org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF9
-rw-r--r--org.eclipse.mylyn.commons.core/plugin.xml4
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CommonMessages.java2
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java17
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/InfiniteSubProgressMonitor.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/InfiniteSubProgressMonitor.java)4
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Messages.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/Messages.java)4
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Policy.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/IProxyProvider.java)16
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingInputStream.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingInputStream.java)11
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingOutputStream.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingOutputStream.java)6
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/ProgressMonitorInputStream.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ProgressMonitorInputStream.java)5
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutInputStream.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutInputStream.java)8
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutOutputStream.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutOutputStream.java)4
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/messages.properties (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/messages.properties)0
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/AuthenticatedProxy.java)7
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java249
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/ProxyProvider.java43
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/TrustAllTrustManager.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TrustAllTrustManager.java)4
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/ICancellable.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ICancellable.java)10
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/IOperationMonitor.java40
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/MonitoredOperation.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/MonitoredRequest.java)87
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/Operation.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebRequest.java)12
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java101
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/CommonsCorePlugin.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/CommonsHttpPlugin.java)26
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/NullOperationMonitor.java65
-rw-r--r--org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/OperationMonitor.java134
-rw-r--r--org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF7
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java17
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpClient3.java114
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpMethod3.java38
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/HttpOperation3.java102
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/CommonsNetPlugin.java33
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java129
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java96
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java130
-rw-r--r--org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java6
-rw-r--r--org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java25
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/META-INF/MANIFEST.MF12
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/pom.xml2
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AbstractWebLocation.java67
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationCredentials.java91
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationType.java30
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/HttpUtil.java585
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/Policy.java139
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/UnsupportedRequestException.java39
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebLocation.java73
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java101
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java87
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpResponse.java77
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java359
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingProtocolSocketFactory.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingProtocolSocketFactory.java)10
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingSslProtocolSocketFactory.java (renamed from org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingSslProtocolSocketFactory.java)23
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.classpath12
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.cvsignore2
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.project34
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.core.runtime.prefs2
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.core.prefs359
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.ui.prefs63
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.ltk.core.refactoring.prefs3
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs4
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.pde.prefs18
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/META-INF/MANIFEST.MF31
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/about.html27
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/build.properties17
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/pom.xml21
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java39
-rw-r--r--org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java80
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java4
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java79
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/NetUtilTest.java164
-rw-r--r--pom.xml1
71 files changed, 3020 insertions, 1203 deletions
diff --git a/org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF
index 9a6db85..6a3e556 100644
--- a/org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.core/META-INF/MANIFEST.MF
@@ -6,8 +6,15 @@ Bundle-Version: 3.7.0.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Export-Package: org.eclipse.mylyn.commons.core,
+ org.eclipse.mylyn.commons.core.io,
+ org.eclipse.mylyn.commons.core.net,
+ org.eclipse.mylyn.commons.core.operations,
org.eclipse.mylyn.internal.commons.core;x-internal:=true,
+ org.eclipse.mylyn.internal.commons.core.operations;x-internal:=true,
org.eclipse.mylyn.internal.provisional.commons.core;x-internal:=true
-Require-Bundle: org.eclipse.core.runtime
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.net
Bundle-ClassPath: .
Bundle-Localization: plugin
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin
diff --git a/org.eclipse.mylyn.commons.core/plugin.xml b/org.eclipse.mylyn.commons.core/plugin.xml
index 80d8745..90bfc2e 100644
--- a/org.eclipse.mylyn.commons.core/plugin.xml
+++ b/org.eclipse.mylyn.commons.core/plugin.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?><!--
+<?eclipse version="3.0"?>
+<!--
Copyright (c) 2009 Tasktop Technologies and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +10,6 @@
Contributors:
Tasktop Technologies - initial API and implementation
-->
-
<plugin>
<extension-point id="errorReporters" name="Error Reporters" schema="schema/errorReporters.exsd"/>
</plugin>
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CommonMessages.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CommonMessages.java
index 5e81aea..ea22b6d 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CommonMessages.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CommonMessages.java
@@ -14,6 +14,8 @@ package org.eclipse.mylyn.commons.core;
import org.eclipse.osgi.util.NLS;
/**
+ * Commons message constants.
+ *
* @author Steffen Pingel
* @since 3.7
*/
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
index df8f943..cb1d33a 100644
--- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/CoreUtil.java
@@ -94,24 +94,29 @@ public class CoreUtil {
}
/**
+ * Compares <code>o1</code> and <code>o2</code>.
+ *
* @since 3.7
+ * @return a negative integer, 0, or a positive, if o1 is less than o2, o1 equals o2 or o1 is more than o2; null is
+ * considered less than any value
*/
- public static <T> int compare(Comparable<T> key1, T key2) {
- if (key1 == null) {
- return (key2 != null) ? 1 : 0;
- } else if (key2 == null) {
+ public static <T> int compare(Comparable<T> o1, T o2) {
+ if (o1 == null) {
+ return (o2 != null) ? 1 : 0;
+ } else if (o2 == null) {
return -1;
}
- return key1.compareTo(key2);
+ return o1.compareTo(o2);
}
/**
* Compares a boolean value.
*
* @since 3.7
+ * @see Boolean#equals(Object)
*/
public static boolean propertyEquals(boolean value, Object expectedValue) {
- return (expectedValue == null) ? value == true : new Boolean(value).equals(expectedValue);
+ return (expectedValue == null) ? value == true : Boolean.valueOf(value).equals(expectedValue);
}
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/InfiniteSubProgressMonitor.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/InfiniteSubProgressMonitor.java
index fbf5dcf..2df347f 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/InfiniteSubProgressMonitor.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/InfiniteSubProgressMonitor.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -20,6 +20,8 @@ import org.eclipse.core.runtime.SubProgressMonitor;
* in actually a hint used to determine how work is translated into ticks. The number of totalWork that can actually be
* worked is n*totalWork/2 where 2^n = totalWork. What this means is that if you provide a totalWork of 32 (2^5) than
* the maximum number of ticks is 5*32/2 = 80.
+ *
+ * @since 3.7
*/
public class InfiniteSubProgressMonitor extends SubProgressMonitor {
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/Messages.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Messages.java
index a02e91a..65a1f08 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/Messages.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Messages.java
@@ -9,11 +9,11 @@
* IBM - Initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import org.eclipse.osgi.util.NLS;
-public class Messages extends NLS {
+class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.commons.net.messages";//$NON-NLS-1$
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/IProxyProvider.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Policy.java
index 6a6baf3..eec271f 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/IProxyProvider.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/Policy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 Tasktop Technologies and others.
+ * Copyright (c) 2011 Tasktop Technologies 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
@@ -9,19 +9,13 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.commons.http;
-
-import java.net.Proxy;
+package org.eclipse.mylyn.commons.core.io;
/**
- * @since 3.6
- * @author Steffen Pingel
+ * @author spingel
*/
-public interface IProxyProvider {
+class Policy {
- /**
- * @since 3.6
- */
- public Proxy getProxyForHost(String host, String proxyType);
+ public static final boolean DEBUG_STREAMS = false;
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingInputStream.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingInputStream.java
index a6261c2..470c7cc 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingInputStream.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingInputStream.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import java.io.FilterInputStream;
import java.io.IOException;
@@ -19,7 +19,9 @@ import java.io.InterruptedIOException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.mylyn.commons.http.Policy;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.commons.core.ICommonsCoreConstants;
/**
* Polls a progress monitor periodically and handles timeouts over extended durations. For this class to be effective, a
@@ -27,8 +29,11 @@ import org.eclipse.mylyn.commons.http.Policy;
* so). Supports resuming partially completed operations after an InterruptedIOException if the underlying stream does.
* Check the bytesTransferred field to determine how much of the operation completed; conversely, at what point to
* resume.
+ *
+ * @since 3.7
*/
public class PollingInputStream extends FilterInputStream {
+
private static final boolean DEBUG = Policy.DEBUG_STREAMS;
private final int numAttempts;
@@ -73,7 +78,7 @@ public class PollingInputStream extends FilterInputStream {
} catch (IOException e) {
// We shouldn't get an exception when we're getting the available input.
// If we do, just log it so we can close.
- CommonsHttpPlugin.log(IStatus.ERROR, e.getMessage(), e);
+ StatusHandler.log(new Status(IStatus.ERROR, ICommonsCoreConstants.ID_PLUGIN, e.getMessage(), e));
} finally {
boolean stop = false;
while (!stop) {
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingOutputStream.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingOutputStream.java
index cd8bf6e..88e2af3 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingOutputStream.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/PollingOutputStream.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import java.io.FilterOutputStream;
import java.io.IOException;
@@ -18,7 +18,6 @@ import java.io.OutputStream;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.mylyn.commons.http.Policy;
/**
* Polls a progress monitor periodically and handles timeouts over extended durations. For this class to be effective, a
@@ -26,8 +25,11 @@ import org.eclipse.mylyn.commons.http.Policy;
* so). Supports resuming partially completed operations after an InterruptedIOException if the underlying stream does.
* Check the bytesTransferred field to determine how much of the operation completed; conversely, at what point to
* resume.
+ *
+ * @since 3.7
*/
public class PollingOutputStream extends FilterOutputStream {
+
private static final boolean DEBUG = Policy.DEBUG_STREAMS;
private final int numAttempts;
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ProgressMonitorInputStream.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/ProgressMonitorInputStream.java
index 04944d2..e30525d 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ProgressMonitorInputStream.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/ProgressMonitorInputStream.java
@@ -9,7 +9,7 @@
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import java.io.FilterInputStream;
import java.io.IOException;
@@ -23,8 +23,11 @@ import org.eclipse.core.runtime.IProgressMonitor;
* responsive cancellation on read(). Supports resuming partially completed operations after an InterruptedIOException
* if the underlying stream does. Check the bytesTransferred field to determine how much of the operation completed;
* conversely, at what point to resume.
+ *
+ * @since 3.7
*/
public abstract class ProgressMonitorInputStream extends FilterInputStream {
+
private final IProgressMonitor monitor;
private final int updateIncrement;
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutInputStream.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutInputStream.java
index 7c44e65..d050ef1 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutInputStream.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutInputStream.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import java.io.FilterInputStream;
import java.io.IOException;
@@ -18,7 +18,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
-import org.eclipse.mylyn.commons.http.Policy;
+import org.eclipse.mylyn.commons.core.operations.OperationUtil;
/**
* Wraps an input stream that blocks indefinitely to simulate timeouts on read(), skip(), and close(). The resulting
@@ -27,6 +27,8 @@ import org.eclipse.mylyn.commons.http.Policy;
* does unless the underlying stream itself generates InterruptedIOExceptions in which case it must also support
* resuming. Check the bytesTransferred field to determine how much of the operation completed; conversely, at what
* point to resume.
+ *
+ * @since 3.7
*/
public class TimeoutInputStream extends FilterInputStream {
// unsynchronized variables
@@ -74,7 +76,7 @@ public class TimeoutInputStream extends FilterInputStream {
this.readTimeout = readTimeout;
this.closeTimeout = closeTimeout;
this.iobuffer = new byte[bufferSize];
- this.future = CommonsHttpPlugin.getExecutorService().submit(new Runnable() {
+ this.future = OperationUtil.getExecutorService().submit(new Runnable() {
public void run() {
runThread();
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutOutputStream.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutOutputStream.java
index dd0ec4f..afe1276 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TimeoutOutputStream.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/TimeoutOutputStream.java
@@ -8,7 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.io;
import java.io.BufferedOutputStream;
import java.io.FilterOutputStream;
@@ -23,6 +23,8 @@ import java.io.OutputStream;
* does unless the underlying stream itself generates InterruptedIOExceptions in which case it must also support
* resuming. Check the bytesTransferred field to determine how much of the operation completed; conversely, at what
* point to resume.
+ *
+ * @since 3.7
*/
public class TimeoutOutputStream extends FilterOutputStream {
// unsynchronized variables
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/messages.properties b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/messages.properties
index 82ded52..82ded52 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/messages.properties
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/io/messages.properties
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/AuthenticatedProxy.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java
index 3d521d5..bf417ad 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/AuthenticatedProxy.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/AuthenticatedProxy.java
@@ -9,7 +9,7 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.net;
import java.net.Proxy;
import java.net.SocketAddress;
@@ -18,12 +18,13 @@ import java.net.SocketAddress;
* Abstraction for a proxy that supports user authentication.
*
* @author Rob Elves
+ * @since 3.7
*/
public class AuthenticatedProxy extends Proxy {
- private String userName = ""; //$NON-NLS-1$
+ private final String userName;
- private String password = ""; //$NON-NLS-1$
+ private final String password;
public AuthenticatedProxy(Type type, SocketAddress sa, String userName, String password) {
super(type, sa);
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java
new file mode 100644
index 0000000..c3704de
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/NetUtil.java
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.core.net;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.Proxy.Type;
+import java.net.ProxySelector;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.List;
+
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.commons.core.operations.ICancellable;
+import org.eclipse.mylyn.commons.core.operations.MonitoredOperation;
+import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin;
+
+/**
+ * Provides network access related utility methods.
+ *
+ * @since 3.7
+ * @author Steffen Pingel
+ */
+public class NetUtil {
+
+ public static final int HTTPS_PORT = 443;
+
+ private static final int HTTP_PORT = 80;
+
+ /**
+ * Invokes {@link Socket#connect(java.net.SocketAddress, int)} on <code>socket</code> to connect to
+ * <code>address</code>.
+ * <p>
+ * If an operation is provided a cancellation listener is attached that aborts the connect in case the operation is
+ * aborted while connecting.
+ *
+ * @param socket
+ * the socket
+ * @param address
+ * the address to connect to
+ * @param timeout
+ * the connect timeout
+ * @param operation
+ * the current operation or null
+ * @throws IOException
+ * @see {@link Socket#connect(java.net.SocketAddress, int)}
+ */
+ public static void connect(final Socket socket, InetSocketAddress address, int timeout,
+ MonitoredOperation<?> operation) throws IOException {
+ if (operation != null) {
+ ICancellable listener = new ICancellable() {
+ public void abort() {
+ try {
+ socket.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ };
+ try {
+ operation.addListener(listener);
+ socket.connect(address, timeout);
+ } finally {
+ operation.removeListener(listener);
+ }
+ } else {
+ socket.connect(address, timeout);
+ }
+ }
+
+ public static Proxy createProxy(String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) {
+ if (proxyHost != null && proxyHost.length() > 0) {
+ InetSocketAddress sockAddr = new InetSocketAddress(proxyHost, proxyPort);
+ boolean authenticated = (proxyUsername != null && proxyPassword != null && proxyUsername.length() > 0 && proxyPassword.length() > 0);
+ if (authenticated) {
+ return new AuthenticatedProxy(Type.HTTP, sockAddr, proxyUsername, proxyPassword);
+ } else {
+ return new Proxy(Type.HTTP, sockAddr);
+ }
+ }
+ return Proxy.NO_PROXY;
+ }
+
+ /**
+ * Returns the host portion of <code>url</code>.
+ *
+ * @return the host portion of <code>url</code>; empty string, if url is not valid
+ * @since 3.7
+ */
+ public static String getHost(String url) {
+ Assert.isNotNull(url);
+
+ String result = url;
+ int colonSlashSlash = url.indexOf("://"); //$NON-NLS-1$
+
+ if (colonSlashSlash >= 0) {
+ result = url.substring(colonSlashSlash + 3);
+ }
+
+ int colonPort = result.indexOf(':');
+ int requestPath = result.indexOf('/');
+
+ int substringEnd;
+
+ // minimum positive, or string length
+ if (colonPort > 0 && requestPath > 0) {
+ substringEnd = Math.min(colonPort, requestPath);
+ } else if (colonPort > 0) {
+ substringEnd = colonPort;
+ } else if (requestPath > 0) {
+ substringEnd = requestPath;
+ } else {
+ substringEnd = result.length();
+ }
+
+ return result.substring(0, substringEnd);
+ }
+
+ /**
+ * Returns the connection port for <code>url</code>. If no port is specified, 443 is returned for URLs that use the
+ * https protocol; otherwise, 80 is returned.
+ *
+ * @return the port portion of <code>url</code>
+ * @throws NumberFormatException
+ * if the port is not a parseable integer
+ * @since 3.7
+ */
+ public static int getPort(String url) {
+ Assert.isNotNull(url);
+
+ int colonSlashSlash = url.indexOf("://"); //$NON-NLS-1$
+ int firstSlash = url.indexOf("/", colonSlashSlash + 3); //$NON-NLS-1$
+ int colonPort = url.indexOf(':', colonSlashSlash + 1);
+ if (firstSlash == -1) {
+ firstSlash = url.length();
+ }
+ if (colonPort < 0 || colonPort > firstSlash) {
+ return isUrlHttps(url) ? HTTPS_PORT : HTTP_PORT;
+ }
+
+ int requestPath = url.indexOf('/', colonPort + 1);
+ int end = requestPath < 0 ? url.length() : requestPath;
+ String port = url.substring(colonPort + 1, end);
+ if (port.length() == 0) {
+ return isUrlHttps(url) ? HTTPS_PORT : HTTP_PORT;
+ }
+
+ return Integer.parseInt(port);
+ }
+
+ public static Proxy getProxy(String host, Proxy.Type proxyType) {
+ Assert.isNotNull(host);
+ Assert.isNotNull(proxyType);
+ return getProxy(host, getPlatformProxyType(proxyType));
+ }
+
+ @SuppressWarnings("deprecation")
+ public static Proxy getProxy(String host, String proxyType) {
+ Assert.isNotNull(host);
+ Assert.isNotNull(proxyType);
+ IProxyService service = CommonsCorePlugin.getProxyService();
+ if (service != null && service.isProxiesEnabled()) {
+ // TODO e3.5 move to new proxy API
+ IProxyData data = service.getProxyDataForHost(host, proxyType);
+ if (data != null && data.getHost() != null) {
+ String proxyHost = data.getHost();
+ int proxyPort = data.getPort();
+ // change the IProxyData default port to the Java default port
+ if (proxyPort == -1) {
+ proxyPort = 0;
+ }
+ return createProxy(proxyHost, proxyPort, data.getUserId(), data.getPassword());
+ }
+ } else {
+ try {
+ // fall back to JDK proxy selector
+ URI uri = new URI(proxyType, "//" + host, null); //$NON-NLS-1$
+ List<Proxy> proxies = ProxySelector.getDefault().select(uri);
+ if (proxies != null && proxies.size() > 0) {
+ Proxy proxy = proxies.iterator().next();
+ if (proxy != Proxy.NO_PROXY) {
+ return proxy;
+ }
+ }
+ } catch (URISyntaxException e) {
+ // ignore
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the platform default proxy for <code>url</code> or <code>null</code> if none.
+ */
+ public static Proxy getProxyForUrl(String url) {
+ String host = getHost(url);
+ Proxy proxy;
+ if (isUrlHttps(url)) {
+ proxy = getProxy(host, IProxyData.HTTPS_PROXY_TYPE);
+ } else {
+ proxy = getProxy(host, IProxyData.HTTP_PROXY_TYPE);
+ }
+ return proxy;
+ }
+
+ /**
+ * Returns the request path part of <code>url</code>.
+ *
+ * @return the request path portion of <code>url</code>; empty string, if url is not valid or not path is specified
+ * @since 3.7
+ */
+ public static String getRequestPath(String url) {
+ int colonSlashSlash = url.indexOf("://"); //$NON-NLS-1$
+ int requestPath = url.indexOf('/', colonSlashSlash + 3);
+
+ if (requestPath < 0) {
+ return ""; //$NON-NLS-1$
+ } else {
+ return url.substring(requestPath);
+ }
+ }
+
+ /**
+ * Returns true if <code>url</code> uses https as the protocol.
+ *
+ * @since 3.7
+ */
+ public static boolean isUrlHttps(String url) {
+ return url.matches("https.*"); //$NON-NLS-1$
+ }
+
+ private static String getPlatformProxyType(Type type) {
+ return type == Type.SOCKS ? IProxyData.SOCKS_PROXY_TYPE : IProxyData.HTTP_PROXY_TYPE;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/ProxyProvider.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/ProxyProvider.java
new file mode 100644
index 0000000..5d2437f
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/ProxyProvider.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.core.net;
+
+import java.net.Proxy;
+
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.net.proxy.IProxyService;
+
+/**
+ * Provides proxy information.
+ *
+ * @author Steffen Pingel
+ * @since 3.7
+ * @see AuthenticatedProxy
+ * @see NetUtil
+ */
+public abstract class ProxyProvider {
+
+ /**
+ * Returns the proxy for <code>host</code>. The type of proxy is specified by <code>proxyType</code>, see
+ * {@link IProxyData} for possible values.
+ *
+ * @param host
+ * the host to route to
+ * @param proxyType
+ * the proxy type
+ * @return a proxy or {@link Proxy#NO_PROXY} or <code>null</code>
+ * @see IProxyService#getProxyDataForHost(String, String)
+ * @see IProxyData
+ */
+ public abstract Proxy getProxyForHost(String host, String proxyType);
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TrustAllTrustManager.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/TrustAllTrustManager.java
index de55cd2..6085f21 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/TrustAllTrustManager.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/net/TrustAllTrustManager.java
@@ -10,7 +10,7 @@
* Eugene Kuleshov - improvements
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.net;
import javax.net.ssl.X509TrustManager;
@@ -18,6 +18,7 @@ import javax.net.ssl.X509TrustManager;
* TrustAll class implements X509TrustManager to access all https servers with signed and unsigned certificates.
*
* @author Mik Kersten
+ * @since 3.7
*/
public class TrustAllTrustManager implements X509TrustManager {
@@ -32,4 +33,5 @@ public class TrustAllTrustManager implements X509TrustManager {
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) {
// don't need to do any checks
}
+
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ICancellable.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/ICancellable.java
index 5a3b685..d96db88 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/ICancellable.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/ICancellable.java
@@ -9,13 +9,21 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.operations;
/**
+ * Intended to be implemented by cancellable operations.
+ *
* @author Steffen Pingel
+ * @since 3.7
*/
public interface ICancellable {
+ /**
+ * Invoked on cancellation.
+ *
+ * @since 3.7
+ */
public abstract void abort();
}
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/IOperationMonitor.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/IOperationMonitor.java
new file mode 100644
index 0000000..2b869a2
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/IOperationMonitor.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.core.operations;
+
+import org.eclipse.core.runtime.IProgressMonitorWithBlocking;
+
+/**
+ * @author Steffen Pingel
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ * @since 3.7
+ */
+public interface IOperationMonitor extends IProgressMonitorWithBlocking {
+
+ public enum OperationFlag {
+ BACKGROUND
+ };
+
+ public abstract void addFlag(OperationFlag flag);
+
+ public abstract boolean hasFlag(OperationFlag flag);
+
+ public abstract IOperationMonitor newChild(int totalWork);
+
+ public abstract IOperationMonitor newChild(int totalWork, int suppressFlags);
+
+ public void removeFlag(OperationFlag flag);
+
+ public abstract IOperationMonitor setWorkRemaining(int workRemaining);
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/MonitoredRequest.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/MonitoredOperation.java
index 854de86..1d57401 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/MonitoredRequest.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/MonitoredOperation.java
@@ -9,54 +9,57 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.core.operations;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.Socket;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.mylyn.commons.http.WebRequest;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin;
+import org.eclipse.osgi.util.NLS;
/**
+ * Intended to be implemented by high-level operation that run on a single thread.
+ *
* @author Steffen Pingel
+ * @since 3.7
+ * @see OperationUtil#execute(IProgressMonitor, Operation)
*/
-public abstract class MonitoredRequest<T> extends WebRequest<T> implements ICancellable {
+public abstract class MonitoredOperation<T> extends Operation<T> implements ICancellable {
- private static ThreadLocal<MonitoredRequest<?>> currentRequest = new ThreadLocal<MonitoredRequest<?>>();
+ private static ThreadLocal<MonitoredOperation<?>> currentOperation = new ThreadLocal<MonitoredOperation<?>>();
- public static MonitoredRequest<?> getCurrentRequest() {
- return currentRequest.get();
+ /**
+ * Returns the operation that is associated with the current thread.
+ */
+ public static MonitoredOperation<?> getCurrentOperation() {
+ return currentOperation.get();
}
- public static void setCurrentRequest(MonitoredRequest<?> request) {
- currentRequest.set(request);
+ /**
+ * Sets <code>operation</code> as the operation associated with the current thread.
+ */
+ static void setCurrentOperation(MonitoredOperation<?> operation) {
+ if (operation != null && currentOperation.get() != null) {
+ StatusHandler.log(new Status(IStatus.ERROR, CommonsCorePlugin.ID_PLUGIN, NLS.bind(
+ "Unexpected operation already in progress ''{0}''", currentOperation.get()), //$NON-NLS-1$
+ new IllegalStateException()));
+ }
+ currentOperation.set(operation);
}
private final CopyOnWriteArrayList<ICancellable> listeners = new CopyOnWriteArrayList<ICancellable>();
private final IProgressMonitor monitor;
- public MonitoredRequest(IProgressMonitor monitor) {
+ public MonitoredOperation(IProgressMonitor monitor) {
Assert.isNotNull(monitor);
this.monitor = monitor;
}
- public T call() throws Exception {
- try {
- assert MonitoredRequest.getCurrentRequest() == null;
- MonitoredRequest.setCurrentRequest(this);
- return execute();
- } finally {
- MonitoredRequest.setCurrentRequest(null);
- listeners.clear();
- }
- }
-
- protected abstract T execute() throws Exception;
-
@Override
public void abort() {
for (ICancellable listener : listeners.toArray(new ICancellable[0])) {
@@ -72,6 +75,17 @@ public abstract class MonitoredRequest<T> extends WebRequest<T> implements ICanc
listeners.add(listener);
}
+ public T call() throws Exception {
+ try {
+ assert MonitoredOperation.getCurrentOperation() == null;
+ MonitoredOperation.setCurrentOperation(this);
+ return execute();
+ } finally {
+ MonitoredOperation.setCurrentOperation(null);
+ listeners.clear();
+ }
+ }
+
public IProgressMonitor getMonitor() {
return monitor;
}
@@ -80,27 +94,6 @@ public abstract class MonitoredRequest<T> extends WebRequest<T> implements ICanc
listeners.remove(listener);
}
- public static void connect(final Socket socket, InetSocketAddress address, int timeout) throws IOException {
- MonitoredRequest<?> request = MonitoredRequest.getCurrentRequest();
- if (request != null) {
- ICancellable listener = new ICancellable() {
- public void abort() {
- try {
- socket.close();
- } catch (IOException e) {
- // ignore
- }
- }
- };
- try {
- request.addListener(listener);
- socket.connect(address, timeout);
- } finally {
- request.removeListener(listener);
- }
- } else {
- socket.connect(address, timeout);
- }
- }
+ protected abstract T execute() throws Exception;
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebRequest.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/Operation.java
index 27b39d4..c8fe0e6 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebRequest.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/Operation.java
@@ -9,18 +9,22 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.commons.http;
+package org.eclipse.mylyn.commons.core.operations;
import java.util.concurrent.Callable;
/**
+ * A callable that is notified on cancellation.
+ *
* @author Steffen Pingel
- * @since 3.6
+ * @since 3.7
*/
-public abstract class WebRequest<T> implements Callable<T> {
+public abstract class Operation<T> implements Callable<T>, ICancellable {
/**
- * @since 3.6
+ * Invoked when the operation is cancelled.
+ *
+ * @since 3.7
*/
public abstract void abort();
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java
new file mode 100644
index 0000000..c9bafb2
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/operations/OperationUtil.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.core.operations;
+
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin;
+import org.eclipse.mylyn.internal.commons.core.operations.NullOperationMonitor;
+import org.eclipse.mylyn.internal.commons.core.operations.OperationMonitor;
+
+/**
+ * @author Steffen Pingel
+ * @since 3.7
+ */
+public class OperationUtil {
+
+ private static final int POLL_INTERVAL = 500;
+
+ public static IOperationMonitor convert(IProgressMonitor monitor) {
+ return convert(monitor, "", 0); //$NON-NLS-1$
+ }
+
+ public static IOperationMonitor convert(IProgressMonitor monitor, int work) {
+ return convert(monitor, "", work); //$NON-NLS-1$
+ }
+
+ public static IOperationMonitor convert(IProgressMonitor monitor, String taskName, int work) {
+ if (monitor instanceof IOperationMonitor) {
+ return (IOperationMonitor) monitor;
+ }
+ if (monitor == null) {
+ return new NullOperationMonitor();
+ }
+ return new OperationMonitor(null, monitor, taskName, work);
+ }
+
+ /**
+ * @since 3.7
+ */
+ public static synchronized ExecutorService getExecutorService() {
+ return CommonsCorePlugin.getExecutorService();
+ }
+
+ /**
+ * @since 3.7
+ */
+ public static <T> T execute(IProgressMonitor monitor, Operation<T> request) throws Throwable {
+ // check for legacy reasons
+ SubMonitor subMonitor = (monitor instanceof SubMonitor) ? (SubMonitor) monitor : SubMonitor.convert(null);
+
+ Future<T> future = getExecutorService().submit(request);
+ while (true) {
+ if (monitor.isCanceled()) {
+ request.abort();
+
+ // wait for executor to finish
+ future.cancel(false);
+ try {
+ if (!future.isCancelled()) {
+ future.get();
+ }
+ } catch (CancellationException e) {
+ // ignore
+ } catch (InterruptedException e) {
+ // ignore
+ } catch (ExecutionException e) {
+ // ignore
+ }
+ throw new OperationCanceledException();
+ }
+
+ try {
+ return future.get(POLL_INTERVAL, TimeUnit.MILLISECONDS);
+ } catch (ExecutionException e) {
+ throw e.getCause();
+ } catch (TimeoutException ignored) {
+ }
+
+ subMonitor.setWorkRemaining(20);
+ subMonitor.worked(1);
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/CommonsHttpPlugin.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/CommonsCorePlugin.java
index ac1c3d7..ee97099 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/CommonsHttpPlugin.java
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/CommonsCorePlugin.java
@@ -10,7 +10,7 @@
* Michael Valenta - improvements
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.internal.commons.core;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
@@ -18,23 +18,21 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.eclipse.core.net.proxy.IProxyService;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
/**
- * Provides an entry point for the proxy service and potentially other web facilities
+ * Tracks core services that are bound to the bundle life-cycle.
*
* @author Mik Kersten
* @author Steffen Pingel
*/
-public class CommonsHttpPlugin extends Plugin {
+public class CommonsCorePlugin extends Plugin {
- public static final String ID_PLUGIN = "org.eclipse.mylyn.commons.http"; //$NON-NLS-1$
+ public static final String ID_PLUGIN = "org.eclipse.mylyn.commons.core"; //$NON-NLS-1$
- private static CommonsHttpPlugin INSTANCE;
+ private static CommonsCorePlugin INSTANCE;
private static final int MAX_CONCURRENT_REQUESTS = 100;
@@ -42,7 +40,7 @@ public class CommonsHttpPlugin extends Plugin {
private static ExecutorService service;
- public static CommonsHttpPlugin getDefault() {
+ public static CommonsCorePlugin getDefault() {
return INSTANCE;
}
@@ -68,22 +66,18 @@ public class CommonsHttpPlugin extends Plugin {
return proxyService;
}
- public static void log(int error, String message, Throwable e) {
- if (getDefault() != null) {
- getDefault().getLog().log(new Status(IStatus.ERROR, ID_PLUGIN, error, message, e));
- }
- }
-
public synchronized static void setProxyService(IProxyService proxyService) {
- CommonsHttpPlugin.proxyService = proxyService;
+ CommonsCorePlugin.proxyService = proxyService;
}
+ @SuppressWarnings("rawtypes")
private ServiceTracker tracker;
- public CommonsHttpPlugin() {
+ public CommonsCorePlugin() {
INSTANCE = this;
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/NullOperationMonitor.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/NullOperationMonitor.java
new file mode 100644
index 0000000..98bea67
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/NullOperationMonitor.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.core.operations;
+
+import java.util.EnumSet;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+
+public class NullOperationMonitor extends NullProgressMonitor implements IOperationMonitor {
+
+ private EnumSet<OperationFlag> flags;
+
+ public synchronized void addFlag(OperationFlag flag) {
+ if (flags == null) {
+ flags = EnumSet.of(flag);
+ } else {
+ flags.add(flag);
+ }
+ }
+
+ public void clearBlocked() {
+ // ignore
+ }
+
+ public synchronized boolean hasFlag(OperationFlag flag) {
+ if (flags != null) {
+ return flags.contains(flag);
+ }
+ return false;
+ }
+
+ public IOperationMonitor newChild(int totalWork) {
+ return this;
+ }
+
+ public IOperationMonitor newChild(int totalWork, int suppressFlags) {
+ return this;
+ }
+
+ public synchronized void removeFlag(OperationFlag flag) {
+ if (flags != null) {
+ flags.remove(flag);
+ }
+ }
+
+ public void setBlocked(IStatus reason) {
+ // ignore
+ }
+
+ public IOperationMonitor setWorkRemaining(int workRemaining) {
+ return this;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/OperationMonitor.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/OperationMonitor.java
new file mode 100644
index 0000000..f900ec9
--- /dev/null
+++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/internal/commons/core/operations/OperationMonitor.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.core.operations;
+
+import java.util.EnumSet;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+
+public class OperationMonitor implements IOperationMonitor {
+
+ private EnumSet<OperationFlag> flags;
+
+ private final SubMonitor monitor;
+
+ private final IOperationMonitor root;
+
+ public OperationMonitor(IOperationMonitor root, IProgressMonitor monitor) {
+ this.root = root;
+ this.monitor = SubMonitor.convert(monitor);
+ }
+
+ public OperationMonitor(IOperationMonitor root, IProgressMonitor monitor, String taskName, int work) {
+ this.root = root;
+ this.monitor = SubMonitor.convert(monitor, taskName, work);
+ }
+
+ public synchronized void addFlag(OperationFlag flag) {
+ if (root != null) {
+ root.addFlag(flag);
+ } else if (flags == null) {
+ flags = EnumSet.of(flag);
+ } else {
+ flags.add(flag);
+ }
+ }
+
+ public void beginTask(String name, int totalWork) {
+ monitor.beginTask(name, totalWork);
+ }
+
+ public void clearBlocked() {
+ monitor.clearBlocked();
+ }
+
+ public void done() {
+ monitor.done();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return monitor.equals(obj);
+ }
+
+ public synchronized boolean hasFlag(OperationFlag flag) {
+ if (root != null) {
+ return root.hasFlag(flag);
+ } else if (flags != null) {
+ return flags.contains(flag);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return monitor.hashCode();
+ }
+
+ public void internalWorked(double work) {
+ monitor.internalWorked(work);
+ }
+
+ public boolean isCanceled() {
+ return monitor.isCanceled();
+ }
+
+ public IOperationMonitor newChild(int totalWork) {
+ return new OperationMonitor((root == null) ? this : root, monitor.newChild(totalWork));
+ }
+
+ public IOperationMonitor newChild(int totalWork, int suppressFlags) {
+ return new OperationMonitor((root == null) ? this : root, monitor.newChild(totalWork, suppressFlags));
+ }
+
+ public synchronized void removeFlag(OperationFlag flag) {
+ if (root != null) {
+ root.removeFlag(flag);
+ } else if (flags != null) {
+ flags.remove(flag);
+ }
+ }
+
+ public void setBlocked(IStatus reason) {
+ monitor.setBlocked(reason);
+ }
+
+ public void setCanceled(boolean b) {
+ monitor.setCanceled(b);
+ }
+
+ public void setTaskName(String name) {
+ monitor.setTaskName(name);
+ }
+
+ public IOperationMonitor setWorkRemaining(int workRemaining) {
+ monitor.setWorkRemaining(workRemaining);
+ return this;
+ }
+
+ public void subTask(String name) {
+ monitor.subTask(name);
+ }
+
+ @Override
+ public String toString() {
+ return monitor.toString();
+ }
+
+ public void worked(int work) {
+ monitor.worked(work);
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF
index fea26b2..4e3d164 100644
--- a/org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.net/META-INF/MANIFEST.MF
@@ -10,10 +10,13 @@ Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0";visibility:=reex
org.apache.commons.httpclient;bundle-version="3.1.0";visibility:=reexport,
org.apache.commons.lang;bundle-version="2.3.0";visibility:=reexport,
org.eclipse.core.runtime,
- org.eclipse.core.net
+ org.eclipse.core.net,
+ org.eclipse.mylyn.commons.core
Bundle-ClassPath: .
Export-Package: org.eclipse.mylyn.commons.net,
- org.eclipse.mylyn.internal.commons.net;x-internal:=true
+ org.eclipse.mylyn.commons.net.http,
+ org.eclipse.mylyn.internal.commons.net;x-internal:=true,
+ org.eclipse.mylyn.internal.commons.net.http;x-internal:=true
Bundle-Activator: org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin
Bundle-Localization: plugin
Import-Package: org.apache.commons.logging;version="[1.0.4,2.0.0)"
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java
index 8698020..62f20d0 100644
--- a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/WebUtil.java
@@ -61,6 +61,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.Token;
import org.eclipse.mylyn.internal.commons.net.AuthenticatedProxy;
import org.eclipse.mylyn.internal.commons.net.CloneableHostConfiguration;
@@ -80,20 +81,6 @@ import org.eclipse.mylyn.internal.commons.net.TimeoutInputStream;
*/
public class WebUtil {
- // FIXME remove this again
- private static final boolean TEST_MODE;
-
- static {
- String application = System.getProperty("eclipse.application", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (application.length() > 0) {
- TEST_MODE = application.endsWith("testapplication"); //$NON-NLS-1$
- } else {
- // eclipse 3.3 does not the eclipse.application property
- String commands = System.getProperty("eclipse.commands", ""); //$NON-NLS-1$ //$NON-NLS-2$
- TEST_MODE = commands.contains("testapplication\n"); //$NON-NLS-1$
- }
- }
-
/**
* like Mylyn/2.1.0 (Rally Connector 1.0) Eclipse/3.3.0 (JBuilder 2007) HttpClient/3.0.1 Java/1.5.0_11 (Sun)
* Linux/2.6.20-16-lowlatency (i386; en)
@@ -211,7 +198,7 @@ public class WebUtil {
client.getHttpConnectionManager().getParams().setSoTimeout(WebUtil.SOCKET_TIMEOUT);
client.getHttpConnectionManager().getParams().setConnectionTimeout(WebUtil.CONNNECT_TIMEOUT);
// FIXME fix connection leaks
- if (TEST_MODE) {
+ if (CoreUtil.TEST_MODE) {
client.getHttpConnectionManager()
.getParams()
.setMaxConnectionsPerHost(HostConfiguration.ANY_HOST_CONFIGURATION, 2);
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpClient3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpClient3.java
new file mode 100644
index 0000000..5e36264
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpClient3.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.net.http;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.auth.DigestScheme;
+import org.apache.commons.httpclient.cookie.CookiePolicy;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+import org.eclipse.mylyn.commons.net.AbstractWebLocation;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.commons.net.UnsupportedRequestException;
+import org.eclipse.mylyn.commons.net.WebUtil;
+
+/**
+ * Facilitates connections to repositories accessed through Http.
+ *
+ * @author Steffen Pingel
+ * @since 3.7
+ */
+public class CommonHttpClient3 {
+
+ static final boolean DEBUG_AUTH = Boolean.valueOf(Platform.getDebugOption("org.eclipse.mylyn.commons.http/debug/authentication")); //$NON-NLS-1$
+
+ private static final String DEFAULT_USER_AGENT = "Apache XML-RPC/3.0"; //$NON-NLS-1$
+
+ private static HttpClient createHttpClient(String userAgent) {
+ HttpClient httpClient = new HttpClient();
+ httpClient.setHttpConnectionManager(WebUtil.getConnectionManager());
+ httpClient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
+ WebUtil.configureHttpClient(httpClient, userAgent);
+ return httpClient;
+ }
+
+ volatile DigestScheme digestScheme;
+
+ final HttpClient httpClient;
+
+ private final AbstractWebLocation location;
+
+ public CommonHttpClient3(AbstractWebLocation location) {
+ this(location, createHttpClient(DEFAULT_USER_AGENT));
+ }
+
+ public CommonHttpClient3(AbstractWebLocation location, HttpClient client) {
+ this.location = location;
+ this.httpClient = createHttpClient(DEFAULT_USER_AGENT);
+ }
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public AbstractWebLocation getLocation() {
+ return location;
+ }
+
+ public int execute(HttpMethodBase method, IOperationMonitor monitor) throws IOException {
+ HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(getHttpClient(), location, monitor);
+ return WebUtil.execute(getHttpClient(), hostConfiguration, method, monitor);
+ }
+
+ public synchronized HostConfiguration getHostConfiguration(IOperationMonitor monitor) throws IOException {
+ if (location.getUrl() == null) {
+ throw new IOException("No URL specified.");
+ }
+ return WebUtil.createHostConfiguration(httpClient, location, monitor);
+ }
+
+ protected void authenticate(IOperationMonitor monitor) throws IOException {
+
+ }
+
+ protected boolean needsReauthentication(int code, IProgressMonitor monitor) throws IOException {
+ final AuthenticationType authenticationType;
+ if (code == HttpStatus.SC_UNAUTHORIZED || code == HttpStatus.SC_FORBIDDEN) {
+ authenticationType = AuthenticationType.HTTP;
+ } else if (code == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
+ authenticationType = AuthenticationType.PROXY;
+ } else {
+ return false;
+ }
+
+ try {
+ location.requestCredentials(authenticationType, null, monitor);
+ } catch (UnsupportedRequestException e) {
+ IOException ioe = new IOException(HttpStatus.getStatusText(code));
+ ioe.initCause(e);
+ throw ioe;
+ } catch (UnsupportedOperationException e) {
+ IOException ioe = new IOException(HttpStatus.getStatusText(code));
+ ioe.initCause(e);
+ throw ioe;
+ }
+
+ return true;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpMethod3.java
new file mode 100644
index 0000000..42bb98a
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/CommonHttpMethod3.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.net.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.HttpMethod;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Steffen Pingel
+ * @since 3.7
+ */
+public interface CommonHttpMethod3 extends HttpMethod {
+
+ public static final String CONTENT_ENCODING = "Content-Encoding"; //$NON-NLS-1$
+
+ public static final String ACCEPT_ENCODING = "Accept-encoding"; //$NON-NLS-1$
+
+ public static final String CONTENT_ENCODING_GZIP = "gzip"; //$NON-NLS-1$
+
+ public abstract String getResponseCharSet();
+
+ public abstract InputStream getResponseBodyAsStream(IProgressMonitor monitor) throws IOException;
+
+ public abstract void releaseConnection(IProgressMonitor monitor);
+
+}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/HttpOperation3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/HttpOperation3.java
new file mode 100644
index 0000000..20d475e
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/commons/net/http/HttpOperation3.java
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ * Eike Stepper - fixes for bug 323568
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.net.http;
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+import org.eclipse.mylyn.commons.core.operations.OperationUtil;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.internal.commons.net.http.CommonGetMethod3;
+import org.eclipse.mylyn.internal.commons.net.http.CommonHeadMethod3;
+import org.eclipse.mylyn.internal.commons.net.http.CommonPostMethod3;
+
+/**
+ * @author Steffen Pingel
+ * @since 3.7
+ */
+public abstract class HttpOperation3<T> {
+
+ private final CommonHttpClient3 client;
+
+ public HttpOperation3(CommonHttpClient3 client) {
+ this.client = client;
+ }
+
+ protected CommonHttpMethod3 createGetMethod(String requestPath) {
+ return new CommonGetMethod3(requestPath);
+ }
+
+ protected CommonHttpMethod3 createPostMethod(String requestPath) {
+ return new CommonPostMethod3(requestPath);
+ }
+
+ protected CommonHttpMethod3 createHeadMethod(String requestPath) {
+ return new CommonHeadMethod3(requestPath);
+ }
+
+ protected int execute(HttpMethod method, IOperationMonitor monitor) throws IOException {
+ monitor = OperationUtil.convert(monitor);
+
+ // force authentication
+ if (needsAuthentication()) {
+ client.authenticate(monitor);
+ }
+
+ // first attempt
+ int code = executeInternal(method, monitor);
+ if (needsReauthentication(code, monitor)) {
+ WebUtil.releaseConnection((HttpMethodBase) method, monitor);
+ client.authenticate(monitor);
+
+ // second attempt
+ return executeInternal(method, monitor);
+ } else {
+ return code;
+ }
+ }
+
+ private int executeInternal(HttpMethod method, IOperationMonitor monitor) throws IOException {
+ int code;
+ try {
+ code = WebUtil.execute(client.getHttpClient(), client.getHostConfiguration(monitor), method, monitor);
+ } catch (IOException e) {
+ WebUtil.releaseConnection((HttpMethodBase) method, monitor);
+ throw e;
+ } catch (RuntimeException e) {
+ WebUtil.releaseConnection((HttpMethodBase) method, monitor);
+ throw e;
+ }
+ return code;
+ }
+
+ protected final CommonHttpClient3 getClient() {
+ return client;
+ }
+
+ protected boolean hasCredentials(AuthenticationCredentials credentials) {
+ return credentials != null;
+ }
+
+ protected boolean needsAuthentication() {
+ return false;
+ }
+
+ private boolean needsReauthentication(int code, IOperationMonitor monitor) throws IOException {
+ return client.needsReauthentication(code, monitor);
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/CommonsNetPlugin.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/CommonsNetPlugin.java
index ed96e27..eb1db2e 100644
--- a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/CommonsNetPlugin.java
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/CommonsNetPlugin.java
@@ -13,14 +13,12 @@
package org.eclipse.mylyn.internal.commons.net;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.SynchronousQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.internal.commons.core.CommonsCorePlugin;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -37,22 +35,12 @@ public class CommonsNetPlugin extends Plugin {
private static CommonsNetPlugin INSTANCE;
- private static final int MAX_CONCURRENT_REQUESTS = 100;
-
- private static IProxyService proxyService;
-
- private static ExecutorService service;
-
public static CommonsNetPlugin getDefault() {
return INSTANCE;
}
public static synchronized ExecutorService getExecutorService() {
- if (service == null) {
- service = new ThreadPoolExecutor(1, MAX_CONCURRENT_REQUESTS, 10L, TimeUnit.SECONDS,
- new SynchronousQueue<Runnable>());
- }
- return service;
+ return CommonsCorePlugin.getExecutorService();
}
/**
@@ -61,12 +49,7 @@ public class CommonsNetPlugin extends Plugin {
* @return the {@link IProxyService} or <code>null</code>
*/
public synchronized static IProxyService getProxyService() {
- if (proxyService == null) {
- if (INSTANCE != null && INSTANCE.tracker != null) {
- return (IProxyService) INSTANCE.tracker.getService();
- }
- }
- return proxyService;
+ return CommonsCorePlugin.getProxyService();
}
public static void log(int error, String message, Throwable e) {
@@ -76,7 +59,7 @@ public class CommonsNetPlugin extends Plugin {
}
public synchronized static void setProxyService(IProxyService proxyService) {
- CommonsNetPlugin.proxyService = proxyService;
+ CommonsCorePlugin.setProxyService(proxyService);
}
@SuppressWarnings("rawtypes")
@@ -90,18 +73,10 @@ public class CommonsNetPlugin extends Plugin {
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
- tracker = new ServiceTracker(getBundle().getBundleContext(), IProxyService.class.getName(), null);
- tracker.open();
}
@Override
public void stop(BundleContext context) throws Exception {
- tracker.close();
- tracker = null;
- if (service != null) {
- service.shutdown();
- service = null;
- }
super.stop(context);
}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java
new file mode 100644
index 0000000..091ea36
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 Composent, Inc., IBM 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:
+ * Composent, Inc. - initial API and implementation
+ * Maarten Meijer - bug 237936, added gzip encoded transfer default
+ * Henrich Kraemer - bug 263869, testHttpsReceiveFile fails using HTTP proxy
+ * Henrich Kraemer - bug 263613, [transport] Update site contacting / downloading is not cancelable
+ * Tasktop Technologies - cancellation support for streams
+ ******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.net.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
+
+/**
+ * Based on {@code org.eclipse.ecf.provider.filetransfer.httpclient.HttpClientRetrieveFileTransfer}.
+ *
+ * @author Steffen Pingel
+ */
+public class CommonGetMethod3 extends GetMethod implements CommonHttpMethod3 {
+
+ private boolean gzipAccepted;
+
+ private boolean gzipReceived;
+
+ private InputStream inputStream;
+
+ private final Object releaseLock = new Object();
+
+ public CommonGetMethod3() {
+ init();
+ }
+
+ public CommonGetMethod3(String requestPath) {
+ super(requestPath);
+ init();
+ }
+
+ @Override
+ public int execute(HttpState state, HttpConnection conn) throws HttpException, IOException {
+ if (gzipAccepted) {
+ this.setRequestHeader("Accept-encoding", CONTENT_ENCODING_GZIP); //$NON-NLS-1$
+ }
+ return super.execute(state, conn);
+ }
+
+ public InputStream getResponseBodyAsStream(IProgressMonitor monitor) throws IOException {
+ if (inputStream == null) {
+ inputStream = WebUtil.getResponseBodyAsStream(this, monitor);
+ }
+ gzipReceived = isZippedResponse();
+ if (gzipReceived) {
+ inputStream = new GZIPInputStream(inputStream);
+ }
+ return inputStream;
+ }
+
+ private void init() {
+ gzipAccepted = true;
+ }
+
+ public final boolean isGzipAccepted() {
+ return gzipAccepted;
+ }
+
+ private boolean isZippedResponse() {
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=269018
+ return this.getResponseHeader(CONTENT_ENCODING) != null
+ && this.getResponseHeader(CONTENT_ENCODING).getValue().equals(CONTENT_ENCODING_GZIP);
+ }
+
+ // This override is a workaround for
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279457
+ // This makes GetMethod.releaseConnection non-reentrant,
+ // as with reentrancy under some circumstances a NPE can be
+ // thrown with multithreaded access
+ @Override
+ public void releaseConnection() {
+ synchronized (releaseLock) {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ inputStream = null;
+ }
+ super.releaseConnection();
+ }
+ }
+
+ public void releaseConnection(IProgressMonitor monitor) {
+ if (monitor != null && monitor.isCanceled()) {
+ // force a connection close on cancel to avoid blocking to do reading the remainder of the response
+ abort();
+ } else {
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
+ }
+ }
+ }
+
+ @Override
+ protected void responseBodyConsumed() {
+ // ensure worker is released to pool
+ super.responseBodyConsumed();
+ }
+
+ public final void setGzipAccepted(boolean gzipAccepted) {
+ this.gzipAccepted = gzipAccepted;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java
new file mode 100644
index 0000000..385d6ab
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 Composent, Inc., IBM 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:
+ * Composent, Inc. - initial API and implementation
+ * Maarten Meijer - bug 237936, added gzip encoded transfer default
+ * Henrich Kraemer - bug 263869, testHttpsReceiveFile fails using HTTP proxy
+ * Henrich Kraemer - bug 263613, [transport] Update site contacting / downloading is not cancelable
+ * Tasktop Technologies - cancellation support for streams
+ ******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.net.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
+
+/**
+ * Based on {@code org.eclipse.ecf.provider.filetransfer.httpclient.HttpClientRetrieveFileTransfer}.
+ *
+ * @author Steffen Pingel
+ */
+public class CommonHeadMethod3 extends HeadMethod implements CommonHttpMethod3 {
+
+ private boolean gzipAccepted;
+
+ private final Object releaseLock = new Object();
+
+ public CommonHeadMethod3() {
+ init();
+ }
+
+ public CommonHeadMethod3(String requestPath) {
+ super(requestPath);
+ init();
+ }
+
+ @Override
+ public int execute(HttpState state, HttpConnection conn) throws HttpException, IOException {
+ if (gzipAccepted) {
+ this.setRequestHeader("Accept-encoding", CONTENT_ENCODING_GZIP); //$NON-NLS-1$
+ }
+ return super.execute(state, conn);
+ }
+
+ public InputStream getResponseBodyAsStream(IProgressMonitor monitor) throws IOException {
+ return null;
+ }
+
+ private void init() {
+ gzipAccepted = true;
+ }
+
+ public final boolean isGzipAccepted() {
+ return gzipAccepted;
+ }
+
+ // This override is a workaround for
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279457
+ // This makes GetMethod.releaseConnection non-reentrant,
+ // as with reentrancy under some circumstances a NPE can be
+ // thrown with multithreaded access
+ @Override
+ public void releaseConnection() {
+ synchronized (releaseLock) {
+ super.releaseConnection();
+ }
+ }
+
+ public void releaseConnection(IProgressMonitor monitor) {
+ if (monitor != null && monitor.isCanceled()) {
+ // force a connection close on cancel to avoid blocking to do reading the remainder of the response
+ abort();
+ } else {
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
+ }
+ }
+ }
+
+ public final void setGzipAccepted(boolean gzipAccepted) {
+ this.gzipAccepted = gzipAccepted;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java
new file mode 100644
index 0000000..5add126
--- /dev/null
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 Composent, Inc., IBM 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:
+ * Composent, Inc. - initial API and implementation
+ * Maarten Meijer - bug 237936, added gzip encoded transfer default
+ * Henrich Kraemer - bug 263869, testHttpsReceiveFile fails using HTTP proxy
+ * Henrich Kraemer - bug 263613, [transport] Update site contacting / downloading is not cancelable
+ * Tasktop Technologies - cancellation support for streams
+ ******************************************************************************/
+
+package org.eclipse.mylyn.internal.commons.net.http;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
+
+import org.apache.commons.httpclient.HttpConnection;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * Based on {@code org.eclipse.ecf.provider.filetransfer.httpclient.HttpClientRetrieveFileTransfer}.
+ *
+ * @author Steffen Pingel
+ */
+public class CommonPostMethod3 extends PostMethod implements CommonHttpMethod3 {
+
+ private boolean gzipAccepted;
+
+ private boolean gzipReceived;
+
+ private InputStream inputStream;
+
+ private final Object releaseLock = new Object();
+
+ public CommonPostMethod3() {
+ init();
+ }
+
+ public CommonPostMethod3(String requestPath) {
+ super(requestPath);
+ init();
+ }
+
+ @Override
+ public int execute(HttpState state, HttpConnection conn) throws HttpException, IOException {
+ if (gzipAccepted) {
+ this.setRequestHeader("Accept-encoding", CONTENT_ENCODING_GZIP); //$NON-NLS-1$
+ }
+ return super.execute(state, conn);
+ }
+
+ public InputStream getResponseBodyAsStream(IProgressMonitor monitor) throws IOException {
+ if (inputStream == null) {
+ inputStream = WebUtil.getResponseBodyAsStream(this, monitor);
+ }
+ gzipReceived = isZippedResponse();
+ if (gzipReceived) {
+ inputStream = new GZIPInputStream(inputStream);
+ }
+ return inputStream;
+ }
+
+ private void init() {
+ gzipAccepted = true;
+ }
+
+ public final boolean isGzipAccepted() {
+ return gzipAccepted;
+ }
+
+ private boolean isZippedResponse() {
+ // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=269018
+ return this.getResponseHeader(CONTENT_ENCODING) != null
+ && this.getResponseHeader(CONTENT_ENCODING).getValue().equals(CONTENT_ENCODING_GZIP);
+ }
+
+ // This override is a workaround for
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279457
+ // This makes GetMethod.releaseConnection non-reentrant,
+ // as with reentrancy under some circumstances a NPE can be
+ // thrown with multithreaded access
+ @Override
+ public void releaseConnection() {
+ synchronized (releaseLock) {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ inputStream = null;
+ }
+ super.releaseConnection();
+ }
+ }
+
+ public void releaseConnection(IProgressMonitor monitor) {
+ if (monitor != null && monitor.isCanceled()) {
+ // force a connection close on cancel to avoid blocking to do reading the remainder of the response
+ abort();
+ } else {
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
+ }
+ }
+ }
+
+ @Override
+ protected void responseBodyConsumed() {
+ // ensure worker is released to pool
+ super.responseBodyConsumed();
+ }
+
+ public final void setGzipAccepted(boolean gzipAccepted) {
+ this.gzipAccepted = gzipAccepted;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF
index e2f610d..52f6a93 100644
--- a/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.repositories.core/META-INF/MANIFEST.MF
@@ -10,7 +10,6 @@ Export-Package: org.eclipse.mylyn.commons.repositories.core;x-internal:=true,
org.eclipse.mylyn.internal.commons.repositories.core;x-internal:=true
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.equinox.security,
- org.eclipse.mylyn.commons.core,
- org.eclipse.mylyn.commons.net;bundle-version="3.5.0"
+ org.eclipse.mylyn.commons.core
Bundle-ClassPath: .
Bundle-Localization: plugin
diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java
index 87b18be..e2c9bfb 100644
--- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java
+++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/commons/repositories/core/RepositoryLocation.java
@@ -19,6 +19,7 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
@@ -94,6 +95,7 @@ public class RepositoryLocation extends PlatformObject {
private boolean workingCopy;
public RepositoryLocation() {
+ this.properties.put(RepositoryLocation.PROPERTY_ID, UUID.randomUUID().toString());
this.service = LocationService.getDefault();
}
@@ -263,6 +265,10 @@ public class RepositoryLocation extends PlatformObject {
properties.put(PROPERTY_OFFLINE, String.valueOf(offline));
}
+ public void setUrl(String url) {
+ setProperty(PROPERTY_URL, url);
+ }
+
public void setProperty(String key, String newValue) {
Assert.isNotNull(key);
String oldValue = this.properties.get(key);
diff --git a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java
index bb4c4d0..e424be0 100644
--- a/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java
+++ b/org.eclipse.mylyn.commons.repositories.core/src/org/eclipse/mylyn/internal/commons/repositories/core/LocationService.java
@@ -18,8 +18,8 @@ import java.util.Map;
import javax.net.ssl.X509TrustManager;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.mylyn.commons.net.IProxyProvider;
-import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.core.net.NetUtil;
+import org.eclipse.mylyn.commons.core.net.ProxyProvider;
import org.eclipse.mylyn.commons.repositories.core.ILocationService;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
@@ -31,25 +31,36 @@ import org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredenti
*/
public class LocationService implements ILocationService {
- private static LocationService instance = new LocationService(null, null, new PlatformProxyProvider());
+ private static LocationService instance = new LocationService();
public static LocationService getDefault() {
return instance;
}
- private static class PlatformProxyProvider implements IProxyProvider {
+ private static class PlatformProxyProvider extends ProxyProvider {
+ static PlatformProxyProvider INSTANCE = new PlatformProxyProvider();
+
+ @Override
public Proxy getProxyForHost(String host, String proxyType) {
- return WebUtil.getProxy(host, proxyType);
+ return NetUtil.getProxy(host, proxyType);
}
}
private final Map<AuthenticationType, UsernamePasswordCredentials> credentialsByType;
- private final IProxyProvider proxyProvider;
+ private final ProxyProvider proxyProvider;
+
+ public LocationService() {
+ this(null, null, PlatformProxyProvider.INSTANCE);
+ }
+
+ public LocationService(ProxyProvider proxyProvider) {
+ this(null, null, proxyProvider);
+ }
- public LocationService(String username, String password, IProxyProvider proxyProvider) {
+ public LocationService(String username, String password, ProxyProvider proxyProvider) {
this.credentialsByType = new HashMap<AuthenticationType, UsernamePasswordCredentials>();
this.proxyProvider = proxyProvider;
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.http.core/META-INF/MANIFEST.MF
index b280454..f958ffc 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.commons.repositories.http.core/META-INF/MANIFEST.MF
@@ -2,21 +2,23 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.eclipse.mylyn.commons.repositories.http.core;singleton:=true
-Bundle-Version: 3.7.0.qualifier
+Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.core.net
+ org.eclipse.core.net,
+ org.eclipse.mylyn.commons.core,
+ org.eclipse.mylyn.commons.repositories.core
Bundle-ClassPath: .
-Export-Package: org.eclipse.mylyn.commons.http,
- org.eclipse.mylyn.internal.commons.http;x-internal:=true
-Bundle-Activator: org.eclipse.mylyn.internal.commons.http.CommonsHttpPlugin
+Export-Package: org.eclipse.mylyn.commons.repositories.http.core;x-internal:=true
Bundle-Localization: plugin
Import-Package: org.apache.commons.logging;version="[1.0.4,2.0.0)",
org.apache.http;version="4.1.0",
+ org.apache.http.impl;version="4.1.0",
org.apache.http.auth;version="4.1.0",
org.apache.http.auth.params;version="4.1.0",
+ org.apache.http.util;version="4.1.0",
org.apache.http.client;version="4.1.0",
org.apache.http.client.methods;version="4.1.0",
org.apache.http.client.params;version="4.1.0",
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/pom.xml b/org.eclipse.mylyn.commons.repositories.http.core/pom.xml
index e5f460b..949b1f9 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/pom.xml
+++ b/org.eclipse.mylyn.commons.repositories.http.core/pom.xml
@@ -8,7 +8,7 @@
<version>3.7.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.mylyn.commons.repositories.http.core</artifactId>
- <version>3.7.0-SNAPSHOT</version>
+ <version>0.9.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AbstractWebLocation.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AbstractWebLocation.java
deleted file mode 100644
index bb6f745..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AbstractWebLocation.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-import java.net.Proxy;
-
-import javax.net.ssl.X509TrustManager;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-/**
- * @since 3.6
- * @author Steffen Pingel
- */
-public abstract class AbstractWebLocation {
-
- private final String url;
-
- /**
- * @since 3.6
- */
- public AbstractWebLocation(String url) {
- this.url = url;
- }
-
- /**
- * @since 3.6
- */
- public abstract AuthenticationCredentials getCredentials(AuthenticationType type);
-
- /**
- * @since 3.6
- */
- public abstract Proxy getProxyForHost(String host, String proxyType);
-
- /**
- * @since 3.6
- */
- public X509TrustManager getTrustManager() {
- return null;
- }
-
- /**
- * @since 3.6
- */
- public String getUrl() {
- return url;
- }
-
- /**
- * @since 3.6
- */
- public void requestCredentials(AuthenticationType type, String message, IProgressMonitor monitor)
- throws UnsupportedRequestException {
- throw new UnsupportedRequestException();
- }
-
-} \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationCredentials.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationCredentials.java
deleted file mode 100644
index bd4d44c..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationCredentials.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-/**
- * Provides a user name and password.
- *
- * @author Steffen Pingel
- * @since 3.6
- * @noextend This class is not intended to be subclassed by clients.
- */
-public class AuthenticationCredentials {
-
- private final String userName;
-
- private final String password;
-
- /**
- * @param userName
- * the user name, must not be null
- * @param password
- * the password, must not be null
- */
- public AuthenticationCredentials(String userName, String password) {
- if (userName == null) {
- throw new IllegalArgumentException();
- }
- if (password == null) {
- throw new IllegalArgumentException();
- }
-
- this.userName = userName;
- this.password = password;
- }
-
- public String getUserName() {
- return userName;
- }
-
- public String getPassword() {
- return password;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((password == null) ? 0 : password.hashCode());
- result = prime * result + ((userName == null) ? 0 : userName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final AuthenticationCredentials other = (AuthenticationCredentials) obj;
- if (password == null) {
- if (other.password != null) {
- return false;
- }
- } else if (!password.equals(other.password)) {
- return false;
- }
- if (userName == null) {
- if (other.userName != null) {
- return false;
- }
- } else if (!userName.equals(other.userName)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationType.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationType.java
deleted file mode 100644
index 7c14d3c..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/AuthenticationType.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-/**
- * An enum of the supported authentication types.
- *
- * @since 3.6
- * @author Steffen Pingel
- */
-public enum AuthenticationType {
- /**
- * HTTP authentication, this is typically basic authentication but other methods such as digest or NTLM are used as
- * well.
- */
- HTTP,
- /** Proxy authentication. */
- PROXY,
- /** Task repository authentication. */
- REPOSITORY
-} \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/HttpUtil.java
deleted file mode 100644
index 6c8430a..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/HttpUtil.java
+++ /dev/null
@@ -1,585 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2009 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.Credentials;
-import org.apache.http.auth.NTCredentials;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.auth.params.AuthPNames;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.apache.http.client.params.AuthPolicy;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.ClientConnectionManagerFactory;
-import org.apache.http.conn.params.ConnRoutePNames;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SchemeSocketFactory;
-import org.apache.http.impl.client.AbstractHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.HttpContext;
-import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.mylyn.internal.commons.http.AuthenticatedProxy;
-import org.eclipse.mylyn.internal.commons.http.CommonsHttpPlugin;
-import org.eclipse.mylyn.internal.commons.http.MonitoredRequest;
-import org.eclipse.mylyn.internal.commons.http.PollingInputStream;
-import org.eclipse.mylyn.internal.commons.http.PollingProtocolSocketFactory;
-import org.eclipse.mylyn.internal.commons.http.PollingSslProtocolSocketFactory;
-import org.eclipse.mylyn.internal.commons.http.TimeoutInputStream;
-
-/**
- * @author Steffen Pingel
- * @author Shawn Minto
- * @since 3.6
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-public class HttpUtil {
-
- public static final class SingleConnectionManagerFactory implements ClientConnectionManagerFactory {
-
- public ClientConnectionManager newInstance(HttpParams params, SchemeRegistry schemeRegistry) {
- return new ThreadSafeClientConnManager(schemeRegistry);
- }
-
- }
-
- private static final int HTTPS_PORT = 443;
-
- private static final int HTTP_PORT = 80;
-
- // FIXME remove this again
- private static final boolean TEST_MODE;
-
- static {
- String application = System.getProperty("eclipse.application", ""); //$NON-NLS-1$ //$NON-NLS-2$
- if (application.length() > 0) {
- TEST_MODE = application.endsWith("testapplication"); //$NON-NLS-1$
- } else {
- // eclipse 3.3 does not the eclipse.application property
- String commands = System.getProperty("eclipse.commands", ""); //$NON-NLS-1$ //$NON-NLS-2$
- TEST_MODE = commands.contains("testapplication\n"); //$NON-NLS-1$
- }
- }
-
- private static final String USER_AGENT_PREFIX;
-
- private static final String USER_AGENT_POSTFIX;
-
- private static final String USER_AGENT;
-
- static {
- initCommonsLoggingSettings();
-
- StringBuilder sb = new StringBuilder();
- sb.append("Mylyn"); //$NON-NLS-1$
- sb.append(getBundleVersion(CommonsHttpPlugin.getDefault()));
-
- USER_AGENT_PREFIX = sb.toString();
- sb.setLength(0);
-
- if (System.getProperty("org.osgi.framework.vendor") != null) { //$NON-NLS-1$
- sb.append(" "); //$NON-NLS-1$
- sb.append(System.getProperty("org.osgi.framework.vendor")); //$NON-NLS-1$
- sb.append(stripQualifier(System.getProperty("osgi.framework.version"))); //$NON-NLS-1$
-
- if (System.getProperty("eclipse.product") != null) { //$NON-NLS-1$
- sb.append(" ("); //$NON-NLS-1$
- sb.append(System.getProperty("eclipse.product")); //$NON-NLS-1$
- sb.append(")"); //$NON-NLS-1$
- }
- }
-
- HttpParams params = new BasicHttpParams();
- DefaultHttpClient.setDefaultHttpParams(params);
- String parameter = HttpProtocolParams.getUserAgent(params);
- if (parameter != null) {
- String userAgent = parameter.toString();
- if (userAgent != null) {
- // shorten default "Apache-HttpClient/4.1 (java 1.5)"
- if (userAgent.startsWith("Apache-HttpClient/")) { //$NON-NLS-1$
- sb.append(" "); //$NON-NLS-1$
- sb.append(userAgent.substring(8));
- } else {
- sb.append(" "); //$NON-NLS-1$
- sb.append(parameter.toString());
- }
- }
- }
-
- sb.append(" Java/"); //$NON-NLS-1$
- sb.append(System.getProperty("java.version")); //$NON-NLS-1$
- sb.append(" ("); //$NON-NLS-1$
- sb.append(System.getProperty("java.vendor").split(" ")[0]); //$NON-NLS-1$ //$NON-NLS-2$
- sb.append(") "); //$NON-NLS-1$
-
- sb.append(System.getProperty("os.name")); //$NON-NLS-1$
- sb.append("/"); //$NON-NLS-1$
- sb.append(System.getProperty("os.version")); //$NON-NLS-1$
- sb.append(" ("); //$NON-NLS-1$
- sb.append(System.getProperty("os.arch")); //$NON-NLS-1$
- if (System.getProperty("osgi.nl") != null) { //$NON-NLS-1$
- sb.append("; "); //$NON-NLS-1$
- sb.append(System.getProperty("osgi.nl")); //$NON-NLS-1$
- }
- sb.append(")"); //$NON-NLS-1$
-
- USER_AGENT_POSTFIX = sb.toString();
-
- USER_AGENT = USER_AGENT_PREFIX + USER_AGENT_POSTFIX;
- }
-
- private static SchemeSocketFactory sslSocketFactory = new PollingSslProtocolSocketFactory();
-
- private static SchemeSocketFactory socketFactory = new PollingProtocolSocketFactory();
-
- private static final int CONNNECT_TIMEOUT = 60 * 1000;
-
- private static final int SOCKET_TIMEOUT = 3 * 60 * 1000;
-
- private static final int POLL_INTERVAL = 500;
-
- private static final int POLL_ATTEMPTS = SOCKET_TIMEOUT / POLL_INTERVAL;
-
- private static final int BUFFER_SIZE = 4096;
-
- private static final long CLOSE_TIMEOUT = -1;
-
- public static void configureHttpClient(AbstractHttpClient client, String userAgent) {
- client.getParams().setParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME,
- SingleConnectionManagerFactory.class.getName());
-
- client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
- HttpProtocolParams.setUserAgent(client.getParams(), getUserAgent(userAgent));
-
-// client.getParams().setLongParameter(AllClientPNames.CONNECTION_TIMEOUT, CONNNECT_TIMEOUT_INTERVAL);
-
- // TODO consider setting this as the default
- //client.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
- configureHttpClientConnectionManager(client);
- }
-
- public static HttpHost createHost(HttpRequestBase method) {
- URI uri = method.getURI();
- return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
- }
-
- public static HttpResponse execute(final AbstractHttpClient client, final HttpContext context,
- final HttpRequestBase method, IProgressMonitor monitor) throws IOException {
- return execute(client, createHost(method), context, method, monitor);
- }
-
- public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host, final HttpContext context,
- final HttpRequestBase method, IProgressMonitor monitor) throws IOException {
- Assert.isNotNull(client);
- Assert.isNotNull(method);
-
- monitor = Policy.monitorFor(monitor);
-
- MonitoredRequest<HttpResponse> executor = new MonitoredRequest<HttpResponse>(monitor) {
- @Override
- public void abort() {
- super.abort();
- method.abort();
- }
-
- @Override
- public HttpResponse execute() throws Exception {
- return client.execute(host, method, context);
- }
- };
-
- return executeInternal(monitor, executor);
- }
-
- /**
- * @since 3.6
- */
- public static <T> T execute(IProgressMonitor monitor, WebRequest<T> request) throws Throwable {
- // check for legacy reasons
- SubMonitor subMonitor = (monitor instanceof SubMonitor) ? (SubMonitor) monitor : SubMonitor.convert(null);
-
- Future<T> future = CommonsHttpPlugin.getExecutorService().submit(request);
- while (true) {
- if (monitor.isCanceled()) {
- request.abort();
-
- // wait for executor to finish
- future.cancel(false);
- try {
- if (!future.isCancelled()) {
- future.get();
- }
- } catch (CancellationException e) {
- // ignore
- } catch (InterruptedException e) {
- // ignore
- } catch (ExecutionException e) {
- // ignore
- }
- throw new OperationCanceledException();
- }
-
- try {
- return future.get(POLL_INTERVAL, TimeUnit.MILLISECONDS);
- } catch (ExecutionException e) {
- throw e.getCause();
- } catch (TimeoutException ignored) {
- }
-
- subMonitor.setWorkRemaining(20);
- subMonitor.worked(1);
- }
- }
-
- /**
- * @since 3.6
- */
- public static String getHost(String repositoryUrl) {
- String result = repositoryUrl;
- int colonSlashSlash = repositoryUrl.indexOf("://"); //$NON-NLS-1$
-
- if (colonSlashSlash >= 0) {
- result = repositoryUrl.substring(colonSlashSlash + 3);
- }
-
- int colonPort = result.indexOf(':');
- int requestPath = result.indexOf('/');
-
- int substringEnd;
-
- // minimum positive, or string length
- if (colonPort > 0 && requestPath > 0) {
- substringEnd = Math.min(colonPort, requestPath);
- } else if (colonPort > 0) {
- substringEnd = colonPort;
- } else if (requestPath > 0) {
- substringEnd = requestPath;
- } else {
- substringEnd = result.length();
- }
-
- return result.substring(0, substringEnd);
- }
-
- public static Credentials getHttpClientCredentials(AuthenticationCredentials credentials, String host) {
- String username = credentials.getUserName();
- String password = credentials.getPassword();
- int i = username.indexOf("\\"); //$NON-NLS-1$
- if (i > 0 && i < username.length() - 1 && host != null) {
- return new NTCredentials(username.substring(i + 1), password, host, username.substring(0, i));
- } else {
- return new UsernamePasswordCredentials(username, password);
- }
- }
-
- public static HttpContext getHttpContext(AbstractHttpClient client, AbstractWebLocation location,
- HttpContext previousContext, IProgressMonitor progressMonitor) {
-
- Assert.isNotNull(client);
- Assert.isNotNull(location);
-
- String url = location.getUrl();
- String host = getHost(url);
- int port = getPort(url);
-
- configureHttpClientConnectionManager(client);
-
- HttpContext context = previousContext;
- if (context == null) {
- context = new BasicHttpContext();
- }
- configureHttpClientProxy(client, context, location);
-
- AuthenticationCredentials authCreds = location.getCredentials(AuthenticationType.HTTP);
- if (authCreds != null) {
- AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
- Credentials credentials = getHttpClientCredentials(authCreds, host);
-
- if (credentials instanceof NTCredentials) {
- List<String> authpref = new ArrayList<String>();
- authpref.add(AuthPolicy.NTLM);
- authpref.add(AuthPolicy.BASIC);
- authpref.add(AuthPolicy.DIGEST);
- client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
- } else {
- List<String> authpref = new ArrayList<String>();
- authpref.add(AuthPolicy.BASIC);
- authpref.add(AuthPolicy.DIGEST);
- authpref.add(AuthPolicy.NTLM);
- client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
- }
- client.getCredentialsProvider().setCredentials(authScope, credentials);
- }
-
- if (isRepositoryHttps(url)) {
- Scheme sch = new Scheme("https", HTTPS_PORT, sslSocketFactory); //$NON-NLS-1$
- client.getConnectionManager().getSchemeRegistry().register(sch);
- } else {
- Scheme sch = new Scheme("http", HTTP_PORT, socketFactory); //$NON-NLS-1$
- client.getConnectionManager().getSchemeRegistry().register(sch);
- }
-
- return context;
-
- }
-
- /**
- * @since 3.6
- */
- public static int getPort(String repositoryUrl) {
- int colonSlashSlash = repositoryUrl.indexOf("://"); //$NON-NLS-1$
- int firstSlash = repositoryUrl.indexOf("/", colonSlashSlash + 3); //$NON-NLS-1$
- int colonPort = repositoryUrl.indexOf(':', colonSlashSlash + 1);
- if (firstSlash == -1) {
- firstSlash = repositoryUrl.length();
- }
- if (colonPort < 0 || colonPort > firstSlash) {
- return isRepositoryHttps(repositoryUrl) ? HTTPS_PORT : HTTP_PORT;
- }
-
- int requestPath = repositoryUrl.indexOf('/', colonPort + 1);
- int end = requestPath < 0 ? repositoryUrl.length() : requestPath;
- String port = repositoryUrl.substring(colonPort + 1, end);
- if (port.length() == 0) {
- return isRepositoryHttps(repositoryUrl) ? HTTPS_PORT : HTTP_PORT;
- }
-
- return Integer.parseInt(port);
- }
-
- /**
- * @since 3.6
- */
- public static String getRequestPath(String repositoryUrl) {
- int colonSlashSlash = repositoryUrl.indexOf("://"); //$NON-NLS-1$
- int requestPath = repositoryUrl.indexOf('/', colonSlashSlash + 3);
-
- if (requestPath < 0) {
- return ""; //$NON-NLS-1$
- } else {
- return repositoryUrl.substring(requestPath);
- }
- }
-
- public static InputStream getResponseBodyAsStream(HttpEntity entity, IProgressMonitor monitor) throws IOException {
- monitor = Policy.monitorFor(monitor);
- return new PollingInputStream(new TimeoutInputStream(entity.getContent(), BUFFER_SIZE, POLL_INTERVAL,
- CLOSE_TIMEOUT), POLL_ATTEMPTS, monitor);
- }
-
- /**
- * Returns a user agent string that contains information about the platform and operating system. The
- * <code>product</code> parameter allows to additional specify custom text that is inserted into the returned
- * string. The exact return value depends on the environment.
- * <p>
- * Examples:
- * <ul>
- * <li>Headless: <code>Mylyn MyProduct HttpClient/3.1 Java/1.5.0_13 (Sun) Linux/2.6.22-14-generic (i386)</code>
- * <li>Eclipse:
- * <code>Mylyn/2.2.0 Eclipse/3.4.0 (org.eclipse.sdk.ide) HttpClient/3.1 Java/1.5.0_13 (Sun) Linux/2.6.22-14-generic (i386; en_CA)</code>
- *
- * @param product
- * an identifier that is inserted into the returned user agent string
- * @return a user agent string
- * @since 3.6
- */
- public static String getUserAgent(String product) {
- if (product != null && product.length() > 0) {
- StringBuilder sb = new StringBuilder();
- sb.append(USER_AGENT_PREFIX);
- sb.append(" "); //$NON-NLS-1$
- sb.append(product);
- sb.append(USER_AGENT_POSTFIX);
- return sb.toString();
- } else {
- return USER_AGENT;
- }
- }
-
- private static void configureHttpClientConnectionManager(AbstractHttpClient client) {
-
- ClientConnectionManager connectionManager = client.getConnectionManager();
-
- HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT);
- HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT);
-
- if (connectionManager instanceof ThreadSafeClientConnManager) {
- ThreadSafeClientConnManager conMgr = (ThreadSafeClientConnManager) connectionManager;
- // FIXME fix connection leaks
- if (TEST_MODE) {
- conMgr.setDefaultMaxPerRoute(2);
- } else {
- conMgr.setDefaultMaxPerRoute(100);
- conMgr.setMaxTotal(1000);
- }
- }
- }
-
- private static void configureHttpClientProxy(AbstractHttpClient client, HttpContext context,
- AbstractWebLocation location) {
- String host = getHost(location.getUrl());
-
- Proxy proxy;
- if (isRepositoryHttps(location.getUrl())) {
- proxy = location.getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE);
- } else {
- proxy = location.getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE);
- }
-
- if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
- InetSocketAddress address = (InetSocketAddress) proxy.address();
-
- client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
- new HttpHost(address.getHostName(), address.getPort()));
-
- if (proxy instanceof AuthenticatedProxy) {
- AuthenticatedProxy authProxy = (AuthenticatedProxy) proxy;
- Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(),
- address.getAddress());
- if (credentials instanceof NTCredentials) {
- List<String> authpref = new ArrayList<String>();
- authpref.add(AuthPolicy.NTLM);
- authpref.add(AuthPolicy.BASIC);
- authpref.add(AuthPolicy.DIGEST);
- client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
- } else {
- List<String> authpref = new ArrayList<String>();
- authpref.add(AuthPolicy.BASIC);
- authpref.add(AuthPolicy.DIGEST);
- authpref.add(AuthPolicy.NTLM);
- client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
- }
- AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(), AuthScope.ANY_REALM);
- client.getCredentialsProvider().setCredentials(proxyAuthScope, credentials);
- }
- } else {
- client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
- }
- }
-
- /**
- * Only sets system property if they are not already set to a value.
- */
- private static void defaultSystemProperty(String key, String defaultValue) {
- if (System.getProperty(key) == null) {
- System.setProperty(key, defaultValue);
- }
- }
-
- @SuppressWarnings("unchecked")
- private static <T> T executeInternal(IProgressMonitor monitor, WebRequest<?> request) throws IOException {
- try {
- return (T) execute(monitor, request);
- } catch (IOException e) {
- throw e;
- } catch (RuntimeException e) {
- throw e;
- } catch (Error e) {
- throw e;
- } catch (Throwable e) {
- throw new RuntimeException(e);
- }
- }
-
- private static String getBundleVersion(Plugin plugin) {
- if (null == plugin) {
- return ""; //$NON-NLS-1$
- }
- Object bundleVersion = plugin.getBundle().getHeaders().get("Bundle-Version"); //$NON-NLS-1$
- if (null == bundleVersion) {
- return ""; //$NON-NLS-1$
- }
- return stripQualifier((String) bundleVersion);
- }
-
- /**
- * Disables logging by default. Set these system properties on launch enables verbose logging of HTTP communication:
- *
- * <pre>
- * -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
- * -Dorg.apache.commons.logging.simplelog.showlogname=true
- * -Dorg.apache.commons.logging.simplelog.defaultlog=off
- * -Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug
- * -Dorg.apache.commons.logging.simplelog.log.org.apache.commons.httpclient=off
- * -Dorg.apache.commons.logging.simplelog.log.org.apache.axis.message=debug
- * </pre>
- */
- private static void initCommonsLoggingSettings() {
- defaultSystemProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private static boolean isRepositoryHttps(String repositoryUrl) {
- return repositoryUrl.matches("https.*"); //$NON-NLS-1$
- }
-
- private static String stripQualifier(String longVersion) {
- if (longVersion == null) {
- return ""; //$NON-NLS-1$
- }
-
- String parts[] = longVersion.split("\\."); //$NON-NLS-1$
- StringBuilder version = new StringBuilder();
- if (parts.length > 0) {
- version.append("/"); //$NON-NLS-1$
- version.append(parts[0]);
- if (parts.length > 1) {
- version.append("."); //$NON-NLS-1$
- version.append(parts[1]);
- if (parts.length > 2) {
- version.append("."); //$NON-NLS-1$
- version.append(parts[2]);
- }
- }
- }
- return version.toString();
-
- }
-
- static Credentials getCredentials(final String username, final String password, final InetAddress address) {
- int i = username.indexOf("\\"); //$NON-NLS-1$
- if (i > 0 && i < username.length() - 1 && address != null) {
- return new NTCredentials(username.substring(i + 1), password, address.getHostName(), username.substring(0,
- i));
- } else {
- return new UsernamePasswordCredentials(username, password);
- }
- }
-}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/Policy.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/Policy.java
deleted file mode 100644
index 552ab8d..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/Policy.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.ProgressMonitorWrapper;
-import org.eclipse.core.runtime.SubProgressMonitor;
-import org.eclipse.mylyn.internal.commons.http.CommonsHttpPlugin;
-import org.eclipse.mylyn.internal.commons.http.InfiniteSubProgressMonitor;
-
-/**
- * @since 3.6
- */
-public class Policy {
-
- /**
- * @since 3.6
- */
- public static boolean DEBUG_STREAMS = false;
-
- static {
- if (CommonsHttpPlugin.getDefault() != null && CommonsHttpPlugin.getDefault().isDebugging()) {
- DEBUG_STREAMS = "true".equalsIgnoreCase(Platform.getDebugOption(CommonsHttpPlugin.ID_PLUGIN + "/streams"));//$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- /**
- * @since 3.6
- */
- public static void advance(IProgressMonitor monitor, int worked) {
- if (monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- monitor.worked(worked);
- }
-
- public static void checkCanceled(IProgressMonitor monitor) {
- if (monitor != null && monitor.isCanceled()) {
- throw new OperationCanceledException();
- }
- }
-
- /**
- * @since 3.6
- */
- public static boolean isBackgroundMonitor(IProgressMonitor monitor) {
- return monitor instanceof BackgroundProgressMonitor;
-
- }
-
- /**
- * @since 3.6
- */
- public static IProgressMonitor backgroundMonitorFor(IProgressMonitor monitor) {
- if (monitor == null) {
- return new NullProgressMonitor();
- }
- return new BackgroundProgressMonitor(monitor);
- }
-
- /**
- * @since 3.6
- */
- public static IProgressMonitor monitorFor(IProgressMonitor monitor) {
- if (monitor == null) {
- return new NullProgressMonitor();
- }
- return monitor;
- }
-
- /**
- * @since 3.6
- */
- public static IProgressMonitor monitorFor(IProgressMonitor monitor, boolean backgroundOperation) {
- if (monitor == null) {
- return new NullProgressMonitor();
- }
- if (backgroundOperation) {
- return backgroundMonitorFor(monitor);
- }
- return monitor;
- }
-
- /**
- * @since 3.6
- */
- public static IProgressMonitor subMonitorFor(IProgressMonitor monitor, int ticks) {
- if (monitor == null) {
- return new NullProgressMonitor();
- }
- if (monitor instanceof NullProgressMonitor) {
- return monitor;
- }
- if (monitor instanceof BackgroundProgressMonitor) {
- return new BackgroundProgressMonitor(new SubProgressMonitor(monitor, ticks));
- }
- return new SubProgressMonitor(monitor, ticks);
- }
-
- /**
- * @since 3.6
- */
- public static IProgressMonitor infiniteSubMonitorFor(IProgressMonitor monitor, int ticks) {
- if (monitor == null) {
- return new NullProgressMonitor();
- }
- if (monitor instanceof NullProgressMonitor) {
- return monitor;
- }
- if (monitor instanceof BackgroundProgressMonitor) {
- return new BackgroundProgressMonitor(new InfiniteSubProgressMonitor(monitor, ticks));
- }
- return new InfiniteSubProgressMonitor(monitor, ticks);
- }
-
- /**
- * Wrapped progress monitor for background operations.
- */
- private static class BackgroundProgressMonitor extends ProgressMonitorWrapper {
-
- protected BackgroundProgressMonitor(IProgressMonitor monitor) {
- super(monitor);
- }
-
- }
-
-}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/UnsupportedRequestException.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/UnsupportedRequestException.java
deleted file mode 100644
index fde21df..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/UnsupportedRequestException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2008 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-/**
- * Indicates that the request is not supported.
- *
- * @author Steffen Pingel
- * @since 3.6
- */
-public class UnsupportedRequestException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- public UnsupportedRequestException() {
- }
-
- public UnsupportedRequestException(String message) {
- super(message);
- }
-
- public UnsupportedRequestException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public UnsupportedRequestException(Throwable cause) {
- super(cause);
- }
-
-}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebLocation.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebLocation.java
deleted file mode 100644
index d17e74d..0000000
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/http/WebLocation.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2009 Tasktop Technologies 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:
- * Tasktop Technologies - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.mylyn.commons.http;
-
-import java.net.Proxy;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @since 3.6
- * @author Steffen Pingel
- */
-public class WebLocation extends AbstractWebLocation {
-
- private static class PlatformProxyProvider implements IProxyProvider {
-
- public Proxy getProxyForHost(String host, String proxyType) {
- // FIXME return WebUtil.getProxy(host, proxyType);
- return null;
- }
-
- }
-
- private final Map<AuthenticationType, AuthenticationCredentials> credentialsByType;
-
- private final IProxyProvider proxyProvider;
-
- public WebLocation(String url, String username, String password, IProxyProvider proxyProvider) {
- super(url);
-
- this.credentialsByType = new HashMap<AuthenticationType, AuthenticationCredentials>();
- this.proxyProvider = proxyProvider;
-
- if (username != null && password != null) {
- setCredentials(AuthenticationType.REPOSITORY, username, password);
- }
- }
-
- public WebLocation(String url, String username, String password) {
- this(url, username, password, new PlatformProxyProvider());
- }
-
- public WebLocation(String url) {
- this(url, null, null, new PlatformProxyProvider());
- }
-
- @Override
- public AuthenticationCredentials getCredentials(AuthenticationType authType) {
- return credentialsByType.get(authType);
- }
-
- @Override
- public Proxy getProxyForHost(String host, String proxyType) {
- if (proxyProvider != null) {
- return proxyProvider.getProxyForHost(host, proxyType);
- }
- return null;
- }
-
- public void setCredentials(AuthenticationType authType, String username, String password) {
- credentialsByType.put(authType, new AuthenticationCredentials(username, password));
- }
-
-}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java
new file mode 100644
index 0000000..a27c12d
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpClient.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.core;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.impl.client.ContentEncodingHttpClient;
+import org.apache.http.protocol.SyncBasicHttpContext;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
+import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
+
+/**
+ * Provides an abstraction for connecting to a {@link RepositoryLocation} through HTTP.
+ *
+ * @author Steffen Pingel
+ */
+public class CommonHttpClient {
+
+ private final SyncBasicHttpContext context;
+
+ private AbstractHttpClient httpClient;
+
+ private final RepositoryLocation location;
+
+ public CommonHttpClient(RepositoryLocation location) {
+ this.location = location;
+ this.context = new SyncBasicHttpContext(null);
+ }
+
+ public HttpResponse execute(HttpRequestBase request, IOperationMonitor monitor) throws IOException {
+ HttpUtil.configureProxyAndAuthentication(getHttpClient(), location, monitor);
+ return HttpUtil.execute(getHttpClient(), HttpUtil.createHost(request), context, request, monitor);
+ }
+
+ public synchronized AbstractHttpClient getHttpClient() {
+ if (httpClient == null) {
+ httpClient = createHttpClient(null);
+ }
+ return httpClient;
+ }
+
+ public RepositoryLocation getLocation() {
+ return location;
+ }
+
+ protected void authenticate(IOperationMonitor monitor) throws IOException {
+ }
+
+ protected AbstractHttpClient createHttpClient(String userAgent) {
+ AbstractHttpClient client = new ContentEncodingHttpClient() {
+ @Override
+ protected ClientConnectionManager createClientConnectionManager() {
+ return HttpUtil.getConnectionManager();
+ }
+ };
+ HttpUtil.configureClient(client, userAgent);
+ return client;
+ }
+
+ protected boolean needsReauthentication(HttpResponse response, IProgressMonitor monitor) throws IOException {
+ int statusCode = response.getStatusLine().getStatusCode();
+ final AuthenticationType authenticationType;
+ if (statusCode == HttpStatus.SC_UNAUTHORIZED || statusCode == HttpStatus.SC_FORBIDDEN) {
+ authenticationType = AuthenticationType.HTTP;
+ } else if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) {
+ authenticationType = AuthenticationType.PROXY;
+ } else {
+ return false;
+ }
+
+ try {
+ org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials authCreds = location.getService()
+ .requestCredentials(AuthenticationType.HTTP,
+ org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials.class, null,
+ monitor);
+ } catch (UnsupportedOperationException e) {
+ IOException ioe = new IOException(HttpUtil.getStatusText(statusCode));
+ ioe.initCause(e);
+ throw ioe;
+ }
+
+ return true;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java
new file mode 100644
index 0000000..7725bc5
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpOperation.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.core;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
+import org.eclipse.mylyn.commons.core.operations.OperationUtil;
+import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationCredentials;
+
+/**
+ * @author Steffen Pingel
+ */
+public abstract class CommonHttpOperation<T> {
+
+ private final CommonHttpClient client;
+
+ public CommonHttpOperation(CommonHttpClient client) {
+ this.client = client;
+ }
+
+ private boolean needsReauthentication(HttpResponse response, IOperationMonitor monitor) throws IOException {
+ return client.needsReauthentication(response, monitor);
+ }
+
+ protected HttpGet createGetRequest(String requestPath) {
+ return new HttpGet(requestPath);
+ }
+
+ protected HttpHead createHeadRequest(String requestPath) {
+ return new HttpHead(requestPath);
+ }
+
+ protected HttpPost createPostRequest(String requestPath) {
+ return new HttpPost(requestPath);
+ }
+
+ protected CommonHttpResponse execute(HttpRequestBase request, IOperationMonitor monitor) throws IOException {
+ monitor = OperationUtil.convert(monitor);
+
+ // force authentication
+ if (needsAuthentication()) {
+ client.authenticate(monitor);
+ }
+
+ // first attempt
+ HttpResponse response = client.execute(request, monitor);
+ if (!needsReauthentication(response, monitor)) {
+ return new CommonHttpResponse(request, response);
+ } else {
+ HttpUtil.release(request, response, monitor);
+
+ client.authenticate(monitor);
+
+ // second attempt
+ response = client.execute(request, monitor);
+ return new CommonHttpResponse(request, response);
+ }
+ }
+
+ protected final CommonHttpClient getClient() {
+ return client;
+ }
+
+ protected boolean hasCredentials(AuthenticationCredentials credentials) {
+ return credentials != null;
+ }
+
+ protected boolean needsAuthentication() {
+ return false;
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpResponse.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpResponse.java
new file mode 100644
index 0000000..5b237a7
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/CommonHttpResponse.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.util.EntityUtils;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Steffen Pingel
+ */
+public class CommonHttpResponse {
+
+ private final HttpRequest request;
+
+ private final HttpResponse response;
+
+ public CommonHttpResponse(HttpRequest request, HttpResponse response) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(response);
+ this.request = request;
+ this.response = response;
+ }
+
+ public HttpRequest getRequest() {
+ return request;
+ }
+
+ public HttpResponse getResponse() {
+ return response;
+ }
+
+ public int getStatusCode() {
+ return response.getStatusLine().getStatusCode();
+ }
+
+ public InputStream getResponseEntityAsStream(IProgressMonitor monitor) throws IOException {
+ HttpEntity entity = response.getEntity();
+ if (entity == null) {
+ throw new IOException("Expected entity"); //$NON-NLS-1$
+ }
+ return HttpUtil.getResponseBodyAsStream(entity, monitor);
+ }
+
+ public void release(IProgressMonitor monitor) {
+ HttpUtil.release(request, response, monitor);
+ }
+
+ public String getRequestPath() {
+ if (request instanceof HttpUriRequest) {
+ return ((HttpUriRequest) request).getURI().getPath();
+ } else {
+ return null;
+ }
+ }
+
+ public String getResponseCharSet() {
+ return EntityUtils.getContentCharSet(response.getEntity());
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
new file mode 100644
index 0000000..088dfab
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/HttpUtil.java
@@ -0,0 +1,359 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.core;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.NTCredentials;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.auth.params.AuthPNames;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.params.AuthPolicy;
+import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.impl.EnglishReasonPhraseCatalog;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+import org.eclipse.core.net.proxy.IProxyData;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.CoreUtil;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.commons.core.io.PollingInputStream;
+import org.eclipse.mylyn.commons.core.io.TimeoutInputStream;
+import org.eclipse.mylyn.commons.core.net.AuthenticatedProxy;
+import org.eclipse.mylyn.commons.core.net.NetUtil;
+import org.eclipse.mylyn.commons.core.operations.MonitoredOperation;
+import org.eclipse.mylyn.commons.core.operations.Operation;
+import org.eclipse.mylyn.commons.core.operations.OperationUtil;
+import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
+import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
+
+/**
+ * @author Steffen Pingel
+ * @author Shawn Minto
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ */
+public class HttpUtil {
+
+ private static final int BUFFER_SIZE = 4096;
+
+ private static final long CLOSE_TIMEOUT = -1;
+
+ /**
+ * @see IdleConnectionTimeoutThread#setTimeoutInterval(long)
+ */
+ private static final int CONNECTION_TIMEOUT_INTERVAL = 30 * 1000;
+
+ private static final int CONNNECT_TIMEOUT = 60 * 1000;
+
+ private static final int HTTP_PORT = 80;
+
+ private static final int HTTPS_PORT = 443;
+
+ private static final int POLL_INTERVAL = 500;
+
+ private static final int SOCKET_TIMEOUT = 3 * 60 * 1000;
+
+ private static final int POLL_ATTEMPTS = SOCKET_TIMEOUT / POLL_INTERVAL;
+
+ private static SchemeSocketFactory socketFactory = new PollingProtocolSocketFactory();
+
+ private static SchemeSocketFactory sslSocketFactory = new PollingSslProtocolSocketFactory();
+
+ static final String ID_PLUGIN = "org.eclipse.mylyn.commons.repositories.http"; //$NON-NLS-1$
+
+ private static ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
+ HttpUtil.getSchemeRegistry());
+
+ static {
+ if (CoreUtil.TEST_MODE) {
+ connectionManager.setDefaultMaxPerRoute(2);
+ } else {
+ connectionManager.setDefaultMaxPerRoute(100);
+ connectionManager.setMaxTotal(1000);
+ }
+ }
+
+ public static void configureClient(AbstractHttpClient client, String userAgent) {
+ HttpClientParams.setCookiePolicy(client.getParams(), CookiePolicy.RFC_2109);
+
+ HttpProtocolParams.setUserAgent(client.getParams(), userAgent);
+ HttpProtocolParams.setUseExpectContinue(client.getParams(), true);
+
+ HttpConnectionParams.setConnectionTimeout(client.getParams(), CONNNECT_TIMEOUT);
+ HttpConnectionParams.setSoTimeout(client.getParams(), SOCKET_TIMEOUT);
+ }
+
+ public static void configureProxyAndAuthentication(AbstractHttpClient client, RepositoryLocation location,
+ IProgressMonitor progressMonitor) {
+ Assert.isNotNull(client);
+ Assert.isNotNull(location);
+
+ String url = location.getUrl();
+ Assert.isNotNull("The location url must not be null", url);
+
+ configureProxy(client, location, url);
+
+ org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials authCreds = location.getCredentials(
+ AuthenticationType.HTTP,
+ org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials.class);
+ if (authCreds != null) {
+ String host = NetUtil.getHost(url);
+ int port = NetUtil.getPort(url);
+ Credentials credentials = getHttpClientCredentials(authCreds, host, false);
+ if (credentials instanceof NTCredentials) {
+ List<String> authpref = new ArrayList<String>();
+ authpref.add(AuthPolicy.NTLM);
+ authpref.add(AuthPolicy.BASIC);
+ authpref.add(AuthPolicy.DIGEST);
+ client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
+
+ AuthScope authScopeNTLM = new AuthScope(host, port, AuthScope.ANY_REALM, AuthPolicy.NTLM);
+ client.getCredentialsProvider().setCredentials(authScopeNTLM, credentials);
+
+ AuthScope authScopeAny = new AuthScope(host, port, AuthScope.ANY_REALM);
+ Credentials usernamePasswordCredentials = getHttpClientCredentials(authCreds, host, true);
+ client.getCredentialsProvider().setCredentials(authScopeAny, usernamePasswordCredentials);
+ } else {
+ List<String> authpref = new ArrayList<String>();
+ authpref.add(AuthPolicy.BASIC);
+ authpref.add(AuthPolicy.DIGEST);
+ authpref.add(AuthPolicy.NTLM);
+ client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
+ AuthScope authScope = new AuthScope(host, port, AuthScope.ANY_REALM);
+ client.getCredentialsProvider().setCredentials(authScope, credentials);
+ }
+ }
+ }
+
+ public static HttpHost createHost(HttpRequestBase method) {
+ URI uri = method.getURI();
+ return new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
+ }
+
+ public static HttpResponse execute(final AbstractHttpClient client, final HttpContext context,
+ final HttpRequestBase method, IProgressMonitor monitor) throws IOException {
+ return execute(client, createHost(method), context, method, monitor);
+ }
+
+ public static HttpResponse execute(final AbstractHttpClient client, final HttpHost host, final HttpContext context,
+ final HttpRequestBase method, IProgressMonitor monitor) throws IOException {
+ Assert.isNotNull(client);
+ Assert.isNotNull(method);
+
+ monitor = OperationUtil.convert(monitor);
+
+ MonitoredOperation<HttpResponse> executor = new MonitoredOperation<HttpResponse>(monitor) {
+ @Override
+ public void abort() {
+ super.abort();
+ method.abort();
+ }
+
+ @Override
+ public HttpResponse execute() throws Exception {
+ return client.execute(host, method, context);
+ }
+ };
+
+ return executeInternal(monitor, executor);
+ }
+
+ public static Credentials getHttpClientCredentials(
+ org.eclipse.mylyn.commons.repositories.core.auth.UsernamePasswordCredentials credentials, String host,
+ boolean forceUserNamePassword) {
+ String username = credentials.getUserName();
+ String password = credentials.getPassword();
+ int i = username.indexOf("\\"); //$NON-NLS-1$
+ if (i > 0 && i < username.length() - 1 && host != null && !forceUserNamePassword) {
+ String hostName = host;
+ try {
+ InetAddress localHost = InetAddress.getLocalHost();
+ if (localHost != null) {
+ hostName = localHost.getHostName();
+ }
+ } catch (UnknownHostException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, ID_PLUGIN,
+ "Unable to get hostname. Defaulting to servers host.", e));
+ }
+ if (hostName == null) {
+ hostName = host;
+ }
+ return new NTCredentials(username.substring(i + 1), password, hostName, username.substring(0, i));
+ } else {
+ return new UsernamePasswordCredentials(username, password);
+ }
+ }
+
+ public static InputStream getResponseBodyAsStream(HttpEntity entity, IProgressMonitor monitor) throws IOException {
+ monitor = OperationUtil.convert(monitor);
+ return new PollingInputStream(new TimeoutInputStream(entity.getContent(), BUFFER_SIZE, POLL_INTERVAL,
+ CLOSE_TIMEOUT), POLL_ATTEMPTS, monitor);
+ }
+
+ public static SchemeRegistry getSchemeRegistry() {
+ SchemeRegistry schemeRegistry = new SchemeRegistry();
+ schemeRegistry.register(new Scheme("http", HTTP_PORT, socketFactory)); //$NON-NLS-1$
+ schemeRegistry.register(new Scheme("https", HTTPS_PORT, sslSocketFactory)); //$NON-NLS-1$
+ return schemeRegistry;
+ }
+
+ private static void configureProxy(AbstractHttpClient client, RepositoryLocation location, String url) {
+ String host = NetUtil.getHost(url);
+
+ Proxy proxy;
+ if (NetUtil.isUrlHttps(location.getUrl())) {
+ proxy = location.getService().getProxyForHost(host, IProxyData.HTTPS_PROXY_TYPE);
+ } else {
+ proxy = location.getService().getProxyForHost(host, IProxyData.HTTP_PROXY_TYPE);
+ }
+
+ if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
+ InetSocketAddress address = (InetSocketAddress) proxy.address();
+
+ client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
+ new HttpHost(address.getHostName(), address.getPort()));
+
+ if (proxy instanceof AuthenticatedProxy) {
+ AuthenticatedProxy authProxy = (AuthenticatedProxy) proxy;
+ Credentials credentials = getCredentials(authProxy.getUserName(), authProxy.getPassword(),
+ address.getAddress(), false);
+ if (credentials instanceof NTCredentials) {
+ List<String> authpref = new ArrayList<String>();
+ authpref.add(AuthPolicy.NTLM);
+ authpref.add(AuthPolicy.BASIC);
+ authpref.add(AuthPolicy.DIGEST);
+ client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
+ AuthScope proxyAuthScopeNTLM = new AuthScope(address.getHostName(), address.getPort(),
+ AuthScope.ANY_REALM, AuthPolicy.NTLM);
+ client.getCredentialsProvider().setCredentials(proxyAuthScopeNTLM, credentials);
+
+ AuthScope proxyAuthScopeAny = new AuthScope(address.getHostName(), address.getPort(),
+ AuthScope.ANY_REALM);
+ Credentials usernamePasswordCredentials = getCredentials(authProxy.getUserName(),
+ authProxy.getPassword(), address.getAddress(), true);
+ client.getCredentialsProvider().setCredentials(proxyAuthScopeAny, usernamePasswordCredentials);
+
+ } else {
+ List<String> authpref = new ArrayList<String>();
+ authpref.add(AuthPolicy.BASIC);
+ authpref.add(AuthPolicy.DIGEST);
+ authpref.add(AuthPolicy.NTLM);
+ client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
+ AuthScope proxyAuthScope = new AuthScope(address.getHostName(), address.getPort(),
+ AuthScope.ANY_REALM);
+ client.getCredentialsProvider().setCredentials(proxyAuthScope, credentials);
+ }
+ }
+ } else {
+ client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> T executeInternal(IProgressMonitor monitor, Operation<?> request) throws IOException {
+ try {
+ return (T) OperationUtil.execute(monitor, request);
+ } catch (IOException e) {
+ throw e;
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Error e) {
+ throw e;
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static Credentials getCredentials(final String username, final String password, final InetAddress address,
+ boolean forceUserNamePassword) {
+ int i = username.indexOf("\\"); //$NON-NLS-1$
+ if (i > 0 && i < username.length() - 1 && address != null && !forceUserNamePassword) {
+ String hostName = address.getHostName();
+ try {
+ InetAddress localHost = InetAddress.getLocalHost();
+ if (localHost != null) {
+ hostName = localHost.getHostName();
+ }
+ } catch (UnknownHostException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, ID_PLUGIN,
+ "Unable to get hostname. Defaulting to servers host.", e));
+ }
+ if (hostName == null) {
+ hostName = address.getHostName();
+ }
+ return new NTCredentials(username.substring(i + 1), password, hostName, username.substring(0, i));
+ } else {
+ return new UsernamePasswordCredentials(username, password);
+ }
+ }
+
+ public static ThreadSafeClientConnManager getConnectionManager() {
+ return connectionManager;
+ }
+
+ public static String getStatusText(int statusCode) {
+ return EnglishReasonPhraseCatalog.INSTANCE.getReason(statusCode, Locale.getDefault());
+ }
+
+ public static void release(HttpRequest request, HttpResponse response, IProgressMonitor monitor) {
+ Assert.isNotNull(request);
+ Assert.isNotNull(response);
+ if (monitor != null && monitor.isCanceled() && request instanceof HttpUriRequest) {
+ // force a connection close on cancel to avoid blocking to do reading the remainder of the response
+ try {
+ ((HttpUriRequest) request).abort();
+ } catch (UnsupportedOperationException e) {
+ // fall back to standard close
+ try {
+ EntityUtils.consume(response.getEntity());
+ } catch (IOException e2) {
+ // ignore
+ }
+ }
+ } else {
+ try {
+ EntityUtils.consume(response.getEntity());
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingProtocolSocketFactory.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingProtocolSocketFactory.java
index 952d1e7..35be6fa 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingProtocolSocketFactory.java
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingProtocolSocketFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 Tasktop Technologies and others.
+ * Copyright (c) 2011 Tasktop Technologies 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
@@ -9,7 +9,7 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.repositories.http.core;
import java.io.IOException;
import java.net.InetSocketAddress;
@@ -22,11 +22,13 @@ import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
+import org.eclipse.mylyn.commons.core.net.NetUtil;
+import org.eclipse.mylyn.commons.core.operations.MonitoredOperation;
/**
* @author Steffen Pingel
*/
-public class PollingProtocolSocketFactory implements SchemeSocketFactory {
+class PollingProtocolSocketFactory implements SchemeSocketFactory {
private final static SocketFactory factory = SocketFactory.getDefault();
@@ -46,7 +48,7 @@ public class PollingProtocolSocketFactory implements SchemeSocketFactory {
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
socket.bind(localAddress);
- MonitoredRequest.connect(socket, remoteAddress, connTimeout);
+ NetUtil.connect(socket, remoteAddress, connTimeout, MonitoredOperation.getCurrentOperation());
return socket;
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingSslProtocolSocketFactory.java b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingSslProtocolSocketFactory.java
index fd8613b..52b6191 100644
--- a/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/internal/commons/http/PollingSslProtocolSocketFactory.java
+++ b/org.eclipse.mylyn.commons.repositories.http.core/src/org/eclipse/mylyn/commons/repositories/http/core/PollingSslProtocolSocketFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2009 Tasktop Technologies and others.
+ * Copyright (c) 2011 Tasktop Technologies 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
@@ -9,7 +9,7 @@
* Tasktop Technologies - initial API and implementation
*******************************************************************************/
-package org.eclipse.mylyn.internal.commons.http;
+package org.eclipse.mylyn.commons.repositories.http.core;
import java.io.FileInputStream;
import java.io.IOException;
@@ -30,6 +30,11 @@ import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.commons.core.net.NetUtil;
+import org.eclipse.mylyn.commons.core.net.TrustAllTrustManager;
+import org.eclipse.mylyn.commons.core.operations.MonitoredOperation;
/**
* Provides support for managing SSL connections.
@@ -38,7 +43,7 @@ import org.eclipse.core.runtime.IStatus;
* @author Rob Elves
* @author Steffen Pingel
*/
-public class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFactory {
+class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFactory {
private static final String KEY_STORE = "javax.net.ssl.keyStore"; //$NON-NLS-1$
@@ -62,7 +67,7 @@ public class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFacto
keyManagerFactory.init(keyStore, password);
keymanagers = keyManagerFactory.getKeyManagers();
} catch (Exception e) {
- CommonsHttpPlugin.log(IStatus.ERROR, "Could not initialize keystore", e); //$NON-NLS-1$
+ StatusHandler.log(new Status(IStatus.ERROR, HttpUtil.ID_PLUGIN, "Could not initialize keystore", e)); //$NON-NLS-1$
}
}
@@ -73,7 +78,7 @@ public class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFacto
sslContext.init(keymanagers, new TrustManager[] { new TrustAllTrustManager() }, null);
this.socketFactory = sslContext.getSocketFactory();
} catch (Exception e) {
- CommonsHttpPlugin.log(IStatus.ERROR, "Could not initialize SSL context", e); //$NON-NLS-1$
+ StatusHandler.log(new Status(IStatus.ERROR, HttpUtil.ID_PLUGIN, "Could not initialize SSL context", e)); //$NON-NLS-1$
}
}
@@ -93,7 +98,7 @@ public class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFacto
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
socket.bind(localAddress);
- MonitoredRequest.connect(socket, remoteAddress, connTimeout);
+ NetUtil.connect(socket, remoteAddress, connTimeout, MonitoredOperation.getCurrentOperation());
return socket;
}
@@ -102,15 +107,15 @@ public class PollingSslProtocolSocketFactory implements LayeredSchemeSocketFacto
*/
public boolean isSecure(Socket sock) throws IllegalArgumentException {
if (sock == null) {
- throw new IllegalArgumentException("Socket may not be null");
+ throw new IllegalArgumentException("Socket may not be null"); //$NON-NLS-1$
}
// This instanceof check is in line with createSocket() above.
if (!(sock instanceof SSLSocket)) {
- throw new IllegalArgumentException("Socket not created by this factory");
+ throw new IllegalArgumentException("Socket not created by this factory"); //$NON-NLS-1$
}
// This check is performed last since it calls the argument object.
if (sock.isClosed()) {
- throw new IllegalArgumentException("Socket is closed");
+ throw new IllegalArgumentException("Socket is closed"); //$NON-NLS-1$
}
return true;
}
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.classpath b/org.eclipse.mylyn.commons.repositories.http.tests/.classpath
new file mode 100644
index 0000000..8d4bac7
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.classpath
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/mylyn/internal/**"/>
+ <accessrule kind="accessible" pattern="org/eclipse/core/internal/net/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.cvsignore b/org.eclipse.mylyn.commons.repositories.http.tests/.cvsignore
new file mode 100644
index 0000000..d567ba0
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.cvsignore
@@ -0,0 +1,2 @@
+bin
+target
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.project b/org.eclipse.mylyn.commons.repositories.http.tests/.project
new file mode 100644
index 0000000..865010f
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.project
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.mylyn.commons.repositories.http.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.core.runtime.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 0000000..5a0ad22
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,2 @@
+eclipse.preferences.version=1
+line.separator=\n
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..74bc985
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,359 @@
+#Wed Mar 02 16:00:04 PST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.codeComplete.argumentPrefixes=
+org.eclipse.jdt.core.codeComplete.argumentSuffixes=
+org.eclipse.jdt.core.codeComplete.fieldPrefixes=
+org.eclipse.jdt.core.codeComplete.fieldSuffixes=
+org.eclipse.jdt.core.codeComplete.localPrefixes=
+org.eclipse.jdt.core.codeComplete.localSuffixes=
+org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
+org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
+org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
+org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=error
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled
+org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,NORMAL
+org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX
+org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_assignment=0
+org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
+org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
+org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=48
+org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
+org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
+org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
+org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80
+org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
+org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
+org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_after_package=1
+org.eclipse.jdt.core.formatter.blank_lines_before_field=1
+org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
+org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
+org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
+org.eclipse.jdt.core.formatter.blank_lines_before_method=1
+org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
+org.eclipse.jdt.core.formatter.blank_lines_before_package=0
+org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
+org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
+org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
+org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
+org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=true
+org.eclipse.jdt.core.formatter.comment.format_block_comments=false
+org.eclipse.jdt.core.formatter.comment.format_comments=true
+org.eclipse.jdt.core.formatter.comment.format_header=false
+org.eclipse.jdt.core.formatter.comment.format_html=true
+org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
+org.eclipse.jdt.core.formatter.comment.format_line_comments=false
+org.eclipse.jdt.core.formatter.comment.format_source_code=true
+org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
+org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
+org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
+org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
+org.eclipse.jdt.core.formatter.comment.line_length=120
+org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
+org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
+org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
+org.eclipse.jdt.core.formatter.compact_else_if=true
+org.eclipse.jdt.core.formatter.continuation_indentation=2
+org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
+org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off
+org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on
+org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
+org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
+org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
+org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_empty_lines=false
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
+org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
+org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
+org.eclipse.jdt.core.formatter.indentation.size=4
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
+org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
+org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
+org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
+org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
+org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
+org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
+org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
+org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
+org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
+org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
+org.eclipse.jdt.core.formatter.join_lines_in_comments=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
+org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
+org.eclipse.jdt.core.formatter.lineSplit=120
+org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=true
+org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=true
+org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
+org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
+org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
+org.eclipse.jdt.core.formatter.tabulation.char=tab
+org.eclipse.jdt.core.formatter.tabulation.size=4
+org.eclipse.jdt.core.formatter.use_on_off_tags=false
+org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
+org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
+org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..2843a88
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,63 @@
+#Wed Mar 02 16:00:08 PST 2011
+cleanup_settings_version=2
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+formatter_profile=_Mylyn based on Eclipse
+formatter_settings_version=12
+internal.default.compliance=default
+org.eclipse.jdt.ui.exception.name=e
+org.eclipse.jdt.ui.gettersetter.use.is=true
+org.eclipse.jdt.ui.javadoc=false
+org.eclipse.jdt.ui.keywordthis=false
+org.eclipse.jdt.ui.overrideannotation=true
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/*******************************************************************************\n * Copyright (c) ${year} Tasktop Technologies and others.\n * All rights reserved. This program and the accompanying materials\n * are made available under the terms of the Eclipse Public License v1.0\n * which accompanies this distribution, and is available at\n * http\://www.eclipse.org/legal/epl-v10.html\n *\n * Contributors\:\n * Tasktop Technologies - initial API and implementation\n *******************************************************************************/\n\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ignore\n${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ignore</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\n * @return the ${bare_field_name}\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\n * @param ${param} the ${bare_field_name} to set\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created JavaScript files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\n * \n */</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\n * @author ${user}\n *\n * ${tags}\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for vars" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\n * \n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding function" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\n * ${tags}\n */</template><template autoinsert\="true" context\="overridecomment_context" deleted\="false" description\="Comment for overriding functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.overridecomment" name\="overridecomment">/* (non-Jsdoc)\n * ${see_to_overridden}\n */</template><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate functions" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\n * ${tags}\n * ${see_to_target}\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.classbody" name\="classbody">\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.enumbody" name\="enumbody">\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created function stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated function stub\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.wst.jsdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_to_enhanced_for_loop=true
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=false
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_variable_declarations_final=true
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=false
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_blocks=true
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=false
+sp_cleanup.use_this_for_non_static_field_access=false
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=false
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.ltk.core.refactoring.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.ltk.core.refactoring.prefs
new file mode 100644
index 0000000..5e7f2bd
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.ltk.core.refactoring.prefs
@@ -0,0 +1,3 @@
+#Tue Aug 18 22:42:26 PDT 2009
+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs
new file mode 100644
index 0000000..d8c6d26
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.mylyn.tasks.ui.prefs
@@ -0,0 +1,4 @@
+#Mon Jun 25 03:02:37 GMT 2007
+eclipse.preferences.version=1
+project.repository.kind=bugzilla
+project.repository.url=https\://bugs.eclipse.org/bugs
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.pde.prefs b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.pde.prefs
new file mode 100644
index 0000000..e8f2d56
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/.settings/org.eclipse.pde.prefs
@@ -0,0 +1,18 @@
+#Tue Apr 15 11:07:59 PDT 2008
+compilers.incompatible-environment=1
+compilers.p.build=1
+compilers.p.deprecated=1
+compilers.p.discouraged-class=2
+compilers.p.missing-bundle-classpath-entries=1
+compilers.p.missing-packages=1
+compilers.p.no-required-att=0
+compilers.p.not-externalized-att=2
+compilers.p.unknown-attribute=0
+compilers.p.unknown-class=0
+compilers.p.unknown-element=0
+compilers.p.unknown-identifier=1
+compilers.p.unknown-resource=0
+compilers.p.unresolved-ex-points=0
+compilers.p.unresolved-import=0
+compilers.use-project=true
+eclipse.preferences.version=1
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.commons.repositories.http.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..378b698
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,31 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Mylyn Commons Tests
+Bundle-SymbolicName: org.eclipse.mylyn.commons.repositories.http.tests;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.net,
+ org.junit4;bundle-version="4.5.0",
+ org.eclipse.mylyn.commons.core,
+ org.eclipse.mylyn.commons.repositories.core,
+ org.eclipse.mylyn.commons.repositories.http.core,
+ org.eclipse.mylyn.commons.sdk.util
+Export-Package: org.eclipse.mylyn.commons.repositories.http.tests;x-internal:=true
+Bundle-Vendor: Eclipse Mylyn
+Import-Package: org.apache.commons.logging;version="[1.0.4,2.0.0)",
+ org.apache.http;version="4.1.0",
+ org.apache.http.auth;version="4.1.0",
+ org.apache.http.auth.params;version="4.1.0",
+ org.apache.http.client;version="4.1.0",
+ org.apache.http.client.methods;version="4.1.0",
+ org.apache.http.client.params;version="4.1.0",
+ org.apache.http.conn;version="4.1.0",
+ org.apache.http.conn.params;version="4.1.0",
+ org.apache.http.conn.scheme;version="4.1.0",
+ org.apache.http.impl.client;version="4.1.0",
+ org.apache.http.impl.conn;version="4.1.0",
+ org.apache.http.impl.conn.tsccm;version="4.1.0",
+ org.apache.http.params;version="4.1.0",
+ org.apache.http.protocol;version="4.1.0",
+ org.apache.http.util;version="4.1.0"
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/about.html b/org.eclipse.mylyn.commons.repositories.http.tests/about.html
new file mode 100644
index 0000000..d774b07
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/about.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
+<html>
+<head>
+<title>About</title>
+<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 25, 2008</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 (&quot;EPL&quot;). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html> \ No newline at end of file
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/build.properties b/org.eclipse.mylyn.commons.repositories.http.tests/build.properties
new file mode 100644
index 0000000..4002fdb
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/build.properties
@@ -0,0 +1,17 @@
+###############################################################################
+# Copyright (c) 2009 Tasktop Technologies 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:
+# Tasktop Technologies - initial API and implementation
+###############################################################################
+source.. = src/
+output.. = bin/
+bin.includes = .,\
+ META-INF/,\
+ about.html
+src.includes = about.html
+jre.compilation.profile = J2SE-1.5
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/pom.xml b/org.eclipse.mylyn.commons.repositories.http.tests/pom.xml
new file mode 100644
index 0000000..10feae0
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/pom.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>org.eclipse.mylyn.commons-parent</artifactId>
+ <groupId>org.eclipse.mylyn.commons</groupId>
+ <version>3.7.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.eclipse.mylyn.commons.repositories.http.tests</artifactId>
+ <version>0.9.0-SNAPSHOT</version>
+ <packaging>eclipse-test-plugin</packaging>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.eclipse.tycho</groupId>
+ <artifactId>tycho-source-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java
new file mode 100644
index 0000000..65a3fa7
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/CommonHttpClientTest.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.HttpGet;
+import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
+import org.eclipse.mylyn.commons.repositories.http.core.CommonHttpClient;
+import org.junit.Test;
+
+/**
+ * @author Steffen Pingel
+ */
+public class CommonHttpClientTest {
+
+ @Test
+ public void testGetRequest() throws Exception {
+ RepositoryLocation location = new RepositoryLocation();
+ location.setUrl("http://eclipse.org/");
+
+ HttpGet request = new HttpGet(location.getUrl());
+ CommonHttpClient client = new CommonHttpClient(location);
+ HttpResponse response = client.execute(request, null);
+ assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java
new file mode 100644
index 0000000..ff85ec8
--- /dev/null
+++ b/org.eclipse.mylyn.commons.repositories.http.tests/src/org/eclipse/mylyn/commons/repositories/http/tests/HttpUtilTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2010 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.repositories.http.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.InetSocketAddress;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.eclipse.mylyn.commons.repositories.http.core.HttpUtil;
+import org.eclipse.mylyn.commons.sdk.util.TestProxy;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Steffen Pingel
+ */
+public class HttpUtilTest {
+
+ private TestProxy testProxy;
+
+ private InetSocketAddress proxyAddress;
+
+ private DefaultHttpClient client;
+
+ private ThreadSafeClientConnManager connectionManager;
+
+ public HttpUtilTest() {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ testProxy = new TestProxy();
+ int proxyPort = testProxy.startAndWait();
+ assert proxyPort > 0;
+ proxyAddress = new InetSocketAddress("localhost", proxyPort);
+
+ connectionManager = new ThreadSafeClientConnManager();
+ client = new DefaultHttpClient() {
+ @Override
+ protected ClientConnectionManager createClientConnectionManager() {
+ return connectionManager;
+ }
+ };
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ testProxy.stop();
+ }
+
+ @Test
+ public void testGetRequestPoolConnections() throws Exception {
+ HttpRequestBase request = new HttpGet("http://" + proxyAddress.toString());
+
+ HttpUtil.configureClient(client, null);
+ assertEquals(0, connectionManager.getConnectionsInPool());
+
+ HttpResponse response = HttpUtil.execute(client, null, request, null);
+ assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
+ assertEquals(1, connectionManager.getConnectionsInPool());
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
index b37cd40..5a77c60 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
@@ -14,6 +14,8 @@ package org.eclipse.mylyn.commons.tests;
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.mylyn.commons.tests.core.CoreUtilTest;
+import org.eclipse.mylyn.commons.tests.net.NetUtilTest;
import org.eclipse.mylyn.commons.tests.net.SslProtocolSocketFactoryTest;
import org.eclipse.mylyn.commons.tests.net.TimeoutInputStreamTest;
import org.eclipse.mylyn.commons.tests.net.WebUtilTest;
@@ -25,6 +27,8 @@ public class AllCommonsTests {
public static Test suite() {
TestSuite suite = new TestSuite(AllCommonsTests.class.getName());
+ suite.addTestSuite(CoreUtilTest.class);
+ suite.addTestSuite(NetUtilTest.class);
suite.addTestSuite(SslProtocolSocketFactoryTest.class);
suite.addTestSuite(WebUtilTest.class);
suite.addTestSuite(TimeoutInputStreamTest.class);
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java
new file mode 100644
index 0000000..e053188
--- /dev/null
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/core/CoreUtilTest.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.tests.core;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.core.CoreUtil;
+
+/**
+ * @author Steffen Pingel
+ */
+public class CoreUtilTest extends TestCase {
+
+ public void testCompareNullNull() {
+ assertEquals(0, CoreUtil.compare(null, null));
+ }
+
+ public void testCompareNullString() {
+ assertEquals(1, CoreUtil.compare(null, "abc"));
+ }
+
+ public void testCompareNumbersBigger() {
+ assertEquals(1, CoreUtil.compare(4, 2));
+ }
+
+ public void testCompareNumbersEquals() {
+ assertEquals(0, CoreUtil.compare(-4, -4));
+ }
+
+ public void testCompareNumbersNull() {
+ assertEquals(1, CoreUtil.compare(null, 2));
+ }
+
+ public void testCompareNumbersSmaller() {
+ assertEquals(-1, CoreUtil.compare(1, 2));
+ }
+
+ public void testCompareStringNull() {
+ assertEquals(-1, CoreUtil.compare("abc", null));
+ }
+
+ public void testPropertyEquallsNullFalse() {
+ assertFalse(CoreUtil.propertyEquals(false, null));
+ }
+
+ public void testPropertyEquallsNullTrue() {
+ assertTrue(CoreUtil.propertyEquals(true, null));
+ }
+
+ public void testPropertyEqualsBooleanTrue() {
+ assertTrue(CoreUtil.propertyEquals(true, Boolean.TRUE));
+ }
+
+ public void testPropertyEqualsNumbe() {
+ assertFalse(CoreUtil.propertyEquals(true, 1));
+ }
+
+ public void testPropertyEqualsStringFalse() {
+ assertFalse(CoreUtil.propertyEquals(false, "false"));
+ }
+
+ public void testPropertyEqualsStringFalseUnexpected() {
+ assertFalse(CoreUtil.propertyEquals(true, "false"));
+ }
+
+ public void testPropertyEqualsStringTrue() {
+ assertFalse(CoreUtil.propertyEquals(true, "true"));
+ }
+
+}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/NetUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/NetUtilTest.java
new file mode 100644
index 0000000..f231de9
--- /dev/null
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/NetUtilTest.java
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.tests.net;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.commons.core.net.NetUtil;
+
+/**
+ * @author Steffen Pingel
+ */
+public class NetUtilTest extends TestCase {
+
+ public void testGetHostDefault() {
+ String url = "http://example.com/";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetHostEmptyPath() {
+ String url = "http://example.com";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetHostEmptyPathPort() {
+ String url = "http://example.com";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetHostNestedUrl() {
+ String url = "https://example.com:444/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetHostNestedUrlNoPort() {
+ String url = "https://example.com/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetHostPortNumber() {
+ String url = "https://example.com:444/folder/file.txt";
+ assertEquals("example.com", NetUtil.getHost(url));
+ }
+
+ public void testGetPortDefault() {
+ String url = "http://example.com/";
+ assertEquals(80, NetUtil.getPort(url));
+ }
+
+ public void testGetPortEmptyPath() {
+ String url = "http://example.com";
+ assertEquals(80, NetUtil.getPort(url));
+ }
+
+ public void testGetPortEmptyPathPort() {
+ String url = "http://example.com:321";
+ assertEquals(321, NetUtil.getPort(url));
+ }
+
+ public void testGetPortNestedUrl() {
+ String url = "https://example.com:444/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals(444, NetUtil.getPort(url));
+ }
+
+ public void testGetPortNestedUrlDefault() {
+ String url = "https://example.com/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals(443, NetUtil.getPort(url));
+ }
+
+ public void testGetPortNoProtocol() {
+ String url = "example.com:321";
+ assertEquals(321, NetUtil.getPort(url));
+ }
+
+ public void testGetPortNoProtocolDefault() {
+ String url = "example.com";
+ assertEquals(80, NetUtil.getPort(url));
+ }
+
+ public void testGetPortNumber() {
+ String url = "https://example.com:444/folder/file.txt";
+ assertEquals(444, NetUtil.getPort(url));
+ }
+
+ public void testGetRequestParameters() {
+ String url = "https://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?&pid=11093&resolution=-1&sorter/field=updated&sorter/order=DESC&tempMax=1000";
+ assertEquals(
+ "/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?&pid=11093&resolution=-1&sorter/field=updated&sorter/order=DESC&tempMax=1000",
+ NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathEmpty() {
+ String url = "http://example.com";
+ assertEquals("", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathEmptyPort() {
+ String url = "http://example.com:321";
+ assertEquals("", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathNestedUrl() {
+ String url = "https://example.com:444/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals("/folder/file.txt?search=https://example.com:812/folder/file.txt", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathNestedUrlNoPort() {
+ String url = "https://example.com/folder/file.txt?search=https://example.com:812/folder/file.txt";
+ assertEquals("/folder/file.txt?search=https://example.com:812/folder/file.txt", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathNoProtocol() {
+ String url = "example.com/folder/file";
+ assertEquals("/folder/file", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathNoProtocolEmtpyPath() {
+ String url = "example.com";
+ assertEquals("", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathPortNumber() {
+ String url = "https://example.com:444/folder/file.txt";
+ assertEquals("/folder/file.txt", NetUtil.getRequestPath(url));
+ }
+
+ public void testGetRequestPathSlash() {
+ String url = "http://example.com/";
+ assertEquals("/", NetUtil.getRequestPath(url));
+ }
+
+ public void testIsUrlHttpsValid() {
+ assertTrue(NetUtil.isUrlHttps("https://example.com"));
+ }
+
+ public void testIUrlHttpsHttpUrl() {
+ assertFalse(NetUtil.isUrlHttps("http://"));
+ }
+
+ public void testIUrlHttpsInvalid() {
+ assertFalse(NetUtil.isUrlHttps("abc"));
+ }
+
+ public void testIUrlHttpsNoHost() {
+ assertTrue(NetUtil.isUrlHttps("https://"));
+ }
+
+ public void testIUrlHttpsNoUrl() {
+ assertTrue(NetUtil.isUrlHttps("httpsabc"));
+ }
+
+ public void testIUrlHttpsTelnets() {
+ assertFalse(NetUtil.isUrlHttps("telnets://"));
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 9ada259..1407b92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,7 @@
<module>org.eclipse.mylyn.commons.repositories.ui</module>
<module>org.eclipse.mylyn.commons.repositories.http-feature</module>
<module>org.eclipse.mylyn.commons.repositories.http.core</module>
+ <module>org.eclipse.mylyn.commons.repositories.http.tests</module>
<module>org.eclipse.mylyn.commons.sdk-feature</module>
<module>org.eclipse.mylyn.commons.sdk.util</module>
<module>org.eclipse.mylyn.discovery-feature</module>