-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate element in plugin <configuration>
Fix #9 Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
- Loading branch information
Showing
9 changed files
with
146 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lemminx-maven/src/main/java/org/eclipse/lemminx/maven/PluginValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.eclipse.lemminx.maven; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.maven.plugin.MavenPluginManager; | ||
import org.apache.maven.plugin.descriptor.Parameter; | ||
import org.eclipse.lemminx.dom.DOMNode; | ||
import org.eclipse.lsp4j.Diagnostic; | ||
import org.eclipse.lsp4j.DiagnosticSeverity; | ||
|
||
public class PluginValidator { | ||
private final MavenProjectCache cache; | ||
private final MavenPluginManager pluginManager; | ||
|
||
public PluginValidator(MavenProjectCache cache, MavenPluginManager pluginManager ) { | ||
this.cache = cache; | ||
this.pluginManager = pluginManager; | ||
} | ||
|
||
public Diagnostic validateConfiguration(DiagnosticRequest diagnosticRequest) { | ||
DOMNode node = diagnosticRequest.getNode(); | ||
if (node == null) { | ||
return null; | ||
} | ||
if (node.isElement() && node.hasChildNodes()) { | ||
List<Parameter> parameters = MavenPluginUtils.collectPluginConfigurationParameters(diagnosticRequest, cache, pluginManager); | ||
for (DOMNode childNode : node.getChildren()) { | ||
DiagnosticRequest childDiagnosticReq = new DiagnosticRequest(childNode, diagnosticRequest.getXMLDocument(), diagnosticRequest.getDiagnostics()); | ||
Diagnostic diag = internalValidateConfiguration(childDiagnosticReq, childNode, parameters); | ||
if (diag != null) { | ||
diagnosticRequest.getDiagnostics().add(diag); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
private static Diagnostic internalValidateConfiguration(DiagnosticRequest diagnosticReq, DOMNode childNode, List<Parameter> parameters) { | ||
DOMNode node = childNode; | ||
if (node.getLocalName() == null) { | ||
return null; | ||
} | ||
for (Parameter parameter : parameters) { | ||
if (node.getLocalName().equals(parameter.getName())) { | ||
return null; | ||
} | ||
} | ||
return new Diagnostic(diagnosticReq.getRange(), | ||
"Invalid plugin configuration", DiagnosticSeverity.Warning, diagnosticReq.getXMLDocument().getDocumentURI(), "XML"); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters