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

(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-2 / +8 lines)
Lines 1758-1765 Link Here
1758
	 */
1758
	 */
1759
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){
1759
	public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){
1760
		IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer);
1760
		IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer);
1761
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136, ignore class path errors from optional entries.
1761
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136
1762
		if (status.getCode() == IJavaModelStatusConstants.INVALID_CLASSPATH && ((ClasspathEntry) entry).isOptional())
1762
		// Ignore class path errors from optional entries.
1763
		int statusCode = status.getCode();
1764
		if ( (statusCode == IJavaModelStatusConstants.INVALID_CLASSPATH || 
1765
				statusCode == IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND ||
1766
				statusCode == IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND ||
1767
				statusCode == IJavaModelStatusConstants.INVALID_PATH) &&
1768
				((ClasspathEntry) entry).isOptional())
1763
			return JavaModelStatus.VERIFIED_OK;
1769
			return JavaModelStatus.VERIFIED_OK;
1764
		return status;
1770
		return status;
1765
	}
1771
	}
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-1 / +86 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 5971-5975 Link Here
5971
		this.deleteProject("P");
5971
		this.deleteProject("P");
5972
	}
5972
	}
5973
}
5973
}
5974
/**
5975
 * @bug 300136:classpathentry OPTIONAL attribute not honored for var entries
5976
 * 
5977
 * Test that classpath entries (CPE_LIB, CPE_CONTAINER and CPE_VARIABLE) that are marked as optional 
5978
 * in the .classpath file are not reported for errors.
5979
 * 
5980
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136"
5981
 */
5982
public void testBug300136() throws Exception {
5983
	boolean autoBuild = getWorkspace().isAutoBuilding();
5984
	IWorkspaceDescription preferences = getWorkspace().getDescription();
5985
	try {
5986
		preferences.setAutoBuilding(false);
5987
		IJavaProject project = createJavaProject("P");
5988
		StringBuffer buffer = new StringBuffer(
5989
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
5990
				"<classpath>\n" +
5991
				"   <classpathentry  kind=\"var\" path=\"TEST_LIB\">\n" +
5992
				"    	<attributes>\n" + 
5993
				"   	 <attribute name=\"optional\" value=\"true\"/>" +
5994
				"    	</attributes>\n" +
5995
				"	</classpathentry>\n" +
5996
				"   <classpathentry  kind=\"var\" path=\"UNBOUND_VAR\">\n" +
5997
				"    	<attributes>\n" + 
5998
				"   	 <attribute name=\"optional\" value=\"true\"/>" +
5999
				"    	</attributes>\n" +
6000
				"	</classpathentry>\n" +
6001
				"   <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\">\n" +
6002
				"    	<attributes>\n" + 
6003
				"   	 <attribute name=\"optional\" value=\"true\"/>" +
6004
				"    	</attributes>\n" +
6005
				"	</classpathentry>\n" +
6006
				"   <classpathentry kind=\"output\" path=\"bin\"/>\n" +
6007
				"</classpath>"
6008
				);
6009
		editFile(
6010
			"/P/.classpath",
6011
			buffer.toString()
6012
		);
6013
		assertMarkers(
6014
				"Unexpected markers",
6015
				"",
6016
				project);
6017
	} finally {
6018
		preferences.setAutoBuilding(autoBuild);
6019
		deleteProject("P");
6020
	}	
6021
}
6022
/**
6023
 * Additional test for bug 300136 - Test that the the errors are reported when the 
6024
 * optional attribute is not used.
6025
 * 
6026
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136"
6027
 */
6028
public void testBug300136a() throws Exception {
6029
	boolean autoBuild = getWorkspace().isAutoBuilding();
6030
	IWorkspaceDescription preferences = getWorkspace().getDescription();
6031
	try {
6032
		preferences.setAutoBuilding(false);
6033
		IJavaProject project = createJavaProject("P");
6034
		StringBuffer buffer = new StringBuffer(
6035
				"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
6036
				"<classpath>\n" +
6037
				"    <classpathentry  kind=\"var\" path=\"TEST_LIB\" />\n" +
6038
				"    <classpathentry  kind=\"var\" path=\"UNBOUND_VAR\" />\n" +
6039
				"    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\">\n" +
6040
				"	</classpathentry>\n" +
6041
				"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
6042
				"</classpath>"
6043
				);
6044
		editFile(
6045
			"/P/.classpath",
6046
			buffer.toString()
6047
		);
6048
		assertMarkers(
6049
				"Unexpected markers",
6050
				"Project \'P\' is missing required library: \'\\lib\\tmp.jar\'\n" + 
6051
				"Unbound classpath container: \'org.eclipse.jdt.core.tests.model.TEST_CONTAINER\' in project \'P\'\n" + 
6052
				"Unbound classpath variable: \'UNBOUND_VAR\' in project \'P\'",
6053
				project);
6054
	} finally {
6055
		preferences.setAutoBuilding(autoBuild);
6056
		deleteProject("P");
6057
	}	
6058
}
5974
6059
5975
}
6060
}

Return to bug 300136