Lines 41-46
Link Here
|
41 |
import org.eclipse.core.runtime.Path; |
41 |
import org.eclipse.core.runtime.Path; |
42 |
import org.eclipse.core.runtime.Preferences; |
42 |
import org.eclipse.core.runtime.Preferences; |
43 |
import org.eclipse.core.runtime.QualifiedName; |
43 |
import org.eclipse.core.runtime.QualifiedName; |
|
|
44 |
import org.eclipse.core.runtime.content.IContentDescription; |
44 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
45 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
45 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
46 |
import org.eclipse.core.runtime.preferences.IScopeContext; |
46 |
import org.eclipse.jdt.core.IClasspathContainer; |
47 |
import org.eclipse.jdt.core.IClasspathContainer; |
Lines 2024-2029
Link Here
|
2024 |
public int hashCode() { |
2025 |
public int hashCode() { |
2025 |
return this.project.hashCode(); |
2026 |
return this.project.hashCode(); |
2026 |
} |
2027 |
} |
|
|
2028 |
|
2029 |
private boolean hasUTF8BOM(byte[] bytes) { |
2030 |
if (bytes.length > IContentDescription.BOM_UTF_8.length) { |
2031 |
for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) { |
2032 |
if (IContentDescription.BOM_UTF_8[i] != bytes[i]) |
2033 |
return false; |
2034 |
} |
2035 |
return true; |
2036 |
} |
2037 |
return false; |
2038 |
} |
2027 |
|
2039 |
|
2028 |
/** |
2040 |
/** |
2029 |
* Answers true if the project potentially contains any source. A project which has no source is immutable. |
2041 |
* Answers true if the project potentially contains any source. A project which has no source is immutable. |
Lines 2354-2370
Link Here
|
2354 |
* Throws exceptions if the file cannot be accessed or is malformed. |
2366 |
* Throws exceptions if the file cannot be accessed or is malformed. |
2355 |
*/ |
2367 |
*/ |
2356 |
public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException { |
2368 |
public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException { |
2357 |
String xmlClasspath; |
|
|
2358 |
IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME); |
2369 |
IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME); |
|
|
2370 |
byte[] bytes; |
2359 |
if (rscFile.exists()) { |
2371 |
if (rscFile.exists()) { |
2360 |
byte[] bytes = Util.getResourceContentsAsByteArray(rscFile); |
2372 |
bytes = Util.getResourceContentsAsByteArray(rscFile); |
2361 |
try { |
|
|
2362 |
xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 |
2363 |
} catch (UnsupportedEncodingException e) { |
2364 |
Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ |
2365 |
// fallback to default |
2366 |
xmlClasspath = new String(bytes); |
2367 |
} |
2368 |
} else { |
2373 |
} else { |
2369 |
// when a project is imported, we get a first delta for the addition of the .project, but the .classpath is not accessible |
2374 |
// when a project is imported, we get a first delta for the addition of the .project, but the .classpath is not accessible |
2370 |
// so default to using java.io.File |
2375 |
// so default to using java.io.File |
Lines 2375-2381
Link Here
|
2375 |
File file = Util.toLocalFile(location, null/*no progress monitor available*/); |
2380 |
File file = Util.toLocalFile(location, null/*no progress monitor available*/); |
2376 |
if (file == null) |
2381 |
if (file == null) |
2377 |
throw new IOException("Unable to fetch file from " + location); //$NON-NLS-1$ |
2382 |
throw new IOException("Unable to fetch file from " + location); //$NON-NLS-1$ |
2378 |
byte[] bytes; |
|
|
2379 |
try { |
2383 |
try { |
2380 |
bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file); |
2384 |
bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file); |
2381 |
} catch (IOException e) { |
2385 |
} catch (IOException e) { |
Lines 2383-2395
Link Here
|
2383 |
return defaultClasspath(); |
2387 |
return defaultClasspath(); |
2384 |
throw e; |
2388 |
throw e; |
2385 |
} |
2389 |
} |
2386 |
try { |
2390 |
} |
2387 |
xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 |
2391 |
if (hasUTF8BOM(bytes)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=240034 |
2388 |
} catch (UnsupportedEncodingException e) { |
2392 |
int length = bytes.length-IContentDescription.BOM_UTF_8.length; |
2389 |
Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ |
2393 |
System.arraycopy(bytes, IContentDescription.BOM_UTF_8.length, bytes = new byte[length], 0, length); |
2390 |
// fallback to default |
2394 |
} |
2391 |
xmlClasspath = new String(bytes); |
2395 |
String xmlClasspath; |
2392 |
} |
2396 |
try { |
|
|
2397 |
xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 |
2398 |
} catch (UnsupportedEncodingException e) { |
2399 |
Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ |
2400 |
// fallback to default |
2401 |
xmlClasspath = new String(bytes); |
2393 |
} |
2402 |
} |
2394 |
return decodeClasspath(xmlClasspath, unknownElements); |
2403 |
return decodeClasspath(xmlClasspath, unknownElements); |
2395 |
} |
2404 |
} |