mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Revisit PluginXmlParserTests
See gh-20190
This commit is contained in:
parent
a9dabe13bb
commit
020ae2c7ba
@ -36,6 +36,7 @@ import org.w3c.dom.NodeList;
|
||||
* A parser for a Maven plugin's {@code plugin.xml} file.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Mike Smithson
|
||||
*/
|
||||
class PluginXmlParser {
|
||||
|
||||
@ -98,21 +99,20 @@ class PluginXmlParser {
|
||||
|
||||
private Parameter parseParameter(Node parameterNode, Map<String, String> defaultValues,
|
||||
Map<String, String> userProperties) throws XPathExpressionException {
|
||||
Parameter parameter = new Parameter(textAt("name", parameterNode), textAt("type", parameterNode),
|
||||
return new Parameter(textAt("name", parameterNode), textAt("type", parameterNode),
|
||||
booleanAt("required", parameterNode), booleanAt("editable", parameterNode),
|
||||
format(textAt("description", parameterNode)), defaultValues.get(textAt("name", parameterNode)),
|
||||
userProperties.get(textAt("name", parameterNode)), textAt("since", parameterNode));
|
||||
return parameter;
|
||||
}
|
||||
|
||||
private boolean booleanAt(String path, Node node) throws XPathExpressionException {
|
||||
return Boolean.valueOf(textAt(path, node));
|
||||
return Boolean.parseBoolean(textAt(path, node));
|
||||
}
|
||||
|
||||
private String format(String input) {
|
||||
return input.replace("<code>", "`").replace("</code>", "`").replace("<", "<").replace(">", ">")
|
||||
.replace("<br>", " ").replace("\n", " ").replace(""", "\"").replaceAll("\\{@code (.*?)\\}", "`$1`")
|
||||
.replaceAll("\\{@link (.*?)\\}", "`$1`").replaceAll("\\{@literal (.*?)\\}", "`$1`")
|
||||
.replace("<br>", " ").replace("\n", " ").replace(""", "\"").replaceAll("\\{@code (.*?)}", "`$1`")
|
||||
.replaceAll("\\{@link (.*?)}", "`$1`").replaceAll("\\{@literal (.*?)}", "`$1`")
|
||||
.replaceAll("<a href=.\"(.*?)\".>(.*?)</a>", "\\$1[\\$2]");
|
||||
}
|
||||
|
||||
|
@ -16,25 +16,42 @@
|
||||
|
||||
package org.springframework.boot.build.mavenplugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.build.mavenplugin.PluginXmlParser.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Tests for {@link PluginXmlParser}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Mike Smithson
|
||||
*/
|
||||
public class PluginXmlParserTests {
|
||||
|
||||
private final PluginXmlParser parser = new PluginXmlParser();
|
||||
|
||||
@Test
|
||||
void dunno() {
|
||||
void parsingAValidPluginXMLFileReturnsTheGAVForThePlugin() {
|
||||
Plugin plugin = this.parser.parse(new File("src/test/resources/plugin.xml"));
|
||||
System.out.println(plugin);
|
||||
assertThat(plugin.getGroupId()).isEqualTo("org.springframework.boot");
|
||||
assertThat(plugin.getArtifactId()).isEqualTo("spring-boot-maven-plugin");
|
||||
assertThat(plugin.getVersion()).isEqualTo("2.2.0.GRADLE-SNAPSHOT");
|
||||
assertThat(plugin.getGoalPrefix()).isEqualTo("spring-boot");
|
||||
assertThat(plugin.getMojos().stream().map(PluginXmlParser.Mojo::getGoal).collect(Collectors.toList()))
|
||||
.isEqualTo(Arrays.<String>asList("build-info", "help", "repackage", "run", "start", "stop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNonExistentPluginFileThrowsARuntimeException() {
|
||||
assertThrows(RuntimeException.class, () ->
|
||||
this.parser.parse(new File("src/test/resources/nonexistent.xml")));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user