Search in sources :

Example 36 with VirtualFile

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

the class ProjectManager method initWatcher.

void initWatcher() throws IOException {
    FileWatcherNotificationListener defaultListener = new FileWatcherNotificationListener(file -> !(file.getPath().toString().contains(".che") || file.getPath().toString().contains(".#"))) {

        @Override
        public void onFileWatcherEvent(VirtualFile virtualFile, FileWatcherEventType eventType) {
            LOG.debug("FS event detected: " + eventType + " " + virtualFile.getPath().toString() + " " + virtualFile.isFile());
        }
    };
    fileWatchNotifier.addNotificationListener(defaultListener);
    try {
        fileWatcher.startup();
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        fileWatchNotifier.removeNotificationListener(defaultListener);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) FileWatcherNotificationListener(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationListener) FileWatcherEventType(org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType) IOException(java.io.IOException)

Example 37 with VirtualFile

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

the class ProjectManager method delete.

/**
     * deletes item including project
     *
     * @param path
     *
     * @throws ServerException
     * @throws ForbiddenException
     * @throws NotFoundException
     * @throws ConflictException
     */
public void delete(String path) throws ServerException, ForbiddenException, NotFoundException, ConflictException {
    final String apath = ProjectRegistry.absolutizePath(path);
    // delete item
    final VirtualFile item = vfs.getRoot().getChild(Path.of(apath));
    if (item != null) {
        item.delete();
    }
    // delete child projects
    projectRegistry.removeProjects(apath);
    workspaceProjectsHolder.sync(projectRegistry);
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile)

Example 38 with VirtualFile

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

the class ProjectRegistry method initProjects.

@PostConstruct
public void initProjects() throws ConflictException, NotFoundException, ServerException, ForbiddenException {
    List<? extends ProjectConfig> projectConfigs = workspaceHolder.getProjects();
    // take all the projects from ws's config
    for (ProjectConfig projectConfig : projectConfigs) {
        final String path = projectConfig.getPath();
        final VirtualFile vf = vfs.getRoot().getChild(Path.of(path));
        final FolderEntry projectFolder = ((vf == null) ? null : new FolderEntry(vf, this));
        putProject(projectConfig, projectFolder, false, false);
    }
    initUnconfiguredFolders();
    initialized = true;
    for (RegisteredProject project : projects.values()) {
        // only for projects with sources
        if (project.getBaseFolder() != null) {
            fireInitHandlers(project);
        }
    }
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) PostConstruct(javax.annotation.PostConstruct)

Example 39 with VirtualFile

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

the class ProjectService method exportFile.

@GET
@Path("/export/file/{path:.*}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response exportFile(@ApiParam(value = "Path to resource to be imported") @PathParam("path") String path) throws NotFoundException, ForbiddenException, ServerException {
    final FileEntry file = projectManager.asFile(path);
    if (file == null) {
        throw new NotFoundException("File not found " + path);
    }
    final VirtualFile virtualFile = file.getVirtualFile();
    return Response.ok(virtualFile.getContent(), TIKA.detect(virtualFile.getName())).lastModified(new Date(virtualFile.getLastModificationDate())).header(HttpHeaders.CONTENT_LENGTH, Long.toString(virtualFile.getLength())).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + virtualFile.getName() + '"').build();
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) NotFoundException(org.eclipse.che.api.core.NotFoundException) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 40 with VirtualFile

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

the class SubversionProjectImporterTest method testValidImportSources.

/**
     * Test for {@link SubversionProjectImporter#importSources(org.eclipse.che.api.project.server.FolderEntry, org.eclipse.che.api.core.model.project.SourceStorage, org.eclipse.che.api.core.util.LineConsumerFactory)}
     * with a valid url.
     *
     * @throws Exception if anything goes wrong
     */
@Test
public void testValidImportSources() throws Exception {
    final String projectName = NameGenerator.generate("project-", 3);
    final VirtualFile virtualFile = root.createFolder(projectName);
    FolderEntry projectFolder = new FolderEntry(virtualFile);
    String repoUrl = Paths.get(repoRoot.getAbsolutePath()).toUri().toString();
    when(sourceStorage.getLocation()).thenReturn(repoUrl);
    projectImporter.importSources(projectFolder, sourceStorage, new TestUtils.SystemOutLineConsumerFactory());
    assertTrue(projectFolder.getChild(".svn").isFolder());
    assertTrue(projectFolder.getChild("trunk").isFolder());
    assertTrue(projectFolder.getChildFolder("trunk").getChild("A").isFolder());
    assertTrue(projectFolder.getChildFolder("trunk").getChildFolder("A").getChild("mu").isFile());
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) TestUtils(org.eclipse.che.plugin.svn.server.utils.TestUtils) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) Test(org.junit.Test)

Aggregations

VirtualFile (org.eclipse.che.api.vfs.VirtualFile)321 Test (org.junit.Test)267 Path (org.eclipse.che.api.vfs.Path)62 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)54 ByteArrayInputStream (java.io.ByteArrayInputStream)32 ConflictException (org.eclipse.che.api.core.ConflictException)28 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)27 MemoryVirtualFileSystem (org.eclipse.che.api.vfs.impl.memory.MemoryVirtualFileSystem)22 QueryExpression (org.eclipse.che.api.vfs.search.QueryExpression)22 ServerException (org.eclipse.che.api.core.ServerException)18 Test (org.testng.annotations.Test)18 File (java.io.File)17 Archiver (org.eclipse.che.api.vfs.Archiver)14 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 OutputStream (java.io.OutputStream)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Map (java.util.Map)5