Search in sources :

Example 1 with VirtualFileVisitor

use of org.eclipse.che.api.vfs.VirtualFileVisitor in project che by eclipse.

the class LocalVirtualFileTest method getFileTreeAsList.

private List<VirtualFile> getFileTreeAsList(VirtualFile rootOfTree) throws Exception {
    List<VirtualFile> list = newArrayList();
    rootOfTree.accept(new VirtualFileVisitor() {

        @Override
        public void visit(VirtualFile virtualFile) throws ServerException {
            list.add(virtualFile);
            if (virtualFile.isFolder()) {
                for (VirtualFile child : virtualFile.getChildren()) {
                    child.accept(this);
                }
            }
        }
    });
    return list;
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor)

Example 2 with VirtualFileVisitor

use of org.eclipse.che.api.vfs.VirtualFileVisitor in project che by eclipse.

the class MemoryVirtualFileTest method getFileTreeAsList.

private List<VirtualFile> getFileTreeAsList(VirtualFile rootOfTree) throws Exception {
    List<VirtualFile> list = newArrayList();
    rootOfTree.accept(new VirtualFileVisitor() {

        @Override
        public void visit(VirtualFile virtualFile) throws ServerException {
            list.add(virtualFile);
            if (virtualFile.isFolder()) {
                for (VirtualFile child : virtualFile.getChildren()) {
                    child.accept(this);
                }
            }
        }
    });
    return list;
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor)

Example 3 with VirtualFileVisitor

use of org.eclipse.che.api.vfs.VirtualFileVisitor in project che by eclipse.

the class MemoryVirtualFileTest method acceptsVisitor.

@Test
public void acceptsVisitor() throws Exception {
    VirtualFile root = getRoot();
    boolean[] visitedFlag = new boolean[] { false };
    VirtualFileVisitor visitor = virtualFile -> {
        assertSame(root, virtualFile);
        visitedFlag[0] = true;
    };
    root.accept(visitor);
    assertTrue("visit(VirtualFile) method was not invoked", visitedFlag[0]);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ArchiverFactory(org.eclipse.che.api.vfs.ArchiverFactory) Path(org.eclipse.che.api.vfs.Path) Hashing(com.google.common.hash.Hashing) Assert.assertSame(org.junit.Assert.assertSame) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ByteArrayInputStream(java.io.ByteArrayInputStream) Matchers.eq(org.mockito.Matchers.eq) Searcher(org.eclipse.che.api.vfs.search.Searcher) Map(java.util.Map) ConflictException(org.eclipse.che.api.core.ConflictException) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider) ByteSource(com.google.common.io.ByteSource) ExpectedException(org.junit.rules.ExpectedException) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) Before(org.junit.Before) OutputStream(java.io.OutputStream) Archiver(org.eclipse.che.api.vfs.Archiver) Iterator(java.util.Iterator) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor) Pair(org.eclipse.che.commons.lang.Pair) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertNull(org.junit.Assert.assertNull) ServerException(org.eclipse.che.api.core.ServerException) Assert.assertFalse(org.junit.Assert.assertFalse) ByteStreams(com.google.common.io.ByteStreams) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor) Test(org.junit.Test)

Example 4 with VirtualFileVisitor

use of org.eclipse.che.api.vfs.VirtualFileVisitor in project che by eclipse.

the class MemoryVirtualFile method getTreeAsList.

List<VirtualFile> getTreeAsList(VirtualFile folder) throws ServerException {
    List<VirtualFile> list = newArrayList();
    folder.accept(new VirtualFileVisitor() {

        @Override
        public void visit(VirtualFile virtualFile) throws ServerException {
            if (virtualFile.isFolder()) {
                for (VirtualFile child : virtualFile.getChildren()) {
                    child.accept(this);
                }
            }
            list.add(virtualFile);
        }
    });
    return list;
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor)

Example 5 with VirtualFileVisitor

use of org.eclipse.che.api.vfs.VirtualFileVisitor in project che by eclipse.

the class LocalVirtualFileTest method acceptsVisitor.

@Test
public void acceptsVisitor() throws Exception {
    VirtualFile root = getRoot();
    boolean[] visitedFlag = new boolean[] { false };
    VirtualFileVisitor visitor = virtualFile -> {
        assertSame(root, virtualFile);
        visitedFlag[0] = true;
    };
    root.accept(visitor);
    assertTrue("visit(VirtualFile) method was not invoked", visitedFlag[0]);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ArchiverFactory(org.eclipse.che.api.vfs.ArchiverFactory) Path(org.eclipse.che.api.vfs.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) Map(java.util.Map) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) FileCleaner(org.eclipse.che.api.core.util.FileCleaner) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) Archiver(org.eclipse.che.api.vfs.Archiver) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Pair(org.eclipse.che.commons.lang.Pair) IoUtil(org.eclipse.che.commons.lang.IoUtil) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Assert.assertFalse(org.junit.Assert.assertFalse) AbstractVirtualFileSystemProvider(org.eclipse.che.api.vfs.AbstractVirtualFileSystemProvider) ByteStreams(com.google.common.io.ByteStreams) Mockito.mock(org.mockito.Mockito.mock) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Hashing(com.google.common.hash.Hashing) VirtualFileFilter(org.eclipse.che.api.vfs.VirtualFileFilter) Assert.assertSame(org.junit.Assert.assertSame) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) Searcher(org.eclipse.che.api.vfs.search.Searcher) ConflictException(org.eclipse.che.api.core.ConflictException) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider) ByteSource(com.google.common.io.ByteSource) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) OutputStream(java.io.OutputStream) Iterator(java.util.Iterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collectors.toList(java.util.stream.Collectors.toList) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Assert.assertNull(org.junit.Assert.assertNull) ServerException(org.eclipse.che.api.core.ServerException) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) VirtualFileVisitor(org.eclipse.che.api.vfs.VirtualFileVisitor) Test(org.junit.Test)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)5 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)5 VirtualFileVisitor (org.eclipse.che.api.vfs.VirtualFileVisitor)5 ImmutableMap (com.google.common.collect.ImmutableMap)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Hashing (com.google.common.hash.Hashing)2 ByteSource (com.google.common.io.ByteSource)2 ByteStreams (com.google.common.io.ByteStreams)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 ConflictException (org.eclipse.che.api.core.ConflictException)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2