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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-2 / +3 lines)
Lines 17-22 Link Here
17
import java.util.HashSet;
17
import java.util.HashSet;
18
import java.util.Hashtable;
18
import java.util.Hashtable;
19
import java.util.Iterator;
19
import java.util.Iterator;
20
import java.util.LinkedHashSet;
20
import java.util.Map;
21
import java.util.Map;
21
22
22
import javax.xml.parsers.DocumentBuilder;
23
import javax.xml.parsers.DocumentBuilder;
Lines 2449-2455 Link Here
2449
	 * Resolve the given raw classpath.
2450
	 * Resolve the given raw classpath.
2450
	 */
2451
	 */
2451
	public IClasspathEntry[] resolveClasspath(IClasspathEntry[] rawClasspath) throws JavaModelException {
2452
	public IClasspathEntry[] resolveClasspath(IClasspathEntry[] rawClasspath) throws JavaModelException {
2452
		ArrayList resolvedEntries = new ArrayList();
2453
		LinkedHashSet resolvedEntries = new LinkedHashSet();
2453
		for (int i = 0, length = rawClasspath.length; i < length; i++) {
2454
		for (int i = 0, length = rawClasspath.length; i < length; i++) {
2454
			IClasspathEntry rawEntry = rawClasspath[i];
2455
			IClasspathEntry rawEntry = rawClasspath[i];
2455
			switch (rawEntry.getEntryKind()){
2456
			switch (rawEntry.getEntryKind()){
Lines 2525-2531 Link Here
2525
			HashMap rawReverseMap = new HashMap();
2526
			HashMap rawReverseMap = new HashMap();
2526
			Map rootPathToResolvedEntries = new HashMap();
2527
			Map rootPathToResolvedEntries = new HashMap();
2527
			
2528
			
2528
			ArrayList resolvedEntries = new ArrayList();
2529
			LinkedHashSet resolvedEntries = new LinkedHashSet();
2529
			int length = rawClasspath.length;
2530
			int length = rawClasspath.length;
2530
			for (int i = 0; i < length; i++) {
2531
			for (int i = 0; i < length; i++) {
2531
	
2532
	
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-10 / +11 lines)
Lines 1284-1289 Link Here
1284
		if (rawClasspath == null)
1284
		if (rawClasspath == null)
1285
			return JavaModelStatus.VERIFIED_OK;
1285
			return JavaModelStatus.VERIFIED_OK;
1286
1286
1287
		// check duplicate entries on raw classpath only (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
1288
		int rawLength = rawClasspath.length;
1289
		HashSet pathes = new HashSet(rawLength);
1290
		for (int i = 0 ; i < rawLength; i++) {
1291
			IPath entryPath = rawClasspath[i].getPath();
1292
			if (!pathes.add(entryPath)){
1293
				String entryPathMsg = projectName.equals(entryPath.segment(0)) ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString();
1294
				return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName}));
1295
			}
1296
		}
1297
1287
		// retrieve resolved classpath
1298
		// retrieve resolved classpath
1288
		IClasspathEntry[] classpath;
1299
		IClasspathEntry[] classpath;
1289
		try {
1300
		try {
Lines 1388-1395 Link Here
1388
			for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
1399
			for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
1389
		}
1400
		}
1390
1401
1391
		HashSet pathes = new HashSet(length);
1392
1393
		// check all entries
1402
		// check all entries
1394
		for (int i = 0 ; i < length; i++) {
1403
		for (int i = 0 ; i < length; i++) {
1395
			IClasspathEntry entry = classpath[i];
1404
			IClasspathEntry entry = classpath[i];
Lines 1397-1410 Link Here
1397
			IPath entryPath = entry.getPath();
1406
			IPath entryPath = entry.getPath();
1398
			int kind = entry.getEntryKind();
1407
			int kind = entry.getEntryKind();
1399
1408
1400
			// Build some common strings for status message
1401
			boolean isProjectRelative = projectName.equals(entryPath.segment(0));
1402
			String entryPathMsg = isProjectRelative ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString();
1403
1404
			// complain if duplicate path
1405
			if (!pathes.add(entryPath)){
1406
				return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName}));
1407
			}
1408
			// no further check if entry coincidates with project or output location
1409
			// no further check if entry coincidates with project or output location
1409
			if (entryPath.equals(projectPath)){
1410
			if (entryPath.equals(projectPath)){
1410
				// complain if self-referring project entry
1411
				// complain if self-referring project entry
(-)model/org/eclipse/jdt/core/IJavaProject.java (+5 lines)
Lines 613-618 Link Here
613
	 * variables are changed, the resolved classpath can become out of date.
613
	 * variables are changed, the resolved classpath can become out of date.
614
	 * Because of this, hanging on resolved classpath is not recommended.
614
	 * Because of this, hanging on resolved classpath is not recommended.
615
	 * </p>
615
	 * </p>
616
	 * <p>
617
	 * Note that if the resolution creates duplicate entries 
618
	 * (i.e. {@link IClasspathEntry entries} which are {@link Object#equals(Object)}), 
619
	 * only the first one is added to the resolved classpath.
620
	 * </p>
616
	 * 
621
	 * 
617
	 * @param ignoreUnresolvedEntry indicates how to handle unresolvable
622
	 * @param ignoreUnresolvedEntry indicates how to handle unresolvable
618
	 * variables and containers; <code>true</code> indicates that missing
623
	 * variables and containers; <code>true</code> indicates that missing
(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-1 / +60 lines)
Lines 53-58 Link Here
53
import org.eclipse.jdt.core.JavaConventions;
53
import org.eclipse.jdt.core.JavaConventions;
54
import org.eclipse.jdt.core.JavaCore;
54
import org.eclipse.jdt.core.JavaCore;
55
import org.eclipse.jdt.core.JavaModelException;
55
import org.eclipse.jdt.core.JavaModelException;
56
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultVariableInitializer;
56
import org.eclipse.jdt.core.tests.util.Util;
57
import org.eclipse.jdt.core.tests.util.Util;
57
import org.eclipse.jdt.internal.core.ClasspathEntry;
58
import org.eclipse.jdt.internal.core.ClasspathEntry;
58
import org.eclipse.jdt.internal.core.JavaModelManager;
59
import org.eclipse.jdt.internal.core.JavaModelManager;
Lines 3768-3774 Link Here
3768
 * Ensures that a duplicate entry created by editing the .classpath is detected.
3769
 * Ensures that a duplicate entry created by editing the .classpath is detected.
3769
 * (regression test for bug 24498 Duplicate entries on classpath cause CP marker to no longer refresh)
3770
 * (regression test for bug 24498 Duplicate entries on classpath cause CP marker to no longer refresh)
3770
 */
3771
 */
3771
public void testDuplicateEntries() throws CoreException {
3772
public void testDuplicateEntries1() throws CoreException {
3772
	try {
3773
	try {
3773
		IJavaProject project = this.createJavaProject("P", new String[] {"src"}, "bin");
3774
		IJavaProject project = this.createJavaProject("P", new String[] {"src"}, "bin");
3774
		this.editFile(
3775
		this.editFile(
Lines 3788-3793 Link Here
3788
		this.deleteProject("P");
3789
		this.deleteProject("P");
3789
	}
3790
	}
3790
}
3791
}
3792
/*
3793
 * Ensures that duplicate entries due to resolution are not reported
3794
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
3795
 */
3796
public void testDuplicateEntries2() throws CoreException {
3797
	try {
3798
		IJavaProject project = createJavaProject("P");
3799
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
3800
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
3801
		createFile("/P/lib.jar", "");
3802
		editFile(
3803
			"/P/.classpath",
3804
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
3805
			"<classpath>\n" +
3806
			"    <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" +
3807
			"    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
3808
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
3809
			"</classpath>"
3810
		);
3811
		assertMarkers(
3812
			"Unexpected markers",
3813
			"",
3814
			project);
3815
	} finally {
3816
		ContainerInitializer.setInitializer(null);
3817
		VariablesInitializer.setInitializer(null);
3818
		deleteProject("P");
3819
	}
3820
}
3821
/*
3822
 * Ensures that the resolved classpath doesn't contain duplicate entries due to resolution
3823
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
3824
 */
3825
public void testDuplicateEntries3() throws CoreException {
3826
	try {
3827
		IJavaProject project = createJavaProject("P");
3828
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
3829
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
3830
		createFile("/P/lib.jar", "");
3831
		editFile(
3832
			"/P/.classpath",
3833
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
3834
			"<classpath>\n" +
3835
			"    <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" +
3836
			"    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
3837
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
3838
			"</classpath>"
3839
		);
3840
		assertClasspathEquals(
3841
			project.getResolvedClasspath(true),
3842
			"/P/lib.jar[CPE_LIBRARY][K_BINARY][isExported:false]"
3843
		);
3844
	} finally {
3845
		ContainerInitializer.setInitializer(null);
3846
		VariablesInitializer.setInitializer(null);
3847
		deleteProject("P");
3848
	}
3849
}
3791
private void denseCycleDetection(final int numberOfParticipants) throws CoreException {
3850
private void denseCycleDetection(final int numberOfParticipants) throws CoreException {
3792
	
3851
	
3793
	final IJavaProject[] projects = new IJavaProject[numberOfParticipants];
3852
	final IJavaProject[] projects = new IJavaProject[numberOfParticipants];

Return to bug 175226