From 963ac5ab299f9f4e948144f553776896053ab715 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 16 Feb 2024 13:38:52 +0100 Subject: [PATCH] Polishing. Validate deployment properties. See #75 --- .../deployment/DeploymentProperties.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/release/deployment/DeploymentProperties.java b/src/main/java/org/springframework/data/release/deployment/DeploymentProperties.java index 1f3a9e5..eb29927 100644 --- a/src/main/java/org/springframework/data/release/deployment/DeploymentProperties.java +++ b/src/main/java/org/springframework/data/release/deployment/DeploymentProperties.java @@ -19,6 +19,7 @@ import lombok.Data; import java.net.URI; +import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.data.release.model.Gpg; import org.springframework.data.release.model.Password; @@ -36,7 +37,7 @@ import org.springframework.web.util.UriTemplate; @Data @Component @ConfigurationProperties(prefix = "deployment") -public class DeploymentProperties { +public class DeploymentProperties implements InitializingBean { private String settingsXml; private MavenCentral mavenCentral; @@ -50,6 +51,18 @@ public class DeploymentProperties { return Streamable.of(opensource, commercial); } + @Override + public void afterPropertiesSet() { + + Assert.notNull(mavenCentral, "Maven Central properties not provided"); + Assert.notNull(opensource, "OSS authentication properties not provided"); + Assert.notNull(commercial, "Commercial authentication properties not provided"); + + mavenCentral.validate(); + opensource.validate(); + commercial.validate(); + } + @Data public static class Server { @@ -93,6 +106,13 @@ public class DeploymentProperties { public boolean hasGpgConfiguration() { return gpg != null && gpg.isGpgAvailable(); } + + public void validate() { + + if (!StringUtils.hasText(stagingProfileId)) { + throw new IllegalArgumentException("No staging profile Id for Maven Central"); + } + } } @Data @@ -111,6 +131,34 @@ public class DeploymentProperties { return StringUtils.hasText(username) && password != null; } + public void validate() { + + if (!StringUtils.hasText(stagingRepository)) { + throw new IllegalArgumentException( + String.format("No staging repository for server authentication %s provided", server)); + } + + if (!StringUtils.hasText(targetRepository)) { + throw new IllegalArgumentException( + String.format("No target repository for server authentication %s provided", server)); + } + + if (!StringUtils.hasText(distributionRepository)) { + throw new IllegalArgumentException( + String.format("No distribution repository for server authentication %s provided", server)); + } + + if (!StringUtils.hasText(server.uri)) { + throw new IllegalArgumentException( + String.format("No server URI for server authentication %s provided", server)); + } + + if (!StringUtils.hasText(server.verificationResource)) { + throw new IllegalArgumentException( + String.format("No verification resource for server authentication %s provided", server)); + } + } + /** * Returns the URI of the staging repository. *