Search in sources :

Example 11 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry in project che by eclipse.

the class Workspace method standardMoveFile.

public void standardMoveFile(IFile file, IFile destination, int updateFlags, IProgressMonitor monitor) throws CoreException {
    VirtualFileEntry child = null;
    try {
        child = getProjectsRoot().getChild(file.getFullPath().toOSString());
        projectManager.get().moveTo(child.getPath().toString(), destination.getFullPath().removeLastSegments(1).toOSString(), destination.getName(), true);
    } catch (ForbiddenException | ServerException | NotFoundException | ConflictException e) {
        throw new CoreException(new Status(IStatus.ERROR, "", "Can't move file: " + file.getFullPath() + " to: " + destination.getFullPath(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) CoreException(org.eclipse.core.runtime.CoreException) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException)

Example 12 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry in project che by eclipse.

the class Workspace method setFileContent.

public void setFileContent(File file, InputStream content) {
    try {
        VirtualFileEntry child = getProjectsRoot().getChild(file.getFullPath().toOSString());
        if (child.isFile()) {
            FileEntry f = (FileEntry) child;
            f.updateContent(content);
        }
    } catch (ForbiddenException | ServerException e) {
        ResourcesPlugin.log(e);
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry)

Example 13 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry in project che by eclipse.

the class Workspace method write.

void write(File file, InputStream content, int updateFlags, boolean append, IProgressMonitor monitor) throws CoreException {
    try {
        FolderEntry projectsRoot = getProjectsRoot();
        VirtualFileEntry child = projectsRoot.getChild(file.getFullPath().toOSString());
        if (child == null) {
            projectsRoot.createFile(file.getFullPath().toOSString(), content);
        } else {
            FileEntry fileEntry = (FileEntry) child;
            fileEntry.updateContent(content);
        }
    } catch (ForbiddenException | ConflictException | ServerException e) {
        throw new CoreException(new Status(0, "", e.getMessage(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) CoreException(org.eclipse.core.runtime.CoreException) ConflictException(org.eclipse.che.api.core.ConflictException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry)

Example 14 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry in project che by eclipse.

the class Workspace method getChildren.

public IResource[] getChildren(IPath path) {
    try {
        VirtualFileEntry parent = getProjectsRoot().getChild(path.toOSString());
        if (parent != null && parent.isFolder()) {
            FolderEntry folder = (FolderEntry) parent;
            List<VirtualFileEntry> children = folder.getChildren();
            if (!children.isEmpty()) {
                IResource[] resources = new IResource[children.size()];
                for (int i = 0; i < children.size(); i++) {
                    VirtualFileEntry child = children.get(i);
                    IPath iPath = new Path(child.getPath().toString());
                    resources[i] = newResource(iPath, getType(child));
                }
                resources = Arrays.stream(resources).sorted((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())).toArray(IResource[]::new);
                return resources;
            }
        }
    } catch (ServerException e) {
        LOG.error(e.getMessage(), e);
    }
    return ICoreConstants.EMPTY_RESOURCE_ARRAY;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ServerException(org.eclipse.che.api.core.ServerException) IPath(org.eclipse.core.runtime.IPath) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) IResource(org.eclipse.core.resources.IResource)

Example 15 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry in project che by eclipse.

the class LanguageServerRegistryImpl method extractProjectPath.

protected String extractProjectPath(String filePath) throws LanguageServerException {
    FolderEntry root;
    try {
        root = projectManagerProvider.get().getProjectsRoot();
    } catch (ServerException e) {
        throw new LanguageServerException("Project not found for " + filePath, e);
    }
    if (!filePath.startsWith(PROJECT_FOLDER_PATH)) {
        throw new LanguageServerException("Project not found for " + filePath);
    }
    VirtualFileEntry fileEntry;
    try {
        fileEntry = root.getChild(filePath.substring(PROJECT_FOLDER_PATH.length() + 1));
    } catch (ServerException e) {
        throw new LanguageServerException("Project not found for " + filePath, e);
    }
    if (fileEntry == null) {
        throw new LanguageServerException("Project not found for " + filePath);
    }
    return PROJECT_FOLDER_PATH + fileEntry.getProject();
}
Also used : LanguageServerException(org.eclipse.che.api.languageserver.exception.LanguageServerException) LanguageServerException(org.eclipse.che.api.languageserver.exception.LanguageServerException) ServerException(org.eclipse.che.api.core.ServerException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry)

Aggregations

VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)21 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)11 ServerException (org.eclipse.che.api.core.ServerException)9 Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)7 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)6 MavenServerService (org.eclipse.che.plugin.maven.server.rest.MavenServerService)6 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)6 Test (org.testng.annotations.Test)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)5 IProject (org.eclipse.core.resources.IProject)5 ConflictException (org.eclipse.che.api.core.ConflictException)4 FileEntry (org.eclipse.che.api.project.server.FileEntry)3 RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)3 IResourceStatus (org.eclipse.core.resources.IResourceStatus)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 MultiStatus (org.eclipse.core.runtime.MultiStatus)3 Status (org.eclipse.core.runtime.Status)3 HashMap (java.util.HashMap)2 List (java.util.List)2