Skip to content

Commit

Permalink
Should not delete the project javanature when removing a nested .clas…
Browse files Browse the repository at this point in the history
…spath resource file (#2750)
  • Loading branch information
testforstephen committed Jul 10, 2023
1 parent 8cff372 commit 9752381
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ default void refresh(IResource resource, CHANGE_TYPE changeType, IProgressMonito
if (changeType == CHANGE_TYPE.DELETED) {
if (IJavaProject.CLASSPATH_FILE_NAME.equals(resource.getName())) {
IProject project = resource.getProject();
if (ProjectUtils.isJavaProject(project)) {
if (ProjectUtils.isJavaProject(project) && (resource.equals(project.getFile(IJavaProject.CLASSPATH_FILE_NAME))
|| resource.getProjectRelativePath().segmentCount() == 1)) {
ProjectUtils.removeJavaNatureAndBuilder(project, monitor);
update(project, true, monitor);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="target"/>
</classpath>
17 changes: 17 additions & 0 deletions org.eclipse.jdt.ls.tests/projects/eclipse/classpath3/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>classpath3</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>
</natures>
</projectDescription>
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.managers.AbstractProjectsManagerBasedTest;
Expand Down Expand Up @@ -98,4 +99,20 @@ public void testDeleteClasspath() throws Exception {
IFile bin = project.getFile("bin");
assertFalse(bin.getRawLocation().toFile().exists());
}

@Test
public void testDeleteNonMetadataClasspath() throws Exception {
String name = "classpath3";
importProjects("eclipse/" + name);
IProject project = getProject(name);
assertNotNull(project);
IFile dotClasspath = project.getFile(new Path("resources/.classpath"));
File file = FileUtil.toPath(dotClasspath.getLocationURI()).toFile();
assertTrue(file.exists());
file.delete();
projectsManager.fileChanged(file.toPath().toUri().toString(), CHANGE_TYPE.DELETED);
waitForBackgroundJobs();
project = getProject(name);
assertTrue(ProjectUtils.isJavaProject(project));
}
}

0 comments on commit 9752381

Please sign in to comment.