Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'MavenPluginUtils.getContainingPluginDescriptor' error processing #445

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private Optional<MavenProject> getMinimalMavenProject(File file) {
// XML document is invalid fo parsing (eg user is typing), it's a valid state that shouldn't log
// exceptions
} catch (IOException ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
LOGGER.log(Level.SEVERE, "Couldn't read Maven project: " + file.getAbsolutePath() + " : " + ex.getMessage(), ex);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public PluginValidator(MavenLemminxExtension plugin) {

public Optional<List<Diagnostic>> validatePluginResolution(DiagnosticRequest diagnosticRequest) {
try {
MavenPluginUtils.getContainingPluginDescriptor(diagnosticRequest.getNode(), plugin);
MavenPluginUtils.getContainingPluginDescriptor(diagnosticRequest.getNode(), plugin, true);
} catch (PluginResolutionException | PluginDescriptorParsingException | InvalidPluginDescriptorException e) {
LOGGER.log(Level.WARNING, "Could not resolve plugin description", e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public static Set<Parameter> collectPluginConfigurationParameters(IPositionReque
public static Set<MojoParameter> collectPluginConfigurationMojoParameters(IPositionRequest request,
MavenLemminxExtension plugin)
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException {
PluginDescriptor pluginDescriptor = MavenPluginUtils.getContainingPluginDescriptor(request.getNode(), plugin);
PluginDescriptor pluginDescriptor = null;
try {
pluginDescriptor = MavenPluginUtils.getContainingPluginDescriptor(request.getNode(), plugin);
} catch (PluginResolutionException | PluginDescriptorParsingException | InvalidPluginDescriptorException e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
if (pluginDescriptor == null) {
return Collections.emptySet();
}
Expand All @@ -127,8 +132,9 @@ public static Set<MojoParameter> collectPluginConfigurationMojoParameters(IPosit
return Collections.emptySet();
}
plugin.getMavenSession().setProjects(Collections.singletonList(project));
final var finalPluginDescriptor = pluginDescriptor;
return mojosToConsiderList.stream().flatMap(mojo -> PlexusConfigHelper
.loadMojoParameters(pluginDescriptor, mojo, plugin.getMavenSession(), plugin.getBuildPluginManager())
.loadMojoParameters(finalPluginDescriptor, mojo, plugin.getMavenSession(), plugin.getBuildPluginManager())
.stream()).collect(Collectors.toSet());
}

Expand All @@ -140,6 +146,12 @@ public static RemoteRepository toRemoteRepo(Repository modelRepo) {
public static PluginDescriptor getContainingPluginDescriptor(DOMNode node,
MavenLemminxExtension lemminxMavenPlugin)
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException {
return getContainingPluginDescriptor(node, lemminxMavenPlugin, false);
}

public static PluginDescriptor getContainingPluginDescriptor(DOMNode node,
MavenLemminxExtension lemminxMavenPlugin, boolean reThrowPluginDescriptorExceptions)
throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException {
MavenProject project = lemminxMavenPlugin.getProjectCache()
.getLastSuccessfulMavenProject(node.getOwnerDocument());
if (project == null) {
Expand Down Expand Up @@ -192,8 +204,13 @@ public static PluginDescriptor getContainingPluginDescriptor(DOMNode node,
pluginDescriptor = lemminxMavenPlugin.getMavenPluginManager().getPluginDescriptor(plugin,
project.getRemotePluginRepositories().stream().collect(Collectors.toList()),
lemminxMavenPlugin.getMavenSession().getRepositorySession());
} catch (PluginResolutionException ex) {
LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
} catch (PluginResolutionException | PluginDescriptorParsingException | InvalidPluginDescriptorException ex) {
LOGGER.log(Level.WARNING, ex.getMessage(), ex);
if (reThrowPluginDescriptorExceptions) {
throw ex; // Needed for plugin validation
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "An error occured while getting a plugin descriptor: " + e.getMessage(), e);
}
if (pluginDescriptor == null && "0.0.1-SNAPSHOT".equals(plugin.getVersion())) { // probably missing or not parsed version
Optional<DefaultArtifactVersion> version;
Expand Down