From a27da4f09f20b7e945bce8c89c79ea17f585a86b Mon Sep 17 00:00:00 2001 From: Dmytro Kulieshov Date: Thu, 17 Aug 2017 15:00:35 +0300 Subject: [PATCH] Fixed bug when the project still present after deletion through terminal or project service (#6013) --- .../api/project/server/ProjectManager.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java index 02c515abfc5..a1552277dd7 100644 --- a/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java +++ b/wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/project/server/ProjectManager.java @@ -48,6 +48,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Singleton; @@ -64,6 +65,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import static java.lang.String.format; import static org.eclipse.che.api.core.ErrorCodes.NOT_UPDATED_PROJECT; +import static org.eclipse.che.api.vfs.watcher.FileWatcherManager.EMPTY_CONSUMER; /** * Facade for all project related operations. @@ -85,6 +87,8 @@ public class ProjectManager { private final WorkspaceProjectsSyncer workspaceProjectsHolder; private final FileWatcherManager fileWatcherManager; + private int rootProjcetOperationSetId; + @Inject public ProjectManager(VirtualFileSystemProvider vfsProvider, ProjectTypeRegistry projectTypeRegistry, @@ -112,6 +116,24 @@ public ProjectManager(VirtualFileSystemProvider vfsProvider, .setDaemon(true).build()); } + @PostConstruct + private void postConstruct() { + String rootPath = vfs.getRoot().getPath().toString(); + rootProjcetOperationSetId = fileWatcherManager.registerByPath(rootPath, EMPTY_CONSUMER, EMPTY_CONSUMER, projectPath -> { + try { + projectRegistry.removeProjects(projectPath); + workspaceProjectsHolder.sync(projectRegistry); + } catch (ServerException e) { + LOG.error("Could not remove or synchronize project: {}", projectPath); + } + }); + } + + @PreDestroy + private void preDestroy() { + fileWatcherManager.unRegisterByPath(rootProjcetOperationSetId); + } + void initWatcher() throws IOException { FileWatcherNotificationListener defaultListener = new FileWatcherNotificationListener(file -> !(file.getPath().toString().contains(".che")