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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java (+40 lines)
Lines 17-22 Link Here
17
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.InstanceScope;
20
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.*;
21
import org.eclipse.jdt.core.compiler.CategorizedProblem;
22
import org.eclipse.jdt.core.compiler.CategorizedProblem;
22
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
23
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
Lines 54-59 Link Here
54
	return jdkLevelProblem.toString();
55
	return jdkLevelProblem.toString();
55
}
56
}
56
57
58
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, mention container name in diagnostic,
59
// so the connection is more obvious in error messages.
60
public void testInaccessibleUserLibrary() throws Exception {
61
	
62
		// Create new user library "SomeUserLibrary"
63
		ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
64
		String libraryName = "SomeUserLibrary";
65
		IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
66
		UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName);
67
		initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion);
68
69
		// Create java project
70
		IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
71
		
72
		// Modify user library
73
		IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
74
		String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"SomeUserLibrary";
75
		StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive");
76
		//String jarFullPath = getWorkspaceRoot().getLocation().append(jarFile.getFullPath()).toString();
77
		propertyValue.append(" path=\"" + "c:\\non\\existent\\bogus\\library.jar");
78
		propertyValue.append("\"/>\r\n</userlibrary>\r\n");
79
		preferences.put(propertyName, propertyValue.toString());
80
		preferences.flush();
81
		
82
		
83
		IClasspathEntry[] entries = env.getJavaProject(projectPath).getRawClasspath();
84
		int length = entries.length;
85
		System.arraycopy(entries, 0, entries = new IClasspathEntry[length+1], 0, length);
86
		entries[length] = JavaCore.newContainerEntry(containerSuggestion.getPath());
87
		env.getJavaProject(projectPath).setRawClasspath(entries, null);
88
89
		expectingOnlySpecificProblemsFor(projectPath,
90
			new Problem[] {
91
				new Problem("Build path", "Project 'Project' is missing required library: 'C:\\non\\existent\\bogus\\library.jar' (contained in 'SomeUserLibrary')", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$
92
			}
93
		);
94
	
95
}
96
57
public void testClasspathFileChange() throws JavaModelException {
97
public void testClasspathFileChange() throws JavaModelException {
58
	// create project with src folder, and alternate unused src2 folder
98
	// create project with src folder, and alternate unused src2 folder
59
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
99
	IPath projectPath = env.addProject("Project"); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-1 / +1 lines)
Lines 2341-2347 Link Here
2341
		setClasspath(p, new IClasspathEntry[] {JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"))});
2341
		setClasspath(p, new IClasspathEntry[] {JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"))});
2342
		assertMarkers(
2342
		assertMarkers(
2343
			"Unexpected markers", 
2343
			"Unexpected markers", 
2344
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "nonExisting.jar\'",
2344
			"Project \'P\' is missing required library: \'"+ getExternalPath() + "nonExisting.jar\' (contained in 'Test container')",
2345
			p);
2345
			p);
2346
	} finally {
2346
	} finally {
2347
		deleteProject("P");
2347
		deleteProject("P");
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-7 / +21 lines)
Lines 1745-1750 Link Here
1745
	 * @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine
1745
	 * @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine
1746
	 */
1746
	 */
1747
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){
1747
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){
1748
		return validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer);
1749
	}
1750
	
1751
	private static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, IClasspathContainer entryContainer, boolean checkSourceAttachment, boolean referredByContainer){
1748
1752
1749
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1753
		IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
1750
		IPath path = entry.getPath();
1754
		IPath path = entry.getPath();
Lines 1796-1802 Link Here
1796
										if (description == null) description = path.makeRelative().toString();
1800
										if (description == null) description = path.makeRelative().toString();
1797
										return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY, project, path);
1801
										return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CP_CONTAINER_ENTRY, project, path);
1798
								}
1802
								}
1799
								IJavaModelStatus containerEntryStatus = validateClasspathEntry(project, containerEntry, checkSourceAttachment, true/*referred by container*/);
1803
								IJavaModelStatus containerEntryStatus = validateClasspathEntry(project, containerEntry, container, checkSourceAttachment, true/*referred by container*/);
1800
								if (!containerEntryStatus.isOK()){
1804
								if (!containerEntryStatus.isOK()){
1801
									return containerEntryStatus;
1805
									return containerEntryStatus;
1802
								}
1806
								}
Lines 1825-1831 Link Here
1825
					}
1829
					}
1826
1830
1827
					// get validation status
1831
					// get validation status
1828
					IJavaModelStatus status = validateClasspathEntry(project, entry, checkSourceAttachment, false/*not referred by container*/);
1832
					IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, false/*not referred by container*/);
1829
					if (!status.isOK()) return status;
1833
					if (!status.isOK()) return status;
1830
1834
1831
					// return deprecation status if any
1835
					// return deprecation status if any
Lines 1846-1853 Link Here
1846
				// do not validate entries from Class-Path: in manifest
1850
				// do not validate entries from Class-Path: in manifest
