Skip to content

Commit

Permalink
New folders do not register in the jdt.ls workspace eclipse-che#10115
Browse files Browse the repository at this point in the history
A draft for directory watcher

Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Aug 3, 2018
1 parent 633785e commit e475486
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,28 @@ private void updateFsTreeAndAcceptConsumables(
Set<Consumer<Path>> createConsumer,
Path path,
BasicFileAttributes attrs) {
logCallStack("[updateFsTreeAndAcceptConsumables] updating "
+ (items == directories ? "DIRs" : "FILEs")
+ ", Path: " + path.toString());
// LOG.info("[updateFsTreeAndAcceptConsumables] updating "
// + (items == directories ? "DIRs" : "FILEs")
// + ", Path: " + path.toString());
Long lastModifiedActual = attrs.lastModifiedTime().toMillis();

if (items.containsKey(path)) {
Long lastModifiedStored = items.get(path);
if (!lastModifiedActual.equals(lastModifiedStored)) {
LOG.info("\"[updateFsTreeAndAcceptConsumables] reporting to updateConsumer: size: {}, path: {}", updateConsumer.size(),path.toString());
items.put(path, lastModifiedActual);
updateConsumer.forEach(it -> it.accept(path));
updateConsumer.forEach(it -> {
LOG.info("\"[updateFsTreeAndAcceptConsumables] reporting to updateConsumer: {}, path: {}", it.getClass().getName(),path.toString());
it.accept(path);
});
}
} else {
items.put(path, lastModifiedActual);
createConsumer.forEach(it -> it.accept(path));
LOG.info("\"[updateFsTreeAndAcceptConsumables] reporting to updateConsumer: size: {}, path: {}", createConsumer.size(),path.toString());
createConsumer.forEach(it -> {
LOG.info("\"[updateFsTreeAndAcceptConsumables] reporting to createConsumer: {}, path: {}", it.getClass().getName(),path.toString());
it.accept(path);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,52 @@ public FileWatcherByPathMatcher(FileWatcherByPathValue watcher, PathTransformer
@Override
public void accept(Path path) {
if (!exists(path)) {
LOG.info("[accept] Reported path doesn't exist: {}", path.toString());
if (pathWatchRegistrations.containsKey(path)) {
pathWatchRegistrations.remove(path).forEach(watcher::unwatch);
}
paths.values().forEach(it -> it.remove(path));
paths.values().forEach(it -> {
LOG.info("[accept] Removing path: {} from '{}' [{}]", path.toString(),
it, it.getClass().getName());
it.remove(path);
});
paths.entrySet().removeIf(it -> it.getValue().isEmpty());
return;
}

for (PathMatcher matcher : matchers.keySet()) {
LOG.info("[accept] start: Reporting path {} to matcher '{}' [{}]", path.toString(),
matcher, matcher.getClass().getName());
if (matcher.matches(path)) {
for (int operationId : matchers.get(matcher)) {
paths.putIfAbsent(operationId, newConcurrentHashSet());
if (paths.get(operationId).contains(path)) {
LOG.info("[accept] Skipping path {} that is already reported to matcher '{}' [{}]", path.toString(),
matcher, matcher.getClass().getName());
return;
}

paths.get(operationId).add(path);

Operation operation = operations.get(operationId);
LOG.info("[accept] Start watching new path {} with operation {} for matcher '{}' [{}]", path.toString(),
operationId, matcher, matcher.getClass().getName());
int pathWatcherOperationId =
watcher.watch(path, operation.create, operation.modify, operation.delete);
pathWatchRegistrations.putIfAbsent(path, newConcurrentHashSet());
pathWatchRegistrations.get(path).add(pathWatcherOperationId);
LOG.info("[accept] Reporting new path {} with operation {} ('{}' [{}]) for matcher '{}' [{}]", path.toString(),
operationId, operation.create, operation.create.getClass().getName(), matcher, matcher.getClass().getName());

operation.create.accept(pathTransformer.transform(path));
}
} else {
LOG.info("[accept] Path {} doesn't match matcher '{}' [{}]", path.toString(),
matcher, matcher.getClass().getName());

}
}
LOG.info("[accept] done: Reporting path to matchers: {}", path.toString());
}
}

int watch(
Expand All @@ -92,6 +111,7 @@ int watch(
Consumer<String> modify,
Consumer<String> delete) {
LOG.debug("Watching matcher '{}'", matcher);
logCallStack("Watching matcher '" + matcher + "' [" + matcher.getClass().getName() + "]");
int operationId = operationIdCounter.getAndIncrement();

matchers.putIfAbsent(matcher, newConcurrentHashSet());
Expand All @@ -100,11 +120,13 @@ int watch(
operations.put(operationId, new Operation(create, modify, delete));

LOG.debug("Registered matcher operation set with id '{}'", operationId);
LOG.info("Registered matcher operation set with id '{}'", operationId);
return operationId;
}

void unwatch(int operationId) {
LOG.debug("Unwatching matcher operation set with id '{}'", operationId);
logCallStack("UnWatching matcher operation set with id '" + operationId + "'");
for (Entry<PathMatcher, Set<Integer>> entry : matchers.entrySet()) {
PathMatcher matcher = entry.getKey();
Set<Integer> operationsIdList = entry.getValue();
Expand Down Expand Up @@ -145,4 +167,14 @@ private Operation(Consumer<String> create, Consumer<String> modify, Consumer<Str
this.delete = delete;
}
}

public static void logCallStack(String msg) {
Exception e = new Exception(msg);
StackTraceElement[] stElements = e.getStackTrace();
String result = msg + ":";
for (StackTraceElement ste : stElements) {
result += "\n\t" + ste.toString();
}
LOG.info(result);
}
}

0 comments on commit e475486

Please sign in to comment.