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