Lines 14-21
Link Here
|
14 |
import java.io.FileNotFoundException; |
14 |
import java.io.FileNotFoundException; |
15 |
import java.io.IOException; |
15 |
import java.io.IOException; |
16 |
import java.io.InputStream; |
16 |
import java.io.InputStream; |
17 |
import java.lang.reflect.InvocationTargetException; |
17 |
import java.net.HttpURLConnection; |
18 |
import java.lang.reflect.Method; |
|
|
19 |
import java.net.JarURLConnection; |
18 |
import java.net.JarURLConnection; |
20 |
import java.net.MalformedURLException; |
19 |
import java.net.MalformedURLException; |
21 |
import java.net.ProtocolException; |
20 |
import java.net.ProtocolException; |
Lines 30-38
Link Here
|
30 |
import java.util.Set; |
29 |
import java.util.Set; |
31 |
|
30 |
|
32 |
import org.eclipse.core.resources.IResource; |
31 |
import org.eclipse.core.resources.IResource; |
33 |
import org.eclipse.core.runtime.*; |
32 |
import org.eclipse.core.runtime.Assert; |
|
|
33 |
import org.eclipse.core.runtime.CoreException; |
34 |
import org.eclipse.core.runtime.IAdaptable; |
35 |
import org.eclipse.core.runtime.IPath; |
36 |
import org.eclipse.core.runtime.IProgressMonitor; |
37 |
import org.eclipse.core.runtime.IStatus; |
38 |
import org.eclipse.core.runtime.PlatformObject; |
34 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
39 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
35 |
import org.eclipse.jdt.core.*; |
40 |
import org.eclipse.jdt.core.IClassFile; |
|
|
41 |
import org.eclipse.jdt.core.IClasspathAttribute; |
42 |
import org.eclipse.jdt.core.IClasspathEntry; |
43 |
import org.eclipse.jdt.core.ICompilationUnit; |
44 |
import org.eclipse.jdt.core.IField; |
45 |
import org.eclipse.jdt.core.IJavaElement; |
46 |
import org.eclipse.jdt.core.IJavaModel; |
47 |
import org.eclipse.jdt.core.IJavaModelStatus; |
48 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
49 |
import org.eclipse.jdt.core.IJavaProject; |
50 |
import org.eclipse.jdt.core.IMember; |
51 |
import org.eclipse.jdt.core.IOpenable; |
52 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
53 |
import org.eclipse.jdt.core.IParent; |
54 |
import org.eclipse.jdt.core.ISourceRange; |
55 |
import org.eclipse.jdt.core.ISourceReference; |
56 |
import org.eclipse.jdt.core.JavaModelException; |
57 |
import org.eclipse.jdt.core.WorkingCopyOwner; |
36 |
import org.eclipse.jdt.core.dom.ASTNode; |
58 |
import org.eclipse.jdt.core.dom.ASTNode; |
37 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
59 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
38 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
60 |
import org.eclipse.jdt.internal.compiler.lookup.Binding; |
Lines 806-847
Link Here
|
806 |
} |
828 |
} |
807 |
} |
829 |
} |
808 |
|
830 |
|
809 |
/* |
|
|
810 |
* We don't use getContentEncoding() on the URL connection, because it might leave open streams behind. |
811 |
* See https://bugs.eclipse.org/bugs/show_bug.cgi?id=117890 |
812 |
*/ |
813 |
protected String getURLContents(URL baseLoc, String docUrlValue) throws JavaModelException { |
831 |
protected String getURLContents(URL baseLoc, String docUrlValue) throws JavaModelException { |
814 |
InputStream stream = null; |
832 |
InputStream stream = null; |
815 |
JarURLConnection connection2 = null; |
833 |
JarURLConnection connection2 = null; |
816 |
try { |
834 |
try { |
817 |
URL docUrl = new URL(docUrlValue); |
835 |
URL docUrl = null; |
818 |
URLConnection connection = docUrl.openConnection(); |
836 |
URLConnection connection = null; |
819 |
Class[] parameterTypes = new Class[]{int.class}; |
837 |
redirect: for (int i= 0; i < 5; i++) { // avoid endless redirects... |
820 |
Integer timeoutVal = new Integer(10000); |
838 |
docUrl = new URL(docUrlValue); |
821 |
// set the connect and read timeouts using reflection since these methods are not available in java 1.4 |
839 |
connection = docUrl.openConnection(); |
822 |
Class URLClass = connection.getClass(); |
840 |
|
823 |
try { |
841 |
int timeoutVal = 10000; |
824 |
Method connectTimeoutMethod = URLClass.getDeclaredMethod("setConnectTimeout", parameterTypes); //$NON-NLS-1$ |
842 |
connection.setConnectTimeout(timeoutVal); |
825 |
Method readTimeoutMethod = URLClass.getDeclaredMethod("setReadTimeout", parameterTypes); //$NON-NLS-1$ |
843 |
connection.setReadTimeout(timeoutVal); |
826 |
connectTimeoutMethod.invoke(connection, new Object[]{timeoutVal}); |
844 |
|
827 |
readTimeoutMethod.invoke(connection, new Object[]{timeoutVal}); |
845 |
if (connection instanceof HttpURLConnection) { |
828 |
} catch (SecurityException e) { |
846 |
// HttpURLConnection doesn't redirect from http to https, see https://bugs.eclipse.org/450684 |
829 |
// ignore |
847 |
HttpURLConnection httpCon = (HttpURLConnection) connection; |
830 |
} catch (IllegalArgumentException e) { |
848 |
if (httpCon.getResponseCode() == 301) { |
831 |
// ignore |
849 |
docUrlValue = httpCon.getHeaderField("location"); //$NON-NLS-1$ |
832 |
} catch (NoSuchMethodException e) { |
850 |
if (docUrlValue != null) { |
833 |
// ignore |
851 |
continue redirect; |
834 |
} catch (IllegalAccessException e) { |
852 |
} |
835 |
// ignore |
853 |
} |
836 |
} catch (InvocationTargetException e) { |
854 |
} else if (connection instanceof JarURLConnection) { |
837 |
// ignore |
855 |
connection2 = (JarURLConnection) connection; |
|
|
856 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=156307 |
857 |
connection.setUseCaches(false); |
858 |
} |
859 |
break; |
838 |
} |
860 |
} |
839 |
|
861 |
|
840 |
if (connection instanceof JarURLConnection) { |
|
|
841 |
connection2 = (JarURLConnection) connection; |
842 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=156307 |
843 |
connection.setUseCaches(false); |
844 |
} |
845 |
try { |
862 |
try { |
846 |
stream = new BufferedInputStream(connection.getInputStream()); |
863 |
stream = new BufferedInputStream(connection.getInputStream()); |
847 |
} catch (IllegalArgumentException e) { |
864 |
} catch (IllegalArgumentException e) { |