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