Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347386

Summary: Cannot delete package from java project (two source and output folders)
Product: [Eclipse Project] JDT Reporter: Elias Volanakis <elias>
Component: CoreAssignee: Jay Arthanareeswaran <jarthana>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr
Version: 3.7Flags: amj87.iitr: review+
Target Milestone: 3.8 M6   
Hardware: PC   
OS: Windows Vista   
Whiteboard:
Attachments:
Description Flags
Project to reproduce issue
none
Proposed fix
none
Patch with test
none
alternate fix none

Description Elias Volanakis CLA 2011-05-26 19:02:16 EDT
Build Id: M20110210-1200

To reproduce:

1. Import attached project into WS
2. Select package "com", in "src" or "test" folder
3. Delete package
4. Rebuild (if autobuild off)

Result: Package "com" reappears. 
Expected: package "com" should remain deleted

Analysis: IncrementalImageBuilder re-creates a deleted package in the output folder, if that package exists in another source folder (lines:550-563). In our case, each source folder is it's own output folder, so re-creating the package does not make sense.
Comment 1 Elias Volanakis CLA 2011-05-26 19:04:58 EDT
Created attachment 196712 [details]
Project to reproduce issue
Comment 2 Ayushman Jain CLA 2011-05-27 02:48:42 EDT
Reproduced with 3.7RC2 build.
Jay, can you please investigate? thanks!
Comment 3 Jay Arthanareeswaran CLA 2011-05-27 02:49:12 EDT
In the concerned project, the output folder for both source folders, the same folders (src and test respectively) are used as output folders. When I remove that and use a different output such as \javaproj\bin, they get removed alright.

Could you try that?
Comment 4 Jay Arthanareeswaran CLA 2011-05-27 03:36:05 EDT
Sorry, I didn't look at the analysis part of the report. My bad. I will see what we can do here.
Comment 5 Jay Arthanareeswaran CLA 2011-05-27 09:32:47 EDT
Created attachment 196751 [details]
Proposed fix

Draft patch.

In the code highlighted in comment #0, we always use the bin folder that gets passed to the findSourceFiles() method. This is not correct esp. when each source folder has it's own output folder.

The patch needs additional regression test and some more testing.
Comment 6 Jay Arthanareeswaran CLA 2011-06-08 04:55:49 EDT
Created attachment 197570 [details]
Patch with test

Patch updated with new test in JavaProjectTests. Will update after running all regression tests.
Comment 7 Jay Arthanareeswaran CLA 2011-06-08 09:34:33 EDT
All existing test + new ones pass.
Comment 8 Jay Arthanareeswaran CLA 2011-06-09 00:27:23 EDT
Ayush, can you please review this? Should be straight forward.
Comment 9 Ayushman Jain CLA 2011-06-09 16:15:16 EDT
Created attachment 197730 [details]
alternate fix

Although the patch does fix the problem, I think there may be a fundamental difference in what you set out to achieve here and what the patch ends up doing. You basically wanted to make sure that deleted packages are not created back in case source folder = output folder. The fix, however, creates the deleted package in the binary folder of a source location which also happens to have a package with the same name. Note that this latter fix is a no-op in all cases (You can debug further inside the call to createFolder(..) and see why - the output folder will always have a directory corresponding to the package in question, except for the source location from where the package is being deleted, if it happens to be the output location itself.)

Hence, attaching an alternate fix here. Let me know what you think. The tests pass with it.
Comment 10 Jay Arthanareeswaran CLA 2011-06-10 02:07:19 EDT
(In reply to comment #9)
> Created attachment 197730 [details]
> alternate fix

Good catch and thanks Ayush! I think I grossly misunderstood the 'hasIndependentOutputFolder' flag. This patch looks good.
Comment 12 Ayushman Jain CLA 2012-03-12 14:23:42 EDT
Verified for 3.8M6 using build I20120306-0800