Bug 12977 - Adding Java nature to a project does not bring it to like in package view
Summary: Adding Java nature to a project does not bring it to like in package view
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 12392 14284 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-04-08 07:48 EDT by Philipe Mulet CLA
Modified: 2002-05-14 11:15 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2002-04-08 07:48:48 EDT
Build 20020404

Adding Java nature is not enough to cause a project to show up inside
the package view.

Steps:
1- create base project "Proj"
2- edit its .project file to add Java nature & builder:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>Proj</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.jdt.core.javabuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.jdt.core.javanature</nature>
		<nature>org.eclipse.team.cvs.core.cvsnature</nature>
	</natures>
</projectDescription>

3- switch to package view, notice that project "Proj" isn't there.

Now go back to navigator, and force close/open of "Proj". It is now listed 
amongst other Java projects in package view.
Comment 1 Philipe Mulet CLA 2002-04-08 07:49:32 EDT
Did we get a delta when the nature got added ? Suspect we did, but the nature 
was not added yet, so we did not consider it...
Comment 2 Jerome Lanneluc CLA 2002-04-09 09:00:06 EDT
You need to go through IProject.setDesription(...) to add a java nature to a 
project. This is done if you use the UI (see Properties->Capabilities).

If you just edit the .project file, platform is not aware of the change.
Moving to Platform/Core for information.
Comment 3 Philipe Mulet CLA 2002-04-09 10:28:37 EDT
I kind of remember platform advertizing this .project file as being reconciled 
(like we do for .classpath file).

Isn't it true ?
Comment 4 DJ Houghton CLA 2002-04-09 11:18:12 EDT
I tried adding the java nature:
- via an editor on the .project file
- using Notepad in Windows Explorer and then doing a refresh local on the 
project

Both times a delta was fired saying that the project description had changed 
and there was a content change on the .project file.

Moving to JDT/Core for comment.
Comment 5 Jerome Lanneluc CLA 2002-04-09 11:39:10 EDT
We were not clear enough. The problem is that configure() is not called on the 
java project when the project description is set.

Moving back to Platform/Core
Comment 6 DJ Houghton CLA 2002-04-09 17:56:16 EDT
Ahh, that explains the problem. The #configure method should only be called 
once on a particular nature, and when we discover new natures via the above 2 
scenerios we do not call #configure.

Check out the UI doc on Natures/Capabilities for more information about when 
#configure is called.

http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-ui-
home/project-capabilities/Proposal.html

Is it possible to listen for resource changes on the project description in 
your case? 

The problem is that in the case where we discover a project nature has been 
added to the description file manually, #configure may have already been 
called on that nature. Consider the scenerio where we are loading a project 
from the server. The team provider copies the .project file to the project 
content location and then it is discovered by us. In most cases #configure has 
already been run by the person who originally shared this project, and thus 
the build spec has already been updated, etc etc. (whatever else the nature's 
#configure method does)

If you are providing the "edit .project manually" as a work-around to another 
problem, note that adding the java builder to the build spec along with the 
java nature will get the project to appear in the packages view. Is having 
users add this second entry reasonable for your work-around?
Comment 7 John Arthorne CLA 2002-04-25 16:22:57 EDT
See also bug 14284.  JDT Core should listen for project description changes in 
the delta.  Moving to JDT Core for comment.
Comment 8 Jerome Lanneluc CLA 2002-04-29 06:20:34 EDT
We can listen for project description changes, but there is no project 
description delta that I can see. So how do we know that the java nature was 
added or removed?
Comment 9 Philipe Mulet CLA 2002-04-29 07:44:50 EDT
If the .project is reconciled, it must be done entirely by the platform, like 
we do for .classpath reconciliation. It is part of the contract that platform 
is configuring natures when added, and deconfiguring natures when removed.

Thus if the nature is added through .project edits, it should still call 
#configure. If not, then consistently it should never do it, and always notify 
a precise delta for it, in reaction to which we would internally call 
#configure.

Moving to Platform/Core for comments.
Comment 10 John Arthorne CLA 2002-04-29 12:27:48 EDT
The contract is that configure/deconfigure is called when a nature is 
added/removed via IProject.setDescription.  The purpose of allowing edits to 
.project is to support "catching up" to project (de)configures that happened in 
another workspace.  In this case, the primary consequence of the (de)configure, 
updating the project build spec, has already happened.  This is described in 
more detail in the nature proposal that DJ included a link to.  Look at the 
final section entitled, "When are natures configured".

However, your problem remains.  How do you detect that a project has just become 
a java project, or has just become a non-java project?  Can you just query the 
java model when the project description changes to see if that project is found 
in the model?  Jeem, do you have any ideas about how they should deal with this? 
 It would be possible for us to expose the old project description in the delta 
if necessary.
Comment 11 John Arthorne CLA 2002-04-29 12:30:00 EDT
*** Bug 14284 has been marked as a duplicate of this bug. ***
Comment 12 John Arthorne CLA 2002-05-01 12:50:02 EDT
Moving back to JDT Core ;-)

You should be able to detect based on the resource delta when a project has 
become a java project.  If the description has changed and the java nature is 
present, but that project is not found in the java model, then you should 
consider this to be a new java project.

If you don't think this is possible, let us know and we can look into 
alternatives.
Comment 13 DJ Houghton CLA 2002-05-01 13:01:32 EDT
Moving back to Platform/Core.

We will revisit the strategy w.r.t. Nature configure/deconfigure to ensure we 
are doing the right thing.
Comment 14 Jerome Lanneluc CLA 2002-05-02 12:42:34 EDT
After discussion between Jim and Philippe, it was decided that the problem 
should be handled by JDT/Core for now.

Moving back to JDT/Core.
Comment 15 Jerome Lanneluc CLA 2002-05-02 12:57:54 EDT
Changed configure() and deconfigure() on JavaProject to just add/remove the 
java builder. 
Changed DeltaProcessor so that it listens for DESCRIPTION changes.
Comment 16 Philipe Mulet CLA 2002-05-14 11:15:11 EDT
*** Bug 12392 has been marked as a duplicate of this bug. ***