Search in sources :

Example 21 with FolderEntry

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));
    }
}
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 22 with FolderEntry

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;
}
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 23 with FolderEntry

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));
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) IProject(org.eclipse.core.resources.IProject)

Example 24 with FolderEntry

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");
}
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 25 with FolderEntry

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();
}
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

FolderEntry (org.eclipse.che.api.project.server.FolderEntry)33 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)11 Test (org.testng.annotations.Test)11 VirtualFileSystem (org.eclipse.che.api.vfs.VirtualFileSystem)9 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)8 IProject (org.eclipse.core.resources.IProject)7 Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)6 MavenServerService (org.eclipse.che.plugin.maven.server.rest.MavenServerService)6 ServerException (org.eclipse.che.api.core.ServerException)5 FileEntry (org.eclipse.che.api.project.server.FileEntry)4 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)4 ConflictException (org.eclipse.che.api.core.ConflictException)3 ValueProvider (org.eclipse.che.api.project.server.type.ValueProvider)3 Model (org.eclipse.che.ide.maven.tools.Model)3 ArrayList (java.util.ArrayList)2 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 ProjectCreatedEvent (org.eclipse.che.api.project.server.ProjectCreatedEvent)2 ResourceChangedEvent (org.eclipse.che.jdt.core.resources.ResourceChangedEvent)2 TestUtils (org.eclipse.che.plugin.svn.server.utils.TestUtils)2 IResourceStatus (org.eclipse.core.resources.IResourceStatus)2