Skip to content

Commit

Permalink
Fixed bug when the project still present after deletion through termi…
Browse files Browse the repository at this point in the history
…nal or project service (#6013)
  • Loading branch information
Dmytro Kulieshov committed Aug 17, 2017
1 parent a3099e7 commit a27da4f
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a27da4f

Please sign in to comment.