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);
}
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);
}
}
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);
}
}
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");
}
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));
}
Aggregations