mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Make sure that Maven plugin executions can be amended
See gh-867
This commit is contained in:
@@ -37,7 +37,7 @@ public class MavenPlugin {
|
||||
|
||||
private final String version;
|
||||
|
||||
private final List<Execution> executions = new ArrayList<>();
|
||||
private final Map<String, ExecutionBuilder> executions = new LinkedHashMap<>();
|
||||
|
||||
private final List<Dependency> dependencies = new ArrayList<>();
|
||||
|
||||
@@ -73,13 +73,13 @@ public class MavenPlugin {
|
||||
}
|
||||
|
||||
public void execution(String id, Consumer<ExecutionBuilder> customizer) {
|
||||
ExecutionBuilder builder = new ExecutionBuilder(id);
|
||||
customizer.accept(builder);
|
||||
this.executions.add(builder.build());
|
||||
customizer.accept(
|
||||
this.executions.computeIfAbsent(id, (key) -> new ExecutionBuilder(id)));
|
||||
}
|
||||
|
||||
public List<Execution> getExecutions() {
|
||||
return this.executions;
|
||||
return this.executions.values().stream().map(ExecutionBuilder::build)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void dependency(String groupId, String artifactId, String version) {
|
||||
|
@@ -109,4 +109,41 @@ class MavenPluginTests {
|
||||
.withMessageContaining("test").withMessageContaining("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executionPhasesCanBeOverridden() {
|
||||
MavenPlugin plugin = new MavenPlugin("com.example", "test-plugin");
|
||||
plugin.execution("test", (test) -> test.phase("compile"));
|
||||
plugin.execution("test", (test) -> test.phase("process-resources"));
|
||||
assertThat(plugin.getExecutions()).hasSize(1);
|
||||
assertThat(plugin.getExecutions().get(0).getPhase())
|
||||
.isEqualTo("process-resources");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executionGoalsCanBeAmended() {
|
||||
MavenPlugin plugin = new MavenPlugin("com.example", "test-plugin");
|
||||
plugin.execution("test", (test) -> test.goal("first"));
|
||||
plugin.execution("test", (test) -> test.goal("second"));
|
||||
assertThat(plugin.getExecutions()).hasSize(1);
|
||||
assertThat(plugin.getExecutions().get(0).getGoals()).containsExactly("first",
|
||||
"second");
|
||||
}
|
||||
|
||||
@Test
|
||||
void executionConfigurationCanBeOverridden() {
|
||||
MavenPlugin plugin = new MavenPlugin("com.example", "test-plugin");
|
||||
plugin.execution("test",
|
||||
(test) -> test.configuration((testConfiguration) -> testConfiguration
|
||||
.parameter("enabled", "true").parameter("another", "test")));
|
||||
plugin.execution("test", (test) -> test.configuration(
|
||||
(testConfiguration) -> testConfiguration.parameter("enabled", "false")));
|
||||
assertThat(plugin.getExecutions()).hasSize(1);
|
||||
List<Setting> settings = plugin.getExecutions().get(0).getConfiguration()
|
||||
.getSettings();
|
||||
assertThat(settings.stream().map(Setting::getName)).containsExactly("enabled",
|
||||
"another");
|
||||
assertThat(settings.stream().map(Setting::getValue)).containsExactly("false",
|
||||
"test");
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user