1847
				// (these entries are considered optional since the user cannot act on them)
1851
				// (these entries are considered optional since the user cannot act on them)
1848
				// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252392
1852
				// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=252392
1849
				
1853
				String containerName = entryContainer != null ? entryContainer.getDescription() : null;
1850
				IJavaModelStatus status = validateLibraryEntry(path, project, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg);
1854
				IJavaModelStatus status = validateLibraryEntry(path, project, containerName, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg);
1851
				if (!status.isOK())
1855
				if (!status.isOK())
1852
					return status;
1856
					return status;
1853
				break;
1857
				break;
Lines 1916-1922 Link Here
1916
		return JavaModelStatus.VERIFIED_OK;
1920
		return JavaModelStatus.VERIFIED_OK;
1917
	}
1921
	}
1918
1922
1919
	private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, IPath sourceAttachment, String entryPathMsg) {
1923
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816, now we have the facility to include a container
1924
	// name in diagnostics.
1925
	private static IJavaModelStatus validateLibraryEntry(IPath path, IJavaProject project, String containerName, IPath sourceAttachment, String entryPathMsg) {
1920
		if (path.isAbsolute() && !path.isEmpty()) {
1926
		if (path.isAbsolute() && !path.isEmpty()) {
1921
			Object target = JavaModel.getTarget(path, true);
1927
			Object target = JavaModel.getTarget(path, true);
1922
			if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
1928
			if (target != null && !JavaCore.IGNORE.equals(project.getOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, true))) {
Lines 1955-1965 Link Here
1955
			} else {
1961
			} else {
1956
				boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists();
1962
				boolean isExternal = path.getDevice() != null || !ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)).exists();
1957
				if (isExternal) {
1963
				if (isExternal) {
1958
					return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()}));
1964
					if (containerName != null) {
1965
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {path.toOSString(), containerName, project.getElementName()}));
1966
					} else {
1967
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {path.toOSString(), project.getElementName()}));	
1968
					}
1959
				} else {
1969
				} else {
1960
					if (entryPathMsg == null) 
1970
					if (entryPathMsg == null) 
1961
						entryPathMsg = 	project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
1971
						entryPathMsg = 	project.getElementName().equals(path.segment(0)) ? path.removeFirstSegments(1).makeRelative().toString() : path.toString();
1962
					return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, project.getElementName()}));
1972
					if (containerName != null) {	
1973
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibraryInContainer, new String[] {entryPathMsg, containerName, project.getElementName()}));
1974
					} else {
1975
						return new JavaModelStatus(IJavaModelStatusConstants.INVALID_CLASSPATH, Messages.bind(Messages.classpath_unboundLibrary, new String[] {entryPathMsg, project.getElementName()}));
1976
					}
1963
				}
1977
				}
1964
			}
1978
			}
1965
		} else {
1979
		} else {
(-)model/org/eclipse/jdt/internal/core/util/messages.properties (+1 lines)
Lines 155-160 Link Here
155
classpath_mustEndWithSlash = End exclusion filter ''{0}'' with / to fully exclude ''{1}''
155
classpath_mustEndWithSlash = End exclusion filter ''{0}'' with / to fully exclude ''{1}''
156
classpath_unboundContainerPath = Unbound classpath container: ''{0}'' in project ''{1}''
156
classpath_unboundContainerPath = Unbound classpath container: ''{0}'' in project ''{1}''
157
classpath_unboundLibrary = Project ''{1}'' is missing required library: ''{0}''
157
classpath_unboundLibrary = Project ''{1}'' is missing required library: ''{0}''
158
classpath_unboundLibraryInContainer = Project ''{2}'' is missing required library: ''{0}'' (contained in ''{1}'')
158
classpath_unboundProject = Project ''{1}'' is missing required Java project: ''{0}''
159
classpath_unboundProject = Project ''{1}'' is missing required Java project: ''{0}''
159
classpath_settingOutputLocationProgress = Setting output location for: ''{0}''
160
classpath_settingOutputLocationProgress = Setting output location for: ''{0}''
160
classpath_settingProgress = Setting classpath for: {0}
161
classpath_settingProgress = Setting classpath for: {0}
(-)model/org/eclipse/jdt/internal/core/util/Messages.java (+1 lines)
Lines 159-164 Link Here
159
	public static String classpath_mustEndWithSlash;
159
	public static String classpath_mustEndWithSlash;
160
	public static String classpath_unboundContainerPath;
160
	public static String classpath_unboundContainerPath;
161
	public static String classpath_unboundLibrary;
161
	public static String classpath_unboundLibrary;
162
	public static String classpath_unboundLibraryInContainer;
162
	public static String classpath_unboundProject;
163
	public static String classpath_unboundProject;
163
	public static String classpath_settingOutputLocationProgress;
164
	public static String classpath_settingOutputLocationProgress;
164
	public static String classpath_settingProgress;
165
	public static String classpath_settingProgress;

Return to bug 232816