if (!filter.doFilter(event)) { if (firstContext == null) { firstContext = (WatchContext) event.context();
final WatchContext context = (WatchContext) event.context(); if (event.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { if (context.getOldPath().getFileName().toString().equals(LAST_MODIFIED_MARKER_FILE)) {
final WatchContext context = (WatchContext) event.context(); if (event.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { if (context.getOldPath().getFileName().toString().equals(LAST_MODIFIED_MARKER_FILE)) {
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
@Override public boolean doFilter(WatchEvent<?> object) { final WatchContext context = (WatchContext) object.context(); if (object.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { if (shouldFilter(context.getOldPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_CREATE)) { if (shouldFilter(context.getPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_RENAME)) { if (shouldFilter(context.getOldPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_DELETE)) { if (shouldFilter(context.getOldPath())) { return true; } } return false; }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
final boolean deleted = event.kind().equals(StandardWatchEventKind.ENTRY_DELETE); final WatchContext context = (WatchContext) event.context(); final Path path = (created) ? context.getPath() : context.getOldPath();
for (WatchEvent object : events) { if (object.kind() == StandardWatchEventKind.ENTRY_MODIFY) { System.out.println("Modify: " + object.context().toString()); System.out.println("Rename: " + object.context().toString()); System.out.println("Delete: " + object.context().toString()); System.out.println("Created: " + object.context().toString());
for (WatchEvent object : events) { if (object.kind() == StandardWatchEventKind.ENTRY_MODIFY) { System.out.println("Modify: " + object.context().toString()); System.out.println("Rename: " + object.context().toString()); System.out.println("Delete: " + object.context().toString()); System.out.println("Created: " + object.context().toString());
private Pair<Path, ResourceChange> buildChange(final WatchEvent<?> event) { final WatchContext context = (WatchContext) event.context(); final Path _affectedPath; final ResourceChange result; if (event.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { _affectedPath = convert(context.getOldPath()); result = new ResourceUpdated(context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_CREATE)) { _affectedPath = convert(context.getPath()); result = new ResourceAdded(context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_RENAME)) { _affectedPath = convert(context.getOldPath()); result = new ResourceRenamed(convert(context.getPath()), context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_DELETE)) { _affectedPath = convert(context.getOldPath()); result = new ResourceDeleted(context.getMessage()); } else { _affectedPath = null; result = null; } if (_affectedPath == null) { return null; } return Pair.newPair(_affectedPath, result); }
private <T extends ResourceEvent> Pair<Path, T> buildEvent(final Class<T> clazz, final WatchEvent<?> event) { final WatchContext context = (WatchContext) event.context();