Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v
retrieving revision 1.130
diff -u -r1.130 ClasspathTests.java
--- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 25 May 2005 16:08:44 -0000 1.130
+++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 5 Sep 2005 10:39:31 -0000
@@ -75,8 +75,8 @@
// All specified tests which do not belong to the class are skipped...
static {
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
-// TESTS_PREFIX = "testClasspathDuplicateExtraAttribute";
-// TESTS_NAMES = new String[] {"testExportContainer"};
+// TESTS_PREFIX = "testUnknownElements";
+// TESTS_NAMES = new String[] {"testUnknownElements2"};
// TESTS_NUMBERS = new int[] { 23, 28, 38 };
// TESTS_RANGE = new int[] { 21, 38 };
}
@@ -3166,7 +3166,7 @@
},
null);
time[0] += System.currentTimeMillis()-start[0];
- System.out.println("No cycle check ("+numberOfParticipants+" participants) : "+ time[0]+" ms, "+ (useForwardReferences ? "forward references" : "backward references") + ", " + (createProjectsFirst ? "two steps (projects created first, then classpaths are set)" : "one step (projects created and classpaths set in one batch)"));
+ //System.out.println("No cycle check ("+numberOfParticipants+" participants) : "+ time[0]+" ms, "+ (useForwardReferences ? "forward references" : "backward references") + ", " + (createProjectsFirst ? "two steps (projects created first, then classpaths are set)" : "one step (projects created and classpaths set in one batch)"));
for (int i = 0; i < numberOfParticipants; i++){
// check cycle markers
@@ -3322,6 +3322,154 @@
}
}
+/*
+ * Ensures that unknown classpath attributes in a .classpath file are not lost when read and rewritten.
+ * (regression test for bug 101425 Classpath persistence should be resilient with unknown attributes)
+ */
+public void testUnknownAttributes() throws CoreException {
+ try {
+ IJavaProject project = createJavaProject("P");
+ editFile(
+ "/P/.classpath",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n"
+ );
+ IClasspathEntry[] classpath = project.getRawClasspath();
+
+ // swap 2 entries
+ IClasspathEntry src1 = classpath[0];
+ classpath[0] = classpath[1];
+ classpath[1] = src1;
+ project.setRawClasspath(classpath, null);
+
+ // check that .classpath has correct content
+ String contents = new String (org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(getFile("/P/.classpath")));
+ assertSourceEquals(
+ "Unexpected content",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n",
+ contents);
+ } finally {
+ deleteProject("P");
+ }
+}
+
+/*
+ * Ensures that unknown classpath elements in a .classpath file are not lost when read and rewritten.
+ * (regression test for bug 101425 Classpath persistence should be resilient with unknown attributes)
+ */
+public void testUnknownElements1() throws CoreException {
+ try {
+ IJavaProject project = createJavaProject("P");
+ editFile(
+ "/P/.classpath",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n"
+ );
+ IClasspathEntry[] classpath = project.getRawClasspath();
+
+ // swap 2 entries
+ IClasspathEntry src1 = classpath[0];
+ classpath[0] = classpath[1];
+ classpath[1] = src1;
+ project.setRawClasspath(classpath, null);
+
+ // check that .classpath has correct content
+ String contents = new String (org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(getFile("/P/.classpath")));
+ assertSourceEquals(
+ "Unexpected content",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n",
+ contents);
+ } finally {
+ deleteProject("P");
+ }
+}
+
+/*
+ * Ensures that unknown classpath elements in a .classpath file are not lost when read and rewritten.
+ * (regression test for bug 101425 Classpath persistence should be resilient with unknown attributes)
+ */
+public void testUnknownElements2() throws CoreException {
+ try {
+ IJavaProject project = createJavaProject("P");
+ editFile(
+ "/P/.classpath",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n"
+ );
+ IClasspathEntry[] classpath = project.getRawClasspath();
+
+ // swap 2 entries
+ IClasspathEntry src1 = classpath[0];
+ classpath[0] = classpath[1];
+ classpath[1] = src1;
+ project.setRawClasspath(classpath, null);
+
+ // check that .classpath has correct content
+ String contents = new String (org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(getFile("/P/.classpath")));
+ assertSourceEquals(
+ "Unexpected content",
+ "\n" +
+ "\n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ " \n" +
+ "\n",
+ contents);
+ } finally {
+ deleteProject("P");
+ }
+}
+
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=55992
* Check that Assert.AssertionFailedException exception is well catched