View | Details | Raw Unified | Return to bug 276373 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaProject.java (+7 lines)
Lines 2171-2176 Link Here
2171
			if (entryPath.equals(exactPath)) { // package fragment roots must match exactly entry pathes (no exclusion there)
2171
			if (entryPath.equals(exactPath)) { // package fragment roots must match exactly entry pathes (no exclusion there)
2172
				return true;
2172
				return true;
2173
			}
2173
			}
2174
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=276373
2175
			// When a classpath entry is absolute, convert the resource's relative path to a file system path and compare
2176
			// e.g - /P/lib/variableLib.jar and /home/P/lib/variableLib.jar when compared should return true
2177
			if (entryPath.isAbsolute()
2178
					&& entryPath.equals(ResourcesPlugin.getWorkspace().getRoot().getLocation().append(exactPath))) {
2179
				return true;
2180
			}
2174
			if (entryPath.isPrefixOf(path)
2181
			if (entryPath.isPrefixOf(path)
2175
					&& !Util.isExcluded(path, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath)) {
2182
					&& !Util.isExcluded(path, ((ClasspathEntry)entry).fullInclusionPatternChars(), ((ClasspathEntry)entry).fullExclusionPatternChars(), isFolderPath)) {
2176
				return true;
2183
				return true;
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (+63 lines)
Lines 5863-5867 Link Here
5863
	assertTrue("Inclusion pattern was null", e.getInclusionPatterns() != null);
5863
	assertTrue("Inclusion pattern was null", e.getInclusionPatterns() != null);
5864
	assertTrue("Exclusion pattern was null", e.getExclusionPatterns() != null);
5864
	assertTrue("Exclusion pattern was null", e.getExclusionPatterns() != null);
5865
}
5865
}
5866
/**
5867
 * Test adding jar files with absolute file system path using the following modes and ensure the comparison
5868
 * with a relative path return true.
5869
 * 1. Variable Entry
5870
 * 2. User Library
5871
 * 3. External Jar file
5872
 * 
5873
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=276373"
5874
 * @throws Exception
5875
 */
5876
public void testBug276373() throws Exception {
5877
	File libDir = null;
5878
	try {
5879
		IJavaProject proj =  this.createJavaProject("P", new String[] {}, "bin");
5880
		IPath libPath = proj.getResource().getLocation().append("lib");
5881
		JavaCore.setClasspathVariable("MyVar", libPath, null);
5882
		libDir = new File(libPath.toPortableString());
5883
		libDir.mkdirs();
5884
		IClasspathEntry[] classpath = new IClasspathEntry[3];
5885
		File libJar = new File(libDir, "variableLib.jar");
5886
		libJar.createNewFile();
5887
		classpath[0] = JavaCore.newVariableEntry(new Path("/MyVar/variableLib.jar"), null, null);
5866
5888
5889
		libJar = new File(libDir, "externalLib.jar");
5890
		libJar.createNewFile();
5891
		classpath[1] = JavaCore.newLibraryEntry(new Path(libJar.getAbsolutePath()), null, null);
5892
5893
		libJar = new File(libDir, "userLib.jar");
5894
		libJar.createNewFile();
5895
		
5896
		ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
5897
		String libraryName = "TestUserLibrary";
5898
		IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
5899
		UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName);
5900
		initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion);
5901
5902
		IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
5903
		String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"TestUserLibrary";
5904
		StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive");
5905
		propertyValue.append(" path=\"" + libJar.getAbsolutePath());
5906
		propertyValue.append("\"/>\r\n</userlibrary>\r\n");
5907
		preferences.put(propertyName, propertyValue.toString());
5908
		preferences.flush();	
5909
		
5910
		classpath[2] = JavaCore.newContainerEntry(containerSuggestion.getPath());
5911
		proj.setRawClasspath(classpath, null);
5912
		
5913
		IResource resource = getWorkspaceRoot().getProject("P").getFile("lib/variableLib.jar");
5914
		assertTrue(proj.isOnClasspath(resource));
5915
5916
		resource = getWorkspaceRoot().getProject("P").getFile("lib/externalLib.jar");
5917
		assertTrue(proj.isOnClasspath(resource));
5918
5919
		resource = getWorkspaceRoot().getProject("P").getFile("lib/userLib.jar");
5920
		assertTrue(proj.isOnClasspath(resource));
5921
	}
5922
	finally {
5923
		if (libDir != null) {
5924
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
5925
		}
5926
		this.deleteProject("P");
5927
		JavaCore.removeClasspathVariable("MyVar", null);
5928
	}		
5929
}
5867
}
5930
}

Return to bug 276373