From aadd5baaf00f13df57c9b9bbb5bd809cf13d6f72 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 3 Feb 2020 16:32:39 +0100 Subject: [PATCH] Uses releaser properties of a given project for certain tasks --- .../main/java/releaser/internal/Releaser.java | 26 ++-- .../internal/ReleaserPropertiesAware.java | 26 ---- .../internal}/ReleaserPropertiesUpdater.java | 41 +++--- .../internal/buildsystem/GradleUpdater.java | 10 +- .../buildsystem/ProjectPomUpdater.java | 10 +- .../internal/docs/DocumentationUpdater.java | 21 +-- .../docs/ProjectDocumentationUpdater.java | 10 +- .../docs/ReleaseTrainContentsUpdater.java | 10 +- .../internal/git/ProjectGitHandler.java | 10 +- .../internal/github/ProjectGitHubHandler.java | 10 +- .../postrelease/PostReleaseActions.java | 24 +++- .../project/ProjectCommandExecutor.java | 110 +++++++-------- .../internal/project/ProjectVersion.java | 4 +- .../internal/template/TemplateGenerator.java | 10 +- .../internal/versions/VersionsFetcher.java | 10 +- .../postrelease/PostReleaseActionsTests.java | 63 +++++---- .../project/ProjectCommandExecutorTests.java | 88 +++++++----- .../internal/spring/ProjectsToRunFactory.java | 1 + .../spring/ReleaserConfiguration.java | 15 +- .../release/BuildProjectReleaseTask.java | 3 +- .../release/DeployArtifactsReleaseTask.java | 3 +- .../tasks/release/PublishDocsReleaseTask.java | 3 +- .../docs/TestDocumentationUpdater.java | 2 +- .../ReleaserPropertiesIntegrationTests.java | 133 ------------------ .../ReleaserPropertiesUpdaterTests.java | 32 +---- .../docs/TestDocumentationUpdater.java | 35 ----- .../docs/TestReleaseContentsUpdater.java | 0 .../{ => internal}/git/GitTestUtils.java | 0 28 files changed, 221 insertions(+), 489 deletions(-) delete mode 100644 releaser-core/src/main/java/releaser/internal/ReleaserPropertiesAware.java rename {releaser-spring/src/main/java/releaser/internal/spring => releaser-core/src/main/java/releaser/internal}/ReleaserPropertiesUpdater.java (84%) delete mode 100644 releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesIntegrationTests.java delete mode 100644 releaser-test/src/main/java/releaser/docs/TestDocumentationUpdater.java rename releaser-test/src/main/java/releaser/{ => internal}/docs/TestReleaseContentsUpdater.java (100%) rename releaser-test/src/main/java/releaser/{ => internal}/git/GitTestUtils.java (100%) diff --git a/releaser-core/src/main/java/releaser/internal/Releaser.java b/releaser-core/src/main/java/releaser/internal/Releaser.java index 1a1b546b..0c151989 100644 --- a/releaser-core/src/main/java/releaser/internal/Releaser.java +++ b/releaser-core/src/main/java/releaser/internal/Releaser.java @@ -41,7 +41,7 @@ import org.springframework.util.Assert; /** * @author Marcin Grzejszczak */ -public class Releaser implements ReleaserPropertiesAware { +public class Releaser { private static final Logger log = LoggerFactory.getLogger(Releaser.class); @@ -118,9 +118,9 @@ public class Releaser implements ReleaserPropertiesAware { return ExecutionResult.success(); } - public ExecutionResult buildProject(ProjectVersion originalVersion, - ProjectVersion versionFromBom) { - this.projectCommandExecutor.build(originalVersion, versionFromBom); + public ExecutionResult buildProject(ReleaserProperties properties, + ProjectVersion originalVersion, ProjectVersion versionFromBom) { + this.projectCommandExecutor.build(properties, originalVersion, versionFromBom); log.info("\nProject was successfully built"); return ExecutionResult.success(); } @@ -132,16 +132,17 @@ public class Releaser implements ReleaserPropertiesAware { return ExecutionResult.success(); } - public ExecutionResult deploy(ProjectVersion originalVersion, - ProjectVersion versionFromBom) { - this.projectCommandExecutor.deploy(originalVersion, versionFromBom); + public ExecutionResult deploy(ReleaserProperties properties, + ProjectVersion originalVersion, ProjectVersion versionFromBom) { + this.projectCommandExecutor.deploy(properties, originalVersion, versionFromBom); log.info("\nThe artifact was deployed successfully"); return ExecutionResult.success(); } - public ExecutionResult publishDocs(ProjectVersion originalVersion, - ProjectVersion changedVersion) { - this.projectCommandExecutor.publishDocs(originalVersion, changedVersion); + public ExecutionResult publishDocs(ReleaserProperties properties, + ProjectVersion originalVersion, ProjectVersion changedVersion) { + this.projectCommandExecutor.publishDocs(properties, originalVersion, + changedVersion); log.info("\nThe docs were published successfully"); return ExecutionResult.success(); } @@ -439,9 +440,4 @@ public class Releaser implements ReleaserPropertiesAware { return ExecutionResult.skipped(); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.releaserProperties = properties; - } - } diff --git a/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesAware.java b/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesAware.java deleted file mode 100644 index 6ca08283..00000000 --- a/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesAware.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013-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 releaser.internal; - -/** - * @author Marcin Grzejszczak - */ -public interface ReleaserPropertiesAware { - - void setReleaserProperties(ReleaserProperties properties); - -} diff --git a/releaser-spring/src/main/java/releaser/internal/spring/ReleaserPropertiesUpdater.java b/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java similarity index 84% rename from releaser-spring/src/main/java/releaser/internal/spring/ReleaserPropertiesUpdater.java rename to releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java index 4ccaff5f..b626b58a 100644 --- a/releaser-spring/src/main/java/releaser/internal/spring/ReleaserPropertiesUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java @@ -14,56 +14,46 @@ * limitations under the License. */ -package releaser.internal.spring; +package releaser.internal; +import java.io.Closeable; import java.io.File; +import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.MapConfigurationPropertySource; -import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.util.StringUtils; /** * @author Marcin Grzejszczak */ -class ReleaserPropertiesUpdater { +public class ReleaserPropertiesUpdater implements Closeable { private static final Logger log = LoggerFactory .getLogger(ReleaserPropertiesUpdater.class); - private final ApplicationContext context; + private static final Map CACHE = new ConcurrentHashMap<>(); - ReleaserPropertiesUpdater(ApplicationContext context) { - this.context = context; - } - - ReleaserProperties updateProperties(ReleaserProperties properties, + public ReleaserProperties updateProperties(ReleaserProperties properties, File clonedProjectFromOrg) { - ReleaserProperties props = updatePropertiesFromFile(properties, - clonedProjectFromOrg); - props.setWorkingDir(clonedProjectFromOrg.getAbsolutePath()); - log.trace("Updated properties [\n\n{}\n\n]", props); - updateProperties(props); - return props; - } - - void updateProperties(ReleaserProperties props) { - Map beans = this.context - .getBeansOfType(ReleaserPropertiesAware.class); - beans.values().forEach(aware -> aware.setReleaserProperties(props)); + return CACHE.computeIfAbsent(clonedProjectFromOrg, file -> { + ReleaserProperties props = updatePropertiesFromFile(properties.copy(), file); + props.setWorkingDir(clonedProjectFromOrg.getAbsolutePath()); + log.trace("Updated properties [\n\n{}\n\n]", props); + return props; + }); } private ReleaserProperties updatePropertiesFromFile(ReleaserProperties copy, @@ -160,4 +150,9 @@ class ReleaserPropertiesUpdater { return new File(clonedProjectFromOrg, "config/releaser.yml"); } + @Override + public void close() throws IOException { + CACHE.clear(); + } + } diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java index 94c2f061..de4c3f39 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java @@ -35,18 +35,17 @@ import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; /** * @author Marcin Grzejszczak */ -public class GradleUpdater implements ReleaserPropertiesAware { +public class GradleUpdater { private static final Logger log = LoggerFactory.getLogger(GradleUpdater.class); - private ReleaserProperties properties; + private final ReleaserProperties properties; public GradleUpdater(ReleaserProperties properties) { this.properties = properties; @@ -78,11 +77,6 @@ public class GradleUpdater implements ReleaserPropertiesAware { } } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - private final class GradlePropertiesWalker extends SimpleFileVisitor { private static final String GRADLE_PROPERTIES = "gradle.properties"; diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java b/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java index 17950b2c..743efc77 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java @@ -36,7 +36,6 @@ import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.git.ProjectGitHandler; import releaser.internal.project.Project; import releaser.internal.project.ProjectVersion; @@ -45,7 +44,7 @@ import releaser.internal.project.Projects; /** * @author Marcin Grzejszczak */ -public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable { +public class ProjectPomUpdater implements Closeable { private static final List IGNORED_SNAPSHOT_LINE_PATTERNS = Arrays.asList( "^.*replace=.*$", @@ -64,7 +63,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable { private final List bomParsers; - private ReleaserProperties properties; + private final ReleaserProperties properties; public ProjectPomUpdater(ReleaserProperties properties, List bomParsers) { this.properties = properties; @@ -173,11 +172,6 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable { } } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - @Override public void close() throws IOException { CACHE.clear(); diff --git a/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java b/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java index 115eeb80..34db77ef 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java @@ -20,7 +20,6 @@ import java.io.File; import java.util.List; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.git.ProjectGitHandler; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; @@ -29,28 +28,23 @@ import releaser.internal.template.TemplateGenerator; /** * @author Marcin Grzejszczak */ -public class DocumentationUpdater implements ReleaserPropertiesAware { +public class DocumentationUpdater { private final ProjectDocumentationUpdater projectDocumentationUpdater; private final ReleaseTrainContentsUpdater releaseTrainContentsUpdater; - private ReleaserProperties properties; - public DocumentationUpdater(ProjectGitHandler gitHandler, ReleaserProperties properties, TemplateGenerator templateGenerator, List updaters) { - this.properties = properties; this.projectDocumentationUpdater = new ProjectDocumentationUpdater(properties, gitHandler, updaters); - this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater( - this.properties, gitHandler, templateGenerator); + this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(properties, + gitHandler, templateGenerator); } - DocumentationUpdater(ReleaserProperties properties, - ProjectDocumentationUpdater updater, + DocumentationUpdater(ProjectDocumentationUpdater updater, ReleaseTrainContentsUpdater contentsUpdater) { - this.properties = properties; this.projectDocumentationUpdater = updater; this.releaseTrainContentsUpdater = contentsUpdater; } @@ -94,11 +88,4 @@ public class DocumentationUpdater implements ReleaserPropertiesAware { return this.releaseTrainContentsUpdater.updateReleaseTrainWiki(projects); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - this.releaseTrainContentsUpdater.setReleaserProperties(properties); - this.projectDocumentationUpdater.setReleaserProperties(properties); - } - } diff --git a/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java b/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java index b5d921c8..81252de4 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java @@ -22,7 +22,6 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.git.ProjectGitHandler; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; @@ -30,7 +29,7 @@ import releaser.internal.project.Projects; /** * @author Marcin Grzejszczak */ -class ProjectDocumentationUpdater implements ReleaserPropertiesAware { +class ProjectDocumentationUpdater { private static final Logger log = LoggerFactory .getLogger(ProjectDocumentationUpdater.class); @@ -39,7 +38,7 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware { private final List updaters; - private ReleaserProperties properties; + private final ReleaserProperties properties; ProjectDocumentationUpdater(ReleaserProperties properties, ProjectGitHandler gitHandler, @@ -91,9 +90,4 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware { return true; } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - } diff --git a/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java b/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java index 10d81c5a..f7bdd3aa 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java @@ -26,7 +26,6 @@ import java.util.StringJoiner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.git.ProjectGitHandler; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; @@ -38,7 +37,7 @@ import org.springframework.util.StringUtils; * @author Marcin Grzejszczak */ // TODO: [SPRING-CLOUD] -class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware { +class ReleaseTrainContentsUpdater { private static final Logger log = LoggerFactory .getLogger(ReleaseTrainContentsUpdater.class); @@ -49,7 +48,7 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware { private final TemplateGenerator templateGenerator; - private ReleaserProperties properties; + private final ReleaserProperties properties; ReleaseTrainContentsUpdater(ReleaserProperties properties, ProjectGitHandler handler, TemplateGenerator templateGenerator) { @@ -166,11 +165,6 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware { return releaseTrainDocFile; } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - } class ReleaseTrainContentsGitHandler { diff --git a/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java b/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java index 51540fbf..e0f02955 100644 --- a/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java +++ b/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java @@ -30,7 +30,6 @@ import org.eclipse.jgit.transport.URIish; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.project.ProjectVersion; import releaser.internal.tech.TemporaryFileStorage; @@ -41,7 +40,7 @@ import org.springframework.util.StringUtils; * * @author Marcin Grzejszczak */ -public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable { +public class ProjectGitHandler implements Closeable { private static final Map CACHE = new ConcurrentHashMap<>(); @@ -55,7 +54,7 @@ public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable { private static final String POST_RELEASE_BUMP_MSG = "Bumping versions to %s after release"; - private ReleaserProperties properties; + private final ReleaserProperties properties; public ProjectGitHandler(ReleaserProperties properties) { this.properties = properties; @@ -314,11 +313,6 @@ public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable { return new GitRepo(workingDir, this.properties); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - @Override public void close() { CACHE.clear(); diff --git a/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java b/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java index c4d90409..9d146165 100644 --- a/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java +++ b/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java @@ -21,7 +21,6 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; import releaser.internal.tech.TemporaryFileStorage; @@ -31,7 +30,7 @@ import releaser.internal.tech.TemporaryFileStorage; * * @author Marcin Grzejszczak */ -public class ProjectGitHubHandler implements ReleaserPropertiesAware { +public class ProjectGitHubHandler { private static final Logger log = LoggerFactory.getLogger(ProjectGitHubHandler.class); @@ -39,7 +38,7 @@ public class ProjectGitHubHandler implements ReleaserPropertiesAware { private final GithubIssues githubIssues; - private ReleaserProperties properties; + private final ReleaserProperties properties; public ProjectGitHubHandler(ReleaserProperties properties, List customGithubIssues) { @@ -87,9 +86,4 @@ public class ProjectGitHubHandler implements ReleaserPropertiesAware { return this.githubMilestones.milestoneUrl(releaseVersion); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - } diff --git a/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java b/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java index 7f5e2d16..1058b82d 100644 --- a/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java +++ b/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java @@ -31,6 +31,7 @@ import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; +import releaser.internal.ReleaserPropertiesUpdater; import releaser.internal.buildsystem.GradleUpdater; import releaser.internal.buildsystem.ProjectPomUpdater; import releaser.internal.git.ProjectGitHandler; @@ -65,16 +66,20 @@ public class PostReleaseActions implements Closeable { private final VersionsFetcher versionsFetcher; + private final ReleaserPropertiesUpdater releaserPropertiesUpdater; + public PostReleaseActions(ProjectGitHandler projectGitHandler, ProjectPomUpdater projectPomUpdater, GradleUpdater gradleUpdater, ProjectCommandExecutor projectCommandExecutor, ReleaserProperties properties, - VersionsFetcher versionsFetcher) { + VersionsFetcher versionsFetcher, + ReleaserPropertiesUpdater releaserPropertiesUpdater) { this.projectGitHandler = projectGitHandler; this.projectPomUpdater = projectPomUpdater; this.gradleUpdater = gradleUpdater; this.projectCommandExecutor = projectCommandExecutor; this.properties = properties; this.versionsFetcher = versionsFetcher; + this.releaserPropertiesUpdater = releaserPropertiesUpdater; } /** @@ -116,16 +121,21 @@ public class PostReleaseActions implements Closeable { return ExecutionResult.skipped(); } File file = this.projectGitHandler.cloneTestSamplesProject(); + ReleaserProperties projectProps = projectProps(file); ProjectVersion projectVersion = newProjectVersion(file); - String releaseTrainVersion = projects.releaseTrain(this.properties).version; + String releaseTrainVersion = projects.releaseTrain(projectProps).version; Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion); updateWithVersions(file, newProjects); - this.projectCommandExecutor.build(projectVersion, projectVersion, + this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion, file.getAbsolutePath()); return ExecutionResult.success(); } + ReleaserProperties projectProps(File file) { + return this.releaserPropertiesUpdater.updateProperties(this.properties, file); + } + /** * Clones all samples for the given project. For each of them, checks out the proper * branch, updates all the poms with the new, bumped versions of release train @@ -180,6 +190,7 @@ public class PostReleaseActions implements Closeable { .cloneProjectFromOrg(processedProject.projectName()); this.projectGitHandler.checkout(clonedProject, tagName); projectBuilder(processedProject).deployGuides( + processedProject.propertiesForProject, processedProject.originalProjectVersion, processedProject.newProjectVersion); }))) @@ -187,7 +198,7 @@ public class PostReleaseActions implements Closeable { } ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) { - return new ProjectCommandExecutor(processedProject.propertiesForProject); + return new ProjectCommandExecutor(); } private Future> updateAllProjects(Projects projects, @@ -300,13 +311,14 @@ public class PostReleaseActions implements Closeable { return ExecutionResult.skipped(); } File file = this.projectGitHandler.cloneReleaseTrainDocumentationProject(); + ReleaserProperties projectProps = projectProps(file); ProjectVersion projectVersion = newProjectVersion(file); String releaseTrainVersion = projects.releaseTrain(this.properties).version; Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion); updateWithVersions(file, newProjects); - this.projectCommandExecutor.generateReleaseTrainDocs(releaseTrainVersion, - file.getAbsolutePath()); + this.projectCommandExecutor.generateReleaseTrainDocs(projectProps, + releaseTrainVersion, file.getAbsolutePath()); return ExecutionResult.success(); } diff --git a/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java b/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java index 78800984..7602e57b 100644 --- a/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java +++ b/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java @@ -40,14 +40,13 @@ import org.zeroturnaround.exec.ProcessExecutor; import org.zeroturnaround.exec.ProcessResult; import org.zeroturnaround.exec.stream.slf4j.Slf4jStream; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import org.springframework.util.StringUtils; /** * @author Marcin Grzejszczak */ -public class ProjectCommandExecutor implements ReleaserPropertiesAware { +public class ProjectCommandExecutor { private static final Logger log = LoggerFactory .getLogger(ProjectCommandExecutor.class); @@ -58,39 +57,28 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { private static final String NEXT_VERSION_MUSTACHE = "{{nextVersion}}"; - private ReleaserProperties properties; - - public ProjectCommandExecutor(ReleaserProperties properties) { - this.properties = properties; - } - - // If you want to call commands that are not parameterized via the props - public ProjectCommandExecutor() { - this.properties = new ReleaserProperties(); - } - - public void build(ProjectVersion originalVersion, + public void build(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion versionFromReleaseTrain) { - build(originalVersion, versionFromReleaseTrain, this.properties.getWorkingDir()); + build(properties, originalVersion, versionFromReleaseTrain, + properties.getWorkingDir()); } - public String version() { - return executeCommandWithOutput( - new CommandPicker(this.properties, this.properties.getWorkingDir()) - .version()); + public String version(ReleaserProperties properties) { + return executeCommandWithOutput(properties, + new CommandPicker(properties, properties.getWorkingDir()).version()); } - public String groupId() { - return executeCommandWithOutput( - new CommandPicker(this.properties, this.properties.getWorkingDir()) - .groupId()); + public String groupId(ReleaserProperties properties) { + return executeCommandWithOutput(properties, + new CommandPicker(properties, properties.getWorkingDir()).groupId()); } - private String executeCommandWithOutput(String command) { + private String executeCommandWithOutput(ReleaserProperties properties, + String command) { try { - String projectRoot = this.properties.getWorkingDir(); + String projectRoot = properties.getWorkingDir(); String[] commands = command.split(" "); - return captureCommandOutput(projectRoot, commands).trim(); + return captureCommandOutput(properties, projectRoot, commands).trim(); } catch (IllegalStateException e) { throw e; @@ -100,14 +88,14 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { } } - public void build(ProjectVersion originalVersion, + public void build(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion versionFromReleaseTrain, String projectRoot) { try { - String command = new CommandPicker(this.properties, projectRoot) + String command = new CommandPicker(properties, projectRoot) .buildCommand(versionFromReleaseTrain); String[] commands = replaceAllPlaceHolders(originalVersion, versionFromReleaseTrain, command).split(" "); - runCommand(projectRoot, commands); + runCommand(properties, projectRoot, commands); assertNoHtmlFilesInDocsContainUnresolvedTags(projectRoot); log.info("No HTML files from docs contain unresolved tags"); } @@ -116,14 +104,15 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { } } - public void generateReleaseTrainDocs(String version, String projectRoot) { + public void generateReleaseTrainDocs(ReleaserProperties properties, String version, + String projectRoot) { try { String updatedCommand = new CommandPicker(properties, projectRoot) .generateReleaseTrainDocsCommand( new ProjectVersion(new File(projectRoot))) .replace(VERSION_MUSTACHE, version); - runCommand(projectRoot, updatedCommand.split(" ")); - assertNoHtmlFilesInDocsContainUnresolvedTags(this.properties.getWorkingDir()); + runCommand(properties, projectRoot, updatedCommand.split(" ")); + assertNoHtmlFilesInDocsContainUnresolvedTags(properties.getWorkingDir()); log.info("No HTML files from docs contain unresolved tags"); } catch (Exception e) { @@ -144,25 +133,27 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { } } - public void deploy(ProjectVersion originalVersion, ProjectVersion version) { - doDeploy(originalVersion, version, - new CommandPicker(properties, this.properties.getWorkingDir()) + public void deploy(ReleaserProperties properties, ProjectVersion originalVersion, + ProjectVersion version) { + doDeploy(properties, originalVersion, version, + new CommandPicker(properties, properties.getWorkingDir()) .deployCommand(version)); } - public void deployGuides(ProjectVersion originalVersion, ProjectVersion version) { - doDeploy(originalVersion, version, - new CommandPicker(properties, this.properties.getWorkingDir()) + public void deployGuides(ReleaserProperties properties, + ProjectVersion originalVersion, ProjectVersion version) { + doDeploy(properties, originalVersion, version, + new CommandPicker(properties, properties.getWorkingDir()) .deployGuidesCommand(version)); } - private void doDeploy(ProjectVersion originalVersion, ProjectVersion changedVersion, - String command) { + private void doDeploy(ReleaserProperties properties, ProjectVersion originalVersion, + ProjectVersion changedVersion, String command) { try { String replacedCommand = replaceAllPlaceHolders(originalVersion, changedVersion, command); String[] commands = replacedCommand.split(" "); - runCommand(commands); + runCommand(properties, commands); log.info("The project has successfully been deployed"); } catch (Exception e) { @@ -170,19 +161,21 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { } } - private void runCommand(String[] commands) { - runCommand(this.properties.getWorkingDir(), commands); + private void runCommand(ReleaserProperties properties, String[] commands) { + runCommand(properties, properties.getWorkingDir(), commands); } - private void runCommand(String projectRoot, String[] commands) { - String[] substitutedCommands = substituteSystemProps(commands); + private void runCommand(ReleaserProperties properties, String projectRoot, + String[] commands) { + String[] substitutedCommands = substituteSystemProps(properties, commands); long waitTimeInMinutes = new CommandPicker(properties, projectRoot) .waitTimeInMinutes(); executor(projectRoot).runCommand(substitutedCommands, waitTimeInMinutes); } - private String captureCommandOutput(String projectRoot, String[] commands) { - String[] substitutedCommands = substituteSystemProps(commands); + private String captureCommandOutput(ReleaserProperties properties, String projectRoot, + String[] commands) { + String[] substitutedCommands = substituteSystemProps(properties, commands); long waitTimeInMinutes = new CommandPicker(properties, projectRoot) .waitTimeInMinutes(); return executor(projectRoot).runCommandWithOutput(substitutedCommands, @@ -193,14 +186,14 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { return new ReleaserProcessExecutor(workDir); } - public void publishDocs(ProjectVersion originalVersion, + public void publishDocs(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion changedVersion) { try { for (String command : new CommandPicker(properties).publishDocsCommands()) { command = replaceAllPlaceHolders(originalVersion, changedVersion, command); String[] commands = command.split(" "); - runCommand(commands); + runCommand(properties, commands); } log.info("The docs got published successfully"); } @@ -220,9 +213,10 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { * We need to insert the system properties as a list of -Dkey=value entries instead of * just pasting the String that contains these values. */ - private String[] substituteSystemProps(String... commands) { - String systemProperties = new CommandPicker(this.properties).systemProperties(); - String systemPropertiesPlaceholder = new CommandPicker(this.properties) + private String[] substituteSystemProps(ReleaserProperties properties, + String... commands) { + String systemProperties = new CommandPicker(properties).systemProperties(); + String systemPropertiesPlaceholder = new CommandPicker(properties) .systemPropertiesPlaceholder(); boolean containsSystemProps = systemProperties.contains("-D"); String[] splitSystemProps = StringUtils @@ -267,14 +261,9 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware { return commandsList.toArray(new String[commandsList.size()]); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - } -class ReleaserProcessExecutor implements ReleaserPropertiesAware { +class ReleaserProcessExecutor { private static final Logger log = LoggerFactory .getLogger(ReleaserProcessExecutor.class); @@ -345,11 +334,6 @@ class ReleaserProcessExecutor implements ReleaserPropertiesAware { return new String[] { "/bin/bash", "-c", lastArg }; } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.workingDir = properties.getWorkingDir(); - } - } class CommandPicker { diff --git a/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java b/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java index d3195ba9..6edbaf7b 100644 --- a/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java +++ b/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java @@ -96,7 +96,7 @@ public class ProjectVersion implements Comparable, Serializable ProjectVersion projectVersion = gradleProject(buildGradle); this.projectName = projectVersion.projectName; this.version = projectVersion.version; - this.groupId = new ProjectCommandExecutor(properties).groupId(); + this.groupId = new ProjectCommandExecutor().groupId(properties); this.artifactId = projectName; } else { @@ -130,7 +130,7 @@ public class ProjectVersion implements Comparable, Serializable String name = parentFolder.getName(); ReleaserProperties properties = new ReleaserProperties(); properties.setWorkingDir(parentFolder.getAbsolutePath()); - String version = new ProjectCommandExecutor(properties).version(); + String version = new ProjectCommandExecutor().version(properties); return new ProjectVersion(nameWithoutParent(name), version); } diff --git a/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java b/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java index 433b0d96..13b0c38e 100644 --- a/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java @@ -21,7 +21,6 @@ import java.io.IOException; import com.github.jknack.handlebars.Template; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.github.ProjectGitHubHandler; import releaser.internal.project.Projects; import releaser.internal.tech.HandlebarsHelper; @@ -29,7 +28,7 @@ import releaser.internal.tech.HandlebarsHelper; /** * @author Marcin Grzejszczak */ -public class TemplateGenerator implements ReleaserPropertiesAware { +public class TemplateGenerator { private static final String EMAIL_TEMPLATE = "email"; @@ -49,7 +48,7 @@ public class TemplateGenerator implements ReleaserPropertiesAware { private final ProjectGitHubHandler handler; - private ReleaserProperties props; + private final ReleaserProperties props; public TemplateGenerator(ReleaserProperties props, ProjectGitHubHandler handler) { this.props = props; @@ -133,9 +132,4 @@ public class TemplateGenerator implements ReleaserPropertiesAware { template); } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.props = properties; - } - } diff --git a/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java b/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java index 8691b75e..af923d6a 100644 --- a/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java +++ b/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java @@ -34,7 +34,6 @@ import io.spring.initializr.metadata.InitializrProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; import releaser.internal.buildsystem.ProjectPomUpdater; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; @@ -51,7 +50,7 @@ import org.springframework.util.StringUtils; * * @author Marcin Grzejszczak */ -public class VersionsFetcher implements ReleaserPropertiesAware, Closeable { +public class VersionsFetcher implements Closeable { private static final Logger log = LoggerFactory.getLogger(VersionsFetcher.class); @@ -59,7 +58,7 @@ public class VersionsFetcher implements ReleaserPropertiesAware, Closeable { private final ToPropertiesConverter toPropertiesConverter; - private ReleaserProperties properties; + private final ReleaserProperties properties; public VersionsFetcher(ReleaserProperties properties, ProjectPomUpdater projectPomUpdater) { @@ -140,11 +139,6 @@ public class VersionsFetcher implements ReleaserPropertiesAware, Closeable { return springCloudVersion; } - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - @Override public void close() { this.toPropertiesConverter.close(); diff --git a/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java b/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java index 9179f83a..57fe7d49 100644 --- a/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java +++ b/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java @@ -39,6 +39,7 @@ import org.mockito.BDDMockito; import releaser.SpringCloudReleaserProperties; import releaser.internal.PomUpdateAcceptanceTests; import releaser.internal.ReleaserProperties; +import releaser.internal.ReleaserPropertiesUpdater; import releaser.internal.buildsystem.GradleUpdater; import releaser.internal.buildsystem.ProjectPomUpdater; import releaser.internal.buildsystem.TestUtils; @@ -78,7 +79,9 @@ public class PostReleaseActionsTests { VersionsFetcher versionsFetcher = fetcher(this.properties); - ProjectCommandExecutor builder = commandExecutor(this.properties); + ReleaserPropertiesUpdater releaserPropertiesUpdater = new ReleaserPropertiesUpdater(); + + ProjectCommandExecutor commandExecutor = new ProjectCommandExecutor(); private ProjectGitHandler projectGitHandler(ReleaserProperties properties) { return new ProjectGitHandler(properties) { @@ -111,10 +114,6 @@ public class PostReleaseActionsTests { return new VersionsFetcher(properties, updater); } - private ProjectCommandExecutor commandExecutor(ReleaserProperties properties) { - return new ProjectCommandExecutor(properties); - } - @Before public void setup() throws Exception { this.temporaryFolder = this.tmp.newFolder(); @@ -126,8 +125,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_is_not_meta_release_and_update_test_is_called() { this.properties.getMetaRelease().setEnabled(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.runUpdatedTests(currentGa()); @@ -139,8 +138,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_the_switch_for_sample_check_is_off_and_update_test_is_called() { this.properties.getGit().setRunUpdatedSamples(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.runUpdatedTests(currentGa()); @@ -158,8 +157,13 @@ public class PostReleaseActionsTests { tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); properties.getMaven().setBuildCommand("touch build.log"); PostReleaseActions actions = new PostReleaseActions(projectGitHandler(properties), - projectPomUpdater(properties), this.gradleUpdater, - commandExecutor(properties), properties, fetcher(properties)); + projectPomUpdater(properties), this.gradleUpdater, commandExecutor, + properties, fetcher(properties), releaserPropertiesUpdater) { + @Override + ReleaserProperties projectProps(File file) { + return properties; + } + }; actions.runUpdatedTests(currentGa()); @@ -181,8 +185,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_is_not_meta_release_and_release_train_docs_generation_is_called() { this.properties.getMetaRelease().setEnabled(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); @@ -193,8 +197,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_the_switch_for_sample_check_is_off_and_release_train_docs_generation_is_called() { this.properties.getGit().setUpdateReleaseTrainDocs(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); @@ -209,8 +213,8 @@ public class PostReleaseActionsTests { tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); this.properties.getMaven().setGenerateReleaseTrainDocsCommand("./test.sh"); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); @@ -226,8 +230,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_is_not_meta_release_and_test_samples_update_is_called() { this.properties.getMetaRelease().setEnabled(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.updateAllTestSamples(currentGa()); @@ -239,8 +243,8 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_the_switch_for_test_samples_update_check_is_off_and_update_is_called() { this.properties.getGit().setUpdateReleaseTrainDocs(false); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.updateAllTestSamples(currentGa()); @@ -260,8 +264,8 @@ public class PostReleaseActionsTests { tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/")); AtomicReference postReleaseProjects = new AtomicReference<>(); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, properties, - versionsFetcher) { + this.updater, this.gradleUpdater, this.commandExecutor, properties, + versionsFetcher, releaserPropertiesUpdater) { @Override Projects getPostReleaseProjects(Projects projects) { postReleaseProjects.set(super.getPostReleaseProjects(projects)); @@ -304,8 +308,8 @@ public class PostReleaseActionsTests { .singletonList(tmpFile("spring-cloud-static/").getAbsolutePath() + "/")); AtomicReference postReleaseProjects = new AtomicReference<>(); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, properties, - versionsFetcher) { + this.updater, this.gradleUpdater, this.commandExecutor, properties, + versionsFetcher, releaserPropertiesUpdater) { @Override Projects getPostReleaseProjects(Projects projects) { postReleaseProjects.set(super.getPostReleaseProjects(projects)); @@ -325,8 +329,8 @@ public class PostReleaseActionsTests { this.properties.getGit().setUpdateSpringGuides(false); VersionsFetcher versionsFetcher = BDDMockito.mock(VersionsFetcher.class); PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.builder, this.properties, - versionsFetcher); + this.updater, this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater); actions.deployGuides(Collections.emptyList()); @@ -346,7 +350,8 @@ public class PostReleaseActionsTests { ProjectCommandExecutor projectCommandExecutor = BDDMockito .mock(ProjectCommandExecutor.class); PostReleaseActions actions = new PostReleaseActions(handler, this.updater, - this.gradleUpdater, this.builder, this.properties, versionsFetcher) { + this.gradleUpdater, this.commandExecutor, this.properties, + versionsFetcher, releaserPropertiesUpdater) { @Override ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) { projectBuilderStub.set(projectCommandExecutor); @@ -362,7 +367,7 @@ public class PostReleaseActionsTests { Awaitility.await().untilAsserted(() -> { BDDAssertions.then(projectBuilderStub.get()).isNotNull(); BDDMockito.then(projectBuilderStub.get()).should() - .deployGuides(projectVersion, projectVersion); + .deployGuides(this.properties, projectVersion, projectVersion); }); } diff --git a/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java b/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java index 1de56957..d6188298 100644 --- a/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java +++ b/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java @@ -64,7 +64,7 @@ public class ProjectCommandExecutorTests { } ProjectCommandExecutor projectBuilder(ReleaserProperties properties) { - return new ProjectCommandExecutor(properties) { + return new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return testExecutor(workingDir); @@ -80,7 +80,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("resolved.log"); @@ -94,7 +95,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(new File("/foo/bar").getAbsolutePath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"), + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"), tmpFile("/builder/resolved").getPath()); then(asString(tmpFile("/builder/resolved/resolved.log"))) @@ -109,7 +111,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.M1")); + builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.M1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -122,7 +124,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.RC1")); + builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") .doesNotContain("-Pguides"); @@ -136,7 +138,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.RELEASE")); + builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -149,7 +151,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.SR1")); + builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.SR1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -163,7 +165,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("-Dhello=world -Dfoo=bar"); @@ -177,7 +180,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -191,7 +195,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("hello=world foo=bar"); @@ -206,7 +211,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("-Dhello=world -Dfoo=bar bar"); @@ -221,7 +227,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.build(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("bar -Dhello=world -Dfoo=bar"); @@ -234,7 +241,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.build(original(), + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( "contains a tag that wasn't resolved properly"); } @@ -247,7 +254,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.build(original(), + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( "Process waiting time of [0] minutes exceeded"); } @@ -259,7 +266,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.deploy(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("resolved.log"); @@ -273,7 +281,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.M1")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") .doesNotContain("-Pguides"); @@ -289,7 +297,7 @@ public class ProjectCommandExecutorTests { .runCommand(new String[] { "touch", "pom.xml" }, 1); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.M1")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("foo -Pmilestone").doesNotContain("-Pguides"); @@ -303,7 +311,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RC1")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") .doesNotContain("-Pguides"); @@ -319,7 +327,7 @@ public class ProjectCommandExecutorTests { .runCommand(new String[] { "touch", "pom.xml" }, 1); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RC1")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("foo -Pmilestone").doesNotContain("-Pguides"); @@ -333,7 +341,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RELEASE")); + builder.deploy(properties, original(), + new ProjectVersion("foo", "1.0.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -348,7 +357,8 @@ public class ProjectCommandExecutorTests { .runCommand(new String[] { "touch", "pom.xml" }, 1); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RELEASE")); + builder.deploy(properties, original(), + new ProjectVersion("foo", "1.0.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("foo -Pcentral"); @@ -362,7 +372,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.SR1")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.SR1")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @@ -376,7 +386,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.deploy(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("-Dhello=hello-world"); @@ -391,7 +402,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); + builder.deploy(properties, original(), + new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("-Dhello=hello-world"); @@ -405,7 +417,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.deploy(original(), + thenThrownBy(() -> builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( "Process waiting time of [0] minutes exceeded"); } @@ -417,14 +429,15 @@ public class ProjectCommandExecutorTests { "echo {{version}} {{oldVersion}} {{nextVersion}}" }); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); - ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) { + ProjectCommandExecutor builder = new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return executor; } }; - builder.publishDocs(original(), new ProjectVersion("foo", "1.0.0.RELEASE")); + builder.publishDocs(properties, original(), + new ProjectVersion("foo", "1.0.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("1.0.0.RELEASE 0.100.0.BUILD-SNAPSHOT 1.0.1.RELEASE"); @@ -440,14 +453,15 @@ public class ProjectCommandExecutorTests { properties.getBash().setSystemProperties("-Dhello=world -Dfoo=bar"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); - ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) { + ProjectCommandExecutor builder = new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return executor; } }; - builder.publishDocs(original(), new ProjectVersion("foo", "Finchley.RELEASE")); + builder.publishDocs(properties, original(), + new ProjectVersion("foo", "Finchley.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("-Dhello=world -Dfoo=bar 2"); @@ -462,14 +476,15 @@ public class ProjectCommandExecutorTests { .setPublishDocsCommands(new String[] { "echo '{{version}}'" }); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); - ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) { + ProjectCommandExecutor builder = new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return executor; } }; - builder.publishDocs(original(), new ProjectVersion("foo", "1.1.0.RELEASE")); + builder.publishDocs(properties, original(), + new ProjectVersion("foo", "1.1.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("1.1.0.RELEASE"); @@ -483,14 +498,15 @@ public class ProjectCommandExecutorTests { File resolved = tmpFile("/builder/resolved"); properties.setWorkingDir(resolved.getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); - ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) { + ProjectCommandExecutor builder = new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return executor; } }; - builder.generateReleaseTrainDocs("1.1.0.RELEASE", resolved.getAbsolutePath()); + builder.generateReleaseTrainDocs(properties, "1.1.0.RELEASE", + resolved.getAbsolutePath()); then(asString(tmpFile("/builder/resolved/resolved.log"))) .contains("1.1.0.RELEASE"); @@ -505,7 +521,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.publishDocs(original(), + thenThrownBy(() -> builder.publishDocs(properties, original(), new ProjectVersion("foo", "1.0.0.RELEASE"))).hasMessageContaining( "Process waiting time of [0] minutes exceeded"); } @@ -515,7 +531,7 @@ public class ProjectCommandExecutorTests { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("exit 1"); properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); - ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) { + ProjectCommandExecutor builder = new ProjectCommandExecutor() { @Override ReleaserProcessExecutor executor(String workingDir) { return new ReleaserProcessExecutor(properties.getWorkingDir()) { @@ -528,7 +544,7 @@ public class ProjectCommandExecutorTests { } }; - thenThrownBy(() -> builder.build(original(), + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( "The process has exited with exit code [1]"); } diff --git a/releaser-spring/src/main/java/releaser/internal/spring/ProjectsToRunFactory.java b/releaser-spring/src/main/java/releaser/internal/spring/ProjectsToRunFactory.java index a2eddd74..920f45a5 100644 --- a/releaser-spring/src/main/java/releaser/internal/spring/ProjectsToRunFactory.java +++ b/releaser-spring/src/main/java/releaser/internal/spring/ProjectsToRunFactory.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.Releaser; import releaser.internal.ReleaserProperties; +import releaser.internal.ReleaserPropertiesUpdater; import releaser.internal.options.Options; import releaser.internal.project.ProjectVersion; diff --git a/releaser-spring/src/main/java/releaser/internal/spring/ReleaserConfiguration.java b/releaser-spring/src/main/java/releaser/internal/spring/ReleaserConfiguration.java index 7a2d0f19..b30fecd8 100644 --- a/releaser-spring/src/main/java/releaser/internal/spring/ReleaserConfiguration.java +++ b/releaser-spring/src/main/java/releaser/internal/spring/ReleaserConfiguration.java @@ -21,6 +21,7 @@ import java.util.List; import releaser.internal.Releaser; import releaser.internal.ReleaserProperties; +import releaser.internal.ReleaserPropertiesUpdater; import releaser.internal.buildsystem.GradleUpdater; import releaser.internal.buildsystem.ProjectPomUpdater; import releaser.internal.docs.CustomProjectDocumentationUpdater; @@ -88,8 +89,8 @@ class ReleaserConfiguration { @Bean @ConditionalOnMissingBean - ProjectCommandExecutor projectBuilder(ReleaserProperties properties) { - return new ProjectCommandExecutor(properties); + ProjectCommandExecutor projectBuilder() { + return new ProjectCommandExecutor(); } @Bean @@ -139,9 +140,11 @@ class ReleaserConfiguration { PostReleaseActions postReleaseActions(ProjectGitHandler handler, ProjectPomUpdater pomUpdater, GradleUpdater gradleUpdater, ProjectCommandExecutor projectCommandExecutor, - ReleaserProperties releaserProperties, VersionsFetcher versionsFetcher) { + ReleaserProperties releaserProperties, VersionsFetcher versionsFetcher, + ReleaserPropertiesUpdater releaserPropertiesUpdater) { return new PostReleaseActions(handler, pomUpdater, gradleUpdater, - projectCommandExecutor, releaserProperties, versionsFetcher); + projectCommandExecutor, releaserProperties, versionsFetcher, + releaserPropertiesUpdater); } @Bean @@ -172,8 +175,8 @@ class ReleaserConfiguration { @Bean @ConditionalOnMissingBean - ReleaserPropertiesUpdater releaserPropertiesUpdater(ApplicationContext context) { - return new ReleaserPropertiesUpdater(context); + ReleaserPropertiesUpdater releaserPropertiesUpdater() { + return new ReleaserPropertiesUpdater(); } @Bean diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/BuildProjectReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/BuildProjectReleaseTask.java index 0bfb2fc3..bd3421af 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/BuildProjectReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/BuildProjectReleaseTask.java @@ -56,7 +56,8 @@ public class BuildProjectReleaseTask implements DryRunReleaseReleaserTask { @Override public ExecutionResult runTask(Arguments args) { - return this.releaser.buildProject(args.originalVersion, args.versionFromBom); + return this.releaser.buildProject(args.properties, args.originalVersion, + args.versionFromBom); } @Override diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/DeployArtifactsReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/DeployArtifactsReleaseTask.java index eec5ed75..b3fb47da 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/DeployArtifactsReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/DeployArtifactsReleaseTask.java @@ -56,7 +56,8 @@ public class DeployArtifactsReleaseTask implements ReleaseReleaserTask { @Override public ExecutionResult runTask(Arguments args) { - return this.releaser.deploy(args.originalVersion, args.versionFromBom); + return this.releaser.deploy(args.properties, args.originalVersion, + args.versionFromBom); } @Override diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java index f4efc053..16014c56 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java @@ -56,7 +56,8 @@ public class PublishDocsReleaseTask implements ReleaseReleaserTask { @Override public ExecutionResult runTask(Arguments args) { - return this.releaser.publishDocs(args.originalVersion, args.versionFromBom); + return this.releaser.publishDocs(args.properties, args.originalVersion, + args.versionFromBom); } @Override diff --git a/releaser-spring/src/test/java/releaser/internal/docs/TestDocumentationUpdater.java b/releaser-spring/src/test/java/releaser/internal/docs/TestDocumentationUpdater.java index 7a99543b..2b9927ae 100644 --- a/releaser-spring/src/test/java/releaser/internal/docs/TestDocumentationUpdater.java +++ b/releaser-spring/src/test/java/releaser/internal/docs/TestDocumentationUpdater.java @@ -28,7 +28,7 @@ public class TestDocumentationUpdater extends DocumentationUpdater { public TestDocumentationUpdater(ReleaserProperties properties, CustomProjectDocumentationUpdater updater, ProjectGitHandler handler, TestReleaseContentsUpdater testRelease) { - super(properties, new ProjectDocumentationUpdater(properties, handler, + super(new ProjectDocumentationUpdater(properties, handler, Collections.singletonList(updater)), testRelease); } diff --git a/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesIntegrationTests.java b/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesIntegrationTests.java deleted file mode 100644 index 4d3692d9..00000000 --- a/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesIntegrationTests.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2013-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 releaser.internal.spring; - -import java.io.File; -import java.net.URL; -import java.util.List; - -import org.assertj.core.api.BDDAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; -import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.junit4.SpringRunner; - -/** - * @author Marcin Grzejszczak - */ -@RunWith(SpringRunner.class) -@Import(ReleaserPropertiesIntegrationTests.Config.class) -public class ReleaserPropertiesIntegrationTests { - - @Autowired - List propertiesAware; - - @Autowired - ApplicationContext context; - - @Test - public void should_update_properties() { - ReleaserProperties properties = new ReleaserProperties(); - properties.getPom().setBranch("fooooo"); - - new ReleaserPropertiesUpdater(this.context).updateProperties(properties, - new File(".")); - - BDDAssertions.then(this.propertiesAware).hasSize(2); - this.propertiesAware.forEach(aware -> BDDAssertions - .then(((ReleaserPropertiesHaving) aware).properties.getPom().getBranch()) - .isEqualTo("fooooo")); - } - - @Test - public void should_update_properties_including_existing_releaser_config() { - ReleaserProperties properties = new ReleaserProperties(); - properties.getPom().setBranch("barrrr"); - URL resource = ReleaserPropertiesIntegrationTests.class - .getResource("/projects/project-with-config"); - - new ReleaserPropertiesUpdater(this.context).updateProperties(properties, - new File(resource.getFile())); - - BDDAssertions.then(this.propertiesAware).hasSize(2); - this.propertiesAware.forEach(aware -> { - ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware); - BDDAssertions.then(having.properties.getPom().getBranch()) - .isEqualTo("barrrr"); - BDDAssertions.then(having.properties.getMaven().getBuildCommand()) - .isEqualTo("./scripts/noIntegration.sh"); - }); - } - - @Test - public void should_update_properties_including_existing_releaser_config_for_netflix() { - ReleaserProperties properties = new ReleaserProperties(); - properties.getPom().setBranch("bazzzz"); - URL resource = ReleaserPropertiesIntegrationTests.class - .getResource("/projects/project-with-netflix-config"); - - new ReleaserPropertiesUpdater(this.context).updateProperties(properties, - new File(resource.getFile())); - - BDDAssertions.then(this.propertiesAware).hasSize(2); - this.propertiesAware.forEach(aware -> { - ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware); - BDDAssertions.then(having.properties.getPom().getBranch()) - .isEqualTo("bazzzz"); - BDDAssertions.then(having.properties.getMaven().getBuildCommand()) - .isEqualTo("./scripts/build.sh {{systemProps}}"); - }); - } - - @Configuration - static class Config { - - @Bean - ReleaserPropertiesAware aware1() { - return new ReleaserPropertiesHaving(); - } - - @Bean - ReleaserPropertiesAware aware2() { - return new ReleaserPropertiesHaving(); - } - - } - - static class ReleaserPropertiesHaving implements ReleaserPropertiesAware { - - ReleaserProperties properties; - - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - - ReleaserProperties getProps() { - return this.properties; - } - - } - -} diff --git a/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java b/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java index 84adde6c..1ef0bc52 100644 --- a/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java +++ b/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java @@ -18,24 +18,17 @@ package releaser.internal.spring; import java.io.File; import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.Map; import org.assertj.core.api.BDDAssertions; import org.junit.Test; -import org.mockito.BDDMockito; import releaser.internal.ReleaserProperties; -import releaser.internal.ReleaserPropertiesAware; - -import org.springframework.context.ApplicationContext; +import releaser.internal.ReleaserPropertiesUpdater; /** * @author Marcin Grzejszczak */ public class ReleaserPropertiesUpdaterTests { - ApplicationContext context = BDDMockito.mock(ApplicationContext.class); - File relaserUpdater; public ReleaserPropertiesUpdaterTests() throws URISyntaxException { @@ -46,15 +39,11 @@ public class ReleaserPropertiesUpdaterTests { @Test public void should_update_properties() { ReleaserProperties original = originalReleaserProperties(); - Aware aware = new Aware(); - BDDMockito.given(this.context.getBeansOfType(BDDMockito.any(Class.class))) - .willReturn(beansOfType(aware)); - ReleaserPropertiesUpdater updater = new ReleaserPropertiesUpdater(this.context); + ReleaserPropertiesUpdater updater = new ReleaserPropertiesUpdater(); ReleaserProperties props = updater.updateProperties(original, this.relaserUpdater); - BDDAssertions.then(aware.properties).isNotNull(); BDDAssertions.then(props.getMaven().getBuildCommand()).isEqualTo("maven_build"); BDDAssertions.then(props.getGradle().getBuildCommand()).isEqualTo("gradle_build"); BDDAssertions.then(props.getBash().getBuildCommand()).isEqualTo("bash_build"); @@ -67,21 +56,4 @@ public class ReleaserPropertiesUpdaterTests { return props; } - private Map beansOfType(Aware aware) { - Map map = new HashMap<>(); - map.put("foo", aware); - return map; - } - - class Aware implements ReleaserPropertiesAware { - - ReleaserProperties properties; - - @Override - public void setReleaserProperties(ReleaserProperties properties) { - this.properties = properties; - } - - } - } diff --git a/releaser-test/src/main/java/releaser/docs/TestDocumentationUpdater.java b/releaser-test/src/main/java/releaser/docs/TestDocumentationUpdater.java deleted file mode 100644 index 7a99543b..00000000 --- a/releaser-test/src/main/java/releaser/docs/TestDocumentationUpdater.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013-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 releaser.internal.docs; - -import edu.emory.mathcs.backport.java.util.Collections; -import releaser.internal.ReleaserProperties; -import releaser.internal.git.ProjectGitHandler; - -/** - * @author Marcin Grzejszczak - */ -public class TestDocumentationUpdater extends DocumentationUpdater { - - public TestDocumentationUpdater(ReleaserProperties properties, - CustomProjectDocumentationUpdater updater, ProjectGitHandler handler, - TestReleaseContentsUpdater testRelease) { - super(properties, new ProjectDocumentationUpdater(properties, handler, - Collections.singletonList(updater)), testRelease); - } - -} diff --git a/releaser-test/src/main/java/releaser/docs/TestReleaseContentsUpdater.java b/releaser-test/src/main/java/releaser/internal/docs/TestReleaseContentsUpdater.java similarity index 100% rename from releaser-test/src/main/java/releaser/docs/TestReleaseContentsUpdater.java rename to releaser-test/src/main/java/releaser/internal/docs/TestReleaseContentsUpdater.java diff --git a/releaser-test/src/main/java/releaser/git/GitTestUtils.java b/releaser-test/src/main/java/releaser/internal/git/GitTestUtils.java similarity index 100% rename from releaser-test/src/main/java/releaser/git/GitTestUtils.java rename to releaser-test/src/main/java/releaser/internal/git/GitTestUtils.java