From 8282a901a98d4e24a966c04f29b073807ea38334 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 6 Apr 2016 13:42:56 +0200 Subject: [PATCH] #20 - Turned DeploymentInformation into an interface. --- .../data/release/build/GradleBuildSystem.java | 3 +- .../data/release/build/MavenBuildSystem.java | 3 +- .../release/deployment/ArtifactoryClient.java | 4 +- .../DefaultDeploymentInformation.java | 96 +++++++++++++++++++ .../deployment/DeploymentInformation.java | 73 +++++--------- ...DeploymentInformationIntegrationTests.java | 4 +- 6 files changed, 127 insertions(+), 56 deletions(-) create mode 100644 src/main/java/org/springframework/data/release/deployment/DefaultDeploymentInformation.java diff --git a/src/main/java/org/springframework/data/release/build/GradleBuildSystem.java b/src/main/java/org/springframework/data/release/build/GradleBuildSystem.java index 19acb64..928e971 100644 --- a/src/main/java/org/springframework/data/release/build/GradleBuildSystem.java +++ b/src/main/java/org/springframework/data/release/build/GradleBuildSystem.java @@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; +import org.springframework.data.release.deployment.DefaultDeploymentInformation; import org.springframework.data.release.deployment.DeploymentInformation; import org.springframework.data.release.deployment.DeploymentProperties; import org.springframework.data.release.io.Workspace; @@ -146,7 +147,7 @@ class GradleBuildSystem implements BuildSystem { */ @Override public DeploymentInformation deploy(ModuleIteration module) { - return new DeploymentInformation(module, properties); + return new DefaultDeploymentInformation(module, properties); } /* diff --git a/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java b/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java index 462f66f..4d00197 100644 --- a/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java +++ b/src/main/java/org/springframework/data/release/build/MavenBuildSystem.java @@ -26,6 +26,7 @@ import java.util.function.Consumer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.annotation.Order; +import org.springframework.data.release.deployment.DefaultDeploymentInformation; import org.springframework.data.release.deployment.DeploymentInformation; import org.springframework.data.release.deployment.DeploymentProperties; import org.springframework.data.release.deployment.DeploymentProperties.Gpg; @@ -242,7 +243,7 @@ class MavenBuildSystem implements BuildSystem { Assert.notNull(module, "Module must not be null!"); - DeploymentInformation information = new DeploymentInformation(module, properties); + DeploymentInformation information = new DefaultDeploymentInformation(module, properties); deployToArtifactory(module, information); deployToMavenCentral(module); diff --git a/src/main/java/org/springframework/data/release/deployment/ArtifactoryClient.java b/src/main/java/org/springframework/data/release/deployment/ArtifactoryClient.java index 0b26e90..fe7d449 100644 --- a/src/main/java/org/springframework/data/release/deployment/ArtifactoryClient.java +++ b/src/main/java/org/springframework/data/release/deployment/ArtifactoryClient.java @@ -80,7 +80,7 @@ class ArtifactoryClient { } } - private void handle(String log, HttpClientErrorException o_O, ModuleIteration module) { + void handle(String log, HttpClientErrorException o_O, ModuleIteration module) { try { @@ -115,7 +115,7 @@ class ArtifactoryClient { } @Value - private static class PromotionRequest { + static class PromotionRequest { String targetRepo; } } diff --git a/src/main/java/org/springframework/data/release/deployment/DefaultDeploymentInformation.java b/src/main/java/org/springframework/data/release/deployment/DefaultDeploymentInformation.java new file mode 100644 index 0000000..c9fdb10 --- /dev/null +++ b/src/main/java/org/springframework/data/release/deployment/DefaultDeploymentInformation.java @@ -0,0 +1,96 @@ +/* + * Copyright 2015-2016 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 + * + * http://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 org.springframework.data.release.deployment; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.HashMap; +import java.util.Map; + +import org.springframework.data.release.model.ModuleIteration; +import org.springframework.web.util.UriTemplate; + +/** + * Information about a deployment. + * + * @author Oliver Gierke + */ +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +public class DefaultDeploymentInformation implements DeploymentInformation { + + private static UriTemplate REPOSITORY_TEMPLATE = new UriTemplate( + "artifactory::default::{server};build.number={buildNumber};build.name={buildName}"); + + private final @Getter @NonNull ModuleIteration module; + private final @NonNull DeploymentProperties properties; + private final @Getter String buildNumber; + + public DefaultDeploymentInformation(ModuleIteration module, DeploymentProperties properties) { + this(module, properties, String.valueOf(LocalDateTime.now().toEpochSecond(ZoneOffset.UTC))); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.release.deployment.DeploymentInformation#getBuildName() + */ + @Override + public String getBuildName() { + return module.getProject().getFullName().concat(" - Release"); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.release.deployment.DeploymentInformation#getTargetRepository() + */ + @Override + public String getTargetRepository() { + return properties.getRepositoryPrefix() + .concat(module.getIteration().isPublic() ? "libs-release-local" : "libs-milestone-local"); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.release.deployment.DeploymentInformation#getDeploymentTargetUrl() + */ + @Override + public String getDeploymentTargetUrl() { + + Map parameters = new HashMap<>(); + parameters.put("server", properties.getStagingRepositoryUrl()); + parameters.putAll(getBuildInfoParameters()); + + return REPOSITORY_TEMPLATE.expand(parameters).toString(); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.release.deployment.DeploymentInformation#getBuildInfoParameters() + */ + @Override + public Map getBuildInfoParameters() { + + Map parameters = new HashMap<>(); + parameters.put("buildNumber", getBuildNumber()); + parameters.put("buildName", getBuildName()); + + return parameters; + } +} diff --git a/src/main/java/org/springframework/data/release/deployment/DeploymentInformation.java b/src/main/java/org/springframework/data/release/deployment/DeploymentInformation.java index 4d0d380..5bf28e2 100644 --- a/src/main/java/org/springframework/data/release/deployment/DeploymentInformation.java +++ b/src/main/java/org/springframework/data/release/deployment/DeploymentInformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2016 the original author or authors. + * Copyright 2016 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. @@ -15,81 +15,54 @@ */ package org.springframework.data.release.deployment; -import lombok.Getter; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; - -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.util.HashMap; import java.util.Map; import org.springframework.data.release.model.ModuleIteration; -import org.springframework.web.util.UriTemplate; /** - * Information about a deployment. - * * @author Oliver Gierke */ -@RequiredArgsConstructor -public class DeploymentInformation { - - private static UriTemplate REPOSITORY_TEMPLATE = new UriTemplate( - "artifactory::default::{server};build.number={buildNumber};build.name={buildName}"); - - private final @Getter @NonNull ModuleIteration module; - private final @NonNull DeploymentProperties properties; - - /** - * Returns a unique build number for this particular deployment. - */ - private final @Getter String buildNumber = String.valueOf(LocalDateTime.now().toEpochSecond(ZoneOffset.UTC)); +public interface DeploymentInformation { /** * Returns the name of the build. * - * @return + * @return will never be {@literal null} or empty. */ - public String getBuildName() { - return module.getProject().getFullName().concat(" - Release"); - } + String getBuildName(); /** - * Returns the name of the repository to deploy to. + * Returns a unique build number for this particular deployment. * - * @return + * @return will never be {@literal null} or empty. */ - public String getTargetRepository() { - return properties.getRepositoryPrefix() - .concat(module.getIteration().isPublic() ? "libs-release-local" : "libs-milestone-local"); - } + String getBuildNumber(); /** * Returns the full URL to be used as deployment target. * + * @return will never be {@literal null} or empty. + */ + String getDeploymentTargetUrl(); + + /** + * Returns the name of the repository to deploy to. + * + * @return will never be {@literal null} or empty. + */ + String getTargetRepository(); + + /** + * Returns the {@link ModuleIteration} the deployment information was created for. + * * @return */ - public String getDeploymentTargetUrl() { - - Map parameters = new HashMap<>(); - parameters.put("server", properties.getStagingRepositoryUrl()); - parameters.putAll(getBuildInfoParameters()); - - return REPOSITORY_TEMPLATE.expand(parameters).toString(); - } + ModuleIteration getModule(); /** * Returns a {@link Map} to expand a URI template to access the build information. * * @return */ - public Map getBuildInfoParameters() { - - Map parameters = new HashMap<>(); - parameters.put("buildNumber", buildNumber); - parameters.put("buildName", getBuildName()); - - return parameters; - } + Map getBuildInfoParameters(); } diff --git a/src/test/java/org/springframework/data/release/deployment/DeploymentInformationIntegrationTests.java b/src/test/java/org/springframework/data/release/deployment/DeploymentInformationIntegrationTests.java index 18e3d3a..92b2d00 100644 --- a/src/test/java/org/springframework/data/release/deployment/DeploymentInformationIntegrationTests.java +++ b/src/test/java/org/springframework/data/release/deployment/DeploymentInformationIntegrationTests.java @@ -28,7 +28,7 @@ import org.springframework.data.release.model.ReleaseTrains; import org.springframework.data.release.model.TrainIteration; /** - * Integration test for {@link DeploymentInformation}. + * Integration test for {@link DefaultDeploymentInformation}. * * @author Oliver Gierke */ @@ -42,7 +42,7 @@ public class DeploymentInformationIntegrationTests extends AbstractIntegrationTe TrainIteration iteration = new TrainIteration(ReleaseTrains.HOPPER, Iteration.M1); ModuleIteration buildModule = iteration.getModule(Projects.BUILD); - DeploymentInformation information = new DeploymentInformation(buildModule, properties); + DeploymentInformation information = new DefaultDeploymentInformation(buildModule, properties); assertThat(information.getDeploymentTargetUrl(), containsString(properties.getServer().getUri().toString())); assertThat(information.getBuildName(), is("Spring Data Build - Release"));