Search in sources :

Example 1 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry 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 2 with VirtualFileEntry

use of org.eclipse.che.api.project.server.VirtualFileEntry 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)

Example 3 with VirtualFileEntry

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

the class PomReconcilerTest method testReconcilePomWhenMavenProjectIsNotFound.

@Test
public void testReconcilePomWhenMavenProjectIsNotFound() throws Exception {
    MavenServerService serverService = new MavenServerService(null, projectRegistry, pm, projectManager, null, null);
    FolderEntry testProject = createTestProject(PROJECT_NAME, "");
    VirtualFileEntry pom = testProject.getChild("pom.xml");
    List<Problem> problems = serverService.reconcilePom(String.format("/%s/pom.xml", PROJECT_NAME));
    assertThat(problems).isEmpty();
    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) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Example 4 with VirtualFileEntry

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

the class PomReconcilerTest method testReconcilePomWhenPomContainsCorrectDependency.

@Test
public void testReconcilePomWhenPomContainsCorrectDependency() throws Exception {
    String dependency = "    <dependency>\n" + "        <groupId>junit</groupId>\n" + "        <artifactId>junit</artifactId>\n" + "        <version>3.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(dependency));
    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).isEmpty();
    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)

Example 5 with VirtualFileEntry

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

the class PomReconcilerTest method testProblemPosition.

@Test
public void testProblemPosition() throws Exception {
    MavenServerService serverService = new MavenServerService(null, projectRegistry, pm, projectManager, null, null);
    FolderEntry testProject = createTestProject("A", "");
    VirtualFileEntry child = testProject.getChild("pom.xml");
    String newContent = getPomContent("<ss");
    child.getVirtualFile().updateContent(newContent);
    List<Problem> problems = serverService.reconcilePom("/A/pom.xml");
    assertThat(problems).isNotEmpty();
    Problem problem = problems.get(0);
    assertThat(problem.getSourceStart()).isEqualTo(newContent.indexOf("<ss") + 3);
    assertThat(problem.getSourceEnd()).isEqualTo(newContent.indexOf("<ss") + 4);
}
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) Test(org.testng.annotations.Test) MavenServerManagerTest(org.eclipse.che.plugin.maven.server.rmi.MavenServerManagerTest)

Aggregations

VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)21 FolderEntry (org.eclipse.che.api.project.server.FolderEntry)11 ServerException (org.eclipse.che.api.core.ServerException)9 Problem (org.eclipse.che.ide.ext.java.shared.dto.Problem)7 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)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 NotFoundException (org.eclipse.che.api.core.NotFoundException)5 IProject (org.eclipse.core.resources.IProject)5 ConflictException (org.eclipse.che.api.core.ConflictException)4 FileEntry (org.eclipse.che.api.project.server.FileEntry)3 RegisteredProject (org.eclipse.che.api.project.server.RegisteredProject)3 IResourceStatus (org.eclipse.core.resources.IResourceStatus)3 CoreException (org.eclipse.core.runtime.CoreException)3 IStatus (org.eclipse.core.runtime.IStatus)3 MultiStatus (org.eclipse.core.runtime.MultiStatus)3 Status (org.eclipse.core.runtime.Status)3 HashMap (java.util.HashMap)2 List (java.util.List)2