Bug 38085 - [IDE] Open Resource shows files in build directory as well as source directories
Summary: [IDE] Open Resource shows files in build directory as well as source directories
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 major with 6 votes (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Nick Edgar CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 34905 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-05-24 17:29 EDT by Alex Blewitt CLA
Modified: 2004-11-03 14:33 EST (History)
3 users (show)

See Also:


Attachments
Fixes bug by ignoring derived resources (666 bytes, patch)
2004-04-04 21:47 EDT, Alex Blewitt CLA
no flags Details | Diff
Patch Jar file implementing patch, can be added to Eclipse startup CP to fix problem (24.29 KB, application/octet-stream)
2004-04-04 21:49 EDT, Alex Blewitt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Blewitt CLA 2003-05-24 17:29:12 EDT
In a Java project, I have a Source and a Build directory. When I use the
Open Resource menu to look at a non-Java file, the Open Resource window shows
me both the copy in the Source directory(s) and also the one in the Build
directory.

I think the Build directory source should be filtered out, since it is more
natural to want to edit the one in the Source directory(s) -- otherwise 
changes may be overwritten with the next edit to the Source file.

Clearly when the source and build directories are the same then the result
should not be filtered, but it should be filtered from the build directory
when they are different.
Comment 1 Debbie Wilson CLA 2003-05-29 11:59:32 EDT
This is happening off the Navigator view.

We have deliberately left both resources in this view.  Do you have a strong 
use case to support the exclusion of the build directory's version?  
Essentially we cannot make assumptions about how someone will want to handle 
these non-Java files.  Sometimes they are the same in the source and build 
directories but sometimes some tool has been run on the source to make 
modifications and the build version is different.  Therefore, it must be 
possible for people to see both.
Comment 2 Alex Blewitt CLA 2003-05-29 17:26:16 EDT
'Build' comes before 'Source' (or 'bin' before 'src' depending on what you call
it) with the result that the open resource will always show the build version
first.

Any modifications to this file will be lost during the next build, with the
great potential for non-Java (which could include things like XML files and
other configuration files) and be subsequently lost.

Additionally, the build directory is also usually not kept in sync with CVS
repositories which means that the changes are most likely to be lost.

Note that it does not necessarily mean that the resource cannot be edited by
direct navigation to the file in the build directory but it should not be
the default (or visible) when viewed in the Open Resource tool, which 99%+ of
the time will be to edit a file and changes should be permanent.

The Java build process copies every non-Java file from the source directory
to the build directory, so it will always be the case that a non-Java file
will be present twice in both the source and build processes.

Your argument that it may be desirable to modify a file in the particular case
of it being modified by a non-Eclipse build process is valid, but sufficently
unlikely to make the preferable option to not make it the default.

I don't understand the comment: re 'Navigator View' -- it has nothing to do
with the view directly; I raised this bug against the 'Open Resource' menu
item which is visible from other perspectives, such as the Java perspective.
Comment 3 Debbie Wilson CLA 2003-06-02 14:59:41 EDT
Am reassigning to Simon as we talked about this bug last week.  Simon, do you 
have any comments to add?
Comment 4 Eldon Metz CLA 2003-06-03 01:37:26 EDT
We've lost changes due to this issue multiple times (it has bitten one of our 
developers frequently).  We attempted to work around this issue by naming the 
output dir "zbin" and this works most of the time.  We say most of the time 
because if you enter a resource name and then press the <home> key to enter 
more chars at the beginning, the match list reverse the order in which the 
hits are shown.

We would like to see this bug fixed as lost changes can be very frustrating.  
I agree with Alex and think the best solution is to filter out the build 
directories from the open resource tool.
Comment 5 Simon Arsenault CLA 2003-06-03 13:15:12 EDT
The workbench has no idea there is such a thing as a "source" and "build" 
directories - that's all JDT stuff. All it knows is the name you typed in 
matches two resources in different folders.

Nevertheless, the dialog results need to be improved so as to avoid (or 
minimize) editing the wrong resource. If you have suggestions, please annotate 
this bug report.

