From 03666265f8d485bbaff131812fd06bfd930db35c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 19 Nov 2018 18:38:43 +0100 Subject: [PATCH] Table done; fixes gh-111 --- .../release/internal/pom/PomUpdater.java | 2 +- .../internal/post/PostReleaseActions.java | 24 +++-- .../template/BlogTemplateGenerator.java | 3 +- .../template/EmailTemplateGenerator.java | 3 +- .../internal/template/NotesGenerator.java | 1 + .../ReleaseNotesTemplateGenerator.java | 17 +--- .../template/TwitterTemplateGenerator.java | 3 +- .../internal/ReleaserPropertiesTests.java | 6 +- .../cloud/release/internal/ReleaserTests.java | 14 +-- .../ProjectDocumentationUpdaterTests.java | 15 ++- .../release/internal/git/GitRepoTests.java | 4 +- .../internal/git/GithubIssuesTests.java | 6 +- .../internal/git/GithubMilestonesTests.java | 27 ++--- .../internal/gradle/GradleUpdaterTests.java | 2 +- .../release/internal/pom/BomParserTests.java | 2 +- .../internal/pom/LoggerToMavenLogTests.java | 32 +++--- .../internal/pom/PropertyStorerTests.java | 2 +- .../internal/project/ProjectBuilderTests.java | 14 +-- .../internal/sagan/SaganUpdaterTest.java | 12 +-- spring-cloud-release-tools-spring/pom.xml | 5 + .../release/internal/ReleaserApplication.java | 2 +- .../cloud/release/internal/spring/Task.java | 22 +++-- .../internal/spring/TaskAndException.java | 57 +++++++++++ .../cloud/release/internal/spring/Tasks.java | 99 +++++++++++++++++-- .../docs/TestDocumentationUpdater.java | 2 +- .../internal/spring/AcceptanceTests.java | 12 +-- .../spring/CompositeConsumerTests.java | 58 +++++++++++ .../spring/OptionsProcessorTests.java | 32 +++--- .../release/internal/spring/TaskTests.java | 2 +- 29 files changed, 333 insertions(+), 147 deletions(-) create mode 100644 spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/TaskAndException.java create mode 100644 spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/CompositeConsumerTests.java diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/pom/PomUpdater.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/pom/PomUpdater.java index d9dbc855..9d7c6bf4 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/pom/PomUpdater.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/pom/PomUpdater.java @@ -346,7 +346,7 @@ class PropertyVersionChanger extends AbstractVersionChanger { this.propertyStorer = propertyStorer; } - @Override public void apply(final VersionChange versionChange) throws XMLStreamException { + @Override public void apply(final VersionChange versionChange) { this.versions.projects .stream() .filter(project -> { diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/post/PostReleaseActions.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/post/PostReleaseActions.java index e90efa33..81d032d2 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/post/PostReleaseActions.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/post/PostReleaseActions.java @@ -2,7 +2,6 @@ package org.springframework.cloud.release.internal.post; import java.io.Closeable; import java.io.File; -import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -84,7 +83,7 @@ public class PostReleaseActions implements Closeable { + "is off. Set [releaser.git.update-all-test-samples] to [true] to change that"); return; } - List projectAndExceptions = this.properties.getGit() + List projectUrlAndExceptions = this.properties.getGit() .getAllTestSampleUrls() .entrySet() .stream() @@ -93,22 +92,21 @@ public class PostReleaseActions implements Closeable { .flatMap(Collection::stream) .collect(Collectors.toList()); log.info("Updated all samples!"); - List exceptionMessages = projectAndExceptions.stream() - .filter(ProjectAndException::hasException) + List exceptionMessages = projectUrlAndExceptions.stream() + .filter(ProjectUrlAndException::hasException) .map(e -> "Project [" + e.key + "] for url [" + e.url + "] " + "has exception [" + Arrays .toString(NestedExceptionUtils.getMostSpecificCause(e.ex) .getStackTrace()) + "]") .collect(Collectors.toList()); if (!exceptionMessages.isEmpty()) { - log.warn("Exceptions were found while updating samples"); - log.warn(String.join("\n", exceptionMessages)); + throw new IllegalStateException("Exceptions were found while updating samples\n" + String.join("\n", exceptionMessages)); } else { log.info("No exceptions were found while updating the samples"); } } - private Future> updateAllProjects(Projects projects, Map.Entry> e) { + private Future> updateAllProjects(Projects projects, Map.Entry> e) { return SERVICE.submit(() -> { String key = e.getKey(); List value = e.getValue(); @@ -162,7 +160,7 @@ public class PostReleaseActions implements Closeable { return new ProjectAndFuture(key, url, SERVICE.submit(runnable)); } - private ProjectAndException getResult(ProjectAndFuture projectAndFuture) { + private ProjectUrlAndException getResult(ProjectAndFuture projectAndFuture) { Exception e = null; try { projectAndFuture.future.get(10, TimeUnit.MINUTES); @@ -171,10 +169,10 @@ public class PostReleaseActions implements Closeable { catch (Exception ex) { e = ex; } - return new ProjectAndException(projectAndFuture.key, projectAndFuture.url, e); + 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); } @@ -211,7 +209,7 @@ public class PostReleaseActions implements Closeable { } @Override - public void close() throws IOException { + public void close() { SERVICE.shutdown(); } } @@ -229,12 +227,12 @@ class ProjectAndFuture { } } -class ProjectAndException { +class ProjectUrlAndException { final String key; final String url; final Exception ex; - ProjectAndException(String key, String url, Exception ex) { + ProjectUrlAndException(String key, String url, Exception ex) { this.key = key; this.url = url; this.ex = ex; diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/BlogTemplateGenerator.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/BlogTemplateGenerator.java index 0ddd9572..b420c2e1 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/BlogTemplateGenerator.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/BlogTemplateGenerator.java @@ -66,8 +66,7 @@ class BlogTemplateGenerator { return this.blogOutput; } catch (Exception e) { - log.warn("Exception occurred while trying to create a blog entry", e); - return null; + throw new IllegalStateException("Exception occurred while trying to create a blog entry", e); } } diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/EmailTemplateGenerator.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/EmailTemplateGenerator.java index 87188fe8..b22738a2 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/EmailTemplateGenerator.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/EmailTemplateGenerator.java @@ -32,8 +32,7 @@ class EmailTemplateGenerator { return this.emailOutput; } catch (Exception e) { - log.warn("Exception occurred while trying to generate an email template", e); - return null; + throw new IllegalStateException("Exception occurred while trying to generate an email template", e); } } } diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/NotesGenerator.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/NotesGenerator.java index 0342af9e..cdde234f 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/NotesGenerator.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/NotesGenerator.java @@ -52,6 +52,7 @@ class Notes { return this.version; } + @SuppressWarnings("unused") public String getClosedMilestoneUrl() { return this.closedMilestoneUrl; } diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/ReleaseNotesTemplateGenerator.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/ReleaseNotesTemplateGenerator.java index 59fcb831..5e3b8168 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/ReleaseNotesTemplateGenerator.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/ReleaseNotesTemplateGenerator.java @@ -49,22 +49,7 @@ class ReleaseNotesTemplateGenerator { return this.blogOutput; } catch (IOException e) { - log.warn("Exception occurred while trying to generate release notes", e); - return null; - } - } - - private int fileSize(File cached) { - try { - int length = Files.readAllBytes(cached.toPath()).length; - if (length == 0) { - log.warn("Cached file has no contents!"); - } - return length; - } - catch (IOException e) { - log.warn("Exception [" + e + "] occurred while trying to retrieve file length - will assume it's empty"); - return 0; + throw new IllegalStateException("Exception occurred while trying to generate release notes", e); } } } diff --git a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/TwitterTemplateGenerator.java b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/TwitterTemplateGenerator.java index 993de65b..4921f17a 100644 --- a/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/TwitterTemplateGenerator.java +++ b/spring-cloud-release-tools-core/src/main/java/org/springframework/cloud/release/internal/template/TwitterTemplateGenerator.java @@ -31,8 +31,7 @@ class TwitterTemplateGenerator { return this.output; } catch (Exception e) { - log.warn("Exception occurred while trying to generate a twitter template", e); - return null; + throw new IllegalStateException("Exception occurred while trying to generate a twitter template", e); } } } diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserPropertiesTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserPropertiesTests.java index 4490c17e..bbd9e209 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserPropertiesTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserPropertiesTests.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.BDDAssertions.then; */ public class ReleaserPropertiesTests { @Test - public void should_return_provided_working_dir_when_it_was_set() throws Exception { + public void should_return_provided_working_dir_when_it_was_set() { String workingDir = "foo"; ReleaserProperties properties = new ReleaserProperties(); @@ -24,14 +24,14 @@ public class ReleaserPropertiesTests { } @Test - public void should_return_current_working_dir_when_it_was_not_previously_set() throws Exception { + public void should_return_current_working_dir_when_it_was_not_previously_set() { ReleaserProperties properties = new ReleaserProperties(); then(properties.getWorkingDir()).isNotEmpty(); } @Test - public void should_return_a_copy_of_properties() throws Exception { + public void should_return_a_copy_of_properties() { ReleaserProperties properties = new ReleaserProperties(); properties.setWorkingDir("foo"); properties.setFixedVersions(map()); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserTests.java index b086d65b..524955f8 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/ReleaserTests.java @@ -68,7 +68,7 @@ public class ReleaserTests { } @Test - public void should_not_bump_versions_for_original_release_project() throws Exception { + 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")), @@ -79,7 +79,7 @@ public class ReleaserTests { } @Test - public void should_not_bump_versions_for_original_snapshot_project_and_current_snapshot() throws Exception { + 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")), @@ -90,7 +90,7 @@ public class ReleaserTests { } @Test - public void should_bump_versions_for_original_snapshot_project() throws Exception { + public void should_bump_versions_for_original_snapshot_project() { ProjectVersion scReleaseVersion = new ProjectVersion("changed", "1.0.0.RELEASE"); releaser(() -> new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")) .rollbackReleaseVersion(this.pom, @@ -105,28 +105,28 @@ public class ReleaserTests { } @Test - public void should_not_generate_email_for_snapshot_version() throws Exception { + public void should_not_generate_email_for_snapshot_version() { 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() throws Exception { + public void should_generate_email_for_release_version() { releaser().createEmail(new ProjectVersion("original", "1.0.0.RELEASE"), projects()); then(this.templateGenerator).should().email(any(Projects.class)); } @Test - public void should_not_close_milestone_for_snapshots() throws Exception { + public void should_not_close_milestone_for_snapshots() { releaser().closeMilestone(new ProjectVersion("original", "1.0.0.BUILD-SNAPSHOT")); then(this.projectGitHandler).should(never()).closeMilestone(any(ProjectVersion.class)); } @Test - public void should_not_rollback_for_snapshots() throws Exception { + 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")), diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/docs/ProjectDocumentationUpdaterTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/docs/ProjectDocumentationUpdaterTests.java index 4e3ce9be..072fe943 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/docs/ProjectDocumentationUpdaterTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/docs/ProjectDocumentationUpdaterTests.java @@ -67,8 +67,7 @@ public class ProjectDocumentationUpdaterTests { BDDAssertions.thenThrownBy(() -> new ProjectDocumentationUpdater(properties, new ProjectGitHandler(properties)) { - @Override String readIndexHtmlContents(File indexHtml) - throws IOException { + @Override String readIndexHtmlContents(File indexHtml) { return ""; } }.updateDocsRepo(releaseTrainVersion, "vAngel.SR33")) @@ -104,8 +103,7 @@ public class ProjectDocumentationUpdaterTests { } @Test - public void should_not_commit_if_the_same_version_is_already_there() - throws URISyntaxException { + public void should_not_commit_if_the_same_version_is_already_there() { ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString()); @@ -120,7 +118,7 @@ public class ProjectDocumentationUpdaterTests { @Test public void should_not_update_current_version_in_the_docs_if_current_release_starts_with_lower_letter_than_the_stored_release() - throws URISyntaxException, IOException { + throws IOException { ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "1.3.4.SR10"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString()); @@ -136,7 +134,7 @@ public class ProjectDocumentationUpdaterTests { @Test public void should_update_current_version_in_the_docs_if_current_release_starts_with_v_and_then_higher_letter_than_the_stored_release() - throws URISyntaxException, IOException { + throws IOException { ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString()); @@ -152,7 +150,7 @@ public class ProjectDocumentationUpdaterTests { @Test public void should_update_current_version_in_the_docs_if_current_release_starts_with_higher_letter_than_the_stored_release() - throws URISyntaxException, IOException { + throws IOException { ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString()); @@ -167,8 +165,7 @@ public class ProjectDocumentationUpdaterTests { } @Test - public void should_not_update_current_version_in_the_docs_if_switch_is_off() - throws URISyntaxException, IOException { + public void should_not_update_current_version_in_the_docs_if_switch_is_off() { ProjectVersion releaseTrainVersion = new ProjectVersion("spring-cloud-sleuth", "2.0.0.SR33"); ReleaserProperties properties = new ReleaserProperties(); properties.getGit().setDocumentationUrl(this.clonedDocProject.toURI().toString()); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GitRepoTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GitRepoTests.java index 0231db0c..6a1bf647 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GitRepoTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GitRepoTests.java @@ -54,7 +54,7 @@ public class GitRepoTests { } @Test - public void should_throw_exception_when_there_is_no_repo() throws IOException, URISyntaxException { + public void should_throw_exception_when_there_is_no_repo() { thenThrownBy(() -> this.gitRepo .cloneProject(new URIish(GitRepoTests.class.getResource("/projects/").toURI().toURL()))) .isInstanceOf(IllegalStateException.class) @@ -62,7 +62,7 @@ public class GitRepoTests { } @Test - public void should_throw_an_exception_when_failed_to_initialize_the_repo() throws IOException { + public void should_throw_an_exception_when_failed_to_initialize_the_repo() { thenThrownBy(() -> new GitRepo(this.tmpFolder, new ExceptionThrowingJGitFactory()).cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL()))) .isInstanceOf(IllegalStateException.class) diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java index 702b3b67..13457547 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubIssuesTests.java @@ -35,13 +35,13 @@ public class GithubIssuesTests { @Rule public OutputCapture capture = new OutputCapture(); @Before - public void setup() throws URISyntaxException, IOException { + public void setup() throws IOException { this.github = new MkGithub("spring-guides"); this.repo = createGettingStartedGuides(this.github); } @Test - public void should_not_do_anything_for_non_release_train_version() throws IOException { + public void should_not_do_anything_for_non_release_train_version() { Github github = BDDMockito.mock(Github.class); GithubIssues issues = new GithubIssues(github, withToken()); @@ -53,7 +53,7 @@ public class GithubIssuesTests { } @Test - public void should_not_do_anything_if_switch_is_not_set() throws IOException { + public void should_not_do_anything_if_switch_is_not_set() { Github github = BDDMockito.mock(Github.class); ReleaserProperties properties = withToken(); properties.getGit().setUpdateSpringGuides(false); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubMilestonesTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubMilestonesTests.java index 55ba91a8..7ea88550 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubMilestonesTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/git/GithubMilestonesTests.java @@ -32,7 +32,7 @@ public class GithubMilestonesTests { @Rule public OutputCapture capture = new OutputCapture(); @Before - public void setup() throws URISyntaxException, IOException { + public void setup() throws IOException { this.github = new MkGithub(); this.repo = createSleuthRepo(this.github); } @@ -44,8 +44,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.2.0.BUILD-SNAPSHOT"; } }; @@ -63,8 +62,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.2.0"; } }; @@ -86,8 +84,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.2.0"; } }; @@ -105,8 +102,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.2.0.RELEASE"; } @@ -123,7 +119,7 @@ public class GithubMilestonesTests { } @Test - public void should_fetch_url_of_a_closed_matching_milestone_from_cache() throws IOException { + public void should_fetch_url_of_a_closed_matching_milestone_from_cache() { GithubMilestones milestones = new GithubMilestones(this.github, withToken()); GithubMilestones.MILESTONE_URL_CACHE.put(gaSleuthProject(), "https://github.com/spring-cloud/spring-cloud-sleuth/milestone/33?closed=1"); @@ -133,14 +129,13 @@ public class GithubMilestonesTests { } @Test - public void should_return_null_if_no_matching_milestone_was_found() throws IOException { + public void should_return_null_if_no_matching_milestone_was_found() { GithubMilestones milestones = new GithubMilestones(this.github, withToken()) { @Override String org() { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.9.0.RELEASE"; } @@ -162,8 +157,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.2.0"; } }; @@ -185,8 +179,7 @@ public class GithubMilestonesTests { return GithubMilestonesTests.this.repo.coordinates().user(); } - @Override String milestoneTitle(Milestone.Smart milestone) - throws IOException { + @Override String milestoneTitle(Milestone.Smart milestone) { return "0.1.0.BUILD-SNAPSHOT"; } }; diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/gradle/GradleUpdaterTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/gradle/GradleUpdaterTests.java index dc13cac5..893a9e5a 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/gradle/GradleUpdaterTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/gradle/GradleUpdaterTests.java @@ -56,7 +56,7 @@ public class GradleUpdaterTests { } @Test - public void should_throw_exception_if_snapshots_remain() throws IOException { + public void should_throw_exception_if_snapshots_remain() { File projectRoot = tmpFile("gradleproject"); ReleaserProperties properties = new ReleaserProperties(); Map props = new HashMap() {{ diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/BomParserTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/BomParserTests.java index 21cec612..1f5d3fd5 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/BomParserTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/BomParserTests.java @@ -22,7 +22,7 @@ public class BomParserTests { ReleaserProperties properties = new ReleaserProperties(); @Before - public void setup() throws IOException, URISyntaxException { + public void setup() throws URISyntaxException { this.springCloudReleaseProject = new File(GitRepoTests.class.getResource("/projects/spring-cloud-release").toURI()); } diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/LoggerToMavenLogTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/LoggerToMavenLogTests.java index 9d2477e5..7e7860d1 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/LoggerToMavenLogTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/LoggerToMavenLogTests.java @@ -19,97 +19,97 @@ public class LoggerToMavenLogTests { @InjectMocks LoggerToMavenLog loggerToMavenLog; RuntimeException exception = new RuntimeException(); - @Test public void isDebugEnabled() throws Exception { + @Test public void isDebugEnabled() { this.loggerToMavenLog.isDebugEnabled(); then(this.logger).should().isDebugEnabled(); } - @Test public void debug() throws Exception { + @Test public void debug() { this.loggerToMavenLog.debug("foo"); then(this.logger).should().debug("foo"); } - @Test public void debug1() throws Exception { + @Test public void debug1() { this.loggerToMavenLog.debug("foo", this.exception); then(this.logger).should().debug("foo", this.exception); } - @Test public void debug2() throws Exception { + @Test public void debug2() { this.loggerToMavenLog.debug(this.exception); then(this.logger).should().debug("Exception occurred", this.exception); } - @Test public void isInfoEnabled() throws Exception { + @Test public void isInfoEnabled() { this.loggerToMavenLog.isInfoEnabled(); then(this.logger).should().isInfoEnabled(); } - @Test public void info() throws Exception { + @Test public void info() { this.loggerToMavenLog.info("foo"); then(this.logger).should().info("foo"); } - @Test public void info1() throws Exception { + @Test public void info1() { this.loggerToMavenLog.info("foo", this.exception); then(this.logger).should().info("foo", this.exception); } - @Test public void info2() throws Exception { + @Test public void info2() { this.loggerToMavenLog.info(this.exception); then(this.logger).should().info("Exception occurred", this.exception); } - @Test public void isWarnEnabled() throws Exception { + @Test public void isWarnEnabled() { this.loggerToMavenLog.isWarnEnabled(); then(this.logger).should().isWarnEnabled(); } - @Test public void warn() throws Exception { + @Test public void warn() { this.loggerToMavenLog.warn("foo"); then(this.logger).should().warn("foo"); } - @Test public void warn1() throws Exception { + @Test public void warn1() { this.loggerToMavenLog.warn("foo", this.exception); then(this.logger).should().warn("foo", this.exception); } - @Test public void warn2() throws Exception { + @Test public void warn2() { this.loggerToMavenLog.warn(this.exception); then(this.logger).should().warn("Exception occurred", this.exception); } - @Test public void isErrorEnabled() throws Exception { + @Test public void isErrorEnabled() { this.loggerToMavenLog.isErrorEnabled(); then(this.logger).should().isErrorEnabled(); } - @Test public void error() throws Exception { + @Test public void error() { this.loggerToMavenLog.error("foo"); then(this.logger).should().error("foo"); } - @Test public void error1() throws Exception { + @Test public void error1() { this.loggerToMavenLog.error("foo", this.exception); then(this.logger).should().error("foo", this.exception); } - @Test public void error2() throws Exception { + @Test public void error2() { this.loggerToMavenLog.error(this.exception); then(this.logger).should().error("Exception occurred", this.exception); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/PropertyStorerTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/PropertyStorerTests.java index f111d01a..b816fdcc 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/PropertyStorerTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/pom/PropertyStorerTests.java @@ -21,7 +21,7 @@ public class PropertyStorerTests { @Mock ModifiedPomXMLEventReader pom; @InjectMocks PropertyStorer propertyStorer; - @Test public void should_not_set_a_version_when_its_empty() throws Exception { + @Test public void should_not_set_a_version_when_its_empty() { this.propertyStorer.setPropertyVersionIfApplicable(new Project("foo", "")); then(this.log).should().warn(containsWarnMsgAboutEmptyVersion()); diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/project/ProjectBuilderTests.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/project/ProjectBuilderTests.java index 646633f1..9ead32ae 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/project/ProjectBuilderTests.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/project/ProjectBuilderTests.java @@ -196,7 +196,7 @@ public class ProjectBuilderTests { } @Test - public void should_throw_exception_when_after_running_there_is_an_html_file_with_unresolved_tag() throws Exception { + public void should_throw_exception_when_after_running_there_is_an_html_file_with_unresolved_tag() { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setBuildCommand("ls -al"); properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); @@ -207,7 +207,7 @@ public class ProjectBuilderTests { } @Test - public void should_throw_exception_when_command_took_too_long_to_execute() throws Exception { + public void should_throw_exception_when_command_took_too_long_to_execute() { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setBuildCommand("sleep 1"); properties.getMaven().setWaitTimeInMinutes(0); @@ -312,7 +312,7 @@ public class ProjectBuilderTests { } @Test - public void should_throw_exception_when_deploy_command_took_too_long_to_execute() throws Exception { + public void should_throw_exception_when_deploy_command_took_too_long_to_execute() { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setDeployCommand("sleep 1"); properties.getMaven().setWaitTimeInMinutes(0); @@ -404,7 +404,7 @@ public class ProjectBuilderTests { } @Test - public void should_throw_exception_when_publish_docs_command_took_too_long_to_execute() throws Exception { + public void should_throw_exception_when_publish_docs_command_took_too_long_to_execute() { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setPublishDocsCommands(new String[] { "sleep 1", "sleep 1" }); properties.getMaven().setWaitTimeInMinutes(0); @@ -415,7 +415,7 @@ public class ProjectBuilderTests { } @Test - public void should_throw_exception_when_process_exits_with_invalid_code() throws Exception { + public void should_throw_exception_when_process_exits_with_invalid_code() { ReleaserProperties properties = new ReleaserProperties(); properties.getMaven().setBuildCommand("exit 1"); properties.setWorkingDir(tmpFile("/builder/unresolved").getPath()); @@ -423,7 +423,7 @@ public class ProjectBuilderTests { @Override ProcessExecutor executor(String workingDir) { return new ProcessExecutor(properties.getWorkingDir()) { - @Override Process startProcess(ProcessBuilder builder) throws IOException { + @Override Process startProcess(ProcessBuilder builder) { return processWithInvalidExitCode(); } }; @@ -448,7 +448,7 @@ public class ProjectBuilderTests { return null; } - @Override public int waitFor() throws InterruptedException { + @Override public int waitFor() { return 0; } diff --git a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/sagan/SaganUpdaterTest.java b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/sagan/SaganUpdaterTest.java index bbdc8467..943ef1aa 100644 --- a/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/sagan/SaganUpdaterTest.java +++ b/spring-cloud-release-tools-core/src/test/java/org/springframework/cloud/release/internal/sagan/SaganUpdaterTest.java @@ -44,7 +44,7 @@ public class SaganUpdaterTest { return release; } - @Test public void should_not_update_sagan_when_switch_is_off() throws Exception { + @Test public void should_not_update_sagan_when_switch_is_off() { this.properties.getSagan().setUpdateSagan(false); this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1")); @@ -52,7 +52,7 @@ public class SaganUpdaterTest { then(this.saganClient).shouldHaveZeroInteractions(); } - @Test public void should_update_sagan_for_milestone() throws Exception { + @Test public void should_update_sagan_for_milestone() { this.saganUpdater.updateSagan("master", version("1.0.0.M1"), version("1.0.0.M1")); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), @@ -60,7 +60,7 @@ public class SaganUpdaterTest { "http://cloud.spring.io/spring-cloud-static/foo/{version}/", "PRERELEASE"))); } - @Test public void should_update_sagan_for_rc() throws Exception { + @Test public void should_update_sagan_for_rc() { this.saganUpdater.updateSagan("master", version("1.0.0.RC1"), version("1.0.0.RC1")); then(this.saganClient).should().updateRelease(BDDMockito.eq("foo"), @@ -72,7 +72,7 @@ public class SaganUpdaterTest { return new ProjectVersion("foo", version); } - @Test public void should_update_sagan_from_master() throws Exception { + @Test public void should_update_sagan_from_master() { ProjectVersion projectVersion = version("1.0.0.BUILD-SNAPSHOT"); this.saganUpdater.updateSagan("master", projectVersion, projectVersion); @@ -82,7 +82,7 @@ public class SaganUpdaterTest { "http://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); } - @Test public void should_update_sagan_from_release_version() throws Exception { + @Test public void should_update_sagan_from_release_version() { ProjectVersion projectVersion = version("1.0.0.RELEASE"); this.saganUpdater.updateSagan("master", projectVersion, projectVersion); @@ -98,7 +98,7 @@ public class SaganUpdaterTest { "http://cloud.spring.io/foo/foo.html", "SNAPSHOT"))); } - @Test public void should_update_sagan_from_non_master() throws Exception { + @Test public void should_update_sagan_from_non_master() { ProjectVersion projectVersion = version("1.1.0.BUILD-SNAPSHOT"); this.saganUpdater.updateSagan("1.1.x", projectVersion, projectVersion); diff --git a/spring-cloud-release-tools-spring/pom.xml b/spring-cloud-release-tools-spring/pom.xml index f2144f99..4a2e8746 100644 --- a/spring-cloud-release-tools-spring/pom.xml +++ b/spring-cloud-release-tools-spring/pom.xml @@ -45,6 +45,11 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml + + com.jakewharton.fliptables + fliptables + 1.0.2 + org.springframework.boot diff --git a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java index 07facd2f..25b801b8 100644 --- a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java +++ b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/ReleaserApplication.java @@ -45,7 +45,7 @@ public class ReleaserApplication implements CommandLineRunner { @Autowired SpringReleaser releaser; @Autowired Parser parser; - @Override public void run(String... strings) throws Exception { + @Override public void run(String... strings) { Options options = this.parser.parse(strings); try { this.releaser.release(options); diff --git a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Task.java b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Task.java index 775ff3c7..7a660c6b 100644 --- a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Task.java +++ b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Task.java @@ -37,11 +37,11 @@ class Task { this.taskType = taskType; } - void execute(Args args) { + TaskAndException execute(Args args) { if (args.taskType != this.taskType) { log.info("Skipping [{}] since task type is [{}] and should be [{}]]", this.name, this.taskType, args.taskType); - return; + return TaskAndException.skipped(this); } try { boolean interactive = args.interactive; @@ -49,18 +49,28 @@ class Task { if (interactive) { boolean skipStep = stepSkipper.skipStep(); if (!skipStep) { - this.consumer.accept(args); + return runTask(args); } + return TaskAndException.skipped(this); } else { - this.consumer.accept(args); + return runTask(args); } } catch (Exception e) { - log.error("\n\n\nBUILD FAILED!!!\n\nException occurred for task <" + + log.error("\n\n\nBUILD FAILED!!!\n\nException occurred for project <" + + (args.project != null ? args.project.getName() : "") + "> task <" + this.name + "> \n\nwith description <" + this.description + ">\n\n", e); - throw e; + if (this.taskType == TaskType.RELEASE) { + throw e; + } + return TaskAndException.failure(this, e); } } + private TaskAndException runTask(Args args) { + this.consumer.accept(args); + return TaskAndException.success(this); + } + private void printLog(boolean interactive) { log.info("\n\n\n=== {} ===\n\n{} {}\n\n", this.header, this.description, interactive ? MSG : ""); } diff --git a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/TaskAndException.java b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/TaskAndException.java new file mode 100644 index 00000000..b3c3ece2 --- /dev/null +++ b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/TaskAndException.java @@ -0,0 +1,57 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.release.internal.spring; + +/** + * @author Marcin Grzejszczak + */ +class TaskAndException { + + final Task task; + final TaskState taskState; + final Exception exception; + + private TaskAndException(Task task, TaskState taskState) { + this.task = task; + this.taskState = taskState; + this.exception = null; + } + + private TaskAndException(Task task, TaskState taskState, Exception exception) { + this.task = task; + this.taskState = taskState; + this.exception = exception; + } + + static TaskAndException skipped(Task task) { + return new TaskAndException(task, TaskState.SKIPPED); + } + + static TaskAndException success(Task task) { + return new TaskAndException(task, TaskState.SUCCESS); + } + + static TaskAndException failure(Task task, Exception exception) { + return new TaskAndException(task, TaskState.FAILURE, exception); + } + + enum TaskState { + SKIPPED, SUCCESS, FAILURE + } +} + + diff --git a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Tasks.java b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Tasks.java index 30c2d0a2..1efb0bda 100644 --- a/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Tasks.java +++ b/spring-cloud-release-tools-spring/src/main/java/org/springframework/cloud/release/internal/spring/Tasks.java @@ -1,11 +1,18 @@ package org.springframework.cloud.release.internal.spring; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; +import com.jakewharton.fliptables.FlipTableConverters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.util.StringUtils; + /** * All tasks that can be executed by the releaser * @@ -135,23 +142,22 @@ class Tasks { static Task RELEASE = Tasks.task("release", "fr", "FULL RELEASE", "Perform a full release of this project without interruptions", - args -> DEFAULT_TASKS_PER_PROJECT.forEach(task -> task.execute(args))); + args -> new CompositeConsumer(DEFAULT_TASKS_PER_PROJECT).accept(args)); static Task POST_RELEASE = Tasks.task("postRelease", "pr", "POST RELEASE TASKS", "Perform post release tasks for this release without interruptions", - args -> DEFAULT_TASKS_PER_RELEASE.forEach(task -> task.execute(args)), + args -> new CompositeConsumer(DEFAULT_TASKS_PER_RELEASE).accept(args), TaskType.POST_RELEASE); static Task RELEASE_VERBOSE = Tasks.task("releaseVerbose", "r", "FULL VERBOSE RELEASE", "Perform a full release of this project in interactive mode (you'll be asked about skipping steps)", - args -> DEFAULT_TASKS_PER_PROJECT.forEach(task -> task.execute(args))); + args -> new CompositeConsumer(DEFAULT_TASKS_PER_PROJECT).accept(args)); static Task META_RELEASE = Tasks.task("metaRelease", "x", "META RELEASE", "Perform a meta release of projects", - args -> DEFAULT_TASKS_PER_PROJECT.forEach(task -> { - args.properties.getMetaRelease().setEnabled(true); - task.execute(args); - })); + args -> new CompositeConsumer(DEFAULT_TASKS_PER_PROJECT, + (args1 -> args.properties.getMetaRelease().setEnabled(true))) + .accept(args)); static final List COMPOSITE_TASKS = Stream.of( RELEASE, @@ -187,4 +193,83 @@ class Tasks { enum TaskType { RELEASE, POST_RELEASE +} + +class CompositeConsumer implements Consumer { + + private static final Logger log = LoggerFactory.getLogger(CompositeConsumer.class); + + private final List tasks; + private final Consumer setup; + + CompositeConsumer(List tasks) { + this.tasks = tasks; + this.setup = args -> {}; + } + + CompositeConsumer(List tasks, Consumer setup) { + this.tasks = tasks; + this.setup = setup; + } + + @Override + public void accept(Args args) { + this.setup.accept(args); + List table = this.tasks.stream() + .map(task -> new Table(task.execute(args))) + .collect(Collectors.toList()); + String string = "\n\n***** BUILD REPORT *****\n\n" + + FlipTableConverters.fromIterable(table, Table.class) + + "\n\n***** BUILD REPORT *****\n\n"; + List
brokenTasks = table.stream() + .filter(table1 -> StringUtils.hasText(table1.thrownException)) + .collect(Collectors.toList()); + if (!brokenTasks.isEmpty()) { + String brokenBuilds = "\n\n[BUILD UNSTABLE] One of the tasks is failing!\n\n" + + FlipTableConverters.fromIterable(brokenTasks, Table.class) + "\n\n"; + log.info(string + brokenBuilds); + throw new IllegalStateException("[BUILD UNSTABLE] One of the tasks is failing! + \n\n\n" + brokenBuilds); + } else { + log.info(string); + } + } + + +} + +class Table { + final String taskCaption; + final String taskDescription; + final String taskState; + final String thrownException; + + Table(TaskAndException tae) { + this.taskCaption = tae.task.name; + this.taskDescription = tae.task.description; + this.taskState = tae.taskState.name().toLowerCase(); + this.thrownException = tae.exception == null ? "" : Arrays + .stream(tae.exception.getStackTrace()) + .map(s -> { + String[] strings = s.toString().split("\\."); + return strings[strings.length - 3] + "." + strings[strings.length - 2] + "." + strings[strings.length - 1]; + }) + .limit(15) + .collect(Collectors.joining("\n")); + } + + public String getTaskCaption() { + return this.taskCaption; + } + + public String getTaskDescription() { + return this.taskDescription; + } + + public String getTaskState() { + return this.taskState; + } + + public String getThrownException() { + return this.thrownException; + } } \ No newline at end of file diff --git a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/docs/TestDocumentationUpdater.java b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/docs/TestDocumentationUpdater.java index fc623c72..ab837c69 100644 --- a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/docs/TestDocumentationUpdater.java +++ b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/docs/TestDocumentationUpdater.java @@ -40,7 +40,7 @@ public class TestDocumentationUpdater extends DocumentationUpdater { } @Override - String readIndexHtmlContents(File indexHtml) throws IOException { + String readIndexHtmlContents(File indexHtml) { return response(); } diff --git a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/AcceptanceTests.java b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/AcceptanceTests.java index 1f1f4379..3d8750cb 100644 --- a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/AcceptanceTests.java +++ b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/AcceptanceTests.java @@ -526,7 +526,7 @@ public class AcceptanceTests { return this.testPomReader.readPom(new File(dir, "pom.xml")); } - private File emailTemplate() throws URISyntaxException { + private File emailTemplate() { return new File("target/email.txt"); } @@ -534,15 +534,15 @@ public class AcceptanceTests { return new String(Files.readAllBytes(emailTemplate().toPath())); } - private File blogTemplate() throws URISyntaxException { + private File blogTemplate() { return new File("target/blog.md"); } - private File tweetTemplate() throws URISyntaxException { + private File tweetTemplate() { return new File("target/tweet.txt"); } - private File releaseNotesTemplate() throws URISyntaxException { + private File releaseNotesTemplate() { return new File("target/notes.md"); } @@ -620,7 +620,7 @@ public class AcceptanceTests { } private Releaser defaultReleaser(String expectedVersion, String projectName, - ReleaserProperties properties) throws Exception { + ReleaserProperties properties) { ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties); ProjectBuilder projectBuilder = new ProjectBuilder(properties); TestProjectGitHandler handler = new TestProjectGitHandler(properties, @@ -644,7 +644,7 @@ public class AcceptanceTests { return releaser; } - private Releaser defaultMetaReleaser(ReleaserProperties properties) throws Exception { + private Releaser defaultMetaReleaser(ReleaserProperties properties) { ProjectPomUpdater pomUpdater = new ProjectPomUpdater(properties); ProjectBuilder projectBuilder = new ProjectBuilder(properties); NonAssertingTestProjectGitHandler handler = new NonAssertingTestProjectGitHandler(properties); diff --git a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/CompositeConsumerTests.java b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/CompositeConsumerTests.java new file mode 100644 index 00000000..528f3bb6 --- /dev/null +++ b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/CompositeConsumerTests.java @@ -0,0 +1,58 @@ +/* + * Copyright 2013-2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.release.internal.spring; + +import java.util.Arrays; + +import org.assertj.core.api.BDDAssertions; +import org.junit.Test; + +/** + * @author Marcin Grzejszczak + */ +public class CompositeConsumerTests { + + @Test + public void should_throw_exception_for_a_release_task() { + CompositeConsumer compositeConsumer = new CompositeConsumer(Arrays.asList( + new Task("foo", "foo", "foo", "foo", + (args -> {})), + new Task("bar", "bar", "bar", "bar", + (args -> { throw new MyException(); })) + )); + + BDDAssertions.thenThrownBy(() -> + compositeConsumer.accept(new Args(TaskType.RELEASE))) + .isInstanceOf(MyException.class); + } + + @Test + public void should_throw_exception_for_a_post_release_task_after_creating_a_report() { + CompositeConsumer compositeConsumer = new CompositeConsumer(Arrays.asList( + new Task("foo", "foo", "foo", "foo", + (args -> {}), TaskType.POST_RELEASE), + new Task("bar", "bar", "bar", "bar", + (args -> { throw new MyException(); }), TaskType.POST_RELEASE) + )); + + BDDAssertions.thenThrownBy(() -> + compositeConsumer.accept(new Args(TaskType.POST_RELEASE))) + .isInstanceOf(IllegalStateException.class); + } +} + +class MyException extends RuntimeException {} \ No newline at end of file diff --git a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/OptionsProcessorTests.java b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/OptionsProcessorTests.java index ed4db166..4e822a62 100644 --- a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/OptionsProcessorTests.java +++ b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/OptionsProcessorTests.java @@ -50,7 +50,7 @@ public class OptionsProcessorTests { } @Test - public void should_throw_exception_when_an_invalid_option_was_picked() throws Exception { + public void should_throw_exception_when_an_invalid_option_was_picked() { Options options = nonInteractiveOpts().options(); thenThrownBy(() -> this.optionsProcessor.processOptions(options, args())) @@ -58,7 +58,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_after_the_provided_one_using_full_name() throws Exception { + public void should_execute_only_tasks_after_the_provided_one_using_full_name() { Options options = nonInteractiveOpts().startFrom("second").options(); this.optionsProcessor.processOptions(options, args()); @@ -70,7 +70,7 @@ public class OptionsProcessorTests { @Test - public void should_execute_only_tasks_after_the_provided_one_using_short_name() throws Exception { + public void should_execute_only_tasks_after_the_provided_one_using_short_name() { Options options = nonInteractiveOpts().startFrom("2").options(); this.optionsProcessor.processOptions(options, args()); @@ -81,7 +81,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_range_using_full_name() throws Exception { + public void should_execute_only_tasks_from_range_using_full_name() { Options options = nonInteractiveOpts().range("second-third").options(); this.optionsProcessor.processOptions(options, args()); @@ -92,7 +92,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_range_using_short_name() throws Exception { + public void should_execute_only_tasks_from_range_using_short_name() { Options options = nonInteractiveOpts().range("2-3").options(); this.optionsProcessor.processOptions(options, args()); @@ -103,7 +103,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_range_using_full_name_with_same_range() throws Exception { + public void should_execute_only_tasks_from_range_using_full_name_with_same_range() { Options options = nonInteractiveOpts().range("second-second").options(); this.optionsProcessor.processOptions(options, args()); @@ -114,7 +114,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_range_using_short_name_with_same_range() throws Exception { + public void should_execute_only_tasks_from_range_using_short_name_with_same_range() { Options options = nonInteractiveOpts().range("2-2").options(); this.optionsProcessor.processOptions(options, args()); @@ -125,7 +125,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_multi_using_full_name() throws Exception { + public void should_execute_only_tasks_from_multi_using_full_name() { Options options = nonInteractiveOpts().taskNames(list("first", "third")).options(); this.optionsProcessor.processOptions(options, args()); @@ -136,7 +136,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_only_tasks_from_multi_using_short_name() throws Exception { + public void should_execute_only_tasks_from_multi_using_short_name() { Options options = nonInteractiveOpts().taskNames(list("1", "3")).options(); this.optionsProcessor.processOptions(options, args()); @@ -147,7 +147,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_interactively_only_single_task() throws Exception { + public void should_execute_interactively_only_single_task() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override String chosenOption() { return "0"; @@ -163,7 +163,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_interactively_range_of_tasks() throws Exception { + public void should_execute_interactively_range_of_tasks() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override String chosenOption() { return "0-1"; @@ -179,7 +179,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_interactively_start_from() throws Exception { + public void should_execute_interactively_start_from() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override String chosenOption() { return "1-"; @@ -195,7 +195,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_interactively_multi() throws Exception { + public void should_execute_interactively_multi() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override String chosenOption() { return "0,2"; @@ -211,7 +211,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_full_release() throws Exception { + public void should_execute_full_release() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override Task releaseTask() { return OptionsProcessorTests.this.firstTask; @@ -231,7 +231,7 @@ public class OptionsProcessorTests { } @Test - public void should_execute_full_verbose_release() throws Exception { + public void should_execute_full_verbose_release() { this.optionsProcessor = new OptionsProcessor(this.releaser, new ReleaserProperties(), this.tasks) { @Override Task releaseVerboseTask() { return OptionsProcessorTests.this.firstTask; @@ -251,7 +251,7 @@ public class OptionsProcessorTests { } @Test - public void should_remove_single_quotes() throws Exception { + public void should_remove_single_quotes() { Options options = interactiveOpts().fullRelease(true) .range("'1-2'") .startFrom("'c'") diff --git a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/TaskTests.java b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/TaskTests.java index 995e1840..8e31bb56 100644 --- a/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/TaskTests.java +++ b/spring-cloud-release-tools-spring/src/test/java/org/springframework/cloud/release/internal/spring/TaskTests.java @@ -43,7 +43,7 @@ public class TaskTests { then(someBool.get()).isTrue(); then(this.capture.toString()) .contains("BUILD FAILED!!!") - .contains("Exception occurred for task ") + .contains("Exception occurred for project <> task ") .contains("with description "); } } \ No newline at end of file