Bug 18684 - Organize Imports doesn't work on external Jars
Summary: Organize Imports doesn't work on external Jars
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-06-03 07:01 EDT by Michael Jakl CLA
Modified: 2002-09-18 11:31 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Jakl CLA 2002-06-03 07:01:35 EDT
The Organize Imports feature of Eclipse doesn't work on libraries which
were included as "external Jars".

When I start OI it deletes all imports which would come from an library
included as "external Jar".

OI works fine with libs which were included as Jar relative to the
projectpath.
Comment 1 Michael Jakl CLA 2002-06-04 11:00:49 EDT
After some research I discovered that the problem
only occurs when the libs reside on a network drive.
Comment 2 Erich Gamma CLA 2002-06-05 06:11:24 EDT
it should not make a difference whether a lib is on a network drive or not. 
Philippe can you see how this could happen?
Comment 3 Philipe Mulet CLA 2002-06-05 07:21:10 EDT
Olivier - pls investigate
Comment 4 Olivier Thomann CLA 2002-06-05 11:10:45 EDT
Would you have a test case I can try to reproduce the problem? On what platform are you running 
Eclipse? Did you use symbolic links?
Please give me as many details as possible to reproduce 
this defect. Thanks.
Comment 5 Olivier Thomann CLA 2002-06-05 11:57:41 EDT
I cannot reproduce under Windows2000. Could you please give more details on your settings? A test 
case would be very welcome.
Comment 6 Philipe Mulet CLA 2002-06-10 09:38:32 EDT
Michael - can you provide some reproduceable steps ? It works fine for us.
Comment 7 Michael Jakl CLA 2002-06-10 10:27:10 EDT
Hi, sure, I wrote Olivier today. So I'm sorry, I can't provide a test case.
I'm running Windows 2k Pro geman with all hotfixes from the WindowsUpdate.
I have a network share on: D:\Eigene Dateien\Projekte (rw to everyone).
Now I connect a network drive (z:\) to my own machine (\\jakl\projekte) - this
is the working directory for eclipse. ("eclipse.exe -data z:\")

Now I start a new project:
Create new Java Project. Sourcefolder: "src" and outputfolder: "classes".
Now I create an folder "lib". I copy some libs to this folder (with the Windows
Explorer).

After this I add an "External Jar" from the Project Properties/Libraries dialog.
(I see this line: "webmacro.jar - Z:TestForEclipse/lib" maybe is there a missing
slash?)

Then I tried to create a new class and wanted to extend WMServlet, but it wasn't
in there. (Obviously it's not a bug in Organize Imports than in the general
function to read the libs)
I also tried log4j.jar an it worked fine on a small (new) project, but on an
larger project this one didn't work either. Webmacro.jar didn't work on both
projects.

I hope this helps a little, if you need more information or you could give me
some hints how to provide a better bugreport please feel free to contact me.

I'm sorry but I'm not familiar with JUnit.

Kind regards,
Michael
Comment 8 Olivier Thomann CLA 2002-06-11 14:31:19 EDT
I reproduced the problem, I think. It fails only if the working directory is directly a drive 
name.
For example, eclipse -data d:\ fails, but eclipse -data d:\workspace works fine.
d:\ is a 
network drive in this case. I have some problem to debug it, because d:\ is not considered as a valid 
working directory in the lanching configuration. I guess it should be, which means this is 
another problem. I will investigate this problem.
Could you please try on your machine with a 
working directory like z:\workspace and let me know if it works. I am trying to isolate the problem 
and it would help if it works for you as well. Thanks for your help.
Comment 9 Olivier Thomann CLA 2002-06-11 14:45:32 EDT
The problem is really related to the fact that the workspace is created in the root folder of the 
network drive. It might be the same for a local drive. I will double check that.
Comment 10 Olivier Thomann CLA 2002-06-11 14:55:19 EDT
I can reproduce a similar problem using a local drive. If I start eclipse with:
 -data c:\ and I 
follow the following steps, Organize imports... doesn't work properly.
1) Create a new 
project P
2) Set 'src' as a source folder for P
3) Create a folder lib in the root of P. 
4) Add a 
jar inside this folder using the Windows Explorer.
5) Refresh from local this folder. You 
should see the jar file.
6) Add this jar as a external jar to your project classpath.
7) Create a 
new class in the default package of P and write code that refers to a class inside the jar without 
qualifying the class name.
For example instead of p1.B, write simply: B.
8) Run organize 
imports. It won't add an import for the class in your jar.

9) Now remove the jar and add it again 
as an internal jar.
10) Now run again "Organize imports" and it works, but the import is 
underlined and it is said: "The import .... cannot be resolved". So there is a second problem here. 
The code compiles fine.

If Eclipse is started with a folder in the -data options, all problems 
are gone.
Comment 11 Olivier Thomann CLA 2002-06-11 15:38:43 EDT
I hacked the pde.ui launchers in order to be able to start a debug workspace on c:\. The problem with 
the external jar pointing to a local file in the workspace is that the NameLookup doesn't find the 
corresponding package fragment root and therefore it cannot retrieve any package fragments or 
types which are located inside this jar. I need to investigate what is wrong when the package 
fragment root is created.
Comment 12 Olivier Thomann CLA 2002-06-11 16:01:09 EDT
We have an inconsistency between the resolved classpath, which considers the jar package 
fragment root with its absolute path (for example c:\P\lib\myLib.jar) and the path of the jar 
package fragment root itself, which is considered as a local resource and therefore its path is 
/P/lib/myLib.jar.
Then the openWhenClosed() method on PackageFragmentRoot failed to open 
this jar package fragment root because it is not considered on the project's classpath even if 
this is the case.
So we need to understand how we got into this inconsistent state.
Comment 13 Olivier Thomann CLA 2002-06-11 17:25:22 EDT
In fact I wonder why an external jar can point to a jar inside the workspace. By definition, this is 
not an external jar and I would expect the wizard to complain about it.
Comment 14 Michael Jakl CLA 2002-06-12 04:18:15 EDT
According to your comment (2002-06-11 14:31).
I tried to put the workspace into an directory, and everything worked fine.

Thanks for your efforts.
Comment 15 Philipe Mulet CLA 2002-06-12 05:01:54 EDT
This would be a consequence of using IContainer#findMember(IPath). This API 
removes any device from the argument path, and transforms it into a relative 
path.
Comment 16 Olivier Thomann CLA 2002-06-12 09:20:18 EDT
This is a known problem with the findMember API.
Defer 2.0.
Comment 17 Philipe Mulet CLA 2002-07-25 06:59:38 EDT
Reopening
Comment 18 Philipe Mulet CLA 2002-07-25 07:00:55 EDT
Clearing resolution
Comment 19 Philipe Mulet CLA 2002-07-25 08:18:24 EDT
We should consider improving on this front:
1- ensure all jdt/core calls are going through JavaModel#getTarget
2- improve JavaModel#getTarget to better deal with such situations.
Comment 20 Jerome Lanneluc CLA 2002-08-30 06:34:43 EDT
Changed all relevant call to findMember in Java Model to use getTarget instead.

Fixed getTarget to consider that a path with a device can only be an external 
path.
Comment 21 David Audel CLA 2002-09-18 11:31:35 EDT
Verified.