Lines 28-33
Link Here
|
28 |
import org.eclipse.core.runtime.content.IContentDescription; |
28 |
import org.eclipse.core.runtime.content.IContentDescription; |
29 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
29 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
30 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
30 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
|
|
31 |
import org.eclipse.jdt.core.IClasspathAttribute; |
31 |
import org.eclipse.jdt.core.IClasspathEntry; |
32 |
import org.eclipse.jdt.core.IClasspathEntry; |
32 |
import org.eclipse.jdt.core.ICompilationUnit; |
33 |
import org.eclipse.jdt.core.ICompilationUnit; |
33 |
import org.eclipse.jdt.core.IJavaProject; |
34 |
import org.eclipse.jdt.core.IJavaProject; |
Lines 62-68
Link Here
|
62 |
// Use this static initializer to specify subset for tests |
63 |
// Use this static initializer to specify subset for tests |
63 |
// All specified tests which do not belong to the class are skipped... |
64 |
// All specified tests which do not belong to the class are skipped... |
64 |
static { |
65 |
static { |
65 |
// TESTS_NAMES = new String[] { "testBug110576" }; |
66 |
// TESTS_NAMES = new String[] { "testBug361356" }; |
66 |
// TESTS_NUMBERS = new int[] { 2, 12 }; |
67 |
// TESTS_NUMBERS = new int[] { 2, 12 }; |
67 |
// TESTS_RANGE = new int[] { 16, -1 }; |
68 |
// TESTS_RANGE = new int[] { 16, -1 }; |
68 |
} |
69 |
} |
Lines 1217-1223
Link Here
|
1217 |
getWorkspaceRoot().setDefaultCharset(wkspEncoding, null); |
1218 |
getWorkspaceRoot().setDefaultCharset(wkspEncoding, null); |
1218 |
} |
1219 |
} |
1219 |
} |
1220 |
} |
1220 |
|
1221 |
public void testBug361356() throws Exception { |
|
|
1222 |
String oldEncoding = this.encodingProject.getDefaultCharset(); |
1223 |
try{ |
1224 |
String encoding = "Shift-JIS"; |
1225 |
if (wkspEncoding.equals(encoding)) |
1226 |
getWorkspaceRoot().setDefaultCharset("UTF-8", null); |
1227 |
this.encodingProject.setDefaultCharset("UTF-8", null); |
1228 |
IJavaProject project = this.createJavaProject("Encoding2", new String[] {""}, ""); |
1229 |
IFile zipFile = (IFile) this.encodingProject.findMember("testShiftJIS.zip"); //$NON-NLS-1$ |
1230 |
IFile sourceFile = (IFile) this.encodingProject.findMember("src/testShiftJIS/A.java"); |
1231 |
|
1232 |
IClasspathEntry[] entries = this.encodingJavaProject.getRawClasspath(); |
1233 |
IClasspathEntry newEntry = null; |
1234 |
for (int index = 0; index < entries.length; index++) { |
1235 |
IClasspathEntry entry = entries[index]; |
1236 |
if (entry.getPath().toOSString().endsWith("testShiftJIS.jar")) { |
1237 |
newEntry = entries[index]; |
1238 |
} |
1239 |
} |
1240 |
|
1241 |
IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding); |
1242 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/src"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1243 |
sourceFile.setCharset(null, null); |
1244 |
|
1245 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1246 |
ISourceReference sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1247 |
assertNotNull(sourceRef); |
1248 |
String source = sourceRef.getSource(); |
1249 |
assertNotNull(source); |
1250 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1251 |
char[] charArray = encodedContents.toCharArray(); |
1252 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1253 |
charArray = source.toCharArray(); |
1254 |
source = new String(CharOperation.remove(charArray, '\r')); |
1255 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1256 |
|
1257 |
attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8"); |
1258 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/src"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1259 |
sourceFile.setCharset(encoding, null); |
1260 |
|
1261 |
root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1262 |
sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1263 |
assertNotNull(sourceRef); |
1264 |
source = sourceRef.getSource(); |
1265 |
assertNotNull(source); |
1266 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1267 |
charArray = encodedContents.toCharArray(); |
1268 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1269 |
charArray = source.toCharArray(); |
1270 |
source = new String(CharOperation.remove(charArray, '\r')); |
1271 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1272 |
|
1273 |
attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding); |
1274 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1275 |
zipFile.setCharset(null, null); |
1276 |
|
1277 |
root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1278 |
sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1279 |
assertNotNull(sourceRef); |
1280 |
source = sourceRef.getSource(); |
1281 |
assertNotNull(source); |
1282 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1283 |
charArray = encodedContents.toCharArray(); |
1284 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1285 |
charArray = source.toCharArray(); |
1286 |
source = new String(CharOperation.remove(charArray, '\r')); |
1287 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1288 |
|
1289 |
attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8"); |
1290 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1291 |
zipFile.setCharset(encoding, null); |
1292 |
|
1293 |
root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1294 |
sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1295 |
assertNotNull(sourceRef); |
1296 |
source = sourceRef.getSource(); |
1297 |
assertNotNull(source); |
1298 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1299 |
charArray = encodedContents.toCharArray(); |
1300 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1301 |
charArray = source.toCharArray(); |
1302 |
source = new String(CharOperation.remove(charArray, '\r')); |
1303 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1304 |
|
1305 |
} |
1306 |
finally { |
1307 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
1308 |
deleteProject("Encoding2"); |
1309 |
getWorkspaceRoot().setDefaultCharset(wkspEncoding, null); |
1310 |
} |
1311 |
} |
1312 |
public void testBug361356a() throws Exception { |
1313 |
String oldEncoding = this.encodingProject.getDefaultCharset(); |
1314 |
try{ |
1315 |
String encoding = "Shift-JIS"; |
1316 |
if (wkspEncoding.equals(encoding)) |
1317 |
getWorkspaceRoot().setDefaultCharset("UTF-8", null); |
1318 |
this.encodingProject.setDefaultCharset("UTF-8", null); |
1319 |
IJavaProject project = this.createJavaProject("Encoding2", new String[] {""}, ""); |
1320 |
IFile zipFile = (IFile) this.encodingProject.findMember("testShiftJIS.zip"); //$NON-NLS-1$ |
1321 |
IFile sourceFile = (IFile) this.encodingProject.findMember("src/testShiftJIS/A.java"); |
1322 |
|
1323 |
IClasspathEntry[] entries = this.encodingJavaProject.getRawClasspath(); |
1324 |
IClasspathEntry newEntry = null; |
1325 |
for (int index = 0; index < entries.length; index++) { |
1326 |
IClasspathEntry entry = entries[index]; |
1327 |
if (entry.getPath().toOSString().endsWith("testShiftJIS.jar")) { |
1328 |
newEntry = entries[index]; |
1329 |
} |
1330 |
} |
1331 |
|
1332 |
IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding); |
1333 |
attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, encoding); |
1334 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1335 |
zipFile.setCharset(null, null); |
1336 |
|
1337 |
IPackageFragmentRoot root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1338 |
ISourceReference sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1339 |
assertNotNull(sourceRef); |
1340 |
String source = sourceRef.getSource(); |
1341 |
assertNotNull(source); |
1342 |
String encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1343 |
char[] charArray = encodedContents.toCharArray(); |
1344 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1345 |
charArray = source.toCharArray(); |
1346 |
source = new String(CharOperation.remove(charArray, '\r')); |
1347 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1348 |
|
1349 |
attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, "UTF-8"); |
1350 |
project.setRawClasspath(new IClasspathEntry[]{JavaCore.newLibraryEntry(newEntry.getPath(), new Path("/Encoding/testShiftJIS.zip"), null, null, new IClasspathAttribute[]{attribute}, false)}, null); |
1351 |
zipFile.setCharset(encoding, null); |
1352 |
|
1353 |
root = getPackageFragmentRoot("Encoding2", "testShiftJIS.jar"); |
1354 |
sourceRef = root.getPackageFragment("testShiftJIS").getClassFile("A.class"); |
1355 |
assertNotNull(sourceRef); |
1356 |
source = sourceRef.getSource(); |
1357 |
assertNotNull(source); |
1358 |
encodedContents = new String (Util.getResourceContentsAsCharArray(sourceFile, encoding)); |
1359 |
charArray = encodedContents.toCharArray(); |
1360 |
encodedContents = new String(CharOperation.remove(charArray, '\r')); |
1361 |
charArray = source.toCharArray(); |
1362 |
source = new String(CharOperation.remove(charArray, '\r')); |
1363 |
assertTrue("Sources should be decoded the same way", encodedContents.equals(source)); |
1364 |
} |
1365 |
finally { |
1366 |
this.encodingProject.setDefaultCharset(oldEncoding, null); |
1367 |
deleteProject("Encoding2"); |
1368 |
getWorkspaceRoot().setDefaultCharset(wkspEncoding, null); |
1369 |
} |
1370 |
} |
1221 |
private void verifyUtf8BOM(IFile file) throws CoreException { |
1371 |
private void verifyUtf8BOM(IFile file) throws CoreException { |
1222 |
assertNull("File should not have any explicit charset", file.getCharset(false)); |
1372 |
assertNull("File should not have any explicit charset", file.getCharset(false)); |
1223 |
IContentDescription contentDescription = file.getContentDescription(); |
1373 |
IContentDescription contentDescription = file.getContentDescription(); |