Search in sources :

Example 1 with PathMatcher

use of java.nio.file.PathMatcher in project che by eclipse.

the class FileWatcherUtilsTest method shouldBeExcluded.

@Test
public void shouldBeExcluded() throws Exception {
    PathMatcher matcher = Mockito.mock(PathMatcher.class);
    Path path = Mockito.mock(Path.class);
    when(matcher.matches(path)).thenReturn(true);
    boolean condition = isExcluded(singleton(matcher), path);
    assertTrue(condition);
}
Also used : FileWatcherUtils.toNormalPath(org.eclipse.che.api.vfs.watcher.FileWatcherUtils.toNormalPath) Path(java.nio.file.Path) FileWatcherUtils.toInternalPath(org.eclipse.che.api.vfs.watcher.FileWatcherUtils.toInternalPath) PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 2 with PathMatcher

use of java.nio.file.PathMatcher in project che by eclipse.

the class FileWatcherUtilsTest method shouldNotBeExcluded.

@Test
public void shouldNotBeExcluded() throws Exception {
    PathMatcher matcher = Mockito.mock(PathMatcher.class);
    Path path = Mockito.mock(Path.class);
    when(matcher.matches(path)).thenReturn(false);
    boolean condition = isExcluded(singleton(matcher), path);
    assertFalse(condition);
}
Also used : FileWatcherUtils.toNormalPath(org.eclipse.che.api.vfs.watcher.FileWatcherUtils.toNormalPath) Path(java.nio.file.Path) FileWatcherUtils.toInternalPath(org.eclipse.che.api.vfs.watcher.FileWatcherUtils.toInternalPath) PathMatcher(java.nio.file.PathMatcher) Test(org.junit.Test)

Example 3 with PathMatcher

use of java.nio.file.PathMatcher in project che by eclipse.

the class BaseTest method initProjectApi.

@BeforeMethod
protected void initProjectApi() throws Exception {
    mavenServerManager = new MavenServerManager(mavenServerPath);
    workspaceHolder = new TestWorkspaceHolder();
    if (root == null)
        root = new File(wsPath);
    if (root.exists()) {
        IoUtil.deleteRecursive(root);
    }
    root.mkdir();
    File indexDir = new File(INDEX_PATH);
    if (indexDir.exists()) {
        IoUtil.deleteRecursive(indexDir);
    }
    indexDir.mkdir();
    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> true);
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
    vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new TestProjectType());
    projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
    projectTypeRegistry.registerProjectType(new MavenProjectType(new MavenValueProviderFactory()));
    projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
    projectRegistry.initProjects();
    importerRegistry = new ProjectImporterRegistry(new HashSet<>());
    fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
    fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
    pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, new TestWorkspaceHolder(new ArrayList<>()), mock(FileWatcherManager.class));
    plugin = new ResourcesPlugin("target/index", wsPath, () -> projectRegistry, () -> pm);
    plugin.start();
    javaPlugin.start();
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) MavenProjectType(org.eclipse.che.plugin.maven.server.projecttype.MavenProjectType) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) JavaValueProviderFactory(org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) PathMatcher(java.nio.file.PathMatcher) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) File(java.io.File) JavaProjectType(org.eclipse.che.plugin.java.server.projecttype.JavaProjectType) HashSet(java.util.HashSet) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) MavenValueProviderFactory(org.eclipse.che.plugin.maven.server.projecttype.MavenValueProviderFactory) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 4 with PathMatcher

use of java.nio.file.PathMatcher in project buck by facebook.

the class FakeProjectFilesystem method getMtimeSortedMatchingDirectoryContents.

