Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 114820 Details for
Bug 175226
[buildpath] Build path contains duplicate entry
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix and regression tests
175226.txt (text/plain), 8.82 KB, created by
Jerome Lanneluc
on 2008-10-10 12:47:32 EDT
(
hide
)
Description:
Proposed fix and regression tests
Filename:
MIME Type:
Creator:
Jerome Lanneluc
Created:
2008-10-10 12:47:32 EDT
Size:
8.82 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v >retrieving revision 1.188 >diff -u -r1.188 ClasspathTests.java >--- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 9 Oct 2008 08:13:00 -0000 1.188 >+++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 10 Oct 2008 15:43:27 -0000 >@@ -54,6 +54,7 @@ > import org.eclipse.jdt.core.JavaConventions; > import org.eclipse.jdt.core.JavaCore; > import org.eclipse.jdt.core.JavaModelException; >+import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultVariableInitializer; > import org.eclipse.jdt.core.tests.util.Util; > import org.eclipse.jdt.internal.core.ClasspathEntry; > import org.eclipse.jdt.internal.core.JavaModelManager; >@@ -4497,7 +4498,7 @@ > * Ensures that a duplicate entry created by editing the .classpath is detected. > * (regression test for bug 24498 Duplicate entries on classpath cause CP marker to no longer refresh) > */ >-public void testDuplicateEntries() throws CoreException { >+public void testDuplicateEntries1() throws CoreException { > try { > IJavaProject project = this.createJavaProject("P", new String[] {"src"}, "bin"); > editFile( >@@ -4517,6 +4518,64 @@ > this.deleteProject("P"); > } > } >+/* >+ * Ensures that duplicate entries due to resolution are not reported >+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 ) >+ */ >+public void testDuplicateEntries2() throws CoreException { >+ try { >+ IJavaProject project = createJavaProject("P"); >+ VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"})); >+ ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"})); >+ createFile("/P/lib.jar", ""); >+ editFile( >+ "/P/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" + >+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ assertMarkers( >+ "Unexpected markers", >+ "", >+ project); >+ } finally { >+ ContainerInitializer.setInitializer(null); >+ VariablesInitializer.setInitializer(null); >+ deleteProject("P"); >+ } >+} >+/* >+ * Ensures that the resolved classpath doesn't contain duplicate entries due to resolution >+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 ) >+ */ >+public void testDuplicateEntries3() throws CoreException { >+ try { >+ IJavaProject project = createJavaProject("P"); >+ VariablesInitializer.setInitializer(new DefaultVariableInitializer(new String[] {"TEST_LIB", "/P/lib.jar"})); >+ ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", "/P/lib.jar"})); >+ createFile("/P/lib.jar", ""); >+ editFile( >+ "/P/.classpath", >+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + >+ "<classpath>\n" + >+ " <classpathentry kind=\"var\" path=\"TEST_LIB\"/>\n" + >+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" + >+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" + >+ "</classpath>" >+ ); >+ assertClasspathEquals( >+ project.getResolvedClasspath(true), >+ "/P/lib.jar[CPE_LIBRARY][K_BINARY][isExported:false]" >+ ); >+ } finally { >+ ContainerInitializer.setInitializer(null); >+ VariablesInitializer.setInitializer(null); >+ deleteProject("P"); >+ } >+} > private void denseCycleDetection(final int numberOfParticipants) throws CoreException { > > final IJavaProject[] projects = new IJavaProject[numberOfParticipants]; >#P org.eclipse.jdt.core >Index: model/org/eclipse/jdt/internal/core/JavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java,v >retrieving revision 1.417 >diff -u -r1.417 JavaProject.java >--- model/org/eclipse/jdt/internal/core/JavaProject.java 9 Oct 2008 08:13:07 -0000 1.417 >+++ model/org/eclipse/jdt/internal/core/JavaProject.java 10 Oct 2008 15:43:29 -0000 >@@ -17,6 +17,7 @@ > import java.util.HashSet; > import java.util.Hashtable; > import java.util.Iterator; >+import java.util.LinkedHashSet; > import java.util.Map; > > import javax.xml.parsers.DocumentBuilder; >@@ -2510,7 +2511,7 @@ > ExternalFoldersManager externalFoldersManager = JavaModelManager.getExternalManager(); > ResolvedClasspath result = new ResolvedClasspath(); > >- ArrayList resolvedEntries = new ArrayList(); >+ LinkedHashSet resolvedEntries = new LinkedHashSet(); > int length = rawClasspath.length; > for (int i = 0; i < length; i++) { > >@@ -2605,7 +2606,7 @@ > return result; > } > >- private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, ArrayList resolvedEntries, ExternalFoldersManager externalFoldersManager) { >+ private void addToResult(IClasspathEntry rawEntry, IClasspathEntry resolvedEntry, ResolvedClasspath result, LinkedHashSet resolvedEntries, ExternalFoldersManager externalFoldersManager) { > IPath resolvedPath; > if (result.rawReverseMap.get(resolvedPath = resolvedEntry.getPath()) == null) { > result.rawReverseMap.put(resolvedPath, rawEntry); >Index: model/org/eclipse/jdt/internal/core/ClasspathEntry.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathEntry.java,v >retrieving revision 1.105 >diff -u -r1.105 ClasspathEntry.java >--- model/org/eclipse/jdt/internal/core/ClasspathEntry.java 9 Oct 2008 08:13:07 -0000 1.105 >+++ model/org/eclipse/jdt/internal/core/ClasspathEntry.java 10 Oct 2008 15:43:29 -0000 >@@ -1485,6 +1485,17 @@ > if (rawClasspath == null) > return JavaModelStatus.VERIFIED_OK; > >+ // check duplicate entries on raw classpath only (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=175226 ) >+ int rawLength = rawClasspath.length; >+ HashSet pathes = new HashSet(rawLength); >+ for (int i = 0 ; i < rawLength; i++) { >+ IPath entryPath = rawClasspath[i].getPath(); >+ if (!pathes.add(entryPath)){ >+ String entryPathMsg = projectName.equals(entryPath.segment(0)) ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString(); >+ return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName})); >+ } >+ } >+ > // retrieve resolved classpath > IClasspathEntry[] classpath; > try { >@@ -1589,8 +1600,6 @@ > for (int i = 0; i < outputCount; i++) allowNestingInOutputLocations[i] = true; > } > >- HashSet pathes = new HashSet(length); >- > // check all entries > for (int i = 0 ; i < length; i++) { > IClasspathEntry entry = classpath[i]; >@@ -1598,14 +1607,6 @@ > IPath entryPath = entry.getPath(); > int kind = entry.getEntryKind(); > >- // Build some common strings for status message >- boolean isProjectRelative = projectName.equals(entryPath.segment(0)); >- String entryPathMsg = isProjectRelative ? entryPath.removeFirstSegments(1).toString() : entryPath.makeRelative().toString(); >- >- // complain if duplicate path >- if (!pathes.add(entryPath)){ >- return new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.classpath_duplicateEntryPath, new String[] {entryPathMsg, projectName})); >- } > // no further check if entry coincidates with project or output location > if (entryPath.equals(projectPath)){ > // complain if self-referring project entry >Index: model/org/eclipse/jdt/core/IJavaProject.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaProject.java,v >retrieving revision 1.101 >diff -u -r1.101 IJavaProject.java >--- model/org/eclipse/jdt/core/IJavaProject.java 27 Jun 2008 16:04:01 -0000 1.101 >+++ model/org/eclipse/jdt/core/IJavaProject.java 10 Oct 2008 15:43:28 -0000 >@@ -613,6 +613,11 @@ > * variables are changed, the resolved classpath can become out of date. > * Because of this, hanging on resolved classpath is not recommended. > * </p> >+ * <p> >+ * Since 3.5, if the resolution creates duplicate entries >+ * (i.e. {@link IClasspathEntry entries} which are {@link Object#equals(Object)}), >+ * only the first one is added to the resolved classpath. >+ * </p> > * > * @param ignoreUnresolvedEntry indicates how to handle unresolvable > * variables and containers; <code>true</code> indicates that missing
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 175226
:
59632
| 114820 |
116045
|
116185