Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not recognize file in workspace root as project #11264

Merged
merged 2 commits into from
Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,13 @@ public void onExecute() {
private Promise<Void> doProcessMultipleChanges(List<FileChange> changes) {
Promise<Void> multipleChainPromise = ProjectTreeChangeHandler.this.promises.resolve(null);

List<FileChange> preProcessedChanges = skipFilesInTheRootDirectory(changes);

multipleChainPromise =
multipleChainPromise.thenPromise(ignored -> doProcessDeleteChanges(changes));
multipleChainPromise.thenPromise(ignored -> doProcessDeleteChanges(preProcessedChanges));

multipleChainPromise =
multipleChainPromise.thenPromise(ignored -> doProcessUpdateChanges(changes));
multipleChainPromise.thenPromise(ignored -> doProcessUpdateChanges(preProcessedChanges));

return multipleChainPromise;
}
Expand Down Expand Up @@ -196,6 +198,10 @@ private boolean isNotDeleteChange(FileChange change) {
return change.getType() != DELETED;
}

private boolean isFileInRootDirectory(FileChange change) {
return change.isFile() && Path.valueOf(change.getPath()).segmentCount() == 1;
}

private List<FileChange> getDeleteFileChanges(List<FileChange> changes) {
return changes.stream().filter(this::isDeleteChange).collect(toList());
}
Expand All @@ -204,6 +210,13 @@ private List<FileChange> getUpdateFileChanges(List<FileChange> changes) {
return changes.stream().filter(this::isNotDeleteChange).collect(toList());
}

private List<FileChange> skipFilesInTheRootDirectory(List<FileChange> changes) {
List<FileChange> newChanges = new ArrayList<>(changes);
newChanges.removeIf(this::isFileInRootDirectory);

return newChanges;
}

private List<Path> getUpdateFileChangePaths(List<FileChange> changes) {
return changes.stream().map(FileChange::getPath).map(Path::valueOf).collect(toList());
}
Expand Down Expand Up @@ -252,6 +265,10 @@ private ResourceDelta getResourceDelta(FileChange change) {
}

private Promise<Void> doProcessSingleChange(FileChange change) {
if (isFileInRootDirectory(change)) {
return promises.resolve(null);
}

return isNullOrEmpty(change.getPath())
? synchronizeChanges()
: synchronizeChanges(getResourceDelta(change));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@
public interface FileChange {
String getPath();

boolean isFile();

FileWatcherEventType getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public interface ProjectTreeStateUpdateDto extends FileChange {

ProjectTreeStateUpdateDto withPath(String path);

boolean isFile();

ProjectTreeStateUpdateDto withFile(boolean isFile);

FileWatcherEventType getType();

ProjectTreeStateUpdateDto withType(FileWatcherEventType type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
public class RootDirCreationHandler {
private final FileWatcherManager fileWatcherManager;
private final ProjectConfigRegistry projectConfigRegistry;
private HiddenItemPathMatcher hiddenItemPathMatcher;
private final HiddenItemPathMatcher hiddenItemPathMatcher;
private final RootDirPathProvider rootDirPathProvider;

@Inject
public RootDirCreationHandler(
FileWatcherManager fileWatcherManager,
ProjectConfigRegistry projectConfigRegistry,
HiddenItemPathMatcher hiddenItemPathMatcher) {
HiddenItemPathMatcher hiddenItemPathMatcher,
RootDirPathProvider rootDirPathProvider) {
this.fileWatcherManager = fileWatcherManager;
this.projectConfigRegistry = projectConfigRegistry;
this.hiddenItemPathMatcher = hiddenItemPathMatcher;
this.rootDirPathProvider = rootDirPathProvider;
}

@PostConstruct
Expand All @@ -43,7 +46,8 @@ private void registerOperation() {
}

private void consumeCreate(String wsPath) {
if (!hiddenItemPathMatcher.matches(Paths.get(wsPath))) {
if (!hiddenItemPathMatcher.matches(Paths.get(wsPath))
&& Paths.get(rootDirPathProvider.get(), wsPath).toFile().isDirectory()) {
projectConfigRegistry.putIfAbsent(wsPath, true, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.inject.Singleton;
import org.eclipse.che.api.core.jsonrpc.commons.RequestHandlerConfigurator;
import org.eclipse.che.api.core.jsonrpc.commons.RequestTransmitter;
import org.eclipse.che.api.project.server.impl.RootDirPathProvider;
import org.eclipse.che.api.project.shared.dto.event.ProjectTreeStateUpdateDto;
import org.eclipse.che.api.project.shared.dto.event.ProjectTreeTrackingOperationDto;
import org.eclipse.che.api.project.shared.dto.event.ProjectTreeTrackingOperationDto.Type;
Expand All @@ -55,15 +56,18 @@ public class ProjectTreeTracker {
private final RequestTransmitter transmitter;
private final FileWatcherManager fileWatcherManager;
private final HiddenItemPathMatcher hiddenItemPathMatcher;
private final RootDirPathProvider rootDirPathProvider;

@Inject
public ProjectTreeTracker(
RequestTransmitter transmitter,
FileWatcherManager fileWatcherManager,
HiddenItemPathMatcher hiddenItemPathMatcher) {
HiddenItemPathMatcher hiddenItemPathMatcher,
RootDirPathProvider rootDirPathProvider) {
this.transmitter = transmitter;
this.fileWatcherManager = fileWatcherManager;
this.hiddenItemPathMatcher = hiddenItemPathMatcher;
this.rootDirPathProvider = rootDirPathProvider;
}

@Inject
Expand Down Expand Up @@ -147,7 +151,10 @@ private Consumer<String> getCreateOperation(String endpointId) {
timers.remove(it);
} else {
ProjectTreeStateUpdateDto params =
newDto(ProjectTreeStateUpdateDto.class).withPath(it).withType(CREATED);
newDto(ProjectTreeStateUpdateDto.class)
.withPath(it)
.withFile(isFile(it))
.withType(CREATED);
transmitter
.newRequest()
.endpointId(endpointId)
Expand Down Expand Up @@ -191,6 +198,10 @@ public void run() {
};
}

private boolean isFile(String path) {
return Paths.get(rootDirPathProvider.get(), path).toFile().isFile();
}

private boolean isExcluded(String path) {
String parentPath = parentOf(path);
return isRoot(parentPath) && hiddenItemPathMatcher.matches(Paths.get(path));
Expand Down