Search in sources :

Example 21 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class LocalWorkspaceFolderPathProvider method getPath.

@Override
public String getPath(@Assisted("workspace") String workspaceId) throws IOException {
    if (!isWindows && hostProjectsFolder != null) {
        return hostProjectsFolder;
    }
    try {
        WorkspaceManager workspaceManager = this.workspaceManager.get();
        Workspace workspace = workspaceManager.getWorkspace(workspaceId);
        String wsName = workspace.getConfig().getName();
        return doGetPathByName(wsName);
    } catch (NotFoundException | ServerException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) IOException(java.io.IOException) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 22 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class DockerInstance method destroy.

@Override
public void destroy() throws MachineException {
    try {
        outputConsumer.close();
    } catch (IOException ignored) {
    }
    machineProcesses.clear();
    processesCleaner.untrackProcesses(getId());
    dockerInstanceStopDetector.stopDetection(container);
    try {
        if (getConfig().isDev()) {
            node.unbindWorkspace();
        }
        // kill container is not needed here, because we removing container with force flag
        docker.removeContainer(RemoveContainerParams.create(container).withRemoveVolumes(true).withForce(true));
    } catch (IOException | ServerException e) {
        LOG.error(e.getLocalizedMessage(), e);
        throw new MachineException(e.getLocalizedMessage());
    }
    try {
        docker.removeImage(RemoveImageParams.create(image).withForce(false));
    } catch (IOException ignore) {
        LOG.error("IOException during destroy(). Ignoring.");
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) IOException(java.io.IOException)

Example 23 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ArchetypeGenerationStrategy method generateProject.

@Override
public void generateProject(final Path projectPath, Map<String, AttributeValue> attributes, Map<String, String> options) throws ForbiddenException, ConflictException, ServerException {
    AttributeValue artifactId = attributes.get(ARTIFACT_ID);
    AttributeValue groupId = attributes.get(GROUP_ID);
    AttributeValue version = attributes.get(VERSION);
    if (groupId == null || artifactId == null || version == null) {
        throw new ServerException("Missed some required attribute (groupId, artifactId or version)");
    }
    String archetypeGroupId = null;
    String archetypeArtifactId = null;
    String archetypeVersion = null;
    String archetypeRepository = null;
    Map<String, String> archetypeProperties = new HashMap<>();
    //TODO: remove prop 'type' now it use only for detecting generation strategy
    options.remove("type");
    for (Entry<String, String> entry : options.entrySet()) {
        switch(entry.getKey()) {
            case "archetypeGroupId":
                archetypeGroupId = entry.getValue();
                break;
            case "archetypeArtifactId":
                archetypeArtifactId = entry.getValue();
                break;
            case "archetypeVersion":
                archetypeVersion = entry.getValue();
                break;
            case "archetypeRepository":
                archetypeRepository = entry.getValue();
                break;
            default:
                archetypeProperties.put(entry.getKey(), entry.getValue());
        }
    }
    if (isNullOrEmpty(archetypeGroupId) || isNullOrEmpty(archetypeArtifactId) || isNullOrEmpty(archetypeVersion)) {
        throw new ServerException("Missed some required option (archetypeGroupId, archetypeArtifactId or archetypeVersion)");
    }
    MavenArchetype mavenArchetype = new MavenArchetypeImpl(archetypeGroupId, archetypeArtifactId, archetypeVersion, archetypeRepository, archetypeProperties);
    final MavenArtifact mavenArtifact = new MavenArtifact();
    mavenArtifact.setGroupId(getFirst(groupId.getList(), projectPath.getName()));
    mavenArtifact.setArtifactId(getFirst(artifactId.getList(), projectPath.getName()));
    mavenArtifact.setVersion(getFirst(version.getList(), DEFAULT_VERSION));
    archetypeGenerator.generateFromArchetype(vfs.getRoot().toIoFile(), mavenArchetype, mavenArtifact);
}
Also used : AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) ServerException(org.eclipse.che.api.core.ServerException) MavenArchetypeImpl(org.eclipse.che.plugin.maven.generator.archetype.MavenArchetypeImpl) HashMap(java.util.HashMap) MavenArchetype(org.eclipse.che.plugin.maven.shared.MavenArchetype) MavenArtifact(org.eclipse.che.ide.maven.tools.MavenArtifact)

Example 24 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class MavenServerService method createProblem.

private Problem createProblem(VirtualFileEntry entry, SAXParseException spe) {
    Problem problem = DtoFactory.newDto(Problem.class);
    problem.setError(true);
    problem.setMessage(spe.getMessage());
    if (entry != null) {
        int lineNumber = spe.getLineNumber();
        int columnNumber = spe.getColumnNumber();
        try {
            String content = entry.getVirtualFile().getContentAsString();
            Document document = new Document(content);
            int lineOffset = document.getLineOffset(lineNumber - 1);
            problem.setSourceStart(lineOffset + columnNumber - 1);
            problem.setSourceEnd(lineOffset + columnNumber);
        } catch (ForbiddenException | ServerException | BadLocationException e) {
            LOG.error(e.getMessage(), e);
        }
    }
    return problem;
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Document(org.eclipse.jface.text.Document) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class MavenServerService method reconcilePom.

@GET
@Path("pom/reconcile")
@ApiOperation(value = "Reconcile pom.xml file")
@ApiResponses({ @ApiResponse(code = 200, message = "OK") })
@Produces("application/json")
public List<Problem> reconcilePom(@ApiParam(value = "The paths to pom.xml file which need to be reconciled") @QueryParam("pompath") String pomPath) {
    VirtualFileEntry entry = null;
    List<Problem> result = new ArrayList<>();
    try {
        entry = cheProjectManager.getProjectsRoot().getChild(pomPath);
        if (entry == null) {
            return result;
        }
        Model.readFrom(entry.getVirtualFile());
        org.eclipse.che.api.vfs.Path path = entry.getPath();
        String pomContent = entry.getVirtualFile().getContentAsString();
        MavenProject mavenProject = mavenProjectManager.findMavenProject(ResourcesPlugin.getWorkspace().getRoot().getProject(path.getParent().toString()));
        if (mavenProject == null) {
            return result;
        }
        List<MavenProjectProblem> problems = mavenProject.getProblems();
        int start = pomContent.indexOf("<project ") + 1;
        int end = start + "<project ".length();
        List<Problem> problemList = problems.stream().map(mavenProjectProblem -> DtoFactory.newDto(Problem.class).withError(true).withSourceStart(start).withSourceEnd(end).withMessage(mavenProjectProblem.getDescription())).collect(Collectors.toList());
        result.addAll(problemList);
    } catch (ServerException | ForbiddenException | IOException e) {
        LOG.error(e.getMessage(), e);
    } catch (XMLTreeException exception) {
        Throwable cause = exception.getCause();
        if (cause != null && cause instanceof SAXParseException) {
            result.add(createProblem(entry, (SAXParseException) cause));
        }
    }
    return result;
}
Also used : MavenWrapperManager(org.eclipse.che.plugin.maven.server.MavenWrapperManager) EclipseWorkspaceProvider(org.eclipse.che.plugin.maven.server.core.EclipseWorkspaceProvider) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProjectRegistry(org.eclipse.che.api.project.server.ProjectRegistry) Inject(com.google.inject.Inject) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) MavenWorkspace(org.eclipse.che.plugin.maven.server.core.MavenWorkspace) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) Document(org.eclipse.jface.text.Document) MavenProgressNotifier(org.eclipse.che.plugin.maven.server.core.MavenProgressNotifier) QueryParam(javax.ws.rs.QueryParam) IProject(org.eclipse.core.resources.IProject) IWorkspace(org.eclipse.core.resources.IWorkspace) Model(org.eclipse.che.ide.maven.tools.Model) BadLocationException(org.eclipse.jface.text.BadLocationException) DtoFactory(org.eclipse.che.dto.server.DtoFactory) ClasspathManager(org.eclipse.che.plugin.maven.server.core.classpath.ClasspathManager) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) TEXT_XML(javax.ws.rs.core.MediaType.TEXT_XML) MavenServerWrapper(org.eclipse.che.plugin.maven.server.MavenServerWrapper) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) NotFoundException(org.eclipse.che.api.core.NotFoundException) SAXParseException(org.xml.sax.SAXParseException) List(java.util.List) ServerException(org.eclipse.che.api.core.ServerException) Response(javax.ws.rs.core.Response) MavenProjectManager(org.eclipse.che.plugin.maven.server.core.MavenProjectManager) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) RegisteredProject(org.eclipse.che.api.project.server.RegisteredProject) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) ProjectManager(org.eclipse.che.api.project.server.ProjectManager) Collections(java.util.Collections) MavenTerminal(org.eclipse.che.maven.server.MavenTerminal) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ArrayList(java.util.ArrayList) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) IOException(java.io.IOException) XMLTreeException(org.eclipse.che.commons.xml.XMLTreeException) MavenProject(org.eclipse.che.plugin.maven.server.core.project.MavenProject) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) SAXParseException(org.xml.sax.SAXParseException) MavenProjectProblem(org.eclipse.che.maven.data.MavenProjectProblem) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8