View | Details | Raw Unified | Return to bug 171136
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (+34 lines)
Lines 164-169 Link Here
164
	return result;
164
	return result;
165
}
165
}
166
166
167
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136, ignore class path errors from optional
168
// class path entries.
169
170
public void test124117() throws CoreException {
171
172
	IJavaProject p = null;
173
	try {
174
175
		p = this.createJavaProject("P0", new String[] {"src0", "src1"}, "bin0");
176
		IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true");
177
		JavaCore.setClasspathContainer(
178
				new Path("container/default"),
179
				new IJavaProject[]{ p },
180
				new IClasspathContainer[] {
181
					new TestContainer(new Path("container/default"),
182
							new IClasspathEntry[]{
183
						JavaCore.newLibraryEntry(new Path("/P0/JUNK"), new Path("/P0/SBlah"), new Path("/P0"), null, new IClasspathAttribute[] {attribute}, false)})
184
				},
185
				null);
186
187
		IClasspathEntry newClasspath = JavaCore.newContainerEntry(new Path("container/default"));
188
189
		IJavaModelStatus status = JavaConventions.validateClasspathEntry(p, newClasspath, true);
190
		
191
		assertStatus(
192
				"should NOT have complained about missing library as it is optional",
193
				"OK",
194
				status);
195
	
196
	} finally {
197
		deleteProject ("P0");
198
	}
199
}
200
167
/*  https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816: Misleading problem text for missing jar in user
201
/*  https://bugs.eclipse.org/bugs/show_bug.cgi?id=232816: Misleading problem text for missing jar in user
168
 *  library. We now mention the container name in this and related diagnostics so the context and connection is clearer.
202
 *  library. We now mention the container name in this and related diagnostics so the context and connection is clearer.
169
 *  The bunch of tests with names of the form test232816*() test several paths in the function 
203
 *  The bunch of tests with names of the form test232816*() test several paths in the function 
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-1 / +8 lines)
Lines 1745-1751 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);
1748
		IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer);
1749
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136, ignore class path errors from optional entries.
1750
		if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) entry).isOptional())
1751
			return JavaModelStatus.VERIFIED_OK;
1752
		return status;
1749
	}
1753
	}
1750
	
1754
	
1751
	private static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, IClasspathContainer entryContainer, boolean checkSourceAttachment, boolean referredByContainer){
1755
	private static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, IClasspathContainer entryContainer, boolean checkSourceAttachment, boolean referredByContainer){
Lines 1860-1865 Link Here
1860
					}
1864
					}
1861
				}
1865
				}
1862
				IJavaModelStatus status = validateLibraryEntry(path, project, containerInfo, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg);
1866
				IJavaModelStatus status = validateLibraryEntry(path, project, containerInfo, checkSourceAttachment ? entry.getSourceAttachmentPath() : null, entryPathMsg);
1867
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136, ignore class path errors from optional entries
1868
				if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) entry).isOptional())
1869
					status = JavaModelStatus.VERIFIED_OK;
1863
				if (!status.isOK())
1870
				if (!status.isOK())
1864
					return status;
1871
					return status;
1865
				break;
1872
				break;
(-)model/org/eclipse/jdt/internal/core/ClasspathValidation.java (-3 lines)
Lines 14-20 Link Here
14
import org.eclipse.core.runtime.IPath;
14
import org.eclipse.core.runtime.IPath;
15
import org.eclipse.jdt.core.IClasspathEntry;
15
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IJavaModelStatus;
16
import org.eclipse.jdt.core.IJavaModelStatus;
17
import org.eclipse.jdt.core.IJavaModelStatusConstants;
18
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.core.JavaModelException;
19
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
18
import org.eclipse.jdt.internal.core.builder.JavaBuilder;
20
19
Lines 68-75 Link Here
68
		 	for (int i = 0; i < rawClasspath.length; i++) {
67
		 	for (int i = 0; i < rawClasspath.length; i++) {
69
				status = ClasspathEntry.validateClasspathEntry(this.project, rawClasspath[i], false/*src attach*/, false /*not referred by a container*/);
68
				status = ClasspathEntry.validateClasspathEntry(this.project, rawClasspath[i], false/*src attach*/, false /*not referred by a container*/);
70
				if (!status.isOK()) {
69
				if (!status.isOK()) {
71
					if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) rawClasspath[i]).isOptional())
72
						continue; // ignore this entry
73
					this.project.createClasspathProblemMarker(status);
70
					this.project.createClasspathProblemMarker(status);
74
				}
71
				}
75
			 }
72
			 }
(-)model/org/eclipse/jdt/core/JavaConventions.java (-4 / +1 lines)
Lines 610-619 Link Here
610
	 * @since 2.0
610
	 * @since 2.0
611
	 */
611
	 */
612
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment){
612
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment){
613
		IJavaModelStatus status = ClasspathEntry.validateClasspathEntry(project, entry, checkSourceAttachment, false/*not referred by container*/);
613
		return ClasspathEntry.validateClasspathEntry(project, entry, checkSourceAttachment, false/*not referred by container*/);
614
		if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) entry).isOptional())
615
			return JavaModelStatus.VERIFIED_OK;
616
		return status;
617
	}
614
	}
618
615
619
	/**
616
	/**

Return to bug 171136