Skip to content

Commit

Permalink
Don't report "Non-parseable POM" error #446
Browse files Browse the repository at this point in the history
Fixes: #446
  • Loading branch information
vrubezhny committed Jul 21, 2023
1 parent a97bd74 commit c67f0d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.io.ModelParseException;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.DefaultProjectBuilder;
import org.apache.maven.project.DefaultProjectBuildingRequest;
Expand Down Expand Up @@ -174,7 +175,9 @@ private void parseAndCache(URI uri, int version, FileModelSource source) {
if (e.getCause() instanceof ModelBuildingException modelBuildingException) {
// Try to manually build a minimal project from the document to collect lower-level
// errors and to have something usable in cache for most basic operations
problems.addAll(modelBuildingException.getProblems());
modelBuildingException.getProblems().stream()
.filter(p -> !(p.getException() instanceof ModelParseException))
.forEach(problems::add);
try (InputStream documentStream = source.getInputStream()) {
Model model = mavenReader.read(documentStream);
project = new MavenProject(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ public void testLocalParentGAVCompletion()
// * if relativePath is not set, complete with remote repo artifacts with "pom" packaging
}

@Test
public void testDoNotReportNonParseablePomError()
throws IOException, InterruptedException, ExecutionException, URISyntaxException {
TextDocument textDocument = new TextDocument("<project> < </project>", "file:///pom.xml");
DOMDocument document = DOMParser.getInstance().parse(textDocument, languageService.getResolverExtensionManager());
List<Diagnostic> diagnostics = languageService.doDiagnostics(document, new XMLValidationSettings(), Map.of(), () -> {});
assertFalse(diagnostics.stream().anyMatch(diag -> diag.getMessage().contains("Non-parseable POM")));
}

@Test
public void testMissingArtifactIdError()
throws IOException, InterruptedException, ExecutionException, URISyntaxException {
Expand Down

0 comments on commit c67f0d6

Please sign in to comment.