### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v retrieving revision 1.200 diff -u -r1.200 ClasspathTests.java --- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 14 May 2009 10:09:36 -0000 1.200 +++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 24 Jun 2009 04:59:56 -0000 @@ -5863,5 +5863,69 @@ assertTrue("Inclusion pattern was null", e.getInclusionPatterns() != null); assertTrue("Exclusion pattern was null", e.getExclusionPatterns() != null); } +/** + * Test adding jar files with absolute file system path using the following modes and ensure the comparison + * with a relative path return true. + * 1. Variable Entry + * 2. User Library + * 3. External Jar file + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=276373" + * @throws Exception + */ +public void testBug276373() throws Exception { + File libDir = null; + try { + IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); + IPath libPath = proj.getResource().getLocation().append("lib"); + JavaCore.setClasspathVariable("MyVar", libPath, null); + libDir = new File(libPath.toPortableString()); + libDir.mkdirs(); + IClasspathEntry[] classpath = new IClasspathEntry[3]; + File libJar = new File(libDir, "variableLib.jar"); + libJar.createNewFile(); + classpath[0] = JavaCore.newVariableEntry(new Path("/MyVar/variableLib.jar"), null, null); + + libJar = new File(libDir, "externalLib.jar"); + libJar.createNewFile(); + classpath[1] = JavaCore.newLibraryEntry(new Path(libJar.getAbsolutePath()), null, null); + + libJar = new File(libDir, "userLib.jar"); + libJar.createNewFile(); + + ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID); + String libraryName = "TestUserLibrary"; + IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID); + UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName); + initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion); + + IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID); + String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"TestUserLibrary"; + StringBuffer propertyValue = new StringBuffer("\r\n\r\n\r\n\r\n"); + preferences.put(propertyName, propertyValue.toString()); + preferences.flush(); + + classpath[2] = JavaCore.newContainerEntry(containerSuggestion.getPath()); + proj.setRawClasspath(classpath, null); + + IResource resource = getWorkspaceRoot().getProject("P").getFile("lib/variableLib.jar"); + assertTrue(proj.isOnClasspath(resource)); + + resource = getWorkspaceRoot().getProject("P").getFile("lib/externalLib.jar"); + assertTrue(proj.isOnClasspath(resource)); + + resource = getWorkspaceRoot().getProject("P").getFile("lib/userLib.jar"); + assertTrue(proj.isOnClasspath(resource)); + } + finally { + if (libDir != null) { + org.eclipse.jdt.core.tests.util.Util.delete(libDir); + } + this.deleteProject("P"); + JavaCore.removeClasspathVariable("MyVar", null); + } +} } #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaProject.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v retrieving revision 1.424 diff -u -r1.424 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 23 Apr 2009 15:32:16 -0000 1.424 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 24 Jun 2009 05:00:00 -0000 @@ -2171,6 +2171,13 @@ if (entryPath.equals(exactPath)) { // package fragment roots must match exactly entry pathes (no exclusion there) return true; } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=276373 + // When a classpath entry is absolute, convert the resource's relative path to a file system path and compare + // e.g - /P/lib/variableLib.jar and /home/P/lib/variableLib.jar when compared should return true + if (entryPath.isAbsolute() + && entryPath.equals(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(exactPath))) { + return true; + } if (entryPath.isPrefixOf(path) && !Util.isExcluded(path, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath)) { return true; @@ -2190,6 +2197,11 @@ && !Util.isExcluded(elementPath, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath)) return true; } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=276373 + if (entryPath.isAbsolute() + && entryPath.equals(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(elementPath))) { + return true; + } return false; }