mirror of
https://gitee.com/dcren/initializr.git
synced 2025-04-05 17:38:06 +08:00
Polish "Add support for Maven extensions"
See gh-1290
This commit is contained in:
parent
26da5ee6aa
commit
4d574a9e01
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -38,7 +38,7 @@ public class MavenBuild extends Build {
|
||||
|
||||
private final MavenPluginContainer plugins = new MavenPluginContainer();
|
||||
|
||||
private final MavenExtensionsContainer extensions = new MavenExtensionsContainer();
|
||||
private final MavenExtensionContainer extensions = new MavenExtensionContainer();
|
||||
|
||||
private final MavenDistributionManagement.Builder distributionManagement = new MavenDistributionManagement.Builder();
|
||||
|
||||
@ -109,11 +109,11 @@ public class MavenBuild extends Build {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@linkplain MavenExtensionsContainer extensions container} to use to
|
||||
* Return the {@linkplain MavenExtensionContainer extension container} to use to
|
||||
* configure extensions.
|
||||
* @return the {@link MavenExtensionsContainer}
|
||||
* @return the {@link MavenExtensionContainer}
|
||||
*/
|
||||
public MavenExtensionsContainer extensions() {
|
||||
public MavenExtensionContainer extensions() {
|
||||
return this.extensions;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -17,9 +17,10 @@
|
||||
package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
/**
|
||||
* An extension entry in a @{@link MavenBuild}.
|
||||
* A build extension in a @{@link MavenBuild}.
|
||||
*
|
||||
* @author Niklas Herder
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class MavenExtension {
|
||||
|
||||
@ -27,7 +28,7 @@ public class MavenExtension {
|
||||
|
||||
private final String artifactId;
|
||||
|
||||
private String version;
|
||||
private final String version;
|
||||
|
||||
protected MavenExtension(Builder builder) {
|
||||
this.groupId = builder.groupId;
|
||||
@ -35,14 +36,26 @@ public class MavenExtension {
|
||||
this.version = builder.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the group ID of the extension.
|
||||
* @return the group id
|
||||
*/
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the artifact ID of the extension.
|
||||
* @return the artifact id
|
||||
*/
|
||||
public String getArtifactId() {
|
||||
return this.artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the version of the extension.
|
||||
* @return the artifact id
|
||||
*/
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
@ -60,11 +73,20 @@ public class MavenExtension {
|
||||
this.artifactId = artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the version of the extension.
|
||||
* @param version the version of the extension
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public Builder version(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link MavenExtension} with the current state of this builder.
|
||||
* @return a {@link MavenExtension}
|
||||
*/
|
||||
public MavenExtension build() {
|
||||
return new MavenExtension(this);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,7 +21,13 @@ import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class MavenExtensionsContainer {
|
||||
/**
|
||||
* A container for {@link MavenExtension maven extensions}.
|
||||
*
|
||||
* @author Niklas Herder
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class MavenExtensionContainer {
|
||||
|
||||
private final Map<String, MavenExtension.Builder> extensions = new LinkedHashMap<>();
|
||||
|
||||
@ -54,14 +60,16 @@ public class MavenExtensionsContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@link MavenExtension} with the specified {@code groupId} and
|
||||
* {@code artifactId}. Does nothing if the extension has already been added.
|
||||
* Add a {@link MavenExtension} with the specified {@code groupId},
|
||||
* {@code artifactId}, and {@code version}. If the extension has already been added,
|
||||
* only update the version if necessary.
|
||||
* @param groupId the groupId of the extension
|
||||
* @param artifactId the artifactId of the extension
|
||||
* @param version the version of the extension
|
||||
* @see #add(String, String, Consumer)
|
||||
*/
|
||||
public void add(String groupId, String artifactId) {
|
||||
addExtension(groupId, artifactId);
|
||||
public void add(String groupId, String artifactId, String version) {
|
||||
add(groupId, artifactId, (extension) -> extension.version(version));
|
||||
}
|
||||
|
||||
/**
|
@ -700,6 +700,23 @@ class MavenBuildWriterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithoutExtensions() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
generatePom(build, (pom) -> assertThat(pom).nodeAtPath("/project/build/extensions").isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithExtension() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.extensions().add("com.example", "testExtension", "1.6.1");
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/groupId").isEqualTo("com.example");
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/artifactId").isEqualTo("testExtension");
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/version").isEqualTo("1.6.1");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithEmptyBuild() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
@ -903,23 +920,6 @@ class MavenBuildWriterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithoutExtensions() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
generatePom(build, (pom) -> assertThat(pom).nodeAtPath("/project/build/extensions").isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithExtension() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.extensions().add("com.example", "testExtension", (builder) -> builder.version("1.6.1"));
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/groupId").isEqualTo("com.example");
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/artifactId").isEqualTo("testExtension");
|
||||
assertThat(pom).textAtPath("/project/build/extensions/extension/version").isEqualTo("1.6.1");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithDistributionManagementRepository() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
|
Loading…
Reference in New Issue
Block a user