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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/ClasspathTests.java (-1 / +60 lines)
Lines 54-59 Link Here
54
import org.eclipse.jdt.core.JavaConventions;
54
import org.eclipse.jdt.core.JavaConventions;
55
import org.eclipse.jdt.core.JavaCore;
55
import org.eclipse.jdt.core.JavaCore;
56
import org.eclipse.jdt.core.JavaModelException;
56
import org.eclipse.jdt.core.JavaModelException;
57
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultVariableInitializer;
57
import org.eclipse.jdt.core.tests.util.Util;
58
import org.eclipse.jdt.core.tests.util.Util;
58
import org.eclipse.jdt.internal.core.ClasspathEntry;
59
import org.eclipse.jdt.internal.core.ClasspathEntry;
59
import org.eclipse.jdt.internal.core.JavaModelManager;
60
import org.eclipse.jdt.internal.core.JavaModelManager;
Lines 4497-4503 Link Here
4497
 * Ensures that a duplicate entry created by editing the .classpath is detected.
4498
 * Ensures that a duplicate entry created by editing the .classpath is detected.
4498
 * (regression test for bug 24498 Duplicate entries on classpath cause CP marker to no longer refresh)
4499
 * (regression test for bug 24498 Duplicate entries on classpath cause CP marker to no longer refresh)
4499
 */
4500
 */
4500
public void testDuplicateEntries() throws CoreException {
4501
public void testDuplicateEntries1() throws CoreException {
4501
	try {
4502
	try {
4502
		IJavaProject project = this.createJavaProject("P", new String[] {"src"}, "bin");
4503
		IJavaProject project = this.createJavaProject("P", new String[] {"src"}, "bin");
4503
		editFile(
4504
		editFile(
Lines 4517-4522 Link Here
4517
		this.deleteProject("P");
4518
		this.deleteProject("P");
4518
	}
4519
	}
4519
}
4520
}
4521
/*
4522
 * Ensures that duplicate entries due to resolution are not reported
4523
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
4524
 */
4525
public void testDuplicateEntries2() throws CoreException {
4526
	try {
4527
		IJavaProject project = createJavaProject("P");
4528
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
4529
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
4530
		createFile("/P/lib.jar", "");
4531
		editFile(
4532
			"/P/.classpath",
4533
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
4534
			"<classpath>\n" +
4535
			"    <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" +
4536
			"    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
4537
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
4538
			"</classpath>"
4539
		);
4540
		assertMarkers(
4541
			"Unexpected markers",
4542
			"",
4543
			project);
4544
	} finally {
4545
		ContainerInitializer.setInitializer(null);
4546
		VariablesInitializer.setInitializer(null);
4547
		deleteProject("P");
4548
	}
4549
}
4550
/*
4551
 * Ensures that the resolved classpath doesn't contain duplicate entries due to resolution
4552
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
4553
 */
4554
public void testDuplicateEntries3() throws CoreException {
4555
	try {
4556
		IJavaProject project = createJavaProject("P");
4557
		VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"}));
4558
		ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"}));
4559
		createFile("/P/lib.jar", "");
4560
		editFile(
4561
			"/P/.classpath",
4562
			"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
4563
			"<classpath>\n" +
4564
			"    <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" +
4565
			"    <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
4566
			"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
4567
			"</classpath>"
4568
		);
4569
		assertClasspathEquals(
4570
			project.getResolvedClasspath(true),
4571
			"/P/lib.jar[CPE_LIBRARY][K_BINARY][isExported:false]"
4572
		);
4573
	} finally {
4574
		ContainerInitializer.setInitializer(null);
4575
		VariablesInitializer.setInitializer(null);
4576
		deleteProject("P");
4577
	}
4578
}
4520
private void denseCycleDetection(final int numberOfParticipants) throws CoreException {
4579
private void denseCycleDetection(final int numberOfParticipants) throws CoreException {
4521
4580
4522
	final IJavaProject[] projects = new IJavaProject[numberOfParticipants];
4581
	final IJavaProject[] projects = new IJavaProject[numberOfParticipants];
(-)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 2510-2516 Link Here
2510
		ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
2511
		ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager();
2511
		ResolvedClasspath result = new ResolvedClasspath();
2512
		ResolvedClasspath result = new ResolvedClasspath();
2512
2513
2513
		ArrayList resolvedEntries = new ArrayList();
2514
		LinkedHashSet resolvedEntries = new LinkedHashSet();
2514
		int length = rawClasspath.length;
2515
		int length = rawClasspath.length;
2515
		for (int i = 0; i < length; i++) {
2516
		for (int i = 0; i < length; i++) {
2516
2517
Lines 2605-2611 Link Here
2605
		return result;
2606
		return result;
2606
	}
2607
	}
2607
2608
2608
	private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, ArrayList resolvedEntries, ExternalFoldersManager externalFoldersManager) {
2609
	private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager) {
2609
		IPath resolvedPath;
2610
		IPath resolvedPath;
2610
		if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) {
2611
		if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) {
2611
			result.rawReverseMap.put(resolvedPath, rawEntry);
2612
			result.rawReverseMap.put(resolvedPath, rawEntry);
(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-10 / +11 lines)
Lines 1485-1490 Link Here
1485
		if (rawClasspath == null)
1485
		if (rawClasspath == null)
1486
			return JavaModelStatus.VERIFIED_OK;
1486
			return JavaModelStatus.VERIFIED_OK;
1487
1487
1488
		// check duplicate entries on raw classpath only (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 )
1489
		int rawLength = rawClasspath.length;
1490
		HashSet pathes = new HashSet(rawLength);
1491
		for (int i = 0 ; i < rawLength; i++) {
1492
			IPath entryPath = rawClasspath[i].getPath();
1493
			if (!pathes.add(entryPath)){
1494
				String entryPathMsg = projectName.equals(entryPath.segment(0)) ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString();
1495
				return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName}));
1496
			}
1497
		}
1498
1488
		// retrieve resolved classpath
1499
		// retrieve resolved classpath
1489
		IClasspathEntry[] classpath;
1500
		IClasspathEntry[] classpath;
1490
		try {
1501
		try {
Lines 1589-1596 Link Here
1589
			for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
1600
			for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true;
1590
		}
1601
		}
1591
1602
1592
		HashSet pathes = new HashSet(length);
1593
1594
		// check all entries
1603
		// check all entries
1595
		for (int i = 0 ; i < length; i++) {
1604
		for (int i = 0 ; i < length; i++) {
1596
			IClasspathEntry entry = classpath[i];
1605
			IClasspathEntry entry = classpath[i];
Lines 1598-1611 Link Here
1598
			IPath entryPath = entry.getPath();
1607
			IPath entryPath = entry.getPath();
1599
			int kind = entry.getEntryKind();
1608
			int kind = entry.getEntryKind();
1600
1609
1601
			// Build some common strings for status message
1602
			boolean isProjectRelative = projectName.equals(entryPath.segment(0));
1603
			String entryPathMsg = isProjectRelative ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString();
1604
1605
			// complain if duplicate path
1606
			if (!pathes.add(entryPath)){
1607
				return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName}));
1608
			}
1609
			// no further check if entry coincidates with project or output location
1610
			// no further check if entry coincidates with project or output location
1610
			if (entryPath.equals(projectPath)){
1611
			if (entryPath.equals(projectPath)){
1611
				// complain if self-referring project entry
1612
				// 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
	 * Since 3.5, 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

Return to bug 175226