Bug 28526 - nested src folders - deleting the outermost one deletes all nested
Summary: nested src folders - deleting the outermost one deletes all nested
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1   Edit
Hardware: PC Linux-Motif
: P3 major (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Adam Kiezun CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-17 11:18 EST by Adam Kiezun CLA
Modified: 2003-01-31 12:35 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2002-12-17 11:18:56 EST
200211216
in a project, create a src folder and another src folder nested in it
delete the outer one
boom, both are gone

need to see if it's us or jcore
Comment 1 Dirk Baeumer CLA 2002-12-17 11:34:00 EST
IMO it is ok moving both. But we have to check what refactoring does to the 
build path.
Comment 2 Dirk Baeumer CLA 2002-12-17 11:54:07 EST
I meant deleting both. After discussing with Adam and seeing it on the screen 
it might not be obvious for a user that this will delete both source folders 
since the aren't visually connected in the UI (no parent/child relationship).
Comment 3 Adam Kiezun CLA 2002-12-17 12:18:49 EST
IPackageFragmentRoot is not an ISourceManipulation
so all these routines for reorg are now implemented in the ui land, which is
suboptimal i think

everytime something fundamental changes (like the fact that you can nest source
folders now), we have to do work that is not really ui work

Phillippe, can deeper reason why IPackageFragmentRoot is not an
ISourceManipulation? Then, we could simply call 'delete/rename/copy/move' 
and jcore, which is in a much better position to do it, would do the right thing
Comment 4 Philipe Mulet CLA 2002-12-17 14:34:19 EST
Jdt/Core should honor this. Altering an enclosing source folder should not 
affect the nested one.
Comment 5 Jerome Lanneluc CLA 2003-01-08 06:39:48 EST
Adam, Dirk, 

Should the manipulations on an IPackageFragmentRoot update the classpath as 
well? If yes, what about jar files that are on several classpath? Won't users 
complain that their classpath is affected? An IWorkingSet used to be updated 
when a project was removed. It now remember the reference to the project. Not 
updating the classpath would be consistent with this behavior.
Comment 6 Adam Kiezun CLA 2003-01-08 09:52:14 EST
what we need is a way to control whether classpath is updated or not (a boolean
flag for example)

if the package fragment root is referenced by more than 1 project we could then
open a warning dialog and ask the user if they want to update other classpaths
as well
Comment 7 Jerome Lanneluc CLA 2003-01-09 09:09:56 EST
In this case, implementing ISourceManipulation wouldn't do it as it doesn't 
have a flag to control the updating of the classpath.
Comment 8 Adam Kiezun CLA 2003-01-09 09:26:03 EST
it will suffice if the required routines are declared on IPackageFragmentRoot
Comment 9 Jerome Lanneluc CLA 2003-01-15 11:11:17 EST
Adam, any objection if the copy, delete, move and rename APIs won't be allowed 
for external jars?
Comment 10 Adam Kiezun CLA 2003-01-16 09:03:04 EST
deleting of external jars should remove them from the classpath
(that's the current behavior)

how 'bbout we get a method removeFromClasspath on IPackageFRagmentRoot?
then the ui could call this method if needed

rename, copy and move are now not allowed on external jars so
i guess it's fine if you do not support it. but delete we do need to keep 
current function.

Dirk, any oppinions?
Comment 11 Jerome Lanneluc CLA 2003-01-16 09:34:12 EST
You don't seem to support renaming, moving, copying of internal jar package 
fragment root either. More generaly, what would be the meaning of copying and 
moving a library (jar or class folder) that is not in the project of the root?
Comment 12 Jerome Lanneluc CLA 2003-01-28 06:36:47 EST
Added the following API on IPackageFragmentRoot:
/**
 * Deletes the resource of this package fragment root as specified by
 * <code>IResource.delete(int, IProgressMonitor)</code> but excluding nested
 * source folders.
 * <p>
 * If specified, update the raw classpaths of all Java projects referring to
 * this root's resource by removing the corresponding classpath entries on
 * the raw classpaths.
 * </p>
 * 
 * @param updateFlags bit-wise or of update flag constants
 *   (<code>FORCE</code> and <code>KEEP_HISTORY</code>)
 * @param updateClasspath whether the classpaths of the referring projects
 * should be updated
 * @param monitor a progress monitor
 * 
 * @exception JavaModelException if this root could not be deleted. Reasons
 * include:
 * <ul>
 * <li> This root does not exist (ELEMENT_DOES_NOT_EXIST)</li>
 * <li> A <code>CoreException</code> occurred while deleting the resource
 * </li>
 * <li> This root is external (INVALID_RESOURCE_TYPE)</li>
 * </ul>
 * @see IResource#delete
 * @since 2.1
 */
void delete(int updateFlags, boolean updateClasspath, IProgressMonitor monitor) 
throws JavaModelException;

Moving back to JDT/UI to use this new API.
Comment 13 Dirk Baeumer CLA 2003-01-28 06:48:12 EST
Adam, you are the man to fix this ;-).
Comment 14 Adam Kiezun CLA 2003-01-29 09:13:12 EST
there're some problems with the current implementation of the delete method

a. it does not handle external jars so we, in the ui, 
have to handle that 1 case specially

b. if the root is internal but not local to the project (e.g. a jar declared in 
project p and put on the classpath of project p2) the method deletes it from 
the disk - it should only remove it from the classpath of p2
Comment 15 Jerome Lanneluc CLA 2003-01-29 09:47:26 EST
a. Please open a separate bug
b. I don't agree: if I select a jar and press delete, I expect it to be deleted 
from disk. If I want to remove it from the classpath, I would edit the 
classpath.
Comment 16 Adam Kiezun CLA 2003-01-29 09:53:32 EST
a. see bug 30506
b. deleting them would be scary - you select a jar in your project and it 
deletes it in some other project
Comment 17 Dirk Baeumer CLA 2003-01-29 09:59:13 EST
I agree that this is scary. The situation is comparable with links on the file 
system.
Comment 18 Jerome Lanneluc CLA 2003-01-29 10:00:24 EST
The jar appears with its full path in the package explorer. So you see that it 
doesn't belong to the current project.
Comment 19 Dirk Baeumer CLA 2003-01-29 10:52:49 EST
If I create a Test project and reference ant.jar from org.apache.ant I only see 
ant.jar.

IMO deleting a reference should never delete the original element without 
presenting a warning to the user. If no warning is presented, deleting a 
reference should never delete the original. This is fail save.

Why can't we add another flag to the updateFlag parameter to control this. Then 
the UI could present a dialog and depending on the users choice we would delete 
the jar or we would keep it.
Comment 20 Jerome Lanneluc CLA 2003-01-29 11:27:36 EST
Dirk, which build are you using? In I20030128, if I reference ant.jar from 
project Test, I see /org.apache.ant/ant.jar under Test.

I agree that a warning should be presented to the user (in all cases actually). 
But isn't the current behavior to prompt for confirmation when the user presses 
delete?
Comment 21 Philipe Mulet CLA 2003-01-29 11:39:25 EST
If no delete behavior was to be performed, then the answer is simple: don't 
call delete on the root. If you want to modify the classpath, simply use 
setRawClasspath instead.
Comment 22 Dirk Baeumer CLA 2003-01-29 11:41:00 EST
I am still using I20030122++ due to the launching problems in 28.

IMO the warning should differ depending on if you delete a reference or if you 
delete a "original" element.

For references I expect to see something like this:

You are going to delete a Jar that is located in a different project.
Do you want to delete the Jar. Doing so will affect the following
projects: <a list of projects that reference the Jar as well>

Since deleting a Jar can affect lots of projects in your workspace we should
not assume that presenting the full path is enough information for the user.
Comment 23 Dirk Baeumer CLA 2003-01-29 11:44:05 EST
Regarding Philippe's comment:

That is what we do right now. The problem is that whenever something changes 
related classpathes the UI has to be adapted as well. That's why we prefer a 
solution that Core is doing it, because you know when something with the class 
path changes and you can adapt all code places.
Comment 24 Philipe Mulet CLA 2003-01-29 12:02:33 EST
The delete API is actually meant to perform some deletion (except for external 
JARs where we don't assume we own them). Maybe we could provide a flag to state 
whether it should delete the corresponding file ? 

delete(boolean shouldDelete)  <g>
Comment 25 Adam Kiezun CLA 2003-01-30 05:44:15 EST
we are considering a different solution: 
- disabling the delete action on package fragment roots that are not residing 
in their parent projects
- adding a 'remove from build path' (see bug 30592) action that would be 
enabled on all package fragment roots and would remove them from the classpath 
of their projects 
(works for both external and internal jars, and could work for source/class 
folders as well)

opinions?
Comment 26 Jerome Lanneluc CLA 2003-01-30 05:59:30 EST
Sounds like a good compromise.

So you really need a 'shouldDelete' flag (would be false if you just want to 
update the classpath).

We're considering changing the APIs to take a bit-wise or of constants instead 
of the 'updateClasspath' boolean. How does it sound?
Comment 27 Adam Kiezun CLA 2003-01-30 06:04:23 EST
maybe add a method like
'removeFromClasspath(boolean allProjects)'

that would remove the receiver from the class path 
of its declaring project or all projects that reference it
Comment 28 Philipe Mulet CLA 2003-01-30 06:30:59 EST
Maybe the API should be called: remove, then using flags you can clarify which 
behavior you want: 
- deleteResource 
- removeFromEnclosingProjectClasspath
- removeFromAllProjectsClasspath

we are thinking of moving away from boolean flags, but rather using an int (one 
bit per flag), so as to ease further adjustments.
Comment 29 Adam Kiezun CLA 2003-01-30 07:51:45 EST
sounds good
Comment 30 Adam Kiezun CLA 2003-01-30 11:38:18 EST
please bounce back when it's there
for now, the 'remove from classpath' action (released today) 
uses our code to remove from classpath - will update to use jcore code when 
it's available 
Comment 31 Philipe Mulet CLA 2003-01-30 12:27:55 EST
It should be released in HEAD.
Comment 32 Adam Kiezun CLA 2003-01-31 12:35:37 EST
fixed!

thanks for all your help here