From 435ef0e58a8a5812c5e359e9e1c8314defaa174e Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Tue, 15 Feb 2022 14:38:12 +0100 Subject: [PATCH] Upgrade dependencies. Start rewriting tests. --- pom.xml | 18 +- .../SpringCloudCustomMavenBomTests.java | 2 +- .../SpringCloudMavenBomParserTests.java | 6 +- .../SpringCloudProjectPomUpdaterTests.java | 2 +- ...ustomProjectDocumentationUpdaterTests.java | 6 +- .../github/SpringCloudGithubIssuesTests.java | 10 +- .../AbstractSpringCloudAcceptanceTests.java | 4 +- ...bstractSpringCloudMetaAcceptanceTests.java | 4 +- .../SpringMetaReleaseAcceptanceTests.java | 2 +- .../SpringSingleProjectAcceptanceTests.java | 2 +- releaser-core/pom.xml | 5 + .../main/java/releaser/internal/Releaser.java | 141 +++---- .../releaser/internal/ReleaserProperties.java | 103 +++--- .../internal/ReleaserPropertiesUpdater.java | 52 +-- .../buildsystem/CompositeBomParser.java | 8 +- .../internal/buildsystem/CustomBomParser.java | 6 +- .../internal/buildsystem/GradleBomParser.java | 11 +- .../GradleProjectNameExtractor.java | 3 +- .../internal/buildsystem/GradleUpdater.java | 65 ++-- .../internal/buildsystem/MavenBomParser.java | 14 +- .../internal/buildsystem/PomUpdater.java | 98 ++--- .../buildsystem/ProjectPomUpdater.java | 72 ++-- .../internal/buildsystem/VersionsFromBom.java | 40 +- .../buildsystem/VersionsFromBomBuilder.java | 26 +- .../CustomProjectDocumentationUpdater.java | 16 +- .../internal/docs/DocumentationUpdater.java | 14 +- .../docs/ProjectDocumentationUpdater.java | 34 +- .../internal/docs/ReleaseTrainContents.java | 3 +- .../docs/ReleaseTrainContentsUpdater.java | 95 ++--- .../main/java/releaser/internal/docs/Row.java | 13 +- .../java/releaser/internal/docs/Title.java | 9 +- .../java/releaser/internal/git/GitRepo.java | 80 ++-- .../internal/git/ProjectGitHandler.java | 46 +-- .../releaser/internal/git/SimpleCommit.java | 14 +- .../internal/github/CachingGithub.java | 80 ++-- .../internal/github/GithubIssueFiler.java | 18 +- .../internal/github/GithubIssues.java | 3 +- .../internal/github/GithubMilestones.java | 25 +- .../internal/github/ProjectGitHubHandler.java | 18 +- .../postrelease/PostReleaseActions.java | 134 +++---- .../internal/project/ProcessedProject.java | 9 +- .../releaser/internal/project/Project.java | 3 +- .../project/ProjectCommandExecutor.java | 196 ++++------ .../internal/project/ProjectVersion.java | 96 ++--- .../releaser/internal/project/Projects.java | 59 ++- .../java/releaser/internal/sagan/Project.java | 13 +- .../java/releaser/internal/sagan/Release.java | 14 +- .../internal/sagan/ReleaseUpdate.java | 9 +- .../releaser/internal/sagan/Repository.java | 5 +- .../sagan/RestTemplateSaganClient.java | 32 +- .../releaser/internal/sagan/SaganUpdater.java | 119 +++--- .../internal/tech/BuildUnstableException.java | 9 +- .../internal/tech/ExecutionResult.java | 30 +- .../internal/tech/HandlebarsHelper.java | 3 +- .../releaser/internal/tech/PomReader.java | 6 +- .../internal/tech/TemporaryFileStorage.java | 11 +- .../template/BlogTemplateGenerator.java | 28 +- .../template/EmailTemplateGenerator.java | 6 +- .../internal/template/NotesGenerator.java | 10 +- .../ReleaseNotesTemplateGenerator.java | 10 +- .../internal/template/TemplateGenerator.java | 13 +- .../template/TwitterTemplateGenerator.java | 6 +- .../internal/versions/VersionsFetcher.java | 62 ++-- .../SpringCloudReleaserProperties.java | 12 +- .../internal/PomUpdateAcceptanceTests.java | 122 +++--- .../internal/ReleaserPropertiesTests.java | 11 +- .../java/releaser/internal/ReleaserTests.java | 103 +++--- .../buildsystem/GradleBomParserTests.java | 21 +- .../buildsystem/LoggerToMavenLogTests.java | 8 +- .../buildsystem/MavenBomParserTests.java | 15 +- .../internal/buildsystem/PomReaderTests.java | 18 +- .../internal/buildsystem/PomUpdaterTests.java | 347 +++++++----------- .../buildsystem/ProjectPomUpdaterTests.java | 7 +- .../buildsystem/ProjectVersionTests.java | 303 ++++++--------- .../internal/buildsystem/ProjectsTests.java | 50 +-- .../buildsystem/PropertyStorerTests.java | 11 +- .../PropertyVersionChangerTests.java | 47 ++- .../internal/buildsystem/TestUtils.java | 3 +- .../buildsystem/VersionChangeAssertions.java | 6 +- .../buildsystem/VersionsFromBomTests.java | 107 ++---- .../docs/ReleaseTrainContentsParserTests.java | 9 +- .../ReleaseTrainContentsUpdaterTests.java | 77 ++-- .../java/releaser/internal/docs/RowTests.java | 8 +- .../docs/SpringCloudGhPagesParserTests.java | 90 ++--- .../releaser/internal/git/GitRepoTests.java | 47 +-- .../releaser/internal/git/GitTestUtils.java | 3 +- .../internal/git/ProjectGitHandlerTests.java | 45 +-- .../internal/github/GithubIssuesTests.java | 44 +-- .../github/GithubMilestonesTests.java | 62 ++-- .../internal/gradle/GradleUpdaterTests.java | 34 +- .../postrelease/PostReleaseActionsTests.java | 144 +++----- .../project/ProjectCommandExecutorTests.java | 259 +++++-------- .../sagan/RestTemplateSaganClientTests.java | 35 +- .../sagan/SaganUpdaterOldDocsTest.java | 108 +++--- .../internal/sagan/SaganUpdaterTest.java | 103 +++--- .../template/TemplateGeneratorTests.java | 265 +++++-------- .../versions/VersionsFromBomFetcherTests.java | 24 +- .../demo/BootstrapClientApplicationTests.java | 2 +- .../StandaloneClientApplicationTests.java | 2 +- ...strapDecryptionClientApplicationTests.java | 2 +- .../StandaloneClientApplicationTests.java | 2 +- .../StandaloneClientApplicationTests.java | 5 +- .../ConfigServerEurekaApplicationTests.java | 2 +- .../ConfigServerEurekaApplicationTests.java | 2 +- .../demo/ConfigServerApplicationTests.java | 2 +- .../demo/EurekaClientApplicationTests.java | 2 +- .../demo/EurekaFirstApplicationTests.java | 2 +- ...faultStandaloneClientApplicationTests.java | 2 +- .../StandaloneClientApplicationTests.java | 2 +- .../demo/EurekaServerApplicationTests.java | 2 +- ...ignEagerInstantiationApplicationTests.java | 2 +- .../demo/HelloClientApplicationTests.java | 2 +- .../test/java/demo/NoWebApplicationTests.java | 2 +- .../demo/FeignClientApplicationTests.java | 2 +- ...nClientWithServerListApplicationTests.java | 2 +- .../demo/FeignClientApplicationTests.java | 2 +- ...nClientWithServerListApplicationTests.java | 2 +- .../java/demo/HystrixApplicationTests.java | 2 +- .../java/demo/HystrixApplicationTests.java | 2 +- .../java/demo/SidecarApplicationTests.java | 2 +- .../java/demo/NotWebApplicationTests.java | 2 +- .../test/DiscoveryNotWebApplicationTests.java | 2 +- .../demo/RibbonClientApplicationTests.java | 2 +- .../test/java/demo/ZuulApplicationTests.java | 2 +- .../RibbonDefaultConfigApplicationTests.java | 2 +- .../demo/HelloClientApplicationTests.java | 2 +- .../test/java/demo/TraceApplicationTests.java | 2 +- .../java/demo/StreamBusApplicationTests.java | 2 +- .../demo/TurbineStreamApplicationTests.java | 2 +- .../java/demo/TurbineApplicationTests.java | 2 +- .../java/demo/VanillaApplicationTests.java | 2 +- .../java/demo/ZipkinApplicationTests.java | 2 +- .../ZuulConfigDiscoveryApplicationTests.java | 2 +- .../demo/ZuulProxyEurekaApplicationTests.java | 2 +- .../java/demo/ZuulProxyApplicationTests.java | 2 +- .../test/java/demo/ZuulApplicationTests.java | 2 +- .../spring/OptionsProcessorTests.java | 4 +- .../ReleaserPropertiesUpdaterTests.java | 2 +- .../spring/AbstractSpringAcceptanceTests.java | 4 +- spring-cloud-info/pom.xml | 6 +- ...InitializrSpringCloudInfoServiceTests.java | 2 +- .../SpringCloudInfoRestControllerTests.java | 6 +- 142 files changed, 1774 insertions(+), 2930 deletions(-) diff --git a/pom.xml b/pom.xml index 6297f630..584bbcbd 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-build - 2.2.3.RELEASE + 3.1.0 @@ -30,17 +30,17 @@ UTF-8 1.8 - Hoxton.SR6 - 1.0 + 2021.0.0 + 1.1.2 0.0.9 - 5.4.1.Final - 5.1.3.201810200350-r + 7.0.2.Final + 6.0.0.202111291000-r - 3.6.3 + 3.8.4 2.7 - 4.2.0 - 0.10.0-SNAPSHOT - 4.0.3 + 4.3.0 + 0.12.0 + 4.1.1 1.0.0.BUILD-SNAPSHOT 1.1.4 5.0.4 diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudCustomMavenBomTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudCustomMavenBomTests.java index e988b750..be2711da 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudCustomMavenBomTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudCustomMavenBomTests.java @@ -21,7 +21,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import releaser.cloud.SpringCloudReleaserProperties; import releaser.internal.buildsystem.CustomBomParser; import releaser.internal.buildsystem.VersionsFromBom; diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudMavenBomParserTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudMavenBomParserTests.java index 717ae82c..17311f6b 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudMavenBomParserTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudMavenBomParserTests.java @@ -22,9 +22,9 @@ import java.net.URISyntaxException; import java.util.Arrays; import org.eclipse.jgit.api.errors.GitAPIException; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.TemporaryFolder; import releaser.cloud.SpringCloudReleaserProperties; import releaser.cloud.docs.TestUtils; @@ -52,7 +52,7 @@ public class SpringCloudMavenBomParserTests { ReleaserProperties properties = SpringCloudReleaserProperties.get(); - @Before + @BeforeEach public void setup() throws URISyntaxException, IOException, GitAPIException { this.tmpFolder = this.tmp.newFolder(); TestUtils.prepareLocalRepo(); diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudProjectPomUpdaterTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudProjectPomUpdaterTests.java index ef0ef6d3..77d2cc2e 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudProjectPomUpdaterTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/buildsystem/SpringCloudProjectPomUpdaterTests.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.stream.Collectors; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import releaser.cloud.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; import releaser.internal.buildsystem.MavenBomParserAccessor; diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/docs/SpringCloudCustomProjectDocumentationUpdaterTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/docs/SpringCloudCustomProjectDocumentationUpdaterTests.java index bf7dcf57..1da8166c 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/docs/SpringCloudCustomProjectDocumentationUpdaterTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/docs/SpringCloudCustomProjectDocumentationUpdaterTests.java @@ -26,9 +26,9 @@ import java.util.Collections; import javax.validation.constraints.NotNull; import org.assertj.core.api.BDDAssertions; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.TemporaryFolder; import org.mockito.BDDMockito; import releaser.cloud.SpringCloudReleaserProperties; @@ -63,7 +63,7 @@ public class SpringCloudCustomProjectDocumentationUpdaterTests { ReleaserProperties properties = SpringCloudReleaserProperties.get(); - @Before + @BeforeEach public void setup() throws IOException, URISyntaxException { this.tmpFolder = this.tmp.newFolder(); this.project = new File(SpringCloudCustomProjectDocumentationUpdater.class diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/github/SpringCloudGithubIssuesTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/github/SpringCloudGithubIssuesTests.java index 59f30a75..298fb5c4 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/github/SpringCloudGithubIssuesTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/github/SpringCloudGithubIssuesTests.java @@ -25,9 +25,9 @@ import com.jcabi.github.Issue; import com.jcabi.github.Repo; import com.jcabi.github.Repos; import com.jcabi.github.mock.MkGithub; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.rules.TemporaryFolder; import org.mockito.BDDMockito; import releaser.cloud.SpringCloudReleaserProperties; @@ -53,7 +53,7 @@ public class SpringCloudGithubIssuesTests { Repo repo; - @Before + @BeforeEach public void setup() throws IOException { this.github = github("spring-guides"); this.properties.getGit().setOauthToken("a"); @@ -81,7 +81,7 @@ public class SpringCloudGithubIssuesTests { "2.0.0.BUILD-SNAPSHOT")), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } @Test @@ -133,7 +133,7 @@ public class SpringCloudGithubIssuesTests { new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE")), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } @Test diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/spring/AbstractSpringCloudAcceptanceTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/spring/AbstractSpringCloudAcceptanceTests.java index 2d5c9609..aaf39b6b 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/spring/AbstractSpringCloudAcceptanceTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/spring/AbstractSpringCloudAcceptanceTests.java @@ -19,7 +19,7 @@ package releaser.cloud.spring; import java.io.File; import java.util.Arrays; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import releaser.internal.buildsystem.TestUtils; import releaser.internal.spring.AbstractSpringAcceptanceTests; @@ -33,7 +33,7 @@ public class AbstractSpringCloudAcceptanceTests extends AbstractSpringAcceptance public File springCloudBuildProject; - @Before + @BeforeEach public void setupCloud() throws Exception { this.temporaryFolder = this.tmp.newFolder(); this.springCloudConsulProject = new File(AbstractSpringAcceptanceTests.class diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/AbstractSpringCloudMetaAcceptanceTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/AbstractSpringCloudMetaAcceptanceTests.java index cde22ce3..98d687bd 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/AbstractSpringCloudMetaAcceptanceTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/AbstractSpringCloudMetaAcceptanceTests.java @@ -19,7 +19,7 @@ package releaser.cloud.spring.meta; import java.io.File; import java.util.Arrays; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import releaser.internal.spring.meta.AbstractSpringMetaReleaseAcceptanceTests; import static org.assertj.core.api.BDDAssertions.then; @@ -31,7 +31,7 @@ public class AbstractSpringCloudMetaAcceptanceTests public File springCloudBuildProject; - @Before + @BeforeEach public void setupCloud() throws Exception { this.springCloudConsulProject = new File( AbstractSpringCloudMetaAcceptanceTests.class diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/SpringMetaReleaseAcceptanceTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/SpringMetaReleaseAcceptanceTests.java index 9fafc02c..6e745b74 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/SpringMetaReleaseAcceptanceTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/spring/meta/SpringMetaReleaseAcceptanceTests.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import releaser.internal.Releaser; import releaser.internal.ReleaserProperties; diff --git a/projects/spring-cloud/src/test/java/releaser/cloud/spring/single/SpringSingleProjectAcceptanceTests.java b/projects/spring-cloud/src/test/java/releaser/cloud/spring/single/SpringSingleProjectAcceptanceTests.java index 8a0e25a7..bbd46cd5 100644 --- a/projects/spring-cloud/src/test/java/releaser/cloud/spring/single/SpringSingleProjectAcceptanceTests.java +++ b/projects/spring-cloud/src/test/java/releaser/cloud/spring/single/SpringSingleProjectAcceptanceTests.java @@ -22,7 +22,7 @@ import java.util.Iterator; import org.assertj.core.api.BDDAssertions; import org.eclipse.jgit.revwalk.RevCommit; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import releaser.cloud.spring.AbstractSpringCloudAcceptanceTests; import releaser.internal.ReleaserProperties; diff --git a/releaser-core/pom.xml b/releaser-core/pom.xml index 44fd792e..9939da45 100644 --- a/releaser-core/pom.xml +++ b/releaser-core/pom.xml @@ -48,6 +48,11 @@ jsch.agentproxy.sshagent ${jsch-agent.version} + + org.eclipse.jgit + org.eclipse.jgit.ssh.jsch + ${org.eclipse.jgit-version} + com.jcraft jsch.agentproxy.jsch diff --git a/releaser-core/src/main/java/releaser/internal/Releaser.java b/releaser-core/src/main/java/releaser/internal/Releaser.java index 859abba4..cacb48d2 100644 --- a/releaser-core/src/main/java/releaser/internal/Releaser.java +++ b/releaser-core/src/main/java/releaser/internal/Releaser.java @@ -69,12 +69,9 @@ public class Releaser { private ReleaserProperties releaserProperties; - public Releaser(ReleaserProperties releaserProperties, - ProjectPomUpdater projectPomUpdater, - ProjectCommandExecutor projectCommandExecutor, - ProjectGitHandler projectGitHandler, - ProjectGitHubHandler projectGitHubHandler, - TemplateGenerator templateGenerator, GradleUpdater gradleUpdater, + public Releaser(ReleaserProperties releaserProperties, ProjectPomUpdater projectPomUpdater, + ProjectCommandExecutor projectCommandExecutor, ProjectGitHandler projectGitHandler, + ProjectGitHubHandler projectGitHubHandler, TemplateGenerator templateGenerator, GradleUpdater gradleUpdater, SaganUpdater saganUpdater, DocumentationUpdater documentationUpdater, PostReleaseActions postReleaseActions) { this.releaserProperties = releaserProperties; @@ -101,56 +98,51 @@ public class Releaser { return this.projectPomUpdater.fixedVersions(); } - public ExecutionResult updateProjectFromBom(File project, Projects versions, - ProjectVersion versionFromBom) { + public ExecutionResult updateProjectFromBom(File project, Projects versions, ProjectVersion versionFromBom) { return updateProjectFromBom(project, versions, versionFromBom, ASSERT_SNAPSHOTS); } - private ExecutionResult updateProjectFromBom(File project, Projects versions, - ProjectVersion versionFromBom, boolean assertSnapshots) { + private ExecutionResult updateProjectFromBom(File project, Projects versions, ProjectVersion versionFromBom, + boolean assertSnapshots) { log.info("Will update the project with versions [{}]", versions); - ReleaserProperties updatedProperties = new ReleaserPropertiesUpdater() - .updateProperties(this.releaserProperties, project); - this.projectPomUpdater.updateProjectFromReleaseTrain(project, versions, - versionFromBom, assertSnapshots); - this.gradleUpdater.updateProjectFromReleaseTrain(updatedProperties, project, - versions, versionFromBom, assertSnapshots); + ReleaserProperties updatedProperties = new ReleaserPropertiesUpdater().updateProperties(this.releaserProperties, + project); + this.projectPomUpdater.updateProjectFromReleaseTrain(project, versions, versionFromBom, assertSnapshots); + this.gradleUpdater.updateProjectFromReleaseTrain(updatedProperties, project, versions, versionFromBom, + assertSnapshots); ProjectVersion changedVersion = new ProjectVersion(project); log.info("\n\nProject was successfully updated to [{}]", changedVersion.version); return ExecutionResult.success(); } - public ExecutionResult buildProject(ReleaserProperties properties, - ProjectVersion originalVersion, ProjectVersion 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(); } - public ExecutionResult commitAndPushTags(File project, - ProjectVersion changedVersion) { + public ExecutionResult commitAndPushTags(File project, ProjectVersion changedVersion) { this.projectGitHandler.commitAndTagIfApplicable(project, changedVersion); log.info("\nCommit was made and tag was pushed successfully"); return ExecutionResult.success(); } - public ExecutionResult deploy(ReleaserProperties properties, - ProjectVersion originalVersion, ProjectVersion 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(ReleaserProperties properties, - ProjectVersion originalVersion, ProjectVersion changedVersion) { - this.projectCommandExecutor.publishDocs(properties, 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(); } - public ExecutionResult rollbackReleaseVersion(File project, Projects projects, - ProjectVersion scReleaseVersion) { + public ExecutionResult rollbackReleaseVersion(File project, Projects projects, ProjectVersion scReleaseVersion) { if (scReleaseVersion.isSnapshot()) { log.info("\nWon't rollback a snapshot version"); return ExecutionResult.skipped(); @@ -158,34 +150,29 @@ public class Releaser { this.projectGitHandler.revertChangesIfApplicable(project, scReleaseVersion); ProjectVersion originalVersion = originalVersion(project); log.info("Original project version is [{}]", originalVersion); - if ((scReleaseVersion.isRelease() || scReleaseVersion.isServiceRelease()) - && originalVersion.isSnapshot()) { + if ((scReleaseVersion.isRelease() || scReleaseVersion.isServiceRelease()) && originalVersion.isSnapshot()) { updateBumpedVersions(project, projects, originalVersion); } else { - log.info( - "\nSuccessfully reverted the commit and came back to snapshot versions"); + log.info("\nSuccessfully reverted the commit and came back to snapshot versions"); } return ExecutionResult.success(); } - private ExecutionResult updateBumpedVersions(File project, Projects projects, - ProjectVersion originalVersion) { + private ExecutionResult updateBumpedVersions(File project, Projects projects, ProjectVersion originalVersion) { Projects newProjects = Projects.forRollback(releaserProperties, projects); ProjectVersion bumpedProject = bumpProject(originalVersion, newProjects); log.info("Will bump versions \n{}", newProjects); - updateProjectFromBom(project, newProjects, originalVersion, - SKIP_SNAPSHOT_ASSERTION); + updateProjectFromBom(project, newProjects, originalVersion, SKIP_SNAPSHOT_ASSERTION); this.projectGitHandler.commitAfterBumpingVersions(project, bumpedProject); log.info("\nSuccessfully reverted the commit and bumped snapshot versions"); return ExecutionResult.success(); } - private ProjectVersion bumpProject(ProjectVersion originalVersion, - Projects newProjects) { + private ProjectVersion bumpProject(ProjectVersion originalVersion, Projects newProjects) { return newProjects.containsProject(originalVersion.projectName) - ? newProjects.forName(originalVersion.projectName) : new ProjectVersion( - originalVersion.projectName, originalVersion.bumpedVersion()); + ? newProjects.forName(originalVersion.projectName) + : new ProjectVersion(originalVersion.projectName, originalVersion.bumpedVersion()); } ProjectVersion originalVersion(File project) { @@ -214,10 +201,8 @@ public class Releaser { } public ExecutionResult createEmail(ProjectVersion releaseVersion, Projects projects) { - Assert.notNull(releaseVersion, - "You must provide a release version for your project"); - Assert.notNull(releaseVersion.version, - "You must provide a release version for your project"); + Assert.notNull(releaseVersion, "You must provide a release version for your project"); + Assert.notNull(releaseVersion.version, "You must provide a release version for your project"); if (releaseVersion.isSnapshot()) { log.info("\nWon't create email template for a SNAPSHOT version"); return ExecutionResult.skipped(); @@ -229,13 +214,11 @@ public class Releaser { return ExecutionResult.success(); } else { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create an email template")); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create an email template")); } } catch (Exception ex) { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create an email template", ex)); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create an email template", ex)); } } @@ -251,53 +234,44 @@ public class Releaser { return ExecutionResult.success(); } else { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create a blog template")); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create a blog template")); } } catch (Exception ex) { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create a blog template", ex)); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create a blog template", ex)); } } - public ExecutionResult updateSpringGuides(ProjectVersion releaseVersion, - Projects projects, List processedProjects) { + public ExecutionResult updateSpringGuides(ProjectVersion releaseVersion, Projects projects, + List processedProjects) { if (!(releaseVersion.isRelease() || releaseVersion.isServiceRelease())) { - log.info( - "\nWon't update Spring Guides for a non Release / Service Release version"); + log.info("\nWon't update Spring Guides for a non Release / Service Release version"); return ExecutionResult.skipped(); } - Exception springGuidesException = createIssueInSpringGuides(releaseVersion, - projects); + Exception springGuidesException = createIssueInSpringGuides(releaseVersion, projects); Exception deployGuidesException = deployGuides(processedProjects); if (springGuidesException != null || deployGuidesException != null) { - return ExecutionResult.unstable(new BuildUnstableException( - "Failed to update Spring Guides. Spring Guides updated successfully [" - + (springGuidesException != null) - + "] deployed guides successfully [" + return ExecutionResult.unstable( + new BuildUnstableException("Failed to update Spring Guides. Spring Guides updated successfully [" + + (springGuidesException != null) + "] deployed guides successfully [" + (deployGuidesException != null) + "]")); } return ExecutionResult.success(); } - public ExecutionResult updateStartSpringIo(ProjectVersion releaseVersion, - Projects projects) { + public ExecutionResult updateStartSpringIo(ProjectVersion releaseVersion, Projects projects) { if (!(releaseVersion.isRelease() || releaseVersion.isServiceRelease())) { - log.info( - "\nWon't update start.spring.io for a non Release / Service Release version"); + log.info("\nWon't update start.spring.io for a non Release / Service Release version"); return ExecutionResult.skipped(); } Exception exception = createIssueInStartSpringIo(releaseVersion, projects); if (exception != null) { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to update start.spring.io")); + return ExecutionResult.unstable(new BuildUnstableException("Failed to update start.spring.io")); } return ExecutionResult.success(); } - private Exception createIssueInSpringGuides(ProjectVersion releaseVersion, - Projects projects) { + private Exception createIssueInSpringGuides(ProjectVersion releaseVersion, Projects projects) { try { this.projectGitHubHandler.createIssueInSpringGuides(projects, releaseVersion); log.info("\nSuccessfully created an issue in Spring Guides"); @@ -309,18 +283,15 @@ public class Releaser { } } - private Exception createIssueInStartSpringIo(ProjectVersion releaseVersion, - Projects projects) { + private Exception createIssueInStartSpringIo(ProjectVersion releaseVersion, Projects projects) { try { - this.projectGitHubHandler.createIssueInStartSpringIo(projects, - releaseVersion); + this.projectGitHubHandler.createIssueInStartSpringIo(projects, releaseVersion); log.info("\nSuccessfully created an issue in start.spring.io"); return null; } catch (Exception ex) { log.error("Failed to update start.spring.io repo", ex); - return new BuildUnstableException("Failed to update start.spring.io repo", - ex); + return new BuildUnstableException("Failed to update start.spring.io repo", ex); } } @@ -348,18 +319,15 @@ public class Releaser { return ExecutionResult.success(); } else { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create a tweet template")); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create a tweet template")); } } catch (Exception ex) { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create a tweet template", ex)); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create a tweet template", ex)); } } - public ExecutionResult createReleaseNotes(ProjectVersion releaseVersion, - Projects projects) { + public ExecutionResult createReleaseNotes(ProjectVersion releaseVersion, Projects projects) { if (releaseVersion.isSnapshot()) { log.info("\nWon't create release notes for a SNAPSHOT version"); return ExecutionResult.skipped(); @@ -370,18 +338,15 @@ public class Releaser { return ExecutionResult.success(); } catch (Exception ex) { - return ExecutionResult.unstable( - new BuildUnstableException("Failed to create release notes", ex)); + return ExecutionResult.unstable(new BuildUnstableException("Failed to create release notes", ex)); } } - public ExecutionResult updateSagan(File project, ProjectVersion releaseVersion, - Projects projects) { + public ExecutionResult updateSagan(File project, ProjectVersion releaseVersion, Projects projects) { String currentBranch = this.projectGitHandler.currentBranch(project); ProjectVersion originalVersion = new ProjectVersion(project); try { - return this.saganUpdater.updateSagan(project, currentBranch, originalVersion, - releaseVersion, projects); + return this.saganUpdater.updateSagan(project, currentBranch, originalVersion, releaseVersion, projects); } catch (Exception ex) { return ExecutionResult.unstable(new BuildUnstableException(ex)); diff --git a/releaser-core/src/main/java/releaser/internal/ReleaserProperties.java b/releaser-core/src/main/java/releaser/internal/ReleaserProperties.java index 1061db9d..3dab2f5d 100644 --- a/releaser-core/src/main/java/releaser/internal/ReleaserProperties.java +++ b/releaser-core/src/main/java/releaser/internal/ReleaserProperties.java @@ -87,8 +87,7 @@ public class ReleaserProperties implements Serializable { private MetaRelease metaRelease = new MetaRelease(); public String getWorkingDir() { - return StringUtils.hasText(this.workingDir) ? this.workingDir - : System.getProperty("user.dir"); + return StringUtils.hasText(this.workingDir) ? this.workingDir : System.getProperty("user.dir"); } public void setWorkingDir(String workingDir) { @@ -201,10 +200,9 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "ReleaserProperties{" + "workingDir='" + this.workingDir + '\'' + ", git=" - + this.git + ", pom=" + this.pom + ", maven=" + this.maven + ", gradle=" - + this.gradle + ", sagan=" + this.sagan + ", fixedVersions=" - + this.fixedVersions + ", metaRelease=" + this.metaRelease + ", template=" + return "ReleaserProperties{" + "workingDir='" + this.workingDir + '\'' + ", git=" + this.git + ", pom=" + + this.pom + ", maven=" + this.maven + ", gradle=" + this.gradle + ", sagan=" + this.sagan + + ", fixedVersions=" + this.fixedVersions + ", metaRelease=" + this.metaRelease + ", template=" + this.template + ", versions=" + this.versions + '}'; } @@ -362,8 +360,7 @@ public class ReleaserProperties implements Serializable { return this.releaseTrainDependencyNames; } - public void setReleaseTrainDependencyNames( - List releaseTrainDependencyNames) { + public void setReleaseTrainDependencyNames(List releaseTrainDependencyNames) { this.releaseTrainDependencyNames = releaseTrainDependencyNames; } @@ -401,12 +398,10 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "MetaRelease{" + "enabled=" + enabled + ", releaseTrainProjectName='" - + releaseTrainProjectName + '\'' + ", releaseTrainDependencyNames=" - + releaseTrainDependencyNames + ", gitOrgUrl='" + gitOrgUrl + '\'' - + ", projectsToSkip=" + projectsToSkip + ", releaseGroups=" - + releaseGroups + ", releaseGroupTimeoutInMinutes=" - + releaseGroupTimeoutInMinutes + ", releaseGroupThreadCount=" + return "MetaRelease{" + "enabled=" + enabled + ", releaseTrainProjectName='" + releaseTrainProjectName + + '\'' + ", releaseTrainDependencyNames=" + releaseTrainDependencyNames + ", gitOrgUrl='" + + gitOrgUrl + '\'' + ", projectsToSkip=" + projectsToSkip + ", releaseGroups=" + releaseGroups + + ", releaseGroupTimeoutInMinutes=" + releaseGroupTimeoutInMinutes + ", releaseGroupThreadCount=" + releaseGroupThreadCount + '}'; } @@ -823,21 +818,16 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "Git{" + "releaseTrainBomUrl='" + this.releaseTrainBomUrl + '\'' - + ", documentationUrl='" + this.documentationUrl + '\'' - + ", documentationBranch='" + this.documentationBranch + '\'' - + ", releaseTrainBranch='" + this.releaseTrainBranch + '\'' - + ", releaseTrainWikiUrl='" + this.releaseTrainWikiUrl + '\'' - + ", updateDocumentationRepo=" + this.updateDocumentationRepo - + ", springProjectUrl=" + this.springProjectUrl - + ", springProjectBranch=" + this.springProjectBranch - + ", releaseTrainWikiPagePrefix=" + this.releaseTrainWikiPagePrefix - + ", cloneDestinationDir='" + this.cloneDestinationDir + '\'' - + ", fetchVersionsFromGit=" + this.fetchVersionsFromGit - + ", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones - + ", updateSpringGuides=" + this.updateSpringGuides - + ", updateSpringProject=" + this.updateSpringProject - + ", sampleUrlsSize=" + this.allTestSampleUrls.size() + '}'; + return "Git{" + "releaseTrainBomUrl='" + this.releaseTrainBomUrl + '\'' + ", documentationUrl='" + + this.documentationUrl + '\'' + ", documentationBranch='" + this.documentationBranch + '\'' + + ", releaseTrainBranch='" + this.releaseTrainBranch + '\'' + ", releaseTrainWikiUrl='" + + this.releaseTrainWikiUrl + '\'' + ", updateDocumentationRepo=" + this.updateDocumentationRepo + + ", springProjectUrl=" + this.springProjectUrl + ", springProjectBranch=" + + this.springProjectBranch + ", releaseTrainWikiPagePrefix=" + this.releaseTrainWikiPagePrefix + + ", cloneDestinationDir='" + this.cloneDestinationDir + '\'' + ", fetchVersionsFromGit=" + + this.fetchVersionsFromGit + ", numberOfCheckedMilestones=" + this.numberOfCheckedMilestones + + ", updateSpringGuides=" + this.updateSpringGuides + ", updateSpringProject=" + + this.updateSpringProject + ", sampleUrlsSize=" + this.allTestSampleUrls.size() + '}'; } } @@ -918,11 +908,10 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "Pom{" + "branch='" + this.branch + '\'' - + ", pomWithBootStarterParent='" + this.pomWithBootStarterParent - + '\'' + ", thisTrainBom='" + this.thisTrainBom + '\'' - + ", bomVersionPattern='" + this.bomVersionPattern + '\'' - + ", ignoredPomRegex=" + this.ignoredPomRegex + '}'; + return "Pom{" + "branch='" + this.branch + '\'' + ", pomWithBootStarterParent='" + + this.pomWithBootStarterParent + '\'' + ", thisTrainBom='" + this.thisTrainBom + '\'' + + ", bomVersionPattern='" + this.bomVersionPattern + '\'' + ", ignoredPomRegex=" + + this.ignoredPomRegex + '}'; } } @@ -1039,8 +1028,7 @@ public class ReleaserProperties implements Serializable { } @Override - public void setGenerateReleaseTrainDocsCommand( - String generateReleaseTrainDocsCommand) { + public void setGenerateReleaseTrainDocsCommand(String generateReleaseTrainDocsCommand) { this.generateReleaseTrainDocsCommand = generateReleaseTrainDocsCommand; } @@ -1056,12 +1044,10 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "Maven{" + "buildCommand='" + this.buildCommand + '\'' - + ", deployCommand='" + this.deployCommand + '\'' - + ", publishDocsCommand=" + this.publishDocsCommand - + "generateReleaseTrainDocsCommand='" - + this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" - + this.waitTimeInMinutes + '}'; + return "Maven{" + "buildCommand='" + this.buildCommand + '\'' + ", deployCommand='" + this.deployCommand + + '\'' + ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='" + + this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" + this.waitTimeInMinutes + + '}'; } } @@ -1173,8 +1159,7 @@ public class ReleaserProperties implements Serializable { } @Override - public void setGenerateReleaseTrainDocsCommand( - String generateReleaseTrainDocsCommand) { + public void setGenerateReleaseTrainDocsCommand(String generateReleaseTrainDocsCommand) { this.generateReleaseTrainDocsCommand = generateReleaseTrainDocsCommand; } @@ -1190,12 +1175,10 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "Bash{" + "buildCommand='" + this.buildCommand + '\'' - + ", deployCommand='" + this.deployCommand + '\'' - + ", publishDocsCommand=" + this.publishDocsCommand - + "generateReleaseTrainDocsCommand='" - + this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" - + this.waitTimeInMinutes + '}'; + return "Bash{" + "buildCommand='" + this.buildCommand + '\'' + ", deployCommand='" + this.deployCommand + + '\'' + ", publishDocsCommand=" + this.publishDocsCommand + "generateReleaseTrainDocsCommand='" + + this.generateReleaseTrainDocsCommand + '\'' + ", waitTimeInMinutes=" + this.waitTimeInMinutes + + '}'; } } @@ -1328,8 +1311,7 @@ public class ReleaserProperties implements Serializable { } @Override - public void setGenerateReleaseTrainDocsCommand( - String generateReleaseTrainDocsCommand) { + public void setGenerateReleaseTrainDocsCommand(String generateReleaseTrainDocsCommand) { this.generateReleaseTrainDocsCommand = generateReleaseTrainDocsCommand; } @@ -1347,8 +1329,7 @@ public class ReleaserProperties implements Serializable { return this.gradlePropsSubstitution; } - public void setGradlePropsSubstitution( - Map gradlePropsSubstitution) { + public void setGradlePropsSubstitution(Map gradlePropsSubstitution) { this.gradlePropsSubstitution = gradlePropsSubstitution; } @@ -1364,15 +1345,13 @@ public class ReleaserProperties implements Serializable { public String toString() { return new StringJoiner(", ", Gradle.class.getSimpleName() + "[", "]") .add("gradlePropsSubstitution=" + gradlePropsSubstitution) - .add("ignoredGradleRegex=" + ignoredGradleRegex) - .add("buildCommand='" + buildCommand + "'") + .add("ignoredGradleRegex=" + ignoredGradleRegex).add("buildCommand='" + buildCommand + "'") .add("deployCommand='" + deployCommand + "'") .add("deployGuidesCommand='" + deployGuidesCommand + "'") .add("publishDocsCommand=" + publishDocsCommand) - .add("generateReleaseTrainDocsCommand='" - + generateReleaseTrainDocsCommand + "'") - .add("systemProperties='" + systemProperties + "'") - .add("waitTimeInMinutes=" + waitTimeInMinutes).toString(); + .add("generateReleaseTrainDocsCommand='" + generateReleaseTrainDocsCommand + "'") + .add("systemProperties='" + systemProperties + "'").add("waitTimeInMinutes=" + waitTimeInMinutes) + .toString(); } } @@ -1519,8 +1498,8 @@ public class ReleaserProperties implements Serializable { @Override public String toString() { - return "Versions{" + "allVersionsFileUrl='" + this.allVersionsFileUrl + '\'' - + ", bomName='" + this.bomName + '\'' + '}'; + return "Versions{" + "allVersionsFileUrl='" + this.allVersionsFileUrl + '\'' + ", bomName='" + this.bomName + + '\'' + '}'; } } diff --git a/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java b/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java index d8633992..837fe4dc 100644 --- a/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/ReleaserPropertiesUpdater.java @@ -41,13 +41,11 @@ import org.springframework.util.StringUtils; */ public class ReleaserPropertiesUpdater implements Closeable { - private static final Logger log = LoggerFactory - .getLogger(ReleaserPropertiesUpdater.class); + private static final Logger log = LoggerFactory.getLogger(ReleaserPropertiesUpdater.class); private static final Map CACHE = new ConcurrentHashMap<>(); - public ReleaserProperties updateProperties(ReleaserProperties properties, - File clonedProjectFromOrg) { + public ReleaserProperties updateProperties(ReleaserProperties properties, File clonedProjectFromOrg) { return CACHE.computeIfAbsent(clonedProjectFromOrg, file -> { ReleaserProperties props = updatePropertiesFromFile(properties.copy(), file); props.setWorkingDir(clonedProjectFromOrg.getAbsolutePath()); @@ -56,8 +54,7 @@ public class ReleaserPropertiesUpdater implements Closeable { }); } - private ReleaserProperties updatePropertiesFromFile(ReleaserProperties copy, - File clonedProjectFromOrg) { + private ReleaserProperties updatePropertiesFromFile(ReleaserProperties copy, File clonedProjectFromOrg) { File releaserConfig = releaserConfig(clonedProjectFromOrg); if (releaserConfig.exists()) { try { @@ -66,11 +63,8 @@ public class ReleaserPropertiesUpdater implements Closeable { Properties properties = yamlProcessor.getObject(); ReleaserProperties releaserProperties = new Binder( new MapConfigurationPropertySource(properties.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(), - e -> e.getValue().toString())))) - .bind("releaser", - ReleaserProperties.class) - .get(); + .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())))) + .bind("releaser", ReleaserProperties.class).get(); log.info("config/releaser.yml found. Will update the current properties"); overrideProperties(releaserProperties, copy); } @@ -79,17 +73,14 @@ public class ReleaserPropertiesUpdater implements Closeable { } } else { - log.info( - "No config/releaser.yml found. Will NOT update the current properties"); + log.info("No config/releaser.yml found. Will NOT update the current properties"); } - log.info("Updating working directory to [{}]", - clonedProjectFromOrg.getAbsolutePath()); + log.info("Updating working directory to [{}]", clonedProjectFromOrg.getAbsolutePath()); copy.setWorkingDir(clonedProjectFromOrg.getAbsolutePath()); return copy; } - private void overrideProperties(ReleaserProperties fromProject, - ReleaserProperties copy) { + private void overrideProperties(ReleaserProperties fromProject, ReleaserProperties copy) { overrideCommandIfPresent(fromProject.getMaven(), copy.getMaven()); overrideCommandIfPresent(fromProject.getGradle(), copy.getGradle()); overrideMapIfPresent(() -> fromProject.getGradle().getGradlePropsSubstitution(), @@ -101,45 +92,36 @@ public class ReleaserPropertiesUpdater implements Closeable { private void overrideCommandIfPresent(ReleaserProperties.Command fromProject, ReleaserProperties.Command commandCopy) { - overrideStringIfPresent(fromProject::getBuildCommand, - commandCopy::setBuildCommand); - overrideStringIfPresent(fromProject::getDeployCommand, - commandCopy::setDeployCommand); + overrideStringIfPresent(fromProject::getBuildCommand, commandCopy::setBuildCommand); + overrideStringIfPresent(fromProject::getDeployCommand, commandCopy::setDeployCommand); overrideStringIfPresent(fromProject::getGenerateReleaseTrainDocsCommand, commandCopy::setGenerateReleaseTrainDocsCommand); - overrideStringIfPresent(fromProject::getPublishDocsCommand, - commandCopy::setPublishDocsCommand); - overrideStringIfPresent(fromProject::getDeployGuidesCommand, - commandCopy::setDeployGuidesCommand); - overrideStringIfPresent(fromProject::getSystemProperties, - commandCopy::setSystemProperties); + overrideStringIfPresent(fromProject::getPublishDocsCommand, commandCopy::setPublishDocsCommand); + overrideStringIfPresent(fromProject::getDeployGuidesCommand, commandCopy::setDeployGuidesCommand); + overrideStringIfPresent(fromProject::getSystemProperties, commandCopy::setSystemProperties); } - private void overrideStringIfPresent(Supplier predicate, - Consumer consumer) { + private void overrideStringIfPresent(Supplier predicate, Consumer consumer) { if (StringUtils.hasText(predicate.get())) { consumer.accept(predicate.get()); } } - private void overrideArrayIfPresent(Supplier predicate, - Consumer consumer) { + private void overrideArrayIfPresent(Supplier predicate, Consumer consumer) { String[] strings = predicate.get(); if (strings.length > 0) { consumer.accept(strings); } } - private void overrideMapIfPresent(Supplier> predicate, - Consumer> consumer) { + private void overrideMapIfPresent(Supplier> predicate, Consumer> consumer) { Map strings = predicate.get(); if (!strings.isEmpty()) { consumer.accept(strings); } } - private void overrideListIfPresent(Supplier> predicate, - Consumer> consumer) { + private void overrideListIfPresent(Supplier> predicate, Consumer> consumer) { List strings = predicate.get(); if (!strings.isEmpty()) { consumer.accept(strings); diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/CompositeBomParser.java b/releaser-core/src/main/java/releaser/internal/buildsystem/CompositeBomParser.java index 4c978c0d..4c1d6448 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/CompositeBomParser.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/CompositeBomParser.java @@ -39,15 +39,13 @@ class CompositeBomParser implements BomParser { } private BomParser firstMatching(File thisProjectRoot) { - return this.parsers.stream().filter(b -> b.isApplicable(thisProjectRoot)) - .findFirst().orElseThrow( - () -> new IllegalStateException("Can't find a matching parser")); + return this.parsers.stream().filter(b -> b.isApplicable(thisProjectRoot)).findFirst() + .orElseThrow(() -> new IllegalStateException("Can't find a matching parser")); } @Override public List customBomParsers() { - return this.parsers.stream().flatMap(b -> b.customBomParsers().stream()) - .collect(Collectors.toList()); + return this.parsers.stream().flatMap(b -> b.customBomParsers().stream()).collect(Collectors.toList()); } } diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/CustomBomParser.java b/releaser-core/src/main/java/releaser/internal/buildsystem/CustomBomParser.java index 425c5790..ae9daf03 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/CustomBomParser.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/CustomBomParser.java @@ -28,8 +28,7 @@ import releaser.internal.project.Project; */ public interface CustomBomParser { - CustomBomParser NO_OP = (thisProjectRoot, - properties) -> VersionsFromBom.EMPTY_VERSION; + CustomBomParser NO_OP = (thisProjectRoot, properties) -> VersionsFromBom.EMPTY_VERSION; /** * When parsing a part of the BOM pom, one can add custom logic to perform project @@ -48,8 +47,7 @@ public interface CustomBomParser { * @param version - version of the project * @return - a new collection with the modified versions from bom */ - default Set setVersion(Set projects, String projectName, - String version) { + default Set setVersion(Set projects, String projectName, String version) { return new LinkedHashSet<>(projects); } diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleBomParser.java b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleBomParser.java index 43818eeb..ec7e3233 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleBomParser.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleBomParser.java @@ -33,8 +33,7 @@ class GradleBomParser implements BomParser { private final GradleProjectNameExtractor extractor = new GradleProjectNameExtractor(); - GradleBomParser(ReleaserProperties releaserProperties, - List customParsers) { + GradleBomParser(ReleaserProperties releaserProperties, List customParsers) { this.properties = releaserProperties; this.customParsers = customParsers; } @@ -55,11 +54,9 @@ class GradleBomParser implements BomParser { return VersionsFromBom.EMPTY_VERSION; } Properties properties = loadProps(gradleProperties); - final Map substitution = this.properties.getGradle() - .getGradlePropsSubstitution(); - VersionsFromBom versionsFromBom = new VersionsFromBomBuilder() - .thisProjectRoot(thisProjectRoot).releaserProperties(this.properties) - .parsers(this.customParsers).retrieveFromBom(); + final Map substitution = this.properties.getGradle().getGradlePropsSubstitution(); + VersionsFromBom versionsFromBom = new VersionsFromBomBuilder().thisProjectRoot(thisProjectRoot) + .releaserProperties(this.properties).parsers(this.customParsers).retrieveFromBom(); properties.forEach((key, value) -> { String projectName = this.extractor.projectName(substitution, key); versionsFromBom.setVersion(projectName, value.toString()); diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleProjectNameExtractor.java b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleProjectNameExtractor.java index 2ab074c2..ee133fec 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleProjectNameExtractor.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleProjectNameExtractor.java @@ -22,8 +22,7 @@ import java.util.regex.Pattern; class GradleProjectNameExtractor { - private static final Pattern VERSION_PATTERN = Pattern - .compile("^([a-zA-Z0-9]+)Version$"); + private static final Pattern VERSION_PATTERN = Pattern.compile("^([a-zA-Z0-9]+)Version$"); String projectName(Map substitution, Object key) { String projectName = key.toString(); 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 0db4ca0a..31cfdfcb 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/GradleUpdater.java @@ -55,18 +55,16 @@ public class GradleUpdater { * @param versionFromBom - version for the project from Spring Cloud Release * @param assertVersions - should snapshots / milestone / rc presence be asserted */ - public void updateProjectFromReleaseTrain(ReleaserProperties properties, - File projectRoot, Projects projects, ProjectVersion versionFromBom, - boolean assertVersions) { - processAllGradleProps(properties, projectRoot, projects, versionFromBom, - assertVersions); + public void updateProjectFromReleaseTrain(ReleaserProperties properties, File projectRoot, Projects projects, + ProjectVersion versionFromBom, boolean assertVersions) { + processAllGradleProps(properties, projectRoot, projects, versionFromBom, assertVersions); } - private void processAllGradleProps(ReleaserProperties properties, File projectRoot, - Projects projects, ProjectVersion versionFromBom, boolean assertVersions) { + private void processAllGradleProps(ReleaserProperties properties, File projectRoot, Projects projects, + ProjectVersion versionFromBom, boolean assertVersions) { try { - Files.walkFileTree(projectRoot.toPath(), new GradlePropertiesWalker( - properties, projects, versionFromBom, assertVersions)); + Files.walkFileTree(projectRoot.toPath(), + new GradlePropertiesWalker(properties, projects, versionFromBom, assertVersions)); } catch (IOException e) { throw new IllegalStateException(e); @@ -89,15 +87,13 @@ public class GradleUpdater { private final GradleProjectNameExtractor extractor = new GradleProjectNameExtractor(); - private GradlePropertiesWalker(ReleaserProperties properties, Projects projects, - ProjectVersion versionFromBom, boolean assertVersions) { + private GradlePropertiesWalker(ReleaserProperties properties, Projects projects, ProjectVersion versionFromBom, + boolean assertVersions) { this.properties = properties; this.projects = projects; - List unacceptableVersionPatterns = versionFromBom - .unacceptableVersionPatterns(); + List unacceptableVersionPatterns = versionFromBom.unacceptableVersionPatterns(); this.unacceptableVersionPatterns = unacceptableVersionPatterns; - this.skipVersionAssert = !assertVersions - || unacceptableVersionPatterns.isEmpty(); + this.skipVersionAssert = !assertVersions || unacceptableVersionPatterns.isEmpty(); this.assertVersions = assertVersions; } @@ -106,20 +102,15 @@ public class GradleUpdater { File file = path.toFile(); if (GRADLE_PROPERTIES.equals(file.getName())) { if (pathIgnored(file)) { - log.debug( - "Ignoring file [{}] since it's on a list of patterns to ignore", - file); + log.debug("Ignoring file [{}] since it's on a list of patterns to ignore", file); return FileVisitResult.CONTINUE; } String parentName = file.getParentFile().getName(); - log.info("Will process the file [{}] and update its gradle properties", - file); + log.info("Will process the file [{}] and update its gradle properties", file); final String fileContents = asString(path); - final AtomicReference changedString = new AtomicReference<>( - fileContents); + final AtomicReference changedString = new AtomicReference<>(fileContents); Properties props = loadProps(file); - final Map substitution = this.properties.getGradle() - .getGradlePropsSubstitution(); + final Map substitution = this.properties.getGradle().getGradlePropsSubstitution(); props.forEach((key, value1) -> { String projectName = projectName(parentName, substitution, key); if (!this.projects.containsProject(projectName)) { @@ -130,10 +121,8 @@ public class GradleUpdater { } ProjectVersion value = this.projects.forName(projectName); if (!value.version.equalsIgnoreCase(value1.toString())) { - log.info("Replacing [{}->{}] with [{}->{}]", key, value1, key, - value); - changedString.set(changedString.get().replace(key + "=" + value1, - key + "=" + value)); + log.info("Replacing [{}->{}] with [{}->{}]", key, value1, key, value); + changedString.set(changedString.get().replace(key + "=" + value1, key + "=" + value)); } }); storeString(path, changedString.get()); @@ -142,8 +131,7 @@ public class GradleUpdater { return FileVisitResult.CONTINUE; } - private String projectName(String parentName, Map substitution, - Object key) { + private String projectName(String parentName, Map substitution, Object key) { // version -> current project version if (key.equals("version")) { return parentName; @@ -155,21 +143,18 @@ public class GradleUpdater { if (this.assertVersions && !this.skipVersionAssert) { log.debug( "Update should check if no wrong versions remained in the gradle prop. List of wrong patterns: {}", - this.unacceptableVersionPatterns.stream().map(Pattern::pattern) - .collect(Collectors.toList())); + this.unacceptableVersionPatterns.stream().map(Pattern::pattern).collect(Collectors.toList())); Scanner scanner = new Scanner(asString(path)); int lineNumber = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); lineNumber++; Pattern matchingPattern = this.unacceptableVersionPatterns.stream() - .filter(pattern -> pattern.matcher(line).matches()) - .findFirst().orElse(null); + .filter(pattern -> pattern.matcher(line).matches()).findFirst().orElse(null); if (matchingPattern != null) { - throw new IllegalStateException("The file [" + path - + "] matches the [ " + matchingPattern.pattern() - + "] pattern in line number [" + lineNumber + "]\n\n" - + line); + throw new IllegalStateException( + "The file [" + path + "] matches the [ " + matchingPattern.pattern() + + "] pattern in line number [" + lineNumber + "]\n\n" + line); } } log.info("No invalid versions remained in the gradle properties"); @@ -178,8 +163,8 @@ public class GradleUpdater { private boolean pathIgnored(File file) { String path = file.getPath(); - return this.assertVersions && this.properties.getGradle() - .getIgnoredGradleRegex().stream().anyMatch(path::matches); + return this.assertVersions + && this.properties.getGradle().getIgnoredGradleRegex().stream().anyMatch(path::matches); } private Properties loadProps(File file) { diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/MavenBomParser.java b/releaser-core/src/main/java/releaser/internal/buildsystem/MavenBomParser.java index ba106ada..494e11ae 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/MavenBomParser.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/MavenBomParser.java @@ -50,10 +50,8 @@ class MavenBomParser implements BomParser { MavenBomParser(ReleaserProperties properties, List customParsers) { this.thisTrainBomLocation = properties.getPom().getThisTrainBom(); - this.versionPattern = StringUtils - .hasText(properties.getPom().getBomVersionPattern()) - ? Pattern.compile(properties.getPom().getBomVersionPattern()) - : Pattern.compile(".*"); + this.versionPattern = StringUtils.hasText(properties.getPom().getBomVersionPattern()) + ? Pattern.compile(properties.getPom().getBomVersionPattern()) : Pattern.compile(".*"); this.properties = properties; this.customParsers = customParsers; } @@ -71,13 +69,11 @@ class MavenBomParser implements BomParser { if (model == null) { return VersionsFromBom.EMPTY_VERSION; } - Set projects = model.getProperties().entrySet().stream() - .filter(propertyMatchesVersionPattern()).map(toProject()) - .collect(Collectors.toSet()); + Set projects = model.getProperties().entrySet().stream().filter(propertyMatchesVersionPattern()) + .map(toProject()).collect(Collectors.toSet()); String releaseTrainProjectVersion = model.getVersion(); projects.add( - new Project(this.properties.getMetaRelease().getReleaseTrainProjectName(), - releaseTrainProjectVersion)); + new Project(this.properties.getMetaRelease().getReleaseTrainProjectName(), releaseTrainProjectVersion)); // @formatter:off return new VersionsFromBomBuilder() .thisProjectRoot(thisProjectRoot) diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/PomUpdater.java b/releaser-core/src/main/java/releaser/internal/buildsystem/PomUpdater.java index 712d9f58..41706f26 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/PomUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/PomUpdater.java @@ -75,13 +75,10 @@ class PomUpdater { } String artifactId = artifactId(model); if (!versionsFromBom.shouldBeUpdated(artifactId)) { - log.info( - "Skipping project [{}] since it's not on the list of projects to update", - model.getArtifactId()); + log.info("Skipping project [{}] since it's not on the list of projects to update", model.getArtifactId()); return false; } - log.info("Project [{}] will have its dependencies updated", - model.getArtifactId()); + log.info("Project [{}] will have its dependencies updated", model.getArtifactId()); return true; } @@ -95,8 +92,7 @@ class PomUpdater { return false; } boolean plugins = model.getBuild().getPlugins().stream() - .filter(plugin -> "maven-deploy-plugin" - .equalsIgnoreCase(plugin.getArtifactId())) + .filter(plugin -> "maven-deploy-plugin".equalsIgnoreCase(plugin.getArtifactId())) .map(this::skipFromConfiguration).findFirst().orElse(false); if (plugins) { return true; @@ -105,8 +101,7 @@ class PomUpdater { return false; } return model.getBuild().getPluginManagement().getPlugins().stream() - .filter(plugin -> "maven-deploy-plugin" - .equalsIgnoreCase(plugin.getArtifactId())) + .filter(plugin -> "maven-deploy-plugin".equalsIgnoreCase(plugin.getArtifactId())) .map(this::skipFromConfiguration).findFirst().orElse(false); } @@ -131,8 +126,7 @@ class PomUpdater { if (!parent) { return model.getArtifactId(); } - return model.getArtifactId().substring(0, - model.getArtifactId().indexOf("-parent")); + return model.getArtifactId().substring(0, model.getArtifactId().indexOf("-parent")); } ModelWrapper readModel(File pom) { @@ -146,14 +140,11 @@ class PomUpdater { * @param versionsFromBom - versions to update * @return updated model */ - ModelWrapper updateModel(ModelWrapper rootPom, File pom, - VersionsFromBom versionsFromBom) { + ModelWrapper updateModel(ModelWrapper rootPom, File pom, VersionsFromBom versionsFromBom) { Model model = PomReader.readPom(pom); List sourceChanges = new ArrayList<>(); - sourceChanges = updateParentIfPossible(rootPom, versionsFromBom, model, - sourceChanges); - sourceChanges = updateVersionIfPossible(rootPom, versionsFromBom, model, - sourceChanges); + sourceChanges = updateParentIfPossible(rootPom, versionsFromBom, model, sourceChanges); + sourceChanges = updateVersionIfPossible(rootPom, versionsFromBom, model, sourceChanges); return new ModelWrapper(model, sourceChanges, versionsFromBom, pom); } @@ -162,8 +153,7 @@ class PomUpdater { * changes in the model. * @return - the pom file */ - File overwritePomIfDirty(ModelWrapper updatedPomModel, - VersionsFromBom versionsFromBom, File pom) { + File overwritePomIfDirty(ModelWrapper updatedPomModel, VersionsFromBom versionsFromBom, File pom) { if (updatedPomModel.isDirty()) { log.debug("There were changes in the pom so file will be overridden"); this.pomWriter.write(updatedPomModel, versionsFromBom, pom); @@ -172,9 +162,8 @@ class PomUpdater { return pom; } - private List updateParentIfPossible(ModelWrapper wrapper, - VersionsFromBom versionsFromBom, Model model, - List sourceChanges) { + private List updateParentIfPossible(ModelWrapper wrapper, VersionsFromBom versionsFromBom, + Model model, List sourceChanges) { String rootProjectName = wrapper.projectName(); List changes = new ArrayList<>(sourceChanges); if (model.getParent() == null || isEmpty(model.getParent().getVersion())) { @@ -183,8 +172,7 @@ class PomUpdater { } String parentGroupId = model.getParent().getGroupId(); String parentArtifactId = model.getParent().getArtifactId(); - log.debug("Searching for a version of parent [{}:{}]", parentGroupId, - parentArtifactId); + log.debug("Searching for a version of parent [{}:{}]", parentGroupId, parentArtifactId); String oldVersion = model.getParent().getVersion(); String version = versionsFromBom.versionForProject(parentArtifactId); log.debug("Found version is [{}]", version); @@ -193,38 +181,32 @@ class PomUpdater { version = versionsFromBom.versionForProject(rootProjectName); } else { - log.warn("There is no info on the [{}:{}] version", parentGroupId, - parentArtifactId); + log.warn("There is no info on the [{}:{}] version", parentGroupId, parentArtifactId); return changes; } } if (oldVersion.equals(version)) { - log.debug( - "Won't update the version of parent [{}:{}] since you're already using the proper one", + log.debug("Won't update the version of parent [{}:{}] since you're already using the proper one", parentGroupId, parentArtifactId); return changes; } - log.info("Setting version of parent [{}] to [{}] for module [{}]", - parentArtifactId, version, model.getArtifactId()); + log.info("Setting version of parent [{}] to [{}] for module [{}]", parentArtifactId, version, + model.getArtifactId()); if (hasText(version)) { - changes.add(new VersionChange(parentGroupId, parentArtifactId, oldVersion, - version)); + changes.add(new VersionChange(parentGroupId, parentArtifactId, oldVersion, version)); } return changes; } - private List updateVersionIfPossible(ModelWrapper wrapper, - VersionsFromBom versionsFromBom, Model model, - List sourceChanges) { + private List updateVersionIfPossible(ModelWrapper wrapper, VersionsFromBom versionsFromBom, + Model model, List sourceChanges) { String rootProjectName = wrapper.projectName(); String rootProjectGroupId = wrapper.groupId(); List changes = new ArrayList<>(sourceChanges); String groupId = groupId(model); String artifactId = model.getArtifactId(); - if (model.getGroupId() != null - && !model.getGroupId().equals(rootProjectGroupId)) { - log.info( - "Will not update project [{}] since its group id [{}] is not equal the parent group id [{}]", + if (model.getGroupId() != null && !model.getGroupId().equals(rootProjectGroupId)) { + log.info("Will not update project [{}] since its group id [{}] is not equal the parent group id [{}]", model.getArtifactId(), model.getGroupId(), rootProjectGroupId); return changes; } @@ -233,15 +215,13 @@ class PomUpdater { String version = versionsFromBom.versionForProject(rootProjectName); log.debug("Found version is [{}]", version); if (isEmpty(version) || isEmpty(model.getVersion())) { - log.debug( - "There was no version set for project [{}], skipping version setting for module [{}]", + log.debug("There was no version set for project [{}], skipping version setting for module [{}]", rootProjectName, model.getArtifactId()); return changes; } if (oldVersion.equals(version)) { - log.debug( - "Won't update the version of module [{}]:[{}] since you're already using the proper one", - groupId, artifactId); + log.debug("Won't update the version of module [{}]:[{}] since you're already using the proper one", groupId, + artifactId); return changes; } log.info("Setting [{}] version to [{}]", artifactId, version); @@ -271,8 +251,7 @@ class ModelWrapper { final File rootFile; - ModelWrapper(Model model, List sourceChanges, - VersionsFromBom versionsFromBom, File rootFile) { + ModelWrapper(Model model, List sourceChanges, VersionsFromBom versionsFromBom, File rootFile) { this.model = model; this.versionsFromBom = versionsFromBom; this.sourceChanges.addAll(sourceChanges); @@ -303,8 +282,7 @@ class ModelWrapper { } boolean isDirty() { - return !this.sourceChanges.isEmpty() - || this.versionsFromBom.shouldSetProperty(this.model.getProperties()); + return !this.sourceChanges.isEmpty() || this.versionsFromBom.shouldSetProperty(this.model.getProperties()); } } @@ -322,17 +300,13 @@ class PomWriter { LoggerToMavenLog loggerToMavenLog = new LoggerToMavenLog(PomWriter.log); versionChangerFactory.setLog(loggerToMavenLog); versionChangerFactory.setModel(wrapper.model); - log.info( - "Applying version / parent / plugin / project changes to the pom [{}]", - pom); - VersionChanger changer = versionChangerFactory.newVersionChanger(true, true, - true, true); + log.info("Applying version / parent / plugin / project changes to the pom [{}]", pom); + VersionChanger changer = versionChangerFactory.newVersionChanger(true, true, true, true); for (VersionChange versionChange : wrapper.sourceChanges) { changer.apply(versionChange); } log.debug("Applying properties changes to the pom [{}]", pom); - new PropertyVersionChanger(wrapper, versionsFromBom, parsedPom, - loggerToMavenLog).apply(null); + new PropertyVersionChanger(wrapper, versionsFromBom, parsedPom, loggerToMavenLog).apply(null); try (BufferedWriter bw = new BufferedWriter(new FileWriter(pom))) { bw.write(input.toString()); } @@ -370,15 +344,15 @@ class PropertyVersionChanger extends AbstractVersionChanger { private final PropertyStorer propertyStorer; - PropertyVersionChanger(ModelWrapper wrapper, VersionsFromBom versionsFromBom, - ModifiedPomXMLEventReader pom, Log log) { + PropertyVersionChanger(ModelWrapper wrapper, VersionsFromBom versionsFromBom, ModifiedPomXMLEventReader pom, + Log log) { super(wrapper.model, pom, log); this.versionsFromBom = versionsFromBom; this.propertyStorer = new PropertyStorer(log, pom); } - PropertyVersionChanger(ModelWrapper wrapper, VersionsFromBom versionsFromBom, - ModifiedPomXMLEventReader pom, Log log, PropertyStorer propertyStorer) { + PropertyVersionChanger(ModelWrapper wrapper, VersionsFromBom versionsFromBom, ModifiedPomXMLEventReader pom, + Log log, PropertyStorer propertyStorer) { super(wrapper.model, pom, log); this.versionsFromBom = versionsFromBom; this.propertyStorer = propertyStorer; @@ -417,8 +391,7 @@ class PropertyStorer { void setPropertyVersionIfApplicable(Project project) { String propertyName = propertyName(project); if (setPropertyVersion(propertyName, project.version)) { - this.log.info("Updating property [" + propertyName + "] to version [" - + project.version + "]"); + this.log.info("Updating property [" + propertyName + "] to version [" + project.version + "]"); } } @@ -429,8 +402,7 @@ class PropertyStorer { private boolean setPropertyVersion(String propertyName, String version) { try { if (StringUtils.isEmpty(version)) { - this.log.warn( - "Version for [" + propertyName + "] is empty. Will not set it"); + this.log.warn("Version for [" + propertyName + "] is empty. Will not set it"); return false; } return PomHelper.setPropertyVersion(this.pom, null, propertyName, version); 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 abe97711..1a3e5e28 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/ProjectPomUpdater.java @@ -46,8 +46,7 @@ import releaser.internal.project.Projects; */ public class ProjectPomUpdater implements Closeable { - private static final List IGNORED_SNAPSHOT_LINE_PATTERNS = Arrays.asList( - "^.*replace=.*$", + private static final List IGNORED_SNAPSHOT_LINE_PATTERNS = Arrays.asList("^.*replace=.*$", // issue [#80] "^[\\s]*.*$"); @@ -79,8 +78,7 @@ public class ProjectPomUpdater implements Closeable { * @return projects retrieved from the release train bom */ public Projects retrieveVersionsFromReleaseTrainBom() { - return retrieveVersionsFromReleaseTrainBom(this.properties.getPom().getBranch(), - UPDATE_FIXED_VERSIONS); + return retrieveVersionsFromReleaseTrainBom(this.properties.getPom().getBranch(), UPDATE_FIXED_VERSIONS); } /** @@ -92,12 +90,10 @@ public class ProjectPomUpdater implements Closeable { * @return projects retrieved from the release train bom */ // TODO: I don't like this flag but don't have a better idea - public Projects retrieveVersionsFromReleaseTrainBom(String branch, - boolean updateFixedVersions) { + public Projects retrieveVersionsFromReleaseTrainBom(String branch, boolean updateFixedVersions) { VersionsFromBom versionsFromBom = cachedVersionFromBom(branch); if (updateFixedVersions) { - log.info("Will update the following versions manually [{}]", - this.properties.getFixedVersions()); + log.info("Will update the following versions manually [{}]", this.properties.getFixedVersions()); this.properties.getFixedVersions().forEach(versionsFromBom::setVersion); } log.info("Retrieved the following versions\n{}", versionsFromBom); @@ -121,14 +117,12 @@ public class ProjectPomUpdater implements Closeable { */ public Projects fixedVersions() { Set projects = this.properties.getFixedVersions().entrySet().stream() - .map(entry -> new Project(entry.getKey(), entry.getValue())) - .collect(Collectors.toSet()); + .map(entry -> new Project(entry.getKey(), entry.getValue())).collect(Collectors.toSet()); if (log.isDebugEnabled()) { log.debug("Will apply the following fixed versions {}", projects); } return new VersionsFromBomBuilder().releaserProperties(this.properties) - .parsers(compositeBomParser().customBomParsers()).projects(projects) - .merged().toProjectVersions(); + .parsers(compositeBomParser().customBomParsers()).projects(projects).merged().toProjectVersions(); } /** @@ -143,9 +137,8 @@ public class ProjectPomUpdater implements Closeable { */ public void updateProjectFromReleaseTrain(File projectRoot, Projects projects, ProjectVersion versionFromReleaseTrain, boolean assertVersions) { - VersionsFromBom versionsFromBom = new VersionsFromBomBuilder() - .thisProjectRoot(projectRoot).releaserProperties(this.properties) - .projects(projects.asProjects()).merged(); + VersionsFromBom versionsFromBom = new VersionsFromBomBuilder().thisProjectRoot(projectRoot) + .releaserProperties(this.properties).projects(projects.asProjects()).merged(); if (!this.pomUpdater.shouldProjectBeUpdated(projectRoot, versionsFromBom)) { log.debug("Skipping project updating"); return; @@ -153,16 +146,16 @@ public class ProjectPomUpdater implements Closeable { updatePoms(projectRoot, versionsFromBom, versionFromReleaseTrain, assertVersions); } - private void updatePoms(File projectRoot, VersionsFromBom projects, - ProjectVersion versionFromScRelease, boolean assertVersions) { + private void updatePoms(File projectRoot, VersionsFromBom projects, ProjectVersion versionFromScRelease, + boolean assertVersions) { File rootPom = new File(projectRoot, "pom.xml"); if (!rootPom.exists()) { log.info("No pom.xml present, skipping!"); return; } ModelWrapper rootPomModel = this.pomUpdater.readModel(rootPom); - processAllPoms(projectRoot, new PomWalker(rootPomModel, projects, this.pomUpdater, - this.properties, versionFromScRelease, assertVersions)); + processAllPoms(projectRoot, new PomWalker(rootPomModel, projects, this.pomUpdater, this.properties, + versionFromScRelease, assertVersions)); } private void processAllPoms(File projectRoot, PomWalker pomWalker) { @@ -197,18 +190,15 @@ public class ProjectPomUpdater implements Closeable { private final List unacceptableVersionPatterns; - private PomWalker(ModelWrapper rootPom, VersionsFromBom projects, - PomUpdater pomUpdater, ReleaserProperties properties, - ProjectVersion versionFromScRelease, boolean assertVersions) { + private PomWalker(ModelWrapper rootPom, VersionsFromBom projects, PomUpdater pomUpdater, + ReleaserProperties properties, ProjectVersion versionFromScRelease, boolean assertVersions) { this.rootPom = rootPom; this.versionsFromBom = projects; this.pomUpdater = pomUpdater; this.properties = properties; - List unacceptableVersionPatterns = versionFromScRelease - .unacceptableVersionPatterns(); + List unacceptableVersionPatterns = versionFromScRelease.unacceptableVersionPatterns(); this.unacceptableVersionPatterns = unacceptableVersionPatterns; - this.skipVersionAssert = !assertVersions - || unacceptableVersionPatterns.isEmpty(); + this.skipVersionAssert = !assertVersions || unacceptableVersionPatterns.isEmpty(); this.assertVersions = assertVersions; } @@ -217,28 +207,21 @@ public class ProjectPomUpdater implements Closeable { File file = path.toFile(); if (POM_XML.equals(file.getName())) { if (pathIgnored(file)) { - log.debug( - "Ignoring file [{}] since it's on a list of patterns to ignore", - file); + log.debug("Ignoring file [{}] since it's on a list of patterns to ignore", file); return FileVisitResult.CONTINUE; } - ModelWrapper model = this.pomUpdater.updateModel(this.rootPom, file, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(this.rootPom, file, this.versionsFromBom); this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, file); - if (this.assertVersions && !this.skipVersionAssert - && !this.pomUpdater.hasSkipDeployment(model.model)) { - log.debug( - "Update is a non-snapshot one. Checking if no snapshot versions remained in the pom"); + if (this.assertVersions && !this.skipVersionAssert && !this.pomUpdater.hasSkipDeployment(model.model)) { + log.debug("Update is a non-snapshot one. Checking if no snapshot versions remained in the pom"); String text = asString(path); Scanner scanner = new Scanner(text); int lineNumber = 0; while (scanner.hasNextLine()) { String line = scanner.nextLine(); lineNumber++; - Pattern matchingPattern = this.unacceptableVersionPatterns - .stream() - .filter(pattern -> IGNORED_SNAPSHOT_LINE_PATTERNS.stream() - .noneMatch(line::matches) + Pattern matchingPattern = this.unacceptableVersionPatterns.stream() + .filter(pattern -> IGNORED_SNAPSHOT_LINE_PATTERNS.stream().noneMatch(line::matches) && !line.contains(SPECIAL_LINE_IGNORING_COMMENT) && pattern.matcher(line).lookingAt()) .findFirst().orElse(null); @@ -246,10 +229,9 @@ public class ProjectPomUpdater implements Closeable { if (log.isDebugEnabled()) { log.debug("File text \n" + text); } - throw new IllegalStateException("The file [" + path - + "] matches the [ " + matchingPattern.pattern() - + "] pattern in line number [" + lineNumber + "]\n\n" - + line); + throw new IllegalStateException( + "The file [" + path + "] matches the [ " + matchingPattern.pattern() + + "] pattern in line number [" + lineNumber + "]\n\n" + line); } } log.info("No invalid versions remained in the pom"); @@ -260,8 +242,8 @@ public class ProjectPomUpdater implements Closeable { private boolean pathIgnored(File file) { String path = file.getPath(); - return this.assertVersions && this.properties.getPom().getIgnoredPomRegex() - .stream().anyMatch(path::matches); + return this.assertVersions + && this.properties.getPom().getIgnoredPomRegex().stream().anyMatch(path::matches); } private String asString(Path path) { diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBom.java b/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBom.java index 16430296..7fbce8c9 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBom.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBom.java @@ -56,15 +56,13 @@ public class VersionsFromBom { this.parser = parser; } - VersionsFromBom(ReleaserProperties releaserProperties, CustomBomParser parser, - Set projects) { + VersionsFromBom(ReleaserProperties releaserProperties, CustomBomParser parser, Set projects) { this.properties = releaserProperties; this.parser = parser; projects.forEach(project -> setVersion(project.name, project.version)); } - VersionsFromBom(ReleaserProperties releaserProperties, CustomBomParser parser, - VersionsFromBom... projects) { + VersionsFromBom(ReleaserProperties releaserProperties, CustomBomParser parser, VersionsFromBom... projects) { this.properties = releaserProperties; this.parser = parser; Arrays.stream(projects).forEach(p -> this.projects.addAll(p.projects)); @@ -84,23 +82,20 @@ public class VersionsFromBom { } public String versionForProject(String projectName) { - return this.projects.stream().filter(project -> nameMatches(projectName, project)) - .findFirst().orElse(Project.EMPTY_PROJECT).version; + return this.projects.stream().filter(project -> nameMatches(projectName, project)).findFirst() + .orElse(Project.EMPTY_PROJECT).version; } public boolean shouldBeUpdated(String projectName) { - return this.projects.stream() - .anyMatch(project -> nameMatches(projectName, project)); + return this.projects.stream().anyMatch(project -> nameMatches(projectName, project)); } public boolean shouldSetProperty(Properties properties) { - return this.projects.stream() - .anyMatch(project -> properties.containsKey(project.name + ".version")); + return this.projects.stream().anyMatch(project -> properties.containsKey(project.name + ".version")); } public Projects toProjectVersions() { - return this.projects.stream() - .map(project -> new ProjectVersion(project.name, project.version)) + return this.projects.stream().map(project -> new ProjectVersion(project.name, project.version)) .collect(Collectors.toCollection(Projects::new)); } @@ -114,23 +109,18 @@ public class VersionsFromBom { } boolean parent = matchesNameWithSuffix(projectName, "-parent", project); boolean bomArtifactId = comparisonOfBomArtifactAndParent(projectName, project); - return !bomArtifactId && (parent - || matchesNameWithSuffix(projectName, "-dependencies", project)); + return !bomArtifactId && (parent || matchesNameWithSuffix(projectName, "-dependencies", project)); } - private boolean comparisonOfBomArtifactAndParent(String projectName, - Project project) { - return artifactOrParent(projectName, project.name) - || artifactOrParent(project.name, projectName); + private boolean comparisonOfBomArtifactAndParent(String projectName, Project project) { + return artifactOrParent(projectName, project.name) || artifactOrParent(project.name, projectName); } private boolean artifactOrParent(String projectName, String otherProjectName) { - return projectName.equals(dependenciesArtifactId()) - && otherProjectName.equals(dependenciesParentArtifactId()); + return projectName.equals(dependenciesArtifactId()) && otherProjectName.equals(dependenciesParentArtifactId()); } - private boolean matchesNameWithSuffix(String projectName, String suffix, - Project project) { + private boolean matchesNameWithSuffix(String projectName, String suffix, Project project) { boolean containsSuffix = projectName.endsWith(suffix); if (!containsSuffix) { return false; @@ -157,8 +147,7 @@ public class VersionsFromBom { } private List bomVersionProjectNames() { - List names = new ArrayList<>( - this.properties.getMetaRelease().getReleaseTrainDependencyNames()); + List names = new ArrayList<>(this.properties.getMetaRelease().getReleaseTrainDependencyNames()); names.add(this.properties.getMetaRelease().getReleaseTrainProjectName()); return names; } @@ -184,8 +173,7 @@ public class VersionsFromBom { @Override public String toString() { - return "Projects=\n\t" + this.projects.stream().map(Object::toString) - .collect(Collectors.joining("\n\t")); + return "Projects=\n\t" + this.projects.stream().map(Object::toString).collect(Collectors.joining("\n\t")); } } diff --git a/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBomBuilder.java b/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBomBuilder.java index f749ff84..731d2615 100644 --- a/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBomBuilder.java +++ b/releaser-core/src/main/java/releaser/internal/buildsystem/VersionsFromBomBuilder.java @@ -42,8 +42,7 @@ public class VersionsFromBomBuilder { return this; } - public VersionsFromBomBuilder releaserProperties( - ReleaserProperties releaserProperties) { + public VersionsFromBomBuilder releaserProperties(ReleaserProperties releaserProperties) { this.releaserProperties = releaserProperties; return this; } @@ -68,8 +67,7 @@ public class VersionsFromBomBuilder { if (!this.projects.isEmpty()) { return new VersionsFromBom(this.releaserProperties, bomParser, this.projects); } - return new VersionsFromBom(this.releaserProperties, bomParser, - this.versionsFromBom); + return new VersionsFromBom(this.releaserProperties, bomParser, this.versionsFromBom); } public VersionsFromBom retrieveFromBom() { @@ -77,13 +75,11 @@ public class VersionsFromBomBuilder { CustomBomParser bomParser = parser(); VersionsFromBom versionsFromBom = versionsFromBom(bomParser); VersionsFromBom customParsing = customParsing(thisProjectRoot); - return new VersionsFromBom(this.releaserProperties, bomParser, versionsFromBom, - customParsing); + return new VersionsFromBom(this.releaserProperties, bomParser, versionsFromBom, customParsing); } private File thisProjectRoot() { - return this.thisProjectRoot != null ? this.thisProjectRoot - : new File(this.releaserProperties.getWorkingDir()); + return this.thisProjectRoot != null ? this.thisProjectRoot : new File(this.releaserProperties.getWorkingDir()); } private CustomBomParser parser() { @@ -95,20 +91,16 @@ public class VersionsFromBomBuilder { return new VersionsFromBom(this.releaserProperties, bomParser, this.projects); } else if (this.versionsFromBom.length != 0) { - return new VersionsFromBom(this.releaserProperties, bomParser, - this.versionsFromBom); + return new VersionsFromBom(this.releaserProperties, bomParser, this.versionsFromBom); } return new VersionsFromBom(this.releaserProperties, bomParser); } private VersionsFromBom customParsing(File thisProjectRoot) { - return this.parsers.stream() - .map(p -> p.parseBom(thisProjectRoot, this.releaserProperties)) - .reduce((versionsFromBom, - versionsFromBom2) -> new VersionsFromBomBuilder() - .parsers(this.parsers).thisProjectRoot(thisProjectRoot) - .releaserProperties(this.releaserProperties) - .projects(versionsFromBom, versionsFromBom2).merged()) + return this.parsers.stream().map(p -> p.parseBom(thisProjectRoot, this.releaserProperties)) + .reduce((versionsFromBom, versionsFromBom2) -> new VersionsFromBomBuilder().parsers(this.parsers) + .thisProjectRoot(thisProjectRoot).releaserProperties(this.releaserProperties) + .projects(versionsFromBom, versionsFromBom2).merged()) .orElse(VersionsFromBom.EMPTY_VERSION); } diff --git a/releaser-core/src/main/java/releaser/internal/docs/CustomProjectDocumentationUpdater.java b/releaser-core/src/main/java/releaser/internal/docs/CustomProjectDocumentationUpdater.java index 67214269..8b34037a 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/CustomProjectDocumentationUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/CustomProjectDocumentationUpdater.java @@ -32,14 +32,14 @@ public interface CustomProjectDocumentationUpdater { CustomProjectDocumentationUpdater NO_OP = new CustomProjectDocumentationUpdater() { @Override - public File updateDocsRepoForReleaseTrain(File clonedDocumentationProject, - ProjectVersion currentProject, Projects projects, String bomBranch) { + public File updateDocsRepoForReleaseTrain(File clonedDocumentationProject, ProjectVersion currentProject, + Projects projects, String bomBranch) { return clonedDocumentationProject; } @Override - public File updateDocsRepoForSingleProject(File clonedDocumentationProject, - ProjectVersion currentProject, Projects projects) { + public File updateDocsRepoForSingleProject(File clonedDocumentationProject, ProjectVersion currentProject, + Projects projects) { return clonedDocumentationProject; } }; @@ -53,8 +53,8 @@ public interface CustomProjectDocumentationUpdater { * @return {@link File cloned temporary directory} - {@code null} if wrong version is * used */ - File updateDocsRepoForReleaseTrain(File clonedDocumentationProject, - ProjectVersion currentProject, Projects projects, String bomBranch); + File updateDocsRepoForReleaseTrain(File clonedDocumentationProject, ProjectVersion currentProject, + Projects projects, String bomBranch); /** * Updates the documentation repository for a single project. @@ -64,7 +64,7 @@ public interface CustomProjectDocumentationUpdater { * @return {@link File cloned temporary directory} - {@code null} if wrong version is * used */ - File updateDocsRepoForSingleProject(File clonedDocumentationProject, - ProjectVersion currentProject, Projects projects); + File updateDocsRepoForSingleProject(File clonedDocumentationProject, ProjectVersion currentProject, + Projects projects); } 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 c347e938..f4fa8f7c 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/DocumentationUpdater.java @@ -33,17 +33,13 @@ public class DocumentationUpdater { private final ReleaseTrainContentsUpdater releaseTrainContentsUpdater; - public DocumentationUpdater(ProjectGitHandler gitHandler, - ReleaserProperties properties, TemplateGenerator templateGenerator, - List updaters) { - this.projectDocumentationUpdater = new ProjectDocumentationUpdater(properties, - gitHandler, updaters); - this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(properties, - gitHandler, templateGenerator); + public DocumentationUpdater(ProjectGitHandler gitHandler, ReleaserProperties properties, + TemplateGenerator templateGenerator, List updaters) { + this.projectDocumentationUpdater = new ProjectDocumentationUpdater(properties, gitHandler, updaters); + this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(properties, gitHandler, templateGenerator); } - DocumentationUpdater(ProjectDocumentationUpdater updater, - ReleaseTrainContentsUpdater contentsUpdater) { + DocumentationUpdater(ProjectDocumentationUpdater updater, ReleaseTrainContentsUpdater contentsUpdater) { this.projectDocumentationUpdater = updater; this.releaseTrainContentsUpdater = contentsUpdater; } 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 3d0262e9..272ece92 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/ProjectDocumentationUpdater.java @@ -31,8 +31,7 @@ import releaser.internal.project.Projects; */ class ProjectDocumentationUpdater { - private static final Logger log = LoggerFactory - .getLogger(ProjectDocumentationUpdater.class); + private static final Logger log = LoggerFactory.getLogger(ProjectDocumentationUpdater.class); private final ProjectGitHandler gitHandler; @@ -40,8 +39,7 @@ class ProjectDocumentationUpdater { private final ReleaserProperties properties; - ProjectDocumentationUpdater(ReleaserProperties properties, - ProjectGitHandler gitHandler, + ProjectDocumentationUpdater(ReleaserProperties properties, ProjectGitHandler gitHandler, List updaters) { this.gitHandler = gitHandler; this.properties = properties; @@ -50,44 +48,38 @@ class ProjectDocumentationUpdater { // Not needed any more cause all projects publish to docs.spring.io @Deprecated - public File updateDocsRepo(Projects projects, ProjectVersion currentProject, - String bomBranch) { + public File updateDocsRepo(Projects projects, ProjectVersion currentProject, String bomBranch) { if (!shouldUpdate(currentProject)) { return null; } File documentationProject = this.gitHandler.cloneDocumentationProject(); log.debug("Cloning the doc project to [{}]", documentationProject); - CustomProjectDocumentationUpdater updater = this.updaters.isEmpty() - ? CustomProjectDocumentationUpdater.NO_OP : this.updaters.get(0); - return updater.updateDocsRepoForReleaseTrain(documentationProject, currentProject, - projects, bomBranch); + CustomProjectDocumentationUpdater updater = this.updaters.isEmpty() ? CustomProjectDocumentationUpdater.NO_OP + : this.updaters.get(0); + return updater.updateDocsRepoForReleaseTrain(documentationProject, currentProject, projects, bomBranch); } // Not needed any more cause all projects publish to docs.spring.io @Deprecated - public File updateDocsRepoForSingleProject(Projects projects, - ProjectVersion currentProject) { + public File updateDocsRepoForSingleProject(Projects projects, ProjectVersion currentProject) { if (!shouldUpdate(currentProject)) { return null; } File documentationProject = this.gitHandler.cloneDocumentationProject(); log.debug("Cloning the doc project to [{}]", documentationProject); - CustomProjectDocumentationUpdater updater = this.updaters.isEmpty() - ? CustomProjectDocumentationUpdater.NO_OP : this.updaters.get(0); - return updater.updateDocsRepoForSingleProject(documentationProject, - currentProject, projects); + CustomProjectDocumentationUpdater updater = this.updaters.isEmpty() ? CustomProjectDocumentationUpdater.NO_OP + : this.updaters.get(0); + return updater.updateDocsRepoForSingleProject(documentationProject, currentProject, projects); } private boolean shouldUpdate(ProjectVersion currentProject) { if (!this.properties.getGit().isUpdateDocumentationRepo()) { - log.info( - "Will not update documentation repository, since the switch to do so " - + "is off. Set [releaser.git.update-documentation-repo] to [true] to change that"); + log.info("Will not update documentation repository, since the switch to do so " + + "is off. Set [releaser.git.update-documentation-repo] to [true] to change that"); return false; } if (!currentProject.isReleaseOrServiceRelease()) { - log.info( - "Will not update documentation repository for non release or service release [{}]", + log.info("Will not update documentation repository for non release or service release [{}]", currentProject.version); return false; } diff --git a/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContents.java b/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContents.java index 2d853dde..53068696 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContents.java +++ b/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContents.java @@ -39,8 +39,7 @@ public class ReleaseTrainContents { return false; } ReleaseTrainContents contents = (ReleaseTrainContents) o; - return Objects.equals(this.title, contents.title) - && Objects.equals(this.rows, contents.rows); + return Objects.equals(this.title, contents.title) && Objects.equals(this.rows, contents.rows); } @Override 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 3b5211fd..293b221e 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/docs/ReleaseTrainContentsUpdater.java @@ -39,8 +39,7 @@ import org.springframework.util.StringUtils; // TODO: [SPRING-CLOUD] class ReleaseTrainContentsUpdater { - private static final Logger log = LoggerFactory - .getLogger(ReleaseTrainContentsUpdater.class); + private static final Logger log = LoggerFactory.getLogger(ReleaseTrainContentsUpdater.class); private final ReleaseTrainContentsGitHandler handler; @@ -63,45 +62,33 @@ class ReleaseTrainContentsUpdater { * @param projects - set of project with versions to assert against */ File updateReleaseTrainWiki(Projects projects) { - if (!this.properties.getGit().isUpdateReleaseTrainWiki() - || !this.properties.getMetaRelease().isEnabled()) { - log.info( - "Will not clone and update the release train wiki, since the switch to do so " - + "is off or it's not a meta-release. Set [releaser.git.update-release-train-wiki] to [true] to change that"); + if (!this.properties.getGit().isUpdateReleaseTrainWiki() || !this.properties.getMetaRelease().isEnabled()) { + log.info("Will not clone and update the release train wiki, since the switch to do so " + + "is off or it's not a meta-release. Set [releaser.git.update-release-train-wiki] to [true] to change that"); return null; } File releaseTrainWiki = this.handler.cloneReleaseTrainWiki(); ProjectVersion releaseTrain = projects.releaseTrain(this.properties); // When using calver this need to be a major plus minor (ie if the release is // 2020.0.1, the name of the wiki page is 2020.0) - String releaseTrainName = releaseTrain.isCalver() ? releaseTrain.majorAndMinor() - : releaseTrain.major(); + String releaseTrainName = releaseTrain.isCalver() ? releaseTrain.majorAndMinor() : releaseTrain.major(); String wikiPagePrefix = this.properties.getGit().getReleaseTrainWikiPagePrefix(); - String releaseTrainDocFileName = releaseTrainDocFileName(releaseTrainName, - wikiPagePrefix); - log.info("Reading the file [{}] for the current release train", - releaseTrainDocFileName); - File releaseTrainDocFile = releaseTrainDocFile(releaseTrainWiki, - releaseTrainDocFileName); - String releaseVersionFromCurrentFile = this.parser - .latestReleaseTrainFromWiki(releaseTrainDocFile); - log.info("Latest release train version in the file is [{}]", - releaseVersionFromCurrentFile); - if (!isThisReleaseTrainVersionNewer(releaseTrain, - releaseVersionFromCurrentFile)) { - log.info( - "Current release train version [{}] is not " - + "newer than the version taken from the wiki [{}]", + String releaseTrainDocFileName = releaseTrainDocFileName(releaseTrainName, wikiPagePrefix); + log.info("Reading the file [{}] for the current release train", releaseTrainDocFileName); + File releaseTrainDocFile = releaseTrainDocFile(releaseTrainWiki, releaseTrainDocFileName); + String releaseVersionFromCurrentFile = this.parser.latestReleaseTrainFromWiki(releaseTrainDocFile); + log.info("Latest release train version in the file is [{}]", releaseVersionFromCurrentFile); + if (!isThisReleaseTrainVersionNewer(releaseTrain, releaseVersionFromCurrentFile)) { + log.info("Current release train version [{}] is not " + "newer than the version taken from the wiki [{}]", releaseTrain.version, releaseVersionFromCurrentFile); return releaseTrainWiki; } - return generateNewWikiEntry(projects, releaseTrainWiki, releaseTrain, - releaseTrainName, releaseTrainDocFile, releaseVersionFromCurrentFile); + return generateNewWikiEntry(projects, releaseTrainWiki, releaseTrain, releaseTrainName, releaseTrainDocFile, + releaseVersionFromCurrentFile); } - private File generateNewWikiEntry(Projects projects, File releaseTrainWiki, - ProjectVersion releaseTrain, String releaseTrainName, - File releaseTrainDocFile, String releaseVersionFromCurrentFile) { + private File generateNewWikiEntry(Projects projects, File releaseTrainWiki, ProjectVersion releaseTrain, + String releaseTrainName, File releaseTrainDocFile, String releaseVersionFromCurrentFile) { File releaseNotes = this.templateGenerator.releaseNotes(projects); try { List lines = Files.readAllLines(releaseTrainDocFile.toPath()); @@ -111,53 +98,43 @@ class ReleaseTrainContentsUpdater { break; } } - return insertNewWikiContentBeforeTheLatestRelease(releaseTrainWiki, - releaseTrain, releaseTrainName, releaseTrainDocFile, releaseNotes, - lines, lineIndex); + return insertNewWikiContentBeforeTheLatestRelease(releaseTrainWiki, releaseTrain, releaseTrainName, + releaseTrainDocFile, releaseNotes, lines, lineIndex); } catch (IOException ex) { throw new IllegalStateException(ex); } } - private File insertNewWikiContentBeforeTheLatestRelease(File releaseTrainWiki, - ProjectVersion releaseTrain, String releaseTrainName, - File releaseTrainDocFile, File releaseNotes, List lines, - int lineIndex) throws IOException { - String newContent = new StringJoiner("\n") - .add(String.join("\n", lines.subList(0, lineIndex))).add("\n") + private File insertNewWikiContentBeforeTheLatestRelease(File releaseTrainWiki, ProjectVersion releaseTrain, + String releaseTrainName, File releaseTrainDocFile, File releaseNotes, List lines, int lineIndex) + throws IOException { + String newContent = new StringJoiner("\n").add(String.join("\n", lines.subList(0, lineIndex))).add("\n") .add(new String(Files.readAllBytes(releaseNotes.toPath()))) - .add(String.join("\n", lines.subList(lineIndex, lines.size()))) - .toString(); + .add(String.join("\n", lines.subList(lineIndex, lines.size()))).toString(); Files.write(releaseTrainDocFile.toPath(), newContent.getBytes()); - log.info("Successfully stored new wiki contents for release train [{}]", - releaseTrainName); + log.info("Successfully stored new wiki contents for release train [{}]", releaseTrainName); this.handler.commitAndPushChanges(releaseTrainWiki, releaseTrain); return releaseTrainWiki; } - private String releaseTrainDocFileName(String releaseTrainName, - String wikiPagePrefix) { - return new StringJoiner("-").add(wikiPagePrefix).add(releaseTrainName) - .add("Release-Notes.md").toString(); + private String releaseTrainDocFileName(String releaseTrainName, String wikiPagePrefix) { + return new StringJoiner("-").add(wikiPagePrefix).add(releaseTrainName).add("Release-Notes.md").toString(); } - private boolean isThisReleaseTrainVersionNewer(ProjectVersion releaseTrain, - String releaseVersionFromCurrentFile) { + private boolean isThisReleaseTrainVersionNewer(ProjectVersion releaseTrain, String releaseVersionFromCurrentFile) { if (StringUtils.hasText(releaseVersionFromCurrentFile)) { return releaseTrain.compareToReleaseTrain(releaseVersionFromCurrentFile) > 0; } return true; } - private File releaseTrainDocFile(File releaseTrainWiki, - String releaseTrainDocFileName) { + private File releaseTrainDocFile(File releaseTrainWiki, String releaseTrainDocFileName) { File releaseTrainDocFile = new File(releaseTrainWiki, releaseTrainDocFileName); if (!releaseTrainDocFile.exists()) { try { if (!releaseTrainDocFile.createNewFile()) { - throw new IllegalStateException( - "Failed to create releae train doc file"); + throw new IllegalStateException("Failed to create releae train doc file"); } } catch (IOException e) { @@ -171,8 +148,7 @@ class ReleaseTrainContentsUpdater { class ReleaseTrainContentsGitHandler { - private static final Logger log = LoggerFactory - .getLogger(ReleaseTrainContentsGitHandler.class); + private static final Logger log = LoggerFactory.getLogger(ReleaseTrainContentsGitHandler.class); private static final String PROJECT_PAGE_UPDATED_COMMIT_MSG = "Updating project page to release train [%s]"; @@ -188,8 +164,7 @@ class ReleaseTrainContentsGitHandler { void commitAndPushChanges(File repo, ProjectVersion releaseTrain) { log.debug("Committing and pushing changes"); - this.handler.commit(repo, - String.format(PROJECT_PAGE_UPDATED_COMMIT_MSG, releaseTrain.version)); + this.handler.commit(repo, String.format(PROJECT_PAGE_UPDATED_COMMIT_MSG, releaseTrain.version)); this.handler.pushCurrentBranch(repo); } @@ -197,8 +172,7 @@ class ReleaseTrainContentsGitHandler { class ReleaseTrainContentsParser { - private static final Logger log = LoggerFactory - .getLogger(ReleaseTrainContentsParser.class); + private static final Logger log = LoggerFactory.getLogger(ReleaseTrainContentsParser.class); ReleaseTrainContents parseProjectPage(File rawHtml) { try { @@ -230,9 +204,8 @@ class ReleaseTrainContentsParser { return Files.readAllLines(rawMd.toPath()).stream() // We want to find only headers like # Finchley.RELEASE and not any // custom headers - .filter(s -> s.trim().startsWith("#") && s.contains(".")) - .map(s -> s.substring(1).trim()).filter(ProjectVersion::isValid) - .findFirst().orElse(""); + .filter(s -> s.trim().startsWith("#") && s.contains(".")).map(s -> s.substring(1).trim()) + .filter(ProjectVersion::isValid).findFirst().orElse(""); } catch (IOException e) { throw new IllegalStateException(e); diff --git a/releaser-core/src/main/java/releaser/internal/docs/Row.java b/releaser-core/src/main/java/releaser/internal/docs/Row.java index c0bc6ff9..ae24cced 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/Row.java +++ b/releaser-core/src/main/java/releaser/internal/docs/Row.java @@ -45,8 +45,7 @@ public class Row { this.currentSnapshotVersion = row[initialIndex + 3].trim(); } - Row(String componentName, String lastGaVersion, String currentGaVersion, - String currentSnapshotVersion) { + Row(String componentName, String lastGaVersion, String currentGaVersion, String currentSnapshotVersion) { this.componentName = componentName.trim(); this.lastGaVersion = lastGaVersion.trim(); this.currentGaVersion = currentGaVersion.trim(); @@ -56,8 +55,7 @@ public class Row { static List fromProjects(Projects projects, boolean lastGa) { return projects.stream() .map(v -> new Row(v.projectName, lastGa ? versionOrEmptyForGa(v) : "", - !lastGa ? versionOrEmptyForGa(v) : "", - v.isSnapshot() ? v.version : "")) + !lastGa ? versionOrEmptyForGa(v) : "", v.isSnapshot() ? v.version : "")) .collect(Collectors.toCollection(LinkedList::new)); } @@ -76,14 +74,13 @@ public class Row { Row row = (Row) o; return Objects.equals(this.componentName, row.componentName) && Objects.equals(this.lastGaVersion, row.lastGaVersion) - && Objects.equals(this.currentGaVersion, row.currentGaVersion) && Objects - .equals(this.currentSnapshotVersion, row.currentSnapshotVersion); + && Objects.equals(this.currentGaVersion, row.currentGaVersion) + && Objects.equals(this.currentSnapshotVersion, row.currentSnapshotVersion); } @Override public int hashCode() { - return Objects.hash(this.componentName, this.lastGaVersion, this.currentGaVersion, - this.currentSnapshotVersion); + return Objects.hash(this.componentName, this.lastGaVersion, this.currentGaVersion, this.currentSnapshotVersion); } public String getComponentName() { diff --git a/releaser-core/src/main/java/releaser/internal/docs/Title.java b/releaser-core/src/main/java/releaser/internal/docs/Title.java index 5e948ab5..3cee4132 100644 --- a/releaser-core/src/main/java/releaser/internal/docs/Title.java +++ b/releaser-core/src/main/java/releaser/internal/docs/Title.java @@ -36,8 +36,7 @@ public class Title { this.currentSnapshotTrainName = row[initialIndex + 2].trim(); } - Title(String lastGaTrainName, String currentGaTrainName, - String currentSnapshotTrainName) { + Title(String lastGaTrainName, String currentGaTrainName, String currentSnapshotTrainName) { this.lastGaTrainName = lastGaTrainName.trim(); this.currentGaTrainName = currentGaTrainName.trim(); this.currentSnapshotTrainName = currentSnapshotTrainName.trim(); @@ -54,14 +53,12 @@ public class Title { Title title = (Title) o; return Objects.equals(this.lastGaTrainName, title.lastGaTrainName) && Objects.equals(this.currentGaTrainName, title.currentGaTrainName) - && Objects.equals(this.currentSnapshotTrainName, - title.currentSnapshotTrainName); + && Objects.equals(this.currentSnapshotTrainName, title.currentSnapshotTrainName); } @Override public int hashCode() { - return Objects.hash(this.lastGaTrainName, this.currentGaTrainName, - this.currentSnapshotTrainName); + return Objects.hash(this.lastGaTrainName, this.currentGaTrainName, this.currentSnapshotTrainName); } public String getLastGaTrainName() { diff --git a/releaser-core/src/main/java/releaser/internal/git/GitRepo.java b/releaser-core/src/main/java/releaser/internal/git/GitRepo.java index 2ffb7bf7..9c380774 100644 --- a/releaser-core/src/main/java/releaser/internal/git/GitRepo.java +++ b/releaser-core/src/main/java/releaser/internal/git/GitRepo.java @@ -56,12 +56,12 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.FetchResult; -import org.eclipse.jgit.transport.JschConfigSessionFactory; -import org.eclipse.jgit.transport.OpenSshConfig; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.transport.SshTransport; import org.eclipse.jgit.transport.URIish; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.eclipse.jgit.transport.ssh.jsch.JschConfigSessionFactory; +import org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.FileUtils; import org.slf4j.Logger; @@ -109,8 +109,7 @@ class GitRepo { */ File cloneProject(URIish projectUri) { try { - log.info("Cloning repo from [{}] to [{}]", projectUri, - humanishDestination(projectUri, this.basedir)); + log.info("Cloning repo from [{}] to [{}]", projectUri, humanishDestination(projectUri, this.basedir)); Git git = cloneToBasedir(projectUri, this.basedir); if (git != null) { git.close(); @@ -190,9 +189,8 @@ class GitRepo { */ Optional findTagIdByName(String tagName, boolean unpeel) { try (Git git = this.gitFactory.open(file(this.basedir))) { - return git.tagList().call().stream() - .filter(ref -> ref.getName().equals("refs/tags/" + tagName)) - .findFirst().map(ref -> { + return git.tagList().call().stream().filter(ref -> ref.getName().equals("refs/tags/" + tagName)).findFirst() + .map(ref -> { if (ref.isPeeled() && unpeel) { return ref.getPeeledObjectId(); } @@ -200,8 +198,7 @@ class GitRepo { }); } catch (Exception e) { - throw new IllegalStateException( - "Unable to fetch git tag id for refs/tags/" + tagName, e); + throw new IllegalStateException("Unable to fetch git tag id for refs/tags/" + tagName, e); } } @@ -212,8 +209,7 @@ class GitRepo { */ List log(String from, String to) { try (Git git = this.gitFactory.open(file(this.basedir))) { - final Optional fromRevisionOptional = findTagOrBranchHeadRevision(git, - from); + final Optional fromRevisionOptional = findTagOrBranchHeadRevision(git, from); final Optional toRevisionOptional = findTagOrBranchHeadRevision(git, to); ObjectId fromRevision; @@ -249,8 +245,7 @@ class GitRepo { return commits; } catch (Exception e) { - throw new IllegalStateException( - "Unable to fetch git log for " + from + ".." + to, e); + throw new IllegalStateException("Unable to fetch git log for " + from + ".." + to, e); } } @@ -279,8 +274,7 @@ class GitRepo { } return d2.compareTo(d1); // more recent first }); - return allTagsNewestFirst.stream() - .map(ref -> Repository.shortenRefName(ref.getName())); + return allTagsNewestFirst.stream().map(ref -> Repository.shortenRefName(ref.getName())); } catch (Exception e) { throw new IllegalStateException("Unable to fetch git tags", e); @@ -290,29 +284,24 @@ class GitRepo { /** * Look for a tag with the given name, and if not found looks for a branch. */ - private Optional findTagOrBranchHeadRevision(Git git, String tagOrBranch) - throws GitAPIException, IOException { + private Optional findTagOrBranchHeadRevision(Git git, String tagOrBranch) throws GitAPIException, IOException { if (tagOrBranch.equals("HEAD")) { return Optional.of(git.getRepository().exactRef(Constants.HEAD).getTarget()); } final Optional tag = git.tagList().call().stream() - .filter(ref -> ref.getName().equals("refs/tags/" + tagOrBranch)) - .findFirst(); + .filter(ref -> ref.getName().equals("refs/tags/" + tagOrBranch)).findFirst(); if (tag.isPresent()) { return tag; } - return git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call() - .stream().filter(ref -> ref.getName().equals("refs/heads/" + tagOrBranch)) - .findFirst(); + return git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call().stream() + .filter(ref -> ref.getName().equals("refs/heads/" + tagOrBranch)).findFirst(); } boolean hasBranch(String branch) { try (Git git = this.gitFactory.open(file(this.basedir))) { - List refs = git.branchList().setListMode(ListBranchCommand.ListMode.ALL) - .call(); - boolean present = refs.stream() - .anyMatch(ref -> branch.equals(nameOfBranch(ref.getName()))); + List refs = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); + boolean present = refs.stream().anyMatch(ref -> branch.equals(nameOfBranch(ref.getName()))); if (log.isDebugEnabled()) { log.debug("Branch [{}] is present [{}]", branch, present); } @@ -335,8 +324,7 @@ class GitRepo { log.info("Printing [{}] last commits for branch [{}]", maxCount, currentBranch); Iterable commits = git.log().setMaxCount(maxCount).call(); for (RevCommit commit : commits) { - log.info("Name [{}], msg [{}]", commit.getId().name(), - commit.getShortMessage()); + log.info("Name [{}], msg [{}]", commit.getId().name(), commit.getShortMessage()); } } @@ -402,9 +390,8 @@ class GitRepo { String id = commit.getId().getName(); if (!shortMessage.contains("Update SNAPSHOT to ")) { throw new IllegalStateException( - "Won't revert the commit with id [" + id + "] " + "and message [" - + shortMessage + "]. Only commit that updated " - + "snapshot to another version can be reverted"); + "Won't revert the commit with id [" + id + "] " + "and message [" + shortMessage + + "]. Only commit that updated " + "snapshot to another version can be reverted"); } log.debug("The commit to be reverted is [{}]", commit); git.revert().include(commit).call(); @@ -429,10 +416,8 @@ class GitRepo { return ResourceUtils.getFile(project.toURI()).getAbsoluteFile(); } - private Git cloneToBasedir(URIish projectUrl, File destinationFolder) - throws GitAPIException { - CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository() - .setURI(projectUrl.toString() + ".git") + private Git cloneToBasedir(URIish projectUrl, File destinationFolder) throws GitAPIException { + CloneCommand command = this.gitFactory.getCloneCommandByCloneRepository().setURI(projectUrl.toString() + ".git") .setDirectory(humanishDestination(projectUrl, destinationFolder)); try { return command.call(); @@ -500,8 +485,7 @@ class GitRepo { } private void trackBranch(CheckoutCommand checkout, String label) { - checkout.setCreateBranch(true).setName(label) - .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) + checkout.setCreateBranch(true).setName(label).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint("origin/" + label); } @@ -513,8 +497,7 @@ class GitRepo { return containsBranch(git, label, null); } - private boolean containsBranch(Git git, String label, - ListBranchCommand.ListMode listMode) throws GitAPIException { + private boolean containsBranch(Git git, String label, ListBranchCommand.ListMode listMode) throws GitAPIException { ListBranchCommand command = git.branchList(); if (listMode != null) { command.setListMode(listMode); @@ -564,17 +547,14 @@ class GitRepo { log.info("Successfully connected to an agent"); } catch (AgentProxyException e) { - log.error( - "Exception occurred while trying to connect to agent. Will create" - + "the default JSch connection", - e); + log.error("Exception occurred while trying to connect to agent. Will create" + + "the default JSch connection", e); return super.createDefaultJSch(fs); } final JSch jsch = super.createDefaultJSch(fs); if (connector != null) { JSch.setConfig("PreferredAuthentications", "publickey,password"); - IdentityRepository identityRepository = new RemoteIdentityRepository( - connector); + IdentityRepository identityRepository = new RemoteIdentityRepository(connector); jsch.setIdentityRepository(identityRepository); } return jsch; @@ -592,8 +572,7 @@ class GitRepo { JGitFactory(ReleaserProperties releaserProperties) { if (StringUtils.hasText(releaserProperties.getGit().getUsername())) { - log.info( - "Passed username and password - will set a custom credentials provider"); + log.info("Passed username and password - will set a custom credentials provider"); this.provider = credentialsProvider(releaserProperties); } else { @@ -608,8 +587,8 @@ class GitRepo { } CredentialsProvider credentialsProvider(ReleaserProperties properties) { - return new UsernamePasswordCredentialsProvider( - properties.getGit().getUsername(), properties.getGit().getPassword()); + return new UsernamePasswordCredentialsProvider(properties.getGit().getUsername(), + properties.getGit().getPassword()); } CloneCommand getCloneCommandByCloneRepository() { @@ -618,8 +597,7 @@ class GitRepo { } PushCommand push(Git git) { - return git.push().setCredentialsProvider(this.provider) - .setTransportConfigCallback(this.callback); + return git.push().setCredentialsProvider(this.provider).setTransportConfigCallback(this.callback); } Git open(File file) { 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 e8c52abd..db871883 100644 --- a/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java +++ b/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java @@ -70,13 +70,11 @@ public class ProjectGitHandler implements Closeable { public void commitAndTagIfApplicable(File project, ProjectVersion version) { GitRepo gitRepo = gitRepo(project); if (version.isSnapshot()) { - log.info("Snapshot version [{}] found. Will only commit the changed poms", - version); + log.info("Snapshot version [{}] found. Will only commit the changed poms", version); gitRepo.commit(MSG); } else { - log.info( - "NON-snapshot version [{}] found. Will commit the changed poms, tag the version and push the tag", + log.info("NON-snapshot version [{}] found. Will commit the changed poms, tag the version and push the tag", version); gitRepo.commit(String.format(PRE_RELEASE_MSG, version.version)); String tagName = "v" + version.version; @@ -87,8 +85,7 @@ public class ProjectGitHandler implements Closeable { public void commitAfterBumpingVersions(File project, ProjectVersion bumpedVersion) { if (bumpedVersion.isSnapshot()) { - log.info("Snapshot version [{}] found. Will only commit the changed poms", - bumpedVersion); + log.info("Snapshot version [{}] found. Will only commit the changed poms", bumpedVersion); commit(project, String.format(POST_RELEASE_BUMP_MSG, bumpedVersion)); } else { @@ -120,8 +117,7 @@ public class ProjectGitHandler implements Closeable { } public File cloneReleaseTrainDocumentationProject(String branch) { - return cloneAndCheckOut(this.properties.getGit().getReleaseTrainDocsUrl(), - branch); + return cloneAndCheckOut(this.properties.getGit().getReleaseTrainDocsUrl(), branch); } public File cloneDocumentationProject() { @@ -134,8 +130,7 @@ public class ProjectGitHandler implements Closeable { this.properties.getGit().getSpringProjectBranch()); } - private File cloneAndCheckOut(String springProjectUrl, - String springProjectUrlBranch) { + private File cloneAndCheckOut(String springProjectUrl, String springProjectUrlBranch) { File clonedProject = cloneProject(springProjectUrl); checkout(clonedProject, springProjectUrlBranch); return clonedProject; @@ -160,8 +155,7 @@ public class ProjectGitHandler implements Closeable { String releaseTrainBranch = this.properties.getGit().getReleaseTrainBranch(); if (!StringUtils.isEmpty(releaseTrainBranch)) { if (log.isDebugEnabled()) { - log.debug("Checking out configured release train branch {}", - releaseTrainBranch); + log.debug("Checking out configured release train branch {}", releaseTrainBranch); } if (gitRepo(clonedProject).hasBranch(releaseTrainBranch)) { log.info("Branch [{}] exists. Will check it out", releaseTrainBranch); @@ -171,8 +165,7 @@ public class ProjectGitHandler implements Closeable { } String version = this.properties.getFixedVersions().get(projectName); if (StringUtils.isEmpty(version)) { - throw new IllegalStateException( - "You haven't provided a version for project [" + projectName + "]"); + throw new IllegalStateException("You haven't provided a version for project [" + projectName + "]"); } return findAndCheckOutBranchForVersion(clonedProject, new String[] { version }); } @@ -200,11 +193,10 @@ public class ProjectGitHandler implements Closeable { log.debug("Checking versions {} for project [{}]", versions, clonedProject); } String branchToCheckout = Arrays.stream(versions).map(this::branchFromVersion) - .map(version -> gitRepo(clonedProject).hasBranch(version) ? version : "") - .filter(StringUtils::hasText).findFirst().orElse("main"); + .map(version -> gitRepo(clonedProject).hasBranch(version) ? version : "").filter(StringUtils::hasText) + .findFirst().orElse("main"); if ("main".equals(branchToCheckout)) { - log.info( - "None of the versions {} matches a branch. Assuming that should work with main branch", + log.info("None of the versions {} matches a branch. Assuming that should work with main branch", (Object) versions); return clonedProject; } @@ -221,10 +213,8 @@ public class ProjectGitHandler implements Closeable { * @param toRef the ref to go to (tag, branch or sha1) * @return the list of revisions between these two references */ - public List commitsBetween(File clonedProject, String fromRef, - String toRef) { - return gitRepo(clonedProject).log(fromRef, toRef).stream().map(SimpleCommit::new) - .collect(Collectors.toList()); + public List commitsBetween(File clonedProject, String fromRef, String toRef) { + return gitRepo(clonedProject).log(fromRef, toRef).stream().map(SimpleCommit::new).collect(Collectors.toList()); } /** @@ -234,8 +224,7 @@ public class ProjectGitHandler implements Closeable { * @return an {@link Optional} that is valued with the sha1, if found */ public Optional findTagSha1(File clonedProject, String tagName) { - return gitRepo(clonedProject).findTagIdByName(tagName, false) - .map(AnyObjectId::getName); + return gitRepo(clonedProject).findTagIdByName(tagName, false).map(AnyObjectId::getName); } private String suffixNonHttpRepo(String orgUrl) { @@ -248,8 +237,7 @@ public class ProjectGitHandler implements Closeable { // retrieve from cache // reset any changes and fetch the latest data File destinationDir = destinationDir(); - File clonedProject = CACHE.computeIfAbsent(urIish, - urIish1 -> gitRepo(destinationDir).cloneProject(urIish)); + File clonedProject = CACHE.computeIfAbsent(urIish, urIish1 -> gitRepo(destinationDir).cloneProject(urIish)); if (clonedProject.exists()) { log.info( "Project has already been cloned. Will try to reset the current branch and fetch the latest changes."); @@ -309,8 +297,7 @@ public class ProjectGitHandler implements Closeable { // [Camden] -> [Camden.x] return splitVersion[0]; } - throw new IllegalStateException( - "Wrong version [" + version + "]. Can't extract semver pieces of it"); + throw new IllegalStateException("Wrong version [" + version + "]. Can't extract semver pieces of it"); } @@ -347,8 +334,7 @@ public class ProjectGitHandler implements Closeable { * @return a {@link Stream} of the tags whose name match the given {@link Pattern} */ public Stream findTagNamesMatching(File clonedProject, Pattern tagPattern) { - return gitRepo(clonedProject).listTags() - .filter(tagName -> tagPattern.matcher(tagName).matches()); + return gitRepo(clonedProject).listTags().filter(tagName -> tagPattern.matcher(tagName).matches()); } } diff --git a/releaser-core/src/main/java/releaser/internal/git/SimpleCommit.java b/releaser-core/src/main/java/releaser/internal/git/SimpleCommit.java index 8accf3ca..d2a7e730 100644 --- a/releaser-core/src/main/java/releaser/internal/git/SimpleCommit.java +++ b/releaser-core/src/main/java/releaser/internal/git/SimpleCommit.java @@ -71,12 +71,9 @@ public class SimpleCommit { public final boolean isMergeCommit; SimpleCommit(RevCommit revCommit) { - this(revCommit.abbreviate(8).name(), revCommit.name(), - revCommit.getShortMessage(), revCommit.getFullMessage(), - revCommit.getAuthorIdent().getName(), - revCommit.getAuthorIdent().getEmailAddress(), - revCommit.getCommitterIdent().getName(), - revCommit.getCommitterIdent().getEmailAddress(), + this(revCommit.abbreviate(8).name(), revCommit.name(), revCommit.getShortMessage(), revCommit.getFullMessage(), + revCommit.getAuthorIdent().getName(), revCommit.getAuthorIdent().getEmailAddress(), + revCommit.getCommitterIdent().getName(), revCommit.getCommitterIdent().getEmailAddress(), revCommit.getParentCount() > 1); } @@ -92,9 +89,8 @@ public class SimpleCommit { * @param committerEmail the email of the commit's committer * @param isMergeCommit is the commit a merge commit (with 2 parents) */ - public SimpleCommit(String abbreviatedSha1, String fullSha1, String title, - String fullMessage, String authorName, String authorEmail, - String committerName, String committerEmail, boolean isMergeCommit) { + public SimpleCommit(String abbreviatedSha1, String fullSha1, String title, String fullMessage, String authorName, + String authorEmail, String committerName, String committerEmail, boolean isMergeCommit) { this.abbreviatedSha1 = abbreviatedSha1; this.fullSha1 = fullSha1; this.title = title; diff --git a/releaser-core/src/main/java/releaser/internal/github/CachingGithub.java b/releaser-core/src/main/java/releaser/internal/github/CachingGithub.java index a9ebfc79..c2f27d05 100644 --- a/releaser-core/src/main/java/releaser/internal/github/CachingGithub.java +++ b/releaser-core/src/main/java/releaser/internal/github/CachingGithub.java @@ -167,8 +167,7 @@ class CachingRepos implements Repos, Closeable { @Override public Repo get(Coordinates coordinates) { - return CACHE.computeIfAbsent(coordinates, - o -> new CachingRepo(this.delegate.get(coordinates))); + return CACHE.computeIfAbsent(coordinates, o -> new CachingRepo(this.delegate.get(coordinates))); } @Override @@ -181,6 +180,11 @@ class CachingRepos implements Repos, Closeable { return this.delegate.iterate(s); } + @Override + public boolean exists(Coordinates coordinates) throws IOException { + return delegate.exists(coordinates); + } + @Override public boolean equals(Object o) { return this.delegate.equals(o); @@ -216,47 +220,40 @@ class CachingRepo implements Repo, Closeable { @Override public Coordinates coordinates() { - return (Coordinates) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "coordinates"), + return (Coordinates) CACHE.computeIfAbsent(new RepoKey(this.delegate, "coordinates"), s -> this.delegate.coordinates()); } @Override public Issues issues() { - return (Issues) CACHE.computeIfAbsent(new RepoKey(this.delegate, "issues"), - s -> this.delegate.issues()); + return (Issues) CACHE.computeIfAbsent(new RepoKey(this.delegate, "issues"), s -> this.delegate.issues()); } @Override public Milestones milestones() { - return (Milestones) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "milestones"), + return (Milestones) CACHE.computeIfAbsent(new RepoKey(this.delegate, "milestones"), s -> this.delegate.milestones()); } @Override public Pulls pulls() { - return (Pulls) CACHE.computeIfAbsent(new RepoKey(this.delegate, "pulls"), - s -> this.delegate.pulls()); + return (Pulls) CACHE.computeIfAbsent(new RepoKey(this.delegate, "pulls"), s -> this.delegate.pulls()); } @Override public Hooks hooks() { - return (Hooks) CACHE.computeIfAbsent(new RepoKey(this.delegate, "hooks"), - s -> this.delegate.hooks()); + return (Hooks) CACHE.computeIfAbsent(new RepoKey(this.delegate, "hooks"), s -> this.delegate.hooks()); } @Override public IssueEvents issueEvents() { - return (IssueEvents) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "issueEvents"), + return (IssueEvents) CACHE.computeIfAbsent(new RepoKey(this.delegate, "issueEvents"), s -> this.delegate.issueEvents()); } @Override public Labels labels() { - return (Labels) CACHE.computeIfAbsent(new RepoKey(this.delegate, "labels"), - s -> this.delegate.labels()); + return (Labels) CACHE.computeIfAbsent(new RepoKey(this.delegate, "labels"), s -> this.delegate.labels()); } @Override @@ -267,63 +264,54 @@ class CachingRepo implements Repo, Closeable { @Override public Releases releases() { - return (Releases) CACHE.computeIfAbsent(new RepoKey(this.delegate, "releases"), - s -> this.delegate.releases()); + return (Releases) CACHE.computeIfAbsent(new RepoKey(this.delegate, "releases"), s -> this.delegate.releases()); } @Override public DeployKeys keys() { - return (DeployKeys) CACHE.computeIfAbsent(new RepoKey(this.delegate, "keys"), - s -> this.delegate.keys()); + return (DeployKeys) CACHE.computeIfAbsent(new RepoKey(this.delegate, "keys"), s -> this.delegate.keys()); } @Override public Forks forks() { - return (Forks) CACHE.computeIfAbsent(new RepoKey(this.delegate, "forks"), - s -> this.delegate.forks()); + return (Forks) CACHE.computeIfAbsent(new RepoKey(this.delegate, "forks"), s -> this.delegate.forks()); } @Override public RepoCommits commits() { - return (RepoCommits) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "repoCommits"), s -> this.delegate.commits()); + return (RepoCommits) CACHE.computeIfAbsent(new RepoKey(this.delegate, "repoCommits"), + s -> this.delegate.commits()); } @Override public Branches branches() { - return (Branches) CACHE.computeIfAbsent(new RepoKey(this.delegate, "branches"), - s -> this.delegate.branches()); + return (Branches) CACHE.computeIfAbsent(new RepoKey(this.delegate, "branches"), s -> this.delegate.branches()); } @Override public Contents contents() { - return (Contents) CACHE.computeIfAbsent(new RepoKey(this.delegate, "contents"), - s -> this.delegate.contents()); + return (Contents) CACHE.computeIfAbsent(new RepoKey(this.delegate, "contents"), s -> this.delegate.contents()); } @Override public Collaborators collaborators() { - return (Collaborators) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "collaborators"), + return (Collaborators) CACHE.computeIfAbsent(new RepoKey(this.delegate, "collaborators"), s -> this.delegate.collaborators()); } @Override public Git git() { - return (Git) CACHE.computeIfAbsent(new RepoKey(this.delegate, "git"), - s -> this.delegate.git()); + return (Git) CACHE.computeIfAbsent(new RepoKey(this.delegate, "git"), s -> this.delegate.git()); } @Override public Stars stars() { - return (Stars) CACHE.computeIfAbsent(new RepoKey(this.delegate, "stars"), - s -> this.delegate.stars()); + return (Stars) CACHE.computeIfAbsent(new RepoKey(this.delegate, "stars"), s -> this.delegate.stars()); } @Override public Notifications notifications() { - return (Notifications) CACHE.computeIfAbsent( - new RepoKey(this.delegate, "notifications"), + return (Notifications) CACHE.computeIfAbsent(new RepoKey(this.delegate, "notifications"), s -> this.delegate.notifications()); } @@ -334,15 +322,14 @@ class CachingRepo implements Repo, Closeable { @Override public JsonObject json() throws IOException { - return (JsonObject) CACHE.computeIfAbsent(new RepoKey(this.delegate, "json"), - s -> { - try { - return this.delegate.json(); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - }); + return (JsonObject) CACHE.computeIfAbsent(new RepoKey(this.delegate, "json"), s -> { + try { + return this.delegate.json(); + } + catch (IOException ex) { + throw new IllegalStateException(ex); + } + }); } @Override @@ -382,8 +369,7 @@ class RepoKey { return false; } RepoKey repoKey = (RepoKey) o; - return Objects.equals(this.repo, repoKey.repo) - && Objects.equals(this.key, repoKey.key); + return Objects.equals(this.repo, repoKey.repo) && Objects.equals(this.key, repoKey.key); } @Override diff --git a/releaser-core/src/main/java/releaser/internal/github/GithubIssueFiler.java b/releaser-core/src/main/java/releaser/internal/github/GithubIssueFiler.java index be118c88..43946c32 100644 --- a/releaser-core/src/main/java/releaser/internal/github/GithubIssueFiler.java +++ b/releaser-core/src/main/java/releaser/internal/github/GithubIssueFiler.java @@ -47,8 +47,8 @@ public class GithubIssueFiler { private final ReleaserProperties properties; public GithubIssueFiler(ReleaserProperties properties) { - this(new RtGithub(new RtGithub(properties.getGit().getOauthToken()).entry() - .through(RetryWire.class)), properties); + this(new RtGithub(new RtGithub(properties.getGit().getOauthToken()).entry().through(RetryWire.class)), + properties); } public GithubIssueFiler(Github github, ReleaserProperties properties) { @@ -56,22 +56,20 @@ public class GithubIssueFiler { this.properties = properties; } - public void fileAGitHubIssue(String user, String repo, ProjectVersion version, - String issueTitle, String issueText) { + public void fileAGitHubIssue(String user, String repo, ProjectVersion version, String issueTitle, + String issueText) { Assert.hasText(this.properties.getGit().getOauthToken(), "You have to pass Github OAuth token for milestone closing to be operational"); // do this only for RELEASE & SR if (version.isSnapshot()) { - log.info( - "Github issue creation will occur only for non snapshot versions. Your version is [{}]", + log.info("Github issue creation will occur only for non snapshot versions. Your version is [{}]", parsedVersion()); return; } fileAGithubIssue(user, repo, issueTitle, issueText); } - private void fileAGithubIssue(String user, String repo, String issueTitle, - String issueText) { + private void fileAGithubIssue(String user, String repo, String issueTitle, String issueText) { Repo ghRepo = this.github.repos().get(new Coordinates.Simple(user, repo)); // check if the issue is not already there boolean issueAlreadyFiled = issueAlreadyFiled(ghRepo, issueTitle); @@ -81,9 +79,7 @@ public class GithubIssueFiler { } try { int number = ghRepo.issues().create(issueTitle, issueText).number(); - log.info( - "Successfully created an issue with " - + "title [{}] for the [{}/{}] GitHub repository" + number, + log.info("Successfully created an issue with " + "title [{}] for the [{}/{}] GitHub repository" + number, issueTitle, user, repo); } catch (IOException e) { diff --git a/releaser-core/src/main/java/releaser/internal/github/GithubIssues.java b/releaser-core/src/main/java/releaser/internal/github/GithubIssues.java index 000cd7f0..86655b0a 100644 --- a/releaser-core/src/main/java/releaser/internal/github/GithubIssues.java +++ b/releaser-core/src/main/java/releaser/internal/github/GithubIssues.java @@ -33,8 +33,7 @@ class GithubIssues { } private CustomGithubIssues customGithubIssues() { - return this.customGithubIssues.isEmpty() ? CustomGithubIssues.NO_OP - : this.customGithubIssues.get(0); + return this.customGithubIssues.isEmpty() ? CustomGithubIssues.NO_OP : this.customGithubIssues.get(0); } void fileIssueInSpringGuides(Projects projects, ProjectVersion version) { diff --git a/releaser-core/src/main/java/releaser/internal/github/GithubMilestones.java b/releaser-core/src/main/java/releaser/internal/github/GithubMilestones.java index d443eb20..8075e36f 100644 --- a/releaser-core/src/main/java/releaser/internal/github/GithubMilestones.java +++ b/releaser-core/src/main/java/releaser/internal/github/GithubMilestones.java @@ -51,8 +51,8 @@ class GithubMilestones { private final ReleaserProperties properties; GithubMilestones(ReleaserProperties properties) { - this(new RtGithub(new RtGithub(properties.getGit().getOauthToken()).entry() - .through(RetryWire.class)), properties); + this(new RtGithub(new RtGithub(properties.getGit().getOauthToken()).entry().through(RetryWire.class)), + properties); } GithubMilestones(Github github, ReleaserProperties properties) { @@ -95,8 +95,7 @@ class GithubMilestones { try { int counter = 0; for (Milestone milestone : milestones) { - if (counter++ >= this.properties.getGit() - .getNumberOfCheckedMilestones()) { + if (counter++ >= this.properties.getGit().getNumberOfCheckedMilestones()) { log.warn( "No matching milestones were found within the provided threshold [{}] of checked milestones", this.properties.getGit().getNumberOfCheckedMilestones()); @@ -104,8 +103,7 @@ class GithubMilestones { } Milestone.Smart smartMilestone = new Milestone.Smart(milestone); String title = milestoneTitle(smartMilestone); - if (tagVersion.equals(title) - || numericVersion(tagVersion).equals(title)) { + if (tagVersion.equals(title) || numericVersion(tagVersion).equals(title)) { log.info("Found a matching milestone [{}]", smartMilestone.number()); return smartMilestone; } @@ -127,15 +125,13 @@ class GithubMilestones { Assert.hasText(this.properties.getGit().getOauthToken(), "You have to pass Github OAuth token for milestone closing to be operational"); String tagVersion = version.version; - Milestone.Smart foundMilestone = matchingMilestone(tagVersion, - closedMilestones(version)); + Milestone.Smart foundMilestone = matchingMilestone(tagVersion, closedMilestones(version)); String foundUrl = ""; if (foundMilestone != null) { try { URL url = foundMilestoneUrl(foundMilestone); log.info("Found a matching milestone with issues URL [{}]", url); - foundUrl = url.toString() - .replace("https://api.github.com/repos", "https://github.com") + foundUrl = url.toString().replace("https://api.github.com/repos", "https://github.com") .replace("milestones", "milestone") + "?closed=1"; } catch (IOException e) { @@ -150,8 +146,7 @@ class GithubMilestones { } private String numericVersion(String version) { - return version.contains("RELEASE") - ? version.substring(0, version.lastIndexOf(".")) : ""; + return version.contains("RELEASE") ? version.substring(0, version.lastIndexOf(".")) : ""; } String milestoneTitle(Milestone.Smart milestone) throws IOException { @@ -162,11 +157,9 @@ class GithubMilestones { return milestone.url(); } - private Iterable getMilestones(ProjectVersion version, - Map map) { + private Iterable getMilestones(ProjectVersion version, Map map) { try { - return this.github.repos() - .get(new Coordinates.Simple(org(), version.projectName)).milestones() + return this.github.repos().get(new Coordinates.Simple(org(), version.projectName)).milestones() .iterate(map); } catch (AssertionError e) { 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 9d146165..1fbd7a51 100644 --- a/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java +++ b/releaser-core/src/main/java/releaser/internal/github/ProjectGitHubHandler.java @@ -40,8 +40,7 @@ public class ProjectGitHubHandler { private final ReleaserProperties properties; - public ProjectGitHubHandler(ReleaserProperties properties, - List customGithubIssues) { + public ProjectGitHubHandler(ReleaserProperties properties, List customGithubIssues) { this.properties = properties; this.githubMilestones = new GithubMilestones(properties); this.githubIssues = new GithubIssues(customGithubIssues); @@ -54,9 +53,8 @@ public class ProjectGitHubHandler { public void closeMilestone(ProjectVersion releaseVersion) { if (!this.properties.getGit().isUpdateGithubMilestones()) { - log.info( - "Will not update the release train documentation, since the switch to do so " - + "is off. Set [releaser.git.update-github-milestones] to [true] to change that"); + log.info("Will not update the release train documentation, since the switch to do so " + + "is off. Set [releaser.git.update-github-milestones] to [true] to change that"); return; } this.githubMilestones.closeMilestone(releaseVersion); @@ -64,9 +62,8 @@ public class ProjectGitHubHandler { public void createIssueInSpringGuides(Projects projects, ProjectVersion version) { if (!this.properties.getGit().isUpdateSpringGuides()) { - log.info( - "Will not update the release train documentation, since the switch to do so " - + "is off. Set [releaser.git.update-spring-guides] to [true] to change that"); + log.info("Will not update the release train documentation, since the switch to do so " + + "is off. Set [releaser.git.update-spring-guides] to [true] to change that"); return; } this.githubIssues.fileIssueInSpringGuides(projects, version); @@ -74,9 +71,8 @@ public class ProjectGitHubHandler { public void createIssueInStartSpringIo(Projects projects, ProjectVersion version) { if (!this.properties.getGit().isUpdateStartSpringIo()) { - log.info( - "Will not update the release train documentation, since the switch to do so " - + "is off. Set [releaser.git.update-start-spring-io] to [true] to change that"); + log.info("Will not update the release train documentation, since the switch to do so " + + "is off. Set [releaser.git.update-start-spring-io] to [true] to change that"); return; } this.githubIssues.fileIssueInStartSpringIo(projects, version); 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 a0113220..8b56bce2 100644 --- a/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java +++ b/releaser-core/src/main/java/releaser/internal/postrelease/PostReleaseActions.java @@ -68,11 +68,9 @@ public class PostReleaseActions implements Closeable { private final ReleaserPropertiesUpdater releaserPropertiesUpdater; - public PostReleaseActions(ProjectGitHandler projectGitHandler, - ProjectPomUpdater projectPomUpdater, GradleUpdater gradleUpdater, - ProjectCommandExecutor projectCommandExecutor, ReleaserProperties properties, - VersionsFetcher versionsFetcher, - ReleaserPropertiesUpdater releaserPropertiesUpdater) { + public PostReleaseActions(ProjectGitHandler projectGitHandler, ProjectPomUpdater projectPomUpdater, + GradleUpdater gradleUpdater, ProjectCommandExecutor projectCommandExecutor, ReleaserProperties properties, + VersionsFetcher versionsFetcher, ReleaserPropertiesUpdater releaserPropertiesUpdater) { this.projectGitHandler = projectGitHandler; this.projectPomUpdater = projectPomUpdater; this.gradleUpdater = gradleUpdater; @@ -90,19 +88,15 @@ public class PostReleaseActions implements Closeable { */ public ExecutionResult deployGuides(List processedProjects) { if (!this.properties.getGit().isUpdateSpringGuides()) { - log.info( - "Will not build and deploy latest Spring Guides, since the switch to do so " - + "is off. Set [releaser.git.update-spring-guides] to [true] to change that"); + log.info("Will not build and deploy latest Spring Guides, since the switch to do so " + + "is off. Set [releaser.git.update-spring-guides] to [true] to change that"); return ExecutionResult.skipped(); } List latestGaProcessedProjects = processedProjects.stream() - .filter(processedProject -> this.versionsFetcher - .isLatestGa(processedProject.newProjectVersion)) + .filter(processedProject -> this.versionsFetcher.isLatestGa(processedProject.newProjectVersion)) .collect(Collectors.toList()); - log.info("Found the following latest ga processed projects " - + latestGaProcessedProjects); - List projectUrlAndExceptions = runDeployGuides( - latestGaProcessedProjects); + log.info("Found the following latest ga processed projects " + latestGaProcessedProjects); + List projectUrlAndExceptions = runDeployGuides(latestGaProcessedProjects); log.info("Deployed all guides!"); assertExceptions(projectUrlAndExceptions); return ExecutionResult.success(); @@ -114,8 +108,7 @@ public class PostReleaseActions implements Closeable { * @return result of the execution */ public ExecutionResult runUpdatedTests(Projects projects) { - if (!this.properties.getGit().isRunUpdatedSamples() - || !this.properties.getMetaRelease().isEnabled()) { + if (!this.properties.getGit().isRunUpdatedSamples() || !this.properties.getMetaRelease().isEnabled()) { log.info("Will not update and run test samples, since the switch to do so " + "is off. Set [releaser.git.run-updated-samples] to [true] to change that"); return ExecutionResult.skipped(); @@ -124,11 +117,9 @@ public class PostReleaseActions implements Closeable { ReleaserProperties projectProps = projectProps(file); ProjectVersion projectVersion = newProjectVersion(file); String releaseTrainVersion = projects.releaseTrain(projectProps).version; - Projects newProjects = addVersionForTestsProject(projects, projectVersion, - releaseTrainVersion); + Projects newProjects = addVersionForTestsProject(projects, projectVersion, releaseTrainVersion); updateWithVersions(file, newProjects); - this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion, - file.getAbsolutePath()); + this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion, file.getAbsolutePath()); return ExecutionResult.success(); } @@ -144,15 +135,13 @@ public class PostReleaseActions implements Closeable { * @return result of the execution */ public ExecutionResult updateAllTestSamples(Projects projects) { - if (!this.properties.getGit().isUpdateAllTestSamples() - || !this.properties.getMetaRelease().isEnabled()) { + if (!this.properties.getGit().isUpdateAllTestSamples() || !this.properties.getMetaRelease().isEnabled()) { log.info("Will not update all test samples, since the switch to do so " + "is off. Set [releaser.git.update-all-test-samples] to [true] to change that"); return ExecutionResult.skipped(); } - List projectUrlAndExceptions = this.properties.getGit() - .getAllTestSampleUrls().entrySet().stream() - .map(e -> updateAllProjects(projects, e)).map(this::getResult) + List projectUrlAndExceptions = this.properties.getGit().getAllTestSampleUrls() + .entrySet().stream().map(e -> updateAllProjects(projects, e)).map(this::getResult) .flatMap(Collection::stream).collect(Collectors.toList()); log.info("Updated all samples!"); assertExceptions(projectUrlAndExceptions); @@ -160,41 +149,30 @@ public class PostReleaseActions implements Closeable { } private void assertExceptions(List projectUrlAndExceptions) { - String exceptionMessages = projectUrlAndExceptions.stream() - .filter(ProjectUrlAndException::hasException) - .map(e -> "Project [" + e.key + "] for url [" + e.url + "] " - + "has exception [\n\n" - + Arrays.stream(NestedExceptionUtils.getMostSpecificCause(e.ex) - .getStackTrace()).map(StackTraceElement::toString) - .collect(Collectors.joining("\n")) + String exceptionMessages = projectUrlAndExceptions.stream().filter(ProjectUrlAndException::hasException) + .map(e -> "Project [" + e.key + "] for url [" + e.url + "] " + "has exception [\n\n" + + Arrays.stream(NestedExceptionUtils.getMostSpecificCause(e.ex).getStackTrace()) + .map(StackTraceElement::toString).collect(Collectors.joining("\n")) + "]") .collect(Collectors.joining("\n")); if (StringUtils.hasText(exceptionMessages)) { throw new IllegalStateException( - "Exceptions were found while running post release tasks\n" - + exceptionMessages); + "Exceptions were found while running post release tasks\n" + exceptionMessages); } else { log.info("No exceptions were found while running post release tasks"); } } - private List runDeployGuides( - List latestGaProcessedProjects) { + private List runDeployGuides(List latestGaProcessedProjects) { return latestGaProcessedProjects.stream() - .map(processedProject -> run(processedProject.projectName(), "", - () -> SERVICE.submit(() -> { - String tagName = processedProject.newProjectVersion - .releaseTagName(); - File clonedProject = this.projectGitHandler - .cloneProjectFromOrg(processedProject.projectName()); - this.projectGitHandler.checkout(clonedProject, tagName); - projectBuilder(processedProject).deployGuides( - processedProject.propertiesForProject, - processedProject.originalProjectVersion, - processedProject.newProjectVersion); - }))) - .map(this::getSingleResult).collect(Collectors.toList()); + .map(processedProject -> run(processedProject.projectName(), "", () -> SERVICE.submit(() -> { + String tagName = processedProject.newProjectVersion.releaseTagName(); + File clonedProject = this.projectGitHandler.cloneProjectFromOrg(processedProject.projectName()); + this.projectGitHandler.checkout(clonedProject, tagName); + projectBuilder(processedProject).deployGuides(processedProject.propertiesForProject, + processedProject.originalProjectVersion, processedProject.newProjectVersion); + }))).map(this::getSingleResult).collect(Collectors.toList()); } ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) { @@ -206,45 +184,37 @@ public class PostReleaseActions implements Closeable { return SERVICE.submit(() -> { String key = e.getKey(); List value = e.getValue(); - log.info("Running version update for project [{}] and samples {}", key, - value); + log.info("Running version update for project [{}] and samples {}", key, value); ProjectVersion projectVersionForReleaseTrain = projects.forName(key); Projects postRelease = getPostReleaseProjects(projects); log.info("Versions to update the samples with \n" + postRelease.stream() - .map(v -> "[" + v.projectName + " => " + v.version + "]") - .collect(Collectors.joining("\n"))); + .map(v -> "[" + v.projectName + " => " + v.version + "]").collect(Collectors.joining("\n"))); return value.stream() .map(url -> run(key, url, - () -> commitUpdatedProject(projects, key, - projectVersionForReleaseTrain, postRelease, url))) + () -> commitUpdatedProject(projects, key, projectVersionForReleaseTrain, postRelease, url))) .map(this::getSingleResult).collect(Collectors.toList()); }); } Projects getPostReleaseProjects(Projects projects) { - return projects.postReleaseSnapshotVersion( - this.properties.getMetaRelease().getProjectsToSkip()); + return projects.postReleaseSnapshotVersion(this.properties.getMetaRelease().getProjectsToSkip()); } - private void commitUpdatedProject(Projects projects, String key, - ProjectVersion projectVersionForReleaseTrain, Projects postRelease, - String url) { + private void commitUpdatedProject(Projects projects, String key, ProjectVersion projectVersionForReleaseTrain, + Projects postRelease, String url) { String releaseTrainVersion = projects.releaseTrain(this.properties).version; String projectVersion = projects.forName(key).version; log.info( "Running version update for project [{}], url [{}], " + "release train version [{}] and project version [{}]", key, url, releaseTrainVersion, projectVersion); - File file = this.projectGitHandler.cloneAndGuessBranch(url, releaseTrainVersion, - projectVersion); + File file = this.projectGitHandler.cloneAndGuessBranch(url, releaseTrainVersion, projectVersion); Projects newPostRelease = new Projects(postRelease); ProjectVersion newProjectVersion = newProjectVersion(file); newPostRelease.add(newProjectVersion); updateWithVersions(file, newPostRelease); - this.projectGitHandler.commit(file, - "Updated versions after [" + releaseTrainVersion + "] " - + "release train and [" + projectVersionForReleaseTrain.version - + "] [" + key + "] project release"); + this.projectGitHandler.commit(file, "Updated versions after [" + releaseTrainVersion + "] " + + "release train and [" + projectVersionForReleaseTrain.version + "] [" + key + "] project release"); this.projectGitHandler.pushCurrentBranch(file); } @@ -261,20 +231,17 @@ public class PostReleaseActions implements Closeable { ProjectVersion projectVersion = ProjectVersion.notMavenProject(file); String name = projectVersion.projectName; String version = projectVersion.version; - log.warn( - "Exception occurred while trying to read the pom file. Will assume that the project name is [" - + name + "] and version [" + version + "]", - ex); + log.warn("Exception occurred while trying to read the pom file. Will assume that the project name is [" + + name + "] and version [" + version + "]", ex); return projectVersion; } } private void updateWithVersions(File file, Projects newPostRelease) { ReleaserProperties updatedProperties = updatedProperties(file); - this.projectPomUpdater.updateProjectFromReleaseTrain(file, newPostRelease, + this.projectPomUpdater.updateProjectFromReleaseTrain(file, newPostRelease, newProjectVersion(file), false); + this.gradleUpdater.updateProjectFromReleaseTrain(updatedProperties, file, newPostRelease, newProjectVersion(file), false); - this.gradleUpdater.updateProjectFromReleaseTrain(updatedProperties, file, - newPostRelease, newProjectVersion(file), false); } private ProjectAndFuture run(String key, String url, Runnable runnable) { @@ -293,8 +260,7 @@ public class PostReleaseActions implements Closeable { return new ProjectUrlAndException(projectAndFuture.key, projectAndFuture.url, e); } - private List getResult( - Future> future) { + private List getResult(Future> future) { try { return future.get(10, TimeUnit.MINUTES); } @@ -309,11 +275,9 @@ public class PostReleaseActions implements Closeable { * @return result of the execution */ public ExecutionResult generateReleaseTrainDocumentation(Projects projects) { - if (!this.properties.getGit().isUpdateReleaseTrainDocs() - || !this.properties.getMetaRelease().isEnabled()) { - log.info( - "Will not update the release train documentation, since the switch to do so " - + "is off. Set [releaser.git.update-release-train-docs] to [true] to change that"); + if (!this.properties.getGit().isUpdateReleaseTrainDocs() || !this.properties.getMetaRelease().isEnabled()) { + log.info("Will not update the release train documentation, since the switch to do so " + + "is off. Set [releaser.git.update-release-train-docs] to [true] to change that"); return ExecutionResult.skipped(); } ProjectVersion releaseTrain = projects.releaseTrain(this.properties); @@ -328,16 +292,14 @@ public class PostReleaseActions implements Closeable { } ReleaserProperties projectProps = projectProps(file); String releaseTrainVersion = releaseTrain.version; - this.projectCommandExecutor.generateReleaseTrainDocs(projectProps, - releaseTrainVersion, file.getAbsolutePath()); + this.projectCommandExecutor.generateReleaseTrainDocs(projectProps, releaseTrainVersion, file.getAbsolutePath()); return ExecutionResult.success(); } - private Projects addVersionForTestsProject(Projects projects, - ProjectVersion projectVersion, String releaseTrainVersion) { + private Projects addVersionForTestsProject(Projects projects, ProjectVersion projectVersion, + String releaseTrainVersion) { Projects newProjects = new Projects(projects); - newProjects - .add(new ProjectVersion(projectVersion.projectName, releaseTrainVersion)); + newProjects.add(new ProjectVersion(projectVersion.projectName, releaseTrainVersion)); return newProjects; } diff --git a/releaser-core/src/main/java/releaser/internal/project/ProcessedProject.java b/releaser-core/src/main/java/releaser/internal/project/ProcessedProject.java index 63429c05..5d3b056b 100644 --- a/releaser-core/src/main/java/releaser/internal/project/ProcessedProject.java +++ b/releaser-core/src/main/java/releaser/internal/project/ProcessedProject.java @@ -44,8 +44,8 @@ public class ProcessedProject implements Serializable { */ public final ProjectVersion originalProjectVersion; - public ProcessedProject(ReleaserProperties propertiesForProject, - ProjectVersion newProjectVersion, ProjectVersion originalProjectVersion) { + public ProcessedProject(ReleaserProperties propertiesForProject, ProjectVersion newProjectVersion, + ProjectVersion originalProjectVersion) { this.propertiesForProject = propertiesForProject; this.newProjectVersion = newProjectVersion; this.originalProjectVersion = originalProjectVersion; @@ -53,9 +53,8 @@ public class ProcessedProject implements Serializable { @Override public String toString() { - return "ProcessedProject{" + "name=" + this.newProjectVersion.projectName - + ",version=" + this.newProjectVersion.version + '}' - + ",originalProjectVersion=" + this.originalProjectVersion + '}'; + return "ProcessedProject{" + "name=" + this.newProjectVersion.projectName + ",version=" + + this.newProjectVersion.version + '}' + ",originalProjectVersion=" + this.originalProjectVersion + '}'; } public String projectName() { diff --git a/releaser-core/src/main/java/releaser/internal/project/Project.java b/releaser-core/src/main/java/releaser/internal/project/Project.java index a04894dc..63c49bba 100644 --- a/releaser-core/src/main/java/releaser/internal/project/Project.java +++ b/releaser-core/src/main/java/releaser/internal/project/Project.java @@ -55,8 +55,7 @@ public class Project { if (this.name != null ? !this.name.equals(project.name) : project.name != null) { return false; } - return this.version != null ? this.version.equals(project.version) - : project.version == null; + return this.version != null ? this.version.equals(project.version) : project.version == null; } @Override 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 acbd592e..e24553b1 100644 --- a/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java +++ b/releaser-core/src/main/java/releaser/internal/project/ProjectCommandExecutor.java @@ -48,8 +48,7 @@ import org.springframework.util.StringUtils; */ public class ProjectCommandExecutor { - private static final Logger log = LoggerFactory - .getLogger(ProjectCommandExecutor.class); + private static final Logger log = LoggerFactory.getLogger(ProjectCommandExecutor.class); private static final String VERSION_MUSTACHE = "{{version}}"; @@ -59,8 +58,7 @@ public class ProjectCommandExecutor { public void build(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion versionFromReleaseTrain) { - build(properties, originalVersion, versionFromReleaseTrain, - properties.getWorkingDir()); + build(properties, originalVersion, versionFromReleaseTrain, properties.getWorkingDir()); } public String version(ReleaserProperties properties) { @@ -73,8 +71,7 @@ public class ProjectCommandExecutor { new CommandPicker(properties, properties.getWorkingDir()).groupId()); } - private String executeCommandWithOutput(ReleaserProperties properties, - String command) { + private String executeCommandWithOutput(ReleaserProperties properties, String command) { try { String projectRoot = properties.getWorkingDir(); String[] commands = command.split(" "); @@ -91,27 +88,22 @@ public class ProjectCommandExecutor { public void build(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion versionFromReleaseTrain, String projectRoot) { try { - String command = new CommandPicker(properties, projectRoot) - .buildCommand(versionFromReleaseTrain); - String[] commands = replaceAllPlaceHolders(originalVersion, - versionFromReleaseTrain, command).split(" "); + String command = new CommandPicker(properties, projectRoot).buildCommand(versionFromReleaseTrain); + String[] commands = replaceAllPlaceHolders(originalVersion, versionFromReleaseTrain, command).split(" "); runCommand(properties, projectRoot, commands); assertNoHtmlFilesInDocsContainUnresolvedTags(projectRoot); log.info("No HTML files from docs contain unresolved tags"); } catch (Exception e) { - String message = properties + "\n" + originalVersion + "\n" - + versionFromReleaseTrain + "\n" + projectRoot; + String message = properties + "\n" + originalVersion + "\n" + versionFromReleaseTrain + "\n" + projectRoot; throw new IllegalStateException(message, e); } } - public void generateReleaseTrainDocs(ReleaserProperties properties, 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))) + .generateReleaseTrainDocsCommand(new ProjectVersion(new File(projectRoot))) .replace(VERSION_MUSTACHE, version); runCommand(properties, projectRoot, updatedCommand.split(" ")); assertNoHtmlFilesInDocsContainUnresolvedTags(properties.getWorkingDir()); @@ -135,25 +127,20 @@ public class ProjectCommandExecutor { } } - public void deploy(ReleaserProperties properties, ProjectVersion originalVersion, - ProjectVersion version) { + public void deploy(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion version) { doDeploy(properties, originalVersion, version, - new CommandPicker(properties, properties.getWorkingDir()) - .deployCommand(version)); + new CommandPicker(properties, properties.getWorkingDir()).deployCommand(version)); } - public void deployGuides(ReleaserProperties properties, - ProjectVersion originalVersion, ProjectVersion version) { + public void deployGuides(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion version) { doDeploy(properties, originalVersion, version, - new CommandPicker(properties, properties.getWorkingDir()) - .deployGuidesCommand(version)); + new CommandPicker(properties, properties.getWorkingDir()).deployGuidesCommand(version)); } - private void doDeploy(ReleaserProperties properties, 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 replacedCommand = replaceAllPlaceHolders(originalVersion, changedVersion, command); String[] commands = replacedCommand.split(" "); runCommand(properties, commands); log.info("The project has successfully been deployed"); @@ -167,21 +154,16 @@ public class ProjectCommandExecutor { runCommand(properties, properties.getWorkingDir(), commands); } - private void runCommand(ReleaserProperties properties, String projectRoot, - String[] commands) { + private void runCommand(ReleaserProperties properties, String projectRoot, String[] commands) { String[] substitutedCommands = substituteSystemProps(properties, commands); - long waitTimeInMinutes = new CommandPicker(properties, projectRoot) - .waitTimeInMinutes(); + long waitTimeInMinutes = new CommandPicker(properties, projectRoot).waitTimeInMinutes(); executor(projectRoot).runCommand(substitutedCommands, waitTimeInMinutes); } - private String captureCommandOutput(ReleaserProperties properties, String projectRoot, - String[] 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, - waitTimeInMinutes); + long waitTimeInMinutes = new CommandPicker(properties, projectRoot).waitTimeInMinutes(); + return executor(projectRoot).runCommandWithOutput(substitutedCommands, waitTimeInMinutes); } ReleaserProcessExecutor executor(String workDir) { @@ -191,15 +173,11 @@ public class ProjectCommandExecutor { public void publishDocs(ReleaserProperties properties, ProjectVersion originalVersion, ProjectVersion changedVersion) { try { - String providedCommand = new CommandPicker(properties) - .publishDocsCommand(changedVersion); - log.info("Executing command(s) for publishing docs " + providedCommand + " / " - + properties); - String[] providedCommands = StringUtils - .delimitedListToStringArray(providedCommand, "&&"); + String providedCommand = new CommandPicker(properties).publishDocsCommand(changedVersion); + log.info("Executing command(s) for publishing docs " + providedCommand + " / " + properties); + String[] providedCommands = StringUtils.delimitedListToStringArray(providedCommand, "&&"); for (String command : providedCommands) { - command = replaceAllPlaceHolders(originalVersion, changedVersion, - command.trim()); + command = replaceAllPlaceHolders(originalVersion, changedVersion, command.trim()); String[] commands = command.split(" "); runCommand(properties, commands); } @@ -210,8 +188,8 @@ public class ProjectCommandExecutor { } } - private String replaceAllPlaceHolders(ProjectVersion originalVersion, - ProjectVersion changedVersion, String command) { + private String replaceAllPlaceHolders(ProjectVersion originalVersion, ProjectVersion changedVersion, + String command) { return command.replace(VERSION_MUSTACHE, changedVersion.version) .replace(NEXT_VERSION_MUSTACHE, changedVersion.bumpedVersion()) .replace(OLD_VERSION_MUSTACHE, originalVersion.version); @@ -221,24 +199,18 @@ public class ProjectCommandExecutor { * 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(ReleaserProperties properties, - String... commands) { + private String[] substituteSystemProps(ReleaserProperties properties, String... commands) { String systemProperties = new CommandPicker(properties).systemProperties(); - String systemPropertiesPlaceholder = new CommandPicker(properties) - .systemPropertiesPlaceholder(); + String systemPropertiesPlaceholder = new CommandPicker(properties).systemPropertiesPlaceholder(); boolean containsSystemProps = systemProperties.contains("-D"); - String[] splitSystemProps = StringUtils - .delimitedListToStringArray(systemProperties, "-D"); + String[] splitSystemProps = StringUtils.delimitedListToStringArray(systemProperties, "-D"); // first element might be empty even though the second one contains values if (splitSystemProps.length > 1) { splitSystemProps = StringUtils.isEmpty(splitSystemProps[0]) - ? Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length) - : splitSystemProps; + ? Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length) : splitSystemProps; } - String[] systemPropsWithPrefix = containsSystemProps ? Arrays - .stream(splitSystemProps).map(s -> "-D" + s.trim()) - .collect(Collectors.toList()).toArray(new String[splitSystemProps.length]) - : splitSystemProps; + String[] systemPropsWithPrefix = containsSystemProps ? Arrays.stream(splitSystemProps).map(s -> "-D" + s.trim()) + .collect(Collectors.toList()).toArray(new String[splitSystemProps.length]) : splitSystemProps; final AtomicInteger index = new AtomicInteger(-1); for (int i = 0; i < commands.length; i++) { if (commands[i].contains(systemPropertiesPlaceholder)) { @@ -249,8 +221,7 @@ public class ProjectCommandExecutor { return toCommandList(systemPropsWithPrefix, index, commands); } - private String[] toCommandList(String[] systemPropsWithPrefix, AtomicInteger index, - String[] commands) { + private String[] toCommandList(String[] systemPropsWithPrefix, AtomicInteger index, String[] commands) { List commandsList = new ArrayList<>(Arrays.asList(commands)); List systemPropsList = Arrays.asList(systemPropsWithPrefix); if (index.get() != -1) { @@ -273,8 +244,7 @@ public class ProjectCommandExecutor { class ReleaserProcessExecutor { - private static final Logger log = LoggerFactory - .getLogger(ReleaserProcessExecutor.class); + private static final Logger log = LoggerFactory.getLogger(ReleaserProcessExecutor.class); private static String[] OS_OPERATORS = { "|", "<", ">", "||", "&&" }; @@ -294,17 +264,15 @@ class ReleaserProcessExecutor { private ProcessResult doRunCommand(String[] commands, long waitTimeInMinutes) { String workingDir = this.workingDir; - log.info("Will run the command from [{}] and wait for result for [{}] minutes", - workingDir, waitTimeInMinutes); + log.info("Will run the command from [{}] and wait for result for [{}] minutes", workingDir, waitTimeInMinutes); try { - ProcessExecutor processExecutor = processExecutor(commands, workingDir) - .timeout(waitTimeInMinutes, TimeUnit.MINUTES); + ProcessExecutor processExecutor = processExecutor(commands, workingDir).timeout(waitTimeInMinutes, + TimeUnit.MINUTES); final ProcessResult processResult = doExecute(processExecutor); int processExitValue = processResult.getExitValue(); if (processExitValue != 0) { - throw new IllegalStateException("The process has exited with exit code [" - + processExitValue + "]"); + throw new IllegalStateException("The process has exited with exit code [" + processExitValue + "]"); } return processResult; } @@ -312,10 +280,8 @@ class ReleaserProcessExecutor { throw new IllegalStateException("Process execution failed", e); } catch (TimeoutException e) { - log.error("The command hasn't managed to finish in [{}] minutes", - waitTimeInMinutes); - throw new IllegalStateException("Process waiting time of [" - + waitTimeInMinutes + "] minutes exceeded", e); + log.error("The command hasn't managed to finish in [{}] minutes", waitTimeInMinutes); + throw new IllegalStateException("Process waiting time of [" + waitTimeInMinutes + "] minutes exceeded", e); } } @@ -331,15 +297,13 @@ class ReleaserProcessExecutor { commandsToRun = commandToExecute(lastArg); } log.info("Will run the command [{}]", Arrays.toString(commandsToRun)); - return new ProcessExecutor().command(commandsToRun).destroyOnExit() - .readOutput(true) + return new ProcessExecutor().command(commandsToRun).destroyOnExit().readOutput(true) // releaser.commands logger should be configured to redirect // only to a file (with additivity=false). ideally the root logger should // append to same file on top of whatever root appender, so that file // contains the most output .redirectOutputAlsoTo(Slf4jStream.of("releaser.commands").asInfo()) - .redirectErrorAlsoTo(Slf4jStream.of("releaser.commands").asWarn()) - .directory(new File(workingDir)); + .redirectErrorAlsoTo(Slf4jStream.of("releaser.commands").asWarn()).directory(new File(workingDir)); } String[] commandToExecute(String lastArg) { @@ -389,12 +353,10 @@ class CommandPicker { public String publishDocsCommand(ProjectVersion version) { if (projectType == ProjectType.GRADLE) { - return mavenCommandWithSystemProps( - releaserProperties.getGradle().getPublishDocsCommand(), version); + return mavenCommandWithSystemProps(releaserProperties.getGradle().getPublishDocsCommand(), version); } else if (projectType == ProjectType.MAVEN) { - return mavenCommandWithSystemProps( - releaserProperties.getMaven().getPublishDocsCommand(), version); + return mavenCommandWithSystemProps(releaserProperties.getMaven().getPublishDocsCommand(), version); } return releaserProperties.getBash().getPublishDocsCommand(); } @@ -411,12 +373,10 @@ class CommandPicker { String buildCommand(ProjectVersion version) { if (projectType == ProjectType.GRADLE) { - return gradleCommandWithSystemProps( - releaserProperties.getGradle().getBuildCommand()); + return gradleCommandWithSystemProps(releaserProperties.getGradle().getBuildCommand()); } else if (projectType == ProjectType.MAVEN) { - return mavenCommandWithSystemProps( - releaserProperties.getMaven().getBuildCommand(), version); + return mavenCommandWithSystemProps(releaserProperties.getMaven().getBuildCommand(), version); } return bashCommandWithSystemProps(releaserProperties.getBash().getBuildCommand()); } @@ -426,9 +386,8 @@ class CommandPicker { if (projectType == ProjectType.GRADLE) { return "./gradlew properties | grep version: | awk '{print $2}'"; } - return "./mvnw -q" + " -Dexec.executable=\"echo\"" - + " -Dexec.args=\"\\${project.version}\"" + " --non-recursive" - + " org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -1"; + return "./mvnw -q" + " -Dexec.executable=\"echo\"" + " -Dexec.args=\"\\${project.version}\"" + + " --non-recursive" + " org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -1"; } String groupId() { @@ -436,50 +395,40 @@ class CommandPicker { if (projectType == ProjectType.GRADLE) { return "./gradlew groupId -q | tail -1"; } - return "./mvnw -q" + " -Dexec.executable=\"echo\"" - + " -Dexec.args=\"\\${project.groupId}\"" + " --non-recursive" - + " org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -1"; + return "./mvnw -q" + " -Dexec.executable=\"echo\"" + " -Dexec.args=\"\\${project.groupId}\"" + + " --non-recursive" + " org.codehaus.mojo:exec-maven-plugin:1.3.1:exec | tail -1"; } String generateReleaseTrainDocsCommand(ProjectVersion version) { if (projectType == ProjectType.GRADLE) { - return gradleCommandWithSystemProps( - releaserProperties.getGradle().getGenerateReleaseTrainDocsCommand()); + return gradleCommandWithSystemProps(releaserProperties.getGradle().getGenerateReleaseTrainDocsCommand()); } else if (projectType == ProjectType.MAVEN) { - return mavenCommandWithSystemProps( - releaserProperties.getMaven().getGenerateReleaseTrainDocsCommand(), + return mavenCommandWithSystemProps(releaserProperties.getMaven().getGenerateReleaseTrainDocsCommand(), version); } - return bashCommandWithSystemProps( - releaserProperties.getBash().getGenerateReleaseTrainDocsCommand()); + return bashCommandWithSystemProps(releaserProperties.getBash().getGenerateReleaseTrainDocsCommand()); } String deployCommand(ProjectVersion version) { if (projectType == ProjectType.GRADLE) { - return gradleCommandWithSystemProps( - releaserProperties.getGradle().getDeployCommand()); + return gradleCommandWithSystemProps(releaserProperties.getGradle().getDeployCommand()); } else if (projectType == ProjectType.MAVEN) { - return mavenCommandWithSystemProps( - releaserProperties.getMaven().getDeployCommand(), version); + return mavenCommandWithSystemProps(releaserProperties.getMaven().getDeployCommand(), version); } - return bashCommandWithSystemProps( - releaserProperties.getBash().getDeployCommand()); + return bashCommandWithSystemProps(releaserProperties.getBash().getDeployCommand()); } String deployGuidesCommand(ProjectVersion version) { if (projectType == ProjectType.GRADLE) { - return gradleCommandWithSystemProps( - releaserProperties.getGradle().getDeployGuidesCommand()); + return gradleCommandWithSystemProps(releaserProperties.getGradle().getDeployGuidesCommand()); } else if (projectType == ProjectType.MAVEN) { - return mavenCommandWithSystemProps( - releaserProperties.getMaven().getDeployGuidesCommand(), version, + return mavenCommandWithSystemProps(releaserProperties.getMaven().getDeployGuidesCommand(), version, MavenProfile.GUIDES, MavenProfile.INTEGRATION); } - return bashCommandWithSystemProps( - releaserProperties.getBash().getDeployGuidesCommand()); + return bashCommandWithSystemProps(releaserProperties.getBash().getDeployGuidesCommand()); } long waitTimeInMinutes() { @@ -499,13 +448,11 @@ class CommandPicker { return command + " " + ReleaserProperties.Gradle.SYSTEM_PROPS_PLACEHOLDER; } - private String mavenCommandWithSystemProps(String command, ProjectVersion version, - MavenProfile... profiles) { + private String mavenCommandWithSystemProps(String command, ProjectVersion version, MavenProfile... profiles) { if (command.contains(ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER)) { return appendMavenProfile(command, version, profiles); } - return appendMavenProfile(command, version, profiles) + " " - + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER; + return appendMavenProfile(command, version, profiles) + " " + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER; } private String bashCommandWithSystemProps(String command) { @@ -515,22 +462,18 @@ class CommandPicker { return command + " " + ReleaserProperties.Maven.SYSTEM_PROPS_PLACEHOLDER; } - private String appendMavenProfile(String command, ProjectVersion version, - MavenProfile... profiles) { + private String appendMavenProfile(String command, ProjectVersion version, MavenProfile... profiles) { String trimmedCommand = command.trim(); if (version.isMilestone() || version.isRc()) { log.info("Adding the milestone profile to the Maven build"); - return withProfile(trimmedCommand, MavenProfile.MILESTONE.asMavenProfile(), - profiles); + return withProfile(trimmedCommand, MavenProfile.MILESTONE.asMavenProfile(), profiles); } else if (version.isRelease() || version.isServiceRelease()) { log.info("Adding the central profile to the Maven build"); - return withProfile(trimmedCommand, MavenProfile.CENTRAL.asMavenProfile(), - profiles); + return withProfile(trimmedCommand, MavenProfile.CENTRAL.asMavenProfile(), profiles); } else { - log.info("The version [" + version.toString() - + "] is a snapshot one - will not add any profiles"); + log.info("The version [" + version.toString() + "] is a snapshot one - will not add any profiles"); } return trimmedCommand; } @@ -548,8 +491,7 @@ class CommandPicker { } private String profilesToString(MavenProfile... profiles) { - return Arrays.stream(profiles).map(profile -> "-P" + profile) - .collect(Collectors.joining(" ")); + return Arrays.stream(profiles).map(profile -> "-P" + profile).collect(Collectors.joining(" ")); } private enum ProjectType { @@ -602,10 +544,8 @@ class HtmlFileWalker extends SimpleFileVisitor { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attr) { File file = path.toFile(); - if (file.getName().endsWith(HTML_EXTENSION) - && asString(file).contains("Unresolved")) { - throw new IllegalStateException( - "File [" + file + "] contains a tag that wasn't resolved properly"); + if (file.getName().endsWith(HTML_EXTENSION) && asString(file).contains("Unresolved")) { + throw new IllegalStateException("File [" + file + "] contains a tag that wasn't resolved properly"); } return FileVisitResult.CONTINUE; } 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 0d532da5..4063a059 100644 --- a/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java +++ b/releaser-core/src/main/java/releaser/internal/project/ProjectVersion.java @@ -51,8 +51,7 @@ public class ProjectVersion implements Comparable, Serializable private static final Logger log = LoggerFactory.getLogger(ProjectVersion.class); - private static final Pattern SNAPSHOT_PATTERN = Pattern - .compile("^.*[\\.|\\-](BUILD-)?SNAPSHOT.*$"); + private static final Pattern SNAPSHOT_PATTERN = Pattern.compile("^.*[\\.|\\-](BUILD-)?SNAPSHOT.*$"); private static final String MILESTONE_REGEX = "^.*[\\.|\\-]M[0-9]+.*$"; @@ -62,12 +61,11 @@ public class ProjectVersion implements Comparable, Serializable private static final String SR_REGEX = "^.*[\\.|\\-]SR[0-9]+.*$"; - private static final Pattern SEMVER_PATTERN = Pattern - .compile("(\\d+)\\.(\\d+)\\.(\\d+)"); + private static final Pattern SEMVER_PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)"); private static final List VALID_PATTERNS = Arrays.asList(SNAPSHOT_PATTERN, - Pattern.compile(MILESTONE_REGEX), Pattern.compile(RC_REGEX), - Pattern.compile(RELEASE_REGEX), Pattern.compile(SR_REGEX)); + Pattern.compile(MILESTONE_REGEX), Pattern.compile(RC_REGEX), Pattern.compile(RELEASE_REGEX), + Pattern.compile(SR_REGEX)); /** * Name of the project. @@ -164,8 +162,7 @@ public class ProjectVersion implements Comparable, Serializable if (StringUtils.hasText(model.getGroupId())) { return model.getGroupId(); } - if (model.getParent() != null - && StringUtils.hasText(model.getParent().getGroupId())) { + if (model.getParent() != null && StringUtils.hasText(model.getParent().getGroupId())) { return model.getParent().getGroupId(); } return ""; @@ -222,8 +219,7 @@ public class ProjectVersion implements Comparable, Serializable int indexOfFirstHyphen = version.indexOf("-"); boolean buildSnapshot = version.endsWith("BUILD-SNAPSHOT"); - if (numberOfHyphens == 1 && !buildSnapshot - || (numberOfHyphens > 1 && buildSnapshot)) { + if (numberOfHyphens == 1 && !buildSnapshot || (numberOfHyphens > 1 && buildSnapshot)) { // Dysprosium or 1.0.0 String versionName = version.substring(0, indexOfFirstHyphen); boolean hasDots = versionName.contains("."); @@ -243,8 +239,7 @@ public class ProjectVersion implements Comparable, Serializable return SplitVersion.hyphen(newArray); } else { - throw new UnsupportedOperationException( - "Unknown version [" + version + "]"); + throw new UnsupportedOperationException("Unknown version [" + version + "]"); } } return null; @@ -319,8 +314,7 @@ public class ProjectVersion implements Comparable, Serializable } public String majorAndMinor() { - return this.assertVersion().major + this.assertVersion().delimiter - + this.assertVersion().minor; + return this.assertVersion().major + this.assertVersion().delimiter + this.assertVersion().minor; } /** @@ -345,15 +339,14 @@ public class ProjectVersion implements Comparable, Serializable patch = Integer.parseInt(splitVersion.patch); } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("Version " + this.version - + " doesn't contain a numerical PATCH number", nfe); + throw new IllegalArgumentException("Version " + this.version + " doesn't contain a numerical PATCH number", + nfe); } if (patch == 0) { return Optional.empty(); } - return Optional.of(prefix + splitVersion.major + splitVersion.delimiter - + splitVersion.minor + splitVersion.delimiter + (patch - 1) - + splitVersion.delimiter + suffix); + return Optional.of(prefix + splitVersion.major + splitVersion.delimiter + splitVersion.minor + + splitVersion.delimiter + (patch - 1) + splitVersion.delimiter + suffix); } /** @@ -368,8 +361,7 @@ public class ProjectVersion implements Comparable, Serializable * previous MAJOR.MINOR, or empty if current MINOR is 0 * @see #computePreviousMajorTagPattern(String, String) */ - public Optional computePreviousMinorTagPattern(String prefix, - String suffix) { + public Optional computePreviousMinorTagPattern(String prefix, String suffix) { SplitVersion splitVersion = this.assertVersion(); if (suffix.isEmpty()) { suffix = splitVersion.suffix; @@ -380,17 +372,15 @@ public class ProjectVersion implements Comparable, Serializable minor = Integer.parseInt(splitVersion.minor); } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("Version " + this.version - + " doesn't contain a numerical MINOR number", nfe); + throw new IllegalArgumentException("Version " + this.version + " doesn't contain a numerical MINOR number", + nfe); } if (minor == 0) { return Optional.empty(); } - Pattern p = Pattern - .compile(Pattern - .quote(prefix + splitVersion.major + splitVersion.delimiter - + (minor - 1) + splitVersion.delimiter) - + "\\d+" + quotedSuffix); + Pattern p = Pattern.compile(Pattern + .quote(prefix + splitVersion.major + splitVersion.delimiter + (minor - 1) + splitVersion.delimiter) + + "\\d+" + quotedSuffix); return Optional.of(p); } @@ -414,16 +404,14 @@ public class ProjectVersion implements Comparable, Serializable major = Integer.parseInt(splitVersion.major); } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("Version " + this.version - + " doesn't contain a numerical MAJOR number", nfe); + throw new IllegalArgumentException("Version " + this.version + " doesn't contain a numerical MAJOR number", + nfe); } if (major == 0) { - throw new IllegalArgumentException( - "Cannot compute previous MAJOR pattern with MAJOR of 0"); + throw new IllegalArgumentException("Cannot compute previous MAJOR pattern with MAJOR of 0"); } - return Pattern.compile( - Pattern.quote(prefix + (major - 1) + splitVersion.delimiter) + "\\d+" - + Pattern.quote(splitVersion.delimiter) + "\\d+" + quotedSuffix); + return Pattern.compile(Pattern.quote(prefix + (major - 1) + splitVersion.delimiter) + "\\d+" + + Pattern.quote(splitVersion.delimiter) + "\\d+" + quotedSuffix); } public boolean isSnapshot() { @@ -511,8 +499,7 @@ public class ProjectVersion implements Comparable, Serializable private ReleaseType releaseTypeForReleaseTrain() { try { SplitVersion splitVersion = assertVersion(); - if (StringUtils.isEmpty(splitVersion.suffix) - && StringUtils.hasText(splitVersion.patch)) { + if (StringUtils.isEmpty(splitVersion.suffix) && StringUtils.hasText(splitVersion.patch)) { if ("0".equals(splitVersion.patch)) { return ReleaseType.RELEASE; } @@ -537,8 +524,7 @@ public class ProjectVersion implements Comparable, Serializable SplitVersion thatSplit = that.assertVersion(); int releaseTypeComparison = this.releaseType.compareTo(that.releaseType); boolean thisReleaseTypeHigher = releaseTypeComparison > 0; - boolean bothGa = this.isReleaseOrServiceRelease() - && that.isReleaseOrServiceRelease(); + boolean bothGa = this.isReleaseOrServiceRelease() && that.isReleaseOrServiceRelease(); // 1.0.1.M2 vs 1.0.0.RELEASE (x) if (thisReleaseTypeHigher && !bothGa) { return 1; @@ -587,8 +573,7 @@ public class ProjectVersion implements Comparable, Serializable else if (thisVersion.isOldReleaseTrain()) { return false; } - return thisVersion.major.equals(thatVersion.major) - && thisVersion.minor.equals(thatVersion.minor); + return thisVersion.major.equals(thatVersion.major) && thisVersion.minor.equals(thatVersion.minor); } private void assertVersionSet() { @@ -598,8 +583,7 @@ public class ProjectVersion implements Comparable, Serializable } public int compareToReleaseTrain(String version) { - return new TrainVersionNumber(this) - .compareTo(new TrainVersionNumber(new ProjectVersion(version))); + return new TrainVersionNumber(this).compareTo(new TrainVersionNumber(new ProjectVersion(version))); } /** @@ -643,8 +627,7 @@ public class ProjectVersion implements Comparable, Serializable return Collections.singletonList(SNAPSHOT_PATTERN); } // treat like GA - return Arrays.asList(SNAPSHOT_PATTERN, Pattern.compile(MILESTONE_REGEX), - Pattern.compile(RC_REGEX)); + return Arrays.asList(SNAPSHOT_PATTERN, Pattern.compile(MILESTONE_REGEX), Pattern.compile(RC_REGEX)); } @Override @@ -675,8 +658,7 @@ public class ProjectVersion implements Comparable, Serializable // 1.0.0.RELEASE // 1.0.0-RELEASE - private SplitVersion(String major, String minor, String patch, String delimiter, - String suffix) { + private SplitVersion(String major, String minor, String patch, String delimiter, String suffix) { this.major = major; this.minor = minor; this.patch = patch; @@ -764,15 +746,13 @@ public class ProjectVersion implements Comparable, Serializable private SplitVersion fullVersionWithIncrementedPatch() { int incrementedPatch = Integer.parseInt(patch) + 1; - return new SplitVersion(major, minor, Integer.toString(incrementedPatch), - delimiter, suffix); + return new SplitVersion(major, minor, Integer.toString(incrementedPatch), delimiter, suffix); } String print() { // Finchley.SR2 if (StringUtils.isEmpty(minor)) { - return StringUtils.isEmpty(suffix) ? major - : String.format("%s%s%s", major, delimiter, suffix); + return StringUtils.isEmpty(suffix) ? major : String.format("%s%s%s", major, delimiter, suffix); } else if (StringUtils.isEmpty(suffix)) { return String.format("%s.%s.%s", major, minor, patch); @@ -790,8 +770,7 @@ public class ProjectVersion implements Comparable, Serializable private boolean tooFewElements() { // 1 is wrong but Finchley-SR3 is ok - return StringUtils.isEmpty(minor) && StringUtils.isEmpty(patch) - && StringUtils.isEmpty(suffix); + return StringUtils.isEmpty(minor) && StringUtils.isEmpty(patch) && StringUtils.isEmpty(suffix); } private SplitVersion withSnapshot() { @@ -807,9 +786,8 @@ public class ProjectVersion implements Comparable, Serializable @Override public String toString() { - return new ToStringCreator(this).append("major", major).append("minor", minor) - .append("patch", patch).append("delimiter", delimiter) - .append("suffix", suffix).toString(); + return new ToStringCreator(this).append("major", major).append("minor", minor).append("patch", patch) + .append("delimiter", delimiter).append("suffix", suffix).toString(); } @@ -859,11 +837,9 @@ public class ProjectVersion implements Comparable, Serializable } } - private int compareWithOldTrain(ProjectVersion oldTrain, - ProjectVersion thatVersion) { + private int compareWithOldTrain(ProjectVersion oldTrain, ProjectVersion thatVersion) { // Hoxton.SR5 > 2020.0.0-M5 - if (oldTrain.isReleaseOrServiceRelease() - && !thatVersion.isReleaseOrServiceRelease()) { + if (oldTrain.isReleaseOrServiceRelease() && !thatVersion.isReleaseOrServiceRelease()) { return 1; } // Hoxton.SR5 < 2020.0.0-RELEASE diff --git a/releaser-core/src/main/java/releaser/internal/project/Projects.java b/releaser-core/src/main/java/releaser/internal/project/Projects.java index c15ddccd..44358fd5 100644 --- a/releaser-core/src/main/java/releaser/internal/project/Projects.java +++ b/releaser-core/src/main/java/releaser/internal/project/Projects.java @@ -40,8 +40,7 @@ public class Projects extends HashSet { @SuppressWarnings("unchecked") public Projects(ProjectVersion... versions) { - addAll(new HashSet<>(Arrays.stream(versions).filter(Objects::nonNull) - .collect(Collectors.toList()))); + addAll(new HashSet<>(Arrays.stream(versions).filter(Objects::nonNull).collect(Collectors.toList()))); } public Projects(List versions) { @@ -62,36 +61,31 @@ public class Projects extends HashSet { }); Projects newProjects = new Projects(foundProjectsToSkip); foundProjectsToBump.forEach(projectVersion -> newProjects - .add(new ProjectVersion(projectVersion.projectName, - projectVersion.postReleaseSnapshotVersion()))); + .add(new ProjectVersion(projectVersion.projectName, projectVersion.postReleaseSnapshotVersion()))); newProjects.addAll(foundProjectsToSkip); return newProjects; } - private static IllegalStateException exception(Projects projects, - String projectName) { - return new IllegalStateException("Project with name [" + projectName - + "] is not present in the list of projects [" + projects.asList() - + "] . " + additionalErrorMessage(projectName)); + private static IllegalStateException exception(Projects projects, String projectName) { + return new IllegalStateException( + "Project with name [" + projectName + "] is not present in the list of projects [" + projects.asList() + + "] . " + additionalErrorMessage(projectName)); } private static String additionalErrorMessage(String projectName) { - return "Either put it in the BOM or set it via the [--releaser.fixed-versions[" - + projectName + "]=1.0.0.RELEASE] property"; + return "Either put it in the BOM or set it via the [--releaser.fixed-versions[" + projectName + + "]=1.0.0.RELEASE] property"; } public ProjectVersion releaseTrain(ReleaserProperties properties) { return stream() - .filter(version -> version.projectName - .equals(properties.getMetaRelease().getReleaseTrainProjectName()) - || properties.getMetaRelease().getReleaseTrainDependencyNames() - .contains(version.projectName)) + .filter(version -> version.projectName.equals(properties.getMetaRelease().getReleaseTrainProjectName()) + || properties.getMetaRelease().getReleaseTrainDependencyNames().contains(version.projectName)) .findFirst() - .orElseThrow(() -> new IllegalStateException("Projects " + this - + " don't contain any of the following release train names [" - + properties.getMetaRelease().getReleaseTrainProjectName() - + "] or " - + properties.getMetaRelease().getReleaseTrainDependencyNames())); + .orElseThrow(() -> new IllegalStateException( + "Projects " + this + " don't contain any of the following release train names [" + + properties.getMetaRelease().getReleaseTrainProjectName() + "] or " + + properties.getMetaRelease().getReleaseTrainDependencyNames())); } @Override @@ -110,8 +104,7 @@ public class Projects extends HashSet { public Projects postReleaseSnapshotVersion(List projectsToSkip) { Projects projects = this.stream().filter(v -> projectsToSkip(projectsToSkip, v)) .collect(Collectors.toCollection(Projects::new)); - Projects bumped = this.stream().map( - v -> new ProjectVersion(v.projectName, v.postReleaseSnapshotVersion())) + Projects bumped = this.stream().map(v -> new ProjectVersion(v.projectName, v.postReleaseSnapshotVersion())) .collect(Collectors.toCollection(Projects::new)); Projects merged = new Projects(projects); merged.addAll(bumped); @@ -129,26 +122,21 @@ public class Projects extends HashSet { public ProjectVersion forFile(File projectRoot) { final ProjectVersion thisProject = new ProjectVersion(projectRoot); - return this.stream() - .filter(projectVersion -> projectVersion.projectName - .equals(thisProject.projectName)) + return this.stream().filter(projectVersion -> projectVersion.projectName.equals(thisProject.projectName)) .findFirst().orElseThrow(() -> exception(this, thisProject.projectName)); } public ProjectVersion forName(String projectName) { - return this.stream() - .filter(projectVersion -> projectVersion.projectName.equals(projectName)) - .findFirst().orElseThrow(() -> exception(this, projectName)); + return this.stream().filter(projectVersion -> projectVersion.projectName.equals(projectName)).findFirst() + .orElseThrow(() -> exception(this, projectName)); } public boolean containsProject(String projectName) { - return this.stream().anyMatch( - projectVersion -> projectVersion.projectName.equals(projectName)); + return this.stream().anyMatch(projectVersion -> projectVersion.projectName.equals(projectName)); } public List forNameStartingWith(String projectName) { - return this.stream().filter( - projectVersion -> projectVersion.projectName.startsWith(projectName)) + return this.stream().filter(projectVersion -> projectVersion.projectName.startsWith(projectName)) .collect(Collectors.toList()); } @@ -162,14 +150,13 @@ public class Projects extends HashSet { } public Set asProjects() { - return this.stream().map(projectVersion -> new Project(projectVersion.projectName, - projectVersion.version)).collect(Collectors.toSet()); + return this.stream().map(projectVersion -> new Project(projectVersion.projectName, projectVersion.version)) + .collect(Collectors.toSet()); } @Override public String toString() { - return stream().map(v -> "[" + v.projectName + "=>" + v.version + "]") - .collect(Collectors.joining("\n")); + return stream().map(v -> "[" + v.projectName + "=>" + v.version + "]").collect(Collectors.joining("\n")); } } diff --git a/releaser-core/src/main/java/releaser/internal/sagan/Project.java b/releaser-core/src/main/java/releaser/internal/sagan/Project.java index 3450b51a..d21a3e1e 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/Project.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/Project.java @@ -61,14 +61,11 @@ public class Project { @Override public String toString() { - return "Project{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' - + ", repoUrl='" + this.repoUrl + '\'' + ", siteUrl='" + this.siteUrl - + '\'' + ", category='" + this.category + '\'' + ", stackOverflowTags='" - + this.stackOverflowTags + '\'' + ", projectReleases=" - + this.projectReleases + ", stackOverflowTagList=" - + this.stackOverflowTagList + ", aggregator=" + this.aggregator - + ", rawBootConfig='" + this.rawBootConfig + '\'' + ", rawOverview='" - + this.rawOverview + '\'' + '}'; + return "Project{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' + ", repoUrl='" + this.repoUrl + + '\'' + ", siteUrl='" + this.siteUrl + '\'' + ", category='" + this.category + '\'' + + ", stackOverflowTags='" + this.stackOverflowTags + '\'' + ", projectReleases=" + this.projectReleases + + ", stackOverflowTagList=" + this.stackOverflowTagList + ", aggregator=" + this.aggregator + + ", rawBootConfig='" + this.rawBootConfig + '\'' + ", rawOverview='" + this.rawOverview + '\'' + '}'; } static class MostCurrentRelease { diff --git a/releaser-core/src/main/java/releaser/internal/sagan/Release.java b/releaser-core/src/main/java/releaser/internal/sagan/Release.java index 873e6369..41c47055 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/Release.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/Release.java @@ -50,14 +50,12 @@ public class Release { @Override public String toString() { - return "Release{" + "releaseStatus='" + this.releaseStatus + '\'' - + ", refDocUrl='" + this.refDocUrl + '\'' + ", apiDocUrl='" - + this.apiDocUrl + '\'' + ", groupId='" + this.groupId + '\'' - + ", artifactId='" + this.artifactId + '\'' + ", repository=" - + this.repository + ", version='" + this.version + '\'' + ", current=" - + this.current + ", generalAvailability=" + this.generalAvailability - + ", preRelease=" + this.preRelease + ", versionDisplayName='" - + this.versionDisplayName + '\'' + ", snapshot=" + this.snapshot + '}'; + return "Release{" + "releaseStatus='" + this.releaseStatus + '\'' + ", refDocUrl='" + this.refDocUrl + '\'' + + ", apiDocUrl='" + this.apiDocUrl + '\'' + ", groupId='" + this.groupId + '\'' + ", artifactId='" + + this.artifactId + '\'' + ", repository=" + this.repository + ", version='" + this.version + '\'' + + ", current=" + this.current + ", generalAvailability=" + this.generalAvailability + ", preRelease=" + + this.preRelease + ", versionDisplayName='" + this.versionDisplayName + '\'' + ", snapshot=" + + this.snapshot + '}'; } } diff --git a/releaser-core/src/main/java/releaser/internal/sagan/ReleaseUpdate.java b/releaser-core/src/main/java/releaser/internal/sagan/ReleaseUpdate.java index dcadbc63..e4b38f18 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/ReleaseUpdate.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/ReleaseUpdate.java @@ -42,11 +42,10 @@ public class ReleaseUpdate { @Override public String toString() { - return "ReleaseUpdate{" + "groupId='" + this.groupId + '\'' + ", artifactId='" - + this.artifactId + '\'' + ", version='" + this.version + '\'' - + ", releaseStatus='" + this.releaseStatus + '\'' + ", refDocUrl='" - + this.refDocUrl + '\'' + ", apiDocUrl='" + this.apiDocUrl + '\'' - + ", repository=" + this.repository + '}'; + return "ReleaseUpdate{" + "groupId='" + this.groupId + '\'' + ", artifactId='" + this.artifactId + '\'' + + ", version='" + this.version + '\'' + ", releaseStatus='" + this.releaseStatus + '\'' + + ", refDocUrl='" + this.refDocUrl + '\'' + ", apiDocUrl='" + this.apiDocUrl + '\'' + ", repository=" + + this.repository + '}'; } } diff --git a/releaser-core/src/main/java/releaser/internal/sagan/Repository.java b/releaser-core/src/main/java/releaser/internal/sagan/Repository.java index b29c0e42..a3548d85 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/Repository.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/Repository.java @@ -34,9 +34,8 @@ public class Repository { @Override public String toString() { - return "Repository{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' - + ", url='" + this.url + '\'' + ", snapshotsEnabled=" - + this.snapshotsEnabled + '}'; + return "Repository{" + "id='" + this.id + '\'' + ", name='" + this.name + '\'' + ", url='" + this.url + '\'' + + ", snapshotsEnabled=" + this.snapshotsEnabled + '}'; } } diff --git a/releaser-core/src/main/java/releaser/internal/sagan/RestTemplateSaganClient.java b/releaser-core/src/main/java/releaser/internal/sagan/RestTemplateSaganClient.java index bb5826dd..a86d23d6 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/RestTemplateSaganClient.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/RestTemplateSaganClient.java @@ -36,8 +36,7 @@ import org.springframework.web.client.RestTemplate; */ class RestTemplateSaganClient implements SaganClient { - private static final Logger log = LoggerFactory - .getLogger(RestTemplateSaganClient.class); + private static final Logger log = LoggerFactory.getLogger(RestTemplateSaganClient.class); private final RestTemplate restTemplate; @@ -50,26 +49,22 @@ class RestTemplateSaganClient implements SaganClient { @Override public Project getProject(String projectName) { - return this.restTemplate.getForObject( - this.baseUrl + "/project_metadata/{projectName}", Project.class, + return this.restTemplate.getForObject(this.baseUrl + "/project_metadata/{projectName}", Project.class, projectName); } @Override public Release getRelease(String projectName, String releaseVersion) { return this.restTemplate.getForObject( - this.baseUrl - + "/project_metadata/{projectName}/releases/{releaseVersion}", - Release.class, projectName, releaseVersion); + this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}", Release.class, projectName, + releaseVersion); } @Override public Release deleteRelease(String projectName, String releaseVersion) { ResponseEntity entity = this.restTemplate.exchange( - this.baseUrl - + "/project_metadata/{projectName}/releases/{releaseVersion}", - HttpMethod.DELETE, new HttpEntity<>(""), Release.class, projectName, - releaseVersion); + this.baseUrl + "/project_metadata/{projectName}/releases/{releaseVersion}", HttpMethod.DELETE, + new HttpEntity<>(""), Release.class, projectName, releaseVersion); Release release = entity.getBody(); log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, release); return release; @@ -78,12 +73,9 @@ class RestTemplateSaganClient implements SaganClient { @Override public Project updateRelease(String projectName, List releaseUpdates) { RequestEntity> request = RequestEntity - .put(URI.create( - this.baseUrl + "/project_metadata/" + projectName + "/releases")) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) - .body(releaseUpdates); - ResponseEntity entity = this.restTemplate.exchange(request, - Project.class); + .put(URI.create(this.baseUrl + "/project_metadata/" + projectName + "/releases")) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).body(releaseUpdates); + ResponseEntity entity = this.restTemplate.exchange(request, Project.class); Project project = entity.getBody(); log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, project); return project; @@ -93,10 +85,8 @@ class RestTemplateSaganClient implements SaganClient { public Project patchProject(Project project) { RequestEntity request = RequestEntity .patch(URI.create(this.baseUrl + "/project_metadata/" + project.id)) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE) - .body(project); - ResponseEntity entity = this.restTemplate.exchange(request, - Project.class); + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE).body(project); + ResponseEntity entity = this.restTemplate.exchange(request, Project.class); Project updatedProject = entity.getBody(); log.info("Response from Sagan\n\n[{}] \n with body [{}]", entity, updatedProject); return updatedProject; diff --git a/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java b/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java index a3a8b7c7..74c2087d 100644 --- a/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java +++ b/releaser-core/src/main/java/releaser/internal/sagan/SaganUpdater.java @@ -19,11 +19,11 @@ package releaser.internal.sagan; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.Collections; import java.util.Comparator; import java.util.Optional; import java.util.stream.Collectors; -import edu.emory.mathcs.backport.java.util.Collections; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import releaser.internal.ReleaserProperties; @@ -50,37 +50,30 @@ public class SaganUpdater { this.releaserProperties = releaserProperties; } - public ExecutionResult updateSagan(File projectFile, String branch, - ProjectVersion originalVersion, ProjectVersion currentVersion, - Projects projects) { + public ExecutionResult updateSagan(File projectFile, String branch, ProjectVersion originalVersion, + ProjectVersion currentVersion, Projects projects) { if (!this.releaserProperties.getSagan().isUpdateSagan()) { log.info("Will not update sagan, since the switch to do so " + "is off. Set [releaser.sagan.update-sagan] to [true] to change that"); return ExecutionResult.skipped(); } - ReleaseUpdate update = releaseUpdate(branch, originalVersion, currentVersion, - projects); - Exception updateReleaseException = updateSaganForNonSnapshot(branch, - originalVersion, currentVersion, projects); + ReleaseUpdate update = releaseUpdate(branch, originalVersion, currentVersion, projects); + Exception updateReleaseException = updateSaganForNonSnapshot(branch, originalVersion, currentVersion, projects); if (updateReleaseException == null) { log.info("Updating Sagan releases with \n\n{}", update); try { - Project project = this.saganClient.updateRelease( - currentVersion.projectName, Collections.singletonList(update)); - Optional projectVersion = latestVersion(currentVersion, - project); - log.info("Found the following latest project version [{}]", - projectVersion); + Project project = this.saganClient.updateRelease(currentVersion.projectName, + Collections.singletonList(update)); + Optional projectVersion = latestVersion(currentVersion, project); + log.info("Found the following latest project version [{}]", projectVersion); boolean present = projectVersion.isPresent(); - if (present - && currentVersionNewerOrEqual(currentVersion, projectVersion)) { + if (present && currentVersionNewerOrEqual(currentVersion, projectVersion)) { updateDocumentationIfNecessary(projectFile, project); } else { log.info(present - ? "Latest version [" + projectVersion.get() + "] present and " - + "the current version [" + currentVersion - + "] is older than that one. " + "Will do nothing." + ? "Latest version [" + projectVersion.get() + "] present and " + "the current version [" + + currentVersion + "] is older than that one. " + "Will do nothing." : "No latest version found. Will do nothing."); return ExecutionResult.skipped(); } @@ -91,23 +84,19 @@ public class SaganUpdater { } } return updateReleaseException == null ? ExecutionResult.success() - : ExecutionResult.unstable( - new IllegalStateException(updateReleaseException.getMessage())); + : ExecutionResult.unstable(new IllegalStateException(updateReleaseException.getMessage())); } private void updateDocumentationIfNecessary(File projectFile, Project project) { boolean shouldUpdate = false; File docsModule = docsModule(projectFile); - File indexDoc = new File(docsModule, - this.releaserProperties.getSagan().getIndexSectionFileName()); - File bootDoc = new File(docsModule, - this.releaserProperties.getSagan().getBootSectionFileName()); + File indexDoc = new File(docsModule, this.releaserProperties.getSagan().getIndexSectionFileName()); + File bootDoc = new File(docsModule, this.releaserProperties.getSagan().getBootSectionFileName()); if (indexDoc.exists()) { log.debug("Index adoc file exists"); String fileText = fileToText(indexDoc); if (StringUtils.hasText(fileText) && !fileText.equals(project.rawOverview)) { - log.info( - "Index adoc content differs from the previously stored, will update it"); + log.info("Index adoc content differs from the previously stored, will update it"); project.rawOverview = fileText; shouldUpdate = true; } @@ -115,10 +104,8 @@ public class SaganUpdater { if (bootDoc.exists()) { log.debug("Boot adoc file exists"); String fileText = fileToText(bootDoc); - if (StringUtils.hasText(fileText) - && !fileText.equals(project.rawBootConfig)) { - log.info( - "Boot adoc content differs from the previously stored, will update it"); + if (StringUtils.hasText(fileText) && !fileText.equals(project.rawBootConfig)) { + log.info("Boot adoc content differs from the previously stored, will update it"); project.rawBootConfig = fileText; shouldUpdate = true; } @@ -133,8 +120,7 @@ public class SaganUpdater { } File docsModule(File projectFile) { - return new File(projectFile, - this.releaserProperties.getSagan().getDocsAdocsFile()); + return new File(projectFile, this.releaserProperties.getSagan().getDocsAdocsFile()); } private String fileToText(File file) { @@ -146,29 +132,24 @@ public class SaganUpdater { } } - private Optional latestVersion(ProjectVersion currentVersion, - Project project) { + private Optional latestVersion(ProjectVersion currentVersion, Project project) { if (project == null) { return Optional.empty(); } return project.projectReleases.stream().filter(release -> release.current) - .map(release -> new ProjectVersion(currentVersion.projectName, - release.version)) + .map(release -> new ProjectVersion(currentVersion.projectName, release.version)) .max(Comparator.comparing(o -> o.version)); } - private boolean currentVersionNewerOrEqual(ProjectVersion currentVersion, - Optional projectVersion) { + private boolean currentVersionNewerOrEqual(ProjectVersion currentVersion, Optional projectVersion) { return currentVersion.compareTo(projectVersion.get()) >= 0; } - private Exception updateSaganForNonSnapshot(String branch, - ProjectVersion originalVersion, ProjectVersion version, Projects projects) { + private Exception updateSaganForNonSnapshot(String branch, ProjectVersion originalVersion, ProjectVersion version, + Projects projects) { Exception updateReleaseException = null; if (!version.isSnapshot()) { - log.info( - "Version is non snapshot [{}]. Will remove all older versions and mark this as current", - version); + log.info("Version is non snapshot [{}]. Will remove all older versions and mark this as current", version); Project project = this.saganClient.getProject(version.projectName); if (project != null) { removeAllSameMinorVersions(version, project); @@ -179,16 +160,12 @@ public class SaganUpdater { try { String bumpedSnapshot = toSnapshot(version.bumpedVersion()); ReleaseUpdate snapshotUpdate = releaseUpdate(branch, originalVersion, - new ProjectVersion(version.projectName, bumpedSnapshot), - projects); - log.info("Updating Sagan with bumped snapshot \n\n[{}]", - snapshotUpdate); - this.saganClient.updateRelease(version.projectName, - Collections.singletonList(snapshotUpdate)); + new ProjectVersion(version.projectName, bumpedSnapshot), projects); + log.info("Updating Sagan with bumped snapshot \n\n[{}]", snapshotUpdate); + this.saganClient.updateRelease(version.projectName, Collections.singletonList(snapshotUpdate)); } catch (Exception e) { - log.warn("Failed to update [" + version.projectName + "/" + snapshot - + "] from Sagan", e); + log.warn("Failed to update [" + version.projectName + "/" + snapshot + "] from Sagan", e); updateReleaseException = e; } } @@ -197,10 +174,8 @@ public class SaganUpdater { } private void removeAllSameMinorVersions(ProjectVersion version, Project project) { - project.projectReleases.stream() - .filter(release -> version.isSameMinor(release.version)) - .collect(Collectors.toList()) - .forEach(release -> removeVersionFromSagan(version, release.version)); + project.projectReleases.stream().filter(release -> version.isSameMinor(release.version)) + .collect(Collectors.toList()).forEach(release -> removeVersionFromSagan(version, release.version)); } private void removeVersionFromSagan(ProjectVersion version, String snapshot) { @@ -209,13 +184,12 @@ public class SaganUpdater { this.saganClient.deleteRelease(version.projectName, snapshot); } catch (Exception e) { - log.warn("Failed to remove [" + version.projectName + "/" + snapshot - + "] from Sagan", e); + log.warn("Failed to remove [" + version.projectName + "/" + snapshot + "] from Sagan", e); } } - private ReleaseUpdate releaseUpdate(String branch, ProjectVersion originalVersion, - ProjectVersion version, Projects projects) { + private ReleaseUpdate releaseUpdate(String branch, ProjectVersion originalVersion, ProjectVersion version, + Projects projects) { ReleaseUpdate update = new ReleaseUpdate(); update.groupId = originalVersion.groupId(); update.artifactId = version.projectName; @@ -251,21 +225,18 @@ public class SaganUpdater { } private String releaseTrainVersion(Projects projects) { - String releaseTrainProjectName = this.releaserProperties.getMetaRelease() - .getReleaseTrainProjectName(); - return projects.containsProject(releaseTrainProjectName) - ? projects.forName(releaseTrainProjectName).version : ""; + String releaseTrainProjectName = this.releaserProperties.getMetaRelease().getReleaseTrainProjectName(); + return projects.containsProject(releaseTrainProjectName) ? projects.forName(releaseTrainProjectName).version + : ""; } - private String referenceUrl(String branch, ProjectVersion version, - Projects projects) { + private String referenceUrl(String branch, ProjectVersion version, Projects projects) { String releaseTrainVersion = releaseTrainVersion(projects); // up till Greenwich we have a different URL for docs // if there's no release train, will assume that 2.2.x is the version that has the // new docs boolean hasReleaseTrainVersion = StringUtils.hasText(releaseTrainVersion); - boolean newDocs = hasReleaseTrainVersion - ? releaseTrainVersion.toLowerCase().charAt(0) > 'g' + boolean newDocs = hasReleaseTrainVersion ? releaseTrainVersion.toLowerCase().charAt(0) > 'g' : version.version.compareTo("2.2") > 0; if (newDocs) { return newReferenceUrl(branch, version); @@ -276,28 +247,24 @@ public class SaganUpdater { private String newReferenceUrl(String branch, ProjectVersion version) { if (!version.isSnapshot()) { // static/sleuth/{version}/ - return "https://cloud.spring.io/spring-cloud-static/" + version.projectName - + "/{version}/reference/html/"; + return "https://cloud.spring.io/spring-cloud-static/" + version.projectName + "/{version}/reference/html/"; } if (branch.toLowerCase().contains("main")) { // sleuth/ return "https://cloud.spring.io/" + version.projectName + "/reference/html/"; } // sleuth/1.1.x/ - return "https://cloud.spring.io/" + version.projectName + "/" + branch - + "/reference/html/"; + return "https://cloud.spring.io/" + version.projectName + "/" + branch + "/reference/html/"; } private String oldReferenceUrl(String branch, ProjectVersion version) { if (!version.isSnapshot()) { // static/sleuth/{version}/ - return "https://cloud.spring.io/spring-cloud-static/" + version.projectName - + "/{version}/"; + return "https://cloud.spring.io/spring-cloud-static/" + version.projectName + "/{version}/"; } if (branch.toLowerCase().contains("main")) { // sleuth/ - return "https://cloud.spring.io/" + version.projectName + "/" - + version.projectName + ".html"; + return "https://cloud.spring.io/" + version.projectName + "/" + version.projectName + ".html"; } // sleuth/1.1.x/ return "https://cloud.spring.io/" + version.projectName + "/" + branch + "/"; diff --git a/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java b/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java index 858115b0..1e5275da 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java +++ b/releaser-core/src/main/java/releaser/internal/tech/BuildUnstableException.java @@ -46,8 +46,7 @@ public class BuildUnstableException extends RuntimeException implements Serializ */ public static final String EXIT_CODE = "BUILD_UNSTABLE"; - private static final Logger log = LoggerFactory - .getLogger(BuildUnstableException.class); + private static final Logger log = LoggerFactory.getLogger(BuildUnstableException.class); /** * List of exceptions causing this instability. @@ -61,8 +60,7 @@ public class BuildUnstableException extends RuntimeException implements Serializ } public BuildUnstableException(String message, List throwables) { - this(throwables.stream().map(BuildUnstableException::breakReferenceChain) - .collect(Collectors.toList())); + this(throwables.stream().map(BuildUnstableException::breakReferenceChain).collect(Collectors.toList())); log.warn("\n\n" + DESCRIPTION + message + " with causes " + throwables); } @@ -72,8 +70,7 @@ public class BuildUnstableException extends RuntimeException implements Serializ private static Throwable breakReferenceChain(Throwable cause) { if (cause instanceof HttpServerErrorException) { - return new RuntimeException( - "[Breaking self reference chain] " + cause.toString()); + return new RuntimeException("[Breaking self reference chain] " + cause.toString()); } return cause; } diff --git a/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java b/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java index 889f0f04..c9b5171d 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java +++ b/releaser-core/src/main/java/releaser/internal/tech/ExecutionResult.java @@ -65,23 +65,20 @@ public class ExecutionResult implements Serializable { } public static ExecutionResult failure(List throwables) { - return new ExecutionResult(throwables.stream() - .map(ExecutionResult::breakReferenceChain).collect(Collectors.toList())); + return new ExecutionResult( + throwables.stream().map(ExecutionResult::breakReferenceChain).collect(Collectors.toList())); } private static Exception breakReferenceChain(Exception cause) { - if (cause instanceof HttpServerErrorException - || cause instanceof HttpClientErrorException) { + if (cause instanceof HttpServerErrorException || cause instanceof HttpClientErrorException) { System.out.println("Breaking the reference chain. . . i think"); - return new RuntimeException( - "[Breaking self reference chain] " + cause.toString()); + return new RuntimeException("[Breaking self reference chain] " + cause.toString()); } return cause; } public static ExecutionResult unstable(Exception ex) { - return new ExecutionResult(ex instanceof BuildUnstableException ? ex - : new BuildUnstableException(ex)); + return new ExecutionResult(ex instanceof BuildUnstableException ? ex : new BuildUnstableException(ex)); } public static ExecutionResult skipped() { @@ -110,18 +107,17 @@ public class ExecutionResult implements Serializable { } public boolean isUnstable() { - return !this.exceptions.isEmpty() && this.exceptions.stream() - .allMatch(t -> t instanceof BuildUnstableException); + return !this.exceptions.isEmpty() + && this.exceptions.stream().allMatch(t -> t instanceof BuildUnstableException); } public String toStringResult() { - return isUnstable() ? "UNSTABLE" - : isFailure() ? "FAILURE" : isSkipped() ? "SKIPPED" : "SUCCESS"; + return isUnstable() ? "UNSTABLE" : isFailure() ? "FAILURE" : isSkipped() ? "SKIPPED" : "SUCCESS"; } public boolean isFailure() { - return !this.exceptions.isEmpty() && this.exceptions.stream() - .anyMatch(t -> !(t instanceof BuildUnstableException)); + return !this.exceptions.isEmpty() + && this.exceptions.stream().anyMatch(t -> !(t instanceof BuildUnstableException)); } public boolean isSuccess() { @@ -148,8 +144,7 @@ public class ExecutionResult implements Serializable { this.skipped = skipped; } - private static final class MergedThrowable extends RuntimeException - implements Serializable { + private static final class MergedThrowable extends RuntimeException implements Serializable { private MergedThrowable(List throwables) { super("Failed due to the following exceptions " + throwables); @@ -157,8 +152,7 @@ public class ExecutionResult implements Serializable { } - private static final class MergedUnstableThrowable extends BuildUnstableException - implements Serializable { + private static final class MergedUnstableThrowable extends BuildUnstableException implements Serializable { private MergedUnstableThrowable(List throwables) { super("Unstable due to the following exceptions " + throwables); diff --git a/releaser-core/src/main/java/releaser/internal/tech/HandlebarsHelper.java b/releaser-core/src/main/java/releaser/internal/tech/HandlebarsHelper.java index 2724e7c8..830f83f9 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/HandlebarsHelper.java +++ b/releaser-core/src/main/java/releaser/internal/tech/HandlebarsHelper.java @@ -34,8 +34,7 @@ public final class HandlebarsHelper { public static Template template(String templateSubFolder, String templateName) { try { - Handlebars handlebars = new Handlebars( - new ClassPathTemplateLoader("/templates/" + templateSubFolder)); + Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader("/templates/" + templateSubFolder)); handlebars.registerHelper("replace", StringHelpers.replace); handlebars.registerHelper("capitalizeFirst", StringHelpers.capitalizeFirst); return handlebars.compile(templateName); diff --git a/releaser-core/src/main/java/releaser/internal/tech/PomReader.java b/releaser-core/src/main/java/releaser/internal/tech/PomReader.java index 51aa3a3f..5125a88a 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/PomReader.java +++ b/releaser-core/src/main/java/releaser/internal/tech/PomReader.java @@ -60,11 +60,9 @@ public final class PomReader { } catch (XmlPullParserException | IOException e) { if (file.isFile() && fileText.length() == 0) { - throw new IllegalStateException( - "File [" + pom.getAbsolutePath() + "] is empty", e); + throw new IllegalStateException("File [" + pom.getAbsolutePath() + "] is empty", e); } - throw new IllegalStateException( - "Failed to read file: " + pom.getAbsolutePath(), e); + throw new IllegalStateException("Failed to read file: " + pom.getAbsolutePath(), e); } } diff --git a/releaser-core/src/main/java/releaser/internal/tech/TemporaryFileStorage.java b/releaser-core/src/main/java/releaser/internal/tech/TemporaryFileStorage.java index 77684ffe..2dea9380 100644 --- a/releaser-core/src/main/java/releaser/internal/tech/TemporaryFileStorage.java +++ b/releaser-core/src/main/java/releaser/internal/tech/TemporaryFileStorage.java @@ -65,8 +65,7 @@ public final class TemporaryFileStorage { if (file.isDirectory()) { Files.walkFileTree(file.toPath(), new SimpleFileVisitor() { @Override - public FileVisitResult visitFile(Path file, - BasicFileAttributes attrs) throws IOException { + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (log.isTraceEnabled()) { log.trace("Removing file [" + file + "]"); } @@ -75,8 +74,7 @@ public final class TemporaryFileStorage { } @Override - public FileVisitResult postVisitDirectory(Path dir, - IOException exc) throws IOException { + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (log.isTraceEnabled()) { log.trace("Removing dir [" + dir + "]"); } @@ -110,9 +108,8 @@ public final class TemporaryFileStorage { return tempDir; } } - throw new IllegalStateException("Failed to create directory within " - + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName - + (TEMP_DIR_ATTEMPTS - 1) + ")"); + throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ")"); } } diff --git a/releaser-core/src/main/java/releaser/internal/template/BlogTemplateGenerator.java b/releaser-core/src/main/java/releaser/internal/template/BlogTemplateGenerator.java index 0aab0245..9b90d1e4 100644 --- a/releaser-core/src/main/java/releaser/internal/template/BlogTemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/BlogTemplateGenerator.java @@ -34,8 +34,7 @@ import releaser.internal.project.Projects; */ class BlogTemplateGenerator { - private static final Logger log = LoggerFactory - .getLogger(BlogTemplateGenerator.class); + private static final Logger log = LoggerFactory.getLogger(BlogTemplateGenerator.class); private static final Pattern RC_PATTERN = Pattern.compile("(.*)(RC)([0-9]+)"); @@ -53,8 +52,8 @@ class BlogTemplateGenerator { private final NotesGenerator notesGenerator; - BlogTemplateGenerator(Template template, String releaseVersion, File blogOutput, - Projects projects, ProjectGitHubHandler handler) { + BlogTemplateGenerator(Template template, String releaseVersion, File blogOutput, Projects projects, + ProjectGitHubHandler handler) { this.template = template; this.releaseVersion = releaseVersion; this.blogOutput = blogOutput; @@ -75,24 +74,21 @@ class BlogTemplateGenerator { boolean release = !SR_PATTERN.matcher(this.releaseVersion).matches() && !RC_PATTERN.matcher(this.releaseVersion).matches() && !MILESTONE_PATTERN.matcher(this.releaseVersion).matches(); - boolean nonRelease = !(release - || SR_PATTERN.matcher(this.releaseVersion).matches()); + boolean nonRelease = !(release || SR_PATTERN.matcher(this.releaseVersion).matches()); String availability = availability(release); String releaseName = parsedReleaseName(this.releaseVersion, release); String releaseLink = link(nonRelease); - Map map = ImmutableMap.builder() - .put("availability", availability).put("releaseName", releaseName) - .put("releaseLink", releaseLink) + Map map = ImmutableMap.builder().put("availability", availability) + .put("releaseName", releaseName).put("releaseLink", releaseLink) .put("releaseVersion", this.releaseVersion) - .put("projects", this.notesGenerator.fromProjects(this.projects)) - .put("nonRelease", nonRelease).build(); + .put("projects", this.notesGenerator.fromProjects(this.projects)).put("nonRelease", nonRelease) + .build(); String blog = this.template.apply(map); Files.write(this.blogOutput.toPath(), blog.getBytes()); return this.blogOutput; } catch (Exception e) { - throw new IllegalStateException( - "Exception occurred while trying to create a blog entry", e); + throw new IllegalStateException("Exception occurred while trying to create a blog entry", e); } } @@ -127,8 +123,7 @@ class BlogTemplateGenerator { } if (log.isWarnEnabled()) { log.warn("Unrecognized release [{}] . " - + "Hopefully, you know what you're doing. Will treat it as milestone", - this.releaseVersion); + + "Hopefully, you know what you're doing. Will treat it as milestone", this.releaseVersion); } return milestone(milestone); } @@ -147,8 +142,7 @@ class BlogTemplateGenerator { return "[Spring Milestone](https://repo.spring.io/milestone/) repository"; } return "[Maven Central](https://repo1.maven.org/maven2/" - + "org/springframework/cloud/spring-cloud-dependencies/" - + this.releaseVersion + "/)"; + + "org/springframework/cloud/spring-cloud-dependencies/" + this.releaseVersion + "/)"; } } diff --git a/releaser-core/src/main/java/releaser/internal/template/EmailTemplateGenerator.java b/releaser-core/src/main/java/releaser/internal/template/EmailTemplateGenerator.java index 68992751..dea50335 100644 --- a/releaser-core/src/main/java/releaser/internal/template/EmailTemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/EmailTemplateGenerator.java @@ -28,8 +28,7 @@ import org.slf4j.LoggerFactory; */ class EmailTemplateGenerator { - private static final Logger log = LoggerFactory - .getLogger(EmailTemplateGenerator.class); + private static final Logger log = LoggerFactory.getLogger(EmailTemplateGenerator.class); private final Template template; @@ -50,8 +49,7 @@ class EmailTemplateGenerator { return this.emailOutput; } catch (Exception e) { - throw new IllegalStateException( - "Exception occurred while trying to generate an email template", e); + throw new IllegalStateException("Exception occurred while trying to generate an email template", e); } } diff --git a/releaser-core/src/main/java/releaser/internal/template/NotesGenerator.java b/releaser-core/src/main/java/releaser/internal/template/NotesGenerator.java index c5de83a3..010d4db7 100644 --- a/releaser-core/src/main/java/releaser/internal/template/NotesGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/NotesGenerator.java @@ -37,13 +37,12 @@ class NotesGenerator { } Set fromProjects(Projects projects) { - return projects.stream().filter(projectVersion -> !projectVersion.projectName - .toLowerCase().contains("boot")).map(projectVersion -> { + return projects.stream().filter(projectVersion -> !projectVersion.projectName.toLowerCase().contains("boot")) + .map(projectVersion -> { String name = projectVersion.projectName; String version = projectVersion.version; String closedMilestoneUrl = this.handler.milestoneUrl(projectVersion); - String convertedName = Arrays.stream(name.split("-")) - .map(StringUtils::capitalize) + String convertedName = Arrays.stream(name.split("-")).map(StringUtils::capitalize) .collect(Collectors.joining(" ")); return new Notes(convertedName, version, closedMilestoneUrl); }).collect(Collectors.toSet()); @@ -90,8 +89,7 @@ class Notes { if (this.name != null ? !this.name.equals(notes.name) : notes.name != null) { return false; } - return this.version != null ? this.version.equals(notes.version) - : notes.version == null; + return this.version != null ? this.version.equals(notes.version) : notes.version == null; } @Override diff --git a/releaser-core/src/main/java/releaser/internal/template/ReleaseNotesTemplateGenerator.java b/releaser-core/src/main/java/releaser/internal/template/ReleaseNotesTemplateGenerator.java index f89acc01..4ef245cd 100644 --- a/releaser-core/src/main/java/releaser/internal/template/ReleaseNotesTemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/ReleaseNotesTemplateGenerator.java @@ -43,8 +43,8 @@ class ReleaseNotesTemplateGenerator { private final NotesGenerator notesGenerator; - ReleaseNotesTemplateGenerator(Template template, String releaseVersion, - File blogOutput, Projects projects, ProjectGitHubHandler handler) { + ReleaseNotesTemplateGenerator(Template template, String releaseVersion, File blogOutput, Projects projects, + ProjectGitHubHandler handler) { this.template = template; this.releaseVersion = releaseVersion; this.blogOutput = blogOutput; @@ -57,15 +57,13 @@ class ReleaseNotesTemplateGenerator { Map map = ImmutableMap.builder() .put("date", LocalDate.now().format(DateTimeFormatter.ISO_DATE)) .put("releaseVersion", this.releaseVersion) - .put("projects", this.notesGenerator.fromProjects(this.projects)) - .build(); + .put("projects", this.notesGenerator.fromProjects(this.projects)).build(); String blog = this.template.apply(map); Files.write(this.blogOutput.toPath(), blog.getBytes()); return this.blogOutput; } catch (IOException e) { - throw new IllegalStateException( - "Exception occurred while trying to generate release notes", e); + throw new IllegalStateException("Exception occurred while trying to generate release notes", e); } } 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 13b0c38e..18df1e66 100644 --- a/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/TemplateGenerator.java @@ -59,8 +59,7 @@ public class TemplateGenerator { this.releaseNotesOutput = new File("target/notes.md"); } - TemplateGenerator(ReleaserProperties props, File output, - ProjectGitHubHandler handler) { + TemplateGenerator(ReleaserProperties props, File output, ProjectGitHubHandler handler) { this.props = props; this.emailOutput = output; this.blogOutput = output; @@ -97,8 +96,7 @@ public class TemplateGenerator { File blogOutput = file(this.blogOutput); String releaseVersion = parsedVersion(projects); Template template = template(BLOG_TEMPLATE); - return new BlogTemplateGenerator(template, releaseVersion, blogOutput, projects, - this.handler).blog(); + return new BlogTemplateGenerator(template, releaseVersion, blogOutput, projects, this.handler).blog(); } public File tweet(Projects projects) { @@ -112,8 +110,8 @@ public class TemplateGenerator { File output = file(this.releaseNotesOutput); String releaseVersion = parsedVersion(projects); Template template = template(RELEASE_NOTES_TEMPLATE); - return new ReleaseNotesTemplateGenerator(template, releaseVersion, output, - projects, this.handler).releaseNotes(); + return new ReleaseNotesTemplateGenerator(template, releaseVersion, output, projects, this.handler) + .releaseNotes(); } private String parsedVersion(Projects projects) { @@ -128,8 +126,7 @@ public class TemplateGenerator { } private Template template(String template) { - return HandlebarsHelper.template(this.props.getTemplate().getTemplateFolder(), - template); + return HandlebarsHelper.template(this.props.getTemplate().getTemplateFolder(), template); } } diff --git a/releaser-core/src/main/java/releaser/internal/template/TwitterTemplateGenerator.java b/releaser-core/src/main/java/releaser/internal/template/TwitterTemplateGenerator.java index 47cc6765..44f26090 100644 --- a/releaser-core/src/main/java/releaser/internal/template/TwitterTemplateGenerator.java +++ b/releaser-core/src/main/java/releaser/internal/template/TwitterTemplateGenerator.java @@ -28,8 +28,7 @@ import org.slf4j.LoggerFactory; */ class TwitterTemplateGenerator { - private static final Logger log = LoggerFactory - .getLogger(TwitterTemplateGenerator.class); + private static final Logger log = LoggerFactory.getLogger(TwitterTemplateGenerator.class); private final Template template; @@ -50,8 +49,7 @@ class TwitterTemplateGenerator { return this.output; } catch (Exception e) { - throw new IllegalStateException( - "Exception occurred while trying to generate a twitter template", e); + throw new IllegalStateException("Exception occurred while trying to generate a twitter template", e); } } 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 af923d6a..76f4a081 100644 --- a/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java +++ b/releaser-core/src/main/java/releaser/internal/versions/VersionsFetcher.java @@ -60,8 +60,7 @@ public class VersionsFetcher implements Closeable { private final ReleaserProperties properties; - public VersionsFetcher(ReleaserProperties properties, - ProjectPomUpdater projectPomUpdater) { + public VersionsFetcher(ReleaserProperties properties, ProjectPomUpdater projectPomUpdater) { this.properties = properties; this.projectPomUpdater = projectPomUpdater; this.toPropertiesConverter = new ToPropertiesConverter(new RawGithubRetriever()); @@ -75,8 +74,7 @@ public class VersionsFetcher implements Closeable { public boolean isLatestGa(ProjectVersion version) { if (!version.isReleaseOrServiceRelease()) { if (log.isDebugEnabled()) { - log.debug("Version [" + version.toString() - + "] is non GA, will not fetch any versions."); + log.debug("Version [" + version.toString() + "] is non GA, will not fetch any versions."); } return false; } @@ -86,55 +84,44 @@ public class VersionsFetcher implements Closeable { return false; } String latestVersionsUrl = this.properties.getVersions().getAllVersionsFileUrl(); - InitializrProperties initializrProperties = this.toPropertiesConverter - .toProperties(latestVersionsUrl); + InitializrProperties initializrProperties = this.toPropertiesConverter.toProperties(latestVersionsUrl); if (initializrProperties == null) { return false; } ProjectVersion bomVersion = latestBomVersion(); if (bomVersion == null) { - log.info("No BOM mapping with name [{}] found", - this.properties.getVersions().getBomName()); + log.info("No BOM mapping with name [{}] found", this.properties.getVersions().getBomName()); return false; } Projects projectVersions = null; try { - projectVersions = this.projectPomUpdater.retrieveVersionsFromReleaseTrainBom( - "v" + bomVersion.toString(), false); + projectVersions = this.projectPomUpdater.retrieveVersionsFromReleaseTrainBom("v" + bomVersion.toString(), + false); } catch (Exception ex) { - log.error( - "Failed to check the project versions. Will return that the project is not GA", - ex); + log.error("Failed to check the project versions. Will return that the project is not GA", ex); return false; } boolean containsProject = projectVersions.containsProject(version.projectName); if (containsProject) { return bomVersion.compareTo(projectVersions.forName(version.projectName)) > 0; } - log.info("The project [" + version.projectName - + "] is not present in the BOM with projects [" + projectVersions.stream() - .map(v -> v.projectName).collect(Collectors.joining(", ")) - + "]"); + log.info("The project [" + version.projectName + "] is not present in the BOM with projects [" + + projectVersions.stream().map(v -> v.projectName).collect(Collectors.joining(", ")) + "]"); return false; } private ProjectVersion latestBomVersion() { String latestVersionsUrl = this.properties.getVersions().getAllVersionsFileUrl(); - InitializrProperties initializrProperties = this.toPropertiesConverter - .toProperties(latestVersionsUrl); + InitializrProperties initializrProperties = this.toPropertiesConverter.toProperties(latestVersionsUrl); if (initializrProperties == null) { return null; } ProjectVersion springCloudVersion = initializrProperties.getEnv().getBoms() - .getOrDefault( - this.properties.getVersions().getBomName(), new BillOfMaterials()) - .getMappings().stream() - .map(mapping -> new ProjectVersion( - this.properties.getVersions().getBomName(), mapping.getVersion())) - .filter(ProjectVersion::isReleaseOrServiceRelease) - .max(ProjectVersion::compareTo).orElse(new ProjectVersion( - this.properties.getVersions().getBomName(), "")); + .getOrDefault(this.properties.getVersions().getBomName(), new BillOfMaterials()).getMappings().stream() + .map(mapping -> new ProjectVersion(this.properties.getVersions().getBomName(), mapping.getVersion())) + .filter(ProjectVersion::isReleaseOrServiceRelease).max(ProjectVersion::compareTo) + .orElse(new ProjectVersion(this.properties.getVersions().getBomName(), "")); log.info("Latest BOM version is [{}]", springCloudVersion.version); return springCloudVersion; } @@ -154,14 +141,13 @@ class RawGithubRetriever { try { URL url = new URL(stringUrl); URLConnection con = url.openConnection(); - try (BufferedReader reader = new BufferedReader(new InputStreamReader( - con.getInputStream(), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) { return reader.lines().collect(Collectors.joining("\n")); } } catch (IOException e) { - LOG.warn("Exception occurred while trying to fetch the URL [" + stringUrl - + "] contents"); + LOG.warn("Exception occurred while trying to fetch the URL [" + stringUrl + "] contents"); return null; } } @@ -185,16 +171,12 @@ class ToPropertiesConverter implements Closeable { return null; } YamlPropertiesFactoryBean yamlProcessor = new YamlPropertiesFactoryBean(); - yamlProcessor.setResources(new InputStreamResource(new ByteArrayInputStream( - retrievedFile.getBytes(StandardCharsets.UTF_8)))); + yamlProcessor.setResources( + new InputStreamResource(new ByteArrayInputStream(retrievedFile.getBytes(StandardCharsets.UTF_8)))); Properties properties = yamlProcessor.getObject(); - return new Binder( - new MapConfigurationPropertySource(properties.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(), - e -> e.getValue().toString())))) - .bind("initializr", - InitializrProperties.class) - .get(); + return new Binder(new MapConfigurationPropertySource(properties.entrySet().stream() + .collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())))) + .bind("initializr", InitializrProperties.class).get(); }); } diff --git a/releaser-core/src/test/java/releaser/SpringCloudReleaserProperties.java b/releaser-core/src/test/java/releaser/SpringCloudReleaserProperties.java index 23c72ec1..32548dde 100644 --- a/releaser-core/src/test/java/releaser/SpringCloudReleaserProperties.java +++ b/releaser-core/src/test/java/releaser/SpringCloudReleaserProperties.java @@ -32,17 +32,13 @@ public class SpringCloudReleaserProperties { public static ReleaserProperties get() { try { - File releaserConfig = new File(SpringCloudReleaserProperties.class - .getResource("/application.yml").toURI()); + File releaserConfig = new File(SpringCloudReleaserProperties.class.getResource("/application.yml").toURI()); YamlPropertiesFactoryBean yamlProcessor = new YamlPropertiesFactoryBean(); yamlProcessor.setResources(new FileSystemResource(releaserConfig)); Properties properties = yamlProcessor.getObject(); - ReleaserProperties releaserProperties = new Binder( - new MapConfigurationPropertySource(properties.entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey().toString(), - e -> e.getValue().toString())))) - .bind("releaser", ReleaserProperties.class) - .get(); + ReleaserProperties releaserProperties = new Binder(new MapConfigurationPropertySource(properties.entrySet() + .stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString())))) + .bind("releaser", ReleaserProperties.class).get(); return releaserProperties; } catch (URISyntaxException e) { diff --git a/releaser-core/src/test/java/releaser/internal/PomUpdateAcceptanceTests.java b/releaser-core/src/test/java/releaser/internal/PomUpdateAcceptanceTests.java index 7dc93b36..4850795d 100644 --- a/releaser-core/src/test/java/releaser/internal/PomUpdateAcceptanceTests.java +++ b/releaser-core/src/test/java/releaser/internal/PomUpdateAcceptanceTests.java @@ -24,10 +24,9 @@ import java.util.Collections; import org.apache.maven.model.Model; import org.assertj.core.api.BDDAssertions; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import releaser.SpringCloudReleaserProperties; import releaser.internal.buildsystem.MavenBomParserAccessor; import releaser.internal.buildsystem.ProjectPomUpdater; @@ -45,14 +44,14 @@ import static org.assertj.core.api.BDDAssertions.then; */ public class PomUpdateAcceptanceTests { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + public File tmp; File temporaryFolder; - @Before + @BeforeEach public void setup() throws Exception { - this.temporaryFolder = this.tmp.newFolder(); + this.temporaryFolder = new File(tmp, "test"); TestUtils.prepareLocalRepo(); FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder); } @@ -62,25 +61,20 @@ public class PomUpdateAcceptanceTests { ReleaserProperties releaserProperties = releaserProperties(); releaserProperties.getFixedVersions().put("checkstyle", "100.0.0.RELEASE"); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); File project = new File(this.temporaryFolder, "/spring-cloud-sleuth"); - projectPomUpdater.updateProjectFromReleaseTrain(project, projects, - projects.forFile(project), true); + projectPomUpdater.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true); then(this.temporaryFolder).exists(); Model rootPom = PomReader.readPom(tmpFile("/spring-cloud-sleuth/pom.xml")); - Model depsPom = PomReader.readPom( - tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-dependencies/pom.xml")); - Model corePom = PomReader.readPom( - tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-core/pom.xml")); + Model depsPom = PomReader.readPom(tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-dependencies/pom.xml")); + Model corePom = PomReader.readPom(tmpFile("/spring-cloud-sleuth/spring-cloud-sleuth-core/pom.xml")); Model zipkinStreamPom = PomReader.readPom(tmpFile( "/spring-cloud-sleuth/spring-cloud-sleuth-samples/spring-cloud-sleuth-sample-zipkin-stream/pom.xml")); then(rootPom.getVersion()).isEqualTo("1.2.0.BUILD-SNAPSHOT"); - then(rootPom.getProperties()) - .containsEntry("spring-cloud-commons.version", "1.2.0.BUILD-SNAPSHOT") + then(rootPom.getProperties()).containsEntry("spring-cloud-commons.version", "1.2.0.BUILD-SNAPSHOT") .containsEntry("spring-cloud-stream.version", "Chelsea.BUILD-SNAPSHOT") .containsEntry("spring-cloud-netflix.version", "1.3.0.BUILD-SNAPSHOT") .containsEntry("checkstyle.version", "100.0.0.RELEASE"); @@ -95,23 +89,20 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); projects.add(new ProjectVersion("spring-cloud-sleuth-samples", "0.0.5.RELEASE")); File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-unmatched-property/spring-cloud-sleuth-samples"); addBuildSnapshotToChildPom(project); - projectPomUpdater.updateProjectFromReleaseTrain(project, projects, - projects.forFile(project), true); + projectPomUpdater.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true); } private void addBuildSnapshotToChildPom(File project) throws IOException { File childPom = new File(project, "pom.xml"); String text = new String(Files.readAllBytes(childPom.toPath())); - Files.write(childPom.toPath(), - text.replaceAll("1.19.2", "1.19.2.BUILD-SNAPSHOT").getBytes()); + Files.write(childPom.toPath(), text.replaceAll("1.19.2", "1.19.2.BUILD-SNAPSHOT").getBytes()); } @Test @@ -119,15 +110,13 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); - File project = new File(this.temporaryFolder, - "/spring-cloud-sleuth-with-unmatched-property"); + File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-unmatched-property"); BDDAssertions - .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain( - project, projects, projects.forFile(project), true)) + .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(project, projects, + projects.forFile(project), true)) .hasMessageContaining("0.3.1.BUILD-SNAPSHOT"); } @@ -136,18 +125,15 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); - projects.removeIf(projectVersion -> projectVersion.projectName - .contains("spring-cloud-build")); + projects.removeIf(projectVersion -> projectVersion.projectName.contains("spring-cloud-build")); projects.add(new ProjectVersion("spring-cloud-build", "1.4.2.RELEASE")); - File project = new File(this.temporaryFolder, - "/spring-cloud-sleuth-with-milestone-dep"); + File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-milestone-dep"); BDDAssertions - .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain( - project, projects, projects.forFile(project), true)) + .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(project, projects, + projects.forFile(project), true)) .hasMessageContaining("1.19.2-M2"); } @@ -156,15 +142,13 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projects(projectPomUpdater); - File project = new File(this.temporaryFolder, - "/spring-cloud-sleuth-with-milestone-dep"); + File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-milestone-dep"); BDDAssertions - .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain( - project, projects, projects.forFile(project), true)) + .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(project, projects, + projects.forFile(project), true)) .hasMessageContaining("1.19.2-M2"); } @@ -173,35 +157,26 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projects(projectPomUpdater); - File project = new File(this.temporaryFolder, - "/spring-cloud-sleuth-with-ignored-line"); + File project = new File(this.temporaryFolder, "/spring-cloud-sleuth-with-ignored-line"); - projectPomUpdater.updateProjectFromReleaseTrain(project, projects, - projects.forFile(project), true); + projectPomUpdater.updateProjectFromReleaseTrain(project, projects, projects.forFile(project), true); } private Projects projects(ProjectPomUpdater projectPomUpdater) { Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); - projects.removeIf( - projectVersion -> projectVersion.projectName.equals("spring-cloud")); + projects.removeIf(projectVersion -> projectVersion.projectName.equals("spring-cloud")); projects.add(new ProjectVersion("spring-cloud", "Camden.RC1")); - projects.removeIf(projectVersion -> projectVersion.projectName - .equals("spring-cloud-dependencies")); + projects.removeIf(projectVersion -> projectVersion.projectName.equals("spring-cloud-dependencies")); projects.add(new ProjectVersion("spring-cloud-dependencies", "Camden.RC1")); - projects.removeIf(projectVersion -> projectVersion.projectName - .equals("spring-cloud-starter")); + projects.removeIf(projectVersion -> projectVersion.projectName.equals("spring-cloud-starter")); projects.add(new ProjectVersion("spring-cloud-starter", "Camden.RC1")); - projects.removeIf(projectVersion -> projectVersion.projectName - .equals("spring-cloud-starter-build")); + projects.removeIf(projectVersion -> projectVersion.projectName.equals("spring-cloud-starter-build")); projects.add(new ProjectVersion("spring-cloud-starter-build", "Camden.RC1")); - projects.removeIf(projectVersion -> projectVersion.projectName - .equals("spring-cloud-release")); + projects.removeIf(projectVersion -> projectVersion.projectName.equals("spring-cloud-release")); projects.add(new ProjectVersion("spring-cloud-release", "Camden.RC1")); - projects.removeIf(projectVersion -> projectVersion.projectName - .contains("spring-cloud-build")); + projects.removeIf(projectVersion -> projectVersion.projectName.contains("spring-cloud-build")); projects.add(new ProjectVersion("spring-cloud-build", "1.4.2.RELEASE")); return projects; } @@ -211,26 +186,21 @@ public class PomUpdateAcceptanceTests { throws Exception { ReleaserProperties releaserProperties = branchReleaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); - projects.removeIf(projectVersion -> projectVersion.projectName - .contains("spring-cloud-build")); + projects.removeIf(projectVersion -> projectVersion.projectName.contains("spring-cloud-build")); projects.add(new ProjectVersion("spring-cloud-build", "1.4.2.BUILD-SNAPSHOT")); File project = new File(this.temporaryFolder, "/spring-cloud-sleuth"); - BDDAssertions - .thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain( - project, projects, projects.forFile(project), true)) - .hasMessageContaining("BUILD-SNAPSHOT"); + BDDAssertions.thenThrownBy(() -> projectPomUpdater.updateProjectFromReleaseTrain(project, projects, + projects.forFile(project), true)).hasMessageContaining("BUILD-SNAPSHOT"); } @Test public void should_not_update_a_project_that_is_not_on_the_list() throws Exception { ReleaserProperties releaserProperties = releaserProperties(); ProjectPomUpdater projectPomUpdater = new ProjectPomUpdater(releaserProperties, - Collections - .singletonList(MavenBomParserAccessor.maven(releaserProperties))); + Collections.singletonList(MavenBomParserAccessor.maven(releaserProperties))); File beforeProcessing = pom("/projects/project/"); Projects projects = projectPomUpdater.retrieveVersionsFromReleaseTrainBom(); File project = tmpFile("/project/"); @@ -245,8 +215,7 @@ public class PomUpdateAcceptanceTests { private ReleaserProperties releaserProperties() throws URISyntaxException { ReleaserProperties releaserProperties = SpringCloudReleaserProperties.get(); - releaserProperties.getGit().setReleaseTrainBomUrl( - file("/projects/spring-cloud-release/").toURI().toString()); + releaserProperties.getGit().setReleaseTrainBomUrl(file("/projects/spring-cloud-release/").toURI().toString()); return releaserProperties; } @@ -265,10 +234,7 @@ public class PomUpdateAcceptanceTests { } private File pom(String relativePath) throws URISyntaxException { - return new File( - new File( - PomUpdateAcceptanceTests.class.getResource(relativePath).toURI()), - "pom.xml"); + return new File(new File(PomUpdateAcceptanceTests.class.getResource(relativePath).toURI()), "pom.xml"); } private String asString(File file) throws IOException { diff --git a/releaser-core/src/test/java/releaser/internal/ReleaserPropertiesTests.java b/releaser-core/src/test/java/releaser/internal/ReleaserPropertiesTests.java index d4be96f0..d5efad0f 100644 --- a/releaser-core/src/test/java/releaser/internal/ReleaserPropertiesTests.java +++ b/releaser-core/src/test/java/releaser/internal/ReleaserPropertiesTests.java @@ -21,7 +21,7 @@ import java.util.HashMap; import java.util.Map; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.BDDAssertions.then; @@ -72,13 +72,10 @@ public class ReleaserPropertiesTests { BDDAssertions.then(properties.getWorkingDir()).isEqualTo("foo"); BDDAssertions.then(properties.getFixedVersions()).isEqualTo(map()); BDDAssertions.then(properties.getMaven().getBuildCommand()).isEqualTo("foo2"); - BDDAssertions.then(properties.getGradle().getIgnoredGradleRegex()) - .isEqualTo(Arrays.asList("foo3", "foo4")); - BDDAssertions.then(properties.getMetaRelease().getProjectsToSkip()) - .isEqualTo(Arrays.asList("foo5", "foo6")); + BDDAssertions.then(properties.getGradle().getIgnoredGradleRegex()).isEqualTo(Arrays.asList("foo3", "foo4")); + BDDAssertions.then(properties.getMetaRelease().getProjectsToSkip()).isEqualTo(Arrays.asList("foo5", "foo6")); BDDAssertions.then(properties.getGit().getPassword()).isEqualTo("foo7"); - BDDAssertions.then(properties.getPom().getIgnoredPomRegex()) - .isEqualTo(Arrays.asList("foo8", "foo9")); + BDDAssertions.then(properties.getPom().getIgnoredPomRegex()).isEqualTo(Arrays.asList("foo8", "foo9")); BDDAssertions.then(properties.getSagan().getBaseUrl()).isEqualTo("foo10"); } diff --git a/releaser-core/src/test/java/releaser/internal/ReleaserTests.java b/releaser-core/src/test/java/releaser/internal/ReleaserTests.java index 79a0220d..92b77e91 100644 --- a/releaser-core/src/test/java/releaser/internal/ReleaserTests.java +++ b/releaser-core/src/test/java/releaser/internal/ReleaserTests.java @@ -22,13 +22,12 @@ import java.net.URISyntaxException; import java.util.function.Supplier; import org.assertj.core.api.BDDAssertions; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.BDDMockito; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import releaser.SpringCloudReleaserProperties; import releaser.internal.buildsystem.GradleUpdater; import releaser.internal.buildsystem.ProjectPomUpdater; @@ -42,7 +41,8 @@ import releaser.internal.project.Projects; import releaser.internal.sagan.SaganUpdater; import releaser.internal.template.TemplateGenerator; -import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.then; @@ -51,12 +51,9 @@ import static org.mockito.Mockito.never; /** * @author Marcin Grzejszczak */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith({ MockitoExtension.class, OutputCaptureExtension.class }) public class ReleaserTests { - @Rule - public OutputCapture outputCapture = new OutputCapture(); - @Mock ProjectPomUpdater projectPomUpdater; @@ -86,16 +83,15 @@ public class ReleaserTests { File pom; - @Before + @BeforeEach public void setup() throws URISyntaxException { URI pomUri = ReleaserTests.class.getResource("/projects/project/pom.xml").toURI(); this.pom = new File(pomUri); } Releaser releaser(Supplier originalVersionSupplier) { - return new Releaser(SpringCloudReleaserProperties.get(), this.projectPomUpdater, - this.projectCommandExecutor, this.projectGitHandler, - this.projectGitHubHandler, this.templateGenerator, this.gradleUpdater, + return new Releaser(SpringCloudReleaserProperties.get(), this.projectPomUpdater, this.projectCommandExecutor, + this.projectGitHandler, this.projectGitHubHandler, this.templateGenerator, this.gradleUpdater, this.saganUpdater, this.documentationUpdater, this.postReleaseActions) { @Override ProjectVersion originalVersion(File project) { @@ -105,71 +101,61 @@ public class ReleaserTests { } Releaser releaser() { - return new Releaser(new ReleaserProperties(), this.projectPomUpdater, - this.projectCommandExecutor, this.projectGitHandler, - this.projectGitHubHandler, this.templateGenerator, this.gradleUpdater, + return new Releaser(new ReleaserProperties(), this.projectPomUpdater, this.projectCommandExecutor, + this.projectGitHandler, this.projectGitHubHandler, this.templateGenerator, this.gradleUpdater, this.saganUpdater, this.documentationUpdater, this.postReleaseActions); } @Test - public void should_not_bump_versions_for_original_release_project() { - releaser(() -> new ProjectVersion("original", "1.0.0.RELEASE")) - .rollbackReleaseVersion(this.pom, - new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")), - new ProjectVersion("changed", "1.0.0.RELEASE")); + public void should_not_bump_versions_for_original_release_project(CapturedOutput outputCapture) { + releaser(() -> new ProjectVersion("original", "1.0.0.RELEASE")).rollbackReleaseVersion(this.pom, + new Projects(new ProjectVersion("changed", "1.0.0.RELEASE")), + new ProjectVersion("changed", "1.0.0.RELEASE")); - BDDAssertions.then(this.outputCapture.toString()).contains( - "Successfully reverted the commit and came back to snapshot versions"); - then(this.projectGitHandler).should(never()) - .commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class)); + BDDAssertions.then(outputCapture.toString()) + .contains("Successfully reverted the commit and came back to snapshot versions"); + then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), + any(ProjectVersion.class)); } @Test - public void should_not_bump_versions_for_original_snapshot_project_and_current_snapshot() { - releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) - .rollbackReleaseVersion(this.pom, - new Projects( - new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")), - new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")); + public void should_not_bump_versions_for_original_snapshot_project_and_current_snapshot( + CapturedOutput outputCapture) { + releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")).rollbackReleaseVersion(this.pom, + new Projects(new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")), + new ProjectVersion("changed", "1.0.0.BUILD-SNAPSHOT")); - BDDAssertions.then(this.outputCapture.toString()) - .contains("Won't rollback a snapshot version"); - then(this.projectGitHandler).should(never()) - .commitAfterBumpingVersions(any(File.class), any(ProjectVersion.class)); + BDDAssertions.then(outputCapture.toString()).contains("Won't rollback a snapshot version"); + then(this.projectGitHandler).should(never()).commitAfterBumpingVersions(any(File.class), + any(ProjectVersion.class)); } @Test - public void should_bump_versions_for_original_snapshot_project() { + public void should_bump_versions_for_original_snapshot_project(CapturedOutput outputCapture) { ProjectVersion scReleaseVersion = new ProjectVersion("changed", "1.0.0.RELEASE"); - releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) - .rollbackReleaseVersion(this.pom, new Projects( - new ProjectVersion("changed", "1.0.0.RELEASE"), + releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")).rollbackReleaseVersion(this.pom, + new Projects(new ProjectVersion("changed", "1.0.0.RELEASE"), new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE"), new ProjectVersion("spring-boot-starter", "3.0.0.RELEASE")), - scReleaseVersion); + scReleaseVersion); - BDDAssertions.then(this.outputCapture.toString()) - .contains("Project was successfully updated") + BDDAssertions.then(outputCapture.toString()).contains("Project was successfully updated") .contains("Successfully reverted the commit and bumped snapshot versions") - .contains("spring-boot-starter=>3.0.0.RELEASE") - .contains("spring-cloud-build=>2.0.1.SNAPSHOT") + .contains("spring-boot-starter=>3.0.0.RELEASE").contains("spring-cloud-build=>2.0.1.SNAPSHOT") .contains("changed=>1.0.1.SNAPSHOT"); } @Test public void should_not_generate_email_for_snapshot_version() { - releaser().createEmail(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"), - projects()); + releaser().createEmail(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT"), projects()); then(this.templateGenerator).should(never()).email(any(Projects.class)); } @Test public void should_generate_email_for_release_version() { - BDDMockito.given(this.templateGenerator.email(projects())) - .willReturn(new File(".")); - releaser().createEmail(new ProjectVersion("original", "1.0.0.RELEASE"), - projects()); + BDDMockito.given(this.templateGenerator.email(projects())).willReturn(new File(".")); + releaser().createEmail(new ProjectVersion("original", "1.0.0.RELEASE"), projects()); then(this.templateGenerator).should().email(any(Projects.class)); } @@ -178,20 +164,17 @@ public class ReleaserTests { public void should_not_close_milestone_for_snapshots() { releaser().closeMilestone(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")); - then(this.projectGitHubHandler).should(never()) - .closeMilestone(any(ProjectVersion.class)); + then(this.projectGitHubHandler).should(never()).closeMilestone(any(ProjectVersion.class)); } @Test public void should_not_rollback_for_snapshots() { - releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) - .rollbackReleaseVersion(null, - new Projects( - new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")), - new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")); + releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")).rollbackReleaseVersion(null, + new Projects(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")), + new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")); - then(this.projectGitHandler).should(never()) - .revertChangesIfApplicable(any(File.class), any(ProjectVersion.class)); + then(this.projectGitHandler).should(never()).revertChangesIfApplicable(any(File.class), + any(ProjectVersion.class)); } Projects projects() { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/GradleBomParserTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/GradleBomParserTests.java index f0e0940f..c2de2d3d 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/GradleBomParserTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/GradleBomParserTests.java @@ -30,8 +30,7 @@ class GradleBomParserTests { @Test void should_read_versions_from_bom_from_properties() { - GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), - new ArrayList<>()) { + GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), new ArrayList<>()) { @Override public boolean isApplicable(File clonedBom) { return true; @@ -52,8 +51,7 @@ class GradleBomParserTests { VersionsFromBom versionsFromBom = parser.versionsFromBom(new File(".")); - BDDAssertions.then(versionsFromBom.versionForProject("spring-cloud-contract")) - .isEqualTo("1.0.0.RELEASE"); + BDDAssertions.then(versionsFromBom.versionForProject("spring-cloud-contract")).isEqualTo("1.0.0.RELEASE"); } @Test @@ -62,8 +60,7 @@ class GradleBomParserTests { gradleSubstitution.put("verifierVersion", "spring-cloud-contract"); ReleaserProperties releaserProperties = new ReleaserProperties(); releaserProperties.getGradle().setGradlePropsSubstitution(gradleSubstitution); - GradleBomParser parser = new GradleBomParser(releaserProperties, - new ArrayList<>()) { + GradleBomParser parser = new GradleBomParser(releaserProperties, new ArrayList<>()) { @Override public boolean isApplicable(File clonedBom) { return true; @@ -84,22 +81,19 @@ class GradleBomParserTests { VersionsFromBom versionsFromBom = parser.versionsFromBom(new File(".")); - BDDAssertions.then(versionsFromBom.versionForProject("spring-cloud-contract")) - .isEqualTo("1.0.0.RELEASE"); + BDDAssertions.then(versionsFromBom.versionForProject("spring-cloud-contract")).isEqualTo("1.0.0.RELEASE"); } @Test void should_be_not_applicable_when_no_build_gradle_is_present() { - GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), - new ArrayList<>()); + GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), new ArrayList<>()); BDDAssertions.then(parser.isApplicable(new File("."))).isFalse(); } @Test void should_be_applicable_when_build_gradle_is_present() { - GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), - new ArrayList<>()) { + GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), new ArrayList<>()) { @Override File file(File clonedBom, String child) { return clonedBom; @@ -111,8 +105,7 @@ class GradleBomParserTests { @Test void should_return_empty_version_when_no_gradle_properties_is_present() { - GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), - new ArrayList<>()); + GradleBomParser parser = new GradleBomParser(new ReleaserProperties(), new ArrayList<>()); VersionsFromBom versionsFromBom = parser.versionsFromBom(new File(".")); diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/LoggerToMavenLogTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/LoggerToMavenLogTests.java index 525f3dcc..7cc3d722 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/LoggerToMavenLogTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/LoggerToMavenLogTests.java @@ -16,11 +16,11 @@ package releaser.internal.buildsystem; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import static org.mockito.BDDMockito.then; @@ -28,7 +28,7 @@ import static org.mockito.BDDMockito.then; /** * @author Marcin Grzejszczak */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class LoggerToMavenLogTests { @Mock diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/MavenBomParserTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/MavenBomParserTests.java index f6b067a5..39eddfd3 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/MavenBomParserTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/MavenBomParserTests.java @@ -20,8 +20,8 @@ import java.io.File; import java.net.URISyntaxException; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import releaser.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; import releaser.internal.git.GitRepoTests; @@ -38,7 +38,7 @@ public class MavenBomParserTests { ReleaserProperties properties = SpringCloudReleaserProperties.get(); - @Before + @BeforeEach public void setup() throws URISyntaxException { this.springCloudReleaseProject = new File( GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI()); @@ -51,8 +51,7 @@ public class MavenBomParserTests { BomParser parser = new MavenBomParser(this.properties, Collections.emptyList()); thenThrownBy(() -> parser.versionsFromBom(this.springCloudReleaseProject)) - .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("Pom is not present"); + .isInstanceOf(IllegalStateException.class).hasMessageContaining("Pom is not present"); } @Test @@ -69,8 +68,7 @@ public class MavenBomParserTests { public void should_throw_exception_when_cloud_pom_is_missing() { BomParser parser = new MavenBomParser(this.properties, Collections.emptyList()); - thenThrownBy(() -> parser.versionsFromBom(new File("."))) - .isInstanceOf(IllegalStateException.class) + thenThrownBy(() -> parser.versionsFromBom(new File("."))).isInstanceOf(IllegalStateException.class) .hasMessageContaining("Pom is not present"); } @@ -81,8 +79,7 @@ public class MavenBomParserTests { BomParser parser = new MavenBomParser(this.properties, Collections.emptyList()); thenThrownBy(() -> parser.versionsFromBom(this.springCloudReleaseProject)) - .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("Pom is not present"); + .isInstanceOf(IllegalStateException.class).hasMessageContaining("Pom is not present"); } } diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/PomReaderTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/PomReaderTests.java index f128bb90..90870c02 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/PomReaderTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/PomReaderTests.java @@ -23,8 +23,8 @@ import java.net.URISyntaxException; import org.apache.maven.model.Model; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import releaser.internal.git.GitRepoTests; import releaser.internal.tech.PomReader; @@ -44,14 +44,12 @@ public class PomReaderTests { File licenseFile; - @Before + @BeforeEach public void setup() throws URISyntaxException { - URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release") - .toURI(); + URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI(); this.springCloudReleaseProject = new File(scRelease); this.springCloudReleaseProjectPom = new File(scRelease.getPath(), "pom.xml"); - this.empty = new File( - GitRepoTests.class.getResource("/projects/project/empty.xml").toURI()); + this.empty = new File(GitRepoTests.class.getResource("/projects/project/empty.xml").toURI()); this.licenseFile = new File(scRelease.getPath(), "LICENSE.txt"); } @@ -78,16 +76,14 @@ public class PomReaderTests { @Test public void should_throw_exception_when_file_is_invalid() { - thenThrownBy(() -> PomReader.readPom(this.licenseFile)) - .hasMessageStartingWith("Failed to read file: ") + thenThrownBy(() -> PomReader.readPom(this.licenseFile)).hasMessageStartingWith("Failed to read file: ") .hasCauseInstanceOf(XmlPullParserException.class); } @Test public void should_throw_exception_when_file_is_empty() { thenThrownBy(() -> PomReader.readPom(this.empty)).hasMessageStartingWith("File [") - .hasMessageContaining("] is empty") - .hasCauseInstanceOf(EOFException.class); + .hasMessageContaining("] is empty").hasCauseInstanceOf(EOFException.class); } } diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/PomUpdaterTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/PomUpdaterTests.java index 0dae4341..06dce917 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/PomUpdaterTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/PomUpdaterTests.java @@ -26,16 +26,14 @@ import java.util.Set; import edu.emory.mathcs.backport.java.util.Collections; import org.apache.maven.model.Model; import org.assertj.core.api.BDDAssertions; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import releaser.SpringCloudReleaserProperties; import releaser.internal.git.GitRepoTests; import releaser.internal.project.Project; import releaser.internal.tech.PomReader; -import org.springframework.boot.test.system.OutputCaptureRule; import org.springframework.util.FileSystemUtils; /** @@ -43,11 +41,8 @@ import org.springframework.util.FileSystemUtils; */ public class PomUpdaterTests { - @Rule - public OutputCaptureRule capture = new OutputCaptureRule(); - - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + public File tmp; VersionsFromBom versionsFromBom = new VersionsFromBomBuilder() .releaserProperties(SpringCloudReleaserProperties.get()).projects(projects()) @@ -57,58 +52,47 @@ public class PomUpdaterTests { File temporaryFolder; - @Before + @BeforeEach public void setup() throws Exception { - this.temporaryFolder = this.tmp.newFolder(); + this.temporaryFolder = new File(tmp, "test"); FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder); } @Test - public void should_not_update_pom_when_project_is_not_on_the_versions_list() - throws Exception { + public void should_not_update_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudReleasePom = file("/projects/spring-cloud-release"); - BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, - this.versionsFromBom)).isFalse(); - } - - @Test - public void should_not_update_pom_when_project_with_parent_suffix_is_not_on_the_versions_list() - throws Exception { - File springCloud = pom("/projects/project", "pom_with_parent_suffix.xml"); - - BDDAssertions.then( - this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versionsFromBom)) + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versionsFromBom)) .isFalse(); } @Test - public void should_update_pom_for_project_with_suffix_when_project_is_on_the_versions_list() - throws Exception { - File springCloud = pom("/projects/project", - "pom_matching_with_parent_suffix.xml"); + public void should_not_update_pom_when_project_with_parent_suffix_is_not_on_the_versions_list() throws Exception { + File springCloud = pom("/projects/project", "pom_with_parent_suffix.xml"); - BDDAssertions.then( - this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versionsFromBom)) - .isTrue(); + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versionsFromBom)).isFalse(); } @Test - public void should_update_pom_when_project_is_not_on_the_versions_list() - throws Exception { + public void should_update_pom_for_project_with_suffix_when_project_is_on_the_versions_list() throws Exception { + File springCloud = pom("/projects/project", "pom_matching_with_parent_suffix.xml"); + + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloud, this.versionsFromBom)).isTrue(); + } + + @Test + public void should_update_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudSleuthPom = file("/projects/spring-cloud-sleuth"); - BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, - this.versionsFromBom)).isTrue(); + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versionsFromBom)).isTrue(); } @Test - public void should_not_update_pom_when_project_is_on_the_versions_list_but_there_is_no_pom() - throws Exception { + public void should_not_update_pom_when_project_is_on_the_versions_list_but_there_is_no_pom() throws Exception { File springCloudSleuthPom = file("/projects/spring-cloud-sleuth/empty-folder"); - BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, - this.versionsFromBom)).isFalse(); + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versionsFromBom)) + .isFalse(); } @Test @@ -116,110 +100,85 @@ public class PomUpdaterTests { File originalPom = pom("/projects/project"); File pomInTemp = tmpFile("/project/pom.xml"); ModelWrapper rootPom = model("foo"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isEqualTo(asString(originalPom)); } @Test - public void should_update_the_pom_if_only_artifact_id_is_matched_in_the_root_pom() - throws Exception { + public void should_update_the_pom_if_only_artifact_id_is_matched_in_the_root_pom() throws Exception { File originalPom = pom("/projects/project", "pom_matching_artifact.xml"); File pomInTemp = tmpFile("/project/pom_matching_artifact.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); } @Test - public void should_update_the_pom_if_parent_is_matched_via_sc_build() - throws Exception { + public void should_update_the_pom_if_parent_is_matched_via_sc_build() throws Exception { File originalPom = pom("/projects/project", "pom_matching_parent_v2.xml"); File pomInTemp = tmpFile("/project/pom_matching_parent_v2.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(originalPom)).isNotEqualTo(asString(storedPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.2"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2"); } @Test - public void should_update_the_pom_if_parent_is_matched_via_sc_dependencies_parent() - throws Exception { + public void should_update_the_pom_if_parent_is_matched_via_sc_dependencies_parent() throws Exception { File originalPom = pom("/projects/project", "pom_matching_parent.xml"); File pomInTemp = tmpFile("/project/pom_matching_parent.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.2"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2"); } @Test - public void should_not_update_child_pom_when_project_is_not_on_the_versions_list() - throws Exception { + public void should_not_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudReleasePom = file("/projects/spring-cloud-release"); - BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, - this.versionsFromBom)).isFalse(); + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versionsFromBom)) + .isFalse(); } @Test - public void should_update_child_pom_when_project_is_not_on_the_versions_list() - throws Exception { + public void should_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { File springCloudSleuthPom = file("/projects/spring-cloud-sleuth"); - BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, - this.versionsFromBom)).isTrue(); + BDDAssertions.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versionsFromBom)).isTrue(); } @Test - public void should_update_the_child_pom_if_parent_is_matched_via_sc_build() - throws Exception { - File originalPom = pom("/projects/project/children", - "pom_matching_parent_v2.xml"); + public void should_update_the_child_pom_if_parent_is_matched_via_sc_build() throws Exception { + File originalPom = pom("/projects/project/children", "pom_matching_parent_v2.xml"); File pomInTemp = tmpFile("/project/children/pom_matching_parent_v2.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); // the rest is the same BDDAssertions.then(overriddenPomModel.getProperties()) .containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT") @@ -227,26 +186,20 @@ public class PomUpdaterTests { } @Test - public void should_update_the_parent_from_properties_even_if_group_ids_dont_match() - throws Exception { - File originalPom = pom("/projects/project/children", - "pom_different_group_boot_parent.xml"); + public void should_update_the_parent_from_properties_even_if_group_ids_dont_match() throws Exception { + File originalPom = pom("/projects/project/children", "pom_different_group_boot_parent.xml"); File pomInTemp = tmpFile("/project/children/pom_different_group_boot_parent.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("1.5.8.RELEASE"); - BDDAssertions.then(overriddenPomModel.getProperties()) - .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE"); + BDDAssertions.then(overriddenPomModel.getProperties()).containsEntry("spring-cloud-sleuth.version", + "0.0.3.BUILD-SNAPSHOT"); } @Test @@ -255,137 +208,104 @@ public class PomUpdaterTests { File originalPom = pom("/projects/project/children", "pom_different_group.xml"); File pomInTemp = tmpFile("/project/children/pom_different_group.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("1.2.2.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("1.5.8.RELEASE"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE"); // the rest is the same - BDDAssertions.then(overriddenPomModel.getProperties()) - .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getProperties()).containsEntry("spring-cloud-sleuth.version", + "0.0.3.BUILD-SNAPSHOT"); } @Test public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_deployment_property() throws Exception { - File originalPom = pom("/projects/project/children", - "pom_different_group_skip_deployment_prop.xml"); - File pomInTemp = tmpFile( - "/project/children/pom_different_group_skip_deployment_prop.xml"); + File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_prop.xml"); + File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_prop.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("1.2.2.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("1.5.8.RELEASE"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE"); // the rest is the same - BDDAssertions.then(overriddenPomModel.getProperties()) - .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getProperties()).containsEntry("spring-cloud-sleuth.version", + "0.0.3.BUILD-SNAPSHOT"); } @Test public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin() throws Exception { - File originalPom = pom("/projects/project/children", - "pom_different_group_skip_deployment_plugin.xml"); - File pomInTemp = tmpFile( - "/project/children/pom_different_group_skip_deployment_plugin.xml"); + File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_plugin.xml"); + File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_plugin.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("1.2.2.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("1.5.8.RELEASE"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE"); // the rest is the same - BDDAssertions.then(overriddenPomModel.getProperties()) - .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getProperties()).containsEntry("spring-cloud-sleuth.version", + "0.0.3.BUILD-SNAPSHOT"); } @Test public void should_update_everything_when_group_ids_dont_match_and_there_is_skip_in_deployment_plugin_management() throws Exception { - File originalPom = pom("/projects/project/children", - "pom_different_group_skip_deployment_plugin_mngmnt.xml"); - File pomInTemp = tmpFile( - "/project/children/pom_different_group_skip_deployment_plugin_mngmnt.xml"); + File originalPom = pom("/projects/project/children", "pom_different_group_skip_deployment_plugin_mngmnt.xml"); + File pomInTemp = tmpFile("/project/children/pom_different_group_skip_deployment_plugin_mngmnt.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth", "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("1.2.2.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("1.5.8.RELEASE"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("1.2.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("1.5.8.RELEASE"); // the rest is the same - BDDAssertions.then(overriddenPomModel.getProperties()) - .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getProperties()).containsEntry("spring-cloud-sleuth.version", + "0.0.3.BUILD-SNAPSHOT"); } @Test - public void should_update_boot_parent_even_if_the_project_group_doesnt_match() - throws Exception { - File originalPom = pom("/projects/project/children", - "pom_case_from_contract.xml"); + public void should_update_boot_parent_even_if_the_project_group_doesnt_match() throws Exception { + File originalPom = pom("/projects/project/children", "pom_case_from_contract.xml"); File pomInTemp = tmpFile("/project/children/pom_case_from_contract.xml"); - ModelWrapper rootPom = model("spring-cloud-contract", - "org.springframework.cloud"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper rootPom = model("spring-cloud-contract", "org.springframework.cloud"); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2.BUILD-SNAPSHOT"); } @Test - public void should_update_the_child_pom_if_parent_is_matched_via_sc_dependencies_parent() - throws Exception { + public void should_update_the_child_pom_if_parent_is_matched_via_sc_dependencies_parent() throws Exception { File originalPom = pom("/projects/project/children", "pom_matching_parent.xml"); File pomInTemp = tmpFile("/project/children/pom_matching_parent.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); // the rest is the same BDDAssertions.then(overriddenPomModel.getProperties()) .containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT") @@ -394,38 +314,30 @@ public class PomUpdaterTests { @Test public void should_update_the_child_pom_if_properties_are_matched() throws Exception { - File originalPom = pom("/projects/project/children", - "pom_matching_properties.xml"); + File originalPom = pom("/projects/project/children", "pom_matching_properties.xml"); File pomInTemp = tmpFile("/project/children/pom_matching_properties.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); BDDAssertions.then(overriddenPomModel.getProperties()) .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT") .containsEntry("spring-cloud-vault.version", "0.0.4.BUILD-SNAPSHOT"); } @Test - public void should_override_a_pom_when_there_was_a_change_in_the_model() - throws Exception { - File beforeProcessing = pom("/projects/project/children", - "pom_matching_properties.xml"); + public void should_override_a_pom_when_there_was_a_change_in_the_model() throws Exception { + File beforeProcessing = pom("/projects/project/children", "pom_matching_properties.xml"); File afterProcessing = tmpFile("/project/children/pom_matching_properties.xml"); - ModelWrapper model = this.pomUpdater.updateModel(model("spring-cloud-sleuth"), - afterProcessing, this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(model("spring-cloud-sleuth"), afterProcessing, + this.versionsFromBom); - File processedPom = this.pomUpdater.overwritePomIfDirty(model, - VersionsFromBom.EMPTY_VERSION, afterProcessing); + File processedPom = this.pomUpdater.overwritePomIfDirty(model, VersionsFromBom.EMPTY_VERSION, afterProcessing); String processedPomText = asString(processedPom); String beforeProcessingText = asString(beforeProcessing); @@ -433,51 +345,39 @@ public class PomUpdaterTests { } @Test - public void should_not_override_a_pom_when_there_was_no_change_in_the_model() - throws Exception { + public void should_not_override_a_pom_when_there_was_no_change_in_the_model() throws Exception { File beforeProcessing = pom("/projects/project/"); File afterProcessing = tmpFile("/project/pom.xml"); - ModelWrapper model = this.pomUpdater.updateModel(model("foo"), afterProcessing, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(model("foo"), afterProcessing, this.versionsFromBom); - File processedPom = this.pomUpdater.overwritePomIfDirty(model, - VersionsFromBom.EMPTY_VERSION, afterProcessing); + File processedPom = this.pomUpdater.overwritePomIfDirty(model, VersionsFromBom.EMPTY_VERSION, afterProcessing); BDDAssertions.then(asString(processedPom)).isEqualTo(asString(beforeProcessing)); } @Test - public void should_update_the_model_when_root_project_has_parent_suffix() - throws Exception { + public void should_update_the_model_when_root_project_has_parent_suffix() throws Exception { File originalPom = pom("/projects/spring-cloud-contract"); File pomInTemp = tmpFile("/spring-cloud-contract/pom.xml"); ModelWrapper rootPom = model("spring-cloud-contract-parent"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isNotEqualTo(asString(originalPom)); Model overriddenPomModel = PomReader.readPom(storedPom); - BDDAssertions.then(overriddenPomModel.getVersion()) - .isEqualTo("0.0.2.BUILD-SNAPSHOT"); - BDDAssertions.then(overriddenPomModel.getParent().getVersion()) - .isEqualTo("0.0.2"); + BDDAssertions.then(overriddenPomModel.getVersion()).isEqualTo("0.0.2.BUILD-SNAPSHOT"); + BDDAssertions.then(overriddenPomModel.getParent().getVersion()).isEqualTo("0.0.2"); } @Test - public void should_not_update_the_model_when_project_uses_same_version_for_artifact() - throws Exception { - File originalPom = pom("/projects/project/", - "pom_matching_artifact_same_version.xml"); + public void should_not_update_the_model_when_project_uses_same_version_for_artifact() throws Exception { + File originalPom = pom("/projects/project/", "pom_matching_artifact_same_version.xml"); File pomInTemp = tmpFile("/project/pom_matching_artifact_same_version.xml"); ModelWrapper rootPom = model("spring-cloud-sleuth"); - ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, - this.versionsFromBom); + ModelWrapper model = this.pomUpdater.updateModel(rootPom, pomInTemp, this.versionsFromBom); - File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, - pomInTemp); + File storedPom = this.pomUpdater.overwritePomIfDirty(model, this.versionsFromBom, pomInTemp); BDDAssertions.then(asString(storedPom)).isEqualTo(asString(originalPom)); } @@ -518,8 +418,7 @@ public class PomUpdaterTests { } private File pom(String relativePath, String pomName) throws URISyntaxException { - return new File(new File(GitRepoTests.class.getResource(relativePath).toURI()), - pomName); + return new File(new File(GitRepoTests.class.getResource(relativePath).toURI()), pomName); } private String asString(File file) throws IOException { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectPomUpdaterTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectPomUpdaterTests.java index b0ee3925..60618799 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectPomUpdaterTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectPomUpdaterTests.java @@ -19,7 +19,7 @@ package releaser.internal.buildsystem; import java.io.File; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import releaser.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; @@ -36,13 +36,12 @@ public class ProjectPomUpdaterTests { public void should_skip_any_steps_if_there_is_no_pom_xml() { ReleaserProperties properties = SpringCloudReleaserProperties.get(); ProjectGitHandler handler = BDDMockito.mock(ProjectGitHandler.class); - ProjectPomUpdater updater = new ProjectPomUpdater(properties, - Collections.emptyList()); + ProjectPomUpdater updater = new ProjectPomUpdater(properties, Collections.emptyList()); updater.updateProjectFromReleaseTrain(new File("target"), new Projects(), new ProjectVersion("foo", "1.0.0.RELEASE"), false); - BDDMockito.then(handler).shouldHaveZeroInteractions(); + BDDMockito.then(handler).shouldHaveNoInteractions(); } } diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectVersionTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectVersionTests.java index 92fd5f28..42bbcb8b 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectVersionTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectVersionTests.java @@ -22,8 +22,8 @@ import java.net.URISyntaxException; import java.util.List; import java.util.regex.Pattern; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import releaser.internal.git.GitRepoTests; import releaser.internal.project.ProjectVersion; @@ -40,12 +40,10 @@ public class ProjectVersionTests { File springCloudContract; - @Before + @BeforeEach public void setup() throws URISyntaxException { - URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release") - .toURI(); - URI scContract = GitRepoTests.class.getResource("/projects/spring-cloud-contract") - .toURI(); + URI scRelease = GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI(); + URI scContract = GitRepoTests.class.getResource("/projects/spring-cloud-contract").toURI(); this.springCloudReleaseProject = new File(scRelease.getPath(), "pom.xml"); this.springCloudContract = new File(scContract.getPath(), "pom.xml"); } @@ -60,8 +58,7 @@ public class ProjectVersionTests { @Test public void should_build_version_from_file() { - ProjectVersion projectVersion = new ProjectVersion( - this.springCloudReleaseProject); + ProjectVersion projectVersion = new ProjectVersion(this.springCloudReleaseProject); then(projectVersion.version).isEqualTo("Dalston.BUILD-SNAPSHOT"); then(projectVersion.projectName).isEqualTo("spring-cloud-starter-build"); @@ -86,8 +83,8 @@ public class ProjectVersionTests { public void should_throw_exception_if_version_is_not_long_enough() { String version = "1"; - thenThrownBy(() -> projectVersion(version).bumpedVersion()) - .isInstanceOf(IllegalStateException.class).hasMessageContaining( + thenThrownBy(() -> projectVersion(version).bumpedVersion()).isInstanceOf(IllegalStateException.class) + .hasMessageContaining( "Version [1] is invalid. Should be of format [1.2.3.A] / [1.2.3-A] or [A.B] / [A-B]"); } @@ -143,8 +140,8 @@ public class ProjectVersionTests { public void should_throw_exception_when_trying_to_get_major_from_invalid_version() { String version = "1"; - thenThrownBy(() -> projectVersion(version).major()) - .isInstanceOf(IllegalStateException.class).hasMessageContaining( + thenThrownBy(() -> projectVersion(version).major()).isInstanceOf(IllegalStateException.class) + .hasMessageContaining( "Version [1] is invalid. Should be of format [1.2.3.A] / [1.2.3-A] or [A.B] / [A-B]"); } @@ -163,88 +160,70 @@ public class ProjectVersionTests { @Test public void should_not_bump_version_by_patch_version_when_non_ga_or_sr() { - then(projectVersion("1.0.1-SNAPSHOT").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("1.0.1-M1").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("1.0.1-RC1").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("Finchley-SR1").postReleaseSnapshotVersion()) - .isEqualTo("Finchley-SNAPSHOT"); + then(projectVersion("1.0.1-SNAPSHOT").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("1.0.1-M1").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("1.0.1-RC1").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("Finchley-SR1").postReleaseSnapshotVersion()).isEqualTo("Finchley-SNAPSHOT"); } @Test public void should_not_bump_version_by_patch_version_when_non_ga_or_sr_with_hyphen() { - then(projectVersion("1.0.1-SNAPSHOT").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("1.0.1-M1").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("1.0.1-RC1").postReleaseSnapshotVersion()) - .isEqualTo("1.0.1-SNAPSHOT"); - then(projectVersion("Finchley-SR1").postReleaseSnapshotVersion()) - .isEqualTo("Finchley-SNAPSHOT"); + then(projectVersion("1.0.1-SNAPSHOT").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("1.0.1-M1").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("1.0.1-RC1").postReleaseSnapshotVersion()).isEqualTo("1.0.1-SNAPSHOT"); + then(projectVersion("Finchley-SR1").postReleaseSnapshotVersion()).isEqualTo("Finchley-SNAPSHOT"); } @Test public void should_bump_version_by_patch_version_when_bumping_snapshots_for_ga() { - then(projectVersion("1.0.1-RELEASE").postReleaseSnapshotVersion()) - .isEqualTo("1.0.2-SNAPSHOT"); + then(projectVersion("1.0.1-RELEASE").postReleaseSnapshotVersion()).isEqualTo("1.0.2-SNAPSHOT"); } @Test public void should_return_the_previous_version_for_release_train_version_when_bumping_snapshots() { String version = "Edgware-SNAPSHOT"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("Edgware-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("Edgware-SNAPSHOT"); } @Test public void should_return_the_previous_version_for_hyphen_release_train_version_when_bumping_snapshots() { String version = "Edgware-SNAPSHOT"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("Edgware-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("Edgware-SNAPSHOT"); } @Test public void should_bump_version_by_patch_version_when_bumping_releases() { String version = "1.0.1-RELEASE"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("1.0.2-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("1.0.2-SNAPSHOT"); } @Test public void should_bump_version_by_patch_version_when_bumping_releases_with_hyphen() { String version = "1.0.1-RELEASE"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("1.0.2-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("1.0.2-SNAPSHOT"); version = "3.1.0"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("3.1.1-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("3.1.1-SNAPSHOT"); version = "3.0.0"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("3.0.1-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("3.0.1-SNAPSHOT"); version = "2.0.0"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("2.0.1-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("2.0.1-SNAPSHOT"); version = "3.0.1"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("3.0.2-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("3.0.2-SNAPSHOT"); } @Test public void should_return_the_previous_version_for_release_train_version_when_bumping_releases() { String version = "Edgware-RELEASE"; - then(projectVersion(version).postReleaseSnapshotVersion()) - .isEqualTo("Edgware-SNAPSHOT"); + then(projectVersion(version).postReleaseSnapshotVersion()).isEqualTo("Edgware-SNAPSHOT"); } @Test @@ -407,8 +386,7 @@ public class ProjectVersionTests { String thisVersion = "1.3.2-SR3"; String thatVersion = "1.3.1-SR3"; - then(projectVersion(thisVersion).compareTo(projectVersion(thatVersion))) - .isPositive(); + then(projectVersion(thisVersion).compareTo(projectVersion(thatVersion))).isPositive(); } @Test @@ -416,117 +394,72 @@ public class ProjectVersionTests { String thisVersion = "1.3.0-RC3"; String thatVersion = "1.3.1-RC3"; - then(projectVersion(thisVersion).compareTo(projectVersion(thatVersion))) - .isNegative(); + then(projectVersion(thisVersion).compareTo(projectVersion(thatVersion))).isNegative(); } @Test public void should_compare_builds_in_terms_of_maturity_for_projects() { String thisVersion = "1.3.2.RELEASE"; - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-SNAPSHOT"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-RC1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1.RELEASE"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-SNAPSHOT"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-RC1"))) - .isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1-RC1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.1.RELEASE"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.3.3-RC1"))).isTrue(); } @Test public void should_compare_builds_in_terms_of_maturity_for_trains() { String thisVersion = "Hoxton-SR1"; - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-SNAPSHOT"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-RC1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton.RELEASE"))) - .isTrue(); - then(projectVersion(thisVersion) - .isMoreMature(projectVersion("Iexample-SNAPSHOT"))).isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-RC1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SR1"))) - .isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-RC1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton.RELEASE"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-RC1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SR1"))).isFalse(); thisVersion = "Hoxton-SNAPSHOT"; - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-SNAPSHOT"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-M1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-RC1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion) - .isMoreMature(projectVersion("Iexample-SNAPSHOT"))).isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-M1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-RC1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SR1"))) - .isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-SNAPSHOT"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-M1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton-RC1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Hoxton.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SNAPSHOT"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-M1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-RC1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("Iexample-SR1"))).isFalse(); thisVersion = "1.0.1.RELEASE"; - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-SNAPSHOT"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-RC1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SNAPSHOT"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-M1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-RC1"))) - .isTrue(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SR1"))) - .isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-RC1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SNAPSHOT"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-M1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-RC1"))).isTrue(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SR1"))).isFalse(); thisVersion = "1.0.1-SNAPSHOT"; - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-SNAPSHOT"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-M1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-RC1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SNAPSHOT"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-M1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-RC1"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2.RELEASE"))) - .isFalse(); - then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SR1"))) - .isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-SNAPSHOT"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-M1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1-RC1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.1.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SNAPSHOT"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-M1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-RC1"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2.RELEASE"))).isFalse(); + then(projectVersion(thisVersion).isMoreMature(projectVersion("1.0.2-SR1"))).isFalse(); } @Test @@ -711,31 +644,26 @@ public class ProjectVersionTests { @Test public void should_return_snapshot_unacceptable_patterns_for_a_milestone_or_rc_version() { - List milestonePatterns = projectVersion("1.0.0-M1") - .unacceptableVersionPatterns(); + List milestonePatterns = projectVersion("1.0.0-M1").unacceptableVersionPatterns(); then(milestonePatterns).isNotEmpty(); then(milestonePatterns.get(0).pattern()).contains("SNAPSHOT"); - List rcPatterns = projectVersion("1.0.0-RC1") - .unacceptableVersionPatterns(); + List rcPatterns = projectVersion("1.0.0-RC1").unacceptableVersionPatterns(); then(rcPatterns).isNotEmpty(); then(rcPatterns.get(0).pattern()).contains("SNAPSHOT"); - List milestonePatternsWithDash = projectVersion("1.0.0-M1") - .unacceptableVersionPatterns(); + List milestonePatternsWithDash = projectVersion("1.0.0-M1").unacceptableVersionPatterns(); then(milestonePatternsWithDash).isNotEmpty(); then(milestonePatternsWithDash.get(0).pattern()).contains("SNAPSHOT"); - List rcPatternsWithDash = projectVersion("1.0.0-RC1") - .unacceptableVersionPatterns(); + List rcPatternsWithDash = projectVersion("1.0.0-RC1").unacceptableVersionPatterns(); then(rcPatternsWithDash).isNotEmpty(); then(rcPatternsWithDash.get(0).pattern()).contains("SNAPSHOT"); } @Test public void should_return_snapshot_milestone_rc_unacceptable_patterns_for_a_ga_or_sr_version() { - List gaPatterns = projectVersion("1.0.0.RELEASE") - .unacceptableVersionPatterns(); + List gaPatterns = projectVersion("1.0.0.RELEASE").unacceptableVersionPatterns(); thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(gaPatterns); gaPatterns = projectVersion("1.0.0").unacceptableVersionPatterns(); @@ -744,24 +672,19 @@ public class ProjectVersionTests { gaPatterns = projectVersion("1.0.0-RELEASE").unacceptableVersionPatterns(); thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(gaPatterns); - List srPatterns = projectVersion("1.0.0-SR1") - .unacceptableVersionPatterns(); + List srPatterns = projectVersion("1.0.0-SR1").unacceptableVersionPatterns(); thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(srPatterns); - List srPatternsWithDash = projectVersion("1.0.0-SR1") - .unacceptableVersionPatterns(); + List srPatternsWithDash = projectVersion("1.0.0-SR1").unacceptableVersionPatterns(); thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(srPatternsWithDash); - List unknownTypeOfVersion = projectVersion("1.0.0.SOMETHING") - .unacceptableVersionPatterns(); - thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent( - unknownTypeOfVersion); + List unknownTypeOfVersion = projectVersion("1.0.0.SOMETHING").unacceptableVersionPatterns(); + thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(unknownTypeOfVersion); } @Test public void should_return_v100RELEASE_when_tag_name_is_requested() { - then(projectVersion("1.0.0.RELEASE").releaseTagName()) - .isEqualTo("v1.0.0.RELEASE"); + then(projectVersion("1.0.0.RELEASE").releaseTagName()).isEqualTo("v1.0.0.RELEASE"); } @Test @@ -771,93 +694,77 @@ public class ProjectVersionTests { @Test public void should_return_decremented_patch_when_patch_above_zero() { - then(projectVersion("1.2.3.RELEASE").computePreviousPatchTag("v", "RELEASE")) - .contains("v1.2.2.RELEASE"); + then(projectVersion("1.2.3.RELEASE").computePreviousPatchTag("v", "RELEASE")).contains("v1.2.2.RELEASE"); } @Test public void should_use_current_suffix_if_no_forced_suffix() { - then(projectVersion("1.2.3.WHATEVER").computePreviousPatchTag("v", "")) - .contains("v1.2.2.WHATEVER"); + then(projectVersion("1.2.3.WHATEVER").computePreviousPatchTag("v", "")).contains("v1.2.2.WHATEVER"); } @Test public void should_replace_suffix() { - then(projectVersion("1.2.3.WHATEVER").computePreviousPatchTag("v", "RELEASE")) - .contains("v1.2.2.RELEASE"); + then(projectVersion("1.2.3.WHATEVER").computePreviousPatchTag("v", "RELEASE")).contains("v1.2.2.RELEASE"); } @Test public void should_return_empty_when_patch_at_zero() { - then(projectVersion("1.2.0.WHATEVER").computePreviousPatchTag("v", "RELEASE")) - .isEmpty(); + then(projectVersion("1.2.0.WHATEVER").computePreviousPatchTag("v", "RELEASE")).isEmpty(); } @Test public void should_return_minor_pattern_when_minor_above_zero() { - then(projectVersion("1.2.0.WHATEVER") - .computePreviousMinorTagPattern("v", "RELEASE").get().pattern()) - .isEqualTo("\\Qv1.1.\\E\\d+\\Q.RELEASE\\E"); + then(projectVersion("1.2.0.WHATEVER").computePreviousMinorTagPattern("v", "RELEASE").get().pattern()) + .isEqualTo("\\Qv1.1.\\E\\d+\\Q.RELEASE\\E"); } @Test public void should_compute_minor_pattern_with_current_suffix_if_no_forced_suffix() { - then(projectVersion("1.2.0.WHATEVER").computePreviousMinorTagPattern("v", "") - .get().pattern()).isEqualTo("\\Qv1.1.\\E\\d+\\Q.WHATEVER\\E"); + then(projectVersion("1.2.0.WHATEVER").computePreviousMinorTagPattern("v", "").get().pattern()) + .isEqualTo("\\Qv1.1.\\E\\d+\\Q.WHATEVER\\E"); } @Test public void should_return_empty_minor_pattern_when_minor_zero() { - then(projectVersion("1.0.0.WHATEVER").computePreviousMinorTagPattern("v", - "RELEASE")).isEmpty(); + then(projectVersion("1.0.0.WHATEVER").computePreviousMinorTagPattern("v", "RELEASE")).isEmpty(); } @Test public void should_return_major_pattern_when_major_above_zero() { - then(projectVersion("1.0.0.WHATEVER") - .computePreviousMajorTagPattern("v", "RELEASE").pattern()) - .isEqualTo("\\Qv0.\\E\\d+\\Q.\\E\\d+\\Q.RELEASE\\E"); + then(projectVersion("1.0.0.WHATEVER").computePreviousMajorTagPattern("v", "RELEASE").pattern()) + .isEqualTo("\\Qv0.\\E\\d+\\Q.\\E\\d+\\Q.RELEASE\\E"); } @Test public void should_compute_major_pattern_with_current_suffix_if_no_forced_suffix() { - then(projectVersion("1.0.0.WHATEVER").computePreviousMajorTagPattern("v", "") - .pattern()).isEqualTo("\\Qv0.\\E\\d+\\Q.\\E\\d+\\Q.WHATEVER\\E"); + then(projectVersion("1.0.0.WHATEVER").computePreviousMajorTagPattern("v", "").pattern()) + .isEqualTo("\\Qv0.\\E\\d+\\Q.\\E\\d+\\Q.WHATEVER\\E"); } @Test public void should_throw_major_pattern_when_major_zero() { assertThatIllegalArgumentException() - .isThrownBy(() -> projectVersion("0.0.1.WHATEVER") - .computePreviousMajorTagPattern("v", "RELEASE")); + .isThrownBy(() -> projectVersion("0.0.1.WHATEVER").computePreviousMajorTagPattern("v", "RELEASE")); } - private void thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent( - List unknownTypeOfVersion) { + private void thenPatternsForSnapshotMilestoneAndReleaseCandidateArePresent(List unknownTypeOfVersion) { then(unknownTypeOfVersion).isNotEmpty(); then(unknownTypeOfVersion.get(0).pattern()).contains("SNAPSHOT"); then(unknownTypeOfVersion.get(1).pattern()).contains("M[0-9]"); then(unknownTypeOfVersion.get(2).pattern()).contains("RC"); - then(unknownTypeOfVersion.get(0).matcher("SomeName-SNAPSHOT").lookingAt()) - .isTrue(); - then(unknownTypeOfVersion.get(0).matcher("SomeName.BUILD-SNAPSHOT").lookingAt()) - .isTrue(); - then(unknownTypeOfVersion.get(0) - .matcher("\t\t1.19.2-SNAPSHOT\n").lookingAt()) - .isTrue(); + then(unknownTypeOfVersion.get(0).matcher("SomeName-SNAPSHOT").lookingAt()).isTrue(); + then(unknownTypeOfVersion.get(0).matcher("SomeName.BUILD-SNAPSHOT").lookingAt()).isTrue(); + then(unknownTypeOfVersion.get(0).matcher("\t\t1.19.2-SNAPSHOT\n").lookingAt()).isTrue(); then(unknownTypeOfVersion.get(1).matcher("SomeName-M3").lookingAt()).isTrue(); then(unknownTypeOfVersion.get(1).matcher("SomeName.M3").lookingAt()).isTrue(); - then(unknownTypeOfVersion.get(1) - .matcher("\t\t1.19.2-M2\n").lookingAt()) - .isTrue(); + then(unknownTypeOfVersion.get(1).matcher("\t\t1.19.2-M2\n").lookingAt()) + .isTrue(); then(unknownTypeOfVersion.get(2).matcher("SomeName-RC3").lookingAt()).isTrue(); then(unknownTypeOfVersion.get(2).matcher("SomeName.RC3").lookingAt()).isTrue(); - then(unknownTypeOfVersion.get(2) - .matcher("1.19.2-RC1").lookingAt()) - .isTrue(); + then(unknownTypeOfVersion.get(2).matcher("1.19.2-RC1").lookingAt()).isTrue(); } private ProjectVersion projectVersion(String version) { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectsTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectsTests.java index 0b2441fd..67cfeef4 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectsTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/ProjectsTests.java @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import releaser.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; import releaser.internal.project.ProjectVersion; @@ -71,8 +71,7 @@ public class ProjectsTests { projectVersions.add(new ProjectVersion("spring-boot-starter-build", "1.0.0")); Projects projects = new Projects(projectVersions); - then(projects.forNameStartingWith("spring-boot").get(0).version) - .isEqualTo("1.0.0"); + then(projects.forNameStartingWith("spring-boot").get(0).version).isEqualTo("1.0.0"); } @Test @@ -82,25 +81,18 @@ public class ProjectsTests { projectVersions.add(build); ProjectVersion boot = new ProjectVersion("spring-boot-starter", "2.0.0-RELEASE"); projectVersions.add(boot); - ProjectVersion bootDeps = new ProjectVersion("spring-boot-dependencies", - "2.0.0.RELEASE"); + ProjectVersion bootDeps = new ProjectVersion("spring-boot-dependencies", "2.0.0.RELEASE"); projectVersions.add(bootDeps); - ProjectVersion original = new ProjectVersion("spring-cloud-starter-foo", - "3.0.0.BUILD-SNAPSHOT"); + ProjectVersion original = new ProjectVersion("spring-cloud-starter-foo", "3.0.0.BUILD-SNAPSHOT"); projectVersions.add(original); Projects projects = new Projects(projectVersions); - Projects forRollback = Projects.forRollback(SpringCloudReleaserProperties.get(), - projects); + Projects forRollback = Projects.forRollback(SpringCloudReleaserProperties.get(), projects); - then(forRollback.forName("spring-cloud-build").version) - .isEqualTo("1.0.1-SNAPSHOT"); - then(forRollback.forName("spring-boot-starter").version) - .isEqualTo("2.0.0-RELEASE"); - then(forRollback.forName("spring-boot-dependencies").version) - .isEqualTo("2.0.0.RELEASE"); - then(forRollback.forName("spring-cloud-starter-foo").version) - .isEqualTo("3.0.0.BUILD-SNAPSHOT"); + then(forRollback.forName("spring-cloud-build").version).isEqualTo("1.0.1-SNAPSHOT"); + then(forRollback.forName("spring-boot-starter").version).isEqualTo("2.0.0-RELEASE"); + then(forRollback.forName("spring-boot-dependencies").version).isEqualTo("2.0.0.RELEASE"); + then(forRollback.forName("spring-cloud-starter-foo").version).isEqualTo("3.0.0.BUILD-SNAPSHOT"); } @Test @@ -149,8 +141,7 @@ public class ProjectsTests { @Test public void should_return_projects_with_bumped_versions() { Set projectVersions = new HashSet<>(); - projectVersions - .add(new ProjectVersion("spring-boot-dependencies", "2.0.0.RELEASE")); + projectVersions.add(new ProjectVersion("spring-boot-dependencies", "2.0.0.RELEASE")); projectVersions.add(new ProjectVersion("spring-boot-starter", "2.0.0.RELEASE")); projectVersions.add(new ProjectVersion("foo", "1.0.0.RELEASE")); projectVersions.add(new ProjectVersion("bar", "1.0.1.M1")); @@ -160,11 +151,9 @@ public class ProjectsTests { projectVersions.add(new ProjectVersion("foo4", "Finchley.SR4")); Projects projects = new Projects(projectVersions); - Projects bumped = projects - .postReleaseSnapshotVersion(Collections.singletonList("spring-boot")); + Projects bumped = projects.postReleaseSnapshotVersion(Collections.singletonList("spring-boot")); - then(bumped.forName("spring-boot-dependencies").version) - .isEqualTo("2.0.0.RELEASE"); + then(bumped.forName("spring-boot-dependencies").version).isEqualTo("2.0.0.RELEASE"); then(bumped.forName("spring-boot-starter").version).isEqualTo("2.0.0.RELEASE"); then(bumped.forName("foo").version).isEqualTo("1.0.1.SNAPSHOT"); then(bumped.forName("bar").version).isEqualTo("1.0.1.SNAPSHOT"); @@ -180,9 +169,8 @@ public class ProjectsTests { projectVersions.add(new ProjectVersion("foo", "1.0.0")); Projects projects = new Projects(projectVersions); - thenThrownBy(() -> projects.forFile(this.springCloudReleasePom)) - .isInstanceOf(IllegalStateException.class).hasMessageContaining( - "Project with name [spring-cloud-starter-build] is not present"); + thenThrownBy(() -> projects.forFile(this.springCloudReleasePom)).isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Project with name [spring-cloud-starter-build] is not present"); } @Test @@ -191,9 +179,8 @@ public class ProjectsTests { projectVersions.add(new ProjectVersion("foo", "1.0.0")); Projects projects = new Projects(projectVersions); - thenThrownBy(() -> projects.forName("spring-cloud-starter-build")) - .isInstanceOf(IllegalStateException.class).hasMessageContaining( - "Project with name [spring-cloud-starter-build] is not present"); + thenThrownBy(() -> projects.forName("spring-cloud-starter-build")).isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Project with name [spring-cloud-starter-build] is not present"); } @Test @@ -224,9 +211,8 @@ public class ProjectsTests { projectVersions.add(new ProjectVersion("foo", "1.0.0")); Projects projects = new Projects(projectVersions); - thenThrownBy(() -> projects.releaseTrain(properties)) - .isInstanceOf(IllegalStateException.class).hasMessageContaining( - "don't contain any of the following release train names"); + thenThrownBy(() -> projects.releaseTrain(properties)).isInstanceOf(IllegalStateException.class) + .hasMessageContaining("don't contain any of the following release train names"); } private File file(String relativePath) { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyStorerTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyStorerTests.java index 66385b55..49109f03 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyStorerTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyStorerTests.java @@ -18,12 +18,12 @@ package releaser.internal.buildsystem; import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.BDDMockito; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import releaser.internal.project.Project; import static org.mockito.BDDMockito.then; @@ -31,7 +31,7 @@ import static org.mockito.BDDMockito.then; /** * @author Marcin Grzejszczak */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PropertyStorerTests { @Mock @@ -51,8 +51,7 @@ public class PropertyStorerTests { } private String containsWarnMsgAboutEmptyVersion() { - return BDDMockito - .argThat(argument -> argument.contains("is empty. Will not set it")); + return BDDMockito.argThat(argument -> argument.contains("is empty. Will not set it")); } } diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyVersionChangerTests.java b/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyVersionChangerTests.java index 7937e35c..028f4372 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyVersionChangerTests.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/PropertyVersionChangerTests.java @@ -22,10 +22,10 @@ import java.util.Set; import edu.emory.mathcs.backport.java.util.Arrays; import org.apache.maven.model.Model; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import releaser.internal.ReleaserProperties; import releaser.internal.project.Project; @@ -36,57 +36,52 @@ import static org.mockito.Mockito.never; /** * @author Marcin Grzejszczak */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PropertyVersionChangerTests { @Mock PropertyStorer propertyStorer; @Test - public void should_set_version_when_project_matches_property_name() throws Exception { - PropertyVersionChanger changer = new PropertyVersionChanger(model(), versions(), - null, null, this.propertyStorer); + public void should_set_version_when_project_matches_property_name() { + PropertyVersionChanger changer = new PropertyVersionChanger(model(), versions(), null, null, + this.propertyStorer); changer.apply(null); - then(this.propertyStorer).should().setPropertyVersionIfApplicable( - project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT")); + then(this.propertyStorer).should() + .setPropertyVersionIfApplicable(project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT")); } @Test - public void should_not_set_version_when_project_doesnt_match_property_name() - throws Exception { - PropertyVersionChanger changer = new PropertyVersionChanger(nonMatchingModel(), - versions(), null, null, this.propertyStorer); + public void should_not_set_version_when_project_doesnt_match_property_name() { + PropertyVersionChanger changer = new PropertyVersionChanger(nonMatchingModel(), versions(), null, null, + this.propertyStorer); changer.apply(null); - then(this.propertyStorer).should(never()) - .setPropertyVersionIfApplicable(any(Project.class)); + then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class)); } @Test - public void should_not_set_version_when_project_matches_property_name_and_versions_are_the_same() - throws Exception { - PropertyVersionChanger changer = new PropertyVersionChanger(modelWithSameValues(), - versions(), null, null, this.propertyStorer); + public void should_not_set_version_when_project_matches_property_name_and_versions_are_the_same() { + PropertyVersionChanger changer = new PropertyVersionChanger(modelWithSameValues(), versions(), null, null, + this.propertyStorer); changer.apply(null); - then(this.propertyStorer).should(never()) - .setPropertyVersionIfApplicable(any(Project.class)); + then(this.propertyStorer).should(never()).setPropertyVersionIfApplicable(any(Project.class)); } VersionsFromBom versions() { - return new VersionsFromBomBuilder().releaserProperties(new ReleaserProperties()) - .projects(allProjects()).retrieveFromBom(); + return new VersionsFromBomBuilder().releaserProperties(new ReleaserProperties()).projects(allProjects()) + .retrieveFromBom(); } @SuppressWarnings("unchecked") private Set allProjects() { - return new HashSet<>(Arrays.asList( - new Project[] { project("spring-cloud-aws", "1.2.0.BUILD-SNAPSHOT"), - project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT") })); + return new HashSet<>(Arrays.asList(new Project[] { project("spring-cloud-aws", "1.2.0.BUILD-SNAPSHOT"), + project("spring-cloud-sleuth", "1.2.0.BUILD-SNAPSHOT") })); } Project project(String name, String value) { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/TestUtils.java b/releaser-core/src/test/java/releaser/internal/buildsystem/TestUtils.java index 7636bd2e..46ba7b1f 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/TestUtils.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/TestUtils.java @@ -36,8 +36,7 @@ public final class TestUtils { prepareLocalRepo("target/test-classes/projects/", "spring-cloud-static"); } - private static void prepareLocalRepo(String buildDir, String repoPath) - throws IOException { + private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { File dotGit = new File(buildDir + repoPath + "/.git"); File git = new File(buildDir + repoPath + "/git"); if (git.exists()) { diff --git a/releaser-core/src/test/java/releaser/internal/buildsystem/VersionChangeAssertions.java b/releaser-core/src/test/java/releaser/internal/buildsystem/VersionChangeAssertions.java index b2541243..602b9dc1 100644 --- a/releaser-core/src/test/java/releaser/internal/buildsystem/VersionChangeAssertions.java +++ b/releaser-core/src/test/java/releaser/internal/buildsystem/VersionChangeAssertions.java @@ -54,12 +54,10 @@ class VersionChangeAssert extends AbstractAssert rows = Row.fromProjects(projects, true); @@ -50,8 +49,7 @@ public class RowTests { @Test public void should_convert_projects_to_rows_for_current_ga() { - Projects projects = new Projects( - new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"), + Projects projects = new Projects(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"), new ProjectVersion("sc-release", "2.0.1.RELEASE")); List rows = Row.fromProjects(projects, false); diff --git a/releaser-core/src/test/java/releaser/internal/docs/SpringCloudGhPagesParserTests.java b/releaser-core/src/test/java/releaser/internal/docs/SpringCloudGhPagesParserTests.java index 201580ee..ce991252 100644 --- a/releaser-core/src/test/java/releaser/internal/docs/SpringCloudGhPagesParserTests.java +++ b/releaser-core/src/test/java/releaser/internal/docs/SpringCloudGhPagesParserTests.java @@ -20,85 +20,61 @@ import java.io.File; import java.net.URISyntaxException; import org.assertj.core.api.BDDAssertions; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; /** * @author Marcin Grzejszczak */ +@ExtendWith(OutputCaptureExtension.class) public class SpringCloudGhPagesParserTests { - @Rule - public OutputCapture capture = new OutputCapture(); + File rawHtml = new File( + SpringCloudGhPagesParserTests.class.getResource("/raw/spring-cloud-gh-pages-index.html").toURI()); - File rawHtml = new File(SpringCloudGhPagesParserTests.class - .getResource("/raw/spring-cloud-gh-pages-index.html").toURI()); - - File wrongHtml = new File(SpringCloudGhPagesParserTests.class - .getResource("/raw/some-file.html").toURI()); + File wrongHtml = new File(SpringCloudGhPagesParserTests.class.getResource("/raw/some-file.html").toURI()); public SpringCloudGhPagesParserTests() throws URISyntaxException { } @Test public void should_parse_the_components_table() { - ReleaseTrainContents contents = new ReleaseTrainContentsParser() - .parseProjectPage(this.rawHtml); + ReleaseTrainContents contents = new ReleaseTrainContentsParser().parseProjectPage(this.rawHtml); BDDAssertions.then(contents).isNotNull(); - BDDAssertions.then(contents.title).isEqualTo( - new Title("Edgware.SR5", "Finchley.SR1", "Finchley.BUILD-SNAPSHOT")); + BDDAssertions.then(contents.title) + .isEqualTo(new Title("Edgware.SR5", "Finchley.SR1", "Finchley.BUILD-SNAPSHOT")); BDDAssertions.then(contents.rows).contains( - new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1", - "Elmhurst.BUILD-SNAPSHOT"), - new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE", - "2.0.4.BUILD-SNAPSHOT"), - new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE", - "2.0.1.BUILD-SNAPSHOT"), - new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE", - "2.0.2.BUILD-SNAPSHOT"), - new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE", - "1.0.1.BUILD-SNAPSHOT")); + new Row("spring-cloud-aws", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-bus", "1.3.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-cli", "1.4.1.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-commons", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-contract", "1.2.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-config", "1.4.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-netflix", "1.4.6.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-security", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-cloudfoundry", "1.1.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-consul", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-sleuth", "1.3.5.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-stream", "Ditmars.SR4", "Elmhurst.SR1", "Elmhurst.BUILD-SNAPSHOT"), + new Row("spring-cloud-zookeeper", "1.2.2.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-boot", "1.5.16.RELEASE", "2.0.4.RELEASE", "2.0.4.BUILD-SNAPSHOT"), + new Row("spring-cloud-task", "1.2.3.RELEASE", "2.0.0.RELEASE", "2.0.1.BUILD-SNAPSHOT"), + new Row("spring-cloud-vault", "1.1.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-gateway", "1.0.2.RELEASE", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-openfeign", "", "2.0.1.RELEASE", "2.0.2.BUILD-SNAPSHOT"), + new Row("spring-cloud-function", "1.0.1.RELEASE", "1.0.0.RELEASE", "1.0.1.BUILD-SNAPSHOT")); } @Test - public void should_not_parse_the_components_table_when_markers_are_not_found() { - ReleaseTrainContents contents = new ReleaseTrainContentsParser() - .parseProjectPage(this.wrongHtml); + public void should_not_parse_the_components_table_when_markers_are_not_found(CapturedOutput capture) { + ReleaseTrainContents contents = new ReleaseTrainContentsParser().parseProjectPage(this.wrongHtml); BDDAssertions.then(contents).isNull(); - BDDAssertions.then(this.capture.toString()) - .contains("The page is missing the components table markers"); + BDDAssertions.then(capture.toString()).contains("The page is missing the components table markers"); } } diff --git a/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java b/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java index b8ca995c..4305a71c 100644 --- a/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java +++ b/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java @@ -31,10 +31,9 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.transport.URIish; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import releaser.internal.buildsystem.TestUtils; import static org.assertj.core.api.Assertions.fail; @@ -46,8 +45,8 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy; */ public class GitRepoTests { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + public File tmp; File springCloudReleaseProject; @@ -55,9 +54,9 @@ public class GitRepoTests { GitRepo gitRepo; - @Before + @BeforeEach public void setup() throws IOException, URISyntaxException { - this.tmpFolder = this.tmp.newFolder(); + this.tmpFolder = new File(tmp, "test"); this.springCloudReleaseProject = new File( GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI()); TestUtils.prepareLocalRepo(); @@ -74,8 +73,8 @@ public class GitRepoTests { @Test public void should_throw_exception_when_there_is_no_repo() { - thenThrownBy(() -> this.gitRepo.cloneProject( - new URIish(GitRepoTests.class.getResource("/projects/").toURI().toURL()))) + thenThrownBy(() -> this.gitRepo + .cloneProject(new URIish(GitRepoTests.class.getResource("/projects/").toURI().toURL()))) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("Exception occurred while cloning repo"); } @@ -97,8 +96,7 @@ public class GitRepoTests { File pom = new File(new File(this.tmpFolder, uri.getHumanishName()), "pom.xml"); then(pom).exists(); - then(Files.lines(pom.toPath()) - .anyMatch(s -> s.contains("Camden.SR3"))).isTrue(); + then(Files.lines(pom.toPath()).anyMatch(s -> s.contains("Camden.SR3"))).isTrue(); } @Test @@ -109,9 +107,7 @@ public class GitRepoTests { File pom = new File(new File(this.tmpFolder, uri.getHumanishName()), "pom.xml"); then(pom).exists(); - then(Files.lines(pom.toPath()) - .anyMatch(s -> s.contains("Camden.BUILD-SNAPSHOT"))) - .isTrue(); + then(Files.lines(pom.toPath()).anyMatch(s -> s.contains("Camden.BUILD-SNAPSHOT"))).isTrue(); } @Test @@ -131,8 +127,7 @@ public class GitRepoTests { } @Test - public void should_throw_an_exception_when_checking_out_nonexisting_branch() - throws IOException { + public void should_throw_an_exception_when_checking_out_nonexisting_branch() throws IOException { File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); try { @@ -190,14 +185,12 @@ public class GitRepoTests { private void tagIsPresent(Git git, String tag) throws GitAPIException { List refs = git.tagList().call(); System.out.println("All tags" + refs); - then(refs.stream().anyMatch(ref -> ref.getName().startsWith("refs/tags/" + tag))) - .isTrue(); + then(refs.stream().anyMatch(ref -> ref.getName().startsWith("refs/tags/" + tag))).isTrue(); } @Test public void should_push_changes_to_master_branch() throws Exception { - File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), - this.springCloudReleaseProject); + File origin = GitTestUtils.clonedProject(new File(tmp, "test1"), this.springCloudReleaseProject); File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); GitTestUtils.setOriginOnProjectToTmp(origin, project); @@ -214,8 +207,7 @@ public class GitRepoTests { @Test public void should_push_changes_to_current_branch() throws Exception { - File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), - this.springCloudReleaseProject); + File origin = GitTestUtils.clonedProject(new File(tmp, "test2"), this.springCloudReleaseProject); File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); GitTestUtils.setOriginOnProjectToTmp(origin, project); @@ -232,8 +224,7 @@ public class GitRepoTests { @Test public void should_return_the_branch_name() throws Exception { - File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), - this.springCloudReleaseProject); + File origin = GitTestUtils.clonedProject(new File(tmp, "test3"), this.springCloudReleaseProject); File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); GitTestUtils.setOriginOnProjectToTmp(origin, project); @@ -246,8 +237,7 @@ public class GitRepoTests { @Test public void should_push_a_tag_to_new_branch_in_origin() throws Exception { - File origin = GitTestUtils.clonedProject(this.tmp.newFolder(), - this.springCloudReleaseProject); + File origin = GitTestUtils.clonedProject(new File(tmp, "test4"), this.springCloudReleaseProject); File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); GitTestUtils.setOriginOnProjectToTmp(origin, project); @@ -297,8 +287,7 @@ public class GitRepoTests { } @Test - public void should_not_revert_changes_when_commit_message_is_not_related_to_updating_snapshots() - throws Exception { + public void should_not_revert_changes_when_commit_message_is_not_related_to_updating_snapshots() throws Exception { File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); diff --git a/releaser-core/src/test/java/releaser/internal/git/GitTestUtils.java b/releaser-core/src/test/java/releaser/internal/git/GitTestUtils.java index 6d2cc492..1a8d508e 100644 --- a/releaser-core/src/test/java/releaser/internal/git/GitTestUtils.java +++ b/releaser-core/src/test/java/releaser/internal/git/GitTestUtils.java @@ -53,8 +53,7 @@ public final class GitTestUtils { return new GitRepo.JGitFactory().open(project); } - public static File clonedProject(File baseDir, File projectToClone) - throws IOException { + public static File clonedProject(File baseDir, File projectToClone) throws IOException { GitRepo projectRepo = new GitRepo(baseDir); return projectRepo.cloneProject(new URIish(projectToClone.toURI().toURL())); } diff --git a/releaser-core/src/test/java/releaser/internal/git/ProjectGitHandlerTests.java b/releaser-core/src/test/java/releaser/internal/git/ProjectGitHandlerTests.java index 437d72e8..091c8aa7 100644 --- a/releaser-core/src/test/java/releaser/internal/git/ProjectGitHandlerTests.java +++ b/releaser-core/src/test/java/releaser/internal/git/ProjectGitHandlerTests.java @@ -19,10 +19,10 @@ package releaser.internal.git; import java.io.File; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import releaser.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; import releaser.internal.project.ProjectVersion; @@ -36,7 +36,7 @@ import static org.mockito.Mockito.never; /** * @author Marcin Grzejszczak */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ProjectGitHandlerTests { @Mock @@ -60,8 +60,7 @@ public class ProjectGitHandlerTests { @Test public void should_only_commit_without_pushing_changes_when_version_is_snapshot() { - this.updater.commitAndTagIfApplicable(this.file, - projectVersion("1.0.0.BUILD-SNAPSHOT")); + this.updater.commitAndTagIfApplicable(this.file, projectVersion("1.0.0.BUILD-SNAPSHOT")); then(this.gitRepo).should().commit(eq("Bumping versions")); then(this.gitRepo).should(never()).tag(anyString()); @@ -78,19 +77,16 @@ public class ProjectGitHandlerTests { @Test public void should_commit_when_snapshot_version_is_present_with_post_release_msg() { - ProjectVersion bumped = new ProjectVersion("name", - projectVersion("1.0.0.BUILD-SNAPSHOT").bumpedVersion()); + ProjectVersion bumped = new ProjectVersion("name", projectVersion("1.0.0.BUILD-SNAPSHOT").bumpedVersion()); this.updater.commitAfterBumpingVersions(this.file, bumped); - then(this.gitRepo).should() - .commit(eq("Bumping versions to 1.0.1.BUILD-SNAPSHOT after release")); + then(this.gitRepo).should().commit(eq("Bumping versions to 1.0.1.BUILD-SNAPSHOT after release")); then(this.gitRepo).should(never()).tag(anyString()); } @Test public void should_not_commit_when_non_snapshot_version_is_present() { - this.updater.commitAfterBumpingVersions(this.file, - projectVersion("1.0.0.RELEASE")); + this.updater.commitAfterBumpingVersions(this.file, projectVersion("1.0.0.RELEASE")); then(this.gitRepo).should(never()).commit(eq("Bumping versions after release")); then(this.gitRepo).should(never()).tag(anyString()); @@ -98,16 +94,14 @@ public class ProjectGitHandlerTests { @Test public void should_not_revert_changes_for_snapshots() { - this.updater.revertChangesIfApplicable(this.file, - projectVersion("1.0.0.BUILD-SNAPSHOT")); + this.updater.revertChangesIfApplicable(this.file, projectVersion("1.0.0.BUILD-SNAPSHOT")); then(this.gitRepo).should(never()).revert(anyString()); } @Test public void should_revert_changes_when_version_is_not_snapshot() { - this.updater.revertChangesIfApplicable(this.file, - projectVersion("1.0.0.RELEASE")); + this.updater.revertChangesIfApplicable(this.file, projectVersion("1.0.0.RELEASE")); then(this.gitRepo).should().revert(eq("Going back to snapshots")); } @@ -128,11 +122,8 @@ public class ProjectGitHandlerTests { @Test public void should_throw_exception_when_no_fixed_version_passed_for_the_project() { - BDDAssertions - .thenThrownBy( - () -> this.updater.cloneProjectFromOrg("spring-cloud-sleuth")) - .isInstanceOf(IllegalStateException.class) - .hasMessageContaining("You haven't provided a version"); + BDDAssertions.thenThrownBy(() -> this.updater.cloneProjectFromOrg("spring-cloud-sleuth")) + .isInstanceOf(IllegalStateException.class).hasMessageContaining("You haven't provided a version"); } @Test @@ -181,8 +172,7 @@ public class ProjectGitHandlerTests { @Test public void should_check_out_a_branch_if_it_exists_when_cloning_from_org_and_its_a_release_train_version_with_at_least_one_dash() { - this.properties.getFixedVersions().put("spring-cloud-release", - "Finchley-BUILD-SNAPSHOT"); + this.properties.getFixedVersions().put("spring-cloud-release", "Finchley-BUILD-SNAPSHOT"); given(this.gitRepo.hasBranch(anyString())).willReturn(false); given(this.gitRepo.hasBranch("Finchley")).willReturn(true); @@ -209,8 +199,7 @@ public class ProjectGitHandlerTests { given(this.gitRepo.hasBranch(anyString())).willReturn(true); given(this.gitRepo.hasBranch("2.3.x")).willReturn(false); - this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), - "2.3.4.RELEASE"); + this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.3.4.RELEASE"); then(this.gitRepo).should(never()).checkout("2.3.x"); } @@ -220,8 +209,7 @@ public class ProjectGitHandlerTests { given(this.gitRepo.hasBranch(anyString())).willReturn(false); given(this.gitRepo.hasBranch("2.3.x")).willReturn(true); - this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), - "2.3.4.RELEASE"); + this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.3.4.RELEASE"); then(this.gitRepo).should().checkout("2.3.x"); } @@ -241,8 +229,7 @@ public class ProjectGitHandlerTests { given(this.gitRepo.hasBranch(anyString())).willReturn(false); given(this.gitRepo.hasBranch("Finchley")).willReturn(true); - this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.0.0.RELEASE", - "Finchley.SR6"); + this.updater.cloneAndGuessBranch(new File(".").getAbsolutePath(), "2.0.0.RELEASE", "Finchley.SR6"); then(this.gitRepo).should(never()).checkout("2.0.0"); then(this.gitRepo).should().checkout("Finchley"); diff --git a/releaser-core/src/test/java/releaser/internal/github/GithubIssuesTests.java b/releaser-core/src/test/java/releaser/internal/github/GithubIssuesTests.java index b7965226..9dfde87f 100644 --- a/releaser-core/src/test/java/releaser/internal/github/GithubIssuesTests.java +++ b/releaser-core/src/test/java/releaser/internal/github/GithubIssuesTests.java @@ -16,6 +16,7 @@ package releaser.internal.github; +import java.io.File; import java.io.IOException; import java.util.Collections; @@ -23,32 +24,30 @@ import com.jcabi.github.Github; import com.jcabi.github.Repo; import com.jcabi.github.Repos; import com.jcabi.github.mock.MkGithub; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.BDDMockito; import releaser.internal.project.ProjectVersion; import releaser.internal.project.Projects; -import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.system.OutputCaptureExtension; /** * @author Marcin Grzejszczak */ +@ExtendWith(OutputCaptureExtension.class) public class GithubIssuesTests { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - - @Rule - public OutputCapture capture = new OutputCapture(); + @TempDir + public File folder; MkGithub github; Repo repo; - @Before + @BeforeEach public void setup() throws IOException { this.github = github("spring-guides"); this.repo = createGettingStartedGuides(this.github); @@ -73,7 +72,7 @@ public class GithubIssuesTests { new ProjectVersion("spring-cloud-build", "2.0.0.BUILD-SNAPSHOT")), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } @Test @@ -82,17 +81,15 @@ public class GithubIssuesTests { GithubIssues issues = new GithubIssues(Collections.emptyList()); issues.fileIssueInSpringGuides( - new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"), - new ProjectVersion("bar", "2.0.0.RELEASE"), + new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"), new ProjectVersion("bar", "2.0.0.RELEASE"), new ProjectVersion("baz", "3.0.0.RELEASE")), new ProjectVersion("sc-release", "Edgware.RELEASE")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } @Test - public void should_not_do_anything_for_non_release_train_version_when_updating_startspringio() - throws IOException { + public void should_not_do_anything_for_non_release_train_version_when_updating_startspringio() throws IOException { setupStartSpringIo(); Github github = BDDMockito.mock(Github.class); GithubIssues issues = new GithubIssues(Collections.emptyList()); @@ -102,28 +99,25 @@ public class GithubIssuesTests { new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE")), new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } @Test - public void should_not_do_anything_if_not_applicable_when_updating_startspringio() - throws IOException { + public void should_not_do_anything_if_not_applicable_when_updating_startspringio() throws IOException { setupStartSpringIo(); Github github = BDDMockito.mock(Github.class); GithubIssues issues = new GithubIssues(Collections.emptyList()); issues.fileIssueInStartSpringIo( - new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"), - new ProjectVersion("bar", "2.0.0.RELEASE"), + new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"), new ProjectVersion("bar", "2.0.0.RELEASE"), new ProjectVersion("baz", "3.0.0.RELEASE")), new ProjectVersion("sc-release", "Edgware.RELEASE")); - BDDMockito.then(github).shouldHaveZeroInteractions(); + BDDMockito.then(github).shouldHaveNoInteractions(); } private Repo createGettingStartedGuides(MkGithub github) throws IOException { - return github.repos() - .create(new Repos.RepoCreate("getting-started-guides", false)); + return github.repos().create(new Repos.RepoCreate("getting-started-guides", false)); } private Repo createStartSpringIo(MkGithub github) throws IOException { diff --git a/releaser-core/src/test/java/releaser/internal/github/GithubMilestonesTests.java b/releaser-core/src/test/java/releaser/internal/github/GithubMilestonesTests.java index 8f6c8044..9769030a 100644 --- a/releaser-core/src/test/java/releaser/internal/github/GithubMilestonesTests.java +++ b/releaser-core/src/test/java/releaser/internal/github/GithubMilestonesTests.java @@ -16,6 +16,7 @@ package releaser.internal.github; +import java.io.File; import java.io.IOException; import java.net.URL; @@ -23,14 +24,15 @@ import com.jcabi.github.Milestone; import com.jcabi.github.Repo; import com.jcabi.github.Repos; import com.jcabi.github.mock.MkGithub; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import releaser.internal.ReleaserProperties; import releaser.internal.project.ProjectVersion; -import org.springframework.boot.test.rule.OutputCapture; +import org.springframework.boot.test.system.CapturedOutput; +import org.springframework.boot.test.system.OutputCaptureExtension; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.BDDAssertions.thenThrownBy; @@ -38,26 +40,24 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy; /** * @author Marcin Grzejszczak */ +@ExtendWith(OutputCaptureExtension.class) public class GithubMilestonesTests { - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - - @Rule - public OutputCapture capture = new OutputCapture(); + @TempDir + public File folder; MkGithub github; Repo repo; - @Before + @BeforeEach public void setup() throws IOException { this.github = new MkGithub(); this.repo = createSleuthRepo(this.github); } @Test - public void should_close_milestone_if_there_is_one() throws IOException { + public void should_close_milestone_if_there_is_one(CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override String org() { @@ -73,12 +73,12 @@ public class GithubMilestonesTests { milestones.closeMilestone(nonGaSleuthProject()); - then(this.capture.toString()).doesNotContain("No matching milestone was found"); + then(capture.toString()).doesNotContain("No matching milestone was found"); } @Test - public void should_close_milestone_when_the_milestone_contains_numeric_version_only_and_version_is_ga() - throws IOException { + public void should_close_milestone_when_the_milestone_contains_numeric_version_only_and_version_is_ga( + CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override String org() { @@ -94,7 +94,7 @@ public class GithubMilestonesTests { milestones.closeMilestone(gaSleuthProject()); - then(this.capture.toString()).doesNotContain("No matching milestone was found"); + then(capture.toString()).doesNotContain("No matching milestone was found"); } private ProjectVersion gaSleuthProject() { @@ -102,7 +102,7 @@ public class GithubMilestonesTests { } @Test - public void should_not_close_milestone_when_the_milestone_contains_numeric_version_only() + public void should_not_close_milestone_when_the_milestone_contains_numeric_version_only(CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override @@ -119,7 +119,7 @@ public class GithubMilestonesTests { milestones.closeMilestone(nonGaSleuthProject()); - then(this.capture.toString()).contains("No matching milestone was found"); + then(capture.toString()).contains("No matching milestone was found"); } @Test @@ -137,16 +137,14 @@ public class GithubMilestonesTests { @Override URL foundMilestoneUrl(Milestone.Smart milestone) throws IOException { - return new URL( - "https://api.github.com/repos/spring-cloud/spring-cloud-sleuth/milestones/33"); + return new URL("https://api.github.com/repos/spring-cloud/spring-cloud-sleuth/milestones/33"); } }; this.repo.milestones().create("0.2.0.RELEASE"); String url = milestones.milestoneUrl(gaSleuthProject()); - then(url).isEqualTo( - "https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1"); + then(url).isEqualTo("https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1"); } @Test @@ -157,8 +155,7 @@ public class GithubMilestonesTests { String url = milestones.milestoneUrl(gaSleuthProject()); - then(url).isEqualTo( - "https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1"); + then(url).isEqualTo("https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1"); } @Test @@ -186,7 +183,7 @@ public class GithubMilestonesTests { } @Test - public void should_return_null_if_no_matching_milestone_was_found_within_threshold() + public void should_return_null_if_no_matching_milestone_was_found_within_threshold(CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withThreshold()) { @Override @@ -203,8 +200,7 @@ public class GithubMilestonesTests { milestones.closeMilestone(gaSleuthProject()); - then(this.capture.toString()).contains( - "No matching milestones were found within the provided threshold [0]"); + then(capture.toString()).contains("No matching milestones were found within the provided threshold [0]"); } private ProjectVersion nonGaSleuthProject() { @@ -212,8 +208,7 @@ public class GithubMilestonesTests { } @Test - public void should_throw_exception_when_there_is_no_matching_milestone() - throws IOException { + public void should_throw_exception_when_there_is_no_matching_milestone(CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override String org() { @@ -228,11 +223,11 @@ public class GithubMilestonesTests { this.repo.milestones().create("v0.2.0.BUILD-SNAPSHOT"); milestones.closeMilestone(nonGaSleuthProject()); - then(this.capture.toString()).contains("No matching milestone was found"); + then(capture.toString()).contains("No matching milestone was found"); } @Test - public void should_print_that_no_milestones_were_found_when_io_problems_occurred() + public void should_print_that_no_milestones_were_found_when_io_problems_occurred(CapturedOutput capture) throws IOException { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override @@ -249,7 +244,7 @@ public class GithubMilestonesTests { milestones.closeMilestone(nonGaSleuthProject()); - then(this.capture.toString()).contains("No matching milestone was found"); + then(capture.toString()).contains("No matching milestone was found"); } private Repo createSleuthRepo(MkGithub github) throws IOException { @@ -260,8 +255,7 @@ public class GithubMilestonesTests { public void should_throw_exception_when_no_token_was_passed() { GithubMilestones milestones = new GithubMilestones(new ReleaserProperties()); - thenThrownBy(() -> milestones.closeMilestone(nonGaSleuthProject())) - .isInstanceOf(IllegalArgumentException.class) + thenThrownBy(() -> milestones.closeMilestone(nonGaSleuthProject())).isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("You must set the value of the OAuth token"); } diff --git a/releaser-core/src/test/java/releaser/internal/gradle/GradleUpdaterTests.java b/releaser-core/src/test/java/releaser/internal/gradle/GradleUpdaterTests.java index 503590a4..0ad4d4c8 100644 --- a/releaser-core/src/test/java/releaser/internal/gradle/GradleUpdaterTests.java +++ b/releaser-core/src/test/java/releaser/internal/gradle/GradleUpdaterTests.java @@ -23,10 +23,9 @@ import java.nio.file.Files; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import releaser.internal.ReleaserProperties; import releaser.internal.buildsystem.GradleUpdater; import releaser.internal.project.ProjectVersion; @@ -42,14 +41,14 @@ import static org.assertj.core.api.BDDAssertions.thenThrownBy; */ public class GradleUpdaterTests { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + public File tmp; File temporaryFolder; - @Before + @BeforeEach public void setup() throws Exception { - this.temporaryFolder = this.tmp.newFolder(); + this.temporaryFolder = new File(tmp, "test.txt"); FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder); } @@ -64,16 +63,14 @@ public class GradleUpdaterTests { } }; properties.getGradle().setGradlePropsSubstitution(props); - Projects projects = new Projects( - new ProjectVersion("spring-cloud-contract", "1.0.0"), + Projects projects = new Projects(new ProjectVersion("spring-cloud-contract", "1.0.0"), new ProjectVersion("spring-cloud-sleuth", "2.0.0")); - new GradleUpdater().updateProjectFromReleaseTrain(properties, projectRoot, - projects, new ProjectVersion("spring-cloud-contract", "1.0.0"), true); + new GradleUpdater().updateProjectFromReleaseTrain(properties, projectRoot, projects, + new ProjectVersion("spring-cloud-contract", "1.0.0"), true); then(asString(tmpFile("gradleproject/gradle.properties"))).contains("foo=1.0.0"); - then(asString(tmpFile("gradleproject/child/gradle.properties"))) - .contains("bar=2.0.0"); + then(asString(tmpFile("gradleproject/child/gradle.properties"))).contains("bar=2.0.0"); } @Test @@ -87,15 +84,12 @@ public class GradleUpdaterTests { } }; properties.getGradle().setGradlePropsSubstitution(props); - Projects projects = new Projects( - new ProjectVersion("spring-cloud-contract", "1.0.0.BUILD-SNAPSHOT"), + Projects projects = new Projects(new ProjectVersion("spring-cloud-contract", "1.0.0.BUILD-SNAPSHOT"), new ProjectVersion("spring-cloud-sleuth", "2.0.0")); - thenThrownBy(() -> new GradleUpdater().updateProjectFromReleaseTrain(properties, - projectRoot, projects, + thenThrownBy(() -> new GradleUpdater().updateProjectFromReleaseTrain(properties, projectRoot, projects, new ProjectVersion("spring-cloud-contract", "1.0.0.RELEASE"), true)) - .hasMessageContaining( - "(BUILD-)?SNAPSHOT.*$] pattern in line number [1]"); + .hasMessageContaining("(BUILD-)?SNAPSHOT.*$] pattern in line number [1]"); } private File file(String relativePath) throws URISyntaxException { 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 5374f995..8dba0d44 100644 --- a/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java +++ b/releaser-core/src/test/java/releaser/internal/postrelease/PostReleaseActionsTests.java @@ -30,11 +30,10 @@ import org.assertj.core.api.BDDAssertions; import org.awaitility.Awaitility; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.revwalk.RevCommit; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.mockito.BDDMockito; import releaser.SpringCloudReleaserProperties; import releaser.internal.PomUpdateAcceptanceTests; @@ -60,8 +59,8 @@ import org.springframework.util.LinkedMultiValueMap; */ public class PostReleaseActionsTests { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); + @TempDir + File tmp; File temporaryFolder; @@ -114,9 +113,9 @@ public class PostReleaseActionsTests { return new VersionsFetcher(properties, updater); } - @Before + @BeforeEach public void setup() throws Exception { - this.temporaryFolder = this.tmp.newFolder(); + this.temporaryFolder = new File(tmp, "test.txt"); TestUtils.prepareLocalRepo(); FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder); } @@ -124,27 +123,25 @@ public class PostReleaseActionsTests { @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.runUpdatedTests(currentGa()); BDDAssertions.then(this.cloned).isNull(); - BDDMockito.then(this.gradleUpdater).shouldHaveZeroInteractions(); + BDDMockito.then(this.gradleUpdater).shouldHaveNoInteractions(); } @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.runUpdatedTests(currentGa()); BDDAssertions.then(this.cloned).isNull(); - BDDMockito.then(this.gradleUpdater).shouldHaveZeroInteractions(); + BDDMockito.then(this.gradleUpdater).shouldHaveNoInteractions(); } @Test @@ -153,12 +150,11 @@ public class PostReleaseActionsTests { properties.getMetaRelease().setEnabled(true); properties.getGit().setRunUpdatedSamples(true); properties.getGit().setUpdateAllTestSamples(true); - properties.getGit().setTestSamplesProjectUrl( - tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); + properties.getGit().setTestSamplesProjectUrl(tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); properties.getMaven().setBuildCommand("touch build.log"); PostReleaseActions actions = new PostReleaseActions(projectGitHandler(properties), - projectPomUpdater(properties), this.gradleUpdater, commandExecutor, - properties, fetcher(properties), releaserPropertiesUpdater) { + projectPomUpdater(properties), this.gradleUpdater, commandExecutor, properties, fetcher(properties), + releaserPropertiesUpdater) { @Override ReleaserProperties projectProps(File file) { return properties; @@ -177,17 +173,15 @@ public class PostReleaseActionsTests { private void thenGradleUpdaterWasCalled() { BDDMockito.then(this.gradleUpdater).should().updateProjectFromReleaseTrain( - BDDMockito.any(ReleaserProperties.class), BDDMockito.any(File.class), - BDDMockito.any(Projects.class), BDDMockito.any(ProjectVersion.class), - BDDMockito.eq(false)); + BDDMockito.any(ReleaserProperties.class), BDDMockito.any(File.class), BDDMockito.any(Projects.class), + BDDMockito.any(ProjectVersion.class), BDDMockito.eq(false)); } @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); @@ -197,25 +191,22 @@ public class PostReleaseActionsTests { @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); BDDAssertions.then(this.cloned).isNull(); } - @Ignore("flakey on circle") + @Disabled("flakey on circle") @Test public void should_update_project_and_run_tests_and_release_train_docs_generation_is_called() { this.properties.getMetaRelease().setEnabled(true); - this.properties.getGit().setReleaseTrainDocsUrl( - tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); + this.properties.getGit().setReleaseTrainDocsUrl(tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"); this.properties.getMaven().setGenerateReleaseTrainDocsCommand("./test.sh"); - PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.generateReleaseTrainDocumentation(currentGa()); @@ -230,43 +221,38 @@ public class PostReleaseActionsTests { @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.updateAllTestSamples(currentGa()); BDDAssertions.then(this.cloned).isNull(); - BDDMockito.then(this.gradleUpdater).shouldHaveZeroInteractions(); + BDDMockito.then(this.gradleUpdater).shouldHaveNoInteractions(); } @Test 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.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.updateAllTestSamples(currentGa()); BDDAssertions.then(this.cloned).isNull(); - BDDMockito.then(this.gradleUpdater).shouldHaveZeroInteractions(); + BDDMockito.then(this.gradleUpdater).shouldHaveNoInteractions(); } @Test - public void should_update_test_sample_projects_when_test_samples_update_is_called() - throws Exception { + public void should_update_test_sample_projects_when_test_samples_update_is_called() throws Exception { ReleaserProperties properties = SpringCloudReleaserProperties.get(); properties.getMetaRelease().setEnabled(true); properties.getGit().setUpdateAllTestSamples(true); properties.getGit().getAllTestSampleUrls().clear(); properties.getGit().getAllTestSampleUrls().put("spring-cloud-sleuth", - Collections.singletonList( - tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/")); + Collections.singletonList(tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/")); AtomicReference postReleaseProjects = new AtomicReference<>(); - PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.commandExecutor, properties, - versionsFetcher, releaserPropertiesUpdater) { + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, properties, versionsFetcher, releaserPropertiesUpdater) { @Override Projects getPostReleaseProjects(Projects projects) { postReleaseProjects.set(super.getPostReleaseProjects(projects)); @@ -280,37 +266,31 @@ public class PostReleaseActionsTests { .filter(s -> s.getKey().contains("spring-cloud-core-tests")).findFirst() .orElseThrow(() -> new IllegalStateException("Not found")); File clonedFile = entry.getValue().get(0); - Model pomWithCloud = PomReader - .readPom(new File(clonedFile, "zuul-proxy-eureka/pom.xml")); + Model pomWithCloud = PomReader.readPom(new File(clonedFile, "zuul-proxy-eureka/pom.xml")); Git git = GitTestUtils.openGitProject(clonedFile); - BDDAssertions - .then(pomWithCloud.getProperties().getProperty("spring-cloud.version")) + BDDAssertions.then(pomWithCloud.getProperties().getProperty("spring-cloud.version")) .isEqualTo("Finchley.SNAPSHOT"); - BDDAssertions.then(pomWithCloud.getParent().getVersion()) - .isEqualTo("2.0.4.RELEASE"); + BDDAssertions.then(pomWithCloud.getParent().getVersion()).isEqualTo("2.0.4.RELEASE"); Iterator iterator = git.log().call().iterator(); RevCommit commit = iterator.next(); BDDAssertions.then(commit.getShortMessage()).isEqualTo( "Updated versions after [Finchley.SR1] release train and [2.0.1.RELEASE] [spring-cloud-sleuth] project release"); thenGradleUpdaterWasCalled(); - BDDAssertions.then( - postReleaseProjects.get().forName("spring-boot-dependencies").version) + BDDAssertions.then(postReleaseProjects.get().forName("spring-boot-dependencies").version) .isEqualTo("2.0.4.RELEASE"); } @Test - public void should_assume_that_project_version_is_snapshot_when_no_pom_is_present() - throws Exception { + public void should_assume_that_project_version_is_snapshot_when_no_pom_is_present() throws Exception { ReleaserProperties properties = SpringCloudReleaserProperties.get(); properties.getMetaRelease().setEnabled(true); properties.getGit().setUpdateAllTestSamples(true); properties.getGit().getAllTestSampleUrls().clear(); - properties.getGit().getAllTestSampleUrls().put("spring-cloud-sleuth", Collections - .singletonList(tmpFile("spring-cloud-static/").getAbsolutePath() + "/")); + properties.getGit().getAllTestSampleUrls().put("spring-cloud-sleuth", + Collections.singletonList(tmpFile("spring-cloud-static/").getAbsolutePath() + "/")); AtomicReference postReleaseProjects = new AtomicReference<>(); - PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.commandExecutor, properties, - versionsFetcher, releaserPropertiesUpdater) { + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, properties, versionsFetcher, releaserPropertiesUpdater) { @Override Projects getPostReleaseProjects(Projects projects) { postReleaseProjects.set(super.getPostReleaseProjects(projects)); @@ -320,8 +300,7 @@ public class PostReleaseActionsTests { actions.updateAllTestSamples(currentGa()); - this.clonedTestProjects.entrySet().stream() - .filter(s -> s.getKey().contains("spring-cloud-static")).findFirst() + this.clonedTestProjects.entrySet().stream().filter(s -> s.getKey().contains("spring-cloud-static")).findFirst() .orElseThrow(() -> new IllegalStateException("Not found")); } @@ -329,14 +308,13 @@ public class PostReleaseActionsTests { public void should_do_nothing_when_guides_are_turned_off() { this.properties.getGit().setUpdateSpringGuides(false); VersionsFetcher versionsFetcher = BDDMockito.mock(VersionsFetcher.class); - PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, - this.updater, this.gradleUpdater, this.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater); + PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater); actions.deployGuides(Collections.emptyList()); BDDAssertions.then(this.cloned).isNull(); - BDDMockito.then(versionsFetcher).shouldHaveZeroInteractions(); + BDDMockito.then(versionsFetcher).shouldHaveNoInteractions(); } @Test @@ -348,33 +326,29 @@ public class PostReleaseActionsTests { BDDMockito.given(versionsFetcher.isLatestGa(BDDMockito.any())).willReturn(true); AtomicReference projectBuilderStub = new AtomicReference<>(); ProjectGitHandler handler = BDDMockito.mock(ProjectGitHandler.class); - ProjectCommandExecutor projectCommandExecutor = BDDMockito - .mock(ProjectCommandExecutor.class); - PostReleaseActions actions = new PostReleaseActions(handler, this.updater, - this.gradleUpdater, this.commandExecutor, this.properties, - versionsFetcher, releaserPropertiesUpdater) { + ProjectCommandExecutor projectCommandExecutor = BDDMockito.mock(ProjectCommandExecutor.class); + PostReleaseActions actions = new PostReleaseActions(handler, this.updater, this.gradleUpdater, + this.commandExecutor, this.properties, versionsFetcher, releaserPropertiesUpdater) { @Override ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) { projectBuilderStub.set(projectCommandExecutor); return projectCommandExecutor; } }; - ProjectVersion projectVersion = new ProjectVersion( - new File(projects, "spring-cloud-release")); + ProjectVersion projectVersion = new ProjectVersion(new File(projects, "spring-cloud-release")); - actions.deployGuides(Collections.singletonList( - new ProcessedProject(this.properties, projectVersion, projectVersion))); + actions.deployGuides( + Collections.singletonList(new ProcessedProject(this.properties, projectVersion, projectVersion))); Awaitility.await().untilAsserted(() -> { BDDAssertions.then(projectBuilderStub.get()).isNotNull(); - BDDMockito.then(projectBuilderStub.get()).should() - .deployGuides(this.properties, projectVersion, projectVersion); + BDDMockito.then(projectBuilderStub.get()).should().deployGuides(this.properties, projectVersion, + projectVersion); }); } private String sleuthParentPomVersion() { - return PomReader.readPom(new File(this.cloned, "sleuth/pom.xml")).getParent() - .getVersion(); + return PomReader.readPom(new File(this.cloned, "sleuth/pom.xml")).getParent().getVersion(); } Projects currentGa() { 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 028d0d1f..3525002e 100644 --- a/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java +++ b/releaser-core/src/test/java/releaser/internal/project/ProjectCommandExecutorTests.java @@ -25,40 +25,35 @@ import java.net.URISyntaxException; import java.nio.file.Files; import java.util.concurrent.TimeoutException; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.zeroturnaround.exec.ProcessExecutor; import org.zeroturnaround.exec.ProcessResult; import releaser.internal.PomUpdateAcceptanceTests; import releaser.internal.ReleaserProperties; import releaser.internal.buildsystem.TestUtils; -import org.springframework.boot.test.rule.OutputCapture; import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.BDDAssertions.then; import static org.assertj.core.api.BDDAssertions.thenThrownBy; +import static org.junit.jupiter.api.Assumptions.assumeFalse; /** * @author Marcin Grzejszczak */ public class ProjectCommandExecutorTests { - @Rule - public TemporaryFolder tmp = new TemporaryFolder(); - - @Rule - public OutputCapture outputCapture = new OutputCapture(); + @TempDir + public File tmp; File temporaryFolder; - @Before + @BeforeEach public void checkOs() throws Exception { - Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); - this.temporaryFolder = this.tmp.newFolder(); + assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win")); + this.temporaryFolder = new File(tmp, "test"); TestUtils.prepareLocalRepo(); FileSystemUtils.copyRecursively(file("/projects"), this.temporaryFolder); } @@ -80,32 +75,26 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("resolved.log"); } @Test - public void should_successfully_execute_a_command_when_path_is_provided_explicitly() - throws Exception { + public void should_successfully_execute_a_command_when_path_is_provided_explicitly() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("ls -al"); properties.setWorkingDir(new File("/foo/bar").getAbsolutePath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"))) - .contains("resolved.log"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("resolved.log"); } @Test - public void should_successfully_execute_a_build_command_for_milestone_version() - throws Exception { + public void should_successfully_execute_a_build_command_for_milestone_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -117,8 +106,7 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_build_command_for_rc_version() - throws Exception { + public void should_successfully_execute_a_build_command_for_rc_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -126,13 +114,11 @@ public class ProjectCommandExecutorTests { builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); - then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") - .doesNotContain("-Pguides"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo").doesNotContain("-Pguides"); } @Test - public void should_successfully_execute_a_build_command_for_release_version() - throws Exception { + public void should_successfully_execute_a_build_command_for_release_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -144,8 +130,7 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_build_command_for_sr_version() - throws Exception { + public void should_successfully_execute_a_build_command_for_sr_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -157,19 +142,16 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_command_when_system_props_placeholder_is_present() - throws Exception { + public void should_successfully_execute_a_command_when_system_props_placeholder_is_present() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setBuildCommand("echo {{systemProps}}"); properties.getBash().setSystemProperties("-Dhello=world -Dfoo=bar"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("-Dhello=world -Dfoo=bar"); } @Test @@ -180,8 +162,7 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); } @@ -195,11 +176,9 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("hello=world foo=bar"); } @Test @@ -211,11 +190,9 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("-Dhello=world -Dfoo=bar bar"); } @Test @@ -227,11 +204,9 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.build(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("bar -Dhello=world -Dfoo=bar"); } @Test @@ -241,9 +216,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.build(properties, original(), - new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( - "contains a tag that wasn't resolved properly"); + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))) + .hasMessageContaining("contains a tag that wasn't resolved properly"); } @Test @@ -254,9 +228,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.build(properties, original(), - new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( - "Process waiting time of [0] minutes exceeded"); + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))) + .hasMessageContaining("Process waiting time of [0] minutes exceeded"); } @Test @@ -266,16 +239,13 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("resolved.log"); } @Test - public void should_successfully_execute_a_deploy_command_for_milestone_version() - throws Exception { + public void should_successfully_execute_a_deploy_command_for_milestone_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setDeployCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -283,90 +253,76 @@ public class ProjectCommandExecutorTests { builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1")); - then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") - .doesNotContain("-Pguides"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo").doesNotContain("-Pguides"); } @Test - public void should_successfully_execute_a_deploy_command_for_milestone_version_for_maven() - throws Exception { + public void should_successfully_execute_a_deploy_command_for_milestone_version_for_maven() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setDeployCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); - new ReleaserProcessExecutor(properties.getWorkingDir()) - .runCommand(new String[] { "touch", "pom.xml" }, 1); + new ReleaserProcessExecutor(properties.getWorkingDir()).runCommand(new String[] { "touch", "pom.xml" }, 1); ProjectCommandExecutor builder = projectBuilder(properties); builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1")); - then(asString(tmpFile("/builder/resolved/resolved.log"))) - .contains("foo -Pmilestone").doesNotContain("-Pguides"); - } - - @Test - public void should_successfully_execute_a_deploy_command_for_rc_version() - throws Exception { - ReleaserProperties properties = new ReleaserProperties(); - properties.getBash().setDeployCommand("echo foo"); - properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); - ProjectCommandExecutor builder = projectBuilder(properties); - - builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); - - then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo") + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo -Pmilestone") .doesNotContain("-Pguides"); } @Test - public void should_successfully_execute_a_deploy_command_for_rc_version_for_maven() - throws Exception { - ReleaserProperties properties = new ReleaserProperties(); - properties.getMaven().setDeployCommand("echo foo"); - properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); - new ReleaserProcessExecutor(properties.getWorkingDir()) - .runCommand(new String[] { "touch", "pom.xml" }, 1); - ProjectCommandExecutor builder = projectBuilder(properties); - - builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); - - then(asString(tmpFile("/builder/resolved/resolved.log"))) - .contains("foo -Pmilestone").doesNotContain("-Pguides"); - } - - @Test - public void should_successfully_execute_a_deploy_command_for_release_version() - throws Exception { + public void should_successfully_execute_a_deploy_command_for_rc_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setDeployCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(properties, original(), - new ProjectVersion("foo", "1.0.0.RELEASE")); + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); + + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo").doesNotContain("-Pguides"); + } + + @Test + public void should_successfully_execute_a_deploy_command_for_rc_version_for_maven() throws Exception { + ReleaserProperties properties = new ReleaserProperties(); + properties.getMaven().setDeployCommand("echo foo"); + properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); + new ReleaserProcessExecutor(properties.getWorkingDir()).runCommand(new String[] { "touch", "pom.xml" }, 1); + ProjectCommandExecutor builder = projectBuilder(properties); + + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1")); + + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo -Pmilestone") + .doesNotContain("-Pguides"); + } + + @Test + public void should_successfully_execute_a_deploy_command_for_release_version() throws Exception { + ReleaserProperties properties = new ReleaserProperties(); + properties.getBash().setDeployCommand("echo foo"); + properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); + ProjectCommandExecutor builder = projectBuilder(properties); + + builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RELEASE")); then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo"); } @Test - public void should_successfully_execute_a_deploy_command_for_release_version_for_maven() - throws Exception { + public void should_successfully_execute_a_deploy_command_for_release_version_for_maven() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setDeployCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); - new ReleaserProcessExecutor(properties.getWorkingDir()) - .runCommand(new String[] { "touch", "pom.xml" }, 1); + new ReleaserProcessExecutor(properties.getWorkingDir()).runCommand(new String[] { "touch", "pom.xml" }, 1); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo -Pcentral"); } @Test - public void should_successfully_execute_a_deploy_command_for_sr_version() - throws Exception { + public void should_successfully_execute_a_deploy_command_for_sr_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setDeployCommand("echo foo"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -378,19 +334,16 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() - throws Exception { + public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setDeployCommand("echo \"{{systemProps}}\""); properties.getBash().setSystemProperties("-Dhello=hello-world"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("-Dhello=hello-world"); } @Test @@ -402,11 +355,9 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - builder.deploy(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("-Dhello=hello-world"); } @Test @@ -417,16 +368,14 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.deploy(properties, original(), - new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( - "Process waiting time of [0] minutes exceeded"); + thenThrownBy(() -> builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))) + .hasMessageContaining("Process waiting time of [0] minutes exceeded"); } @Test public void should_successfully_execute_a_publish_docs_command() throws Exception { ReleaserProperties properties = new ReleaserProperties(); - properties.getBash().setPublishDocsCommand( - "ls -al && echo {{version}} {{oldVersion}} {{nextVersion}}"); + properties.getBash().setPublishDocsCommand("ls -al && echo {{version}} {{oldVersion}} {{nextVersion}}"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); ProjectCommandExecutor builder = new ProjectCommandExecutor() { @@ -436,8 +385,7 @@ public class ProjectCommandExecutorTests { } }; - builder.publishDocs(properties, 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"); @@ -445,11 +393,9 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder() - throws Exception { + public void should_successfully_execute_a_publish_docs_command_with_sys_props_placeholder() throws Exception { ReleaserProperties properties = new ReleaserProperties(); - properties.getBash().setPublishDocsCommand( - "echo {{systemProps}} 1 && echo {{systemProps}} 2"); + properties.getBash().setPublishDocsCommand("echo {{systemProps}} 1 && echo {{systemProps}} 2"); properties.getBash().setSystemProperties("-Dhello=world -Dfoo=bar"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir()); @@ -460,8 +406,7 @@ public class ProjectCommandExecutorTests { } }; - builder.publishDocs(properties, original(), - new ProjectVersion("foo", "Finchley.RELEASE")); + builder.publishDocs(properties, original(), new ProjectVersion("foo", "Finchley.RELEASE")); String s = asString(tmpFile("/builder/resolved/resolved.log")); System.out.println("====> " + s); @@ -470,8 +415,7 @@ public class ProjectCommandExecutorTests { } @Test - public void should_successfully_execute_a_publish_docs_command_and_substitute_the_version() - throws Exception { + public void should_successfully_execute_a_publish_docs_command_and_substitute_the_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setPublishDocsCommand("echo '{{version}}'"); properties.setWorkingDir(tmpFile("/builder/resolved").getPath()); @@ -483,16 +427,13 @@ public class ProjectCommandExecutorTests { } }; - builder.publishDocs(properties, 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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("1.1.0.RELEASE"); } @Test - public void should_successfully_execute_an_update_docs_command_and_substitute_the_version() - throws Exception { + public void should_successfully_execute_an_update_docs_command_and_substitute_the_version() throws Exception { ReleaserProperties properties = new ReleaserProperties(); properties.getBash().setGenerateReleaseTrainDocsCommand("echo '{{version}}'"); File resolved = tmpFile("/builder/resolved"); @@ -505,11 +446,9 @@ public class ProjectCommandExecutorTests { } }; - builder.generateReleaseTrainDocs(properties, "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"); + then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("1.1.0.RELEASE"); } @Test @@ -520,9 +459,8 @@ public class ProjectCommandExecutorTests { properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); ProjectCommandExecutor builder = projectBuilder(properties); - thenThrownBy(() -> builder.publishDocs(properties, original(), - new ProjectVersion("foo", "1.0.0.RELEASE"))).hasMessageContaining( - "Process waiting time of [0] minutes exceeded"); + thenThrownBy(() -> builder.publishDocs(properties, original(), new ProjectVersion("foo", "1.0.0.RELEASE"))) + .hasMessageContaining("Process waiting time of [0] minutes exceeded"); } @Test @@ -543,9 +481,8 @@ public class ProjectCommandExecutorTests { } }; - thenThrownBy(() -> builder.build(properties, original(), - new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining( - "The process has exited with exit code [1]"); + thenThrownBy(() -> builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))) + .hasMessageContaining("The process has exited with exit code [1]"); } private TestReleaserProcessExecutor testExecutor(String workingDir) { @@ -579,14 +516,12 @@ public class ProjectCommandExecutorTests { @Override ProcessExecutor processExecutor(String[] commands, String workingDir) { this.counter++; - final ProcessExecutor processExecutor = super.processExecutor(commands, - workingDir); + final ProcessExecutor processExecutor = super.processExecutor(commands, workingDir); File tempFile = tmpFile("/builder/resolved/resolved.log"); try { tempFile.createNewFile(); - OutputStream fos = new BufferedOutputStream( - new FileOutputStream(tempFile)); + OutputStream fos = new BufferedOutputStream(new FileOutputStream(tempFile)); return processExecutor // use redirectOutputAlsoTo to avoid overriding all output diff --git a/releaser-core/src/test/java/releaser/internal/sagan/RestTemplateSaganClientTests.java b/releaser-core/src/test/java/releaser/internal/sagan/RestTemplateSaganClientTests.java index 002b6bf5..b309dcd1 100644 --- a/releaser-core/src/test/java/releaser/internal/sagan/RestTemplateSaganClientTests.java +++ b/releaser-core/src/test/java/releaser/internal/sagan/RestTemplateSaganClientTests.java @@ -21,10 +21,9 @@ import java.util.Arrays; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import releaser.internal.ReleaserProperties; import org.springframework.beans.factory.annotation.Autowired; @@ -34,7 +33,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.BDDAssertions.then; @@ -42,7 +40,6 @@ import static org.assertj.core.api.BDDAssertions.then; /** * @author Marcin Grzejszczak */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = RestTemplateSaganClientTests.Config.class) @AutoConfigureStubRunner(ids = "sagan:sagan-site") public class RestTemplateSaganClientTests { @@ -55,7 +52,7 @@ public class RestTemplateSaganClientTests { SaganClient client; - @Before + @BeforeEach public void setup() { ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setOauthToken("foo"); @@ -64,14 +61,13 @@ public class RestTemplateSaganClientTests { } @Test - @Ignore("2 stubs point to the same endpoint") + @Disabled("2 stubs point to the same endpoint") public void should_get_a_project() { Project project = this.client.getProject("spring-framework"); then(project.id).isEqualTo("spring-framework"); then(project.name).isEqualTo("Spring Framework"); - then(project.repoUrl) - .isEqualTo("https://github.com/spring-projects/spring-framework"); + then(project.repoUrl).isEqualTo("https://github.com/spring-projects/spring-framework"); then(project.siteUrl).isEqualTo("https://projects.spring.io/spring-framework"); then(project.category).isEqualTo("active"); then(project.stackOverflowTags).isNotBlank(); @@ -80,10 +76,8 @@ public class RestTemplateSaganClientTests { then(project.projectReleases).isNotEmpty(); Release release = project.projectReleases.get(0); then(release.releaseStatus).isEqualTo("PRERELEASE"); - then(release.refDocUrl).isEqualTo( - "http://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/"); - then(release.apiDocUrl) - .isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/javadoc-api/"); + then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/spring-framework-reference/"); + then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/5.0.0.RC4/javadoc-api/"); then(release.groupId).isEqualTo("org.springframework"); then(release.artifactId).isEqualTo("spring-context"); then(release.repository.id).isEqualTo("spring-milestones"); @@ -103,10 +97,8 @@ public class RestTemplateSaganClientTests { Release release = this.client.getRelease("spring-framework", "5.0.0.RC4"); then(release.releaseStatus).isEqualTo("PRERELEASE"); - then(release.refDocUrl).isEqualTo( - "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/"); - then(release.apiDocUrl) - .isEqualTo("http://docs.spring.io/spring/docs/{version}/javadoc-api/"); + then(release.refDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/spring-framework-reference/"); + then(release.apiDocUrl).isEqualTo("http://docs.spring.io/spring/docs/{version}/javadoc-api/"); then(release.groupId).isEqualTo("org.springframework"); then(release.artifactId).isEqualTo("spring-context"); then(release.repository.id).isEqualTo("spring-milestones"); @@ -186,8 +178,8 @@ public class RestTemplateSaganClientTests { sithRelease.refDocUrl = "http://docs.spring.io/spring/docs/{version}/spring-framework-reference/htmlsingle/"; sithRelease.apiDocUrl = "http://docs.spring.io/spring/docs/{version}/javadoc-api/"; - List updates = Arrays.asList(firstRelease, secondRelease, - thirdRelease, fourthRelease, fithRelease, sithRelease); + List updates = Arrays.asList(firstRelease, secondRelease, thirdRelease, fourthRelease, + fithRelease, sithRelease); Project project = this.client.updateRelease("spring-framework", updates); @@ -237,8 +229,7 @@ public class RestTemplateSaganClientTests { } private RestTemplate restTemplate(ReleaserProperties properties) { - return new RestTemplateBuilder() - .basicAuthentication(properties.getGit().getOauthToken(), "").build(); + return new RestTemplateBuilder().basicAuthentication(properties.getGit().getOauthToken(), "").build(); } @Configuration diff --git a/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterOldDocsTest.java b/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterOldDocsTest.java index 193c40c6..726bff5c 100644 --- a/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterOldDocsTest.java +++ b/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterOldDocsTest.java @@ -24,8 +24,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.BDDMockito; import org.mockito.Mockito; @@ -51,11 +51,11 @@ public class SaganUpdaterOldDocsTest { Projects projects = new Projects(); - @Before + @BeforeEach public void setup() { Project project = new Project(); - project.projectReleases.addAll(Arrays.asList(release("1.0.0.RC1"), - release("1.1.0.BUILD-SNAPSHOT"), release("2.0.0.M4"))); + project.projectReleases + .addAll(Arrays.asList(release("1.0.0.RC1"), release("1.1.0.BUILD-SNAPSHOT"), release("2.0.0.M4"))); BDDMockito.given(this.saganClient.getProject(anyString())).willReturn(project); this.properties.getSagan().setUpdateSagan(true); this.saganUpdater = new SaganUpdater(this.saganClient, this.properties); @@ -72,44 +72,37 @@ public class SaganUpdaterOldDocsTest { public void should_not_update_sagan_when_switch_is_off() { this.properties.getSagan().setUpdateSagan(false); - this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), - version("2.2.0.M1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), version("2.2.0.M1"), projects); - then(this.saganClient).shouldHaveZeroInteractions(); + then(this.saganClient).shouldHaveNoInteractions(); } @Test public void should_update_sagan_releases_for_milestone() { - this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.M1"), - version("1.0.0.M1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.M1"), version("1.0.0.M1"), projects); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("1.0.0.M1", - "https://cloud.spring.io/spring-cloud-static/foo/{version}/", - "PRERELEASE"))); + "https://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE"))); } @Test public void should_update_sagan_releases_for_rc() { - this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.RC1"), - version("1.0.0.RC1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.RC1"), version("1.0.0.RC1"), projects); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("1.0.0.RC1", - "https://cloud.spring.io/spring-cloud-static/foo/{version}/", - "PRERELEASE"))); + "https://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE"))); } @Test public void should_not_update_docs_for_sagan_when_current_version_older() { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); - this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.RC1"), - version("1.0.0.RC1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("1.0.0.RC1"), version("1.0.0.RC1"), projects); - then(this.saganClient).should(BDDMockito.never()) - .patchProject(BDDMockito.any(Project.class)); + then(this.saganClient).should(BDDMockito.never()).patchProject(BDDMockito.any(Project.class)); } @@ -123,13 +116,11 @@ public class SaganUpdaterOldDocsTest { } @Test - public void should_not_update_docs_for_sagan_when_files_exist_but_content_does_not_differ() - throws IOException { + public void should_not_update_docs_for_sagan_when_files_exist_but_content_does_not_differ() throws IOException { Project project = a2_0_0_ReleaseProject(); project.rawOverview = "new overview"; project.rawBootConfig = "new boot"; - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(project); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())).willReturn(project); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-index.adoc", "new overview"); @@ -141,18 +132,16 @@ public class SaganUpdaterOldDocsTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should(BDDMockito.never()) - .patchProject(BDDMockito.any(Project.class)); + then(this.saganClient).should(BDDMockito.never()).patchProject(BDDMockito.any(Project.class)); } @Test public void should_update_docs_for_sagan_when_current_version_newer_and_only_overview_adoc_exists() throws IOException { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-index.adoc", "new text"); @@ -163,18 +152,16 @@ public class SaganUpdaterOldDocsTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should().patchProject( - BDDMockito.argThat(argument -> "new text".equals(argument.rawOverview))); + then(this.saganClient).should() + .patchProject(BDDMockito.argThat(argument -> "new text".equals(argument.rawOverview))); } @Test - public void should_update_docs_for_sagan_when_current_version_newer_and_only_boot_adoc_exists() - throws IOException { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + public void should_update_docs_for_sagan_when_current_version_newer_and_only_boot_adoc_exists() throws IOException { + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-boot.adoc", "new text"); @@ -185,11 +172,10 @@ public class SaganUpdaterOldDocsTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should().patchProject(BDDMockito - .argThat(argument -> "new text".equals(argument.rawBootConfig))); + then(this.saganClient).should() + .patchProject(BDDMockito.argThat(argument -> "new text".equals(argument.rawBootConfig))); } private void createFile(Path tmp, String filename, String text) throws IOException { @@ -206,52 +192,44 @@ public class SaganUpdaterOldDocsTest { public void should_update_sagan_from_main() { ProjectVersion projectVersion = version("1.0.0.BUILD-SNAPSHOT"); - this.saganUpdater.updateSagan(new File("."), "main", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "main", projectVersion, projectVersion, projects); - then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), - BDDMockito.argThat(withReleaseUpdate("1.0.0.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); + then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat( + withReleaseUpdate("1.0.0.BUILD-SNAPSHOT", "https://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); } @Test public void should_update_sagan_from_release_version() { ProjectVersion projectVersion = version("1.0.0.RELEASE"); - this.saganUpdater.updateSagan(new File("."), "main", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "main", projectVersion, projectVersion, projects); then(this.saganClient).should().deleteRelease("foo", "1.0.0.RC1"); then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT"); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("1.0.0.RELEASE", - "https://cloud.spring.io/spring-cloud-static/foo/{version}/", - "GENERAL_AVAILABILITY"))); + "https://cloud.spring.io/spring-cloud-static/foo/{version}/", "GENERAL_AVAILABILITY"))); then(this.saganClient).should().deleteRelease("foo", "1.0.0.BUILD-SNAPSHOT"); - then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), - BDDMockito.argThat(withReleaseUpdate("1.0.1.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); + then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat( + withReleaseUpdate("1.0.1.BUILD-SNAPSHOT", "https://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); } @Test public void should_update_sagan_from_non_main() { ProjectVersion projectVersion = version("1.1.0.BUILD-SNAPSHOT"); - this.saganUpdater.updateSagan(new File("."), "1.1.x", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "1.1.x", projectVersion, projectVersion, projects); then(this.saganClient).should(never()).deleteRelease(anyString(), anyString()); - then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), - BDDMockito.argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/1.1.x/", "SNAPSHOT"))); + then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito + .argThat(withReleaseUpdate("1.1.0.BUILD-SNAPSHOT", "https://cloud.spring.io/foo/1.1.x/", "SNAPSHOT"))); } - private ArgumentMatcher> withReleaseUpdate(final String version, - final String refDocUrl, final String releaseStatus) { + private ArgumentMatcher> withReleaseUpdate(final String version, final String refDocUrl, + final String releaseStatus) { return argument -> { ReleaseUpdate item = argument.get(0); - return "foo".equals(item.artifactId) - && releaseStatus.equals(item.releaseStatus) + return "foo".equals(item.artifactId) && releaseStatus.equals(item.releaseStatus) && version.equals(item.version) && refDocUrl.equals(item.apiDocUrl) && refDocUrl.equals(item.refDocUrl) && item.current; }; diff --git a/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterTest.java b/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterTest.java index 806a31ab..5605b543 100644 --- a/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterTest.java +++ b/releaser-core/src/test/java/releaser/internal/sagan/SaganUpdaterTest.java @@ -24,8 +24,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.mockito.BDDMockito; import org.mockito.Mockito; @@ -51,11 +51,11 @@ public class SaganUpdaterTest { Projects projects = new Projects(); - @Before + @BeforeEach public void setup() { Project project = new Project(); - project.projectReleases.addAll(Arrays.asList(release("2.2.0.RC1"), - release("2.3.0.BUILD-SNAPSHOT"), release("2.2.0.M4"))); + project.projectReleases + .addAll(Arrays.asList(release("2.2.0.RC1"), release("2.3.0.BUILD-SNAPSHOT"), release("2.2.0.M4"))); BDDMockito.given(this.saganClient.getProject(anyString())).willReturn(project); this.properties.getSagan().setUpdateSagan(true); this.saganUpdater = new SaganUpdater(this.saganClient, this.properties); @@ -72,44 +72,37 @@ public class SaganUpdaterTest { public void should_not_update_sagan_when_switch_is_off() { this.properties.getSagan().setUpdateSagan(false); - this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), - version("2.2.0.M1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), version("2.2.0.M1"), projects); - then(this.saganClient).shouldHaveZeroInteractions(); + then(this.saganClient).shouldHaveNoInteractions(); } @Test public void should_update_sagan_releases_for_milestone() { - this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), - version("2.2.0.M1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.M1"), version("2.2.0.M1"), projects); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("2.2.0.M1", - "https://cloud.spring.io/spring-cloud-static/foo/{version}/reference/html/", - "PRERELEASE"))); + "https://cloud.spring.io/spring-cloud-static/foo/{version}/reference/html/", "PRERELEASE"))); } @Test public void should_update_sagan_releases_for_rc() { - this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.RC1"), - version("2.2.0.RC1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.RC1"), version("2.2.0.RC1"), projects); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("2.2.0.RC1", - "https://cloud.spring.io/spring-cloud-static/foo/{version}/reference/html/", - "PRERELEASE"))); + "https://cloud.spring.io/spring-cloud-static/foo/{version}/reference/html/", "PRERELEASE"))); } @Test public void should_not_update_docs_for_sagan_when_current_version_older() { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); - this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.RC1"), - version("2.2.0.RC1"), projects); + this.saganUpdater.updateSagan(new File("."), "master", version("2.2.0.RC1"), version("2.2.0.RC1"), projects); - then(this.saganClient).should(BDDMockito.never()) - .patchProject(BDDMockito.any(Project.class)); + then(this.saganClient).should(BDDMockito.never()).patchProject(BDDMockito.any(Project.class)); } @@ -123,13 +116,11 @@ public class SaganUpdaterTest { } @Test - public void should_not_update_docs_for_sagan_when_files_exist_but_content_does_not_differ() - throws IOException { + public void should_not_update_docs_for_sagan_when_files_exist_but_content_does_not_differ() throws IOException { Project project = a2_0_0_ReleaseProject(); project.rawOverview = "new overview"; project.rawBootConfig = "new boot"; - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(project); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())).willReturn(project); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-index.adoc", "new overview"); @@ -141,18 +132,16 @@ public class SaganUpdaterTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should(BDDMockito.never()) - .patchProject(BDDMockito.any(Project.class)); + then(this.saganClient).should(BDDMockito.never()).patchProject(BDDMockito.any(Project.class)); } @Test public void should_update_docs_for_sagan_when_current_version_newer_and_only_overview_adoc_exists() throws IOException { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-index.adoc", "new text"); @@ -163,18 +152,16 @@ public class SaganUpdaterTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should().patchProject( - BDDMockito.argThat(argument -> "new text".equals(argument.rawOverview))); + then(this.saganClient).should() + .patchProject(BDDMockito.argThat(argument -> "new text".equals(argument.rawOverview))); } @Test - public void should_update_docs_for_sagan_when_current_version_newer_and_only_boot_adoc_exists() - throws IOException { - given(this.saganClient.updateRelease(BDDMockito.anyString(), - BDDMockito.anyList())).willReturn(a2_0_0_ReleaseProject()); + public void should_update_docs_for_sagan_when_current_version_newer_and_only_boot_adoc_exists() throws IOException { + given(this.saganClient.updateRelease(BDDMockito.anyString(), BDDMockito.anyList())) + .willReturn(a2_0_0_ReleaseProject()); Path tmp = Files.createTempDirectory("releaser-test"); createFile(tmp, "sagan-boot.adoc", "new text"); @@ -185,11 +172,10 @@ public class SaganUpdaterTest { } }; - saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), - version("3.0.0.RC1"), projects); + saganUpdater.updateSagan(new File("."), "master", version("3.0.0.RC1"), version("3.0.0.RC1"), projects); - then(this.saganClient).should().patchProject(BDDMockito - .argThat(argument -> "new text".equals(argument.rawBootConfig))); + then(this.saganClient).should() + .patchProject(BDDMockito.argThat(argument -> "new text".equals(argument.rawBootConfig))); } private void createFile(Path tmp, String filename, String text) throws IOException { @@ -206,20 +192,17 @@ public class SaganUpdaterTest { public void should_update_sagan_from_main() { ProjectVersion projectVersion = version("2.2.0.BUILD-SNAPSHOT"); - this.saganUpdater.updateSagan(new File("."), "main", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "main", projectVersion, projectVersion, projects); - then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), - BDDMockito.argThat(withReleaseUpdate("2.2.0.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/reference/html/", "SNAPSHOT"))); + then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat( + withReleaseUpdate("2.2.0.BUILD-SNAPSHOT", "https://cloud.spring.io/foo/reference/html/", "SNAPSHOT"))); } @Test public void should_update_sagan_from_release_version() { ProjectVersion projectVersion = version("2.2.0.RELEASE"); - this.saganUpdater.updateSagan(new File("."), "main", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "main", projectVersion, projectVersion, projects); then(this.saganClient).should().deleteRelease("foo", "2.2.0.RC1"); then(this.saganClient).should().deleteRelease("foo", "2.2.0.BUILD-SNAPSHOT"); @@ -228,31 +211,27 @@ public class SaganUpdaterTest { "https://cloud.spring.io/spring-cloud-static/foo/{version}/reference/html/", "GENERAL_AVAILABILITY"))); then(this.saganClient).should().deleteRelease("foo", "2.2.0.BUILD-SNAPSHOT"); - then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), - BDDMockito.argThat(withReleaseUpdate("2.2.1.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/reference/html/", "SNAPSHOT"))); + then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat( + withReleaseUpdate("2.2.1.BUILD-SNAPSHOT", "https://cloud.spring.io/foo/reference/html/", "SNAPSHOT"))); } @Test public void should_update_sagan_from_non_master() { ProjectVersion projectVersion = version("2.3.0.BUILD-SNAPSHOT"); - this.saganUpdater.updateSagan(new File("."), "2.3.x", projectVersion, - projectVersion, projects); + this.saganUpdater.updateSagan(new File("."), "2.3.x", projectVersion, projectVersion, projects); then(this.saganClient).should(never()).deleteRelease(anyString(), anyString()); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), BDDMockito.argThat(withReleaseUpdate("2.3.0.BUILD-SNAPSHOT", - "https://cloud.spring.io/foo/2.3.x/reference/html/", - "SNAPSHOT"))); + "https://cloud.spring.io/foo/2.3.x/reference/html/", "SNAPSHOT"))); } - private ArgumentMatcher> withReleaseUpdate(final String version, - final String refDocUrl, final String releaseStatus) { + private ArgumentMatcher> withReleaseUpdate(final String version, final String refDocUrl, + final String releaseStatus) { return argument -> { ReleaseUpdate item = argument.get(0); - return "foo".equals(item.artifactId) - && releaseStatus.equals(item.releaseStatus) + return "foo".equals(item.artifactId) && releaseStatus.equals(item.releaseStatus) && version.equals(item.version) && refDocUrl.equals(item.apiDocUrl) && refDocUrl.equals(item.refDocUrl) && item.current; }; diff --git a/releaser-core/src/test/java/releaser/internal/template/TemplateGeneratorTests.java b/releaser-core/src/test/java/releaser/internal/template/TemplateGeneratorTests.java index 761f76d0..f4f995de 100644 --- a/releaser-core/src/test/java/releaser/internal/template/TemplateGeneratorTests.java +++ b/releaser-core/src/test/java/releaser/internal/template/TemplateGeneratorTests.java @@ -22,7 +22,7 @@ import java.nio.file.Files; import java.util.Collections; import java.util.HashSet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import releaser.SpringCloudReleaserProperties; import releaser.internal.ReleaserProperties; import releaser.internal.github.ProjectGitHubHandler; @@ -38,8 +38,7 @@ public class TemplateGeneratorTests { ReleaserProperties props = SpringCloudReleaserProperties.get(); - ProjectGitHubHandler handler = new ProjectGitHubHandler(this.props, - Collections.emptyList()) { + ProjectGitHubHandler handler = new ProjectGitHubHandler(this.props, Collections.emptyList()) { @Override public String milestoneUrl(ProjectVersion releaseVersion) { if (releaseVersion.projectName.equals("spring-cloud-foo")) { @@ -53,8 +52,7 @@ public class TemplateGeneratorTests { public void should_generate_email_from_template_for_tag_with_v_prefix() { this.props.getPom().setBranch("vDalston.RELEASE"); - File generatedMail = new TemplateGenerator(this.props, this.handler) - .email(new Projects()); + File generatedMail = new TemplateGenerator(this.props, this.handler).email(new Projects()); then(generatedMail).hasContent(expectedEmail()); } @@ -63,9 +61,8 @@ public class TemplateGeneratorTests { public void should_generate_email_from_template_when_output_folder_is_missing() { this.props.getPom().setBranch("vDalston.RELEASE"); - File generatedMail = new TemplateGenerator(this.props, - new File("target/foo/bar/baz/template.txt"), this.handler) - .email(new Projects()); + File generatedMail = new TemplateGenerator(this.props, new File("target/foo/bar/baz/template.txt"), + this.handler).email(new Projects()); then(generatedMail).hasContent(expectedEmail()); } @@ -74,8 +71,7 @@ public class TemplateGeneratorTests { public void should_generate_email_from_template_for_tag_without_v_prefix() { this.props.getPom().setBranch("Dalston.RELEASE"); - File generatedMail = new TemplateGenerator(this.props, this.handler) - .email(new Projects()); + File generatedMail = new TemplateGenerator(this.props, this.handler).email(new Projects()); then(generatedMail).hasContent(expectedEmail()); } @@ -84,8 +80,7 @@ public class TemplateGeneratorTests { public void should_generate_tweet_from_template_for_tag_with_v_prefix() { this.props.getPom().setBranch("vDalston.RELEASE"); - File generatedTweet = new TemplateGenerator(this.props, this.handler) - .tweet(new Projects()); + File generatedTweet = new TemplateGenerator(this.props, this.handler).tweet(new Projects()); then(generatedTweet).hasContent(expectedTweet()); } @@ -94,15 +89,13 @@ public class TemplateGeneratorTests { public void should_generate_tweet_from_template_for_tag_without_v_prefix() { this.props.getPom().setBranch("Dalston.RELEASE"); - File generatedTweet = new TemplateGenerator(this.props, this.handler) - .tweet(new Projects()); + File generatedTweet = new TemplateGenerator(this.props, this.handler).tweet(new Projects()); then(generatedTweet).hasContent(expectedTweet()); } @Test - public void should_generate_blog_from_template_for_tag_with_v_prefix_release() - throws IOException { + public void should_generate_blog_from_template_for_tag_with_v_prefix_release() throws IOException { this.props.getPom().setBranch("vDalston.RELEASE"); Projects projects = new Projects(new HashSet() { { @@ -112,23 +105,18 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("General Availability (RELEASE) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Maven Central]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") + then(content(generatedBlog)).contains("General Availability (RELEASE) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Maven Central]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") .contains("| Spring Cloud Foo | 1.0.2.RELEASE |  ") - .contains("Dalston.RELEASE").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'"); + .contains("Dalston.RELEASE") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'"); } @Test - public void should_generate_blog_from_template_for_tag_without_v_prefix_release() - throws IOException { + public void should_generate_blog_from_template_for_tag_without_v_prefix_release() throws IOException { this.props.getPom().setBranch("Dalston.RELEASE"); Projects projects = new Projects(new HashSet() { { @@ -137,22 +125,17 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("General Availability (RELEASE) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Maven Central]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") - .contains("Dalston.RELEASE").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'"); + then(content(generatedBlog)).contains("General Availability (RELEASE) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Maven Central]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") + .contains("Dalston.RELEASE") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RELEASE'"); } @Test - public void should_generate_blog_from_template_for_tag_without_v_prefix_release_using_calver() - throws IOException { + public void should_generate_blog_from_template_for_tag_without_v_prefix_release_using_calver() throws IOException { this.props.getPom().setBranch("2020.0.5"); Projects projects = new Projects(new HashSet() { { @@ -161,22 +144,17 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("General Availability (RELEASE) of the [Spring Cloud 2020.0.5]") - .contains("The release can be found in [Maven Central]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0 | ([issues](https://foo.bar.com))") - .contains("2020.0.5").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.5'"); + then(content(generatedBlog)).contains("General Availability (RELEASE) of the [Spring Cloud 2020.0.5]") + .contains("The release can be found in [Maven Central]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0 | ([issues](https://foo.bar.com))") + .contains("2020.0.5") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.5'"); } @Test - public void should_generate_sr_blog_from_template_for_tag_with_v_prefix_release() - throws IOException { + public void should_generate_sr_blog_from_template_for_tag_with_v_prefix_release() throws IOException { this.props.getPom().setBranch("vDalston.SR1"); Projects projects = new Projects(new HashSet() { { @@ -185,22 +163,17 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Maven Central]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") - .contains("Dalston.SR1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'"); + then(content(generatedBlog)).contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Maven Central]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") + .contains("Dalston.SR1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'"); } @Test - public void should_generate_sr_blog_from_template_for_tag_without_v_prefix_release() - throws IOException { + public void should_generate_sr_blog_from_template_for_tag_without_v_prefix_release() throws IOException { this.props.getPom().setBranch("Dalston.SR1"); Projects projects = new Projects(new HashSet() { { @@ -209,22 +182,17 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Maven Central]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") - .contains("Dalston.SR1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'"); + then(content(generatedBlog)).contains("Service Release 1 (SR1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Maven Central]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RELEASE | ([issues](https://foo.bar.com))") + .contains("Dalston.SR1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR1'"); } @Test - public void should_generate_milestone_blog_from_template_for_tag_with_v_prefix_release() - throws IOException { + public void should_generate_milestone_blog_from_template_for_tag_with_v_prefix_release() throws IOException { this.props.getPom().setBranch("vDalston.M1"); Projects projects = new Projects(new HashSet() { { @@ -233,24 +201,18 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Milestone 1 (M1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.M1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("Dalston.M1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'"); + then(content(generatedBlog)).contains("Milestone 1 (M1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.M1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("Dalston.M1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'"); } @Test - public void should_generate_milestone_blog_from_template_for_tag_without_v_prefix_release() - throws IOException { + public void should_generate_milestone_blog_from_template_for_tag_without_v_prefix_release() throws IOException { this.props.getPom().setBranch("Dalston.M1"); Projects projects = new Projects(new HashSet() { { @@ -259,19 +221,14 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Milestone 1 (M1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.M1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("Dalston.M1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'"); + then(content(generatedBlog)).contains("Milestone 1 (M1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.M1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("Dalston.M1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.M1'"); } @Test @@ -285,24 +242,18 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Milestone 1 (M1) of the [Spring Cloud 2020.0.0]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0-M1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("2020.0.0-M1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-M1'"); + then(content(generatedBlog)).contains("Milestone 1 (M1) of the [Spring Cloud 2020.0.0]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0-M1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("2020.0.0-M1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-M1'"); } @Test - public void should_generate_rc_blog_from_template_for_tag_with_v_prefix_release() - throws IOException { + public void should_generate_rc_blog_from_template_for_tag_with_v_prefix_release() throws IOException { this.props.getPom().setBranch("vDalston.RC1"); Projects projects = new Projects(new HashSet() { { @@ -311,24 +262,18 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RC1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("Dalston.RC1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'"); + then(content(generatedBlog)).contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RC1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("Dalston.RC1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'"); } @Test - public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release() - throws IOException { + public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release() throws IOException { this.props.getPom().setBranch("Dalston.RC1"); Projects projects = new Projects(new HashSet() { { @@ -337,24 +282,18 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0.RC1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("Dalston.RC1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'"); + then(content(generatedBlog)).contains("Release Candidate 1 (RC1) of the [Spring Cloud Dalston]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0.RC1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("Dalston.RC1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.RC1'"); } @Test - public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release_calver() - throws IOException { + public void should_generate_rc_blog_from_template_for_tag_without_v_prefix_release_calver() throws IOException { this.props.getPom().setBranch("2020.0.0-RC1"); Projects projects = new Projects(new HashSet() { { @@ -363,26 +302,19 @@ public class TemplateGeneratorTests { } }); - File generatedBlog = new TemplateGenerator(this.props, this.handler) - .blog(projects); + File generatedBlog = new TemplateGenerator(this.props, this.handler).blog(projects); - then(content(generatedBlog)) - .contains("Release Candidate 1 (RC1) of the [Spring Cloud 2020.0.0]") - .contains("The release can be found in [Spring Milestone]") - .contains("### Spring Cloud Sleuth") - .contains( - "| Spring Cloud Sleuth | 1.0.0-RC1 | ([issues](https://foo.bar.com))") - .contains("spring-milestones") - .contains("url 'https://repo.spring.io/milestone'") - .contains("2020.0.0-RC1").contains( - "mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-RC1'"); + then(content(generatedBlog)).contains("Release Candidate 1 (RC1) of the [Spring Cloud 2020.0.0]") + .contains("The release can be found in [Spring Milestone]").contains("### Spring Cloud Sleuth") + .contains("| Spring Cloud Sleuth | 1.0.0-RC1 | ([issues](https://foo.bar.com))") + .contains("spring-milestones").contains("url 'https://repo.spring.io/milestone'") + .contains("2020.0.0-RC1") + .contains("mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.0-RC1'"); } @Test - public void should_generate_release_notes_template_when_url_exists() - throws IOException { - ProjectGitHubHandler handler = new ProjectGitHubHandler(this.props, - Collections.emptyList()) { + public void should_generate_release_notes_template_when_url_exists() throws IOException { + ProjectGitHubHandler handler = new ProjectGitHubHandler(this.props, Collections.emptyList()) { @Override public String milestoneUrl(ProjectVersion releaseVersion) { return "https://foo.bar.com?closed=1"; @@ -397,13 +329,11 @@ public class TemplateGeneratorTests { } }); - File generatedOutput = new TemplateGenerator(this.props, handler) - .releaseNotes(projects); + File generatedOutput = new TemplateGenerator(this.props, handler).releaseNotes(projects); - then(content(generatedOutput)).contains("# Dalston.RC1").contains( - "Spring Cloud Sleuth `1.0.0.RC1` ([issues](https://foo.bar.com?closed=1))") - .contains( - "Spring Cloud Consul `1.0.1.RC1` ([issues](https://foo.bar.com?closed=1))") + then(content(generatedOutput)).contains("# Dalston.RC1") + .contains("Spring Cloud Sleuth `1.0.0.RC1` ([issues](https://foo.bar.com?closed=1))") + .contains("Spring Cloud Consul `1.0.1.RC1` ([issues](https://foo.bar.com?closed=1))") .doesNotContain("Boot"); } @@ -412,8 +342,7 @@ public class TemplateGeneratorTests { } private String expectedEmail() { - return "Title:\n" + "Spring Cloud Dalston.RELEASE available\n\n" + "Content:\n" - + "All,\n" + "\n" + return "Title:\n" + "Spring Cloud Dalston.RELEASE available\n\n" + "Content:\n" + "All,\n" + "\n" + "On behalf of the team and the community, I'm excited to announce Spring Cloud Dalston RELEASE Train release.\n" + "\n" + "link to blog post\n" + "link to twitter\n\n" + "Cheers,\n"; } diff --git a/releaser-core/src/test/java/releaser/internal/versions/VersionsFromBomFetcherTests.java b/releaser-core/src/test/java/releaser/internal/versions/VersionsFromBomFetcherTests.java index d279bc44..d5be80bd 100644 --- a/releaser-core/src/test/java/releaser/internal/versions/VersionsFromBomFetcherTests.java +++ b/releaser-core/src/test/java/releaser/internal/versions/VersionsFromBomFetcherTests.java @@ -49,17 +49,13 @@ class VersionsFromBomFetcherTests { } @Test - void should_return_false_when_current_version_is_not_present_in_the_bom() - throws URISyntaxException { - ProjectVersion projectVersion = new ProjectVersion("spring-cloud-non-existant", - "1.0.0.RELEASE"); - URI initilizrUri = VersionsFromBomFetcherTests.class - .getResource("/raw/initializr.yml").toURI(); + void should_return_false_when_current_version_is_not_present_in_the_bom() throws URISyntaxException { + ProjectVersion projectVersion = new ProjectVersion("spring-cloud-non-existant", "1.0.0.RELEASE"); + URI initilizrUri = VersionsFromBomFetcherTests.class.getResource("/raw/initializr.yml").toURI(); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setUpdateSpringGuides(true); properties.getVersions().setAllVersionsFileUrl(initilizrUri.toString()); - properties.getGit().setReleaseTrainBomUrl( - file("/projects/spring-cloud-release/").toURI().toString()); + properties.getGit().setReleaseTrainBomUrl(file("/projects/spring-cloud-release/").toURI().toString()); ProjectPomUpdater updater = new ProjectPomUpdater(properties, new ArrayList<>()); VersionsFetcher versionsFetcher = new VersionsFetcher(properties, updater); @@ -70,8 +66,7 @@ class VersionsFromBomFetcherTests { @Test void should_return_false_when_current_version_is_not_ga() { - ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract", - "1.0.0.BUILD-SNAPSHOT"); + ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract", "1.0.0.BUILD-SNAPSHOT"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setUpdateSpringGuides(true); ProjectPomUpdater updater = new ProjectPomUpdater(properties, new ArrayList<>()); @@ -84,15 +79,13 @@ class VersionsFromBomFetcherTests { @Test void should_return_false_when_exception_occurs_while_fetching_version_info() { - ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract", - "1.0.0.BUILD-SNAPSHOT"); + ProjectVersion projectVersion = new ProjectVersion("spring-cloud-contract", "1.0.0.BUILD-SNAPSHOT"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setUpdateSpringGuides(true); VersionsFetcher versionsFetcher = new VersionsFetcher(properties, new ProjectPomUpdater(properties, new ArrayList<>()) { @Override - public Projects retrieveVersionsFromReleaseTrainBom(String branch, - boolean updateFixedVersions) { + public Projects retrieveVersionsFromReleaseTrainBom(String branch, boolean updateFixedVersions) { throw new IllegalStateException("BOOM!"); } }); @@ -103,8 +96,7 @@ class VersionsFromBomFetcherTests { } private File localFile(String relativePath) throws URISyntaxException { - return new File( - VersionsFromBomFetcherTests.class.getResource(relativePath).toURI()); + return new File(VersionsFromBomFetcherTests.class.getResource(relativePath).toURI()); } private File file(String relativePath) { diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java index 2b2235bc..278ddbc1 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bootstrap/src/test/java/demo/BootstrapClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bus/src/test/java/demo/StandaloneClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bus/src/test/java/demo/StandaloneClientApplicationTests.java index b47eb57c..40878f3c 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bus/src/test/java/demo/StandaloneClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/bus/src/test/java/demo/StandaloneClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client-decrypt/src/test/java/demo/BootstrapDecryptionClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client-decrypt/src/test/java/demo/BootstrapDecryptionClientApplicationTests.java index 85054f1c..923c512a 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client-decrypt/src/test/java/demo/BootstrapDecryptionClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client-decrypt/src/test/java/demo/BootstrapDecryptionClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client/src/test/java/demo/StandaloneClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client/src/test/java/demo/StandaloneClientApplicationTests.java index b47eb57c..40878f3c 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client/src/test/java/demo/StandaloneClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-client/src/test/java/demo/StandaloneClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-retry/src/test/java/demo/StandaloneClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-retry/src/test/java/demo/StandaloneClientApplicationTests.java index bea07532..21ddc2d3 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-retry/src/test/java/demo/StandaloneClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/config-retry/src/test/java/demo/StandaloneClientApplicationTests.java @@ -23,8 +23,7 @@ import java.util.concurrent.Executors; import apps.ConfigServer; import org.aopalliance.intercept.MethodInterceptor; import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; @@ -55,7 +54,7 @@ public class StandaloneClientApplicationTests { @Autowired private ConfigServicePropertySourceLocator locator; - @BeforeClass + @BeforeEachClass public static void delayConfigServer() { Executors.newSingleThreadExecutor().execute(new Runnable() { @Override diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-bootstrap/src/test/java/demo/ConfigServerEurekaApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-bootstrap/src/test/java/demo/ConfigServerEurekaApplicationTests.java index ef4b55a9..b68e966e 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-bootstrap/src/test/java/demo/ConfigServerEurekaApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-bootstrap/src/test/java/demo/ConfigServerEurekaApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-eureka/src/test/java/demo/ConfigServerEurekaApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-eureka/src/test/java/demo/ConfigServerEurekaApplicationTests.java index fd115626..60bac0fb 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-eureka/src/test/java/demo/ConfigServerEurekaApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver-eureka/src/test/java/demo/ConfigServerEurekaApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver/src/test/java/demo/ConfigServerApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver/src/test/java/demo/ConfigServerApplicationTests.java index 01104578..14ea1d0e 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver/src/test/java/demo/ConfigServerApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/configserver/src/test/java/demo/ConfigServerApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java index 7db90d5b..6ac5baeb 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-client/src/test/java/demo/EurekaClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-first/src/test/java/demo/EurekaFirstApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-first/src/test/java/demo/EurekaFirstApplicationTests.java index e01a8f2d..ae870c20 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-first/src/test/java/demo/EurekaFirstApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-first/src/test/java/demo/EurekaFirstApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/DefaultStandaloneClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/DefaultStandaloneClientApplicationTests.java index 0703e596..78f882b3 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/DefaultStandaloneClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/DefaultStandaloneClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/StandaloneClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/StandaloneClientApplicationTests.java index b7f35756..f592e471 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/StandaloneClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-noweb/src/test/java/demo/StandaloneClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-server/src/test/java/demo/EurekaServerApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-server/src/test/java/demo/EurekaServerApplicationTests.java index 013b71b1..0ae62f72 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-server/src/test/java/demo/EurekaServerApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/eureka-server/src/test/java/demo/EurekaServerApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eager-instantiation/src/test/java/demo/FeignEagerInstantiationApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eager-instantiation/src/test/java/demo/FeignEagerInstantiationApplicationTests.java index b821b31c..ff12b97a 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eager-instantiation/src/test/java/demo/FeignEagerInstantiationApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eager-instantiation/src/test/java/demo/FeignEagerInstantiationApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/HelloClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/HelloClientApplicationTests.java index f6fc7667..572d4bb7 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/HelloClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/HelloClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/NoWebApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/NoWebApplicationTests.java index 3e5283f7..31a97723 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/NoWebApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-eureka/src/test/java/demo/NoWebApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java index 34ebc770..8030abab 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientApplicationTests.java @@ -17,7 +17,7 @@ package demo; import demo.FeignClientWithServerListApplicationTests.FallbackRestClient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientWithServerListApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientWithServerListApplicationTests.java index 7110ee22..b8a7e568 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientWithServerListApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign-hystrix/src/test/java/demo/FeignClientWithServerListApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientApplicationTests.java index 19652936..555084a8 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientWithServerListApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientWithServerListApplicationTests.java index c977d4ca..3b5ac1df 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientWithServerListApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/feign/src/test/java/demo/FeignClientWithServerListApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix-amqp/src/test/java/demo/HystrixApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix-amqp/src/test/java/demo/HystrixApplicationTests.java index 239b3838..c48509d6 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix-amqp/src/test/java/demo/HystrixApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix-amqp/src/test/java/demo/HystrixApplicationTests.java @@ -19,7 +19,7 @@ package demo; import java.io.InputStream; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix/src/test/java/demo/HystrixApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix/src/test/java/demo/HystrixApplicationTests.java index 239b3838..c48509d6 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix/src/test/java/demo/HystrixApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/hystrix/src/test/java/demo/HystrixApplicationTests.java @@ -19,7 +19,7 @@ package demo; import java.io.InputStream; import java.net.URL; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/netflix-sidecar/src/test/java/demo/SidecarApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/netflix-sidecar/src/test/java/demo/SidecarApplicationTests.java index 180c5882..d4ab9d36 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/netflix-sidecar/src/test/java/demo/SidecarApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/netflix-sidecar/src/test/java/demo/SidecarApplicationTests.java @@ -17,7 +17,7 @@ package demo; import com.netflix.appinfo.EurekaInstanceConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/demo/NotWebApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/demo/NotWebApplicationTests.java index 0a917582..5a3f937a 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/demo/NotWebApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/demo/NotWebApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/test/DiscoveryNotWebApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/test/DiscoveryNotWebApplicationTests.java index 8d2196ed..8e08af34 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/test/DiscoveryNotWebApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/noweb/src/test/java/test/DiscoveryNotWebApplicationTests.java @@ -21,7 +21,7 @@ import java.util.List; import demo.NotWebApplication; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-ribbon/src/test/java/demo/RibbonClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-ribbon/src/test/java/demo/RibbonClientApplicationTests.java index 2c0189ee..f6d4260e 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-ribbon/src/test/java/demo/RibbonClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-ribbon/src/test/java/demo/RibbonClientApplicationTests.java @@ -17,7 +17,7 @@ package demo; import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-zuul/src/test/java/demo/ZuulApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-zuul/src/test/java/demo/ZuulApplicationTests.java index 6773e645..71a83886 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-zuul/src/test/java/demo/ZuulApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/oauth2-zuul/src/test/java/demo/ZuulApplicationTests.java @@ -17,7 +17,7 @@ package demo; import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-default-config/src/test/java/demo/RibbonDefaultConfigApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-default-config/src/test/java/demo/RibbonDefaultConfigApplicationTests.java index 1b20a03e..d034278f 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-default-config/src/test/java/demo/RibbonDefaultConfigApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-default-config/src/test/java/demo/RibbonDefaultConfigApplicationTests.java @@ -32,7 +32,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-eureka/src/test/java/demo/HelloClientApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-eureka/src/test/java/demo/HelloClientApplicationTests.java index 9a111227..4f2d4c11 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-eureka/src/test/java/demo/HelloClientApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/ribbon-eureka/src/test/java/demo/HelloClientApplicationTests.java @@ -17,7 +17,7 @@ package demo; import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/sleuth/src/test/java/demo/TraceApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/sleuth/src/test/java/demo/TraceApplicationTests.java index c314ace8..c01da652 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/sleuth/src/test/java/demo/TraceApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/sleuth/src/test/java/demo/TraceApplicationTests.java @@ -17,7 +17,7 @@ package demo; import brave.Tracer; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/stream-bus/src/test/java/demo/StreamBusApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/stream-bus/src/test/java/demo/StreamBusApplicationTests.java index b6e18649..f06b8272 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/stream-bus/src/test/java/demo/StreamBusApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/stream-bus/src/test/java/demo/StreamBusApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine-amqp/src/test/java/demo/TurbineStreamApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine-amqp/src/test/java/demo/TurbineStreamApplicationTests.java index 6c711f05..ce29c3cf 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine-amqp/src/test/java/demo/TurbineStreamApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine-amqp/src/test/java/demo/TurbineStreamApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine/src/test/java/demo/TurbineApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine/src/test/java/demo/TurbineApplicationTests.java index 175a3357..ff4133d7 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine/src/test/java/demo/TurbineApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/turbine/src/test/java/demo/TurbineApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/vanilla/src/test/java/demo/VanillaApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/vanilla/src/test/java/demo/VanillaApplicationTests.java index 35625e0d..7bae29b6 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/vanilla/src/test/java/demo/VanillaApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/vanilla/src/test/java/demo/VanillaApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zipkin/src/test/java/demo/ZipkinApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zipkin/src/test/java/demo/ZipkinApplicationTests.java index a9b9a9a3..4c4bee8b 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zipkin/src/test/java/demo/ZipkinApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zipkin/src/test/java/demo/ZipkinApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-config-discovery/src/test/java/demo/ZuulConfigDiscoveryApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-config-discovery/src/test/java/demo/ZuulConfigDiscoveryApplicationTests.java index af52b5bd..0c8055bd 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-config-discovery/src/test/java/demo/ZuulConfigDiscoveryApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-config-discovery/src/test/java/demo/ZuulConfigDiscoveryApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy-eureka/src/test/java/demo/ZuulProxyEurekaApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy-eureka/src/test/java/demo/ZuulProxyEurekaApplicationTests.java index b49282f2..031ed301 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy-eureka/src/test/java/demo/ZuulProxyEurekaApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy-eureka/src/test/java/demo/ZuulProxyEurekaApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy/src/test/java/demo/ZuulProxyApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy/src/test/java/demo/ZuulProxyApplicationTests.java index 08b76acf..51d2f021 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy/src/test/java/demo/ZuulProxyApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul-proxy/src/test/java/demo/ZuulProxyApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul/src/test/java/demo/ZuulApplicationTests.java b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul/src/test/java/demo/ZuulApplicationTests.java index 0b93eb73..56307e64 100644 --- a/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul/src/test/java/demo/ZuulApplicationTests.java +++ b/releaser-core/src/test/resources/projects/spring-cloud-core-tests/zuul/src/test/java/demo/ZuulApplicationTests.java @@ -16,7 +16,7 @@ package demo; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/releaser-spring/src/test/java/releaser/internal/spring/OptionsProcessorTests.java b/releaser-spring/src/test/java/releaser/internal/spring/OptionsProcessorTests.java index 8042e87e..30d9da2b 100644 --- a/releaser-spring/src/test/java/releaser/internal/spring/OptionsProcessorTests.java +++ b/releaser-spring/src/test/java/releaser/internal/spring/OptionsProcessorTests.java @@ -19,7 +19,7 @@ package releaser.internal.spring; /** * @author Marcin Grzejszczak */ -// @RunWith(MockitoJUnitRunner.class) +// @ExtendWith(MockitoExtension.class) @SuppressWarnings("unchecked") public class OptionsProcessorTests { @@ -45,7 +45,7 @@ public class OptionsProcessorTests { * Consumer function) { return new Task(name, shortName, header, description, * function); } * - * @Before public void setup() { this.optionsProcessor = new + * @BeforeEach public void setup() { this.optionsProcessor = new * OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks); Task.stepSkipper * = () -> false; } * 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 1ef0bc52..1fe2b544 100644 --- a/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java +++ b/releaser-spring/src/test/java/releaser/internal/spring/ReleaserPropertiesUpdaterTests.java @@ -20,7 +20,7 @@ import java.io.File; import java.net.URISyntaxException; import org.assertj.core.api.BDDAssertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import releaser.internal.ReleaserProperties; import releaser.internal.ReleaserPropertiesUpdater; diff --git a/releaser-test/src/main/java/releaser/internal/spring/AbstractSpringAcceptanceTests.java b/releaser-test/src/main/java/releaser/internal/spring/AbstractSpringAcceptanceTests.java index 72435549..6c1d0f34 100644 --- a/releaser-test/src/main/java/releaser/internal/spring/AbstractSpringAcceptanceTests.java +++ b/releaser-test/src/main/java/releaser/internal/spring/AbstractSpringAcceptanceTests.java @@ -35,8 +35,8 @@ import org.eclipse.jgit.api.ResetCommand; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.revwalk.RevCommit; import org.junit.After; -import org.junit.Before; import org.junit.Rule; +import org.junit.jupiter.api.BeforeEach; import org.junit.rules.TemporaryFolder; import org.mockito.BDDMockito; import releaser.internal.ReleaserProperties; @@ -89,7 +89,7 @@ public abstract class AbstractSpringAcceptanceTests { return release; } - @Before + @BeforeEach public void setup() throws Exception { this.temporaryFolder = this.tmp.newFolder(); TestUtils.prepareLocalRepo(); diff --git a/spring-cloud-info/pom.xml b/spring-cloud-info/pom.xml index 195b358b..27d5be6a 100644 --- a/spring-cloud-info/pom.xml +++ b/spring-cloud-info/pom.xml @@ -103,17 +103,17 @@ org.asciidoctor asciidoctor-maven-plugin - ${asciidoctor-maven-plugin.version} + 2.2.2 io.spring.asciidoctor spring-asciidoctor-extensions - ${spring-asciidoctor-extensions.version} + 0.6.0 org.springframework.restdocs spring-restdocs-asciidoctor - ${spring-rest-docs.version} + 2.0.6.RELEASE diff --git a/spring-cloud-info/src/test/java/org/springframework/cloud/info/InitializrSpringCloudInfoServiceTests.java b/spring-cloud-info/src/test/java/org/springframework/cloud/info/InitializrSpringCloudInfoServiceTests.java index a69d706c..ab02fd81 100644 --- a/spring-cloud-info/src/test/java/org/springframework/cloud/info/InitializrSpringCloudInfoServiceTests.java +++ b/spring-cloud-info/src/test/java/org/springframework/cloud/info/InitializrSpringCloudInfoServiceTests.java @@ -46,7 +46,7 @@ import com.jcabi.immutable.Array; import org.apache.commons.io.IOUtils; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.cloud.info.exceptions.SpringCloudVersionNotFoundException; import org.springframework.core.io.ClassPathResource; diff --git a/spring-cloud-info/src/test/java/org/springframework/cloud/info/SpringCloudInfoRestControllerTests.java b/spring-cloud-info/src/test/java/org/springframework/cloud/info/SpringCloudInfoRestControllerTests.java index 5973e90c..647d8409 100644 --- a/spring-cloud-info/src/test/java/org/springframework/cloud/info/SpringCloudInfoRestControllerTests.java +++ b/spring-cloud-info/src/test/java/org/springframework/cloud/info/SpringCloudInfoRestControllerTests.java @@ -18,9 +18,9 @@ package org.springframework.cloud.info; import java.util.stream.Collectors; -import org.junit.Before; import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -65,7 +65,7 @@ public class SpringCloudInfoRestControllerTests { @Autowired private WebApplicationContext context; - @Before + @BeforeEach public void setUp() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(documentationConfiguration(this.restDocumentation).uris()