Bug 18953 - Package disapears when disconnected from CVS repopsitory
Summary: Package disapears when disconnected from CVS repopsitory
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 F3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 19586 19676 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-06-03 19:26 EDT by Christopher Nelson CLA
Modified: 2002-06-14 05:37 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Nelson CLA 2002-06-03 19:26:39 EDT
When disconnecting a project from a CVS repository in build 20020602, if "Also 
delete CVS meta information from the file system." is selected, the project 
disapears from the Packages view in the java perspective.  The only way I have 
foud to get the project to redisplay in the Packages view is to close eclipse 
and relaunch the program.  The project also disapears from the project view in 
the java browser perspective, but it does not disapear from the navigator view 
in the rtesource perspective.

Replication:

1.  Create a new project
2.  Right click on the project name in the Packages view in the java perspective
3.  Go to Team->Share Project
4.  Connect the project to a repository
5.  Right click on the project again
6.  Go to Team->Disconnect...
7.  Select "Also delete CVS meta information from the file system."
8.  Notice that the project is no longer shown in the Packages View.
Comment 1 Erich Gamma CLA 2002-06-09 17:42:15 EDT
can reproduce in 0706.
The .project file is correct and still shows the java nature. Also the project 
is still adorned with the J in the navigator.
Closing and reopening the project in the navigator brings the project back in 
the packages view.

Moving to JDT core for investigation.
Comment 2 Philipe Mulet CLA 2002-06-10 06:55:24 EDT
Was able to reproduce this one scenario. Problem is element type computation 
which keep the project element type once inside a java project, and until it 
enters a package fragment root.

Therefore, if a folder is removed (CVS), then the project is thought to be 
removed completely.
Comment 3 Philipe Mulet CLA 2002-06-10 08:49:25 EDT
Changing the element type computation has other implication which we cannot 
change at this point.

However, DeltaProcessor#createElement is also causing trouble, since due to the 
incorrect element type, it may answer a project element for something else 
(like non-java resource nested inside).

When tracing this scenario, it appears that currentElement was set to the 
project being touched, but the changed resource was the .project or a CVS 
folder. However, the element creation code got fooled into thinking this was 
the project being removed since it was still rooted onto it (current element 
had been positionned prior to this point).

Investigating adding protection on element creation.
Comment 4 Philipe Mulet CLA 2002-06-10 08:56:22 EDT
Proposed fix: DeltaProcessor#createElement

[	/**
	 * Creates the openables corresponding to this resource.
	 * Returns null if none was found.
	 */
	protected Openable createElement(IResource resource, int elementType, 
IJavaProject project) {
		if (resource == null) return null;
		
		IPath path = resource.getFullPath();
		IJavaElement element = null;
		switch (elementType) {
			
			case IJavaElement.JAVA_PROJECT:
			
				// note that non-java resources rooted the 
project level will also enter this code with
				// an elementType JAVA_PROJECT (see #elementType
(...)).
				if (resource instanceof IProject){

					this.popUntilPrefixOf(path);
					
					if (this.currentElement != null 
						&& 
this.currentElement.getElementType() == IJavaElement.JAVA_PROJECT
						&& ((IJavaProject)
this.currentElement).getProject().equals(resource)) {
						return this.currentElement;
					}
					if  (project != null && 
project.getProject().equals(resource)){
						element = (Openable)project;
						break;
					}
					IProject proj = (IProject)resource;
					boolean isOpened = proj.isOpen();
					if (isOpened && this.hasJavaNature
(proj)) {
						element = JavaCore.create(proj);
					} else {
						// java project may have been 
been closed or removed (look for
						// element amongst old java 
project s list).
						element =  (Openable) 
manager.getJavaModel().findJavaProject(proj);
					}
				}
				break;
			case IJavaElement.PACKAGE_FRAGMENT_ROOT:
				element = project == null ? JavaCore.create
(resource) : project.getPackageFragmentRoot(resource);
				break;
			case IJavaElement.PACKAGE_FRAGMENT:
				// find the element that encloses the resource
				this.popUntilPrefixOf(path);
				
				if (this.currentElement == null) {
					element = 
JavaModelManager.getJavaModelManager().create(resource, project);
				} else {
					// find the root
					IPackageFragmentRoot root = 
this.currentElement.getPackageFragmentRoot();
					if (root == null) {
						element = 
JavaModelManager.getJavaModelManager().create(resource, project);
					} else if (!
JavaModelManager.conflictsWithOutputLocation(path, (JavaProject)
root.getJavaProject())) {
						// create package handle
						IPath pkgPath = 
path.removeFirstSegments(root.getPath().segmentCount());
						String pkg = Util.packageName
(pkgPath);
						if (pkg == null) return null;
						element = 
root.getPackageFragment(pkg);
					}
				}
				break;
			case IJavaElement.COMPILATION_UNIT:
			case IJavaElement.CLASS_FILE:
				// find the element that encloses the resource
				this.popUntilPrefixOf(path);
				
				if (this.currentElement == null) {
					element = element = 
JavaModelManager.getJavaModelManager().create(resource, project);
				} else {
					// find the package
					IPackageFragment pkgFragment = null;
					switch 
(this.currentElement.getElementType()) {
						case 
IJavaElement.PACKAGE_FRAGMENT_ROOT:
							IPackageFragmentRoot 
root = (IPackageFragmentRoot)this.currentElement;
							IPath rootPath = 
root.getPath();
							IPath pkgPath = 
path.removeLastSegments(1);
							String pkgName = 
Util.packageName(pkgPath.removeFirstSegments(rootPath.segmentCount()));
							if (pkgName != null) {
								pkgFragment = 
root.getPackageFragment(pkgName);
							}
							break;
						case 
IJavaElement.PACKAGE_FRAGMENT:
							Openable pkg = 
(Openable)this.currentElement;
							if (pkg.getPath().equals
(path.removeLastSegments(1))) {
								pkgFragment = 
(IPackageFragment)pkg;
							} // else case of 
package x which is a prefix of x.y
							break;
						case 
IJavaElement.COMPILATION_UNIT:
						case IJavaElement.CLASS_FILE:
							pkgFragment = 
(IPackageFragment)this.currentElement.getParent();
							break;
					}
					if (pkgFragment == null) {
						element = 
JavaModelManager.getJavaModelManager().create(resource, project);
					} else {
						if (elementType == 
IJavaElement.COMPILATION_UNIT) {
							// create compilation 
unit handle 
							// fileName validation 
has been done in elementType(IResourceDelta, int, boolean)
							String fileName = 
path.lastSegment();
							element = 
pkgFragment.getCompilationUnit(fileName);
						} else {
							// create class file 
handle
							// fileName validation 
has been done in elementType(IResourceDelta, int, boolean)
							String fileName = 
path.lastSegment();
							element = 
pkgFragment.getClassFile(fileName);
						}
					}
				}
				break;
		}
		if (element == null) {
			return null;
		} else {
			this.currentElement = (Openable)element;
			return this.currentElement;
		}
	}
]
Comment 5 Philipe Mulet CLA 2002-06-10 09:31:15 EDT
Also got fix from Jerome for #elementType which got fooled by a description 
change (fooled into thinking this was a nature change).

Fixed.
Comment 6 Philipe Mulet CLA 2002-06-10 09:33:42 EDT
*** Bug 19586 has been marked as a duplicate of this bug. ***
Comment 7 Philipe Mulet CLA 2002-06-11 09:10:12 EDT
*** Bug 19676 has been marked as a duplicate of this bug. ***
Comment 8 David Audel CLA 2002-06-14 05:37:50 EDT
Verified.