Lines 26-31
Link Here
|
26 |
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer; |
26 |
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer; |
27 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
27 |
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
28 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
28 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
|
|
29 |
import org.eclipse.jdt.internal.core.PackageFragmentRoot; |
29 |
import org.eclipse.jdt.internal.core.UserLibrary; |
30 |
import org.eclipse.jdt.internal.core.UserLibrary; |
30 |
import org.eclipse.jdt.internal.core.UserLibraryManager; |
31 |
import org.eclipse.jdt.internal.core.UserLibraryManager; |
31 |
import org.eclipse.jdt.internal.core.util.Util; |
32 |
import org.eclipse.jdt.internal.core.util.Util; |
Lines 1041-1046
Link Here
|
1041 |
JavaCore.removeClasspathVariable("MyVar", null); |
1042 |
JavaCore.removeClasspathVariable("MyVar", null); |
1042 |
} |
1043 |
} |
1043 |
} |
1044 |
} |
|
|
1045 |
/** |
1046 |
* @bug 162104: NPE in PackageExplorerContentProvider.getPackageFragmentRoots() |
1047 |
* @test That a JME is thrown when a classpath entry is no longer on the classpath |
1048 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162104" |
1049 |
*/ |
1050 |
public void testPackageFragmentRootNullRawEntry() throws CoreException, IOException { |
1051 |
File libDir = null; |
1052 |
try { |
1053 |
String libPath = getExternalPath() + "lib"; |
1054 |
JavaCore.setClasspathVariable("MyVar", new Path(libPath), null); |
1055 |
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); |
1056 |
libDir = new File(libPath); |
1057 |
libDir.mkdirs(); |
1058 |
final int length = 10; |
1059 |
IClasspathEntry[] classpath = new IClasspathEntry[length]; |
1060 |
for (int i = 0; i < length; i++){ |
1061 |
File libJar = new File(libDir, "lib"+i+".jar"); |
1062 |
libJar.createNewFile(); |
1063 |
classpath[i] = JavaCore.newVariableEntry(new Path("/MyVar/lib"+i+".jar"), null, null); |
1064 |
} |
1065 |
proj.setRawClasspath(classpath, null); |
1066 |
|
1067 |
IPackageFragmentRoot[] roots = proj.getPackageFragmentRoots(); |
1068 |
assertEquals("wrong number of entries:", length, roots.length); |
1069 |
|
1070 |
// remove last classpath entry |
1071 |
System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length-1], 0, length-1); |
1072 |
proj.setRawClasspath(classpath, null); |
1073 |
|
1074 |
// verify that JME occurs |
1075 |
IPackageFragmentRoot lastRoot = roots[length-1]; |
1076 |
String rootPath = ((PackageFragmentRoot)lastRoot).toStringWithAncestors(); |
1077 |
try { |
1078 |
IClasspathEntry rawEntry = roots[length-1].getRawClasspathEntry(); |
1079 |
assertNotNull("We should no longer get a null classpath entry:", rawEntry); |
1080 |
} catch (JavaModelException jme) { |
1081 |
assertEquals("Unexpected JME exception", |
1082 |
"Illegal path for required library: '"+rootPath+"' in project 'P'", jme.getJavaModelStatus().getMessage()); |
1083 |
} |
1084 |
} finally { |
1085 |
if (libDir != null) { |
1086 |
org.eclipse.jdt.core.tests.util.Util.delete(libDir); |
1087 |
} |
1088 |
this.deleteProject("P"); |
1089 |
JavaCore.removeClasspathVariable("MyVar", null); |
1090 |
} |
1091 |
} |
1044 |
/* |
1092 |
/* |
1045 |
* Ensures that opening a project update the project references |
1093 |
* Ensures that opening a project update the project references |
1046 |
* (regression test for bug 73253 [model] Project references not set on project open) |
1094 |
* (regression test for bug 73253 [model] Project references not set on project open) |