use of org.eclipse.che.api.project.server.FolderEntry 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.FolderEntry 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;
}
use of org.eclipse.che.api.project.server.FolderEntry 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));
}
use of org.eclipse.che.api.project.server.FolderEntry 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.FolderEntry 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();
}
Aggregations