Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111947 Details for
Bug 240034
[buildpath] Eclipse ignores .classpath file if it is encoded in UTF8 with BOM
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix and regression test
240034.txt (text/plain), 6.29 KB, created by
Jerome Lanneluc
on 2008-09-08 07:18:29 EDT
(
hide
)
Description:
Proposed fix and regression test
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2008-09-08 07:18:29 EDT
Size:
6.29 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v >retrieving revision 1.184 >diff -u -r1.184 ClasspathTests.java >--- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 5 Sep 2008 10:29:20 -0000 1.184 >+++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 8 Sep 2008 11:16:30 -0000 >@@ -39,6 +39,7 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.content.IContentDescription; > import org.eclipse.jdt.core.IAccessRule; > import org.eclipse.jdt.core.IClasspathAttribute; > import org.eclipse.jdt.core.IClasspathContainer; >@@ -2333,7 +2334,7 @@ > * Ensures that a source folder that contains character that must be encoded can be written. > * (regression test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=70193) > */ >-public void testEncoding() throws CoreException { >+public void testEncoding1() throws CoreException { > try { > createJavaProject("P", new String[] {"src\u3400"}, "bin"); > IFile file = getFile("/P/.classpath"); >@@ -2351,6 +2352,35 @@ > } > } > /* >+ * Ensures that a .classpath encoded with a BOM can be read >+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=240034 ) >+ */ >+public void testEncoding2() throws Exception { >+ try { >+ IJavaProject p = createJavaProject("P", new String[] {"src"}, "bin"); >+ IFile file = getFile("/P/.classpath"); >+ byte[] contents = org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsByteArray(file); >+ FileOutputStream output = null; >+ try { >+ output = new FileOutputStream(file.getLocation().toFile()); >+ output.write(IContentDescription.BOM_UTF_8); // UTF-8 BOM >+ output.write(contents); >+ output.flush(); >+ } finally { >+ if (output != null) >+ output.close(); >+ } >+ file.refreshLocal(IResource.DEPTH_ONE, null); >+ >+ assertClasspathEquals( >+ p.getResolvedClasspath(false), >+ "/P/src[CPE_SOURCE][K_SOURCE][isExported:false]" >+ ); >+ } finally { >+ deleteProject("P"); >+ } >+} >+/* > * Ensures that a source classpath entry can be encoded and decoded. > */ > public void testEncodeDecodeEntry01() { >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.412 >diff -u -r1.412 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 5 Sep 2008 08:53:01 -0000 1.412 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 8 Sep 2008 11:16:32 -0000 >@@ -41,6 +41,7 @@ > import org.eclipse.core.runtime.Path; > import org.eclipse.core.runtime.Preferences; > import org.eclipse.core.runtime.QualifiedName; >+import org.eclipse.core.runtime.content.IContentDescription; > import org.eclipse.core.runtime.preferences.IEclipsePreferences; > import org.eclipse.core.runtime.preferences.IScopeContext; > import org.eclipse.jdt.core.IClasspathContainer; >@@ -2024,6 +2025,17 @@ > public int hashCode() { > return this.project.hashCode(); > } >+ >+ private boolean hasUTF8BOM(byte[] bytes) { >+ if (bytes.length > IContentDescription.BOM_UTF_8.length) { >+ for (int i = 0, length = IContentDescription.BOM_UTF_8.length; i < length; i++) { >+ if (IContentDescription.BOM_UTF_8[i] != bytes[i]) >+ return false; >+ } >+ return true; >+ } >+ return false; >+ } > > /** > * Answers true if the project potentially contains any source. A project which has no source is immutable. >@@ -2354,17 +2366,10 @@ > * Throws exceptions if the file cannot be accessed or is malformed. > */ > public IClasspathEntry[] readFileEntriesWithException(Map unknownElements) throws CoreException, IOException, ClasspathEntry.AssertionFailedException { >- String xmlClasspath; > IFile rscFile = this.project.getFile(JavaProject.CLASSPATH_FILENAME); >+ byte[] bytes; > if (rscFile.exists()) { >- byte[] bytes = Util.getResourceContentsAsByteArray(rscFile); >- try { >- xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 >- } catch (UnsupportedEncodingException e) { >- Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ >- // fallback to default >- xmlClasspath = new String(bytes); >- } >+ bytes = Util.getResourceContentsAsByteArray(rscFile); > } else { > // when a project is imported, we get a first delta for the addition of the .project, but the .classpath is not accessible > // so default to using java.io.File >@@ -2375,7 +2380,6 @@ > File file = Util.toLocalFile(location, null/*no progress monitor available*/); > if (file == null) > throw new IOException("Unable to fetch file from " + location); //$NON-NLS-1$ >- byte[] bytes; > try { > bytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file); > } catch (IOException e) { >@@ -2383,13 +2387,18 @@ > return defaultClasspath(); > throw e; > } >- try { >- xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 >- } catch (UnsupportedEncodingException e) { >- Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ >- // fallback to default >- xmlClasspath = new String(bytes); >- } >+ } >+ if (hasUTF8BOM(bytes)) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=240034 >+ int length = bytes.length-IContentDescription.BOM_UTF_8.length; >+ System.arraycopy(bytes, IContentDescription.BOM_UTF_8.length, bytes = new byte[length], 0, length); >+ } >+ String xmlClasspath; >+ try { >+ xmlClasspath = new String(bytes, org.eclipse.jdt.internal.compiler.util.Util.UTF_8); // .classpath always encoded with UTF-8 >+ } catch (UnsupportedEncodingException e) { >+ Util.log(e, "Could not read .classpath with UTF-8 encoding"); //$NON-NLS-1$ >+ // fallback to default >+ xmlClasspath = new String(bytes); > } > return decodeClasspath(xmlClasspath, unknownElements); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 240034
: 111947