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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 2744-2749 Link Here
2744
		if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) {
2744
		if (resolvedEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && ExternalFoldersManager.isExternalFolderPath(resolvedPath)) {
2745
			externalFoldersManager.addFolder(resolvedPath, true/*scheduleForCreation*/); // no-op if not an external folder or if already registered
2745
			externalFoldersManager.addFolder(resolvedPath, true/*scheduleForCreation*/); // no-op if not an external folder or if already registered
2746
		}
2746
		}
2747
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336376
2748
		// The source attachment path could be external too and in which case, must be added.
2749
		IPath sourcePath = resolvedEntry.getSourceAttachmentPath();
2750
		if (sourcePath != null && ExternalFoldersManager.isExternalFolderPath(sourcePath)) {
2751
			externalFoldersManager.addFolder(sourcePath, true);
2752
		}
2747
	}
2753
	}
2748
2754
2749
	private void copyFromOldChainedEntry(ClasspathEntry resolvedEntry, ClasspathEntry chainedEntry) {
2755
	private void copyFromOldChainedEntry(ClasspathEntry resolvedEntry, ClasspathEntry chainedEntry) {
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-1 / +78 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 11-25 Link Here
11
package org.eclipse.jdt.core.tests.model;
11
package org.eclipse.jdt.core.tests.model;
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.io.FileOutputStream;
14
import java.io.IOException;
15
import java.io.IOException;
16
import java.net.URI;
17
import java.util.Hashtable;
15
18
16
import junit.framework.Test;
19
import junit.framework.Test;
17
20
21
import org.eclipse.core.filesystem.URIUtil;
18
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProjectDescription;
21
import org.eclipse.core.resources.IResource;
26
import org.eclipse.core.resources.IResource;
27
import org.eclipse.core.resources.IWorkspace;
22
import org.eclipse.core.resources.IncrementalProjectBuilder;
28
import org.eclipse.core.resources.IncrementalProjectBuilder;
29
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
31
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.Path;
32
import org.eclipse.core.runtime.Path;
Lines 40-45 Link Here
40
import org.eclipse.jdt.core.dom.ASTNode;
47
import org.eclipse.jdt.core.dom.ASTNode;
41
import org.eclipse.jdt.core.dom.ASTParser;
48
import org.eclipse.jdt.core.dom.ASTParser;
42
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
49
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
50
import org.eclipse.jdt.internal.core.ExternalFoldersManager;
43
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
51
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
44
import org.eclipse.jdt.internal.core.JavaProject;
52
import org.eclipse.jdt.internal.core.JavaProject;
45
import org.eclipse.jdt.internal.core.util.Util;
53
import org.eclipse.jdt.internal.core.util.Util;
Lines 1561-1564 Link Here
1561
	attachSource(root, null, null); // detach source
1569
	attachSource(root, null, null); // detach source
1562
	root.close();
1570
	root.close();
1563
}
1571
}
1572
/**
1573
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=336376
1574
 */
1575
public void testBug336046() throws Exception {
1576
	String externalSourceLocation = getExternalFolder() + File.separator + "336046src";
1577
	IJavaProject project = this.getJavaProject("/AttachSourceTests");
1578
	Hashtable javaCoreOptions = JavaCore.getOptions();
1579
	IJavaProject importedProject = null;
1580
	try {
1581
		
1582
		String classpathContent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
1583
		"<classpath>\n" +
1584
		"    <classpathentry kind=\"lib\" path=\"attach.jar\"/>\n" +
1585
		"    <classpathentry kind=\"lib\" path=\"attach2.jar\"/>\n" +
1586
		"    <classpathentry kind=\"lib\" path=\"test.jar\"/>\n" + 
1587
		"    <classpathentry kind=\"lib\" path=\"update.jar\"/>\n" +   
1588
		"    <classpathentry kind=\"lib\" path=\"full.jar\"/>\n" +
1589
		"    <classpathentry kind=\"lib\" path=\"test2.jar\"/>\n" +  
1590
		"    <classpathentry kind=\"lib\" path=\"test4.jar\"/>  \n" +  
1591
		"    <classpathentry kind=\"lib\" path=\"test5.jar\"/>  \n" +  
1592
		"    <classpathentry kind=\"lib\" path=\"test6.jar\"/>\n" +
1593
		"    <classpathentry kind=\"lib\" path=\"test7.jar\"/>\n" +
1594
		"    <classpathentry kind=\"lib\" path=\"267046.jar\"/>\n" +
1595
		"    <classpathentry kind=\"lib\" path=\"bug336046.jar\" sourcepath=\"" + externalSourceLocation + "\"/>\n" +
1596
		"    <classpathentry kind=\"lib\" path=\"lib\"/>\n" +
1597
		"    <classpathentry kind=\"src\" path=\"src\" output=\"src\"/>\n" +
1598
		"    <classpathentry kind=\"var\" path=\"JCL_LIB\"/>\n" +
1599
		"    <classpathentry kind=\"output\" path=\"bin\"/>\n" +
1600
		"</classpath>";
1601
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
1602
		
1603
		IPath sourceLocation = project.getProject().getLocation();
1604
		IPath destination = new Path(getExternalFolder()).append("ImportedProject");
1605
		String classpathLocation = destination.append(".classpath").toString();
1606
		File srcFolder = destination.append("336046src").toFile();
1607
		copyDirectory(new File(sourceLocation.toString()), new File(destination.toString()));
1608
	
1609
		project.getProject().close(null);
1610
1611
		System.out.println("classpathLocation: "+ classpathLocation);
1612
		System.out.println("project location:" + sourceLocation);
1613
		FileOutputStream fos = new FileOutputStream(classpathLocation);
1614
		fos.write(classpathContent.getBytes());
1615
		assertTrue(srcFolder.renameTo(new File(getExternalFolder() + File.separator + "336046src")));
1616
		fos.close();
1617
1618
		
1619
		IProject newProject = workspace.getRoot().getProject("ImportedProject");
1620
		URI uri=  URIUtil.toURI(destination);
1621
		IProjectDescription desc = workspace.newProjectDescription(newProject.getName());
1622
		desc.setLocationURI(uri);
1623
		newProject.create(desc, null);
1624
		if (!newProject.isOpen()) {
1625
			newProject.open(null);
1626
		}
1627
		importedProject = JavaCore.create(newProject);
1628
		importedProject.setOptions(project.getOptions(false));
1629
1630
		((JavaProject)importedProject).resolveClasspath(importedProject.getRawClasspath());
1631
		IFolder linkedFolder = ExternalFoldersManager.getExternalFoldersManager().getFolder(new Path(getExternalFolder() + File.separator + "336046src"));
1632
		assertNotNull(linkedFolder);
1633
	}
1634
	finally {
1635
		if (importedProject != null)
1636
			importedProject.getProject().delete(true, true, null);
1637
		project.getProject().open(null);
1638
		JavaCore.setOptions(javaCoreOptions);
1639
	}
1640
}
1564
}
1641
}

Return to bug 336046