My recommendation is to make use of IResource.isDerived() (maybe also isPhantom
() and isTeamPrivateMember()). This indicates the resource was created using an 
other resource. So we could filter these out, or better yet place them at the 
bottom of the list so they are still accessible.
Comment 6 Owen Nichols CLA 2003-06-03 13:24:40 EDT
In ANY case, the default behavior if the user just types a file name and hits 
enter should NEVER be to open a derived file when a non-derived file with the 
same name is present in the list of hits.  That is, I don't care so much 
whether the derived stuff is filtered out or not, just so long as the non-
derived one is listed first [regardless of how I've named my output directory 
or what sequence of keystrokes I've used to compose a pattern string].

If both the filtered and non-filtered views seem to be quite useful, perhaps a 
checkbox should be added to the Open Resource dialog to toggle the filtering.

If build and src directories are the same, then there is no derived file, 
because no copy takes place, so this issue has no bearing.
Comment 7 Alex Blewitt CLA 2003-06-03 13:25:31 EDT
I'd go further than that, and not show them if they are derived. After all,
there's not much point in editing a derived resource if they then may be 
overwritten at a later stage.

What you might like to do is have a checkbox (or preferences tab) which says
'Show derived resources in open resource window' which is initially unchecked;
that way, you'll only see the one non-derived resource when you open the
window, but it's an option that can be changed afterwards.

Note that browsing through the navigator view should let you see any resources,
whether derived or not, and as such there probably isn't any reason for showing
derived resources in the open resource window.

Of course, this assumes that everything in the build directory (compiled Java
files and non-Java copied files) are marked as derived ;-)
Comment 8 Alex Blewitt CLA 2003-06-04 10:27:39 EDT
I'm not sure this should be classified as an enhancement over a minor bug.
As raised in the first instance (and repeated in comment 4 and comment 6 above)
this has caused work to be lost when the 'wrong' file was edited.
Comment 9 Alex Blewitt CLA 2004-04-04 20:44:37 EDT
I've just spent the last couple of hours wondering why my changes haven't made it into a piece of code 
that I've tested, only to find that this bug is still kicking around in M7.

It's not an ehanchement, it's a real bug and it's causing me grief -- the suggestion to filter derived 
resources from the 'Open Resource' view as suggested in comment #5 would seem like an excellent fix 
to this problem. (on the assumption that the JDT is correctly marking copied resources from the 
'Source' to 'Build' directories as derived ... but that could be a subject of another bug.

Adding a checkbox to the 'Open resource' page to allow derived resources to be hidden/shown may be 
a possibility, but I don't see the need for ever editing a derived resource ...
Comment 10 Alex Blewitt CLA 2004-04-04 21:47:07 EDT
Created attachment 9195 [details]
Fixes bug by ignoring derived resources

Checked patch against M7, works by filtering resources from build directories
:-)
Comment 11 Alex Blewitt CLA 2004-04-04 21:49:41 EDT
Created attachment 9196 [details]
Patch Jar file implementing patch, can be added to Eclipse startup CP to fix problem

Compiled single file with patch, can insert it into existing builds by amending
org.eclipse.ui.ide_x.x.x/plugin.xml file as follows:

   <runtime>
      <library name="patch.jar">
	 <export name="*"/>
	 <packages prefixes="org.eclipse.ui"/>
      </library>
      <library name="ide.jar">
	 <export name="*"/>
	 <packages prefixes="org.eclipse.ui"/>
      </library>
   </runtime>

Provided for those working with WSAD 5.0/5.1 or Eclipse 2.1 for whom the patch
isn't going to make it in.
Comment 12 Paul Smith CLA 2004-08-02 00:05:09 EDT
This issue is so frustrating, I can't believe that it does not annoy the Eclipse 
developers themselves! :)

Please, a tick box, or filter option at the very least to allow resources in the 
build output to be excluded from view.  I have had many people confused by this, 
editing a file open from this dialog and not thinking about exactly where it is 
they are editing the file.
Comment 13 Alex Blewitt CLA 2004-08-02 06:17:10 EDT
What's worse, I fixed the bug in time for the 3.0 stream, but it didn't make it 
in ...

The JAR file attached fixes the bug for the 2.1 release; if you're interested, 
I can mail a patch for the 3.0 release (or attach one to this bug)
Comment 14 Alex Blewitt CLA 2004-10-03 04:41:51 EDT
Still applies in 3.0, still causes data loss when you open up the wrong resource and edit that instead. 
Updated bug version to apply to 3.0 in the hope this will get it fixed sooner.
Comment 15 Nick Edgar CLA 2004-10-08 14:38:24 EDT
Patch released.  Sorry this didn't make it into 3.0.

I debated adding a toggle to the UI, but unless someone complains I don't think
it's worth the additional complexity.
Comment 16 Nick Edgar CLA 2004-10-08 14:40:47 EDT
*** Bug 34905 has been marked as a duplicate of this bug. ***
Comment 17 Kim Horne CLA 2004-11-03 14:33:35 EST
Verified in 200411022000