Lines 6433-6447
Link Here
|
6433 |
} |
6433 |
} |
6434 |
} |
6434 |
} |
6435 |
/** |
6435 |
/** |
6436 |
* @bug 304081:IJavaProject#isOnClasspath(IJavaElement) returns false for type from referenced JAR |
6436 |
* @bug 252431: Additional tests |
6437 |
* When the JAR, which a variable classpath entry resolves to, references other JAR via |
6437 |
* Test that attributes set on referenced libraries of variable entries via MANIFEST are persisted |
6438 |
* MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true |
6438 |
* and can be retrieved |
6439 |
* for the referenced classpath entries. |
|
|
6440 |
* |
6439 |
* |
6441 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081" |
6440 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252431" |
6442 |
* @throws Exception |
6441 |
* @throws Exception |
6443 |
*/ |
6442 |
*/ |
6444 |
public void testBug304081() throws Exception { |
6443 |
public void testBug252431d() throws Exception { |
6445 |
File libDir = null; |
6444 |
File libDir = null; |
6446 |
try { |
6445 |
try { |
6447 |
|
6446 |
|
Lines 6463-6517
Link Here
|
6463 |
|
6462 |
|
6464 |
createFile("/P/lib1.jar", ""); |
6463 |
createFile("/P/lib1.jar", ""); |
6465 |
|
6464 |
|
6466 |
classpath[0] = JavaCore.newVariableEntry(new Path( |
6465 |
classpath = proj.getResolvedClasspath(true); |
6467 |
"/MyVar/variable.jar"), null, null); |
6466 |
assertClasspathEquals(classpath, |
6468 |
|
6467 |
"/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" + |
6469 |
proj.setRawClasspath(classpath, null); |
6468 |
"/P/variable.jar[CPE_LIBRARY][K_BINARY][isExported:true]"); |
6470 |
waitForAutoBuild(); |
6469 |
|
6471 |
IProject project = getWorkspaceRoot().getProject("P"); |
6470 |
IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(classpath[1], null); |
6472 |
IResource resource = project.getFile("variable.jar"); |
6471 |
assertClasspathEquals(chains, "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]"); |
6473 |
assertTrue(proj.isOnClasspath(resource)); |
6472 |
((ClasspathEntry)chains[0]).sourceAttachmentPath = new Path("/P/efg.zip"); |
6474 |
IJavaElement element = proj.getPackageFragmentRoot(resource); |
6473 |
((ClasspathEntry)chains[0]).sourceAttachmentRootPath = new Path("/src2"); |
6475 |
assertTrue(proj.isOnClasspath(element)); |
6474 |
|
6476 |
|
6475 |
IClasspathAttribute javadocLoc = JavaCore.newClasspathAttribute("javadoc_location", "/P/efg.zip"); |
6477 |
resource = project.getFile("lib1.jar"); |
6476 |
((ClasspathEntry)chains[0]).extraAttributes = new IClasspathAttribute[]{javadocLoc}; |
6478 |
assertTrue(proj.isOnClasspath(resource)); |
6477 |
|
6479 |
element = proj.getPackageFragmentRoot(resource); |
6478 |
proj.setRawClasspath(proj.getRawClasspath(), chains, proj.getOutputLocation(), null); |
6480 |
assertTrue(proj.isOnClasspath(element)); |
6479 |
classpath = proj.getResolvedClasspath(true); |
|
|
6480 |
assertClasspathEquals(classpath, |
6481 |
"/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/efg.zip][rootPath:/src2][isExported:true][attributes:javadoc_location=/P/efg.zip]\n" + |
6482 |
"/P/variable.jar[CPE_LIBRARY][K_BINARY][isExported:true]"); |
6481 |
} finally { |
6483 |
} finally { |
6482 |
this.deleteProject("P"); |
6484 |
this.deleteProject("P"); |
6483 |
JavaCore.removeClasspathVariable("MyVar", null); |
6485 |
JavaCore.removeClasspathVariable("MyVar", null); |
6484 |
} |
6486 |
} |
6485 |
} |
6487 |
} |
6486 |
/** |
6488 |
/** |
6487 |
* Additional tests for 304081 |
6489 |
* @bug 304081:IJavaProject#isOnClasspath(IJavaElement) returns false for type from referenced JAR |
6488 |
* When the JAR, which is in the raw classpath, references other JAR via |
6490 |
* When the JAR, which a variable classpath entry resolves to, references other JAR via |
6489 |
* MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true |
6491 |
* MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true |
6490 |
* for the referenced classpath entries. |
6492 |
* for the referenced classpath entries. |
6491 |
* |
6493 |
* |
6492 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081" |
6494 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081" |
6493 |
* @throws Exception |
6495 |
* @throws Exception |
6494 |
*/ |
6496 |
*/ |
6495 |
public void testBug304081a() throws Exception { |
6497 |
public void testBug304081() throws Exception { |
|
|
6498 |
File libDir = null; |
6496 |
try { |
6499 |
try { |
6497 |
|
6500 |
|
6498 |
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); |
6501 |
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); |
|
|
6502 |
IPath libPath = proj.getResource().getLocation(); |
6503 |
JavaCore.setClasspathVariable("MyVar", libPath, null); |
6504 |
libDir = new File(libPath.toPortableString()); |
6499 |
IClasspathEntry[] classpath = new IClasspathEntry[1]; |
6505 |
IClasspathEntry[] classpath = new IClasspathEntry[1]; |
6500 |
|
6506 |
File libJar = new File(libDir, "variable.jar"); |
6501 |
addLibrary(proj, "library.jar", null, new String[0], |
6507 |
libJar.createNewFile(); |
|
|
6508 |
|
6509 |
addLibrary(proj, "variable.jar", null, new String[0], |
6502 |
new String[] { |
6510 |
new String[] { |
6503 |
"META-INF/MANIFEST.MF", |
6511 |
"META-INF/MANIFEST.MF", |
6504 |
"Manifest-Version: 1.0\n" + |
6512 |
"Manifest-Version: 1.0\n" + |
6505 |
"Class-Path: lib1.jar\n", |
6513 |
"Class-Path: lib1.jar\n", |
6506 |
}, |
6514 |
}, |
6507 |
JavaCore.VERSION_1_4); |
6515 |
JavaCore.VERSION_1_4); |
6508 |
createFile("/P/lib1.jar", ""); |
6516 |
|
6509 |
classpath[0] = JavaCore.newLibraryEntry(new Path("/P/library.jar"), null, null); |
6517 |
createFile("/P/lib1.jar", ""); |
|
|
6518 |
|
6519 |
classpath[0] = JavaCore.newVariableEntry(new Path( |
6520 |
"/MyVar/variable.jar"), null, null); |
6510 |
|
6521 |
|
6511 |
proj.setRawClasspath(classpath, null); |
6522 |
proj.setRawClasspath(classpath, null); |
6512 |
waitForAutoBuild(); |
6523 |
waitForAutoBuild(); |
6513 |
IProject project = getWorkspaceRoot().getProject("P"); |
6524 |
IProject project = getWorkspaceRoot().getProject("P"); |
6514 |
IResource resource = project.getFile("library.jar"); |
6525 |
IResource resource = project.getFile("variable.jar"); |
6515 |
assertTrue(proj.isOnClasspath(resource)); |
6526 |
assertTrue(proj.isOnClasspath(resource)); |
6516 |
IJavaElement element = proj.getPackageFragmentRoot(resource); |
6527 |
IJavaElement element = proj.getPackageFragmentRoot(resource); |
6517 |
assertTrue(proj.isOnClasspath(element)); |
6528 |
assertTrue(proj.isOnClasspath(element)); |
Lines 6522-6576
Link Here
|
6522 |
assertTrue(proj.isOnClasspath(element)); |
6533 |
assertTrue(proj.isOnClasspath(element)); |
6523 |
} finally { |
6534 |
} finally { |
6524 |
this.deleteProject("P"); |
6535 |
this.deleteProject("P"); |
|
|
6536 |
JavaCore.removeClasspathVariable("MyVar", null); |
6525 |
} |
6537 |
} |
6526 |
} |
6538 |
} |
6527 |
/** |
6539 |
/** |
6528 |
* Additional tests for 304081 |
6540 |
* Additional tests for 304081 |
6529 |
* When the JAR, which is part of a classpath container, references other JAR via |
6541 |
* When the JAR, which is in the raw classpath, references other JAR via |
6530 |
* MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true |
6542 |
* MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true |
6531 |
* for the referenced classpath entries. |
6543 |
* for the referenced classpath entries. |
6532 |
* |
6544 |
* |
6533 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081" |
6545 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081" |
6534 |
* @throws Exception |
6546 |
* @throws Exception |
6535 |
*/ |
6547 |
*/ |
6536 |
public void testBug304081b() throws Exception { |
6548 |
public void testBug304081a() throws Exception { |
6537 |
File libDir = null; |
|
|
6538 |
try { |
6549 |
try { |
6539 |
|
6550 |
|
6540 |
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); |
6551 |
IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); |
6541 |
IClasspathEntry[] classpath = new IClasspathEntry[1]; |
6552 |
IClasspathEntry[] classpath = new IClasspathEntry[1]; |
6542 |
libDir = new File(proj.getResource().getLocation().toPortableString()); |
6553 |
|
6543 |
File libJar = new File(libDir, "container.jar"); |
6554 |
addLibrary(proj, "library.jar", null, new String[0], |
6544 |
|
|
|
6545 |
addLibrary(proj, "container.jar", null, new String[0], |
6546 |
new String[] { |
6555 |
new String[] { |
6547 |
"META-INF/MANIFEST.MF", |
6556 |
"META-INF/MANIFEST.MF", |
6548 |
"Manifest-Version: 1.0\n" + |
6557 |
"Manifest-Version: 1.0\n" + |
6549 |
"Class-Path: lib1.jar\n", |
6558 |
"Class-Path: lib1.jar\n", |
6550 |
}, |
6559 |
}, |
6551 |
JavaCore.VERSION_1_4); |
6560 |
JavaCore.VERSION_1_4); |
6552 |
createFile("/P/lib1.jar", ""); |
6561 |
createFile("/P/lib1.jar", ""); |
6553 |
|
6562 |
classpath[0] = JavaCore.newLibraryEntry(new Path("/P/library.jar"), null, null); |
6554 |
ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID); |
|
|
6555 |
String libraryName = "TestUserLibrary"; |
6556 |
IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID); |
6557 |
UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName); |
6558 |
initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion); |
6559 |
|
6560 |
IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID); |
6561 |
String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"TestUserLibrary"; |
6562 |
StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive"); |
6563 |
propertyValue.append(" path=\"" + libJar.getAbsolutePath()); |
6564 |
propertyValue.append("\"/>\r\n</userlibrary>\r\n"); |
6565 |
preferences.put(propertyName, propertyValue.toString()); |
6566 |
preferences.flush(); |
6567 |
|
6568 |
classpath[0] = JavaCore.newContainerEntry(containerSuggestion.getPath()); |
6569 |
|
6563 |
|
6570 |
proj.setRawClasspath(classpath, null); |
6564 |
proj.setRawClasspath(classpath, null); |
6571 |
waitForAutoBuild(); |
6565 |
waitForAutoBuild(); |
6572 |
IProject project = getWorkspaceRoot().getProject("P"); |
6566 |
IProject project = getWorkspaceRoot().getProject("P"); |
6573 |
IResource resource = project.getFile("container.jar"); |
6567 |
IResource resource = project.getFile("library.jar"); |
6574 |
assertTrue(proj.isOnClasspath(resource)); |
6568 |
assertTrue(proj.isOnClasspath(resource)); |
6575 |
IJavaElement element = proj.getPackageFragmentRoot(resource); |
6569 |
IJavaElement element = proj.getPackageFragmentRoot(resource); |
6576 |
assertTrue(proj.isOnClasspath(element)); |
6570 |
assertTrue(proj.isOnClasspath(element)); |
Lines 6579-6585
Link Here
|
6579 |
assertTrue(proj.isOnClasspath(resource)); |
6573 |
assertTrue(proj.isOnClasspath(resource)); |
6580 |
element = proj.getPackageFragmentRoot(resource); |
6574 |
element = proj.getPackageFragmentRoot(resource); |
6581 |
assertTrue(proj.isOnClasspath(element)); |
6575 |
assertTrue(proj.isOnClasspath(element)); |
6582 |
|
|
|
6583 |
} finally { |
6576 |
} finally { |
6584 |
this.deleteProject("P"); |
6577 |
this.deleteProject("P"); |
6585 |
} |
6578 |
} |