Bug 3648

Summary: Java source attachment lost when same JAR added to another project (1GDKX8O)
Product: [Eclipse Project] JDT Reporter: Jim des Rivieres <jeem>
Component: UIAssignee: Martin Aeschlimann <martinae>
Status: RESOLVED WORKSFORME QA Contact:
Severity: major    
Priority: P1    
Version: 2.0   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Jim des Rivieres CLA 2001-10-10 22:58:34 EDT
The Java source attachment for an external JAR gets lost when the same JAR is 
added to another project. While it is a desirable feature that all source attachments
are maintained at the workspace level (i.e., shared between probjects), this bug 
cripples that feature.

1. create a Java project P1; add an external JAR to P1
	D:/eclipse105-jdk/eclipse/plugins/org.eclipse.core.runtime/runtime.zip
with source attachment
	D:/eclipse105-jdk/eclipse/plugins/org.eclipse.core.runtime/runtimesrc.zip

2. In package view of P1, select the JAR and open its Properties.

Observe: It has a Java source attachment.

3. create a Java project P2; add the same external JAR to P2
	D:/eclipse105-jdk/eclipse/plugins/org.eclipse.core.runtime/runtime.zip
with no source attachment

4 [details]. In package view of P1, select the JAR and open its Properties.

Observe: It has lost its Java source attachment.

Expectation: As soon as I said I wanted to add the JAR, it should have
recognized that this JAR was already known in this workspace to have
a source attachment. The source attachment should have been picked
up and preserved (and had I opened the subdialog to set the source
attachment, I should see the value already primed).

NOTES:

OT (17/05/2001 3:53:28 PM)
	The problem seems to be related to the fact that the source attachement property are stored according to the path. So for two external jars the source attachement property is
	identical. Then when adding the second time the same external jar to a different project, the source attachement of the first one is deleted.
	The following method should test if the root has a source attachement path before deleting it. In the example, entry.getSourceAttachementPath() and 
	entry.getSourceAttachmentRootPath() are null when we add the second external jar without any source attachement. But if you check the value of root.getSourceAttachementPath()
	and root.getSourceAttachmentRootPath() before executing root.attachSource(sourcePath, sourcePrefix, null); you will find that the two values are not null and point to the previous
	source attachement settings for the first external jar added in the first project.

org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock.attachSource(IPath, CPListElement)
	private void attachSource(IPath path, CPListElement entry) throws CoreException {
		IPackageFragmentRoot root= fCurrJProject.findPackageFragmentRoot(path);
		if (root != null && root.isArchive()) {
			IPath sourcePath= entry.getSourceAttachmentPath();
			IPath sourcePrefix= entry.getSourceAttachmentRootPath();
			root.attachSource(sourcePath, sourcePrefix, null);
			JavaDocAccess.setJavaDocLocation(root, entry.getJavaDocLocation());
		}
	}

	Should move to ITPJUI.

MA (5/22/01 4:38:14 PM)
	lots of changes with source attachments
	please verify

PA (5/29/01 2:44:18 PM)
	build 113
	still problems:
	- 2 Projects
	- both use the same rt.jar and src.jar (but dont take ./jre/rt.jar, use rt.jar and src.jar provided by JDK)
	-> 2nd project has no source attachment !

MA (5/30/01 6:15:13 PM)
	cant reproduce. asked P for a reproducable case
Comment 1 DJ Houghton CLA 2001-10-24 07:15:30 EDT
PRODUCT VERSION:

build 105

Comment 2 Martin Aeschlimann CLA 2001-11-01 04:45:23 EST
close. seems to work.