Search in sources :

Example 16 with FolderEntry

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

the class SubversionProjectImporterTest method testInvalidImportSources.

/**
     * Test for {@link SubversionProjectImporter#importSources(org.eclipse.che.api.project.server.FolderEntry, org.eclipse.che.api.core.model.project.SourceStorage, org.eclipse.che.api.core.util.LineConsumerFactory)}
     * invalid url.
     *
     * @throws Exception if anything goes wrong
     */
@Test
public void testInvalidImportSources() throws Exception {
    final String projectName = NameGenerator.generate("project-", 3);
    //root.getChild(org.eclipse.che.api.vfs.Path.of(projectName));
    final VirtualFile virtualFile = root.createFolder(projectName);
    FolderEntry projectFolder = new FolderEntry(virtualFile);
    try {
        String fakeUrl = Paths.get(repoRoot.getAbsolutePath()).toUri() + "fake";
        when(sourceStorage.getLocation()).thenReturn(fakeUrl);
        projectImporter.importSources(projectFolder, sourceStorage, new TestUtils.SystemOutLineConsumerFactory());
        fail("The code above should had failed");
    } catch (SubversionException e) {
        final String message = e.getMessage();
        boolean assertBoolean = Pattern.matches("svn: (E[0-9]{6}: )?URL 'file://.*/fake' doesn't exist\n?", message.trim());
        assertTrue(message, assertBoolean);
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) TestUtils(org.eclipse.che.plugin.svn.server.utils.TestUtils) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) Test(org.junit.Test)

Example 17 with FolderEntry

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

the class SubversionValueProviderFactory method isSvn.

private boolean isSvn(final FolderEntry project) throws ForbiddenException, ServerException {
    LOG.debug("Searching for '.svn' in {}.", project.getPath());
    final VirtualFileEntry svn = project.getChild(".svn");
    if (svn != null && svn instanceof FolderEntry) {
        LOG.debug("Found it.");
        return true;
    } else {
        LOG.debug("Didn't find it.");
        return false;
    }
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry)

Example 18 with FolderEntry

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

the class Workspace method createResource.

public void createResource(IResource resource, int updateFlags) throws CoreException {
    try {
        IPath path = resource.getFullPath();
        switch(resource.getType()) {
            case IResource.FILE:
                String newName = path.lastSegment();
                VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
                if (child == null) {
                    throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
                }
                FolderEntry entry = (FolderEntry) child;
                entry.createFile(newName, new byte[0]);
                break;
            case IResource.FOLDER:
                getProjectsRoot().createFolder(path.toOSString());
                break;
            case IResource.PROJECT:
                ProjectConfigImpl projectConfig = new ProjectConfigImpl();
                projectConfig.setPath(resource.getName());
                projectConfig.setName(resource.getName());
                projectConfig.setType(BaseProjectType.ID);
                projectManager.get().createProject(projectConfig, new HashMap<>());
                break;
            default:
                throw new UnsupportedOperationException();
        }
    } catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
        throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), 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) IPath(org.eclipse.core.runtime.IPath) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException) CoreException(org.eclipse.core.runtime.CoreException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 19 with FolderEntry

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

the class JsonExampleCreateProjectHandler method onCreateProject.

@Override
public void onCreateProject(Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    VirtualFileSystem vfs = virtualFileSystemProvider.getVirtualFileSystem();
    FolderEntry baseFolder = new FolderEntry(vfs.getRoot().createFolder(projectPath.toString()));
    try (InputStream packageJson = getClass().getClassLoader().getResourceAsStream("files/default_package");
        InputStream personJson = getClass().getClassLoader().getResourceAsStream("files/default_person")) {
        FolderEntry myJsonFiles = baseFolder.createFolder("myJsonFiles");
        baseFolder.createFile(FILE_NAME, packageJson);
        myJsonFiles.createFile("person.json", personJson);
    } catch (IOException ioEx) {
        throw new ServerException(ioEx.getLocalizedMessage(), ioEx);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) VirtualFileSystem(org.eclipse.che.api.vfs.VirtualFileSystem) InputStream(java.io.InputStream) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) IOException(java.io.IOException)

Example 20 with FolderEntry

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

the class GitService method deleteRepository.

@DELETE
@Path("repository")
public void deleteRepository(@Context UriInfo uriInfo) throws ApiException {
    final RegisteredProject project = projectRegistry.getProject(projectPath);
    final FolderEntry gitFolder = project.getBaseFolder().getChildFolder(".git");
    gitFolder.getVirtualFile().delete();
    projectRegistry.removeProjectType(projectPath, GitProjectType.TYPE_ID);
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

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