Lines 37-42
Link Here
|
37 |
import org.eclipse.jdt.core.ISourceReference; |
37 |
import org.eclipse.jdt.core.ISourceReference; |
38 |
import org.eclipse.jdt.core.JavaCore; |
38 |
import org.eclipse.jdt.core.JavaCore; |
39 |
import org.eclipse.jdt.core.JavaModelException; |
39 |
import org.eclipse.jdt.core.JavaModelException; |
|
|
40 |
import org.eclipse.jdt.core.compiler.CharOperation; |
40 |
import org.eclipse.jdt.core.search.IJavaSearchConstants; |
41 |
import org.eclipse.jdt.core.search.IJavaSearchConstants; |
41 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
42 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
42 |
import org.eclipse.jdt.core.search.SearchEngine; |
43 |
import org.eclipse.jdt.core.search.SearchEngine; |
Lines 463-481
Link Here
|
463 |
* Verification is done by comparing source with file contents read directly with UTF-8 encoding... |
464 |
* Verification is done by comparing source with file contents read directly with UTF-8 encoding... |
464 |
*/ |
465 |
*/ |
465 |
public void test022() throws JavaModelException, CoreException { |
466 |
public void test022() throws JavaModelException, CoreException { |
|
|
467 |
String oldEncoding = this.encodingProject.getDefaultCharset(); |
468 |
try{ |
469 |
// Set project encoding |
470 |
String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; |
471 |
this.encodingProject.setDefaultCharset(vmEncoding, null); |
466 |
|
472 |
|
467 |
// Set project encoding |
473 |
// Get class file and compare source (should not be the same as modify charset on zip file has no effect...) |
468 |
String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; |
474 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding", "testUTF8.jar"); |
469 |
this.encodingProject.setDefaultCharset(encoding, null); |
475 |
this.utf8Source = root.getPackageFragment("testUTF8").getClassFile("Test.class"); |
470 |
|
476 |
assertNotNull(this.utf8Source); |
471 |
// Get class file and compare source (should not be the same as modify charset on zip file has no effect...) |
477 |
String source = this.utf8Source.getSource(); |
472 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding", "testUTF8.jar"); |
478 |
assertNotNull(source); |
473 |
this.utf8Source = root.getPackageFragment("testUTF8").getClassFile("Test.class"); |
479 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(this.utf8File, encoding)); |
474 |
assertNotNull(this.utf8Source); |
480 |
assertFalse("Sources should not be the same as they were decoded with different encoding!", encodedContents.equals(source)); |
475 |
String source = this.utf8Source.getSource(); |
481 |
} |
476 |
assertNotNull(source); |
482 |
finally{ |
477 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(this.utf8File, encoding)); |
483 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
478 |
assertFalse("Sources should not be the same as they were decoded with different encoding!", encodedContents.equals(source)); |
484 |
} |
479 |
} |
485 |
} |
480 |
|
486 |
|
481 |
/* |
487 |
/* |
Lines 483-506
Link Here
|
483 |
* Verification is done by comparing source with file contents read directly with UTF-8 encoding... |
489 |
* Verification is done by comparing source with file contents read directly with UTF-8 encoding... |
484 |
*/ |
490 |
*/ |
485 |
public void test023() throws JavaModelException, CoreException { |
491 |
public void test023() throws JavaModelException, CoreException { |
486 |
|
|
|
487 |
// Set file encoding |
488 |
String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; |
489 |
IFile zipFile = (IFile) this.encodingProject.findMember("testUTF8.zip"); //$NON-NLS-1$ |
492 |
IFile zipFile = (IFile) this.encodingProject.findMember("testUTF8.zip"); //$NON-NLS-1$ |
490 |
assertNotNull("Cannot find class file!", zipFile); |
493 |
try { |
491 |
zipFile.setCharset(encoding, null); |
494 |
// Set file encoding |
492 |
|
495 |
String encoding = "UTF-8".equals(vmEncoding) ? "Cp1252" : "UTF-8"; |
493 |
// Get class file and compare source (should not be the same as modify charset on zip file has no effect...) |
496 |
assertNotNull("Cannot find class file!", zipFile); |
494 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding", "testUTF8.jar"); |
497 |
zipFile.setCharset(vmEncoding, null); |
495 |
this.utf8Source = root.getPackageFragment("testUTF8").getClassFile("Test.class"); |
|
|
496 |
assertNotNull(this.utf8Source); |
497 |
String source = this.utf8Source.getSource(); |
498 |
assertNotNull(source); |
499 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(this.utf8File, encoding)); |
500 |
assertFalse("Sources should not be the same as they were decoded with different encoding!", encodedContents.equals(source)); |
501 |
|
498 |
|
502 |
// Reset zip file encoding |
499 |
// Get class file and compare source (should not be the same as modify charset on zip file has no effect...) |
503 |
zipFile.setCharset(null, null); |
500 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding", "testUTF8.jar"); |
|
|
501 |
this.utf8Source = root.getPackageFragment("testUTF8").getClassFile("Test.class"); |
502 |
assertNotNull(this.utf8Source); |
503 |
String source = this.utf8Source.getSource(); |
504 |
assertNotNull(source); |
505 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(this.utf8File, encoding)); |
506 |
assertFalse("Sources should not be the same as they were decoded with different encoding!", encodedContents.equals(source)); |
507 |
} |
508 |
finally { |
509 |
// Reset zip file encoding |
510 |
zipFile.setCharset(null, null); |
511 |
} |
504 |
} |
512 |
} |
505 |
|
513 |
|
506 |
/** |
514 |
/** |
Lines 959-965
Link Here
|
959 |
assertNotNull(sourceRef); |
967 |
assertNotNull(sourceRef); |
960 |
String source = sourceRef.getSource(); |
968 |
String source = sourceRef.getSource(); |
961 |
assertNotNull(source); |
969 |
assertNotNull(source); |
|
|
970 |
char[] charArray = source.toCharArray(); |
971 |
source = new String(CharOperation.remove(charArray, '\r')); |
962 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
972 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
973 |
charArray = encodedContents.toCharArray(); |
974 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
963 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
975 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
964 |
|
976 |
|
965 |
// Reset zip file encoding |
977 |
// Reset zip file encoding |
Lines 973-978
Link Here
|
973 |
source = sourceRef.getSource(); |
985 |
source = sourceRef.getSource(); |
974 |
assertNotNull(source); |
986 |
assertNotNull(source); |
975 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
987 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
988 |
charArray = encodedContents.toCharArray(); |
989 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
990 |
charArray = source.toCharArray(); |
991 |
source = new String(CharOperation.remove(charArray, '\r')); |
976 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
992 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
977 |
|
993 |
|
978 |
this.encodingProject.setDefaultCharset(null, null); |
994 |
this.encodingProject.setDefaultCharset(null, null); |
Lines 983-988
Link Here
|
983 |
source = sourceRef.getSource(); |
999 |
source = sourceRef.getSource(); |
984 |
assertNotNull(source); |
1000 |
assertNotNull(source); |
985 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1001 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1002 |
charArray = encodedContents.toCharArray(); |
1003 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1004 |
charArray = source.toCharArray(); |
1005 |
source = new String(CharOperation.remove(charArray, '\r')); |
986 |
assertFalse("Sources should be decoded the same way", encodedContents.equals(source)); |
1006 |
assertFalse("Sources should be decoded the same way", encodedContents.equals(source)); |
987 |
|
1007 |
|
988 |
// Reset zip file encoding |
1008 |
// Reset zip file encoding |
Lines 1033-1038
Link Here
|
1033 |
String source = sourceRef.getSource(); |
1053 |
String source = sourceRef.getSource(); |
1034 |
assertNotNull(source); |
1054 |
assertNotNull(source); |
1035 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1055 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1056 |
char[] charArray = encodedContents.toCharArray(); |
1057 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1058 |
charArray = source.toCharArray(); |
1059 |
source = new String(CharOperation.remove(charArray, '\r')); |
1036 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1060 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1037 |
|
1061 |
|
1038 |
entries = this.encodingJavaProject.getRawClasspath(); |
1062 |
entries = this.encodingJavaProject.getRawClasspath(); |
Lines 1099-1104
Link Here
|
1099 |
String source = sourceRef.getSource(); |
1123 |
String source = sourceRef.getSource(); |
1100 |
assertNotNull(source); |
1124 |
assertNotNull(source); |
1101 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1125 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1126 |
char[] charArray = encodedContents.toCharArray(); |
1127 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1128 |
charArray = source.toCharArray(); |
1129 |
source = new String(CharOperation.remove(charArray, '\r')); |
1102 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1130 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1103 |
|
1131 |
|
1104 |
zipFile.setCharset(null, null); |
1132 |
zipFile.setCharset(null, null); |
Lines 1110-1115
Link Here
|
1110 |
source = sourceRef.getSource(); |
1138 |
source = sourceRef.getSource(); |
1111 |
assertNotNull(source); |
1139 |
assertNotNull(source); |
1112 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1140 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1141 |
charArray = encodedContents.toCharArray(); |
1142 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1143 |
charArray = source.toCharArray(); |
1144 |
source = new String(CharOperation.remove(charArray, '\r')); |
1113 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1145 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1114 |
|
1146 |
|
1115 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
1147 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
Lines 1157-1162
Link Here
|
1157 |
String source = sourceRef.getSource(); |
1189 |
String source = sourceRef.getSource(); |
1158 |
assertNotNull(source); |
1190 |
assertNotNull(source); |
1159 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1191 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1192 |
char[] charArray = encodedContents.toCharArray(); |
1193 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1194 |
charArray = source.toCharArray(); |
1195 |
source = new String(CharOperation.remove(charArray, '\r')); |
1160 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1196 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1161 |
|
1197 |
|
1162 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
1198 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
Lines 1168-1173
Link Here
|
1168 |
source = sourceRef.getSource(); |
1204 |
source = sourceRef.getSource(); |
1169 |
assertNotNull(source); |
1205 |
assertNotNull(source); |
1170 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1206 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
|
|
1207 |
charArray = encodedContents.toCharArray(); |
1208 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1209 |
charArray = source.toCharArray(); |
1210 |
source = new String(CharOperation.remove(charArray, '\r')); |
1171 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1211 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1172 |
|
1212 |
|
1173 |
sourceFile.setCharset(null, null); |
1213 |
sourceFile.setCharset(null, null); |