@Override
public ImmutableSortedSet<Path> getMtimeSortedMatchingDirectoryContents(final Path pathRelativeToProjectRoot, String globPattern) throws IOException {
    Preconditions.checkState(isDirectory(pathRelativeToProjectRoot));
    final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + globPattern);
    return fileContents.keySet().stream().filter(i -> i.getParent().equals(pathRelativeToProjectRoot) && pathMatcher.matches(i.getFileName())).sorted((f0, f1) -> {
        try {
            return getLastModifiedTimeFetcher().getLastModifiedTime(f1).compareTo(getLastModifiedTimeFetcher().getLastModifiedTime(f0));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }).collect(MoreCollectors.toImmutableSortedSet());
}
Also used : Manifest(java.util.jar.Manifest) NoSuchFileException(java.nio.file.NoSuchFileException) ImmutableCollection(com.google.common.collect.ImmutableCollection) FileTime(java.nio.file.attribute.FileTime) Random(java.util.Random) JarFile(java.util.jar.JarFile) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ByteArrayInputStream(java.io.ByteArrayInputStream) FluentIterable(com.google.common.collect.FluentIterable) Map(java.util.Map) Clock(com.facebook.buck.timing.Clock) PathMatcher(java.nio.file.PathMatcher) BigInteger(java.math.BigInteger) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) FileVisitor(java.nio.file.FileVisitor) Platform(com.facebook.buck.util.environment.Platform) NotLinkException(java.nio.file.NotLinkException) Set(java.util.Set) FileAttribute(java.nio.file.attribute.FileAttribute) FileSystem(java.nio.file.FileSystem) DefaultProjectFilesystemDelegate(com.facebook.buck.io.DefaultProjectFilesystemDelegate) FileVisitResult(java.nio.file.FileVisitResult) FakeClock(com.facebook.buck.timing.FakeClock) List(java.util.List) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) ByteStreams(com.google.common.io.ByteStreams) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) CopyOption(java.nio.file.CopyOption) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Hashing(com.google.common.hash.Hashing) LinkedHashMap(java.util.LinkedHashMap) LinkOption(java.nio.file.LinkOption) JarEntry(java.util.jar.JarEntry) ImmutableList(com.google.common.collect.ImmutableList) Jimfs(com.google.common.jimfs.Jimfs) JarInputStream(java.util.jar.JarInputStream) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) OutputStream(java.io.OutputStream) Charsets(com.google.common.base.Charsets) Configuration(com.google.common.jimfs.Configuration) Iterator(java.util.Iterator) Files(java.nio.file.Files) HashCode(com.google.common.hash.HashCode) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) MorePaths(com.facebook.buck.io.MorePaths) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) Preconditions(com.google.common.base.Preconditions) MoreFiles(com.facebook.buck.io.MoreFiles) Comparator(java.util.Comparator) FileSystems(java.nio.file.FileSystems) InputStream(java.io.InputStream) PathMatcher(java.nio.file.PathMatcher) IOException(java.io.IOException)

Example 5 with PathMatcher

use of java.nio.file.PathMatcher in project che by eclipse.

the class BaseTest method initProjectApi.

@BeforeClass
protected void initProjectApi() throws Exception {
    JavaPlugin javaPlugin = new JavaPlugin(wsPath + "/set", null, null);
    EventService eventService = new EventService();
    TestWorkspaceHolder workspaceHolder = new TestWorkspaceHolder();
    if (root == null)
        root = new File(wsPath);
    if (root.exists()) {
        IoUtil.deleteRecursive(root);
    }
    root.mkdir();
    File indexDir = new File(INDEX_PATH);
    if (indexDir.exists()) {
        IoUtil.deleteRecursive(indexDir);
    }
    indexDir.mkdir();
    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> true);
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
    vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new JavaProjectType(new JavaValueProviderFactory()));
    projectTypeRegistry.registerProjectType(new PlainJavaProjectType(new PlainJavaValueProviderFactory()));
    ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
    projectRegistry.initProjects();
    ProjectImporterRegistry importerRegistry = new ProjectImporterRegistry(new HashSet<>());
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
    projectManager = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, new TestWorkspaceHolder(new ArrayList<>()), mock(FileWatcherManager.class));
    ResourcesPlugin plugin = new ResourcesPlugin("target/index", wsPath, () -> projectRegistry, () -> projectManager);
    plugin.start();
    javaPlugin.start();
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) PlainJavaProjectType(org.eclipse.che.plugin.java.plain.server.projecttype.PlainJavaProjectType) JavaValueProviderFactory(org.eclipse.che.plugin.java.server.projecttype.JavaValueProviderFactory) PlainJavaValueProviderFactory(org.eclipse.che.plugin.java.plain.server.projecttype.PlainJavaValueProviderFactory) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) JavaPlugin(org.eclipse.jdt.internal.ui.JavaPlugin) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) EventService(org.eclipse.che.api.core.notification.EventService) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) PathMatcher(java.nio.file.PathMatcher) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) PlainJavaValueProviderFactory(org.eclipse.che.plugin.java.plain.server.projecttype.PlainJavaValueProviderFactory) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) File(java.io.File) JavaProjectType(org.eclipse.che.plugin.java.server.projecttype.JavaProjectType) PlainJavaProjectType(org.eclipse.che.plugin.java.plain.server.projecttype.PlainJavaProjectType) HashSet(java.util.HashSet) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

PathMatcher (java.nio.file.PathMatcher)87 Path (java.nio.file.Path)40 Test (org.junit.Test)23 IOException (java.io.IOException)22 File (java.io.File)16 ArrayList (java.util.ArrayList)12 FileSystem (java.nio.file.FileSystem)11 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)10 FileVisitResult (java.nio.file.FileVisitResult)9 Files (java.nio.file.Files)5 Paths (java.nio.file.Paths)5 HashSet (java.util.HashSet)5 List (java.util.List)5 ProjectHandlerRegistry (org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry)5 ProjectImporterRegistry (org.eclipse.che.api.project.server.importer.ProjectImporterRegistry)5 ProjectTypeRegistry (org.eclipse.che.api.project.server.type.ProjectTypeRegistry)5 DefaultFileWatcherNotificationHandler (org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler)5 FileTreeWatcher (org.eclipse.che.api.vfs.impl.file.FileTreeWatcher)5 LocalVirtualFileSystemProvider (org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider)5 FSLuceneSearcherProvider (org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider)5