mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-26 21:53:14 +08:00
Add distributionManagement support for Maven pom
See gh-1038
This commit is contained in:
committed by
Stephane Nicoll
parent
39960b1cdd
commit
10deca608d
@@ -37,6 +37,8 @@ public class MavenBuild extends Build {
|
||||
|
||||
private final MavenPluginContainer plugins = new MavenPluginContainer();
|
||||
|
||||
private final MavenDistributionManagement.Builder distributionManagement = new MavenDistributionManagement.Builder();
|
||||
|
||||
public MavenBuild(BuildItemResolver buildItemResolver) {
|
||||
super(buildItemResolver);
|
||||
}
|
||||
@@ -55,6 +57,14 @@ public class MavenBuild extends Build {
|
||||
return this.settings.build();
|
||||
}
|
||||
|
||||
public MavenDistributionManagement.Builder distributionManagement() {
|
||||
return this.distributionManagement;
|
||||
}
|
||||
|
||||
public MavenDistributionManagement getDistributionManagement() {
|
||||
return this.distributionManagement.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@linkplain MavenResource resource container} to use to configure main
|
||||
* resources.
|
||||
|
||||
@@ -18,6 +18,7 @@ package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -35,6 +36,10 @@ import io.spring.initializr.generator.buildsystem.DependencyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.DependencyScope;
|
||||
import io.spring.initializr.generator.buildsystem.MavenRepository;
|
||||
import io.spring.initializr.generator.buildsystem.PropertyContainer;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.DeploymentRepository;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Relocation;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.RepositoryPolicy;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenDistributionManagement.Site;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Configuration;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Execution;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenPlugin.Setting;
|
||||
@@ -51,6 +56,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Stephane Nicoll
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @author Jafer Khan Shamshad
|
||||
* @author Joachim Pasquali
|
||||
*/
|
||||
public class MavenBuildWriter {
|
||||
|
||||
@@ -74,6 +80,7 @@ public class MavenBuildWriter {
|
||||
writeDependencyManagement(writer, build);
|
||||
writeBuild(writer, build);
|
||||
writeRepositories(writer, build);
|
||||
writeDistributionManagement(writer, build);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -425,6 +432,60 @@ public class MavenBuildWriter {
|
||||
});
|
||||
}
|
||||
|
||||
private void writeDistributionManagement(IndentingWriter writer, MavenBuild build) {
|
||||
MavenDistributionManagement distributionManagement = build.getDistributionManagement();
|
||||
if (!distributionManagement.isEmpty()) {
|
||||
writeElement(writer, "distributionManagement", () -> {
|
||||
writeSingleElement(writer, "downloadUrl", distributionManagement.getDownloadUrl());
|
||||
this.writeDeploymentRepository(writer, "repository", distributionManagement.getRepository());
|
||||
this.writeDeploymentRepository(writer, "snapshotRepository",
|
||||
distributionManagement.getSnapshotRepository());
|
||||
if (!distributionManagement.getRelocation().isEmpty()) {
|
||||
Relocation relocation = distributionManagement.getRelocation();
|
||||
writeElement(writer, "relocation", () -> {
|
||||
writeSingleElement(writer, "groupId", relocation.getGroupId());
|
||||
writeSingleElement(writer, "artifactId", relocation.getArtifactId());
|
||||
writeSingleElement(writer, "version", relocation.getVersion());
|
||||
writeSingleElement(writer, "message", relocation.getMessage());
|
||||
});
|
||||
}
|
||||
if (!distributionManagement.getSite().isEmpty()) {
|
||||
Site site = distributionManagement.getSite();
|
||||
writeElementWithAttributes(writer, "site", () -> {
|
||||
writeSingleElement(writer, "id", site.getId());
|
||||
writeSingleElement(writer, "name", site.getName());
|
||||
writeSingleElement(writer, "url", site.getUrl());
|
||||
}, Collections.singletonMap("child.site.url.inherit.append.path",
|
||||
site.getChildSiteUrlInheritAppendPath()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void writeDeploymentRepository(IndentingWriter writer, String name, DeploymentRepository repository) {
|
||||
if (!repository.isEmpty()) {
|
||||
writeElement(writer, name, () -> {
|
||||
writeSingleElement(writer, "id", repository.getId());
|
||||
writeSingleElement(writer, "name", repository.getName());
|
||||
writeSingleElement(writer, "url", repository.getUrl());
|
||||
writeSingleElement(writer, "layout", repository.getLayout());
|
||||
writeSingleElement(writer, "uniqueVersion", repository.getUniqueVersion().toString());
|
||||
this.writeRepositoryPolicy(writer, "releases", repository.getReleases());
|
||||
this.writeRepositoryPolicy(writer, "snapshots", repository.getSnapshots());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void writeRepositoryPolicy(IndentingWriter writer, String name, RepositoryPolicy policy) {
|
||||
if (!policy.isEmpty()) {
|
||||
writeElement(writer, name, () -> {
|
||||
writeSingleElement(writer, "enabled", policy.isEnabled().toString());
|
||||
writeSingleElement(writer, "updatePolicy", policy.getUpdatePolicy());
|
||||
writeSingleElement(writer, "checksumPolicy", policy.getChecksumPolicy());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void writeSingleElement(IndentingWriter writer, String name, String text) {
|
||||
if (text != null) {
|
||||
writer.print(String.format("<%s>", name));
|
||||
@@ -433,6 +494,16 @@ public class MavenBuildWriter {
|
||||
}
|
||||
}
|
||||
|
||||
private void writeElementWithAttributes(IndentingWriter writer, String name, Runnable withContent,
|
||||
Map<String, Object> attributeMap) {
|
||||
writer.print(String.format("<%s", name));
|
||||
attributeMap.entrySet().stream().filter((entry) -> entry.getValue() != null).forEach(
|
||||
(entry) -> writer.print(String.format(" %s=\"%s\"", entry.getKey(), entry.getValue().toString())));
|
||||
writer.println(">");
|
||||
writer.indented(withContent);
|
||||
writer.println(String.format("</%s>", name));
|
||||
}
|
||||
|
||||
private void writeElement(IndentingWriter writer, String name, Runnable withContent) {
|
||||
writer.println(String.format("<%s>", name));
|
||||
writer.indented(withContent);
|
||||
|
||||
@@ -0,0 +1,448 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Maven DistributionManagement as defined in the Maven XSD: <a href=
|
||||
* "https://maven.apache.org/xsd/maven-4.0.0.xsd">https://maven.apache.org/xsd/maven-4.0.0.xsd</a>.
|
||||
* For further documentation see
|
||||
* <a href="https://maven.apache.org/pom.html#Distribution_Management">
|
||||
* https://maven.apache.org/pom.html#Distribution_Management </a>
|
||||
*
|
||||
* @author Joachim Pasquali
|
||||
*/
|
||||
public class MavenDistributionManagement {
|
||||
|
||||
private final String downloadUrl;
|
||||
|
||||
private final DeploymentRepository repository;
|
||||
|
||||
private final DeploymentRepository snapshotRepository;
|
||||
|
||||
private final Site site;
|
||||
|
||||
private final Relocation relocation;
|
||||
|
||||
protected MavenDistributionManagement(final Builder builder) {
|
||||
this.downloadUrl = builder.downloadUrl;
|
||||
this.repository = builder.repository.build();
|
||||
this.snapshotRepository = builder.snapshotRepository.build();
|
||||
this.site = builder.site.build();
|
||||
this.relocation = builder.relocation.build();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.downloadUrl == null && this.repository.isEmpty() && this.snapshotRepository.isEmpty()
|
||||
&& this.site.isEmpty() && this.relocation.isEmpty();
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return this.downloadUrl;
|
||||
}
|
||||
|
||||
public DeploymentRepository getRepository() {
|
||||
return this.repository;
|
||||
}
|
||||
|
||||
public DeploymentRepository getSnapshotRepository() {
|
||||
return this.snapshotRepository;
|
||||
}
|
||||
|
||||
public Site getSite() {
|
||||
return this.site;
|
||||
}
|
||||
|
||||
public Relocation getRelocation() {
|
||||
return this.relocation;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String downloadUrl;
|
||||
|
||||
private DeploymentRepositoryBuilder repository = new DeploymentRepositoryBuilder();
|
||||
|
||||
private DeploymentRepositoryBuilder snapshotRepository = new DeploymentRepositoryBuilder();
|
||||
|
||||
private SiteBuilder site = new SiteBuilder();
|
||||
|
||||
private RelocationBuilder relocation = new RelocationBuilder();
|
||||
|
||||
public Builder downloadUrl(final String downloadUrl) {
|
||||
this.downloadUrl = downloadUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder repository(Consumer<DeploymentRepositoryBuilder> repository) {
|
||||
repository.accept(this.repository);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder snapshotRepository(Consumer<DeploymentRepositoryBuilder> snapshotRepository) {
|
||||
snapshotRepository.accept(this.snapshotRepository);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder site(Consumer<SiteBuilder> site) {
|
||||
site.accept(this.site);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder relocation(Consumer<RelocationBuilder> relocation) {
|
||||
relocation.accept(this.relocation);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MavenDistributionManagement build() {
|
||||
return new MavenDistributionManagement(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DeploymentRepositoryBuilder {
|
||||
|
||||
private Boolean uniqueVersion;
|
||||
|
||||
private RepositoryPolicyBuilder releases = new RepositoryPolicyBuilder();
|
||||
|
||||
private RepositoryPolicyBuilder snapshots = new RepositoryPolicyBuilder();
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
private String layout;
|
||||
|
||||
public DeploymentRepositoryBuilder uniqueVersion(Boolean uniqueVersion) {
|
||||
this.uniqueVersion = uniqueVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder releases(Consumer<RepositoryPolicyBuilder> releases) {
|
||||
releases.accept(this.releases);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder snapshots(Consumer<RepositoryPolicyBuilder> snapshots) {
|
||||
snapshots.accept(this.snapshots);
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepositoryBuilder layout(String layout) {
|
||||
this.layout = layout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeploymentRepository build() {
|
||||
return new DeploymentRepository(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RepositoryPolicyBuilder {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
private String updatePolicy;
|
||||
|
||||
private String checksumPolicy;
|
||||
|
||||
public RepositoryPolicyBuilder enabled(Boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepositoryPolicyBuilder updatePolicy(String updatePolicy) {
|
||||
this.updatePolicy = updatePolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepositoryPolicyBuilder checksumPolicy(String checksumPolicy) {
|
||||
this.checksumPolicy = checksumPolicy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RepositoryPolicy build() {
|
||||
return new RepositoryPolicy(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SiteBuilder {
|
||||
|
||||
private String id;
|
||||
|
||||
private String url;
|
||||
|
||||
private String name;
|
||||
|
||||
private Boolean childSiteUrlInheritAppendPath;
|
||||
|
||||
public SiteBuilder childSiteUrlInheritAppendPath(Boolean childSiteUrlInheritAppendPath) {
|
||||
this.childSiteUrlInheritAppendPath = childSiteUrlInheritAppendPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiteBuilder id(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiteBuilder url(String url) {
|
||||
this.url = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SiteBuilder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Site build() {
|
||||
return new Site(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RelocationBuilder {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String artifactId;
|
||||
|
||||
private String version;
|
||||
|
||||
private String message;
|
||||
|
||||
public RelocationBuilder groupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelocationBuilder artifactId(String artifactId) {
|
||||
this.artifactId = artifactId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelocationBuilder version(String version) {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RelocationBuilder message(String message) {
|
||||
this.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Relocation build() {
|
||||
return new Relocation(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DeploymentRepository {
|
||||
|
||||
private final Boolean uniqueVersion;
|
||||
|
||||
private final RepositoryPolicy releases;
|
||||
|
||||
private final RepositoryPolicy snapshots;
|
||||
|
||||
private final String id;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String url;
|
||||
|
||||
private final String layout;
|
||||
|
||||
protected DeploymentRepository(DeploymentRepositoryBuilder builder) {
|
||||
this.uniqueVersion = builder.uniqueVersion;
|
||||
this.releases = builder.releases.build();
|
||||
this.snapshots = builder.snapshots.build();
|
||||
this.id = builder.id;
|
||||
this.name = builder.name;
|
||||
this.url = builder.url;
|
||||
this.layout = builder.layout;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.uniqueVersion == null && this.id == null && this.name == null && this.url == null
|
||||
&& this.layout == null && this.releases.isEmpty() && this.snapshots.isEmpty();
|
||||
}
|
||||
|
||||
public Boolean getUniqueVersion() {
|
||||
return Optional.ofNullable(this.uniqueVersion).orElse(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public RepositoryPolicy getReleases() {
|
||||
return this.releases;
|
||||
}
|
||||
|
||||
public RepositoryPolicy getSnapshots() {
|
||||
return this.snapshots;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public String getLayout() {
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class RepositoryPolicy {
|
||||
|
||||
private final Boolean enabled;
|
||||
|
||||
private final String updatePolicy;
|
||||
|
||||
private final String checksumPolicy;
|
||||
|
||||
protected RepositoryPolicy(RepositoryPolicyBuilder builder) {
|
||||
this.enabled = builder.enabled;
|
||||
this.updatePolicy = builder.updatePolicy;
|
||||
this.checksumPolicy = builder.checksumPolicy;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.enabled == null && this.updatePolicy == null && this.checksumPolicy == null;
|
||||
}
|
||||
|
||||
public Boolean isEnabled() {
|
||||
return Optional.ofNullable(this.enabled).orElse(Boolean.TRUE);
|
||||
}
|
||||
|
||||
public String getUpdatePolicy() {
|
||||
return this.updatePolicy;
|
||||
}
|
||||
|
||||
public String getChecksumPolicy() {
|
||||
return this.checksumPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Site {
|
||||
|
||||
private final String id;
|
||||
|
||||
private final String url;
|
||||
|
||||
private final String name;
|
||||
|
||||
private final Boolean childSiteUrlInheritAppendPath;
|
||||
|
||||
public Site(SiteBuilder builder) {
|
||||
this.id = builder.id;
|
||||
this.url = builder.url;
|
||||
this.name = builder.name;
|
||||
this.childSiteUrlInheritAppendPath = builder.childSiteUrlInheritAppendPath;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.id == null && this.url == null && this.name == null;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Boolean getChildSiteUrlInheritAppendPath() {
|
||||
return this.childSiteUrlInheritAppendPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Relocation {
|
||||
|
||||
private final String groupId;
|
||||
|
||||
private final String artifactId;
|
||||
|
||||
private final String version;
|
||||
|
||||
private final String message;
|
||||
|
||||
public Relocation(RelocationBuilder builder) {
|
||||
this.groupId = builder.groupId;
|
||||
this.artifactId = builder.artifactId;
|
||||
this.version = builder.version;
|
||||
this.message = builder.message;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.groupId == null && this.artifactId == null && this.version == null && this.message == null;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return this.artifactId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Stephane Nicoll
|
||||
* @author Olga Maciaszek-Sharma
|
||||
* @author Jafer Khan Shamshad
|
||||
* @author Joachim Pasquali
|
||||
*/
|
||||
class MavenBuildWriterTests {
|
||||
|
||||
@@ -657,6 +658,78 @@ class MavenBuildWriterTests {
|
||||
generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/version").isEqualTo("1.2.4.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithDistributionManagement() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
|
||||
build.distributionManagement().downloadUrl("downloadUrl")
|
||||
.relocation((relocation) -> relocation.groupId("groupId").artifactId("my.artifact").version("version")
|
||||
.message("message"))
|
||||
.repository((repository) -> repository.id("id").layout("layout").name("name")
|
||||
.releases((releases) -> releases.checksumPolicy("checksumPolicy").updatePolicy("updatePolicy"))
|
||||
.snapshots(
|
||||
(snapshots) -> snapshots.checksumPolicy("checksumPolicy").updatePolicy("updatePolicy"))
|
||||
.url("url"))
|
||||
.site((site) -> site.id("id").name("name").url("url").childSiteUrlInheritAppendPath(Boolean.TRUE))
|
||||
.snapshotRepository((snapshotRepository) -> snapshotRepository.id("id").layout("layout").name("name")
|
||||
.releases((releases) -> releases.checksumPolicy("checksumPolicy").updatePolicy("updatePolicy"))
|
||||
.snapshots(
|
||||
(snapshots) -> snapshots.checksumPolicy("checksumPolicy").updatePolicy("updatePolicy"))
|
||||
.url("url"));
|
||||
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/downloadUrl").isEqualTo("downloadUrl");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/relocation/groupId").isEqualTo("groupId");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/relocation/artifactId")
|
||||
.isEqualTo("my.artifact");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/relocation/version").isEqualTo("version");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/relocation/message").isEqualTo("message");
|
||||
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/id").isEqualTo("id");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/layout").isEqualTo("layout");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/name").isEqualTo("name");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/url").isEqualTo("url");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/releases/checksumPolicy")
|
||||
.isEqualTo("checksumPolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/releases/updatePolicy")
|
||||
.isEqualTo("updatePolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/snapshots/checksumPolicy")
|
||||
.isEqualTo("checksumPolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/repository/snapshots/updatePolicy")
|
||||
.isEqualTo("updatePolicy");
|
||||
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/id").isEqualTo("id");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/layout").isEqualTo("layout");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/name").isEqualTo("name");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/url").isEqualTo("url");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/releases/checksumPolicy")
|
||||
.isEqualTo("checksumPolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/releases/updatePolicy")
|
||||
.isEqualTo("updatePolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/snapshots/checksumPolicy")
|
||||
.isEqualTo("checksumPolicy");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/snapshotRepository/snapshots/updatePolicy")
|
||||
.isEqualTo("updatePolicy");
|
||||
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/site/id").isEqualTo("id");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/site/name").isEqualTo("name");
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/site/url").isEqualTo("url");
|
||||
assertThat(pom).nodeAtPath("/project/distributionManagement/site").matches((node) -> node.getAttributes()
|
||||
.getNamedItem("child.site.url.inherit.append.path").getTextContent().equals("true"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithDistributionManagementWithNullAttributeValue() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.distributionManagement().site((site) -> site.id("id").childSiteUrlInheritAppendPath(null));
|
||||
generatePom(build, (pom) -> {
|
||||
assertThat(pom).textAtPath("/project/distributionManagement/site/id").isEqualTo("id");
|
||||
assertThat(pom).nodeAtPath("/project/distributionManagement/site")
|
||||
.matches((node) -> node.getAttributes().getNamedItem("child.site.url.inherit.append.path") == null);
|
||||
});
|
||||
}
|
||||
|
||||
private void generatePom(MavenBuild mavenBuild, Consumer<NodeAssert> consumer) {
|
||||
MavenBuildWriter writer = new MavenBuildWriter();
|
||||
StringWriter out = new StringWriter();
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.buildsystem.maven;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link MavenDistributionManagement}
|
||||
*
|
||||
* @author Joachim Pasquali
|
||||
*/
|
||||
class MavenDistributionManagementTests {
|
||||
|
||||
private static final String TEST_URL = "testURL";
|
||||
|
||||
@Test
|
||||
void emptyDistributionManagement() {
|
||||
MavenDistributionManagement result = builder().build();
|
||||
assertThat(result.isEmpty()).isTrue();
|
||||
assertThat(result.getRelocation().isEmpty()).isTrue();
|
||||
assertThat(result.getRepository().isEmpty()).isTrue();
|
||||
assertThat(result.getSite().isEmpty()).isTrue();
|
||||
assertThat(result.getSnapshotRepository().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void addDownloadUrl() {
|
||||
MavenDistributionManagement result = builder().downloadUrl(TEST_URL).build();
|
||||
assertThat(result.getDownloadUrl()).isEqualTo(TEST_URL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void addRelocation() {
|
||||
MavenDistributionManagement result = builder().relocation((relocation) -> relocation.artifactId("artifactId")
|
||||
.groupId("groupId").version("version").message("message")).build();
|
||||
assertThat(result.getRelocation().getArtifactId()).isEqualTo("artifactId");
|
||||
assertThat(result.getRelocation().getGroupId()).isEqualTo("groupId");
|
||||
assertThat(result.getRelocation().getVersion()).isEqualTo("version");
|
||||
assertThat(result.getRelocation().getMessage()).isEqualTo("message");
|
||||
}
|
||||
|
||||
@Test
|
||||
void addRepository() {
|
||||
MavenDistributionManagement result = builder().repository((repository) -> repository.id("id").layout("layout")
|
||||
.name("name")
|
||||
.releases((releases) -> releases.checksumPolicy("checksumPolicy").enabled(Boolean.FALSE)
|
||||
.updatePolicy("updatePolicy"))
|
||||
.snapshots((snapshots) -> snapshots.checksumPolicy("checksumPolicy").updatePolicy("updatePolicy"))
|
||||
.uniqueVersion(Boolean.FALSE).url("url")).build();
|
||||
assertThat(result.getRepository().getId()).isEqualTo("id");
|
||||
assertThat(result.getRepository().getUrl()).isEqualTo("url");
|
||||
assertThat(result.getRepository().getUniqueVersion()).isFalse();
|
||||
assertThat(result.getRepository().getLayout()).isEqualTo("layout");
|
||||
assertThat(result.getRepository().getName()).isEqualTo("name");
|
||||
assertThat(result.getRepository().getReleases().isEnabled()).isFalse();
|
||||
assertThat(result.getRepository().getReleases().getChecksumPolicy()).isEqualTo("checksumPolicy");
|
||||
assertThat(result.getRepository().getReleases().getUpdatePolicy()).isEqualTo("updatePolicy");
|
||||
|
||||
assertThat(result.getRepository().getSnapshots().getChecksumPolicy()).isEqualTo("checksumPolicy");
|
||||
assertThat(result.getRepository().getSnapshots().getUpdatePolicy()).isEqualTo("updatePolicy");
|
||||
assertThat(result.getRepository().getSnapshots().isEnabled()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void addSnapshotRepository() {
|
||||
MavenDistributionManagement result = builder().snapshotRepository((repository) -> repository.id("id")
|
||||
.layout("layout").name("name").releases((releases) -> releases.checksumPolicy("checksumPolicy")
|
||||
.enabled(Boolean.TRUE).updatePolicy("updatePolicy"))
|
||||
.uniqueVersion(Boolean.FALSE).url("url")).build();
|
||||
assertThat(result.getSnapshotRepository().getId()).isEqualTo("id");
|
||||
assertThat(result.getSnapshotRepository().getLayout()).isEqualTo("layout");
|
||||
assertThat(result.getSnapshotRepository().getName()).isEqualTo("name");
|
||||
assertThat(result.getSnapshotRepository().getReleases().getChecksumPolicy()).isEqualTo("checksumPolicy");
|
||||
assertThat(result.getSnapshotRepository().getReleases().getUpdatePolicy()).isEqualTo("updatePolicy");
|
||||
|
||||
assertThat(result.getSnapshotRepository().getSnapshots().isEmpty()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void addSite() {
|
||||
MavenDistributionManagement result = builder()
|
||||
.site((site) -> site.id("id").name("name").url("url").childSiteUrlInheritAppendPath(Boolean.FALSE))
|
||||
.build();
|
||||
assertThat(result.getSite().getId()).isEqualTo("id");
|
||||
assertThat(result.getSite().getName()).isEqualTo("name");
|
||||
assertThat(result.getSite().getUrl()).isEqualTo("url");
|
||||
assertThat(result.getSite().getChildSiteUrlInheritAppendPath()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void addSiteWithNullAttribute() {
|
||||
MavenDistributionManagement result = builder().site((site) -> site.id("id")).build();
|
||||
assertThat(result.getSite().getChildSiteUrlInheritAppendPath()).isNull();
|
||||
}
|
||||
|
||||
private MavenDistributionManagement.Builder builder() {
|
||||
return new MavenDistributionManagement.Builder();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user