use of org.apache.maven.project.InvalidProjectModelException in project che by eclipse.
the class MavenServerImpl method validate.
private void validate(File pom, List<Exception> exceptions, List<MavenProjectProblem> problems) throws RemoteException {
for (Throwable exception : exceptions) {
if (exception instanceof IllegalStateException && exception.getCause() != null) {
exception = exception.getCause();
}
if (exception instanceof InvalidProjectModelException) {
ModelValidationResult validationResult = ((InvalidProjectModelException) exception).getValidationResult();
if (validationResult != null) {
problems.addAll(validationResult.getMessages().stream().map(s -> MavenProjectProblem.newStructureProblem(pom.getPath(), s)).collect(Collectors.toList()));
} else {
problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), exception.getCause().getMessage()));
}
}
if (exception instanceof ProjectBuildingException) {
String message = exception.getCause() == null ? exception.getMessage() : exception.getCause().getMessage();
problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), message));
} else {
MavenServerContext.getLogger().info(exception);
problems.add(MavenProjectProblem.newStructureProblem(pom.getPath(), exception.getMessage()));
}
}
}
use of org.apache.maven.project.InvalidProjectModelException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method getProjects.
@SuppressWarnings("unchecked")
protected List<MavenProject> getProjects() throws MojoExecutionException {
List<MavenProject> projects = new ArrayList<MavenProject>();
// add filters in well known order, least specific to most specific
FilterArtifacts filter = new FilterArtifacts();
Set<Artifact> artifacts = resolveProjectArtifacts();
if (this.excludeTransitive) {
Set<Artifact> depArtifacts;
if (runOnlyAtExecutionRoot) {
depArtifacts = aggregateProjectDependencyArtifacts();
} else {
depArtifacts = project.getDependencyArtifacts();
}
filter.addFilter(new ProjectTransitivityFilter(depArtifacts, true));
}
filter.addFilter(new ScopeFilter(this.includeScope, this.excludeScope));
filter.addFilter(new GroupIdFilter(this.includeGroupIds, this.excludeGroupIds));
filter.addFilter(new ArtifactIdFilter(this.includeArtifactIds, this.excludeArtifactIds));
// perform filtering
try {
artifacts = filter.filter(artifacts);
} catch (ArtifactFilterException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
for (Artifact artifact : artifacts) {
try {
List<ArtifactRepository> remoteRepo = remoteArtifactRepositories;
if (artifact.isSnapshot()) {
VersionRange rng = VersionRange.createFromVersion(artifact.getBaseVersion());
artifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(), artifact.getArtifactId(), rng, artifact.getType(), artifact.getClassifier(), artifact.getScope(), null, artifact.isOptional());
}
getLog().debug("Building project for " + artifact);
MavenProject p;
try {
p = mavenProjectBuilder.buildFromRepository(artifact, remoteRepo, localRepository);
} catch (InvalidProjectModelException e) {
getLog().warn("Invalid project model for artifact [" + artifact.getArtifactId() + ":" + artifact.getGroupId() + ":" + artifact.getVersion() + "]. " + "It will be ignored by the remote resources Mojo.");
continue;
}
String supplementKey = generateSupplementMapKey(p.getModel().getGroupId(), p.getModel().getArtifactId());
if (supplementModels.containsKey(supplementKey)) {
Model mergedModel = mergeModels(p.getModel(), supplementModels.get(supplementKey));
MavenProject mergedProject = new MavenProject(mergedModel);
projects.add(mergedProject);
mergedProject.setArtifact(artifact);
mergedProject.setVersion(artifact.getVersion());
getLog().debug("Adding project with groupId [" + mergedProject.getGroupId() + "] (supplemented)");
} else {
projects.add(p);
getLog().debug("Adding project with groupId [" + p.getGroupId() + "]");
}
} catch (ProjectBuildingException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Collections.sort(projects, new ProjectComparator());
return projects;
}
Aggregations