Bug 65186 - Can't attach source from project directory [build path]
Summary: Can't attach source from project directory [build path]
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.0 RC3   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-01 17:38 EDT by Jared Burns CLA
Modified: 2004-06-18 07:12 EDT (History)
4 users (show)

See Also:


Attachments
Patch to apply on HEAD (3.33 KB, patch)
2004-06-10 16:04 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test. Apply on HEAD (1.66 KB, patch)
2004-06-10 16:05 EDT, Olivier Thomann CLA
no flags Details | Diff
New patch (3.44 KB, patch)
2004-06-15 19:49 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jared Burns CLA 2004-06-01 17:38:25 EDT
Build 20040529

The dialog to attach source to a JAR doesn't allow you to choose a project, only a directory. 
However, projects *are* valid directories which can contain source at the top level.

# Setup steps
1. Create a project containing a class with a main method, Hello.java.
2. Put a breakpoint in the main method.
3. Create a JAR containing only Hello.class.
# Execution steps
4. Launch Hello.class, making sure the source lookup path is empty.
5. Debug to the breakpoint. You should get the compilation unit editor.
6. Click the "Attach source" button.
7. In the resulting dialog, click "Workspace..." to browse the workspace.
8. In the resulting dialog, select the project containing Hello.java
9. The OK button disables.
7. In the dialog, click "Workspace..."
Comment 1 Jared Burns CLA 2004-06-01 18:03:44 EDT
This isn't actually related to debugging. Simpler steps:

1. Create a project containing a class with a main method, Hello.java (default package).
2. Create a JAR containing only Hello.class.
3. Double-click Hello.class.
4. A class file editor opens.
5. Click "Change attached source...".
6. In the resulting dialog, click "Workspace..."
7. Select the project containing Hello.java.
8. The OK button disables.
Comment 2 Martin Aeschlimann CLA 2004-06-07 09:24:51 EDT
I think jdt.core deosn't support this. I manipulated the jdt.ui code to allo
picking a project, but the source attachment was not taken by jdt.core.

Moving to jdt.core.
Let me know if the UI should allow picking a project as source attachment folder
Comment 3 Philipe Mulet CLA 2004-06-08 05:18:40 EDT
Olivier - pls check expectation, no feature to add; we only want to align core 
and ui here.
Comment 4 Olivier Thomann CLA 2004-06-09 10:27:16 EDT
Martin, how do you enable/disable the OK button in the source selection dialog?
Comment 5 Martin Aeschlimann CLA 2004-06-09 11:34:27 EDT
You would have to fix it in our code, comment out line
dialog.setValidator(validator);
in the 'SourceAttachmentBlock'

But you can always just type the project path yourself in the text field.
Comment 6 Olivier Thomann CLA 2004-06-09 17:26:25 EDT
Philippe,

Do you have any idea where the /P as a source attachment is discarded?
Comment 7 Olivier Thomann CLA 2004-06-10 12:09:01 EDT
I am preparing a patch for RC3.
Comment 8 Olivier Thomann CLA 2004-06-10 16:04:59 EDT
Created attachment 11906 [details]
Patch to apply on HEAD
Comment 9 Olivier Thomann CLA 2004-06-10 16:05:16 EDT
Created attachment 11907 [details]
Regression test. Apply on HEAD
Comment 10 Philipe Mulet CLA 2004-06-10 18:37:11 EDT
Jerome - pls verify
Comment 11 Olivier Thomann CLA 2004-06-10 18:43:56 EDT
Follow the steps in comment 1, now the button OK should be disabled.
If not, type /P if P is the name of the project.
Comment 12 Philipe Mulet CLA 2004-06-15 09:06:27 EDT
If we don't fix this, then the project == source folder scenario doesn't allow 
to pick this source folder as a source attachment for subsequent libraries.
Fix is safe.

Only remaining issue is that this scenario should be leveraged as well in 
build path wizard, as explained in comment #2.

Propose we only fix it if UI can leverage it.
Dirk - what is your take ?
Comment 13 Martin Aeschlimann CLA 2004-06-15 09:31:43 EDT
The UI wizard does already allow to select and also enter a project. That was 
done for RC2 and annotated in bug 65191.
Is that what you want, or should I disallow it again?
Comment 14 Dirk Baeumer CLA 2004-06-15 09:32:27 EDT
Since the UI already supports it I opt to fix it. 
Comment 15 Philipe Mulet CLA 2004-06-15 12:56:44 EDT
Ok for me as well.
Comment 16 Philipe Mulet CLA 2004-06-15 13:01:58 EDT
Jerome: pls verify change
Comment 17 Jerome Lanneluc CLA 2004-06-15 13:38:14 EDT
Olivier, in SourceMapper#computeRootPath(IContainer, HashSet, boolean) 
shouldn't the following:

if (hasJavaSourceFile) {
  IPath fullPath = container.getFullPath();
  IPath rootPathEntry = fullPath.removeFirstSegments
(this.sourcePath.segmentCount()).setDevice(null);
  this.rootPaths.add(rootPathEntry.toString());
}

be this instead ?

if (hasJavaSourceFile) {
  IPath fullPath = container2.getFullPath();
  IPath rootPathEntry = fullPath.removeFirstSegments
(this.sourcePath.segmentCount()).setDevice(null);
  this.rootPaths.add(rootPathEntry.toString());
}

Comment 18 Olivier Thomann CLA 2004-06-15 14:07:30 EDT
Yes, you are right.
In this case, container and container2 are the same. This is why it didn't fail
with the test case.
Please make the change.
Comment 19 Olivier Thomann CLA 2004-06-15 19:49:32 EDT
Created attachment 12205 [details]
New patch

Here is a new patch. In fact, "container2" is always the same container than 
"container". So I simplified that code.
Jerome, please review that patch.
Comment 20 Philipe Mulet CLA 2004-06-16 05:35:09 EDT
I am missing how the following code in SourceMapper#computeAllRootPaths(...) 
is performing ok:

Object target = JavaModel.getTarget(...);
if (target instanceof IContainer) {
  IResource resource = root.getResource();
  if (resource.getType() == IResource.FOLDER) {
     ...
  }
} else if (target instanceof File) {
  ...
}

I don't see how this change is improving anything, as it still checks for 
resource.getType() to be an IResource.FOLDER.
Also (cosmetic) for code clarity, first instanceof check should be instanceof 
IResource, then you go and check against type to be a CONTAINER (?). Indeed, 
if it is a resource to start with, it is pointless to retest whether it is an 
io.File after.
Comment 21 Jerome Lanneluc CLA 2004-06-16 07:46:46 EDT
Agreed. Changing this code to :

if (target instanceof IResource) {
	IResource resource = (IResource) target;
	if (resource instanceof IContainer) {
	  ...
	}
} else if (target instanceof File) {
  ...
}

is the right change.
Comment 22 Jerome Lanneluc CLA 2004-06-16 07:49:55 EDT
To summurarize, the fix consists in changing:
- PackageFragmentRoot#findSourceAttachmentRecommendation() 
- SourceMapper#computeAllRootPaths(...)
- SourceMapper#computeRootPath(...)
- SourceMapper#findSource(...)
to check for IContainer instead of IFolder
Comment 23 Jerome Lanneluc CLA 2004-06-16 07:55:20 EDT
Released changes decribed in comment #20 and added regression tests 
AttachSourceTests#testProjectAsClassFolder1(), #testProjectAsClassFolder2() 
and #testProjectAsSourceAttachment()
Comment 24 David Audel CLA 2004-06-18 07:12:58 EDT
Verified for 3.0RC3 I200406180010