Search in sources :

Example 6 with FileEntry

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

the class JavaValueProviderFactoryTest method checkWithErrorInSubfolder.

/**
     * In this case we have an exception while trying to search in sub folders
     */
@Test(expectedExceptions = ValueStorageException.class)
public void checkWithErrorInSubfolder() throws Throwable {
    // we return a file entry that is a javascript file
    FileEntry fileEntry = mock(FileEntry.class);
    when(fileEntry.getName()).thenReturn("helloworld.js");
    when(rootProjectFolder.getChildFiles()).thenReturn(Collections.singletonList(fileEntry));
    FileEntry javaFileEntry = mock(FileEntry.class);
    when(javaFileEntry.getName()).thenThrow(new IllegalStateException("unable to get name of this file"));
    FolderEntry subFolder = mock(FolderEntry.class);
    when(subFolder.getChildFiles()).thenReturn(Collections.singletonList(javaFileEntry));
    when(rootProjectFolder.getChildFolders()).thenReturn(Collections.singletonList(subFolder));
    ValueProvider javaPropertiesValueProvider = new JavaValueProviderFactory().newInstance(rootProjectFolder);
    javaPropertiesValueProvider.getValues(CONTAINS_JAVA_FILES);
    org.testng.Assert.fail("We should have exception reported");
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) FileEntry(org.eclipse.che.api.project.server.FileEntry) ValueProvider(org.eclipse.che.api.project.server.type.ValueProvider) Test(org.testng.annotations.Test)

Example 7 with FileEntry

use of org.eclipse.che.api.project.server.FileEntry 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 8 with FileEntry

use of org.eclipse.che.api.project.server.FileEntry 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 9 with FileEntry

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

the class JsonLocService method countLinesPerFile.

/**
     * Count LOC for all JSON files within the given project.
     *
     * @param projectPath
     *         the path to the project that contains the JSON files for which to calculate the LOC
     * @return a Map mapping the file name to their respective LOC value
     * @throws ServerException
     *         in case the server encounters an error
     * @throws NotFoundException
     *         in case the project couldn't be found
     * @throws ForbiddenException
     *         in case the operation is forbidden
     */
@GET
@Path("{projectPath}")
public Map<String, String> countLinesPerFile(@PathParam("projectPath") String projectPath) throws ServerException, NotFoundException, ForbiddenException {
    Map<String, String> linesPerFile = new LinkedHashMap<>();
    RegisteredProject project = projectManager.getProject(projectPath);
    for (FileEntry child : project.getBaseFolder().getChildFiles()) {
        if (isJsonFile(child)) {
            linesPerFile.put(child.getName(), Integer.toString(countLines(child)));
        }
    }
    return linesPerFile;
}
Also used : RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) FileEntry(org.eclipse.che.api.project.server.FileEntry) LinkedHashMap(java.util.LinkedHashMap) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

FileEntry (org.eclipse.che.api.project.server.FileEntry)9 ValueProvider (org.eclipse.che.api.project.server.type.ValueProvider)5 Test (org.testng.annotations.Test)5 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)4 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 ServerException (org.eclipse.che.api.core.ServerException)2 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ConflictException (org.eclipse.che.api.core.ConflictException)1 RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)1 AttributeValue (org.eclipse.che.api.project.server.type.AttributeValue)1 ValueStorageException (org.eclipse.che.api.project.server.type.ValueStorageException)1 IResourceStatus (org.eclipse.core.resources.IResourceStatus)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1