use of org.eclipse.che.maven.data.MavenProjectProblem 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.maven.data.MavenProjectProblem in project che by eclipse.
the class MavenModelReader method doRead.
private ModelReadingResult doRead(File pom) {
List<MavenProjectProblem> problems = new ArrayList<>();
Set<String> enabledProfiles = new HashSet<>();
MavenModel result = new MavenModel();
fillModelByDefaults(result);
Model model = null;
try {
model = Model.readFrom(pom);
} catch (IOException e) {
problems.add(MavenProjectProblem.newProblem(pom.getPath(), e.getMessage(), MavenProblemType.SYNTAX));
}
if (model == null) {
return new ModelReadingResult(result, problems, enabledProfiles);
}
final MavenKey parentKey;
if (model.getParent() == null) {
parentKey = result.getParent().getMavenKey();
} else {
Parent modelParent = model.getParent();
parentKey = new MavenKey(modelParent.getGroupId(), modelParent.getArtifactId(), modelParent.getVersion());
MavenParent parent = new MavenParent(parentKey, modelParent.getRelativePath());
result.setParent(parent);
}
final MavenKey mavenKey = new MavenKey(getNotNull(model.getGroupId(), parentKey.getGroupId()), model.getArtifactId(), getNotNull(model.getVersion(), parentKey.getVersion()));
result.setMavenKey(mavenKey);
if (model.getPackaging() != null) {
result.setPackaging(model.getPackaging());
}
result.setName(model.getName());
final List<String> modules = model.getModules();
if (modules != null) {
result.setModules(new ArrayList<>(model.getModules()));
}
Map<String, String> properties = model.getProperties();
Properties prop = new Properties();
if (properties != null) {
prop.putAll(properties);
}
result.setProperties(prop);
final Build build = model.getBuild();
if (build != null) {
final String sourceDirectory = build.getSourceDirectory();
if (sourceDirectory != null) {
result.getBuild().setSources(singletonList(sourceDirectory));
}
final String testSourceDirectory = build.getTestSourceDirectory();
if (testSourceDirectory != null) {
result.getBuild().setTestSources(singletonList(testSourceDirectory));
}
result.getBuild().setResources(convertResources(build.getResources()));
}
//TODO add profiles
return new ModelReadingResult(result, problems, enabledProfiles);
}
use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.
the class MavenProject method generateProblems.
private List<MavenProjectProblem> generateProblems() {
List<MavenProjectProblem> result = new ArrayList<>();
result.addAll(info.problems);
result.addAll(info.modulesNameToPath.entrySet().stream().filter(entry -> !project.getFolder(entry.getKey()).exists()).map(entry -> new MavenProjectProblem(getPomPath(), "Can't find module: " + entry.getKey(), MavenProblemType.DEPENDENCY)).collect(Collectors.toList()));
result.addAll(getDependencies().stream().filter(artifact -> !artifact.isResolved()).map(artifact -> new MavenProjectProblem(getPomPath(), "Can't find dependency: " + artifact.getDisplayString(), MavenProblemType.DEPENDENCY)).collect(Collectors.toList()));
//TODO add unresolved plugins and extensions
return result;
}
use of org.eclipse.che.maven.data.MavenProjectProblem in project che by eclipse.
the class MavenServerImpl method createResult.
private MavenServerResult createResult(File pom, MavenResult mavenResult) throws RemoteException {
List<MavenProjectProblem> problems = new ArrayList<>();
Set<MavenKey> unresolvedArtifacts = new HashSet<>();
validate(pom, mavenResult.getExceptions(), problems);
MavenProject project = mavenResult.getMavenProject();
if (project == null) {
return new MavenServerResult(null, problems, unresolvedArtifacts);
}
MavenModel model = null;
try {
DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult();
org.eclipse.aether.graph.DependencyNode dependencyNode = null;
if (resolutionResult != null) {
dependencyNode = resolutionResult.getDependencyGraph();
}
List<org.eclipse.aether.graph.DependencyNode> dependencyNodes = null;
if (dependencyNode != null) {
dependencyNodes = dependencyNode.getChildren();
}
model = MavenModelUtil.convertProjectToModel(project, dependencyNodes, new File(localRepo.getBasedir()));
} catch (Exception e) {
validate(project.getFile(), Collections.singletonList(e), problems);
}
List<String> activeProfiles = getActiveProfiles(project);
MavenProjectInfo projectInfo = new MavenProjectInfo(model, null, activeProfiles);
return new MavenServerResult(projectInfo, problems, unresolvedArtifacts);
}
Aggregations