Search in sources :

Example 21 with VirtualFileSystem

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

the class MemoryLuceneSearcherTest method initializesIndexForExistedFiles.

@Test
public void initializesIndexForExistedFiles() throws Exception {
    VirtualFileSystem virtualFileSystem = virtualFileSystem();
    VirtualFile folder = virtualFileSystem.getRoot().createFolder("folder");
    folder.createFile("xxx.txt", TEST_CONTENT[2]);
    folder.createFile("zzz.txt", TEST_CONTENT[1]);
    searcher.init(virtualFileSystem);
    List<String> paths = searcher.search(new QueryExpression().setText("think")).getFilePaths();
    assertEquals(newArrayList("/folder/zzz.txt"), paths);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) MemoryVirtualFileSystem(org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) QueryExpression(org.eclipse.che.api.vfs.search.QueryExpression) Test(org.junit.Test)

Example 22 with VirtualFileSystem

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

the class IndexedFileCreateConsumer method accept.

@Override
public void accept(Path path) {
    try {
        VirtualFileSystem virtualFileSystem = vfsProvider.getVirtualFileSystem();
        SearcherProvider searcherProvider = virtualFileSystem.getSearcherProvider();
        Searcher searcher = searcherProvider.getSearcher(virtualFileSystem);
        Path innerPath = root.toPath().relativize(path);
        org.eclipse.che.api.vfs.Path vfsPath = org.eclipse.che.api.vfs.Path.of(innerPath.toString());
        VirtualFile child = virtualFileSystem.getRoot().getChild(vfsPath);
        if (child != null) {
            searcher.add(child);
        }
    } catch (ServerException e) {
        LOG.error("Issue happened during adding created file to index", e);
    }
}
Also used : Path(java.nio.file.Path) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) Searcher(org.eclipse.che.api.vfs.search.Searcher) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider)

Example 23 with VirtualFileSystem

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

the class IndexedFileDeleteConsumer method accept.

@Override
public void accept(Path path) {
    try {
        VirtualFileSystem virtualFileSystem = vfsProvider.getVirtualFileSystem();
        SearcherProvider searcherProvider = virtualFileSystem.getSearcherProvider();
        Searcher searcher = searcherProvider.getSearcher(virtualFileSystem);
        Path innerPath = root.toPath().relativize(path);
        searcher.delete("/" + innerPath.toString(), true);
    } catch (ServerException e) {
        LOG.error("Issue happened during removing deleted file from index", e);
    }
}
Also used : Path(java.nio.file.Path) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) Searcher(org.eclipse.che.api.vfs.search.Searcher) SearcherProvider(org.eclipse.che.api.vfs.search.SearcherProvider)

Example 24 with VirtualFileSystem

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

the class CreateBaseProjectTypeHandlerTest method testCreateProject.

@Test
public void testCreateProject() throws Exception {
    Path path = Path.of("test");
    VirtualFileSystemProvider virtualFileSystemProvider = mock(VirtualFileSystemProvider.class);
    VirtualFileSystem virtualFileSystem = mock(VirtualFileSystem.class);
    VirtualFile base = mock(VirtualFile.class);
    when(base.isRoot()).thenReturn(false);
    VirtualFile root = mock(VirtualFile.class);
    when(root.isRoot()).thenReturn(true);
    when(root.createFolder(anyString())).thenReturn(base);
    when(virtualFileSystem.getRoot()).thenReturn(root);
    when(virtualFileSystemProvider.getVirtualFileSystem()).thenReturn(virtualFileSystem);
    when(virtualFileSystem.getRoot()).thenReturn(root);
    CreateBaseProjectTypeHandler createBaseProjectTypeHandler = new CreateBaseProjectTypeHandler(virtualFileSystemProvider);
    createBaseProjectTypeHandler.onCreateProject(path, null, null);
    verify(root).createFolder("test");
}
Also used : Path(org.eclipse.che.api.vfs.Path) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) VirtualFileSystemProvider(org.eclipse.che.api.vfs.VirtualFileSystemProvider) Test(org.testng.annotations.Test)

Example 25 with VirtualFileSystem

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

the class PlainJavaProjectGenerator method onCreateProject.

@Override
public void onCreateProject(Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    List<String> sourceFolders;
    if (attributes.containsKey(SOURCE_FOLDER) && !attributes.get(SOURCE_FOLDER).isEmpty()) {
        sourceFolders = attributes.get(SOURCE_FOLDER).getList();
    } else {
        sourceFolders = singletonList(DEFAULT_SOURCE_FOLDER_VALUE);
    }
    VirtualFileSystem vfs = virtualFileSystemProvider.getVirtualFileSystem();
    FolderEntry baseFolder = new FolderEntry(vfs.getRoot().createFolder(projectPath.toString()));
    baseFolder.createFolder(DEFAULT_OUTPUT_FOLDER_VALUE);
    FolderEntry sourceFolder = baseFolder.createFolder(sourceFolders.get(0));
    sourceFolder.createFile(FILE_NAME, getClass().getClassLoader().getResourceAsStream("files/main_class_content"));
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(baseFolder.getPath().toString());
    IJavaProject javaProject = JavaCore.create(project);
    classpathBuilder.generateClasspath(javaProject, sourceFolders, singletonList(DEFAULT_LIBRARY_FOLDER_VALUE));
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) IProject(org.eclipse.core.resources.IProject)

Aggregations

VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)63 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)32 Test (org.junit.Test)29 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)28 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)27 Test (org.testng.annotations.Test)18 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)9 Searcher (org.eclipse.che.api.vfs.search.Searcher)7 SearchResult (org.eclipse.che.api.vfs.search.SearchResult)6 ServerException (org.eclipse.che.api.core.ServerException)5 Path (java.nio.file.Path)3 SearcherProvider (org.eclipse.che.api.vfs.search.SearcherProvider)3 IOException (java.io.IOException)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 File (java.io.File)1 InputStream (java.io.InputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ProjectImporter (org.eclipse.che.api.project.server.importer.ProjectImporter)1