### Eclipse Workspace Patch 1.0 #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.441 diff -u -r1.441 JavaProject.java --- model/org/eclipse/jdt/internal/core/JavaProject.java 22 Dec 2010 05:56:55 -0000 1.441 +++ model/org/eclipse/jdt/internal/core/JavaProject.java 7 Feb 2011 05:27:09 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2744,6 +2744,12 @@ if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) { externalFoldersManager.addFolder(resolvedPath, true/*scheduleForCreation*/); // no-op if not an external folder or if already registered } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336376 + // The source attachment path could be external too and in which case, must be added. + IPath sourcePath = resolvedEntry.getSourceAttachmentPath(); + if (sourcePath != null && ExternalFoldersManager.isExternalFolderPath(sourcePath)) { + externalFoldersManager.addFolder(sourcePath, true); + } } private void copyFromOldChainedEntry(ClasspathEntry resolvedEntry, ClasspathEntry chainedEntry) { #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java,v retrieving revision 1.67 diff -u -r1.67 AttachSourceTests.java --- src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 25 Oct 2010 10:30:07 -0000 1.67 +++ src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 7 Feb 2011 05:27:11 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,15 +11,22 @@ package org.eclipse.jdt.core.tests.model; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.net.URI; +import java.util.Hashtable; import junit.framework.Test; +import org.eclipse.core.filesystem.URIUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -40,6 +47,7 @@ import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.core.ExternalFoldersManager; import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.util.Util; @@ -1561,4 +1569,73 @@ attachSource(root, null, null); // detach source root.close(); } +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=336376 + */ +public void testBug336046() throws Exception { + String externalSourceLocation = getExternalFolder() + File.separator + "336046src"; + IJavaProject project = this.getJavaProject("/AttachSourceTests"); + Hashtable javaCoreOptions = JavaCore.getOptions(); + IJavaProject importedProject = null; + try { + + String classpathContent = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + + IPath sourceLocation = project.getProject().getLocation(); + IPath destination = new Path(getExternalFolder()).append("ImportedProject"); + String classpathLocation = destination.append(".classpath").toString(); + File srcFolder = destination.append("336046src").toFile(); + copyDirectory(new File(sourceLocation.toString()), new File(destination.toString())); + + project.getProject().close(null); + + System.out.println("classpathLocation: "+ classpathLocation); + System.out.println("project location:" + sourceLocation); + FileOutputStream fos = new FileOutputStream(classpathLocation); + fos.write(classpathContent.getBytes()); + assertTrue(srcFolder.renameTo(new File(getExternalFolder() + File.separator + "336046src"))); + fos.close(); + + + IProject newProject = workspace.getRoot().getProject("ImportedProject"); + URI uri= URIUtil.toURI(destination); + IProjectDescription desc = workspace.newProjectDescription(newProject.getName()); + desc.setLocationURI(uri); + newProject.create(desc, null); + if (!newProject.isOpen()) { + newProject.open(null); + } + importedProject = JavaCore.create(newProject); + importedProject.setOptions(project.getOptions(false)); + + ((JavaProject)importedProject).resolveClasspath(importedProject.getRawClasspath()); + IFolder linkedFolder = ExternalFoldersManager.getExternalFoldersManager().getFolder(new Path(getExternalFolder() + File.separator + "336046src")); + assertNotNull(linkedFolder); + } + finally { + if (importedProject != null) + importedProject.getProject().delete(true, true, null); + project.getProject().open(null); + JavaCore.setOptions(javaCoreOptions); + } +} }