Bug 29546 - Project rebuild cannot write over .class files
Summary: Project rebuild cannot write over .class files
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M5   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-15 12:03 EST by graham_perks CLA
Modified: 2003-02-10 10:13 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description graham_perks CLA 2003-01-15 12:03:49 EST
I have a classes directory full of files that come pre-shipped to me.  My own 
class files live in the same tree as additional files.  To make this work, I 
have to deselect the Project's "Allow to clean output folders" setting.  
However now the project does not clean output files, a rebuild cannot be 
performed.

Steps to reproduce: - we'll basically create a new project with one class.

1) Make a "test" directory, with subdir "classes/otherpackage".  Put a 
dummy "fred.class" file in the otherpackage directory (it can just be a text 
file in reality, doesn't matter)

2) In Eclipse, create a new project with project contents being the "test" 
directory from step 1.  Browse to the "classes" directory as the default output 
dir.

You immediately get an error on the project about "Problems encountered while 
deleting resources".  Seems bogus to me (is this a bug in itself?), but there 
is a workaround.

3) Go to project properties->Java Compiler.  Click Use Project Settings, go to 
the Other tab, and deselect "Allow to clean output folders..." (which isn't 
very good English!  "Allow cleaning output folders" perhaps?  )  Anyway...

Click Apply, and Yes to rebuild, then OK from the project properties.  All is 
well!!

4) Create a new class, Main.java, give it a main method.  Builds great!

5) From the menu bar, click Project->Rebuild.  

You get an error "Class file not written".  

In order to workaround this, one must manually delete the .class file, Refresh 
the project, then rebuild.  But that's a lot of trouble to go to.

Be great if it would clean only the .class files relevant to the project's 
source but leave the rest of the classes directory alone.  Or, at least compile 
if the class file already exists - basically fixing the "Allow to clean output 
folders..." checkbox is broken.

Thanks!
Comment 1 graham_perks CLA 2003-01-15 12:06:25 EST
This is using the M4 build.
Comment 2 Kent Johnson CLA 2003-01-16 11:38:13 EST
Cannot reproduce... I need clarification on some of the steps.

1. Where is the 'test' directory created? Is it a subdirectory in your 
workspace (ie. a project directory, that's what I tried)? Do you need to leave 
an editor open on the dummy class OR an explorer on the 
directory 'classes/otherpackage'?

2. How do you browse to the "classes" directory as the default output dir? In 
M4, I have to edit my output folder by hand since the new project doesn't know 
it has a classes subfolder yet... the Browse button is disabled.

--------------

I believe the "Problems encountered while deleting resources" is a result of an 
open editor on the file or an explorer whose current directory 
is 'classes/otherpackage'. The builder can fail while trying to delete 
directories or files that are currently in use by other tools on your machine.

--------------

We may want to consider changing the UI since its not possible to set 
the 'cleaning' option before or at the same time as one would configure the 
output folder.

It doesn't appear to do much good after the fact if all the .class files were 
deleted.
Comment 3 graham_perks CLA 2003-01-16 11:53:05 EST
To clarify:

1. Where is the 'test' directory created?

I just created a d:\test.  For reproduction, the steps are creating a new test 
project.  I needed some directory to put the project into!

So I have:

d:\test
d:\test\classes
d:\test\classes\otherpackage
d:\test\classes\otherpackage\fred.class

Basically a class hierarchy that my project is going to be adding to.  In my 
Real World work, this is the classes directory under a Tomcat webserver.  There 
are plenty of other classes unrelated to my project, but those class files need 
to stay there!  Eclipse shouldn't be wanting to delete them.

2. Browsing to the classes directory.  I can browse.  The button is enabled for 
me.  It's for the field "Default output folder" on the Java Settings wizard 
that comes up during the New Java Project process.


I'm not really clear exactly what the bug is, because I don't know what the 
intended behaviour is!

> The builder can fail while trying to delete directories or files that are 
currently in use by other tools on your machine.

OK - but I don't want Eclipse deleting "otherpackage".  That was predelivered 
to me.  I'm not using Eclipse to build it at all.  Why is it trying to clean 
(delete) it?  That could be bug #1 - although I'm not sure what Eclipse's 
intention here is.

Definitely the Project's "Allow to clean output folders" setting is broken 
though.  If Eclipse doesn't clean out the .class files, it won't build.  You 
don't need the otherpackage stuff to see that.  Just create a test dir, create 
a new project in there, add a Main.java, go to project settings and turn off 
this setting.  Build error on Main.java.
Comment 4 graham_perks CLA 2003-01-16 11:54:16 EST
Erm, I didn't realize Bugzilla would hyperlink bug-number-1 I wasn't trying to 
refer to the first Eclipse bug report :-)
Comment 5 Kent Johnson CLA 2003-01-16 12:09:14 EST
Let's be clear here...

The option exists for you to control the cleaning behaviour. The problem is you 
cannot set it at the same time as you define your output folder.

If you were to set the output folder to 'test\bin', disable the option to clean 
the output folder, then set the output folder to 'classes'... do you see any 
problems?
Comment 6 Kent Johnson CLA 2003-01-16 15:24:14 EST
Steps to reproduce:

1. Create d:\test
2. Create a new Java project Test & point it at d:\test.
3. Create a new class X in the default package.
4. Turn off the 'cleaning' option... an error appears on the class X saying the 
class file could not be written.

---------------

This is what I get for trying to reproduce problems in our latest code. I 
released a fix to this problem on December 19th but forgot.

Graham: This is fixed in the latest integration build.

thanks
Comment 7 David Audel CLA 2003-02-10 10:13:47 EST
Verified.