Search in sources :

Example 1 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class JavaAnnotationModel method reportProblems.

private void reportProblems(final List<Problem> problems) {
    boolean temporaryProblemsChanged = false;
    if (!generatedAnnotations.isEmpty()) {
        temporaryProblemsChanged = true;
        super.clear();
        generatedAnnotations.clear();
    }
    if (reportedProblems != null && !reportedProblems.isEmpty()) {
        for (final Problem problem : reportedProblems) {
            final Position position = createPositionFromProblem(problem);
            if (position != null) {
                final ProblemAnnotation annotation = new ProblemAnnotation(problem);
                addAnnotation(annotation, position, false);
                generatedAnnotations.add(annotation);
                temporaryProblemsChanged = true;
            }
        }
    }
    if (temporaryProblemsChanged) {
        fireModelChanged();
    }
}
Also used : Position(org.eclipse.che.ide.api.editor.text.Position) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem)

Example 2 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class JavaQuickAssistProcessor method createProblem.

private Problem createProblem(JavaAnnotation javaAnnotation, Position pos) {
    Problem problem = dtoFactory.createDto(Problem.class);
    //server use only this fields
    problem.setID(javaAnnotation.getId());
    problem.setError(javaAnnotation.isError());
    problem.setArguments(Arrays.asList(javaAnnotation.getArguments()));
    problem.setSourceStart(pos.getOffset());
    //TODO I don't know why but in that place source end is bugger on 1 char
    problem.setSourceEnd(pos.getOffset() + pos.getLength() - 1);
    return problem;
}
Also used : Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem)

Example 3 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem 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 4 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem 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)

Example 5 with Problem

use of org.eclipse.che.ide.ext.java.shared.dto.Problem in project che by eclipse.

the class PomReconcilerTest method testReconcilePomWhenPomContainsDependecyWithIncorrectVersion.

@Test
public void testReconcilePomWhenPomContainsDependecyWithIncorrectVersion() throws Exception {
    String brokenDependency = "    <dependency>\n" + "        <groupId>junit</groupId>\n" + "        <artifactId>junit</artifactId>\n" + "        <version>33333333.8.1</version>\n" + "        <scope>test</scope>\n" + "    </dependency>\n";
    MavenServerService serverService = new MavenServerService(null, projectRegistry, pm, projectManager, null, null);
    FolderEntry testProject = createTestProject(PROJECT_NAME, getPomContentWithDependency(brokenDependency));
    VirtualFileEntry pom = testProject.getChild("pom.xml");
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
    mavenWorkspace.update(Collections.singletonList(project));
    mavenWorkspace.waitForUpdate();
    List<Problem> problems = serverService.reconcilePom(String.format("/%s/pom.xml", PROJECT_NAME));
    assertThat(problems).hasSize(1);
    assertThat(problems.get(0).isError()).isTrue();
    assertThat(pom).isNotNull();
}
Also used : FolderEntry(org.eclipse.che.api.project.server.FolderEntry) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) MavenServerService(org.eclipse.che.plugin.maven.server.rest.MavenServerService) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) IProject(org.eclipse.core.resources.IProject) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Aggregations

Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)15 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)7 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)6 MavenServerService (org.eclipse.che.plugin.maven.server.rest.MavenServerService)6 MavenServerManagerTest (org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)6 Test (org.testng.annotations.Test)6 IProject (org.eclipse.core.resources.IProject)5 ArrayList (java.util.ArrayList)3 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)2 ServerException (org.eclipse.che.api.core.ServerException)2 MavenProjectProblem (org.eclipse.che.maven.data.MavenProjectProblem)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Document (org.eclipse.jface.text.Document)2 Inject (com.google.inject.Inject)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponse (io.swagger.annotations.ApiResponse)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1