use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.
the class MavenProjectManager method update.
public void update(List<IProject> projects, boolean recursive) {
if (projects.isEmpty()) {
return;
}
mavenNotifier.start();
UpdateState state = new UpdateState();
Deque<MavenProject> stack = new LinkedList<>();
for (IProject project : projects) {
MavenProject mavenProject = findMavenProject(project);
if (mavenProject != null) {
internalUpdate(mavenProject, findParentProject(mavenProject), false, recursive, state, stack);
} else {
internalAddMavenProject(project, recursive, state, stack);
}
}
mavenNotifier.stop();
state.fireUpdate();
}
use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.
the class MavenProjectManager method findDependentProjects.
public List<MavenProject> findDependentProjects(List<MavenProject> projects) {
readLock.lock();
try {
List<MavenProject> result = new ArrayList<>();
Set<MavenKey> mavenKeys = projects.stream().map(MavenProject::getMavenKey).collect(Collectors.toSet());
Set<String> paths = projects.stream().map(project -> project.getProject().getFullPath().toOSString()).collect(Collectors.toSet());
for (MavenProject project : projectToMavenProjectMap.values()) {
boolean isAdd = false;
for (String path : project.getModulesPath()) {
if (paths.contains(path)) {
isAdd = true;
break;
}
}
if (!isAdd) {
for (MavenArtifact artifact : project.getDependencies()) {
if (contains(mavenKeys, artifact.getArtifactId(), artifact.getGroupId(), artifact.getVersion())) {
isAdd = true;
break;
}
}
}
if (isAdd) {
result.add(project);
}
}
return result;
} finally {
readLock.unlock();
}
}
use of org.eclipse.che.plugin.maven.server.core.project.MavenProject in project che by eclipse.
the class MavenProjectManager method updateChild.
private boolean updateChild(MavenProject parentProject, MavenProject module) {
MavenProject oldParent = findParentProject(module);
if (oldParent == parentProject) {
return false;
}
writeLock.lock();
try {
if (oldParent == null) {
rootProjects.remove(module);
} else {
removeModule(oldParent, module);
}
if (parentProject == null) {
rootProjects.add(module);
} else {
addModule(parentProject, module);
}
} finally {
writeLock.unlock();
}
return false;
}
use of org.eclipse.che.plugin.maven.server.core.project.MavenProject 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.plugin.maven.server.core.project.MavenProject in project che by eclipse.
the class WorkspaceTest method testProjectNameShuldUseArtifactIdIfNotDeclared.
@Test
public void testProjectNameShuldUseArtifactIdIfNotDeclared() throws Exception {
String pom = "<groupId>test</groupId>" + "<artifactId>testArtifact</artifactId>" + "<version>42</version>" + "<dependencies>" + " <dependency>" + " <groupId>junit</groupId>" + " <artifactId>junit</artifactId>" + " <version>4.12</version>" + " </dependency>" + "</dependencies>";
createTestProject("test", pom);
IProject test = ResourcesPlugin.getWorkspace().getRoot().getProject("test");
mavenWorkspace.update(Collections.singletonList(test));
mavenWorkspace.waitForUpdate();
MavenProject mavenProject = mavenProjectManager.findMavenProject(test);
String name = mavenProject.getName();
assertThat(name).isNotNull().isNotEmpty().isEqualTo("testArtifact");
}
Aggregations