mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 23:13:30 +08:00
Allow adding <extensions>true</extensions> to plugin config
See gh-921
This commit is contained in:
parent
593b9ec878
commit
3e86a446a8
@ -43,6 +43,7 @@ import io.spring.initializr.generator.version.VersionReference;
|
|||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class MavenBuildWriter {
|
public class MavenBuildWriter {
|
||||||
|
|
||||||
@ -270,6 +271,9 @@ public class MavenBuildWriter {
|
|||||||
writeSingleElement(writer, "groupId", plugin.getGroupId());
|
writeSingleElement(writer, "groupId", plugin.getGroupId());
|
||||||
writeSingleElement(writer, "artifactId", plugin.getArtifactId());
|
writeSingleElement(writer, "artifactId", plugin.getArtifactId());
|
||||||
writeSingleElement(writer, "version", plugin.getVersion());
|
writeSingleElement(writer, "version", plugin.getVersion());
|
||||||
|
if (plugin.shouldLoadExtensions()) {
|
||||||
|
writeSingleElement(writer, "extensions", Boolean.toString(true));
|
||||||
|
}
|
||||||
writePluginConfiguration(writer, plugin.getConfiguration());
|
writePluginConfiguration(writer, plugin.getConfiguration());
|
||||||
if (!plugin.getExecutions().isEmpty()) {
|
if (!plugin.getExecutions().isEmpty()) {
|
||||||
writeElement(writer, "executions", () -> writeCollection(writer,
|
writeElement(writer, "executions", () -> writeCollection(writer,
|
||||||
|
@ -28,6 +28,7 @@ import java.util.stream.Collectors;
|
|||||||
* A plugin in a {@link MavenBuild}.
|
* A plugin in a {@link MavenBuild}.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
public class MavenPlugin {
|
public class MavenPlugin {
|
||||||
|
|
||||||
@ -43,6 +44,8 @@ public class MavenPlugin {
|
|||||||
|
|
||||||
private ConfigurationCustomization configurationCustomization = null;
|
private ConfigurationCustomization configurationCustomization = null;
|
||||||
|
|
||||||
|
private boolean extensions;
|
||||||
|
|
||||||
public MavenPlugin(String groupId, String artifactId) {
|
public MavenPlugin(String groupId, String artifactId) {
|
||||||
this(groupId, artifactId, null);
|
this(groupId, artifactId, null);
|
||||||
}
|
}
|
||||||
@ -99,6 +102,17 @@ public class MavenPlugin {
|
|||||||
: this.configurationCustomization.build();
|
: this.configurationCustomization.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean shouldLoadExtensions() {
|
||||||
|
return this.extensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables loading plugin extensions.
|
||||||
|
*/
|
||||||
|
public void extensions() {
|
||||||
|
this.extensions = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for creation an {@link Execution}.
|
* Builder for creation an {@link Execution}.
|
||||||
*/
|
*/
|
||||||
|
@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* Tests for {@link MavenBuild}.
|
* Tests for {@link MavenBuild}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
class MavenBuildTests {
|
class MavenBuildTests {
|
||||||
|
|
||||||
@ -94,4 +95,24 @@ class MavenBuildTests {
|
|||||||
.containsExactly("run-this", "run-that");
|
.containsExactly("run-this", "run-that");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mavenPluginExtensionsNotLoadedByDefault() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.plugin("com.example", "test-plugin");
|
||||||
|
|
||||||
|
MavenPlugin testPlugin = build.getPlugins().get(0);
|
||||||
|
|
||||||
|
assertThat(testPlugin.shouldLoadExtensions()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void mavenPluginExtensionsCanBeLoaded() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.plugin("com.example", "test-plugin").extensions();
|
||||||
|
|
||||||
|
MavenPlugin testPlugin = build.getPlugins().get(0);
|
||||||
|
|
||||||
|
assertThat(testPlugin.shouldLoadExtensions()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* Tests for {@link MavenBuildWriter}.
|
* Tests for {@link MavenBuildWriter}.
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Olga Maciaszek-Sharma
|
||||||
*/
|
*/
|
||||||
class MavenBuildWriterTests {
|
class MavenBuildWriterTests {
|
||||||
|
|
||||||
@ -381,6 +382,7 @@ class MavenBuildWriterTests {
|
|||||||
assertThat(plugin).textAtPath("artifactId")
|
assertThat(plugin).textAtPath("artifactId")
|
||||||
.isEqualTo("spring-boot-maven-plugin");
|
.isEqualTo("spring-boot-maven-plugin");
|
||||||
assertThat(plugin).textAtPath("version").isNullOrEmpty();
|
assertThat(plugin).textAtPath("version").isNullOrEmpty();
|
||||||
|
assertThat(plugin).textAtPath("extensions").isNullOrEmpty();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,6 +462,21 @@ class MavenBuildWriterTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithPluginWithExtensions() throws Exception {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.setGroup("com.example.demo");
|
||||||
|
build.setArtifact("demo");
|
||||||
|
MavenPlugin demoPlugin = build.plugin("com.example.demo", "demo-plugin");
|
||||||
|
demoPlugin.extensions();
|
||||||
|
generatePom(build, (pom) -> {
|
||||||
|
NodeAssert plugin = pom.nodeAtPath("/project/build/plugins/plugin");
|
||||||
|
assertThat(plugin).textAtPath("groupId").isEqualTo("com.example.demo");
|
||||||
|
assertThat(plugin).textAtPath("artifactId").isEqualTo("demo-plugin");
|
||||||
|
assertThat(plugin).textAtPath("extensions").isEqualTo(Boolean.toString(true));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithMavenCentral() throws Exception {
|
void pomWithMavenCentral() throws Exception {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
|
Loading…
Reference in New Issue
Block a user