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 f79edb21..d7595f60 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 @@ -33,12 +33,16 @@ public class AbstractSpringCloudAcceptanceTests extends AbstractSpringAcceptance public File springCloudBuildProject; + public File springCloudBusProject; + @BeforeEach public void setupCloud() throws Exception { this.springCloudConsulProject = new File( AbstractSpringAcceptanceTests.class.getResource("/projects/spring-cloud-consul").toURI()); this.springCloudBuildProject = new File( AbstractSpringAcceptanceTests.class.getResource("/projects/spring-cloud-build").toURI()); + this.springCloudBusProject = new File( + AbstractSpringAcceptanceTests.class.getResource("/projects/spring-cloud-bus").toURI()); TestUtils.prepareLocalRepo(); FileSystemUtils.copyRecursively(file("/projects/"), this.temporaryFolder); } 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 f83808c4..6296b8cf 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 @@ -100,7 +100,7 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc .properties("test.metarelease=true", "releaser.git.create-release-notes-for-milestone=false") .properties(metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud, tempDirReleaseTrainWiki, tempDirAllTestSample).bomBranch("v2022.0.2") - .addFixedVersions(v2022_0_4()).distributeReleaseTrainSourceReleaseBundle(true) + .addFixedVersions(v2022_0_6()).distributeReleaseTrainSourceReleaseBundle(true) .releaseTrainSourceReleaseBundle(true).projectReleaseBundle(true).commercial(true) .build()), context -> { @@ -131,12 +131,12 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc thenUpdateReleaseTrainDocsWasCalled(postReleaseActions); BDDMockito.then(creator).should(times(1)) .createReleaseTrainSourceBundle(List.of(new ProjectVersion("spring-cloud-consul", "4.0.2"), - new ProjectVersion("spring-cloud-starter-build", "2022.0.4")), "2022.0.4"); + new ProjectVersion("spring-cloud-starter-build", "2022.0.6")), "2022.0.6"); BDDMockito.then(creator).should(times(1)).createReleaseBundle( List.of("org/springframework/cloud/spring-cloud-consul*", "org/springframework/cloud/spring-cloud-starter-consul*"), "4.0.2", "TNZ-spring-cloud-consul-commercial"); - BDDMockito.then(creator).should(times(1)).distributeReleaseTrainSourceBundle("2022.0.4"); + BDDMockito.then(creator).should(times(1)).distributeReleaseTrainSourceBundle("2022.0.6"); // This should never be called when releasing a release train since // distributing a release train source bundle // will distribute individual project release bundles @@ -158,7 +158,7 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc .properties("test.metarelease=true", "releaser.git.create-release-notes-for-milestone=false") .properties(metaReleaseArgsForParallel(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud, tempDirReleaseTrainWiki, tempDirAllTestSample).bomBranch("v2022.0.2") - .addFixedVersions(v2022_0_4()) + .addFixedVersions(v2022_0_6()) .metaReleaseGroups("example1,example2", "spring-cloud-build,spring-cloud-consul,spring-cloud-release") .build()), @@ -207,7 +207,7 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc properties("debugx=true").properties("test.metarelease=true") .properties(metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud, tempDirReleaseTrainWiki, tempDirAllTestSample) - .bomBranch("v2022.0.2").addFixedVersions(v2022_0_4()).build()), + .bomBranch("v2022.0.2").addFixedVersions(v2022_0_6()).build()), context -> { SpringReleaser releaser = context.getBean(SpringReleaser.class); NonAssertingTestProjectGitHandler nonAssertingTestProjectGitHandler = context @@ -375,7 +375,7 @@ public class SpringMetaReleaseAcceptanceTests extends AbstractSpringCloudMetaAcc "releaser.flow.default-enabled=false") .properties(metaReleaseArgs(project, tempDirTestSamplesProject, tempDirReleaseTrainDocs, tempDirSpringCloud, tempDirReleaseTrainWiki, tempDirAllTestSample) - .bomBranch("v2022.0.2").addFixedVersions(v2022_0_4()).build()), + .bomBranch("v2022.0.2").addFixedVersions(v2022_0_6()).build()), context -> { SpringReleaser releaser = context.getBean(SpringReleaser.class); NonAssertingTestProjectGitHandler nonAssertingTestProjectGitHandler = context 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 7dbcc784..8ab76f3d 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 @@ -136,6 +136,7 @@ public class SpringSingleProjectAcceptanceTests extends AbstractSpringCloudAccep Iterable commits = listOfCommits(project); Iterator iterator = commits.iterator(); tagIsPresentInOrigin(origin, "v4.0.2"); + commitIsPresent(iterator, "Bumping dependency versions after release"); commitIsPresent(iterator, "Bumping versions to 4.0.3-SNAPSHOT after release"); commitIsPresent(iterator, "Going back to snapshots"); commitIsPresent(iterator, "Update SNAPSHOT to 4.0.2"); @@ -169,6 +170,71 @@ public class SpringSingleProjectAcceptanceTests extends AbstractSpringCloudAccep }); } + // This test verifies that the actual antora documentation generation actually works + // during a release. + // We use Spring Cloud Bus as an example project and override the test antora build + // and sync commands in the ArgsBuilder + // configuration. The anotra command is the actual antora command to build the docs. + // The docs sync command checks that the index.html + // file for the release and the snapshot exist. + @Test + public void should_perform_a_release_of_sc_bus(@TempDir File tempDirSpringCloudBusOrigin, + @TempDir File tempDirSpringCloudBusProject) throws Exception { + checkoutReleaseTrainBranch("/projects/spring-cloud-release/", "v2023.0.3"); + File origin = cloneToTemporaryDirectory(tempDirSpringCloudBusOrigin, this.springCloudBusProject); + pomVersionIsEqualTo(origin, "4.1.2-SNAPSHOT"); + pomParentVersionIsEqualTo(origin, "spring-cloud-bus-dependencies", "4.1.3-SNAPSHOT"); + File project = cloneToTemporaryDirectory(tempDirSpringCloudBusProject, tmpFile("spring-cloud-bus")); + GitTestUtils.setOriginOnProjectToTmp(origin, project); + + run(this.runner, properties("debugx=true").properties(new ArgsBuilder(project, tempDirTestSamplesProject, + tempDirReleaseTrainDocs, tempDirSpringCloud, tempDirReleaseTrainWiki, tempDirAllTestSample) + .releaseTrainUrl("/projects/spring-cloud-release/").bomBranch("v2023.0.3") + .projectName("spring-cloud-bus").expectedVersion("4.1.2") + .antoraCommand("./mvnw clean antora -Pdocs") + .syncAntoraDocsCommand( + "[ -f {{site-path}}/index.html ] && [ -f {{site-path}}/4.1-SNAPSHOT/index.html ]") + .build()), + context -> { + SpringReleaser releaser = context.getBean(SpringReleaser.class); + TestProjectGitHubHandler gitHubHandler = context.getBean(TestProjectGitHubHandler.class); + SaganClient saganClient = context.getBean(SaganClient.class); + PostReleaseActions postReleaseActions = context.getBean(PostReleaseActions.class); + TestExecutionResultHandler testExecutionResultHandler = context + .getBean(TestExecutionResultHandler.class); + + ExecutionResult result = releaser.release(new OptionsBuilder().interactive(true).options()); + + Iterable commits = listOfCommits(project); + Iterator iterator = commits.iterator(); + then(GitTestUtils.openGitProject(origin).tagList().call().stream() + .anyMatch(r -> r.getName().equals("refs/tags/v4.1.2"))).isTrue(); + commitIsPresent(iterator, "Bumping dependency versions after release"); + commitIsPresent(iterator, "Bumping versions to 4.1.3-SNAPSHOT after release"); + commitIsPresent(iterator, "Going back to snapshots"); + commitIsPresent(iterator, "Update SNAPSHOT to 4.1.2"); + pomVersionIsEqualTo(project, "4.1.3-SNAPSHOT"); + pomParentVersionIsEqualTo(project, "spring-cloud-bus-dependencies", "4.1.4-SNAPSHOT"); + then(gitHubHandler.closedMilestones).isTrue(); + then(emailTemplate()).doesNotExist(); + then(blogTemplate()).doesNotExist(); + then(tweetTemplate()).doesNotExist(); + then(releaseNotesTemplate()).doesNotExist(); + // once for updating GA + // second time to update SNAPSHOT + BDDMockito.then(saganClient).should(times(2)).addRelease(BDDMockito.eq("spring-cloud-bus"), + BDDMockito.any()); + BDDMockito.then(saganClient).should().deleteRelease("spring-cloud-bus", "4.1.2-SNAPSHOT"); + then(gitHubHandler.issueCreatedInSpringGuides).isFalse(); + then(gitHubHandler.issueCreatedInStartSpringIo).isFalse(); + thenRunUpdatedTestsWereNotCalled(postReleaseActions); + + // print results + testExecutionResultHandler.accept(result); + then(testExecutionResultHandler.exitedSuccessOrUnstable).isTrue(); + }); + } + // issue #74 @Test public void should_perform_a_release_of_sc_build(@TempDir File tempDirSpringCloudConsulOrigin, @@ -198,6 +264,7 @@ public class SpringSingleProjectAcceptanceTests extends AbstractSpringCloudAccep Iterator iterator = commits.iterator(); tagIsPresentInOrigin(origin, "v2.1.6.RELEASE"); // we're running against camden sc-release + commitIsPresent(iterator, "Bumping dependency versions after release"); commitIsPresent(iterator, "Bumping versions to 2.1.7.SNAPSHOT after release"); commitIsPresent(iterator, "Going back to snapshots"); commitIsPresent(iterator, "Update SNAPSHOT to 2.1.6.RELEASE"); diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.editorconfig b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.editorconfig new file mode 100644 index 00000000..e65ee453 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = tab +indent_size = 4 +end_of_line = lf +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/CONTRIBUTING.md b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/CONTRIBUTING.md new file mode 100644 index 00000000..eb9a16ae --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/CONTRIBUTING.md @@ -0,0 +1,45 @@ + +# Contributing + +Spring Cloud is released under the non-restrictive Apache 2.0 license, +and follows a very standard Github development process, using Github +tracker for issues and merging pull requests into master. If you want +to contribute even something trivial please do not hesitate, but +follow the guidelines below. + +## Sign the Contributor License Agreement +Before we accept a non-trivial patch or pull request we will need you to sign the +[Contributor License Agreement](https://cla.pivotal.io/sign/spring). +Signing the contributor's agreement does not grant anyone commit rights to the main +repository, but it does mean that we can accept your contributions, and you will get an +author credit if we do. Active contributors might be asked to join the core team, and +given the ability to merge pull requests. + +## Code of Conduct +This project adheres to the Contributor Covenant [code of +conduct](https://github.com/spring-cloud/spring-cloud-build/blob/master/docs/src/main/asciidoc/code-of-conduct.adoc). By participating, you are expected to uphold this code. Please report +unacceptable behavior to spring-code-of-conduct@pivotal.io. + +## Code Conventions and Housekeeping +None of these is essential for a pull request, but they will all help. They can also be +added after the original pull request but before a merge. + +* Use the Spring Framework code format conventions. If you use Eclipse + you can import formatter settings using the + `eclipse-code-formatter.xml` file from the + [Spring Cloud Build](https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/spring-cloud-dependencies-parent/eclipse-code-formatter.xml) project. If using IntelliJ, you can use the + [Eclipse Code Formatter Plugin](https://plugins.jetbrains.com/plugin/6546) to import the same file. +* Make sure all new `.java` files to have a simple Javadoc class comment with at least an + `@author` tag identifying you, and preferably at least a paragraph on what the class is + for. +* Add the ASF license header comment to all new `.java` files (copy from existing files + in the project) +* Add yourself as an `@author` to the .java files that you modify substantially (more + than cosmetic changes). +* Add some Javadocs and, if you change the namespace, some XSD doc elements. +* A few unit tests would help a lot as well -- someone has to do it. +* If no-one else is using your branch, please rebase it against the current master (or + other target branch in the main project). +* When writing a commit message please follow [these conventions](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), + if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit + message (where XXXX is the issue number). diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE.md b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..0bc5ef4f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,20 @@ + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/bug_report.md b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..aeafef9d --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,17 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +Please provide details of the problem, including the version of Spring Cloud that you +are using. + +**Sample** +If possible, please provide a test case or sample application that reproduces +the problem. This makes it much easier for us to diagnose the problem and to verify that +we have fixed it. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/feature_request.md b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..bbcbbe7d --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/deploy-docs.yml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/deploy-docs.yml new file mode 100644 index 00000000..be4b92df --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/deploy-docs.yml @@ -0,0 +1,32 @@ +name: Deploy Docs +on: + push: + branches-ignore: [ gh-pages ] + tags: '**' + repository_dispatch: + types: request-build-reference # legacy + #schedule: + #- cron: '0 10 * * *' # Once per day at 10am UTC + workflow_dispatch: +permissions: + actions: write +jobs: + build: + runs-on: ubuntu-latest + # if: github.repository_owner == 'spring-cloud' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: docs-build + fetch-depth: 1 + - name: Dispatch (partial build) + if: github.ref_type == 'branch' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) -f build-refname=${{ github.ref_name }} + - name: Dispatch (full build) + if: github.ref_type == 'tag' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh workflow run deploy-docs.yml -r $(git rev-parse --abbrev-ref HEAD) diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/maven.yaml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/maven.yaml new file mode 100644 index 00000000..a55f1443 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.github/workflows/maven.yaml @@ -0,0 +1,38 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Build +on: + push: + branches: [ main, 3.1.x ] + pull_request: + branches: [ main, 3.1.x ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '17' + - name: Cache local Maven repository + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Build with Maven + run: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + - name: Publish Test Report + uses: mikepenz/action-junit-report@v2 + if: always() # always run even if the previous step fails + with: + report_paths: '**/surefire-reports/TEST-*.xml' + - name: Archive code coverage results + uses: actions/upload-artifact@v2 + with: + name: surefire-reports + path: '**/surefire-reports/*' diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.gitignore b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.gitignore new file mode 100644 index 00000000..3aba1706 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.gitignore @@ -0,0 +1,26 @@ +*~ +#* +*# +.#* +.classpath +.project +.settings +.springBeans +.gradle +build +bin +target/ +_site/ +*.swp +.idea +*.iml +.factorypath +.vscode/ +.flattened-pom.xml + + +node +node_modules +build +/package.json +package-lock.json diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/jvm.config b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/jvm.config new file mode 100644 index 00000000..0e7dabef --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/jvm.config @@ -0,0 +1 @@ +-Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/maven.config b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/maven.config new file mode 100644 index 00000000..a6829905 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/maven.config @@ -0,0 +1 @@ +-P spring diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/MavenWrapperDownloader.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 00000000..b901097f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,117 @@ +/* + * Copyright 2007-present 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. + */ +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + private static final String WRAPPER_VERSION = "0.5.6"; + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" + + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + String username = System.getenv("MVNW_USERNAME"); + char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.jar b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 00000000..2cc7d4a5 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.jar differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.properties b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..598fb341 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.settings.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.settings.xml new file mode 100644 index 00000000..a50de34a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.settings.xml @@ -0,0 +1,68 @@ + + + + + repo.spring.io + ${env.CI_DEPLOY_USERNAME} + ${env.CI_DEPLOY_PASSWORD} + + + + + + spring + + true + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.springformat b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/.springformat new file mode 100644 index 00000000..e69de29b diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/Guardfile b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/Guardfile new file mode 100644 index 00000000..b5561567 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/Guardfile @@ -0,0 +1,12 @@ +require 'asciidoctor' +require 'erb' +require './src/main/ruby/readme.rb' + +options = {:mkdirs => true, :safe => :unsafe, :attributes => ['linkcss', 'allow-uri-read']} + +guard 'shell' do + watch(/^src\/[A-Z-a-z][^#]*\.adoc$/) {|m| + SpringCloud::Build.render_file('src/main/asciidoc/README.adoc', :to_file => './README.adoc') + Asciidoctor.render_file('src/main/asciidoc/spring-cloud-bus.adoc', options.merge(:to_dir => 'target/generated-docs')) + } +end diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/LICENSE.txt b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/LICENSE.txt new file mode 100644 index 00000000..62589edd --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/README.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/README.adoc new file mode 100644 index 00000000..7726d92a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/README.adoc @@ -0,0 +1,349 @@ +//// +DO NOT EDIT THIS FILE. IT WAS GENERATED. +Manual changes to this file will be lost when it is generated again. +Edit the files in the src/main/asciidoc/ directory instead. +//// + + +[[spring-cloud-bus]] += Spring Cloud Bus +:page-section-summary-toc: 1 + + +[[quick-start]] +== Quick Start + + +[[building]] +== Building + +:jdkversion: 17 + +[[basic-compile-and-test]] +== Basic Compile and Test + +To build the source you will need to install JDK {jdkversion}. + +Spring Cloud uses Maven for most build-related activities, and you +should be able to get off the ground quite quickly by cloning the +project you are interested in and typing + +---- +$ ./mvnw install +---- + +NOTE: You can also install Maven (>=3.3.3) yourself and run the `mvn` command +in place of `./mvnw` in the examples below. If you do that you also +might need to add `-P spring` if your local Maven settings do not +contain repository declarations for spring pre-release artifacts. + +NOTE: Be aware that you might need to increase the amount of memory +available to Maven by setting a `MAVEN_OPTS` environment variable with +a value like `-Xmx512m -XX:MaxPermSize=128m`. We try to cover this in +the `.mvn` configuration, so if you find you have to do it to make a +build succeed, please raise a ticket to get the settings added to +source control. + +The projects that require middleware (i.e. Redis) for testing generally +require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. + +[[documentation]] +== Documentation + +The spring-cloud-build module has a "docs" profile, and if you switch +that on it will try to build asciidoc sources using https://docs.antora.org/antora/latest/[Antora] from +`modules/ROOT/`. + +As part of that process it will look for a +`docs/src/main/asciidoc/README.adoc` and process it by loading all the includes, but not +parsing or rendering it, just copying it to `${main.basedir}` +(defaults to `$\{basedir}`, i.e. the root of the project). If there are +any changes in the README it will then show up after a Maven build as +a modified file in the correct place. Just commit it and push the change. + +[[working-with-the-code]] +== Working with the code +If you don't have an IDE preference we would recommend that you use +https://www.springsource.com/developer/sts[Spring Tools Suite] or +https://eclipse.org[Eclipse] when working with the code. We use the +https://eclipse.org/m2e/[m2eclipse] eclipse plugin for maven support. Other IDEs and tools +should also work without issue as long as they use Maven 3.3.3 or better. + +[[activate-the-spring-maven-profile]] +=== Activate the Spring Maven profile +Spring Cloud projects require the 'spring' Maven profile to be activated to resolve +the spring milestone and snapshot repositories. Use your preferred IDE to set this +profile to be active, or you may experience build errors. + +[[importing-into-eclipse-with-m2eclipse]] +=== Importing into eclipse with m2eclipse +We recommend the https://eclipse.org/m2e/[m2eclipse] eclipse plugin when working with +eclipse. If you don't already have m2eclipse installed it is available from the "eclipse +marketplace". + +NOTE: Older versions of m2e do not support Maven 3.3, so once the +projects are imported into Eclipse you will also need to tell +m2eclipse to use the right profile for the projects. If you +see many different errors related to the POMs in the projects, check +that you have an up to date installation. If you can't upgrade m2e, +add the "spring" profile to your `settings.xml`. Alternatively you can +copy the repository settings from the "spring" profile of the parent +pom into your `settings.xml`. + +[[importing-into-eclipse-without-m2eclipse]] +=== Importing into eclipse without m2eclipse +If you prefer not to use m2eclipse you can generate eclipse project metadata using the +following command: + +[indent=0] +---- + $ ./mvnw eclipse:eclipse +---- + +The generated eclipse projects can be imported by selecting `import existing projects` +from the `file` menu. + + +[[contributing]] +== Contributing + +:spring-cloud-build-branch: main + +Spring Cloud is released under the non-restrictive Apache 2.0 license, +and follows a very standard Github development process, using Github +tracker for issues and merging pull requests into main. If you want +to contribute even something trivial please do not hesitate, but +follow the guidelines below. + +[[sign-the-contributor-license-agreement]] +== Sign the Contributor License Agreement + +Before we accept a non-trivial patch or pull request we will need you to sign the +https://cla.pivotal.io/sign/spring[Contributor License Agreement]. +Signing the contributor's agreement does not grant anyone commit rights to the main +repository, but it does mean that we can accept your contributions, and you will get an +author credit if we do. Active contributors might be asked to join the core team, and +given the ability to merge pull requests. + +[[code-of-conduct]] +== Code of Conduct +This project adheres to the Contributor Covenant https://github.com/spring-cloud/spring-cloud-build/blob/main/docs/src/main/asciidoc/code-of-conduct.adoc[code of +conduct]. By participating, you are expected to uphold this code. Please report +unacceptable behavior to spring-code-of-conduct@pivotal.io. + +[[code-conventions-and-housekeeping]] +== Code Conventions and Housekeeping +None of these is essential for a pull request, but they will all help. They can also be +added after the original pull request but before a merge. + +* Use the Spring Framework code format conventions. If you use Eclipse + you can import formatter settings using the + `eclipse-code-formatter.xml` file from the + https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-dependencies-parent/eclipse-code-formatter.xml[Spring + Cloud Build] project. If using IntelliJ, you can use the + https://plugins.jetbrains.com/plugin/6546[Eclipse Code Formatter + Plugin] to import the same file. +* Make sure all new `.java` files to have a simple Javadoc class comment with at least an + `@author` tag identifying you, and preferably at least a paragraph on what the class is + for. +* Add the ASF license header comment to all new `.java` files (copy from existing files + in the project) +* Add yourself as an `@author` to the .java files that you modify substantially (more + than cosmetic changes). +* Add some Javadocs and, if you change the namespace, some XSD doc elements. +* A few unit tests would help a lot as well -- someone has to do it. +* If no-one else is using your branch, please rebase it against the current main (or + other target branch in the main project). +* When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions], + if you are fixing an existing issue please add `Fixes gh-XXXX` at the end of the commit + message (where XXXX is the issue number). + +[[checkstyle]] +== Checkstyle + +Spring Cloud Build comes with a set of checkstyle rules. You can find them in the `spring-cloud-build-tools` module. The most notable files under the module are: + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    └── checkstyle.xml <1> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules + +[[checkstyle-configuration]] +=== Checkstyle configuration + +Checkstyle rules are *disabled by default*. To add checkstyle to your project just define the following properties and plugins. + +.pom.xml +---- + +true <1> + true + <2> + true + <3> + + + + + <4> + io.spring.javaformat + spring-javaformat-maven-plugin + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + <5> + org.apache.maven.plugins + maven-checkstyle-plugin + + + + +---- +<1> Fails the build upon Checkstyle errors +<2> Fails the build upon Checkstyle violations +<3> Checkstyle analyzes also the test sources +<4> Add the Spring Java Format plugin that will reformat your code to pass most of the Checkstyle formatting rules +<5> Add checkstyle plugin to your build and reporting phases + +If you need to suppress some rules (e.g. line length needs to be longer), then it's enough for you to define a file under `${project.root}/src/checkstyle/checkstyle-suppressions.xml` with your suppressions. Example: + +.projectRoot/src/checkstyle/checkstyle-suppresions.xml +---- + + + + + + +---- + +It's advisable to copy the `${spring-cloud-build.rootFolder}/.editorconfig` and `${spring-cloud-build.rootFolder}/.springformat` to your project. That way, some default formatting rules will be applied. You can do so by running this script: + +```bash +$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/.editorconfig -o .editorconfig +$ touch .springformat +``` + +[[ide-setup]] +== IDE setup + +[[intellij-idea]] +=== Intellij IDEA + +In order to setup Intellij you should import our coding conventions, inspection profiles and set up the checkstyle plugin. +The following files can be found in the https://github.com/spring-cloud/spring-cloud-build/tree/main/spring-cloud-build-tools[Spring Cloud Build] project. + +.spring-cloud-build-tools/ +---- +└── src +    ├── checkstyle +    │   └── checkstyle-suppressions.xml <3> +    └── main +    └── resources +    ├── checkstyle-header.txt <2> +    ├── checkstyle.xml <1> +    └── intellij +       ├── Intellij_Project_Defaults.xml <4> +       └── Intellij_Spring_Boot_Java_Conventions.xml <5> +---- +<1> Default Checkstyle rules +<2> File header setup +<3> Default suppression rules +<4> Project defaults for Intellij that apply most of Checkstyle rules +<5> Project style conventions for Intellij that apply most of Checkstyle rules + +.Code style + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/assets/images/intellij-code-style.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Code style`. There click on the icon next to the `Scheme` section. There, click on the `Import Scheme` value and pick the `Intellij IDEA code style XML` option. Import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Spring_Boot_Java_Conventions.xml` file. + +.Inspection profiles + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/assets/images/intellij-inspections.png[Code style] + +Go to `File` -> `Settings` -> `Editor` -> `Inspections`. There click on the icon next to the `Profile` section. There, click on the `Import Profile` and import the `spring-cloud-build-tools/src/main/resources/intellij/Intellij_Project_Defaults.xml` file. + +.Checkstyle + +To have Intellij work with Checkstyle, you have to install the `Checkstyle` plugin. It's advisable to also install the `Assertions2Assertj` to automatically convert the JUnit assertions + +image::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/assets/images/intellij-checkstyle.png[Checkstyle] + +Go to `File` -> `Settings` -> `Other settings` -> `Checkstyle`. There click on the `+` icon in the `Configuration file` section. There, you'll have to define where the checkstyle rules should be picked from. In the image above, we've picked the rules from the cloned Spring Cloud Build repository. However, you can point to the Spring Cloud Build's GitHub repository (e.g. for the `checkstyle.xml` : `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/main/resources/checkstyle.xml`). We need to provide the following variables: + +- `checkstyle.header.file` - please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/main/resources/checkstyle-header.txt` URL. +- `checkstyle.suppressions.file` - default suppressions. Please point it to the Spring Cloud Build's, `spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` file either in your cloned repo or via the `https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/spring-cloud-build-tools/src/checkstyle/checkstyle-suppressions.xml` URL. +- `checkstyle.additional.suppressions.file` - this variable corresponds to suppressions in your local project. E.g. you're working on `spring-cloud-contract`. Then point to the `project-root/src/checkstyle/checkstyle-suppressions.xml` folder. Example for `spring-cloud-contract` would be: `/home/username/spring-cloud-contract/src/checkstyle/checkstyle-suppressions.xml`. + +IMPORTANT: Remember to set the `Scan Scope` to `All sources` since we apply checkstyle rules for production and test sources. + +[[duplicate-finder]] +== Duplicate Finder + +Spring Cloud Build brings along the `basepom:duplicate-finder-maven-plugin`, that enables flagging duplicate and conflicting classes and resources on the java classpath. + +[[duplicate-finder-configuration]] +=== Duplicate Finder configuration + +Duplicate finder is *enabled by default* and will run in the `verify` phase of your Maven build, but it will only take effect in your project if you add the `duplicate-finder-maven-plugin` to the `build` section of the projecst's `pom.xml`. + +.pom.xml +[source,xml] +---- + + + + org.basepom.maven + duplicate-finder-maven-plugin + + + +---- + +For other properties, we have set defaults as listed in the https://github.com/basepom/duplicate-finder-maven-plugin/wiki[plugin documentation]. + +You can easily override them but setting the value of the selected property prefixed with `duplicate-finder-maven-plugin`. For example, set `duplicate-finder-maven-plugin.skip` to `true` in order to skip duplicates check in your build. + +If you need to add `ignoredClassPatterns` or `ignoredResourcePatterns` to your setup, make sure to add them in the plugin configuration section of your project: + +[source,xml] +---- + + + + org.basepom.maven + duplicate-finder-maven-plugin + + + org.joda.time.base.BaseDateTime + .*module-info + + + changelog.txt + + + + + + + +---- + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/SECURITY.md b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/SECURITY.md new file mode 100644 index 00000000..04685956 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/SECURITY.md @@ -0,0 +1,5 @@ +# Security Policy + +## Reporting a Vulnerability + +To report security vulnerabilities, please go to https://pivotal.io/security. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora-playbook.yml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora-playbook.yml new file mode 100644 index 00000000..06bba579 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora-playbook.yml @@ -0,0 +1,33 @@ +antora: + extensions: + - require: '@springio/antora-extensions' + root_component_name: 'cloud-bus' +site: + title: Spring Cloud Bus + url: https://docs.spring.io/spring-cloud-bus/reference/ +content: + sources: + - url: ./.. + branches: HEAD + start_path: docs + worktrees: true +asciidoc: + attributes: + page-stackoverflow-url: https://stackoverflow.com/tags/spring-cloud + page-pagination: '' + hide-uri-scheme: '@' + tabs-sync-option: '@' + chomp: 'all' + extensions: + - '@asciidoctor/tabs' + - '@springio/asciidoctor-extensions' + sourcemap: true +urls: + latest_version_segment: '' +runtime: + log: + failure_level: warn + format: pretty +ui: + bundle: + url: https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.15/ui-bundle.zip diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora.yml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora.yml new file mode 100644 index 00000000..5b7ac25e --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/antora.yml @@ -0,0 +1,12 @@ +name: cloud-bus +version: true +title: spring-cloud-bus +nav: + - modules/ROOT/nav.adoc +ext: + collector: + run: + command: ./mvnw --no-transfer-progress -B process-resources -Pdocs -pl docs -Dantora-maven-plugin.phase=none -Dgenerate-docs.phase=none -Dgenerate-readme.phase=none -Dgenerate-cloud-resources.phase=none -Dmaven-dependency-plugin-for-docs.phase=none -Dmaven-dependency-plugin-for-docs-classes.phase=none -DskipTests + local: true + scan: + dir: ./target/classes/antora-resources/ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/nav.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/nav.adoc new file mode 100644 index 00000000..1702d2a2 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/nav.adoc @@ -0,0 +1,8 @@ +* xref:index.adoc[] +* xref:quickstart.adoc[] +* xref:spring-cloud-bus.adoc[] +** xref:spring-cloud-bus/bus-endpoints.adoc[] +** xref:spring-cloud-bus/addressing.adoc[] +** xref:spring-cloud-bus/configuration.adoc[] +** xref:spring-cloud-bus/custom-events.adoc[] +* xref:appendix.adoc[] diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/_attributes.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/_attributes.adoc new file mode 100644 index 00000000..c84b3ee6 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/_attributes.adoc @@ -0,0 +1,13 @@ +:doctype: book +:idprefix: +:idseparator: - +:tabsize: 4 +:numbered: +:sectanchors: +:sectnums: +:icons: font +:hide-uri-scheme: +:docinfo: shared,private + +:sc-ext: java +:project-full-name: Spring Cloud Bus diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/appendix.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/appendix.adoc new file mode 100644 index 00000000..6a783608 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/appendix.adoc @@ -0,0 +1,14 @@ +:numbered!: +[appendix] +[[common-application-properties]] += Common application properties +:page-section-summary-toc: 1 + + +Various properties can be specified inside your `application.properties` file, inside your `application.yml` file, or as command line switches. +This appendix provides a list of common Spring Cloud Bus properties and references to the underlying classes that consume them. + +NOTE: Property contributions can come from additional jar files on your classpath, so you should not consider this an exhaustive list. +Also, you can define your own properties. + +include::partial$_configprops.adoc[] \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/configprops.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/configprops.adoc new file mode 100644 index 00000000..32cbb8e5 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/configprops.adoc @@ -0,0 +1,6 @@ +[[configuration-properties]] += Configuration Properties + +Below you can find a list of configuration properties. + +include::partial$_configprops.adoc[] diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/index.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/index.adoc new file mode 100755 index 00000000..58168dfb --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/index.adoc @@ -0,0 +1 @@ +include::intro.adoc[] \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/intro.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/intro.adoc new file mode 100644 index 00000000..670fdc8f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/intro.adoc @@ -0,0 +1,9 @@ +[[spring-cloud-bus-intro]] += Introduction + +Spring Cloud Bus links the nodes of a distributed system with a lightweight message +broker. This broker can then be used to broadcast state changes (such as configuration +changes) or other management instructions. A key idea is that the bus is like a +distributed actuator for a Spring Boot application that is scaled out. However, it can +also be used as a communication channel between apps. This project provides starters for +either an AMQP broker or Kafka as the transport. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/quickstart.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/quickstart.adoc new file mode 100644 index 00000000..98a17bfc --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/quickstart.adoc @@ -0,0 +1,31 @@ +[[spring-cloud-gateway-quickstart]] += Quickstart + +Spring Cloud Bus works by adding Spring Boot autconfiguration if it detects itself on the +classpath. To enable the bus, add `spring-cloud-starter-bus-amqp` or +`spring-cloud-starter-bus-kafka` to your dependency management. Spring Cloud takes care of +the rest. Make sure the broker (RabbitMQ or Kafka) is available and configured. When +running on localhost, you need not do anything. If you run remotely, use Spring Cloud +Connectors or Spring Boot conventions to define the broker credentials, as shown in the +following example for Rabbit: + +.application.yml +---- +spring: + rabbitmq: + host: mybroker.com + port: 5672 + username: user + password: secret +---- + +The bus currently supports sending messages to all nodes listening or all nodes for a +particular service (as defined by Eureka). The `/bus/*` actuator namespace has some HTTP +endpoints. Currently, two are implemented. The first, `/bus/env`, sends key/value pairs to +update each node's Spring Environment. The second, `/bus/refresh`, reloads each +application's configuration, as though they had all been pinged on their `/refresh` +endpoint. + +NOTE: The Spring Cloud Bus starters cover Rabbit and Kafka, because those are the two most +common implementations. However, Spring Cloud Stream is quite flexible, and the binder +works with `spring-cloud-bus`. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus.adoc new file mode 100644 index 00000000..883c77bc --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus.adoc @@ -0,0 +1,5 @@ +[[spring-cloud-bus]] += Spring Cloud Bus +:page-section-summary-toc: 1 + +*{spring-cloud-version}* diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/addressing.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/addressing.adoc new file mode 100644 index 00000000..9fea5337 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/addressing.adoc @@ -0,0 +1,43 @@ +[[addressing]] += Addressing Instances +:page-section-summary-toc: 1 + +[[addressing-an-instance]] +== Addressing an Instance + +Each instance of the application has a service ID, whose value can be set with +`spring.cloud.bus.id` and whose value is expected to be a colon-separated list of +identifiers, in order from least specific to most specific. The default value is +constructed from the environment as a combination of the `spring.application.name` and +`server.port` (or `spring.application.index`, if set). The default value of the ID is +constructed in the form of `app:index:id`, where: + +* `app` is the `vcap.application.name`, if it exists, or `spring.application.name` +* `index` is the `vcap.application.instance_index`, if it exists, +`spring.application.index`, `local.server.port`, `server.port`, or `0` (in that order). +* `id` is the `vcap.application.instance_id`, if it exists, or a random value. + +The HTTP endpoints accept a "`destination`" path parameter, such as +`/busrefresh/customers:9000`, where `destination` is a service ID. If the ID +is owned by an instance on the bus, it processes the message, and all other instances +ignore it. + +[[addressing-all-instances-of-a-service]] +== Addressing All Instances of a Service + +The "`destination`" parameter is used in a Spring `PathMatcher` (with the path separator +as a colon -- `:`) to determine if an instance processes the message. Using the example +from earlier, `/busenv/customers:**` targets all instances of the +"`customers`" service regardless of the rest of the service ID. + +[[service-id-must-be-unique]] +== Service ID Must Be Unique + +The bus tries twice to eliminate processing an event -- once from the original +`ApplicationEvent` and once from the queue. To do so, it checks the sending service ID +against the current service ID. If multiple instances of a service have the same ID, +events are not processed. When running on a local machine, each service is on a different +port, and that port is part of the ID. Cloud Foundry supplies an index to differentiate. +To ensure that the ID is unique outside Cloud Foundry, set `spring.application.index` to +something unique for each instance of a service. + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/bus-endpoints.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/bus-endpoints.adoc new file mode 100644 index 00000000..76ff8853 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/bus-endpoints.adoc @@ -0,0 +1,44 @@ +[[bus-endpoints]] += Bus Endpoints +:page-section-summary-toc: 1 + +Spring Cloud Bus provides two endpoints, `/actuator/busrefresh` and `/actuator/busenv` +that correspond to individual actuator endpoints in Spring Cloud Commons, +`/actuator/refresh` and `/actuator/env` respectively. + +[[bus-refresh-endpoint]] +== Bus Refresh Endpoint +The `/actuator/busrefresh` endpoint clears the `RefreshScope` cache and rebinds +`@ConfigurationProperties`. See the <> documentation for +more information. + +To expose the `/actuator/busrefresh` endpoint, you need to add following configuration to your +application: + +[source,properties] +---- +management.endpoints.web.exposure.include=busrefresh +---- + +[[bus-env-endpoint]] +== Bus Env Endpoint +The `/actuator/busenv` endpoint updates each instances environment with the specified +key/value pair across multiple instances. + +To expose the `/actuator/busenv` endpoint, you need to add following configuration to your +application: + +[source,properties] +---- +management.endpoints.web.exposure.include=busenv +---- + +The `/actuator/busenv` endpoint accepts `POST` requests with the following shape: + +[source,json] +---- +{ + "name": "key1", + "value": "value1" +} +---- \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/configuration.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/configuration.adoc new file mode 100644 index 00000000..30e86eb4 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/configuration.adoc @@ -0,0 +1,76 @@ +[[configuration]] += Configuration +:page-section-summary-toc: 1 + +[[customizing-the-message-broker]] +== Customizing the Message Broker + +Spring Cloud Bus uses https://cloud.spring.io/spring-cloud-stream[Spring Cloud Stream] to +broadcast the messages. So, to get messages to flow, you need only include the binder +implementation of your choice in the classpath. There are convenient starters for the bus +with AMQP (RabbitMQ) and Kafka (`spring-cloud-starter-bus-[amqp|kafka]`). Generally +speaking, Spring Cloud Stream relies on Spring Boot autoconfiguration conventions for +configuring middleware. For instance, the AMQP broker address can be changed with +`spring.rabbitmq.{asterisk}` configuration properties. Spring Cloud Bus has a handful of +native configuration properties in `spring.cloud.bus.{asterisk}` (for example, +`spring.cloud.bus.destination` is the name of the topic to use as the external +middleware). Normally, the defaults suffice. + +To learn more about how to customize the message broker settings, consult the Spring Cloud +Stream documentation. + +[[tracing-bus-events]] +== Tracing Bus Events + +Bus events (subclasses of `RemoteApplicationEvent`) can be traced by setting +`spring.cloud.bus.trace.enabled=true`. If you do so, the Spring Boot `TraceRepository` +(if it is present) shows each event sent and all the acks from each service instance. The +following example comes from the `/trace` endpoint: + +[source,json] +---- +{ + "timestamp": "2015-11-26T10:24:44.411+0000", + "info": { + "signal": "spring.cloud.bus.ack", + "type": "RefreshRemoteApplicationEvent", + "id": "c4d374b7-58ea-4928-a312-31984def293b", + "origin": "stores:8081", + "destination": "*:**" + } + }, + { + "timestamp": "2015-11-26T10:24:41.864+0000", + "info": { + "signal": "spring.cloud.bus.sent", + "type": "RefreshRemoteApplicationEvent", + "id": "c4d374b7-58ea-4928-a312-31984def293b", + "origin": "customers:9000", + "destination": "*:**" + } + }, + { + "timestamp": "2015-11-26T10:24:41.862+0000", + "info": { + "signal": "spring.cloud.bus.ack", + "type": "RefreshRemoteApplicationEvent", + "id": "c4d374b7-58ea-4928-a312-31984def293b", + "origin": "customers:9000", + "destination": "*:**" + } +} +---- + +The preceding trace shows that a `RefreshRemoteApplicationEvent` was sent from +`customers:9000`, broadcast to all services, and received (acked) by `customers:9000` and +`stores:8081`. + +To handle the ack signals yourself, you could add an `@EventListener` for the +`AckRemoteApplicationEvent` and `SentApplicationEvent` types to your app (and enable +tracing). Alternatively, you could tap into the `TraceRepository` and mine the data from +there. + +NOTE: Any Bus application can trace acks. However, sometimes, it is +useful to do this in a central service that can do more complex +queries on the data or forward it to a specialized tracing service. + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/custom-events.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/custom-events.adoc new file mode 100644 index 00000000..985b99e8 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/pages/spring-cloud-bus/custom-events.adoc @@ -0,0 +1,76 @@ +[[custom-events]] += Custom Events +:page-section-summary-toc: 1 + +[[broadcasting-your-own-events]] +== Broadcasting Your Own Events + +The Bus can carry any event of type `RemoteApplicationEvent`. The default transport is +JSON, and the deserializer needs to know which types are going to be used ahead of time. +To register a new type, you must put it in a subpackage of +`org.springframework.cloud.bus.event`. + +To customise the event name, you can use `@JsonTypeName` on your custom class or rely on +the default strategy, which is to use the simple name of the class. + +NOTE: Both the producer and the consumer need access to the class definition. + +[[registering-events-in-custom-packages]] +=== Registering events in custom packages + +If you cannot or do not want to use a subpackage of `org.springframework.cloud.bus.event` +for your custom events, you must specify which packages to scan for events of type +`RemoteApplicationEvent` by using the `@RemoteApplicationEventScan` annotation. Packages +specified with `@RemoteApplicationEventScan` include subpackages. + +For example, consider the following custom event, called `MyEvent`: + +[source,java] +---- +package com.acme; + +public class MyEvent extends RemoteApplicationEvent { + ... +} +---- + +You can register that event with the deserializer in the following way: + +[source,java] +---- +package com.acme; + +@Configuration +@RemoteApplicationEventScan +public class BusConfiguration { + ... +} +---- + +Without specifying a value, the package of the class where `@RemoteApplicationEventScan` +is used is registered. In this example, `com.acme` is registered by using the package of +`BusConfiguration`. + +You can also explicitly specify the packages to scan by using the `value`, `basePackages` +or `basePackageClasses` properties on `@RemoteApplicationEventScan`, as shown in the +following example: + +[source,java] +---- +package com.acme; + +@Configuration +//@RemoteApplicationEventScan({"com.acme", "foo.bar"}) +//@RemoteApplicationEventScan(basePackages = {"com.acme", "foo.bar", "fizz.buzz"}) +@RemoteApplicationEventScan(basePackageClasses = BusConfiguration.class) +public class BusConfiguration { + ... +} +---- + +All of the preceding examples of `@RemoteApplicationEventScan` are equivalent, in that the +`com.acme` package is registered by explicitly specifying the packages on +`@RemoteApplicationEventScan`. + +NOTE: You can specify multiple base packages to scan. + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/partials/_configprops.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/partials/_configprops.adoc new file mode 100644 index 00000000..3c5e4634 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/modules/ROOT/partials/_configprops.adoc @@ -0,0 +1,14 @@ +|=== +|Name | Default | Description + +|spring.cloud.bus.ack.destination-service | | Service that wants to listen to acks. By default null (meaning all services). +|spring.cloud.bus.ack.enabled | `+++true+++` | Flag to switch off acks (default on). +|spring.cloud.bus.content-type | | The bus mime-type. +|spring.cloud.bus.destination | | Name of Spring Cloud Stream destination for messages. +|spring.cloud.bus.enabled | `+++true+++` | Flag to indicate that the bus is enabled. +|spring.cloud.bus.env.enabled | `+++true+++` | Flag to switch off environment change events (default on). +|spring.cloud.bus.id | `+++application+++` | The identifier for this application instance. +|spring.cloud.bus.refresh.enabled | `+++true+++` | Flag to switch off refresh events (default on). +|spring.cloud.bus.trace.enabled | `+++false+++` | Flag to switch on tracing of acks (default off). + +|=== \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/package.json b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/package.json new file mode 100644 index 00000000..be7a0c4a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/package.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "antora": "3.2.0-alpha.4", + "@antora/atlas-extension": "1.0.0-alpha.2", + "@antora/collector-extension": "1.0.0-alpha.3", + "@asciidoctor/tabs": "1.0.0-beta.6", + "@springio/antora-extensions": "1.11.1", + "@springio/asciidoctor-extensions": "1.0.0-alpha.10" + } +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/pom.xml new file mode 100644 index 00000000..80813a80 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + org.springframework.cloud + spring-cloud-bus-docs + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + + jar + Spring Cloud Bus Docs + Spring Cloud Bus Docs + + spring-cloud-bus + ${basedir}/.. + spring.cloud.bus.* + + none + + + src/main/asciidoc + + + + ${project.groupId} + spring-cloud-starter-bus-amqp + + + ${project.groupId} + spring-cloud-starter-bus-kafka + + + + + docs + + + + src/main/antora/resources/antora-resources + true + + + + + pl.project13.maven + git-commit-id-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + + + org.codehaus.mojo + exec-maven-plugin + + + io.spring.maven.antora + antora-component-version-maven-plugin + + + org.antora + antora-maven-plugin + + + org.apache.maven.plugins + maven-antrun-plugin + + + maven-deploy-plugin + + + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/antora/resources/antora-resources/antora.yml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/antora/resources/antora-resources/antora.yml new file mode 100644 index 00000000..9148923f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/antora/resources/antora-resources/antora.yml @@ -0,0 +1,20 @@ +version: @antora-component.version@ +prerelease: @antora-component.prerelease@ + +asciidoc: + attributes: + attribute-missing: 'warn' + chomp: 'all' + project-root: @maven.multiModuleProjectDirectory@ + github-repo: @docs.main@ + github-raw: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ + github-code: https://github.com/spring-cloud/@docs.main@/tree/@github-tag@ + github-issues: https://github.com/spring-cloud/@docs.main@/issues/ + github-wiki: https://github.com/spring-cloud/@docs.main@/wiki + spring-cloud-version: @project.version@ + github-tag: @github-tag@ + version-type: @version-type@ + docs-url: https://docs.spring.io/@docs.main@/docs/@project.version@ + raw-docs-url: https://raw.githubusercontent.com/spring-cloud/@docs.main@/@github-tag@ + project-version: @project.version@ + project-name: @docs.main@ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/README.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/README.adoc new file mode 100644 index 00000000..8b768872 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/README.adoc @@ -0,0 +1,18 @@ +[[spring-cloud-bus]] += Spring Cloud Bus +:page-section-summary-toc: 1 + + +[[quick-start]] +== Quick Start + + +[[building]] +== Building + +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[] + +[[contributing]] +== Contributing + +include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[] diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/ghpages.sh b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/ghpages.sh new file mode 100755 index 00000000..afcc9b16 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/ghpages.sh @@ -0,0 +1,335 @@ +#!/bin/bash -x + +set -e + +# Set default props like MAVEN_PATH, ROOT_FOLDER etc. +function set_default_props() { + # The script should be run from the root folder + ROOT_FOLDER=`pwd` + echo "Current folder is ${ROOT_FOLDER}" + + if [[ ! -e "${ROOT_FOLDER}/.git" ]]; then + echo "You're not in the root folder of the project!" + exit 1 + fi + + # Prop that will let commit the changes + COMMIT_CHANGES="no" + MAVEN_PATH=${MAVEN_PATH:-} + echo "Path to Maven is [${MAVEN_PATH}]" + REPO_NAME=${PWD##*/} + echo "Repo name is [${REPO_NAME}]" + SPRING_CLOUD_STATIC_REPO=${SPRING_CLOUD_STATIC_REPO:-git@github.com:spring-cloud/spring-cloud-static.git} + echo "Spring Cloud Static repo is [${SPRING_CLOUD_STATIC_REPO}" +} + +# Check if gh-pages exists and docs have been built +function check_if_anything_to_sync() { + git remote set-url --push origin `git config remote.origin.url | sed -e 's/^git:/https:/'` + + if ! (git remote set-branches --add origin gh-pages && git fetch -q); then + echo "No gh-pages, so not syncing" + exit 0 + fi + + if ! [ -d docs/target/generated-docs ] && ! [ "${BUILD}" == "yes" ]; then + echo "No gh-pages sources in docs/target/generated-docs, so not syncing" + exit 0 + fi +} + +function retrieve_current_branch() { + # Code getting the name of the current branch. For master we want to publish as we did until now + # https://stackoverflow.com/questions/1593051/how-to-programmatically-determine-the-current-checked-out-git-branch + # If there is a branch already passed will reuse it - otherwise will try to find it + CURRENT_BRANCH=${BRANCH} + if [[ -z "${CURRENT_BRANCH}" ]] ; then + CURRENT_BRANCH=$(git symbolic-ref -q HEAD) + CURRENT_BRANCH=${CURRENT_BRANCH##refs/heads/} + CURRENT_BRANCH=${CURRENT_BRANCH:-HEAD} + fi + echo "Current branch is [${CURRENT_BRANCH}]" + git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script" +} + +# Switches to the provided value of the release version. We always prefix it with `v` +function switch_to_tag() { + git checkout v${VERSION} +} + +# Build the docs if switch is on +function build_docs_if_applicable() { + if [[ "${BUILD}" == "yes" ]] ; then + ./mvnw clean install -P docs -pl docs -DskipTests + fi +} + +# Get the name of the `docs.main` property +# Get allowed branches - assumes that a `docs` module is available under `docs` profile +function retrieve_doc_properties() { + MAIN_ADOC_VALUE=$("${MAVEN_PATH}"mvn -q \ + -Dexec.executable="echo" \ + -Dexec.args='${docs.main}' \ + --non-recursive \ + org.codehaus.mojo:exec-maven-plugin:1.3.1:exec) + echo "Extracted 'main.adoc' from Maven build [${MAIN_ADOC_VALUE}]" + + + ALLOW_PROPERTY=${ALLOW_PROPERTY:-"docs.allowed.branches"} + ALLOWED_BRANCHES_VALUE=$("${MAVEN_PATH}"mvn -q \ + -Dexec.executable="echo" \ + -Dexec.args="\${${ALLOW_PROPERTY}}" \ + org.codehaus.mojo:exec-maven-plugin:1.3.1:exec \ + -P docs \ + -pl docs) + echo "Extracted '${ALLOW_PROPERTY}' from Maven build [${ALLOWED_BRANCHES_VALUE}]" +} + +# Stash any outstanding changes +function stash_changes() { + git diff-index --quiet HEAD && dirty=$? || (echo "Failed to check if the current repo is dirty. Assuming that it is." && dirty="1") + if [ "$dirty" != "0" ]; then git stash; fi +} + +# Switch to gh-pages branch to sync it with current branch +function add_docs_from_target() { + local DESTINATION_REPO_FOLDER + if [[ -z "${DESTINATION}" && -z "${CLONE}" ]] ; then + DESTINATION_REPO_FOLDER=${ROOT_FOLDER} + elif [[ "${CLONE}" == "yes" ]]; then + mkdir -p ${ROOT_FOLDER}/target + local clonedStatic=${ROOT_FOLDER}/target/spring-cloud-static + if [[ ! -e "${clonedStatic}/.git" ]]; then + echo "Cloning Spring Cloud Static to target" + git clone ${SPRING_CLOUD_STATIC_REPO} ${clonedStatic} && git checkout gh-pages + else + echo "Spring Cloud Static already cloned - will pull changes" + cd ${clonedStatic} && git checkout gh-pages && git pull origin gh-pages + fi + DESTINATION_REPO_FOLDER=${clonedStatic}/${REPO_NAME} + mkdir -p ${DESTINATION_REPO_FOLDER} + else + if [[ ! -e "${DESTINATION}/.git" ]]; then + echo "[${DESTINATION}] is not a git repository" + exit 1 + fi + DESTINATION_REPO_FOLDER=${DESTINATION}/${REPO_NAME} + mkdir -p ${DESTINATION_REPO_FOLDER} + echo "Destination was provided [${DESTINATION}]" + fi + cd ${DESTINATION_REPO_FOLDER} + git checkout gh-pages + git pull origin gh-pages + + # Add git branches + ################################################################### + if [[ -z "${VERSION}" ]] ; then + copy_docs_for_current_version + else + copy_docs_for_provided_version + fi + commit_changes_if_applicable +} + + +# Copies the docs by using the retrieved properties from Maven build +function copy_docs_for_current_version() { + if [[ "${CURRENT_BRANCH}" == "master" ]] ; then + echo -e "Current branch is master - will copy the current docs only to the root folder" + for f in docs/target/generated-docs/*; do + file=${f#docs/target/generated-docs/*} + if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then + # Not ignored... + cp -rf $f ${ROOT_FOLDER}/ + git add -A ${ROOT_FOLDER}/$file + fi + done + COMMIT_CHANGES="yes" + else + echo -e "Current branch is [${CURRENT_BRANCH}]" +<<<<<<< Updated upstream + # https://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin + if [[ ",${WHITELISTED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then +======= + # http://stackoverflow.com/questions/29300806/a-bash-script-to-check-if-a-string-is-present-in-a-comma-separated-list-of-strin + if [[ ",${ALLOWED_BRANCHES_VALUE}," = *",${CURRENT_BRANCH},"* ]] ; then +>>>>>>> Stashed changes + mkdir -p ${ROOT_FOLDER}/${CURRENT_BRANCH} + echo -e "Branch [${CURRENT_BRANCH}] is allowed! Will copy the current docs to the [${CURRENT_BRANCH}] folder" + for f in docs/target/generated-docs/*; do + file=${f#docs/target/generated-docs/*} + if ! git ls-files -i -o --exclude-standard --directory | grep -q ^$file$; then + # Not ignored... + # We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html + if [[ "${file}" == "${MAIN_ADOC_VALUE}.html" ]] ; then + # We don't want to copy the spring-cloud-sleuth.html + # we want it to be converted to index.html + cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html + git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/index.html + else + cp -rf $f ${ROOT_FOLDER}/${CURRENT_BRANCH} + git add -A ${ROOT_FOLDER}/${CURRENT_BRANCH}/$file + fi + fi + done + COMMIT_CHANGES="yes" + else + echo -e "Branch [${CURRENT_BRANCH}] is not on the allow list! Check out the Maven [${ALLOW_PROPERTY}] property in + [docs] module available under [docs] profile. Won't commit any changes to gh-pages for this branch." + fi + fi +} + +# Copies the docs by using the explicitly provided version +function copy_docs_for_provided_version() { + local FOLDER=${DESTINATION_REPO_FOLDER}/${VERSION} + mkdir -p ${FOLDER} + echo -e "Current tag is [v${VERSION}] Will copy the current docs to the [${FOLDER}] folder" + for f in ${ROOT_FOLDER}/docs/target/generated-docs/*; do + file=${f#${ROOT_FOLDER}/docs/target/generated-docs/*} + copy_docs_for_branch ${file} ${FOLDER} + done + COMMIT_CHANGES="yes" + CURRENT_BRANCH="v${VERSION}" +} + +# Copies the docs from target to the provided destination +# Params: +# $1 - file from target +# $2 - destination to which copy the files +function copy_docs_for_branch() { + local file=$1 + local destination=$2 + if ! git ls-files -i -o --exclude-standard --directory | grep -q ^${file}$; then + # Not ignored... + # We want users to access 1.0.0.RELEASE/ instead of 1.0.0.RELEASE/spring-cloud.sleuth.html + if [[ ("${file}" == "${MAIN_ADOC_VALUE}.html") || ("${file}" == "${REPO_NAME}.html") ]] ; then + # We don't want to copy the spring-cloud-sleuth.html + # we want it to be converted to index.html + cp -rf $f ${destination}/index.html + git add -A ${destination}/index.html + else + cp -rf $f ${destination} + git add -A ${destination}/$file + fi + fi +} + +function commit_changes_if_applicable() { + if [[ "${COMMIT_CHANGES}" == "yes" ]] ; then + COMMIT_SUCCESSFUL="no" + git commit -a -m "Sync docs from ${CURRENT_BRANCH} to gh-pages" && COMMIT_SUCCESSFUL="yes" || echo "Failed to commit changes" + + # Uncomment the following push if you want to auto push to + # the gh-pages branch whenever you commit to master locally. + # This is a little extreme. Use with care! + ################################################################### + if [[ "${COMMIT_SUCCESSFUL}" == "yes" ]] ; then + git push origin gh-pages + fi + fi +} + +# Switch back to the previous branch and exit block +function checkout_previous_branch() { + # If -version was provided we need to come back to root project + cd ${ROOT_FOLDER} + git checkout ${CURRENT_BRANCH} || echo "Failed to check the branch... continuing with the script" + if [ "$dirty" != "0" ]; then git stash pop; fi + exit 0 +} + +# Assert if properties have been properly passed +function assert_properties() { +echo "VERSION [${VERSION}], DESTINATION [${DESTINATION}], CLONE [${CLONE}]" +if [[ "${VERSION}" != "" && (-z "${DESTINATION}" && -z "${CLONE}") ]] ; then echo "Version was set but destination / clone was not!"; exit 1;fi +if [[ ("${DESTINATION}" != "" && "${CLONE}" != "") && -z "${VERSION}" ]] ; then echo "Destination / clone was set but version was not!"; exit 1;fi +if [[ "${DESTINATION}" != "" && "${CLONE}" == "yes" ]] ; then echo "Destination and clone was set. Pick one!"; exit 1;fi +} + +# Prints the usage +function print_usage() { +cat </` +- if the destination switch is passed (-d) then the script will check if the provided dir is a git repo and then will + switch to gh-pages of that repo and copy the generated docs to `docs//` + +USAGE: + +You can use the following options: + +-v|--version - the script will apply the whole procedure for a particular library version +-d|--destination - the root of destination folder where the docs should be copied. You have to use the full path. + E.g. point to spring-cloud-static folder. Can't be used with (-c) +-b|--build - will run the standard build process after checking out the branch +-c|--clone - will automatically clone the spring-cloud-static repo instead of providing the destination. + Obviously can't be used with (-d) + +EOF +} + + +# ========================================== +# ____ ____ _____ _____ _____ _______ +# / ____|/ ____| __ \|_ _| __ \__ __| +# | (___ | | | |__) | | | | |__) | | | +# \___ \| | | _ / | | | ___/ | | +# ____) | |____| | \ \ _| |_| | | | +# |_____/ \_____|_| \_\_____|_| |_| +# +# ========================================== + +while [[ $# > 0 ]] +do +key="$1" +case ${key} in + -v|--version) + VERSION="$2" + shift # past argument + ;; + -d|--destination) + DESTINATION="$2" + shift # past argument + ;; + -b|--build) + BUILD="yes" + ;; + -c|--clone) + CLONE="yes" + ;; + -h|--help) + print_usage + exit 0 + ;; + *) + echo "Invalid option: [$1]" + print_usage + exit 1 + ;; +esac +shift # past argument or value +done + +assert_properties +set_default_props +check_if_anything_to_sync +if [[ -z "${VERSION}" ]] ; then + retrieve_current_branch +else + switch_to_tag +fi +build_docs_if_applicable +retrieve_doc_properties +stash_changes +add_docs_from_target +checkout_previous_branch diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/sagan-index.adoc b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/sagan-index.adoc new file mode 100644 index 00000000..d56dc83b --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/docs/src/main/asciidoc/sagan-index.adoc @@ -0,0 +1,26 @@ + +Spring Cloud Bus links nodes of a distributed system with a lightweight message broker. This can then be used to broadcast state changes (e.g. configuration changes) or other management instructions. AMQP and Kafka broker implementations are included with the project. Alternatively, any link:https://spring.io/projects/spring-cloud-stream[Spring Cloud Stream] binder found on the classpath will work out of the box as a transport. + +## Getting Started +As long as Spring Cloud Bus AMQP and RabbitMQ are on the +classpath any Spring Boot application will try to contact a RabbitMQ +server on `localhost:5672` (the default value of +`spring.rabbitmq.addresses`): + +```java +@Configuration +@EnableAutoConfiguration +@RestController +public class Application { + + @RequestMapping("/") + public String home() { + return "Hello World"; + } + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} +``` diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/COMMIT_EDITMSG b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/COMMIT_EDITMSG new file mode 100644 index 00000000..1049ca62 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/COMMIT_EDITMSG @@ -0,0 +1 @@ +fixing pom diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/FETCH_HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/FETCH_HEAD new file mode 100644 index 00000000..4831dc7d --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/FETCH_HEAD @@ -0,0 +1,23 @@ +8445b044de0845b9435d5ca828a07e8a03f7c7ca branch 'main' of github.com:spring-cloud/spring-cloud-bus +fe9e42180820c94988f2bc817c3fbae709bb854e not-for-merge branch '1.0.0.M2' of github.com:spring-cloud/spring-cloud-bus +bd144126e14feed9603fe6cd3e5a37107d5e2e60 not-for-merge branch '1.0.0.M3' of github.com:spring-cloud/spring-cloud-bus +369e393115952d70edaf00f19d941c2b4cff1dd6 not-for-merge branch '1.0.0.RC1' of github.com:spring-cloud/spring-cloud-bus +b26be221b2bd301ddbd06af39e8bde0b38ad0f41 not-for-merge branch '1.0.0.RELEASE' of github.com:spring-cloud/spring-cloud-bus +e49f99094121838835bc853958e75f3a36a267d3 not-for-merge branch '1.0.1.RELEASE' of github.com:spring-cloud/spring-cloud-bus +1464dd0f0e070369485c44df395b992e86d87dc4 not-for-merge branch '1.0.2.RELEASE' of github.com:spring-cloud/spring-cloud-bus +64f0252fb8d91027c542c4c984968e41e02d9ee6 not-for-merge branch '1.0.3.RELEASE' of github.com:spring-cloud/spring-cloud-bus +a70dda9c68fda523b92181c9a42642d0c86565b9 not-for-merge branch '1.0.x' of github.com:spring-cloud/spring-cloud-bus +6bf43bfd653741cc7174657b14c06e635a8d3f81 not-for-merge branch '1.1.x' of github.com:spring-cloud/spring-cloud-bus +31940b2fd40c4d796c0d52d393f1962d063b8b16 not-for-merge branch '1.2.x' of github.com:spring-cloud/spring-cloud-bus +f00b4c2ec0d74c2c147063076455c695f02403e0 not-for-merge branch '1.3.x' of github.com:spring-cloud/spring-cloud-bus +2d46c687c78e322666c1b66a96a708123df2de03 not-for-merge branch '2.0.x' of github.com:spring-cloud/spring-cloud-bus +c3b6feea2d878c508059f3208217b35a35afa0a1 not-for-merge branch '2.1.x' of github.com:spring-cloud/spring-cloud-bus +7ca22f129b3edd969b3ea7d91797d05b35a115db not-for-merge branch '2.2.x' of github.com:spring-cloud/spring-cloud-bus +45de9276badef94fe08061e15e9a5b85509260ff not-for-merge branch '3.0.x' of github.com:spring-cloud/spring-cloud-bus +7f1a400692c814456c544ab14d7e5e434388737d not-for-merge branch '3.1.x' of github.com:spring-cloud/spring-cloud-bus +9662ac236349ad36422550f38c1aee490d12d191 not-for-merge branch '4.0.x' of github.com:spring-cloud/spring-cloud-bus +e8b8207b2d0025be7b43f211c9ea05a36cf4759b not-for-merge branch 'antora' of github.com:spring-cloud/spring-cloud-bus +798cf84f044a3882acdbbcfdc33e4b9fc2424080 not-for-merge branch 'dependabot/maven/testcontainers.version-1.15.0' of github.com:spring-cloud/spring-cloud-bus +e3e1ec9b64aafc84bdbe8e740f72e5458de72301 not-for-merge branch 'docs-build' of github.com:spring-cloud/spring-cloud-bus +33caf2d4246328459cda33b19c9064ec0b56ea38 not-for-merge branch 'gh-pages' of github.com:spring-cloud/spring-cloud-bus +dd7b7141ee793ec26ef08393257e028c31004eee not-for-merge tag 'v4.1.2' of github.com:spring-cloud/spring-cloud-bus diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/HEAD new file mode 100644 index 00000000..b870d826 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/config b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/config new file mode 100644 index 00000000..b75f2375 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/config @@ -0,0 +1,18 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = git@github.com:spring-cloud/spring-cloud-bus.git + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "main"] + remote = origin + merge = refs/heads/main +[lfs] + repositoryformatversion = 0 +[branch "docs-build"] + remote = origin + merge = refs/heads/docs-build diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/description b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/description new file mode 100644 index 00000000..498b267a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/applypatch-msg.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/applypatch-msg.sample new file mode 100755 index 00000000..a5d7b84a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/commit-msg.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/commit-msg.sample new file mode 100755 index 00000000..b58d1184 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/fsmonitor-watchman.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/fsmonitor-watchman.sample new file mode 100755 index 00000000..23e856f5 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/fsmonitor-watchman.sample @@ -0,0 +1,174 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 2) and last update token +# formatted as a string and outputs to stdout a new update token and +# all files that have been modified since the update token. Paths must +# be relative to the root of the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $last_update_token) = @ARGV; + +# Uncomment for debugging +# print STDERR "$0 $version $last_update_token\n"; + +# Check the hook interface version +if ($version ne 2) { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree = get_working_dir(); + +my $retry = 1; + +my $json_pkg; +eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; +} or do { + require JSON::PP; + $json_pkg = "JSON::PP"; +}; + +launch_watchman(); + +sub launch_watchman { + my $o = watchman_query(); + if (is_work_tree_watched($o)) { + output_result($o->{clock}, @{$o->{files}}); + } +} + +sub output_result { + my ($clockid, @files) = @_; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # binmode $fh, ":utf8"; + # print $fh "$clockid\n@files\n"; + # close $fh; + + binmode STDOUT, ":utf8"; + print $clockid; + print "\0"; + local $, = "\0"; + print @files; +} + +sub watchman_clock { + my $response = qx/watchman clock "$git_work_tree"/; + die "Failed to get clock id on '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + return $json_pkg->new->utf8->decode($response); +} + +sub watchman_query { + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $last_update_token but not from the .git folder. + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + my $last_update_line = ""; + if (substr($last_update_token, 0, 1) eq "c") { + $last_update_token = "\"$last_update_token\""; + $last_update_line = qq[\n"since": $last_update_token,]; + } + my $query = <<" END"; + ["query", "$git_work_tree", {$last_update_line + "fields": ["name"], + "expression": ["not", ["dirname", ".git"]] + }] + END + + # Uncomment for debugging the watchman query + # open (my $fh, ">", ".git/watchman-query.json"); + # print $fh $query; + # close $fh; + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + # Uncomment for debugging the watch response + # open ($fh, ">", ".git/watchman-response.json"); + # print $fh $response; + # close $fh; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + return $json_pkg->new->utf8->decode($response); +} + +sub is_work_tree_watched { + my ($output) = @_; + my $error = $output->{error}; + if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { + $retry--; + my $response = qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + $output = $json_pkg->new->utf8->decode($response); + $error = $output->{error}; + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # close $fh; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + my $o = watchman_clock(); + $error = $output->{error}; + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + output_result($o->{clock}, ("/")); + $last_update_token = $o->{clock}; + + eval { launch_watchman() }; + return 0; + } + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + return 1; +} + +sub get_working_dir { + my $working_dir; + if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $working_dir = Win32::GetCwd(); + $working_dir =~ tr/\\/\//; + } else { + require Cwd; + $working_dir = Cwd::cwd(); + } + + return $working_dir; +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/post-update.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/post-update.sample new file mode 100755 index 00000000..ec17ec19 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-applypatch.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-applypatch.sample new file mode 100755 index 00000000..4142082b --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-commit.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-commit.sample new file mode 100755 index 00000000..29ed5ee4 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --type=bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff-index --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-merge-commit.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-merge-commit.sample new file mode 100755 index 00000000..399eab19 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-merge-commit.sample @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-push.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-push.sample new file mode 100755 index 00000000..4ce688d3 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-rebase.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-rebase.sample new file mode 100755 index 00000000..6cbef5c3 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-receive.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-receive.sample new file mode 100755 index 00000000..a1fd29ec --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/prepare-commit-msg.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/prepare-commit-msg.sample new file mode 100755 index 00000000..10fa14c5 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/push-to-checkout.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/push-to-checkout.sample new file mode 100755 index 00000000..af5a0c00 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/push-to-checkout.sample @@ -0,0 +1,78 @@ +#!/bin/sh + +# An example hook script to update a checked-out tree on a git push. +# +# This hook is invoked by git-receive-pack(1) when it reacts to git +# push and updates reference(s) in its repository, and when the push +# tries to update the branch that is currently checked out and the +# receive.denyCurrentBranch configuration variable is set to +# updateInstead. +# +# By default, such a push is refused if the working tree and the index +# of the remote repository has any difference from the currently +# checked out commit; when both the working tree and the index match +# the current commit, they are updated to match the newly pushed tip +# of the branch. This hook is to be used to override the default +# behaviour; however the code below reimplements the default behaviour +# as a starting point for convenient modification. +# +# The hook receives the commit with which the tip of the current +# branch is going to be updated: +commit=$1 + +# It can exit with a non-zero status to refuse the push (when it does +# so, it must not modify the index or the working tree). +die () { + echo >&2 "$*" + exit 1 +} + +# Or it can make any necessary changes to the working tree and to the +# index to bring them to the desired state when the tip of the current +# branch is updated to the new commit, and exit with a zero status. +# +# For example, the hook can simply run git read-tree -u -m HEAD "$1" +# in order to emulate git fetch that is run in the reverse direction +# with git push, as the two-tree form of git read-tree -u -m is +# essentially the same as git switch or git checkout that switches +# branches while keeping the local changes in the working tree that do +# not interfere with the difference between the branches. + +# The below is a more-or-less exact translation to shell of the C code +# for the default behaviour for git's push-to-checkout hook defined in +# the push_to_deploy() function in builtin/receive-pack.c. +# +# Note that the hook will be executed from the repository directory, +# not from the working tree, so if you want to perform operations on +# the working tree, you will have to adapt your code accordingly, e.g. +# by adding "cd .." or using relative paths. + +if ! git update-index -q --ignore-submodules --refresh +then + die "Up-to-date check failed" +fi + +if ! git diff-files --quiet --ignore-submodules -- +then + die "Working directory has unstaged changes" +fi + +# This is a rough translation of: +# +# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX +if git cat-file -e HEAD 2>/dev/null +then + head=HEAD +else + head=$(git hash-object -t tree --stdin &2 + exit 1 +} + +unset GIT_DIR GIT_WORK_TREE +cd "$worktree" && + +if grep -q "^diff --git " "$1" +then + validate_patch "$1" +else + validate_cover_letter "$1" +fi && + +if test "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL" +then + git config --unset-all sendemail.validateWorktree && + trap 'git worktree remove -ff "$worktree"' EXIT && + validate_series +fi diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/update.sample b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/update.sample new file mode 100755 index 00000000..c4d426bc --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --type=bool hooks.allowunannotated) +allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) +denycreatebranch=$(git config --type=bool hooks.denycreatebranch) +allowdeletetag=$(git config --type=bool hooks.allowdeletetag) +allowmodifytag=$(git config --type=bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero=$(git hash-object --stdin &2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/index b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/index new file mode 100644 index 00000000..8a208562 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/index differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/info/exclude b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/info/exclude new file mode 100644 index 00000000..a5196d1b --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/HEAD new file mode 100644 index 00000000..8cdba2ff --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/HEAD @@ -0,0 +1,14 @@ +0000000000000000000000000000000000000000 8445b044de0845b9435d5ca828a07e8a03f7c7ca Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240374 -0400 clone: from github.com:spring-cloud/spring-cloud-bus.git +8445b044de0845b9435d5ca828a07e8a03f7c7ca 3a0f899ba6804aeb567ed0437936b8d8b0b8c48a Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241311 -0400 revert: Revert "Bumping versions to 4.1.3-SNAPSHOT after release" +3a0f899ba6804aeb567ed0437936b8d8b0b8c48a 74134cf60dccfef0469a1720d7afb4ee2bb6f921 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241320 -0400 revert: Revert "Going back to snapshots" +74134cf60dccfef0469a1720d7afb4ee2bb6f921 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241324 -0400 revert: Revert "Update SNAPSHOT to 4.1.2" +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721242706 -0400 checkout: moving from main to docs-build +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721242743 -0400 checkout: moving from docs-build to main +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 e3e1ec9b64aafc84bdbe8e740f72e5458de72301 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721242773 -0400 checkout: moving from main to docs-build +e3e1ec9b64aafc84bdbe8e740f72e5458de72301 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721242793 -0400 checkout: moving from docs-build to main +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 e3e1ec9b64aafc84bdbe8e740f72e5458de72301 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721243349 -0400 checkout: moving from main to docs-build +e3e1ec9b64aafc84bdbe8e740f72e5458de72301 af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721243555 -0400 commit: updating antora sources +af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721243563 -0400 checkout: moving from docs-build to main +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721243884 -0400 checkout: moving from main to docs-build +af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 bd817cb93cc1d46638fe8b737bb2fc5affdd5f5b Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721244230 -0400 commit: fixing pom +bd817cb93cc1d46638fe8b737bb2fc5affdd5f5b 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721244236 -0400 checkout: moving from docs-build to main diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/docs-build b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/docs-build new file mode 100644 index 00000000..79f5c5f2 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/docs-build @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 e3e1ec9b64aafc84bdbe8e740f72e5458de72301 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721242773 -0400 branch: Created from refs/remotes/origin/docs-build +e3e1ec9b64aafc84bdbe8e740f72e5458de72301 af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721243555 -0400 commit: updating antora sources +af7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 bd817cb93cc1d46638fe8b737bb2fc5affdd5f5b Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721244230 -0400 commit: fixing pom diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/main b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/main new file mode 100644 index 00000000..51860d87 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/heads/main @@ -0,0 +1,4 @@ +0000000000000000000000000000000000000000 8445b044de0845b9435d5ca828a07e8a03f7c7ca Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240374 -0400 clone: from github.com:spring-cloud/spring-cloud-bus.git +8445b044de0845b9435d5ca828a07e8a03f7c7ca 3a0f899ba6804aeb567ed0437936b8d8b0b8c48a Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241311 -0400 revert: Revert "Bumping versions to 4.1.3-SNAPSHOT after release" +3a0f899ba6804aeb567ed0437936b8d8b0b8c48a 74134cf60dccfef0469a1720d7afb4ee2bb6f921 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241320 -0400 revert: Revert "Going back to snapshots" +74134cf60dccfef0469a1720d7afb4ee2bb6f921 5fbd5cef4a98df979047dd51dc2a1c4951c35c98 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721241324 -0400 revert: Revert "Update SNAPSHOT to 4.1.2" diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/remotes/origin/HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/remotes/origin/HEAD new file mode 100644 index 00000000..935f0fc0 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/logs/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 8445b044de0845b9435d5ca828a07e8a03f7c7ca Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240374 -0400 clone: from github.com:spring-cloud/spring-cloud-bus.git diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/3a/0f899ba6804aeb567ed0437936b8d8b0b8c48a b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/3a/0f899ba6804aeb567ed0437936b8d8b0b8c48a new file mode 100644 index 00000000..c861fb70 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/3a/0f899ba6804aeb567ed0437936b8d8b0b8c48a @@ -0,0 +1,3 @@ +xMN1 YVQ~%Xj{L LFIۓX>Oi +黚W:Rh.)CaD->\!N $\vMowyam3!e8\ {U)ÃQ >ʅ)rX!M +`74e\a_eT\&@._ߏ/o'v<Ӆ| ca,M 8:z \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/5f/bd5cef4a98df979047dd51dc2a1c4951c35c98 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/5f/bd5cef4a98df979047dd51dc2a1c4951c35c98 new file mode 100644 index 00000000..ef5635b4 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/5f/bd5cef4a98df979047dd51dc2a1c4951c35c98 @@ -0,0 +1,2 @@ +xMN0Ynxıb-ϘrDo)W`5ҧ^Xi,Z{U23xtT@d6>'B2`{L)<0Z*R1 ug4Ѹ53y%KR K gmISseKy˰&,TFnP#Jk_?JŞ8ؽ+  8 +_ x#d6Vqn+5%܈pWq \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/6a/406a200d6e37459d95e1beed998cef4b13d787 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/6a/406a200d6e37459d95e1beed998cef4b13d787 new file mode 100644 index 00000000..54622e8f Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/6a/406a200d6e37459d95e1beed998cef4b13d787 differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/74/134cf60dccfef0469a1720d7afb4ee2bb6f921 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/74/134cf60dccfef0469a1720d7afb4ee2bb6f921 new file mode 100644 index 00000000..a16862d3 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/74/134cf60dccfef0469a1720d7afb4ee2bb6f921 @@ -0,0 +1 @@ +xAN0EYn=3Nl !Ć}ƉH\.'+}y]d]+1&Gؓ3zb:J I@ɤ`YJ;{C4nrA7%6ǫl"-xh=R-xv͗Ѝy}3A64kvOTW, yNdnrsnۼT(X@frD{/y MBBql,;p \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/ad/37b474721ece7929937ab2f1b1d6b8b1f94aff b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/ad/37b474721ece7929937ab2f1b1d6b8b1f94aff new file mode 100644 index 00000000..6688638b Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/ad/37b474721ece7929937ab2f1b1d6b8b1f94aff differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/af/7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/af/7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 new file mode 100644 index 00000000..b6dae143 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/af/7d3bd36db12bcdbdb4d5dff0fae95f0f7ac260 @@ -0,0 +1 @@ +xAn 9ZRUE=Bo0!qAjn_3tů˾o [^Ze(u^G$McKW<.jVU xfчRt-d5 zJPoRI>q7Qa_ϮzNT>鶵{S,;(C?FE?Vj[V*Yz|R]X \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/bd/817cb93cc1d46638fe8b737bb2fc5affdd5f5b b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/bd/817cb93cc1d46638fe8b737bb2fc5affdd5f5b new file mode 100644 index 00000000..463bf2d8 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/bd/817cb93cc1d46638fe8b737bb2fc5affdd5f5b differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/de/b23010c29d850e8b043db5e887fa8a8fe1d6b5 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/de/b23010c29d850e8b043db5e887fa8a8fe1d6b5 new file mode 100644 index 00000000..ad035514 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/de/b23010c29d850e8b043db5e887fa8a8fe1d6b5 differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/f6/11f77892c58df05b91f7059c91e38c48c298d4 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/f6/11f77892c58df05b91f7059c91e38c48c298d4 new file mode 100644 index 00000000..d8cae9c1 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/f6/11f77892c58df05b91f7059c91e38c48c298d4 differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.idx b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.idx new file mode 100644 index 00000000..07a782e2 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.idx differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.pack b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.pack new file mode 100644 index 00000000..81978be3 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.pack differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.rev b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.rev new file mode 100644 index 00000000..299bd375 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/objects/pack/pack-5dd7a41699a3186e227bc0192017de63704434cd.rev differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/packed-refs b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/packed-refs new file mode 100644 index 00000000..0c6bfc62 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/packed-refs @@ -0,0 +1,121 @@ +# pack-refs with: peeled fully-peeled sorted +fe9e42180820c94988f2bc817c3fbae709bb854e refs/remotes/origin/1.0.0.M2 +bd144126e14feed9603fe6cd3e5a37107d5e2e60 refs/remotes/origin/1.0.0.M3 +369e393115952d70edaf00f19d941c2b4cff1dd6 refs/remotes/origin/1.0.0.RC1 +b26be221b2bd301ddbd06af39e8bde0b38ad0f41 refs/remotes/origin/1.0.0.RELEASE +e49f99094121838835bc853958e75f3a36a267d3 refs/remotes/origin/1.0.1.RELEASE +1464dd0f0e070369485c44df395b992e86d87dc4 refs/remotes/origin/1.0.2.RELEASE +64f0252fb8d91027c542c4c984968e41e02d9ee6 refs/remotes/origin/1.0.3.RELEASE +a70dda9c68fda523b92181c9a42642d0c86565b9 refs/remotes/origin/1.0.x +6bf43bfd653741cc7174657b14c06e635a8d3f81 refs/remotes/origin/1.1.x +31940b2fd40c4d796c0d52d393f1962d063b8b16 refs/remotes/origin/1.2.x +f00b4c2ec0d74c2c147063076455c695f02403e0 refs/remotes/origin/1.3.x +2d46c687c78e322666c1b66a96a708123df2de03 refs/remotes/origin/2.0.x +c3b6feea2d878c508059f3208217b35a35afa0a1 refs/remotes/origin/2.1.x +7ca22f129b3edd969b3ea7d91797d05b35a115db refs/remotes/origin/2.2.x +45de9276badef94fe08061e15e9a5b85509260ff refs/remotes/origin/3.0.x +7f1a400692c814456c544ab14d7e5e434388737d refs/remotes/origin/3.1.x +9662ac236349ad36422550f38c1aee490d12d191 refs/remotes/origin/4.0.x +e8b8207b2d0025be7b43f211c9ea05a36cf4759b refs/remotes/origin/antora +798cf84f044a3882acdbbcfdc33e4b9fc2424080 refs/remotes/origin/dependabot/maven/testcontainers.version-1.15.0 +e3e1ec9b64aafc84bdbe8e740f72e5458de72301 refs/remotes/origin/docs-build +33caf2d4246328459cda33b19c9064ec0b56ea38 refs/remotes/origin/gh-pages +8445b044de0845b9435d5ca828a07e8a03f7c7ca refs/remotes/origin/main +8921aa119b432c54e7862363ca31e5421db21a85 refs/tags/1.0.0.M1 +bd144126e14feed9603fe6cd3e5a37107d5e2e60 refs/tags/v1.0.0.M3 +369e393115952d70edaf00f19d941c2b4cff1dd6 refs/tags/v1.0.0.RC1 +0e10717af997bc9c1192b6dcad25488ea65e31a5 refs/tags/v1.0.0.RC2 +f70e25981ee0564e401072caa7623942e99d9f3f refs/tags/v1.0.0.RC3 +a87b1db6b5cbdad09aa75a2058ffc9f63a2b0d1e refs/tags/v1.0.0.RELEASE +e49f99094121838835bc853958e75f3a36a267d3 refs/tags/v1.0.1.RELEASE +1464dd0f0e070369485c44df395b992e86d87dc4 refs/tags/v1.0.2.RELEASE +64f0252fb8d91027c542c4c984968e41e02d9ee6 refs/tags/v1.0.3.RELEASE +ed180031911a3c8e776286ad295db18299b15253 refs/tags/v1.1.0.M1 +a282f2fd97d2c4d9a785b89ede52c1fd3a9ffd52 refs/tags/v1.1.0.M2 +88779bf77e32cc247efb4e0dade6bb370ffba277 refs/tags/v1.1.0.M3 +04ce561d4d4ad12b45903bd2bf35592abc6d7668 refs/tags/v1.1.0.M4 +404e6ac13b40faf888f2d765f67b571d52d51081 refs/tags/v1.1.0.M5 +0d197a9037f5bce6d401cd46489359a3d632e49e refs/tags/v1.1.0.RC1 +700ace536e1977161925b35d4227a5a3700c9953 refs/tags/v1.1.0.RC2 +708087e0272f4878f7241371ae3d4594f317a72e refs/tags/v1.1.0.RELEASE +94174df768cc73ba1343d74a9cb96c937ed8fcab refs/tags/v1.1.1.RELEASE +35b53ba927a997f1bacc15bd2243462dcc047bea refs/tags/v1.2.0.M1 +afebf7330e2654fb810d335a44882a1c1065a5ad refs/tags/v1.2.0.RC1 +fe34beba8c71e409a7f57d3cb610f936bab5277d refs/tags/v1.2.0.RELEASE +896560df808260e57c81d401e4ceaab8f3dc1cce refs/tags/v1.2.1.RELEASE +b6f470837edf1ae24d1221217c7e5cc089008eb3 refs/tags/v1.2.2.RELEASE +968e387bb454e60bb695b71db302f801c666d317 refs/tags/v1.3.0.M1 +^a6db47353f30f3f375c6c3ebafd7c576ad48e2ba +4d75d9666c371673717103e4b517e822edd28cd4 refs/tags/v1.3.0.RELEASE +25e7890345d68539a1934da4f38839c6084307c2 refs/tags/v1.3.1.RELEASE +1c3cae40e7d0962d51a520657fbd42feb619cb6a refs/tags/v1.3.2.RC1 +29c216c41d5eaf9e937846380b4d7baa6fd0d959 refs/tags/v1.3.2.RELEASE +cc75705c436ea3d95946ef859a568e5ddba8ed54 refs/tags/v1.3.3.RELEASE +b909287d70f483437c0b9399e4827613e57aef81 refs/tags/v1.3.4.RELEASE +8c4ea8ad555e87e5166037c82e7fcbcf32eefa61 refs/tags/v1.3.5.RELEASE +7ee380793c744227042fde0079936d511e59b742 refs/tags/v2.0.0.M1 +cb2d840af1d47c4cb047ec2fa5c671c15ec1fe4c refs/tags/v2.0.0.M2 +f67585b1b04cb464ac38f661d75a0549c7374919 refs/tags/v2.0.0.M3 +c1cd51e70bd1d071468ff095b118430cc3ad1472 refs/tags/v2.0.0.M4 +e0596e8128867e1893f7c6cf3423812f66ab77f0 refs/tags/v2.0.0.M5 +8576a71e331a0873ecaf0eabe75083a3b1105f1a refs/tags/v2.0.0.M6 +f61c8eebb80b41473f8c725546379233049339ef refs/tags/v2.0.0.M7 +142f90dee998a4b8277661536643dd5ae7c2ec01 refs/tags/v2.0.0.RC1 +597baded52c30202b9b3743b964159885292e3e5 refs/tags/v2.0.0.RC2 +1974b23bec5867cbc8c8ff35b7fe41c2d947b0a8 refs/tags/v2.0.0.RELEASE +8cc6ddc9b1183da379c1c37a1b99333a1daac590 refs/tags/v2.0.1.RELEASE +365834fc97ac6d13b5899becfccd606377983a04 refs/tags/v2.0.2.RELEASE +647acce61ebd76dac94ea1ff5b9c7ef6f53b12e7 refs/tags/v2.1.0.M1 +cd5f299fb3e869751993002bee27806fa8f1284b refs/tags/v2.1.0.M2 +1a6ec6880740f84ce9d322ee38a9bfce0e5c8534 refs/tags/v2.1.0.RC1 +74d896eb2a7b016e1d0991e062c6aca8d8877268 refs/tags/v2.1.0.RC2 +779a4f40a1bf091e501396467f3b8086d3924573 refs/tags/v2.1.0.RC3 +79cb162309d9980fa85df17adccf8ee126a363d4 refs/tags/v2.1.0.RELEASE +17510d30c822f19ef8f73a0b98f35aa09b12030f refs/tags/v2.1.1.RELEASE +063595e0294987e3faea81263605806eb9498156 refs/tags/v2.1.2.RELEASE +8d2d234e0a8821042becc44429e848b37a2d51a8 refs/tags/v2.1.3.RELEASE +e2733514282a3ba050b949a915249a2b7f46e894 refs/tags/v2.1.4.RELEASE +dfc23d2add26e53ab3e7133b7df8f94c6594cd73 refs/tags/v2.2.0.M1 +907312192b6f7463b045082de8dd11f290a12d26 refs/tags/v2.2.0.M2 +05ffc7240b53c89f591ea6b6af4187a61fbb19eb refs/tags/v2.2.0.M3 +27db6026c9c4e66bf8a3bdda0e80ace76de6adeb refs/tags/v2.2.0.RC1 +764c4a2e4283086d8a2bfc6cec3c9739431a4d49 refs/tags/v2.2.0.RC2 +84de69d4e02544b726338fe03e5167daeb68e52b refs/tags/v2.2.0.RELEASE +22ba14a285b99129a05267eb4a34bc812065d129 refs/tags/v2.2.1.RELEASE +286b62f1448746e6ade6c86ed251499cf4319cf1 refs/tags/v2.2.2.RELEASE +02acecbfbfb5221967088ca6ffe56ff3253cf0d6 refs/tags/v2.2.3.RELEASE +7959e19c9a03ffa7c777dfd9bcc1955c6b9ae607 refs/tags/v2.2.4.RELEASE +b898bb90c0def99897f4a9e77af10c66ce5713bf refs/tags/v3.0.0 +5da65b2491f196905253cb1a32659b6a62175a90 refs/tags/v3.0.0-M2 +c8bfcd894928c0bff5c3f2ba67bd32815ab1e5e4 refs/tags/v3.0.0-M3 +0959a3a42220836f53cf10016671aa10ca4ca3c0 refs/tags/v3.0.0-M4 +df967da0d58b93fb57be470bdb3e9a0da0156081 refs/tags/v3.0.0-M5 +8d88bc42837081978728623c089182467ea11961 refs/tags/v3.0.0-M6 +13ec6af55a07d9d4295f505882abe6fde7be9634 refs/tags/v3.0.0-RC1 +a6b97bce521e810b6d297c54bf6c22cd43a10a3e refs/tags/v3.0.0.M1 +2eac8e7c85762788ecf999e7f8561ff885999914 refs/tags/v3.0.1 +3d1f20c1fc236a048b9fe6b6f49050384f26c49a refs/tags/v3.0.2 +65423af0c0ad73a59736abb0f388b728fe86e0bc refs/tags/v3.0.3 +10117369ea66f528515ef0dc0006ea610d777b46 refs/tags/v3.1.0 +68571b7ed03cac9e277d7cbd262bdf1f7337412a refs/tags/v3.1.0-M1 +6a45b1cb7de7b536c55fd5bb15a0ce4a481129fd refs/tags/v3.1.0-M2 +6c4980df8e34b5e750fc2d6eec58e3abe29aa9cc refs/tags/v3.1.0-M3 +51f1039d1d3b64eacfcb634a74354b407e78a477 refs/tags/v3.1.0-RC1 +c620219e9b87f900e29188db3d7ac51d3de1703f refs/tags/v3.1.2 +da3a1c7013c415b6d4e2cdfffff4455dce120b2f refs/tags/v3.1.3 +d43b0a28430e9fb383af8ec608fa9c86c8f594bc refs/tags/v4.0.0 +daa95cc2f3971eaf0c7e27def7c9f9502e3d0442 refs/tags/v4.0.0-M1 +c0f2a87a5cb9e165a22241cd41e9eee1a8ec29e3 refs/tags/v4.0.0-M2 +8a88f39f0f50b74fd712ee6219c2a92df9dd69ae refs/tags/v4.0.0-M3 +18f1980aefc10805267bd6de9dd20b0077a525b2 refs/tags/v4.0.0-M4 +e694bd46afbeeca7656f962c2ad5c2bfef3c92a6 refs/tags/v4.0.0-M5 +16ad2e3a081b0cc575bd591395d0f2c7336fe719 refs/tags/v4.0.0-RC1 +ef0a09fc7b553383ab9f3d14a1a7911b56a4ba10 refs/tags/v4.0.0-RC2 +5f7889a885483fc1c6f5f0e5057897550a13190a refs/tags/v4.0.0-RC3 +4f62ec1a80505da1faa7a6910859a395afe3fe7c refs/tags/v4.0.1 +85c0df313cfd146f3f19141d67be5d9727ba2b26 refs/tags/v4.0.3 +410aaec75448dd3bae2fcc176f2fbab481c9bc2e refs/tags/v4.1.0 +cf0c1bf98671c6f30bd09c003bdd771e946dfe45 refs/tags/v4.1.0-M1 +3714c6eee611cda1cfc77c1cc0b562f89f3210f8 refs/tags/v4.1.0-M2 +de5f981ffa02251298f019207ebac190176c3edd refs/tags/v4.1.0-RC1 +dcf7024ff47aef6d0427a4154296b48b2715b73a refs/tags/v4.1.1 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/docs-build b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/docs-build new file mode 100644 index 00000000..d2403d36 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/docs-build @@ -0,0 +1 @@ +bd817cb93cc1d46638fe8b737bb2fc5affdd5f5b diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/main b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/main new file mode 100644 index 00000000..51015d0b --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/heads/main @@ -0,0 +1 @@ +5fbd5cef4a98df979047dd51dc2a1c4951c35c98 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/remotes/origin/HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/remotes/origin/HEAD new file mode 100644 index 00000000..4b0a8759 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/git/refs/remotes/origin/HEAD @@ -0,0 +1 @@ +ref: refs/remotes/origin/main diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw new file mode 100755 index 00000000..41c0f0c2 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw @@ -0,0 +1,310 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw.cmd b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw.cmd new file mode 100644 index 00000000..86115719 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/mvnw.cmd @@ -0,0 +1,182 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + +FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/pom.xml new file mode 100644 index 00000000..cd81b8a3 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/pom.xml @@ -0,0 +1,186 @@ + + + 4.0.0 + + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + pom + + spring-cloud-bus-parent + Spring Cloud Bus Parent + + + org.springframework.cloud + spring-cloud-build + 4.1.3-SNAPSHOT + + + + + spring-cloud-bus-dependencies + spring-cloud-bus + spring-cloud-bus-rsocket + spring-cloud-bus-tests + spring-cloud-starter-bus-amqp + spring-cloud-starter-bus-kafka + spring-cloud-starter-bus-stream + docs + + + + 4.1.4-SNAPSHOT + 4.1.3-SNAPSHOT + 4.1.3-SNAPSHOT + bus + + + + + + org.codehaus.mojo + flatten-maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + io.spring.javaformat + spring-javaformat-maven-plugin + + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + + spring + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + + + + + + org.springframework.cloud + spring-cloud-bus-dependencies + ${project.version} + pom + import + + + org.springframework.cloud + spring-cloud-commons-dependencies + ${spring-cloud-commons.version} + pom + import + + + org.springframework.cloud + spring-cloud-test-support + ${spring-cloud-commons.version} + + + org.springframework.cloud + spring-cloud-stream + ${spring-cloud-stream.version} + + + org.springframework.cloud + spring-cloud-stream-dependencies + ${spring-cloud-stream.version} + pom + import + + + org.springframework.cloud + spring-cloud-function-dependencies + ${spring-cloud-function.version} + pom + import + + + org.springframework.cloud + spring-cloud-function-rsocket + ${spring-cloud-function.version} + + + + + + https://github.com/spring-cloud/spring-cloud-bus + scm:git:git://github.com/spring-cloud/spring-cloud-bus.git + + + scm:git:ssh://git@github.com/spring-cloud/spring-cloud-bus.git + + HEAD + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-dependencies/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-dependencies/pom.xml new file mode 100644 index 00000000..821c0da7 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-dependencies/pom.xml @@ -0,0 +1,101 @@ + + + 4.0.0 + + spring-cloud-dependencies-parent + org.springframework.cloud + 4.1.3-SNAPSHOT + + + spring-cloud-bus-dependencies + 4.1.2-SNAPSHOT + pom + spring-cloud-bus-dependencies + Spring Cloud Bus Dependencies + + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + ${project.version} + + + org.springframework.cloud + spring-cloud-starter-bus-kafka + ${project.version} + + + org.springframework.cloud + spring-cloud-starter-bus-stream + ${project.version} + + + org.springframework.cloud + spring-cloud-bus + ${project.version} + + + org.springframework.cloud + spring-cloud-bus-rsocket + ${project.version} + + + + + + spring + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-releases + Spring Releases + https://repo.spring.io/release + + false + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + true + + + false + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/pom.xml new file mode 100644 index 00000000..ff036c84 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + spring-cloud-bus-rsocket + jar + + spring-cloud-bus-rsocket + Spring Cloud Bus + + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + + + 0.2.0 + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-actuator + true + + + org.springframework.cloud + spring-cloud-bus + + + org.springframework.cloud + spring-cloud-function-rsocket + + + com.fasterxml.jackson.dataformat + jackson-dataformat-cbor + + + io.rsocket.routing + rsocket-routing-client-spring + ${rsocket-routing.version} + true + + + org.springframework.boot + spring-boot-autoconfigure-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.springframework.cloud + spring-cloud-test-support + test + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java new file mode 100644 index 00000000..264173a2 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketAutoConfiguration.java @@ -0,0 +1,61 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import io.rsocket.RSocket; +import io.rsocket.routing.client.spring.RoutingClientProperties; +import io.rsocket.routing.client.spring.RoutingRSocketRequester; + +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.bus.BusAutoConfiguration; +import org.springframework.cloud.bus.BusProperties; +import org.springframework.cloud.bus.BusRefreshAutoConfiguration; +import org.springframework.cloud.bus.ConditionalOnBusEnabled; +import org.springframework.cloud.bus.PathServiceMatcherAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Spencer Gibb + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@EnableConfigurationProperties(BusRSocketProperties.class) +@ConditionalOnClass({ RSocket.class, RoutingRSocketRequester.class }) +@AutoConfigureBefore({ BusAutoConfiguration.class, BusRefreshAutoConfiguration.class, + PathServiceMatcherAutoConfiguration.class }) +public class BusRSocketAutoConfiguration { + + @Bean + public RoutingClientDestinationFactory routingClientDestinationFactory(BusRSocketProperties properties) { + return new RoutingClientDestinationFactory(properties); + } + + @Bean + public RSocketRequesterBusBridge rSocketRequesterBusBridge(RoutingRSocketRequester requester) { + return new RSocketRequesterBusBridge(requester); + } + + @Bean + public RSocketServiceMatcher rSocketServiceMatcher(BusProperties properties, + RoutingClientProperties routingClientProperties) { + return new RSocketServiceMatcher(properties.getId(), routingClientProperties); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java new file mode 100644 index 00000000..51af6f88 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketEnvironmentPostProcessor.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import java.util.HashMap; +import java.util.Map; + +import io.rsocket.routing.client.spring.RoutingClientProperties; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.core.env.ConfigurableEnvironment; + +import static org.springframework.cloud.bus.BusEnvironmentPostProcessor.addOrReplace; + +/** + * {@link EnvironmentPostProcessor} that sets the default properties for the RSocket + * Routing Client. + */ +public class BusRSocketEnvironmentPostProcessor implements EnvironmentPostProcessor { + + static final String DEFAULTS_PROPERTY_SOURCE_NAME = "springCloudBusRSocketDefaultProperties"; + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + Map defaults = new HashMap<>(); + defaults.put(RoutingClientProperties.CONFIG_PREFIX + ".tags.bus", true); + addOrReplace(environment.getPropertySources(), defaults, DEFAULTS_PROPERTY_SOURCE_NAME, false); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java new file mode 100644 index 00000000..b183430d --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/BusRSocketProperties.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import java.util.LinkedHashMap; +import java.util.Map; + +import io.rsocket.routing.common.MutableKey; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.style.ToStringCreator; +import org.springframework.util.CollectionUtils; + +@ConfigurationProperties("spring.cloud.bus.rsocket") +public class BusRSocketProperties implements InitializingBean { + + private final Map defaultTags = new LinkedHashMap<>(); + + @Override + public void afterPropertiesSet() { + if (CollectionUtils.isEmpty(defaultTags)) { + defaultTags.put(MutableKey.of("bus"), "true"); + } + } + + public Map getDefaultTags() { + return this.defaultTags; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("defaultTags", defaultTags).toString(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java new file mode 100644 index 00000000..e9404d0a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketRequesterBusBridge.java @@ -0,0 +1,87 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import java.util.HashMap; +import java.util.Map; + +import io.rsocket.routing.client.spring.RoutingRSocketRequester; +import io.rsocket.routing.common.Key; +import io.rsocket.routing.common.WellKnownKey; +import io.rsocket.routing.frames.RoutingType; + +import org.springframework.cloud.bus.BusBridge; +import org.springframework.cloud.bus.BusConstants; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.util.StringUtils; + +public class RSocketRequesterBusBridge implements BusBridge { + + public RSocketRequesterBusBridge(RoutingRSocketRequester requester) { + this.requester = requester; + } + + private final RoutingRSocketRequester requester; + + @Override + public void send(RemoteApplicationEvent event) { + requester.route(BusConstants.BUS_CONSUMER).address(builder -> { + builder.routingType(RoutingType.MULTICAST); + // get tags out of destination + getTagsFromDestination(event.getDestinationService()).forEach(builder::with); + }).data(event).send().subscribe(); + } + + static Map getTagsFromDestination(String delimitedProperties) { + String[] properties = StringUtils.tokenizeToStringArray(delimitedProperties, ":"); + Map map = new HashMap<>(); + for (String property : properties) { + int index = lowestIndexOf(property, "="); + String key = (index > 0) ? property.substring(0, index) : property; + String value = (index > 0) ? property.substring(index + 1) : null; + + try { + WellKnownKey wellKnownKey = WellKnownKey.valueOf(key); + map.put(Key.of(wellKnownKey), value); + } + catch (IllegalArgumentException e) { + try { + WellKnownKey wellKnownKey = WellKnownKey.valueOf(key.toUpperCase()); + map.put(Key.of(wellKnownKey), value); + } + catch (IllegalArgumentException e2) { + // not a WellKnownKey, use string + map.put(Key.of(key), value); + } + } + + } + return map; + } + + private static int lowestIndexOf(String property, String... candidates) { + int index = -1; + for (String candidate : candidates) { + int candidateIndex = property.indexOf(candidate); + if (candidateIndex > 0) { + index = (index != -1) ? Math.min(index, candidateIndex) : candidateIndex; + } + } + return index; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java new file mode 100644 index 00000000..8944f375 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RSocketServiceMatcher.java @@ -0,0 +1,88 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import java.util.HashMap; +import java.util.Map; + +import io.rsocket.routing.client.spring.RoutingClientProperties; +import io.rsocket.routing.common.Key; +import io.rsocket.routing.common.WellKnownKey; + +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.util.AntPathMatcher; + +import static org.springframework.cloud.bus.rsocket.RSocketRequesterBusBridge.getTagsFromDestination; + +/** + * A pass thru patcher that allows the RSocket Routing broker to determine which instances + * to send to. + */ +public class RSocketServiceMatcher implements ServiceMatcher { + + private final String busId; + + private final RoutingClientProperties properties; + + private final AntPathMatcher antPathMatcher = new AntPathMatcher(); + + private final Map localTags = new HashMap<>(); + + public RSocketServiceMatcher(String busId, RoutingClientProperties properties) { + this.busId = busId; + this.properties = properties; + convertLocalTags(properties); + } + + @Override + public boolean isFromSelf(RemoteApplicationEvent event) { + String originService = event.getOriginService(); + String serviceId = getBusId(); + return antPathMatcher.match(originService, serviceId); + } + + @Override + public boolean isForSelf(RemoteApplicationEvent event) { + Map tags = getTagsFromDestination(event.getDestinationService()); + for (Map.Entry entry : tags.entrySet()) { + String existingValue = localTags.get(entry.getKey()); + if (existingValue == null || !existingValue.equals(entry.getValue())) { + return false; + } + } + return true; + } + + private void convertLocalTags(RoutingClientProperties properties) { + properties.getTags().forEach((key, value) -> { + if (key.getWellKnownKey() != null) { + localTags.put(Key.of(key.getWellKnownKey()), value); + } + else { + localTags.put(Key.of(key.getKey()), value); + } + }); + localTags.put(Key.of(WellKnownKey.SERVICE_NAME), properties.getServiceName()); + } + + @Override + public String getBusId() { + return busId; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java new file mode 100644 index 00000000..432e7c03 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/java/org/springframework/cloud/bus/rsocket/RoutingClientDestinationFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.rsocket; + +import java.util.ArrayList; + +import org.springframework.cloud.bus.event.Destination; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +public class RoutingClientDestinationFactory implements Destination.Factory { + + private final BusRSocketProperties properties; + + public RoutingClientDestinationFactory(BusRSocketProperties properties) { + this.properties = properties; + } + + @Override + public Destination getDestination(String originalDestination) { + ArrayList entries = new ArrayList<>(); + properties.getDefaultTags().forEach((key, s) -> { + String keyStr = (key.getWellKnownKey() != null) ? key.getWellKnownKey().name() : key.getKey(); + entries.add(keyStr + "=" + s); + }); + String defaultTags = StringUtils.collectionToDelimitedString(entries, ":"); + return () -> { + String destination = (ObjectUtils.isEmpty(originalDestination)) ? defaultTags + : defaultTags + ":" + originalDestination; + if (ObjectUtils.isEmpty(destination)) { + throw new IllegalArgumentException("destination may not be empty"); + } + return destination; + }; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..0d36dfe7 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Environment Post Processor +org.springframework.boot.env.EnvironmentPostProcessor=\ +org.springframework.cloud.bus.rsocket.BusRSocketEnvironmentPostProcessor diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..91a5ae78 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-rsocket/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +org.springframework.cloud.bus.rsocket.BusRSocketAutoConfiguration diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/pom.xml new file mode 100644 index 00000000..c228b202 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + spring-cloud-bus-tests + jar + + spring-cloud-bus-tests + Spring Cloud Bus Tests + + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + + + 1.17.6 + + + + + org.springframework.boot + spring-boot-starter-web + test + + + org.springframework.boot + spring-boot-starter-webflux + test + + + org.springframework.boot + spring-boot-starter-actuator + test + + + org.springframework.cloud + spring-cloud-starter-bus-amqp + test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.testcontainers + junit-jupiter + ${testcontainers.version} + test + + + org.testcontainers + rabbitmq + ${testcontainers.version} + test + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusAmqpIntegrationTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusAmqpIntegrationTests.java new file mode 100644 index 00000000..07a5b890 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusAmqpIntegrationTests.java @@ -0,0 +1,114 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.RabbitMQContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.cloud.stream.binder.ProducerProperties; +import org.springframework.cloud.stream.config.BindingServiceProperties; +import org.springframework.context.ApplicationListener; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(webEnvironment = RANDOM_PORT, properties = { "management.endpoints.web.exposure.include=*", + "spring.cloud.stream.bindings.springCloudBusOutput.producer.errorChannelEnabled=true", + "logging.level.org.springframework.cloud.bus=TRACE", "spring.cloud.bus.id=app:1", + "spring.autoconfigure.exclude=org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration" }) +@Testcontainers +public class BusAmqpIntegrationTests { + + @Container + private static final RabbitMQContainer rabbitMQContainer = new RabbitMQContainer( + "rabbitmq:3.7.25-management-alpine"); + + private static ConfigurableApplicationContext context; + + @Autowired + private BindingServiceProperties bindingServiceProperties; + + @DynamicPropertySource + static void properties(DynamicPropertyRegistry registry) { + registry.add("spring.rabbitmq.host", rabbitMQContainer::getHost); + registry.add("spring.rabbitmq.port", rabbitMQContainer::getAmqpPort); + } + + @BeforeAll + static void before() { + context = new SpringApplicationBuilder(TestConfig.class).properties("server.port=0", + "spring.rabbitmq.host=" + rabbitMQContainer.getHost(), + "spring.rabbitmq.port=" + rabbitMQContainer.getAmqpPort(), + "management.endpoints.web.exposure.include=*", "spring.cloud.bus.id=app:2", + "spring.autoconfigure.exclude=org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration") + .run(); + } + + @AfterAll + static void after() { + if (context != null) { + context.close(); + } + } + + @Test + void remoteEventsAreSentViaAmqp(@Autowired WebTestClient client, @Autowired TestConfig testConfig) + throws InterruptedException { + assertThat(rabbitMQContainer.isRunning()); + HashMap map = new HashMap<>(); + map.put("name", "foo"); + map.put("value", "bar"); + client.post().uri("/actuator/busenv").bodyValue(map).exchange().expectStatus().is2xxSuccessful(); + TestConfig remoteTestConfig = context.getBean(TestConfig.class); + assertThat(remoteTestConfig.latch.await(5, TimeUnit.SECONDS)).isTrue(); + assertThat(testConfig.latch.await(5, TimeUnit.SECONDS)).isTrue(); + ProducerProperties producerProperties = bindingServiceProperties.getProducerProperties(BusConstants.OUTPUT); + assertThat(producerProperties.isErrorChannelEnabled()).isTrue(); + } + + @SpringBootConfiguration + @EnableAutoConfiguration + static class TestConfig implements ApplicationListener { + + CountDownLatch latch = new CountDownLatch(1); + + @Override + public void onApplicationEvent(EnvironmentChangeRemoteApplicationEvent event) { + latch.countDown(); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java new file mode 100644 index 00000000..4c274921 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/BusJmxEndpointTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.bus.endpoint.EnvironmentBusEndpoint; +import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(properties = { "spring.jmx.enabled=true", "endpoints.default.jmx.enabled=true", + "management.endpoints..jmx.exposure.include=busrefresh,busenv", "debug=true" }) +public class BusJmxEndpointTests { + + @Autowired(required = false) + private RefreshBusEndpoint refreshBusEndpoint; + + @Autowired(required = false) + private EnvironmentBusEndpoint environmentBusEndpoint; + + @Test + public void contextLoads() { + assertThat(this.refreshBusEndpoint).isNotNull(); + assertThat(this.environmentBusEndpoint).isNotNull(); + } + + @SpringBootConfiguration + @EnableAutoConfiguration + protected static class TestConfig { + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java new file mode 100644 index 00000000..ae3e9a23 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus-tests/src/test/java/org/springframework/cloud/bus/jackson/BusJacksonIntegrationTests.java @@ -0,0 +1,147 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +import com.fasterxml.jackson.databind.SerializationFeature; +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.event.EventListener; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RestController; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(properties = "spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS:true", + webEnvironment = RANDOM_PORT) +@DirtiesContext +public class BusJacksonIntegrationTests { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate rest; + + @Autowired + private BusJacksonMessageConverter converter; + + @Test + @SuppressWarnings("unchecked") + public void testCustomEventSerializes() { + assertThat(this.converter.isMapperCreated()).isFalse(); + + // set by configuration + assertThat(this.converter.getMapper().getSerializationConfig() + .isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)).isTrue(); + + Map map = this.rest.getForObject("http://localhost:" + this.port + "/date", Map.class); + assertThat(map).containsOnlyKeys("date"); + assertThat(map.get("date")).isInstanceOf(Long.class); + + this.rest.put("http://localhost:" + this.port + "/names" + "/foo", null); + this.rest.put("http://localhost:" + this.port + "/names" + "/bar", null); + + ResponseEntity response = this.rest.getForEntity("http://localhost:" + this.port + "/names", List.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).contains("foo", "bar"); + } + + public static class NameEvent extends RemoteApplicationEvent { + + private String name; + + protected NameEvent() { + } + + public NameEvent(Object source, String originService, String name) { + super(source, originService); + this.name = name; + } + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + } + + @RestController + @EnableAutoConfiguration + @SpringBootConfiguration + @RemoteApplicationEventScan + protected static class Config { + + final private Set names = ConcurrentHashMap.newKeySet(); + + @Autowired + private ServiceMatcher busServiceMatcher; + + @Autowired + private ApplicationEventPublisher publisher; + + @GetMapping("/names") + public Collection names() { + return this.names; + } + + @PutMapping("/names/{name}") + public void sayName(@PathVariable String name) { + this.names.add(name); + this.publisher.publishEvent(new NameEvent(this, this.busServiceMatcher.getBusId(), name)); + } + + @GetMapping("/date") + public Map testTimeJsonSerialization() { + Map map = new HashMap<>(); + map.put("date", new Date()); + return map; + } + + @EventListener + public void handleNameSaid(NameEvent event) { + this.names.add(event.getName()); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/pom.xml new file mode 100644 index 00000000..f17393f4 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + + spring-cloud-bus + jar + + spring-cloud-bus + Spring Cloud Bus + + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-actuator + true + + + org.springframework.boot + spring-boot-starter-web + true + + + org.springframework.cloud + spring-cloud-starter + + + org.springframework.cloud + spring-cloud-stream + true + + + org.springframework.integration + spring-integration-core + + + com.fasterxml.jackson.dataformat + jackson-dataformat-cbor + true + + + org.springframework.boot + spring-boot-autoconfigure-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.springframework.cloud + spring-cloud-test-support + test + + + org.springframework.cloud + spring-cloud-stream-test-binder + ${spring-cloud-stream.version} + test + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java new file mode 100644 index 00000000..cf4a8d85 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusAutoConfiguration.java @@ -0,0 +1,109 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.bus.endpoint.EnvironmentBusEndpoint; +import org.springframework.cloud.bus.event.Destination; +import org.springframework.cloud.bus.event.EnvironmentChangeListener; +import org.springframework.cloud.bus.event.PathDestinationFactory; +import org.springframework.cloud.bus.event.TraceListener; +import org.springframework.cloud.context.environment.EnvironmentManager; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.springframework.cloud.bus.BusConstants.BUS_CONSUMER; + +/** + * @author Spencer Gibb + * @author Dave Syer + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@EnableConfigurationProperties(BusProperties.class) +public class BusAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(Destination.Factory.class) + public PathDestinationFactory pathDestinationFactory() { + return new PathDestinationFactory(); + } + + @Bean + @ConditionalOnMissingBean + public RemoteApplicationEventListener busRemoteApplicationEventListener(ServiceMatcher serviceMatcher, + BusBridge busBridge) { + return new RemoteApplicationEventListener(serviceMatcher, busBridge); + } + + @Bean + @ConditionalOnMissingBean(name = BUS_CONSUMER) + public BusConsumer busConsumer(ApplicationEventPublisher applicationEventPublisher, ServiceMatcher serviceMatcher, + ObjectProvider busBridge, BusProperties properties, Destination.Factory destinationFactory) { + return new BusConsumer(applicationEventPublisher, serviceMatcher, busBridge, properties, destinationFactory); + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass({ Endpoint.class }) + @ConditionalOnBean(HttpExchangeRepository.class) + @ConditionalOnProperty(BusProperties.PREFIX + ".trace.enabled") + protected static class BusAckTraceConfiguration { + + @Bean + @ConditionalOnMissingBean + public TraceListener ackTraceListener(HttpExchangeRepository repository) { + return new TraceListener(repository); + } + + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(EnvironmentManager.class) + @ConditionalOnBean(EnvironmentManager.class) + protected static class BusEnvironmentConfiguration { + + @Bean + @ConditionalOnProperty(value = "spring.cloud.bus.env.enabled", matchIfMissing = true) + public EnvironmentChangeListener environmentChangeListener() { + return new EnvironmentChangeListener(); + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(Endpoint.class) + protected static class EnvironmentBusEndpointConfiguration { + + @Bean + @ConditionalOnAvailableEndpoint + public EnvironmentBusEndpoint environmentBusEndpoint(ApplicationEventPublisher publisher, BusProperties bus, + Destination.Factory destinationFactory) { + return new EnvironmentBusEndpoint(publisher, bus.getId(), destinationFactory); + } + + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusBridge.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusBridge.java new file mode 100644 index 00000000..be95194f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusBridge.java @@ -0,0 +1,25 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +public interface BusBridge { + + void send(RemoteApplicationEvent event); + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConstants.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConstants.java new file mode 100644 index 00000000..0d1ee110 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConstants.java @@ -0,0 +1,45 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +/** + * @author Dave Syer + * + */ +public abstract class BusConstants { + + /** + * Name of the input channel for Spring Cloud Bus. + */ + public static final String INPUT = "springCloudBusInput"; + + /** + * Name of the output channel for Spring Cloud Bus. + */ + public static final String OUTPUT = "springCloudBusOutput"; + + /** + * Name of the binding destination for Spring Cloud Bus. + */ + public static final String DESTINATION = "springCloudBus"; + + /** + * Name of the Spring Cloud Bus function. + */ + public static final String BUS_CONSUMER = "busConsumer"; + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConsumer.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConsumer.java new file mode 100644 index 00000000..dccf2748 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusConsumer.java @@ -0,0 +1,89 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.function.Consumer; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; +import org.springframework.cloud.bus.event.Destination; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.bus.event.SentApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; + +public class BusConsumer implements Consumer { + + private final Log log = LogFactory.getLog(getClass()); + + private final ApplicationEventPublisher publisher; + + private final ServiceMatcher serviceMatcher; + + private final ObjectProvider busBridge; + + private final BusProperties properties; + + private final Destination.Factory destinationFactory; + + public BusConsumer(ApplicationEventPublisher publisher, ServiceMatcher serviceMatcher, + ObjectProvider busBridge, BusProperties properties, Destination.Factory destinationFactory) { + this.publisher = publisher; + this.serviceMatcher = serviceMatcher; + this.busBridge = busBridge; + this.properties = properties; + this.destinationFactory = destinationFactory; + } + + @Override + public void accept(RemoteApplicationEvent event) { + if (event instanceof AckRemoteApplicationEvent) { + if (this.properties.getTrace().isEnabled() && !this.serviceMatcher.isFromSelf(event) + && this.publisher != null) { + this.publisher.publishEvent(event); + } + // If it's an ACK we are finished processing at this point + return; + } + + if (log.isDebugEnabled()) { + log.debug("Received remote event from bus: " + event); + } + + if (this.serviceMatcher.isForSelf(event) && this.publisher != null) { + if (!this.serviceMatcher.isFromSelf(event)) { + this.publisher.publishEvent(event); + } + if (this.properties.getAck().isEnabled()) { + AckRemoteApplicationEvent ack = new AckRemoteApplicationEvent(this, this.serviceMatcher.getBusId(), + destinationFactory.getDestination(this.properties.getAck().getDestinationService()), + event.getDestinationService(), event.getId(), event.getClass()); + this.busBridge.ifAvailable(bridge -> bridge.send(ack)); + this.publisher.publishEvent(ack); + } + } + if (this.properties.getTrace().isEnabled() && this.publisher != null) { + // We are set to register sent events so publish it for local consumption, + // irrespective of the origin + this.publisher.publishEvent(new SentApplicationEvent(this, event.getOriginService(), + event.getDestinationService(), event.getId(), event.getClass())); + } + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java new file mode 100644 index 00000000..78eaee0f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusEnvironmentPostProcessor.java @@ -0,0 +1,112 @@ +/* + * Copyright 2012-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.cloud.commons.util.IdUtils; +import org.springframework.cloud.function.context.FunctionProperties; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; +import org.springframework.util.StringUtils; + +import static org.springframework.cloud.bus.BusProperties.PREFIX; + +/** + * {@link EnvironmentPostProcessor} that sets the default properties for the Bus. + * + * @author Dave Syer + * @since 1.0.0 + */ +public class BusEnvironmentPostProcessor implements EnvironmentPostProcessor { + + static final String DEFAULTS_PROPERTY_SOURCE_NAME = "springCloudBusDefaultProperties"; + + static final String OVERRIDES_PROPERTY_SOURCE_NAME = "springCloudBusOverridesProperties"; + + private static final String FN_DEF_PROP = FunctionProperties.PREFIX + ".definition"; + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + if (environment.containsProperty(ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED)) { + if (Boolean.FALSE.toString() + .equalsIgnoreCase(environment.getProperty(ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED))) { + return; + } + } + Map overrides = new HashMap<>(); + String definition = BusConstants.BUS_CONSUMER; + if (environment.containsProperty(FN_DEF_PROP)) { + String property = environment.getProperty(FN_DEF_PROP); + if (property != null && property.contains(BusConstants.BUS_CONSUMER)) { + // in the case that EnvironmentPostProcessor are run more than once. + return; + } + definition = property + ";" + definition; + } + overrides.put(FN_DEF_PROP, definition); + addOrReplace(environment.getPropertySources(), overrides, OVERRIDES_PROPERTY_SOURCE_NAME, true); + + Map defaults = new HashMap<>(); + defaults.put("spring.cloud.stream.function.bindings." + BusConstants.BUS_CONSUMER + "-in-0", + BusConstants.INPUT); + String destination = environment.getProperty(PREFIX + ".destination", BusConstants.DESTINATION); + defaults.put("spring.cloud.stream.bindings." + BusConstants.INPUT + ".destination", destination); + defaults.put("spring.cloud.stream.bindings." + BusConstants.OUTPUT + ".destination", destination); + if (!environment.containsProperty(PREFIX + ".id")) { + String unresolvedServiceId = IdUtils.getUnresolvedServiceId(); + if (StringUtils.hasText(environment.getProperty("spring.profiles.active"))) { + unresolvedServiceId = IdUtils.getUnresolvedServiceIdWithActiveProfiles(); + } + defaults.put(PREFIX + ".id", unresolvedServiceId); + } + addOrReplace(environment.getPropertySources(), defaults, DEFAULTS_PROPERTY_SOURCE_NAME, false); + } + + public static void addOrReplace(MutablePropertySources propertySources, Map map, + String propertySourceName, boolean first) { + MapPropertySource target = null; + if (propertySources.contains(propertySourceName)) { + PropertySource source = propertySources.get(propertySourceName); + if (source instanceof MapPropertySource) { + target = (MapPropertySource) source; + for (String key : map.keySet()) { + if (!target.containsProperty(key)) { + target.getSource().put(key, map.get(key)); + } + } + } + } + if (target == null) { + target = new MapPropertySource(propertySourceName, map); + } + if (!propertySources.contains(propertySourceName)) { + if (first) { + propertySources.addFirst(target); + } + else { + propertySources.addLast(target); + } + } + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java new file mode 100644 index 00000000..19ddb18f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusPathMatcher.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.beans.factory.annotation.Qualifier; + +/** + * Qualifier annotation for components to do with matching paths in the bus. + * + * @author Dave Syer + * + */ +@Qualifier +@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER }) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +public @interface BusPathMatcher { + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java new file mode 100644 index 00000000..0daa9a12 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusProperties.java @@ -0,0 +1,177 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.core.style.ToStringCreator; +import org.springframework.util.MimeType; +import org.springframework.util.MimeTypeUtils; + +/** + * @author Dave Syer + * + */ +@ConfigurationProperties(BusProperties.PREFIX) +public class BusProperties { + + /** + * Configuration prefix for spring cloud bus. + */ + public static final String PREFIX = "spring.cloud.bus"; + + /** + * Properties related to acks. + */ + private final Ack ack = new Ack(); + + /** + * Properties related to tracing of acks. + */ + private final Trace trace = new Trace(); + + /** + * Name of Spring Cloud Stream destination for messages. + */ + private String destination = BusConstants.DESTINATION; + + /** + * The identifier for this application instance. + */ + private String id = "application"; + + /** + * The bus mime-type. + */ + private MimeType contentType = MimeTypeUtils.APPLICATION_JSON; + + /** + * Flag to indicate that the bus is enabled. + */ + private boolean enabled = true; + + public Ack getAck() { + return this.ack; + } + + public Trace getTrace() { + return this.trace; + } + + public String getDestination() { + return this.destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getId() { + return this.id; + } + + public void setId(String id) { + this.id = id; + } + + public MimeType getContentType() { + return this.contentType; + } + + public void setContentType(MimeType contentType) { + this.contentType = contentType; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("ack", ack).append("trace", trace).append("destination", destination) + .append("id", id).append("contentType", contentType).append("enabled", enabled).toString(); + + } + + /** + * Spring Cloud Bus properties related to acknowledgments. + */ + public static class Ack { + + /** + * Flag to switch off acks (default on). + */ + private boolean enabled = true; + + /** + * Service that wants to listen to acks. By default null (meaning all services). + */ + private String destinationService; + + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getDestinationService() { + return this.destinationService; + } + + public void setDestinationService(String destinationService) { + this.destinationService = destinationService; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("enabled", enabled).append("destinationService", destinationService) + .toString(); + } + + } + + /** + * Spring Cloud Bus trace properties. + */ + public static class Trace { + + /** + * Flag to switch on tracing of acks (default off). + */ + private boolean enabled = false; + + public boolean isEnabled() { + return this.enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("enabled", enabled).toString(); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusRefreshAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusRefreshAutoConfiguration.java new file mode 100644 index 00000000..de936dcf --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusRefreshAutoConfiguration.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint; +import org.springframework.cloud.bus.event.Destination; +import org.springframework.cloud.bus.event.RefreshListener; +import org.springframework.cloud.context.refresh.ContextRefresher; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author Ryan Baxter + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@AutoConfigureAfter(name = { "org.springframework.cloud.autoconfigure.RefreshAutoConfiguration" }) +public class BusRefreshAutoConfiguration { + + @Bean + @ConditionalOnProperty(value = "spring.cloud.bus.refresh.enabled", matchIfMissing = true) + @ConditionalOnBean(ContextRefresher.class) + public RefreshListener refreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) { + return new RefreshListener(contextRefresher, serviceMatcher); + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(name = { "org.springframework.boot.actuate.endpoint.annotation.Endpoint", + "org.springframework.cloud.context.scope.refresh.RefreshScope" }) + protected static class BusRefreshEndpointConfiguration { + + @Bean + @ConditionalOnAvailableEndpoint + public RefreshBusEndpoint refreshBusEndpoint(ApplicationEventPublisher publisher, BusProperties bus, + Destination.Factory destinationFactory) { + return new RefreshBusEndpoint(publisher, bus.getId(), destinationFactory); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusStreamAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusStreamAutoConfiguration.java new file mode 100644 index 00000000..19ada031 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/BusStreamAutoConfiguration.java @@ -0,0 +1,45 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.autoconfigure.LifecycleMvcEndpointAutoConfiguration; +import org.springframework.cloud.stream.config.BindingServiceConfiguration; +import org.springframework.cloud.stream.function.StreamBridge; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@ConditionalOnClass({ StreamBridge.class, BindingServiceConfiguration.class }) +@EnableConfigurationProperties(BusProperties.class) +@AutoConfigureBefore({ BindingServiceConfiguration.class, BusAutoConfiguration.class }) +// so stream bindings work properly +@AutoConfigureAfter({ LifecycleMvcEndpointAutoConfiguration.class, PathServiceMatcherAutoConfiguration.class }) +public class BusStreamAutoConfiguration { + + @Bean + @ConditionalOnMissingBean(BusBridge.class) + public StreamBusBridge streamBusBridge(StreamBridge streamBridge, BusProperties properties) { + return new StreamBusBridge(streamBridge, properties); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java new file mode 100644 index 00000000..fb9aea27 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ConditionalOnBusEnabled.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; + +/** + * @author Spencer Gibb + */ +@ConditionalOnProperty(value = ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED, matchIfMissing = true) +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +public @interface ConditionalOnBusEnabled { + + /** + * Property name to enable / disable Spring Cloud Bus. + */ + String SPRING_CLOUD_BUS_ENABLED = "spring.cloud.bus.enabled"; + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java new file mode 100644 index 00000000..800f990a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/DefaultBusPathMatcher.java @@ -0,0 +1,141 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.Comparator; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.util.PathMatcher; +import org.springframework.util.StringUtils; + +import static org.springframework.util.StringUtils.tokenizeToStringArray; + +/** + * {@link BusPathMatcher} that matches application context ids with multiple, + * comma-separated, profiles. Original + * https://gist.github.com/kelapure/61d3f948acf478cc95225ff1d7d239c4 + * + * See https://github.com/spring-cloud/spring-cloud-config/issues/678 + * + * @author Rohit Kelapure + * @author Spencer Gibb + */ +public class DefaultBusPathMatcher implements PathMatcher { + + private static final Log log = LogFactory.getLog(DefaultBusPathMatcher.class); + + private final PathMatcher delagateMatcher; + + public DefaultBusPathMatcher(PathMatcher delagateMatcher) { + this.delagateMatcher = delagateMatcher; + } + + protected boolean matchMultiProfile(String pattern, String idToMatch) { + + if (log.isDebugEnabled()) { + log.debug("matchMultiProfile : " + pattern + ", " + idToMatch); + } + + // parse the id + String[] tokens = tokenizeToStringArray(idToMatch, ":"); + if (tokens.length <= 1) { + // no parts, default to delegate which already returned false; + return false; + } + String selfProfiles = tokens[1]; + + // short circuit if possible + String[] profiles = tokenizeToStringArray(selfProfiles, ","); + + if (profiles.length == 1) { + // there aren't multiple profiles to check, the delegate match was + // originally false so return what delegate determined + return false; + } + + // gather candidate ids with a single profile rather than a comma separated list + String[] idsWithSingleProfile = new String[profiles.length]; + + for (int i = 0; i < profiles.length; i++) { + // replace comma separated profiles with single profile + String profile = profiles[i]; + String[] newTokens = new String[tokens.length]; + System.arraycopy(tokens, 0, newTokens, 0, tokens.length); + newTokens[1] = profile; + idsWithSingleProfile[i] = StringUtils.arrayToDelimitedString(newTokens, ":"); + } + + for (String id : idsWithSingleProfile) { + if (this.delagateMatcher.match(pattern, id)) { + if (log.isDebugEnabled()) { + log.debug("matched true"); + } + return true; + } + } + + if (log.isDebugEnabled()) { + log.debug("matched false"); + } + return false; + } + + @Override + public boolean isPattern(String path) { + return this.delagateMatcher.isPattern(path); + } + + @Override + public boolean match(String pattern, String path) { + if (log.isDebugEnabled()) { + log.debug("In match: " + pattern + ", " + path); + } + if (!this.delagateMatcher.match(pattern, path)) { + return matchMultiProfile(pattern, path); + } + return true; + } + + @Override + public boolean matchStart(String pattern, String path) { + return this.delagateMatcher.matchStart(pattern, path); + } + + @Override + public String extractPathWithinPattern(String pattern, String path) { + return this.delagateMatcher.extractPathWithinPattern(pattern, path); + } + + @Override + public Map extractUriTemplateVariables(String pattern, String path) { + return this.delagateMatcher.extractUriTemplateVariables(pattern, path); + } + + @Override + public Comparator getPatternComparator(String path) { + return this.delagateMatcher.getPatternComparator(path); + } + + @Override + public String combine(String pattern1, String pattern2) { + return this.delagateMatcher.combine(pattern1, pattern2); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcher.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcher.java new file mode 100644 index 00000000..b0e2534a --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcher.java @@ -0,0 +1,79 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.util.PathMatcher; + +/** + * @author Spencer Gibb + */ +public class PathServiceMatcher implements ServiceMatcher { + + private final PathMatcher matcher; + + private final String id; + + private String[] configNames = new String[] {}; + + public PathServiceMatcher(PathMatcher matcher, String id) { + this.matcher = matcher; + this.id = id; + } + + public PathServiceMatcher(PathMatcher matcher, String id, String[] configNames) { + this(matcher, id); + + int colonIndex = id.indexOf(":"); + if (colonIndex >= 0) { + // if the id contains profiles and port, append them to the config names + String profilesAndPort = id.substring(colonIndex); + for (int i = 0; i < configNames.length; i++) { + configNames[i] = configNames[i] + profilesAndPort; + } + } + this.configNames = configNames; + } + + public boolean isFromSelf(RemoteApplicationEvent event) { + String originService = event.getOriginService(); + String serviceId = getBusId(); + return this.matcher.match(originService, serviceId); + } + + public boolean isForSelf(RemoteApplicationEvent event) { + String destinationService = event.getDestinationService(); + if (destinationService == null || destinationService.trim().isEmpty() + || this.matcher.match(destinationService, getBusId())) { + return true; + } + + // Check all potential config names instead of service name + for (String configName : this.configNames) { + if (this.matcher.match(destinationService, configName)) { + return true; + } + } + + return false; + } + + public String getBusId() { + return this.id; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcherAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcherAutoConfiguration.java new file mode 100644 index 00000000..fa745b85 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/PathServiceMatcherAutoConfiguration.java @@ -0,0 +1,61 @@ +/* + * Copyright 2012-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.util.AntPathMatcher; +import org.springframework.util.PathMatcher; + +/** + * @author Ryan Baxter + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@EnableConfigurationProperties(BusProperties.class) +public class PathServiceMatcherAutoConfiguration { + + /** + * Name of the Bus path matcher. + */ + public static final String BUS_PATH_MATCHER_NAME = "busPathMatcher"; + + /** + * Name of the Spring Cloud Config property. + */ + public static final String CLOUD_CONFIG_NAME_PROPERTY = "spring.cloud.config.name"; + + @BusPathMatcher + // There is a @Bean of type PathMatcher coming from Spring MVC + @ConditionalOnMissingBean(name = BUS_PATH_MATCHER_NAME) + @Bean(name = BUS_PATH_MATCHER_NAME) + public PathMatcher busPathMatcher() { + return new DefaultBusPathMatcher(new AntPathMatcher(":")); + } + + @Bean + @ConditionalOnMissingBean(ServiceMatcher.class) + public PathServiceMatcher pathServiceMatcher(@BusPathMatcher PathMatcher pathMatcher, BusProperties properties, + Environment environment) { + String[] configNames = environment.getProperty(CLOUD_CONFIG_NAME_PROPERTY, String[].class, new String[] {}); + return new PathServiceMatcher(pathMatcher, properties.getId(), configNames); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/RemoteApplicationEventListener.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/RemoteApplicationEventListener.java new file mode 100644 index 00000000..d7581f86 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/RemoteApplicationEventListener.java @@ -0,0 +1,50 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.context.ApplicationListener; + +public class RemoteApplicationEventListener implements ApplicationListener { + + private final Log log = LogFactory.getLog(getClass()); + + private final ServiceMatcher serviceMatcher; + + private final BusBridge busBridge; + + public RemoteApplicationEventListener(ServiceMatcher serviceMatcher, BusBridge busBridge) { + this.serviceMatcher = serviceMatcher; + this.busBridge = busBridge; + } + + @Override + public void onApplicationEvent(RemoteApplicationEvent event) { + if (this.serviceMatcher.isFromSelf(event) && !(event instanceof AckRemoteApplicationEvent)) { + if (log.isDebugEnabled()) { + log.debug("Sending remote event on bus: " + event); + } + // TODO: configurable mimetype? + this.busBridge.send(event); + } + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java new file mode 100644 index 00000000..e7d4c913 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/ServiceMatcher.java @@ -0,0 +1,32 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +/** + * @author Spencer Gibb + */ +public interface ServiceMatcher { + + boolean isFromSelf(RemoteApplicationEvent event); + + boolean isForSelf(RemoteApplicationEvent event); + + String getBusId(); + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/StreamBusBridge.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/StreamBusBridge.java new file mode 100644 index 00000000..eddc06d8 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/StreamBusBridge.java @@ -0,0 +1,39 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.stream.function.StreamBridge; +import org.springframework.messaging.support.MessageBuilder; + +public class StreamBusBridge implements BusBridge { + + private final StreamBridge streamBridge; + + private final BusProperties properties; + + public StreamBusBridge(StreamBridge streamBridge, BusProperties properties) { + this.streamBridge = streamBridge; + this.properties = properties; + } + + public void send(RemoteApplicationEvent event) { + // TODO: configurable mimetype? + this.streamBridge.send(BusConstants.OUTPUT, MessageBuilder.withPayload(event).build()); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java new file mode 100644 index 00000000..c48ab783 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/AbstractBusEndpoint.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.endpoint; + +import org.springframework.cloud.bus.event.Destination; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; + +/** + * @author Spencer Gibb + */ +public class AbstractBusEndpoint { + + private ApplicationEventPublisher publisher; + + private String appId; + + private final Destination.Factory destinationFactory; + + public AbstractBusEndpoint(ApplicationEventPublisher publisher, String appId, + Destination.Factory destinationFactory) { + this.publisher = publisher; + this.appId = appId; + this.destinationFactory = destinationFactory; + } + + protected String getInstanceId() { + return this.appId; + } + + protected Destination.Factory getDestinationFactory() { + return this.destinationFactory; + } + + protected Destination getDestination(String original) { + return destinationFactory.getDestination(original); + } + + protected void publish(ApplicationEvent event) { + this.publisher.publishEvent(event); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java new file mode 100644 index 00000000..b2f93e35 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/EnvironmentBusEndpoint.java @@ -0,0 +1,58 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.endpoint; + +import java.util.Collections; +import java.util.Map; + +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.Selector; +import org.springframework.boot.actuate.endpoint.annotation.Selector.Match; +import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; +import org.springframework.cloud.bus.event.Destination; +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.util.StringUtils; + +/** + * @author Spencer Gibb + */ +@Endpoint(id = "busenv") // TODO: document +public class EnvironmentBusEndpoint extends AbstractBusEndpoint { + + public EnvironmentBusEndpoint(ApplicationEventPublisher publisher, String id, + Destination.Factory destinationFactory) { + super(publisher, id, destinationFactory); + } + + @WriteOperation + // TODO: document params + public void busEnvWithDestination(String name, String value, + @Selector(match = Match.ALL_REMAINING) String[] destinations) { + Map params = Collections.singletonMap(name, value); + String destination = StringUtils.arrayToDelimitedString(destinations, ":"); + publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), getDestination(destination), + params)); + } + + @WriteOperation + public void busEnv(String name, String value) { // TODO: document params + Map params = Collections.singletonMap(name, value); + publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(), getDestination(null), params)); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java new file mode 100644 index 00000000..31b2297c --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpoint.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.endpoint; + +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.Selector; +import org.springframework.boot.actuate.endpoint.annotation.Selector.Match; +import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; +import org.springframework.cloud.bus.event.Destination; +import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.util.StringUtils; + +/** + * @author Spencer Gibb + */ +@Endpoint(id = "busrefresh") // TODO: document new id +public class RefreshBusEndpoint extends AbstractBusEndpoint { + + public RefreshBusEndpoint(ApplicationEventPublisher publisher, String id, Destination.Factory destinationFactory) { + super(publisher, id, destinationFactory); + } + + @WriteOperation + public void busRefreshWithDestination(@Selector(match = Match.ALL_REMAINING) String[] destinations) { + String destination = StringUtils.arrayToDelimitedString(destinations, ":"); + publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(destination))); + } + + @WriteOperation + public void busRefresh() { + publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), getDestination(null))); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java new file mode 100644 index 00000000..61c3c295 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/AckRemoteApplicationEvent.java @@ -0,0 +1,133 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * An event that signals an ack of a specific {@link RemoteApplicationEvent}. These events + * can be monitored by any applications that want to audit the responses to bus events. + * They behave like normal remote application events, in the sense that if the destination + * service matches the local service ID the application fires the event in its context. + * + * @author Dave Syer + * + */ +@SuppressWarnings("serial") +public class AckRemoteApplicationEvent extends RemoteApplicationEvent { + + private final String ackId; + + private final String ackDestinationService; + + private Class event; + + @SuppressWarnings("unused") + private AckRemoteApplicationEvent() { + super(); + this.ackDestinationService = null; + this.ackId = null; + this.event = null; + } + + public AckRemoteApplicationEvent(Object source, String originService, Destination destination, + String ackDestinationService, String ackId, Class type) { + super(source, originService, destination); + this.ackDestinationService = ackDestinationService; + this.ackId = ackId; + this.event = type; + } + + public String getAckId() { + return this.ackId; + } + + public String getAckDestinationService() { + return this.ackDestinationService; + } + + public Class getEvent() { + return this.event; + } + + /** + * Used by Jackson to set the remote class name of the event implementation. If the + * implementing class is unknown to this app, set the event to + * {@link UnknownRemoteApplicationEvent}. + * @param eventName the fq class name of the event implementation, not null + */ + @JsonProperty("event") + @SuppressWarnings("unchecked") + public void setEventName(String eventName) { + try { + this.event = (Class) Class.forName(eventName); + } + catch (ClassNotFoundException e) { + this.event = UnknownRemoteApplicationEvent.class; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.ackDestinationService == null) ? 0 : this.ackDestinationService.hashCode()); + result = prime * result + ((this.ackId == null) ? 0 : this.ackId.hashCode()); + result = prime * result + ((this.event == null) ? 0 : this.event.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AckRemoteApplicationEvent other = (AckRemoteApplicationEvent) obj; + if (this.ackDestinationService == null) { + if (other.ackDestinationService != null) { + return false; + } + } + else if (!this.ackDestinationService.equals(other.ackDestinationService)) { + return false; + } + if (this.ackId == null) { + if (other.ackId != null) { + return false; + } + } + else if (!this.ackId.equals(other.ackId)) { + return false; + } + if (this.event == null) { + if (other.event != null) { + return false; + } + } + else if (!this.event.equals(other.event)) { + return false; + } + return true; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/Destination.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/Destination.java new file mode 100644 index 00000000..efd0595e --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/Destination.java @@ -0,0 +1,30 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +public interface Destination { + + String getDestinationAsString(); + + @FunctionalInterface + interface Factory { + + Destination getDestination(String originalDestination); + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java new file mode 100644 index 00000000..c5e4af9f --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeListener.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.context.environment.EnvironmentManager; +import org.springframework.context.ApplicationListener; + +/** + * @author Spencer Gibb + */ +public class EnvironmentChangeListener implements ApplicationListener { + + private static Log log = LogFactory.getLog(EnvironmentChangeListener.class); + + @Autowired + private EnvironmentManager env; + + @Override + public void onApplicationEvent(EnvironmentChangeRemoteApplicationEvent event) { + Map values = event.getValues(); + log.info("Received remote environment change request. Keys/values to update " + values); + for (Map.Entry entry : values.entrySet()) { + this.env.setProperty(entry.getKey(), entry.getValue()); + } + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java new file mode 100644 index 00000000..d0ef03f5 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/EnvironmentChangeRemoteApplicationEvent.java @@ -0,0 +1,93 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import java.util.Map; + +import org.springframework.core.style.ToStringCreator; +import org.springframework.util.Assert; + +/** + * @author Spencer Gibb + */ +@SuppressWarnings("serial") +public class EnvironmentChangeRemoteApplicationEvent extends RemoteApplicationEvent { + + private final Map values; + + @SuppressWarnings("unused") + private EnvironmentChangeRemoteApplicationEvent() { + // for serializers + this.values = null; + } + + @Deprecated + public EnvironmentChangeRemoteApplicationEvent(Object source, String originService, String destinationService, + Map values) { + this(source, originService, new PathDestinationFactory().getDestination(destinationService), values); + } + + public EnvironmentChangeRemoteApplicationEvent(Object source, String originService, Destination destination, + Map values) { + super(source, originService, destination); + Assert.notNull(values, "values may not be null"); + this.values = values; + } + + public Map getValues() { + return this.values; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((this.values == null) ? 0 : this.values.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnvironmentChangeRemoteApplicationEvent other = (EnvironmentChangeRemoteApplicationEvent) obj; + if (this.values == null) { + if (other.values != null) { + return false; + } + } + else if (!this.values.equals(other.values)) { + return false; + } + return true; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService()) + .append("destinationService", getDestinationService()).append("values", values).toString(); + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/PathDestinationFactory.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/PathDestinationFactory.java new file mode 100644 index 00000000..d63edd33 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/PathDestinationFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright 2015-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import org.springframework.util.StringUtils; + +public class PathDestinationFactory implements Destination.Factory { + + public Destination getDestination(String originalDestination) { + String path = originalDestination; + if (path == null) { + path = "**"; + } + // If the path is not already a wildcard, match everything that + // follows if there at most two path elements, and last element is not a global + // wildcard already + if (!"**".equals(path)) { + if (StringUtils.countOccurrencesOf(path, ":") <= 1 && !StringUtils.endsWithIgnoreCase(path, ":**")) { + // All instances of the destination unless specifically requested + path = path + ":**"; + } + } + + final String finalPath = path; + return () -> finalPath; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java new file mode 100644 index 00000000..af4998d9 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshListener.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.cloud.bus.ServiceMatcher; +import org.springframework.cloud.context.refresh.ContextRefresher; +import org.springframework.context.ApplicationListener; + +/** + * @author Spencer Gibb + * @author Ryan Baxter + */ +public class RefreshListener implements ApplicationListener { + + private static Log log = LogFactory.getLog(RefreshListener.class); + + private ContextRefresher contextRefresher; + + private ServiceMatcher serviceMatcher; + + public RefreshListener(ContextRefresher contextRefresher, ServiceMatcher serviceMatcher) { + this.contextRefresher = contextRefresher; + this.serviceMatcher = serviceMatcher; + } + + @Override + public void onApplicationEvent(RefreshRemoteApplicationEvent event) { + log.info("Received remote refresh request."); + if (serviceMatcher.isForSelf(event)) { + Set keys = this.contextRefresher.refresh(); + log.info("Keys refreshed " + keys); + } + else { + log.info("Refresh not performed, the event was targeting " + event.getDestinationService()); + } + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java new file mode 100644 index 00000000..dd0fa49c --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RefreshRemoteApplicationEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +/** + * @author Spencer Gibb + */ +@SuppressWarnings("serial") +public class RefreshRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private RefreshRemoteApplicationEvent() { + // for serializers + } + + @Deprecated + public RefreshRemoteApplicationEvent(Object source, String originService, String destination) { + this(source, originService, new PathDestinationFactory().getDestination(destination)); + } + + public RefreshRemoteApplicationEvent(Object source, String originService, Destination destination) { + super(source, originService, destination); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java new file mode 100644 index 00000000..1445fe58 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/RemoteApplicationEvent.java @@ -0,0 +1,148 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import java.util.UUID; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import org.springframework.context.ApplicationEvent; +import org.springframework.core.style.ToStringCreator; +import org.springframework.util.Assert; + +/** + * @author Spencer Gibb + */ +@SuppressWarnings("serial") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonIgnoreProperties("source") +public abstract class RemoteApplicationEvent extends ApplicationEvent { + + private static final Object TRANSIENT_SOURCE = new Object(); + + private static final String TRANSIENT_ORIGIN = "____transient_origin_service___"; + + private static final String TRANSIENT_DESTINATION = "____transient_destination___"; + + protected static final PathDestinationFactory DEFAULT_DESTINATION_FACTORY = new PathDestinationFactory(); + + private final String originService; + + private final String destinationService; + + private final String id; + + protected RemoteApplicationEvent() { + // for serialization libs like jackson + this(TRANSIENT_SOURCE, TRANSIENT_ORIGIN, DEFAULT_DESTINATION_FACTORY.getDestination(TRANSIENT_DESTINATION)); + } + + @Deprecated + protected RemoteApplicationEvent(Object source, String originService, String destinationService) { + this(source, originService, DEFAULT_DESTINATION_FACTORY.getDestination(destinationService)); + } + + protected RemoteApplicationEvent(Object source, String originService, Destination destination) { + super(source); + if (!originService.equals(TRANSIENT_ORIGIN)) { + Assert.notNull(originService, "originService may not be null"); + this.originService = originService; + } + else { + this.originService = null; + } + Assert.notNull(destination, "destination may not be null"); + this.destinationService = destination.getDestinationAsString(); + Assert.hasText(destinationService, "destinationService may not be empty"); + this.id = UUID.randomUUID().toString(); + } + + @Deprecated + protected RemoteApplicationEvent(Object source, String originService) { + this(source, originService, DEFAULT_DESTINATION_FACTORY.getDestination(null)); + } + + public String getOriginService() { + return this.originService; + } + + public String getDestinationService() { + return this.destinationService; + } + + public String getId() { + return this.id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.destinationService == null) ? 0 : this.destinationService.hashCode()); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.originService == null) ? 0 : this.originService.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + RemoteApplicationEvent other = (RemoteApplicationEvent) obj; + if (this.destinationService == null) { + if (other.destinationService != null) { + return false; + } + } + else if (!this.destinationService.equals(other.destinationService)) { + return false; + } + if (this.id == null) { + if (other.id != null) { + return false; + } + } + else if (!this.id.equals(other.id)) { + return false; + } + if (this.originService == null) { + if (other.originService != null) { + return false; + } + } + else if (!this.originService.equals(other.originService)) { + return false; + } + return true; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("id", id).append("originService", originService) + .append("destinationService", destinationService).toString(); + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java new file mode 100644 index 00000000..440d8d33 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/SentApplicationEvent.java @@ -0,0 +1,148 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +import org.springframework.context.ApplicationEvent; + +/** + * An event signalling that a remote event was sent somewhere in the system. This is not + * itself a {@link RemoteApplicationEvent}, so it isn't sent over the bus, instead it is + * generated locally (possibly in response to a remote event). Applications that want to + * audit remote events can listen for this one and the {@link AckRemoteApplicationEvent} + * from all the consumers (the {@link #getId() id} of this event is the + * {@link AckRemoteApplicationEvent#getAckId() ackId} of the corresponding ACK. + * + * @author Dave Syer + */ +@SuppressWarnings("serial") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonIgnoreProperties("source") +public class SentApplicationEvent extends ApplicationEvent { + + private static final Object TRANSIENT_SOURCE = new Object(); + + private final String originService; + + private final String destinationService; + + private final String id; + + private Class type; + + protected SentApplicationEvent() { + // for serialization libs like jackson + this(TRANSIENT_SOURCE, null, null, null, RemoteApplicationEvent.class); + } + + public SentApplicationEvent(Object source, String originService, String destinationService, String id, + Class type) { + super(source); + this.originService = originService; + this.type = type; + if (destinationService == null) { + destinationService = "*"; + } + if (!destinationService.contains(":")) { + // All instances of the destination unless specifically requested + destinationService = destinationService + ":**"; + } + this.destinationService = destinationService; + this.id = id; + } + + public Class getType() { + return this.type; + } + + public void setType(Class type) { + this.type = type; + } + + public String getOriginService() { + return this.originService; + } + + public String getDestinationService() { + return this.destinationService; + } + + public String getId() { + return this.id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.destinationService == null) ? 0 : this.destinationService.hashCode()); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.originService == null) ? 0 : this.originService.hashCode()); + result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SentApplicationEvent other = (SentApplicationEvent) obj; + if (this.destinationService == null) { + if (other.destinationService != null) { + return false; + } + } + else if (!this.destinationService.equals(other.destinationService)) { + return false; + } + if (this.id == null) { + if (other.id != null) { + return false; + } + } + else if (!this.id.equals(other.id)) { + return false; + } + if (this.originService == null) { + if (other.originService != null) { + return false; + } + } + else if (!this.originService.equals(other.originService)) { + return false; + } + if (this.type == null) { + if (other.type != null) { + return false; + } + } + else if (!this.type.equals(other.type)) { + return false; + } + return true; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java new file mode 100644 index 00000000..0dfcfda9 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/TraceListener.java @@ -0,0 +1,82 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import java.util.LinkedHashMap; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository; +import org.springframework.context.event.EventListener; + +/** + * A listener for sends and acks of remote application events. Inserts a record for each + * signal in the {@link HttpExchangeRepository}. + * + * @author Dave Syer + */ +public class TraceListener { + + private static Log log = LogFactory.getLog(TraceListener.class); + + private HttpExchangeRepository repository; + + public TraceListener(HttpExchangeRepository repository) { + this.repository = repository; + } + + @EventListener + public void onAck(AckRemoteApplicationEvent event) { + Map trace = getReceivedTrace(event); + // FIXME boot 2 this.repository.add(trace); + } + + @EventListener + public void onSend(SentApplicationEvent event) { + Map trace = getSentTrace(event); + // FIXME boot 2 this.repository.add(trace); + } + + protected Map getSentTrace(SentApplicationEvent event) { + Map map = new LinkedHashMap(); + map.put("signal", "spring.cloud.bus.sent"); + map.put("type", event.getType().getSimpleName()); + map.put("id", event.getId()); + map.put("origin", event.getOriginService()); + map.put("destination", event.getDestinationService()); + if (log.isDebugEnabled()) { + log.debug(map); + } + return map; + } + + protected Map getReceivedTrace(AckRemoteApplicationEvent event) { + Map map = new LinkedHashMap(); + map.put("signal", "spring.cloud.bus.ack"); + map.put("event", event.getEvent().getSimpleName()); + map.put("id", event.getAckId()); + map.put("origin", event.getOriginService()); + map.put("destination", event.getAckDestinationService()); + if (log.isDebugEnabled()) { + log.debug(map); + } + return map; + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java new file mode 100644 index 00000000..25ab2420 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/event/UnknownRemoteApplicationEvent.java @@ -0,0 +1,68 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event; + +import org.springframework.core.style.ToStringCreator; + +/** + * @author Stefan Pfeiffer + */ +public class UnknownRemoteApplicationEvent extends RemoteApplicationEvent { + + protected String typeInfo; + + protected byte[] payload; + + @SuppressWarnings("unused") + private UnknownRemoteApplicationEvent() { + super(); + this.typeInfo = null; + this.payload = null; + } + + public UnknownRemoteApplicationEvent(Object source, String typeInfo, byte[] payload) { + // Initialize originService with an empty String, to avoid NullPointer in + // AntPathMatcher. + super(source, "", () -> "unknown"); + this.typeInfo = typeInfo; + this.payload = payload; + } + + public String getTypeInfo() { + return this.typeInfo; + } + + public byte[] getPayload() { + return this.payload; + } + + public String getPayloadAsString() { + if (this.payload != null) { + return new String(this.payload); + } + return null; + } + + @Override + public String toString() { + return new ToStringCreator(this).append("id", getId()).append("originService", getOriginService()) + .append("destinationService", getDestinationService()).append("typeInfo", typeInfo) + .append("payload", getPayloadAsString()).toString(); + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java new file mode 100644 index 00000000..c2825948 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/BusJacksonAutoConfiguration.java @@ -0,0 +1,210 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.exc.InvalidTypeIdException; +import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.cloud.bus.BusAutoConfiguration; +import org.springframework.cloud.bus.ConditionalOnBusEnabled; +import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.bus.event.UnknownRemoteApplicationEvent; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.type.filter.AssignableTypeFilter; +import org.springframework.lang.Nullable; +import org.springframework.messaging.Message; +import org.springframework.messaging.converter.AbstractMessageConverter; +import org.springframework.util.ClassUtils; +import org.springframework.util.MimeType; +import org.springframework.util.MimeTypeUtils; + +/** + * @author Spencer Gibb + * @author Dave Syer + * @author Donovan Muller + * @author Stefan Pfeiffer + */ +@Configuration(proxyBeanMethods = false) +@ConditionalOnBusEnabled +@ConditionalOnClass({ RefreshBusEndpoint.class, ObjectMapper.class }) +@AutoConfigureBefore({ BusAutoConfiguration.class, JacksonAutoConfiguration.class }) +public class BusJacksonAutoConfiguration { + + // needed in the case where @RemoteApplicationEventScan is not used + // otherwise RemoteApplicationEventRegistrar will register the bean + @Bean + @ConditionalOnMissingBean(name = "busJsonConverter") + public AbstractMessageConverter busJsonConverter(@Autowired(required = false) ObjectMapper objectMapper) { + return new BusJacksonMessageConverter(objectMapper); + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnClass(CBORFactory.class) + protected static class CborConfiguration { + + @Bean + public AbstractMessageConverter busCborConverter() { + return new BusJacksonMessageConverter(new MimeType("application", "cbor"), + new ObjectMapper(new CBORFactory())); + } + + } + +} + +class BusJacksonMessageConverter extends AbstractMessageConverter implements InitializingBean { + + private static final Log log = LogFactory.getLog(BusJacksonMessageConverter.class); + + private static final String DEFAULT_PACKAGE = ClassUtils.getPackageName(RemoteApplicationEvent.class); + + private final ObjectMapper mapper; + + private final boolean mapperCreated; + + private String[] packagesToScan = new String[] { DEFAULT_PACKAGE }; + + private BusJacksonMessageConverter() { + this(null); + } + + @Autowired(required = false) + BusJacksonMessageConverter(@Nullable ObjectMapper objectMapper) { + this(MimeTypeUtils.APPLICATION_JSON, objectMapper); + } + + @Autowired(required = false) + BusJacksonMessageConverter(MimeType mimeType, @Nullable ObjectMapper objectMapper) { + super(mimeType); + + if (objectMapper != null) { + this.mapper = objectMapper; + this.mapperCreated = false; + } + else { + this.mapper = new ObjectMapper(); + this.mapperCreated = true; + } + } + + /* for testing */ boolean isMapperCreated() { + return this.mapperCreated; + } + + /* for testing */ ObjectMapper getMapper() { + return this.mapper; + } + + public void setPackagesToScan(String[] packagesToScan) { + List packages = new ArrayList<>(Arrays.asList(packagesToScan)); + if (!packages.contains(DEFAULT_PACKAGE)) { + packages.add(DEFAULT_PACKAGE); + } + this.packagesToScan = packages.toArray(new String[0]); + } + + private Class[] findSubTypes() { + List> types = new ArrayList<>(); + if (this.packagesToScan != null) { + for (String pkg : this.packagesToScan) { + ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( + false); + provider.addIncludeFilter(new AssignableTypeFilter(RemoteApplicationEvent.class)); + + Set components = provider.findCandidateComponents(pkg); + for (BeanDefinition component : components) { + try { + types.add(Class.forName(component.getBeanClassName())); + } + catch (ClassNotFoundException e) { + throw new IllegalStateException("Failed to scan classpath for remote event classes", e); + } + } + } + } + if (log.isDebugEnabled()) { + log.debug("Found sub types: " + types); + } + return types.toArray(new Class[0]); + } + + @Override + protected boolean supports(Class aClass) { + // This converter applies only to RemoteApplicationEvent and subclasses + return RemoteApplicationEvent.class.isAssignableFrom(aClass); + } + + @Override + public Object convertFromInternal(Message message, Class targetClass, Object conversionHint) { + Object result = null; + try { + Object payload = message.getPayload(); + + if (payload instanceof byte[]) { + try { + result = this.mapper.readValue((byte[]) payload, targetClass); + } + catch (InvalidTypeIdException e) { + return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), (byte[]) payload); + } + } + else if (payload instanceof String) { + try { + result = this.mapper.readValue((String) payload, targetClass); + } + catch (InvalidTypeIdException e) { + return new UnknownRemoteApplicationEvent(new Object(), e.getTypeId(), + ((String) payload).getBytes()); + } + // workaround for + // https://github.com/spring-cloud/spring-cloud-stream/issues/1564 + } + else if (payload instanceof RemoteApplicationEvent) { + return payload; + } + } + catch (Exception e) { + this.logger.error(e.getMessage(), e); + return null; + } + return result; + } + + @Override + public void afterPropertiesSet() throws Exception { + this.mapper.registerModule(new SubtypeModule(findSubTypes())); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java new file mode 100644 index 00000000..ab1501b1 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventRegistrar.java @@ -0,0 +1,99 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.type.AnnotationMetadata; +import org.springframework.util.ClassUtils; +import org.springframework.util.StringUtils; + +/** + * @author Donovan Muller + */ +public class RemoteApplicationEventRegistrar implements ImportBeanDefinitionRegistrar { + + private static final String PACKAGES_TO_SCAN = "packagesToScan"; + + private static final String BUS_JSON_CONVERTER = "busJsonConverter"; + + // patterned after Spring Integration IntegrationComponentScanRegistrar + + @Override + public void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, + final BeanDefinitionRegistry registry) { + + Map componentScan = importingClassMetadata + .getAnnotationAttributes(RemoteApplicationEventScan.class.getName(), false); + + Set basePackages = new HashSet<>(); + for (String pkg : (String[]) componentScan.get("value")) { + if (StringUtils.hasText(pkg)) { + basePackages.add(pkg); + } + } + for (String pkg : (String[]) componentScan.get("basePackages")) { + if (StringUtils.hasText(pkg)) { + basePackages.add(pkg); + } + } + for (Class clazz : (Class[]) componentScan.get("basePackageClasses")) { + basePackages.add(ClassUtils.getPackageName(clazz)); + } + + if (basePackages.isEmpty()) { + basePackages.add(ClassUtils.getPackageName(importingClassMetadata.getClassName())); + } + + if (!registry.containsBeanDefinition(BUS_JSON_CONVERTER)) { + BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder + .genericBeanDefinition(BusJacksonMessageConverter.class); + beanDefinitionBuilder.addPropertyValue(PACKAGES_TO_SCAN, + basePackages.toArray(new String[basePackages.size()])); + AbstractBeanDefinition beanDefinition = beanDefinitionBuilder.getBeanDefinition(); + + BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, BUS_JSON_CONVERTER); + BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); + } + else { + basePackages.addAll(getEarlierPackagesToScan(registry)); + registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().addPropertyValue(PACKAGES_TO_SCAN, + basePackages.toArray(new String[basePackages.size()])); + } + } + + private Set getEarlierPackagesToScan(final BeanDefinitionRegistry registry) { + if (registry.containsBeanDefinition(BUS_JSON_CONVERTER) + && registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues().get(PACKAGES_TO_SCAN) != null) { + String[] earlierValues = (String[]) registry.getBeanDefinition(BUS_JSON_CONVERTER).getPropertyValues() + .get(PACKAGES_TO_SCAN); + return new HashSet<>(Arrays.asList(earlierValues)); + } + + return new HashSet<>(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java new file mode 100644 index 00000000..be054ede --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScan.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.context.annotation.Import; + +/** + * @author Donovan Muller + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Documented +@Import(RemoteApplicationEventRegistrar.class) +public @interface RemoteApplicationEventScan { + + String[] value() default {}; + + String[] basePackages() default {}; + + Class[] basePackageClasses() default {}; + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java new file mode 100644 index 00000000..76f9e909 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/java/org/springframework/cloud/bus/jackson/SubtypeModule.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import com.fasterxml.jackson.databind.module.SimpleModule; + +/** + * @author Spencer Gibb + */ +@SuppressWarnings("serial") +public class SubtypeModule extends SimpleModule { + + private Class[] subtypes; + + public SubtypeModule(Class... subtypes) { + this.subtypes = subtypes; + } + + @Override + public void setupModule(SetupContext context) { + context.registerSubtypes(this.subtypes); + super.setupModule(context); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..06714087 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -0,0 +1,23 @@ +{ + "properties": [ + { + "name": "spring.cloud.bus.env.enabled", + "type": "java.lang.Boolean", + "description": "Flag to switch off environment change events (default on).", + "defaultValue": true + }, + { + "name": "spring.cloud.bus.refresh.enabled", + "type": "java.lang.Boolean", + "description": "Flag to switch off refresh events (default on).", + "defaultValue": true + }, + { + "name": "spring.cloud.bus.trace.enabled", + "type": "java.lang.Boolean", + "description": "Flag to switch on tracing of acks (default off).", + "defaultValue": false + } + ] +} + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring.factories b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..665f0a37 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring.factories @@ -0,0 +1,3 @@ +# Environment Post Processor +org.springframework.boot.env.EnvironmentPostProcessor=\ +org.springframework.cloud.bus.BusEnvironmentPostProcessor diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 00000000..ac7da219 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,5 @@ +org.springframework.cloud.bus.PathServiceMatcherAutoConfiguration +org.springframework.cloud.bus.BusAutoConfiguration +org.springframework.cloud.bus.BusRefreshAutoConfiguration +org.springframework.cloud.bus.BusStreamAutoConfiguration +org.springframework.cloud.bus.jackson.BusJacksonAutoConfiguration \ No newline at end of file diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java new file mode 100644 index 00000000..74906d6e --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationClassPathTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.junit.Test; + +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.FilteredClassLoader; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.autoconfigure.RefreshAutoConfiguration; +import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint; +import org.springframework.cloud.bus.event.RefreshListener; + +import static org.assertj.core.api.Assertions.assertThat; + +public class BusAutoConfigurationClassPathTests { + + @Test + public void refreshListenerCreatedWithoutActuator() { + new ApplicationContextRunner().withClassLoader(new FilteredClassLoader("org.springframework.boot.actuate")) + .withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class, + PathServiceMatcherAutoConfiguration.class, BusRefreshAutoConfiguration.class)) + .run(context -> assertThat(context).hasSingleBean(RefreshListener.class) + .doesNotHaveBean(RefreshBusEndpoint.class)); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java new file mode 100644 index 00000000..d9cc93dc --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusAutoConfigurationTests.java @@ -0,0 +1,328 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.Test; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; +import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; +import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; +import org.springframework.cloud.bus.event.PathDestinationFactory; +import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.bus.event.SentApplicationEvent; +import org.springframework.cloud.bus.event.UnknownRemoteApplicationEvent; +import org.springframework.cloud.context.refresh.ContextRefresher; +import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; +import org.springframework.cloud.stream.config.BindingProperties; +import org.springframework.cloud.stream.config.BindingServiceProperties; +import org.springframework.cloud.stream.function.StreamBridge; +import org.springframework.context.ApplicationListener; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.GenericMessage; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class BusAutoConfigurationTests { + + private ConfigurableApplicationContext context; + + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void defaultId() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--server.port=0"); + assertThat(this.context.getBean(BusProperties.class).getId().startsWith("application:0:")) + .as("Wrong ID: " + this.context.getBean(BusProperties.class).getId()).isTrue(); + } + + @Test + public void inboundNotForSelf() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "bar", "bar"))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull(); + } + + @Test + public void inboundFromSelf() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=foo", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNull(); + } + + @Test + public void inboundNotFromSelf() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull(); + } + + @Test + public void inboundNotFromSelfWithAck() throws Exception { + this.context = SpringApplication.run( + new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class, + SentMessageConfiguration.class }, + new String[] { "--spring.cloud.bus.id=bar", "--server.port=0", + "--spring.main.allow-bean-definition-overriding=true" }); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", (String) null))); + RefreshRemoteApplicationEvent refresh = this.context.getBean(InboundMessageHandlerConfiguration.class).refresh; + assertThat(refresh).isNotNull(); + TestStreamBusBridge busBridge = this.context.getBean(TestStreamBusBridge.class); + busBridge.latch.await(200, TimeUnit.SECONDS); + assertThat(busBridge.message).isInstanceOf(AckRemoteApplicationEvent.class); + AckRemoteApplicationEvent message = (AckRemoteApplicationEvent) busBridge.message; + assertThat(message.getAckId()).as("Wrong ackId: %s", message).isEqualTo(refresh.getId()); + } + + @Test + public void inboundNotFromSelfWithTrace() { + this.context = SpringApplication.run( + new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class, + SentMessageConfiguration.class }, + new String[] { "--spring.cloud.bus.trace.enabled=true", "--spring.cloud.bus.id=bar", + "--server.port=0" }); + this.context.getBean(BusConsumer.class).accept(new RefreshRemoteApplicationEvent(this, "foo", (String) null)); + RefreshRemoteApplicationEvent refresh = this.context.getBean(InboundMessageHandlerConfiguration.class).refresh; + assertThat(refresh).isNotNull(); + SentMessageConfiguration sent = this.context.getBean(SentMessageConfiguration.class); + assertThat(sent.event).isNotNull(); + assertThat(sent.count).isEqualTo(1); + } + + @Test + public void inboundAckWithTrace() throws InterruptedException { + this.context = SpringApplication.run( + new Class[] { InboundMessageHandlerConfiguration.class, OutboundMessageHandlerConfiguration.class, + AckMessageConfiguration.class }, + new String[] { "--spring.cloud.bus.trace.enabled=true", "--spring.cloud.bus.id=bar", + "--server.port=0" }); + this.context.getBean(BusConsumer.class).accept(new AckRemoteApplicationEvent(this, "foo", + new PathDestinationFactory().getDestination(null), "ID", "bar", RefreshRemoteApplicationEvent.class)); + AckMessageConfiguration ack = this.context.getBean(AckMessageConfiguration.class); + assertThat(ack.latch.await(5, TimeUnit.SECONDS)).isTrue(); + assertThat(ack.event).isNotNull(); + assertThat(ack.count).isEqualTo(1); + } + + @Test + public void outboundFromSelf() throws Exception { + this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class, "--debug=true", + "--spring.cloud.bus.id=foo", "--server.port=0"); + this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", (String) null)); + TestStreamBusBridge busBridge = this.context.getBean(TestStreamBusBridge.class); + busBridge.latch.await(2, TimeUnit.SECONDS); + assertThat(busBridge.message).as("message was null").isNotNull(); + } + + @Test + public void outboundNotFromSelf() { + this.context = SpringApplication.run(OutboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar", + "--server.port=0"); + this.context.publishEvent(new RefreshRemoteApplicationEvent(this, "foo", (String) null)); + assertThat(this.context.getBean(TestStreamBusBridge.class).message).isNull(); + } + + @Test + public void inboundNotFromSelfPathPattern() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar:1000", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:*"))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull(); + } + + @Test + public void inboundNotFromSelfDeepPathPattern() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, + "--spring.cloud.bus.id=bar:test:1000", "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar:**"))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull(); + } + + @Test + public void inboundNotFromSelfFlatPattern() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new RefreshRemoteApplicationEvent(this, "foo", "bar*"))); + assertThat(this.context.getBean(InboundMessageHandlerConfiguration.class).refresh).isNotNull(); + } + + // see https://github.com/spring-cloud/spring-cloud-bus/issues/74 + @Test + public void inboundNotFromSelfUnknown() { + this.context = SpringApplication.run(InboundMessageHandlerConfiguration.class, "--spring.cloud.bus.id=bar", + "--server.port=0"); + this.context.getBean(BusConstants.INPUT, MessageChannel.class) + .send(new GenericMessage<>(new UnknownRemoteApplicationEvent(this, "UnknownEvent", "yada".getBytes()))); + // No Exception expected + } + + @Test + public void initDoesNotOverrideCustomDestination() { + HashMap properties = new HashMap<>(); + BindingProperties input = new BindingProperties(); + input.setDestination("mydestination"); + properties.put(BusConstants.INPUT, input); + BindingProperties output = new BindingProperties(); + output.setDestination("mydestination"); + properties.put(BusConstants.OUTPUT, output); + + setupBusAutoConfig(properties); + + BindingProperties inputProps = properties.get(BusConstants.INPUT); + assertThat(inputProps.getDestination()).isEqualTo("mydestination"); + + BindingProperties outputProps = properties.get(BusConstants.OUTPUT); + assertThat(outputProps.getDestination()).isEqualTo("mydestination"); + } + + private BusProperties setupBusAutoConfig(HashMap properties) { + BindingServiceProperties serviceProperties = mock(BindingServiceProperties.class); + when(serviceProperties.getBindings()).thenReturn(properties); + + BusProperties bus = new BusProperties(); + BusAutoConfiguration configuration = new BusAutoConfiguration(); + return bus; + } + + // see https://github.com/spring-cloud/spring-cloud-bus/issues/101 + @Test + public void serviceMatcherIdIsConstantAfterRefresh() { + this.context = SpringApplication.run(new Class[] { RefreshConfig.class, TestChannelBinderConfiguration.class }, + new String[] { "--server.port=0", "--spring.main.allow-bean-definition-overriding=true" }); + String originalServiceId = this.context.getBean(ServiceMatcher.class).getBusId(); + this.context.getBean(ContextRefresher.class).refresh(); + String newServiceId = this.context.getBean(ServiceMatcher.class).getBusId(); + assertThat(newServiceId).isEqualTo(originalServiceId); + } + + @Configuration(proxyBeanMethods = false) + @EnableAutoConfiguration + protected static class RefreshConfig { + + } + + @Configuration(proxyBeanMethods = false) + @EnableAutoConfiguration + @ImportAutoConfiguration({ BusAutoConfiguration.class, TestChannelBinderConfiguration.class, + PropertyPlaceholderAutoConfiguration.class }) + protected static class OutboundMessageHandlerConfiguration { + + @Bean + @Primary + StreamBusBridge testStreamBusBridge(StreamBridge streamBridge, BusProperties properties) { + return new TestStreamBusBridge(streamBridge, properties); + } + + } + + protected static class TestStreamBusBridge extends StreamBusBridge { + + private CountDownLatch latch = new CountDownLatch(1); + + private RemoteApplicationEvent message; + + public TestStreamBusBridge(StreamBridge streamBridge, BusProperties properties) { + super(streamBridge, properties); + } + + @Override + public void send(RemoteApplicationEvent event) { + latch.countDown(); + message = event; + super.send(event); + } + + } + + @Configuration(proxyBeanMethods = false) + @EnableAutoConfiguration + @ImportAutoConfiguration({ BusAutoConfiguration.class, TestChannelBinderConfiguration.class, + PropertyPlaceholderAutoConfiguration.class }) + protected static class InboundMessageHandlerConfiguration + implements ApplicationListener { + + private RefreshRemoteApplicationEvent refresh; + + @Override + public void onApplicationEvent(RefreshRemoteApplicationEvent event) { + this.refresh = event; + } + + } + + @Configuration(proxyBeanMethods = false) + protected static class SentMessageConfiguration implements ApplicationListener { + + private SentApplicationEvent event; + + private int count; + + @Override + public void onApplicationEvent(SentApplicationEvent event) { + this.event = event; + this.count++; + } + + } + + @Configuration(proxyBeanMethods = false) + protected static class AckMessageConfiguration implements ApplicationListener { + + private CountDownLatch latch = new CountDownLatch(1); + + private AckRemoteApplicationEvent event; + + private int count; + + @Override + public void onApplicationEvent(AckRemoteApplicationEvent event) { + this.event = event; + this.count++; + latch.countDown(); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusEnvironmentPostProcessorTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusEnvironmentPostProcessorTests.java new file mode 100644 index 00000000..1ae9343b --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/BusEnvironmentPostProcessorTests.java @@ -0,0 +1,82 @@ +/* + * Copyright 2015-2022 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.function.context.FunctionProperties; +import org.springframework.mock.env.MockEnvironment; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.springframework.cloud.bus.BusConstants.BUS_CONSUMER; +import static org.springframework.cloud.bus.BusConstants.DESTINATION; +import static org.springframework.cloud.bus.BusConstants.INPUT; +import static org.springframework.cloud.bus.BusConstants.OUTPUT; +import static org.springframework.cloud.bus.BusEnvironmentPostProcessor.DEFAULTS_PROPERTY_SOURCE_NAME; +import static org.springframework.cloud.bus.BusEnvironmentPostProcessor.OVERRIDES_PROPERTY_SOURCE_NAME; + +public class BusEnvironmentPostProcessorTests { + + @Test + void testDefaults() { + MockEnvironment env = new MockEnvironment().withProperty("cachedrandom.application.value", "123"); + new BusEnvironmentPostProcessor().postProcessEnvironment(env, mock(SpringApplication.class)); + assertThat(env.getProperty(FunctionProperties.PREFIX + ".definition")).isEqualTo(BUS_CONSUMER); + assertThat(env.getProperty("spring.cloud.stream.function.bindings." + BUS_CONSUMER + "-in-0")).isEqualTo(INPUT); + assertThat(env.getProperty("spring.cloud.stream.bindings." + INPUT + ".destination")).isEqualTo(DESTINATION); + assertThat(env.getProperty("spring.cloud.stream.bindings." + OUTPUT + ".destination")).isEqualTo(DESTINATION); + assertThat(env.getProperty(BusProperties.PREFIX + ".id")).isEqualTo("application:8080:123"); + assertThat(env.getPropertySources().contains(OVERRIDES_PROPERTY_SOURCE_NAME)); + assertThat(env.getPropertySources().contains(DEFAULTS_PROPERTY_SOURCE_NAME)); + } + + @Test + void testWithActiveProfile() { + MockEnvironment env = new MockEnvironment().withProperty("cachedrandom.application.value", "123") + .withProperty("spring.profiles.active", "dev"); + new BusEnvironmentPostProcessor().postProcessEnvironment(env, mock(SpringApplication.class)); + assertThat(env.getProperty(FunctionProperties.PREFIX + ".definition")).isEqualTo(BUS_CONSUMER); + assertThat(env.getProperty("spring.cloud.stream.function.bindings." + BUS_CONSUMER + "-in-0")).isEqualTo(INPUT); + assertThat(env.getProperty("spring.cloud.stream.bindings." + INPUT + ".destination")).isEqualTo(DESTINATION); + assertThat(env.getProperty("spring.cloud.stream.bindings." + OUTPUT + ".destination")).isEqualTo(DESTINATION); + assertThat(env.getProperty(BusProperties.PREFIX + ".id")).isEqualTo("application:dev:8080:123"); + assertThat(env.getPropertySources().contains(OVERRIDES_PROPERTY_SOURCE_NAME)); + assertThat(env.getPropertySources().contains(DEFAULTS_PROPERTY_SOURCE_NAME)); + } + + @Test + void testOverrides() { + String fnDefKey = FunctionProperties.PREFIX + ".definition"; + String idKey = BusProperties.PREFIX + ".id"; + MockEnvironment env = new MockEnvironment().withProperty("cachedrandom.application.value", "123") + .withProperty(BusProperties.PREFIX + ".destination", "mydestination").withProperty(idKey, "app:1") + .withProperty(fnDefKey, "uppercase"); + new BusEnvironmentPostProcessor().postProcessEnvironment(env, mock(SpringApplication.class)); + assertThat(env.getProperty(fnDefKey)).isEqualTo("uppercase;" + BUS_CONSUMER); + assertThat(env.getProperty("spring.cloud.stream.function.bindings." + BUS_CONSUMER + "-in-0")).isEqualTo(INPUT); + assertThat(env.getProperty("spring.cloud.stream.bindings." + INPUT + ".destination")) + .isEqualTo("mydestination"); + assertThat(env.getProperty("spring.cloud.stream.bindings." + OUTPUT + ".destination")) + .isEqualTo("mydestination"); + assertThat(env.getProperty(idKey)).isEqualTo("app:1"); + assertThat(env.getPropertySources().contains(OVERRIDES_PROPERTY_SOURCE_NAME)); + assertThat(env.getPropertySources().contains(DEFAULTS_PROPERTY_SOURCE_NAME)); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java new file mode 100644 index 00000000..2a119c3c --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/ConditionalOnBusEnabledTests.java @@ -0,0 +1,85 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Spencer Gibb + */ +public class ConditionalOnBusEnabledTests { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private AnnotationConfigApplicationContext context; + + @After + public void tearDown() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void busEnabledTrue() { + load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":true"); + assertThat(this.context.containsBean("foo")).as("missing bean from @ConditionalOnBusEnabled config").isTrue(); + } + + @Test + public void busEnabledMissing() { + load(MyBusEnabledConfig.class); + assertThat(this.context.containsBean("foo")).as("missing bean from @ConditionalOnBusEnabled config").isTrue(); + } + + @Test + public void busDisabled() { + load(MyBusEnabledConfig.class, ConditionalOnBusEnabled.SPRING_CLOUD_BUS_ENABLED + ":false"); + assertThat(this.context.containsBean("foo")).as("bean exists from disabled @ConditionalOnBusEnabled config") + .isFalse(); + } + + private void load(Class config, String... environment) { + this.context = new AnnotationConfigApplicationContext(); + TestPropertyValues.of(environment).applyTo(this.context); + this.context.register(config); + this.context.refresh(); + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnBusEnabled + protected static class MyBusEnabledConfig { + + @Bean + public String foo() { + return "foo"; + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherTests.java new file mode 100644 index 00000000..30139108 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherTests.java @@ -0,0 +1,173 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.Collections; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.util.AntPathMatcher; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Dave Syer + * + */ +public class PathServiceMatcherTests { + + private static final Map EMPTY_MAP = Collections.emptyMap(); + + private ServiceMatcher matcher; + + @Before + public void init() { + initMatcher("one:two:8888"); + } + + private void initMatcher(String id) { + BusProperties properties = new BusProperties(); + properties.setId(id); + DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":")); + this.matcher = new PathServiceMatcher(pathMatcher, properties.getId()); + } + + @Test + public void fromSelf() { + assertThat(this.matcher.isFromSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "one:two:8888", "foo:bar:spam", EMPTY_MAP))).isTrue(); + } + + @Test + public void forSelf() { + assertThat(this.matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:8888", EMPTY_MAP))).isTrue(); + } + + @Test + public void forSelfWithWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithGlobalWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardName() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardNameAndProfile() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardString() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void notForSelfWithWildCardNameAndMismatchingProfile() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP))) + .isFalse(); + } + + @Test + public void forSelfWithDoubleWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithNoWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithProfileNoWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void notForSelf() { + assertThat(this.matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))) + .isFalse(); + } + + @Test + public void notFromSelf() { + assertThat(this.matcher.isFromSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "one:two:9999", "foo:bar:spam", EMPTY_MAP))) + .isFalse(); + } + + /** + * see gh-678 + */ + @Test + public void forSelfWithMultipleProfiles() { + initMatcher("customerportal:dev,cloud:80"); + assertThat(this.matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "customerportal:cloud:*", EMPTY_MAP))) + .isTrue(); + } + + /** + * see gh-678 + */ + @Test + public void notForSelfWithMultipleProfiles() { + initMatcher("customerportal:dev,cloud:80"); + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))) + .isFalse(); + } + + /** + * see gh-678 + */ + @Test + public void notForSelfWithMultipleProfilesDifferentPort() { + initMatcher("customerportal:dev,cloud:80"); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "customerportal:cloud:8008", EMPTY_MAP))).isFalse(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherWithConfigNamesTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherWithConfigNamesTests.java new file mode 100644 index 00000000..867658e3 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/PathServiceMatcherWithConfigNamesTests.java @@ -0,0 +1,152 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.Collections; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; + +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.util.AntPathMatcher; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Stefan Pfeiffer + * + */ +public class PathServiceMatcherWithConfigNamesTests { + + private static final Map EMPTY_MAP = Collections.emptyMap(); + + private ServiceMatcher matcher; + + @Before + public void init() { + initMatcher("otherid:two:8888", new String[] { "one", "three" }); + } + + private void initMatcher(String id, String[] configNames) { + BusProperties properties = new BusProperties(); + properties.setId(id); + DefaultBusPathMatcher pathMatcher = new DefaultBusPathMatcher(new AntPathMatcher(":")); + this.matcher = new PathServiceMatcher(pathMatcher, properties.getId(), configNames); + } + + @Test + public void forSelfWithWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardAndOtherConfigName() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "three:two:*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithGlobalWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "**", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardName() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardNameAndProfile() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:t*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithWildcardString() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void notForSelfWithWildCardNameAndMismatchingProfile() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "o*:f*", EMPTY_MAP))) + .isFalse(); + } + + @Test + public void forSelfWithDoubleWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:**", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithNoWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void forSelfWithProfileNoWildcard() { + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void notForSelf() { + assertThat(this.matcher.isForSelf( + new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:two:9999", EMPTY_MAP))) + .isFalse(); + } + + @Test + public void forSelfWithMultipleProfiles() { + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "one:cloud:*", EMPTY_MAP))) + .isTrue(); + } + + @Test + public void notForSelfWithMultipleProfiles() { + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); + assertThat(this.matcher + .isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", "bar:cloud:*", EMPTY_MAP))) + .isFalse(); + } + + @Test + public void notForSelfWithMultipleProfilesDifferentPort() { + initMatcher("customerportal:dev,cloud:80", new String[] { "one", "three" }); + assertThat(this.matcher.isForSelf(new EnvironmentChangeRemoteApplicationEvent(this, "foo:bar:spam", + "customerportal:cloud:8008", EMPTY_MAP))).isFalse(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/RefreshListenerIntegrationTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/RefreshListenerIntegrationTests.java new file mode 100644 index 00000000..f5e9f4b0 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/RefreshListenerIntegrationTests.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus; + +import java.util.HashMap; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; +import org.springframework.context.annotation.Import; +import org.springframework.http.HttpStatus; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +/** + * @author Ryan Baxter + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, + classes = RefreshListenerIntegrationTests.MyApp.class, + properties = { "management.endpoints.web.exposure.include=*", "spring.application.name=foobar" }) +public class RefreshListenerIntegrationTests { + + @Autowired + private TestRestTemplate rest; + + @MockBean + private BusBridge busBridge; + + @Test + public void testEndpoint() { + System.out.println(rest.getForObject("/actuator", String.class)); + assertThat(rest.postForEntity("/actuator/busrefresh/demoapp", new HashMap<>(), String.class).getStatusCode()) + .isEqualTo(HttpStatus.NO_CONTENT); + assertThat(rest.postForEntity("/actuator/busrefresh/foobar", new HashMap<>(), String.class).getStatusCode()) + .isEqualTo(HttpStatus.NO_CONTENT); + verify(busBridge, times(2)).send(any()); + } + + @SpringBootApplication + @Import(TestChannelBinderConfiguration.class) + static class MyApp { + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java new file mode 100644 index 00000000..4284e8fa --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/endpoint/RefreshBusEndpointTests.java @@ -0,0 +1,35 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.endpoint; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Dave Syer + */ +public class RefreshBusEndpointTests { + + @Test + public void instanceId() throws Exception { + RefreshBusEndpoint endpoint = new RefreshBusEndpoint(null, "foo", + originalDestination -> () -> originalDestination); + assertThat(endpoint.getInstanceId()).isEqualTo("foo"); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java new file mode 100644 index 00000000..e3ab60c2 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TestRemoteApplicationEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event.test; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +@SuppressWarnings("serial") +public class TestRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private TestRemoteApplicationEvent() { + } + + protected TestRemoteApplicationEvent(Object source, String originService, String destinationService) { + super(source, originService, destinationService); + } + + protected TestRemoteApplicationEvent(Object source, String originService) { + super(source, originService); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java new file mode 100644 index 00000000..63d72e32 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/event/test/TypedRemoteApplicationEvent.java @@ -0,0 +1,39 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.event.test; + +import com.fasterxml.jackson.annotation.JsonTypeName; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +@SuppressWarnings("serial") +@JsonTypeName("typed") +public class TypedRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private TypedRemoteApplicationEvent() { + } + + protected TypedRemoteApplicationEvent(Object source, String originService, String destinationService) { + super(source, originService, destinationService); + } + + protected TypedRemoteApplicationEvent(Object source, String originService) { + super(source, originService); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java new file mode 100644 index 00000000..8aa68920 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/RemoteApplicationEventScanTests.java @@ -0,0 +1,156 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsontype.NamedType; +import org.junit.Test; +import test.foo.bar.FooBarTestRemoteApplicationEvent; + +import org.springframework.boot.Banner; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; +import org.springframework.cloud.bus.event.UnknownRemoteApplicationEvent; +import org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent; +import org.springframework.cloud.bus.event.test.TypedRemoteApplicationEvent; +import org.springframework.cloud.bus.jackson.SubtypeModuleTests.AnotherRemoteApplicationEvent; +import org.springframework.cloud.bus.jackson.SubtypeModuleTests.MyRemoteApplicationEvent; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.test.util.ReflectionTestUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +public class RemoteApplicationEventScanTests { + + private BusJacksonMessageConverter converter; + + @Test + public void importingClassMetadataPackageRegistered() { + this.converter = createTestContext(DefaultConfig.class).getBean(BusJacksonMessageConverter.class); + + assertConverterBeanAfterPropertiesSet( + new String[] { "org.springframework.cloud.bus.jackson", "org.springframework.cloud.bus.event" }, + AnotherRemoteApplicationEvent.class, MyRemoteApplicationEvent.class, TestRemoteApplicationEvent.class, + TypedRemoteApplicationEvent.class); + } + + @Test + public void annotationValuePackagesRegistered() { + this.converter = createTestContext(ValueConfig.class).getBean(BusJacksonMessageConverter.class); + + assertConverterBeanAfterPropertiesSet( + new String[] { "test.foo.bar", "com.acme", "org.springframework.cloud.bus.event" }, + FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class, + TypedRemoteApplicationEvent.class); + } + + @Test + public void annotationValueBasePackagesRegistered() { + this.converter = createTestContext(BasePackagesConfig.class).getBean(BusJacksonMessageConverter.class); + + assertConverterBeanAfterPropertiesSet( + new String[] { "test.foo.bar", "fizz.buzz", "com.acme", "org.springframework.cloud.bus.event" }, + FooBarTestRemoteApplicationEvent.class, TestRemoteApplicationEvent.class, + TypedRemoteApplicationEvent.class); + } + + @Test + public void annotationBasePackagesRegistered() { + this.converter = createTestContext(BasePackageClassesConfig.class).getBean(BusJacksonMessageConverter.class); + + assertConverterBeanAfterPropertiesSet( + new String[] { "org.springframework.cloud.bus.event.test", "org.springframework.cloud.bus.event" }, + TestRemoteApplicationEvent.class, TypedRemoteApplicationEvent.class); + } + + private ConfigurableApplicationContext createTestContext(Class configuration) { + return new SpringApplicationBuilder(configuration).web(WebApplicationType.NONE).bannerMode(Banner.Mode.OFF) + .run(); + } + + private void assertConverterBeanAfterPropertiesSet(final String[] expectedPackageToScan, + final Class... expectedRegisterdClasses) { + final ObjectMapper mapper = (ObjectMapper) ReflectionTestUtils.getField(this.converter, "mapper"); + + @SuppressWarnings("unchecked") + final LinkedHashSet registeredSubtypes = (LinkedHashSet) ReflectionTestUtils + .getField(mapper.getSubtypeResolver(), "_registeredSubtypes"); + + final List> expectedRegisterdClassesAsList = new ArrayList<>(Arrays.asList(expectedRegisterdClasses)); + addStandardSpringCloudEventBusEvents(expectedRegisterdClassesAsList); + + assertThat(expectedRegisterdClassesAsList.size() == registeredSubtypes.size()) + .as("Wrong RemoteApplicationEvent classes are registerd in object mapper").isTrue(); + + for (final NamedType namedType : registeredSubtypes) { + assertThat(expectedRegisterdClassesAsList.contains(namedType.getType())).isTrue(); + } + + assertThat(Arrays.asList((String[]) ReflectionTestUtils.getField(this.converter, "packagesToScan"))) + .as("RemoteApplicationEvent packages not registered").contains(expectedPackageToScan); + + } + + private void addStandardSpringCloudEventBusEvents(final List> expectedRegisterdClassesAsList) { + expectedRegisterdClassesAsList.add(AckRemoteApplicationEvent.class); + expectedRegisterdClassesAsList.add(EnvironmentChangeRemoteApplicationEvent.class); + expectedRegisterdClassesAsList.add(RefreshRemoteApplicationEvent.class); + expectedRegisterdClassesAsList.add(UnknownRemoteApplicationEvent.class); + } + + @Configuration(proxyBeanMethods = false) + @RemoteApplicationEventScan + static class DefaultConfig { + + } + + @Configuration(proxyBeanMethods = false) + @RemoteApplicationEventScan({ "com.acme", "test.foo.bar" }) + static class ValueConfig { + + } + + @Configuration(proxyBeanMethods = false) + @Import(ExtraBasePackagesConfig.class) + @RemoteApplicationEventScan(basePackages = { "com.acme", "test.foo.bar" }) + static class BasePackagesConfig { + + } + + @Configuration(proxyBeanMethods = false) + @RemoteApplicationEventScan(basePackages = { "fizz.buzz" }) + static class ExtraBasePackagesConfig { + + } + + @Configuration(proxyBeanMethods = false) + @RemoteApplicationEventScan(basePackageClasses = TestRemoteApplicationEvent.class) + static class BasePackageClassesConfig { + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java new file mode 100644 index 00000000..d1b55c05 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SerializationTests.java @@ -0,0 +1,65 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import java.util.Collections; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; + +import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Dave Syer + * + */ +public class SerializationTests { + + ObjectMapper mapper = new ObjectMapper(); + + @Test + public void vanillaDeserialize() throws Exception { + this.mapper.registerModule( + new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class)); + EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(this, "foo", "bar", + Collections.emptyMap()); + String value = this.mapper.writeValueAsString(source); + RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); + assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); + assertThat(event.getId()).isNotNull(); + assertThat(event.getId().equals(source.getId())).isTrue(); + } + + @Test + public void deserializeOldValueWithNoId() throws Exception { + this.mapper.registerModule( + new SubtypeModule(RefreshRemoteApplicationEvent.class, EnvironmentChangeRemoteApplicationEvent.class)); + EnvironmentChangeRemoteApplicationEvent source = new EnvironmentChangeRemoteApplicationEvent(this, "foo", "bar", + Collections.emptyMap()); + String value = this.mapper.writeValueAsString(source); + value = value.replaceAll(",\"id\":\"[a-f0-9-]*\"", ""); + RemoteApplicationEvent event = this.mapper.readValue(value, RemoteApplicationEvent.class); + assertThat(event instanceof EnvironmentChangeRemoteApplicationEvent).isTrue(); + assertThat(event.getId()).isNotNull(); + assertThat(event.getId().equals(source.getId())).isFalse(); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java new file mode 100644 index 00000000..cd1f670e --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/org/springframework/cloud/bus/jackson/SubtypeModuleTests.java @@ -0,0 +1,179 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.bus.jackson; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import org.junit.Test; + +import org.springframework.cloud.bus.event.AckRemoteApplicationEvent; +import org.springframework.cloud.bus.event.RemoteApplicationEvent; +import org.springframework.cloud.bus.event.UnknownRemoteApplicationEvent; +import org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent; +import org.springframework.cloud.bus.event.test.TypedRemoteApplicationEvent; +import org.springframework.messaging.support.MessageBuilder; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Spencer Gibb + * @author Stefan Pfeiffer + */ +public class SubtypeModuleTests { + + @Test + public void testDeserializeSubclass() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new SubtypeModule(MyRemoteApplicationEvent.class)); + + RemoteApplicationEvent event = mapper.readValue( + "{\"type\":\"my\", \"destinationService\":\"myservice\", \"originService\":\"myorigin\"}", + RemoteApplicationEvent.class); + assertThat(event instanceof MyRemoteApplicationEvent).as("event is wrong type").isTrue(); + MyRemoteApplicationEvent myEvent = MyRemoteApplicationEvent.class.cast(event); + assertThat(myEvent.getOriginService()).as("originService was wrong").isEqualTo("myorigin"); + assertThat(myEvent.getDestinationService()).as("destinationService was wrong").isEqualTo("myservice"); + } + + @Test + public void testDeserializeWhenTypeIsKnown() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + + RemoteApplicationEvent event = mapper.readValue("{\"type\":\"another\"}", AnotherRemoteApplicationEvent.class); + assertThat(event instanceof AnotherRemoteApplicationEvent).as("event is wrong type").isTrue(); + } + + @Test + public void testDeserializeCustomizedObjectMapper() throws Exception { + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); + + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(mapper); + converter.afterPropertiesSet(); + Object event = converter.fromMessage(MessageBuilder + .withPayload("{\"type\":\"TestRemoteApplicationEvent\", \"origin_service\":\"myorigin\"}").build(), + RemoteApplicationEvent.class); + assertThat(event).isNotNull().isInstanceOf(TestRemoteApplicationEvent.class); + assertThat(TestRemoteApplicationEvent.class.cast(event).getOriginService()).isEqualTo("myorigin"); + } + + @Test + public void testDeserializeWithMessageConverter() throws Exception { + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); + converter.afterPropertiesSet(); + Object event = converter.fromMessage( + MessageBuilder.withPayload("{\"type\":\"TestRemoteApplicationEvent\"}").build(), + RemoteApplicationEvent.class); + assertThat(event instanceof TestRemoteApplicationEvent).as("event is wrong type").isTrue(); + } + + @Test + public void testDeserializeUnknownTypeWithMessageConverter() throws Exception { + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); + converter.afterPropertiesSet(); + Object event = converter.fromMessage( + MessageBuilder.withPayload("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}").build(), + RemoteApplicationEvent.class); + assertThat(event instanceof UnknownRemoteApplicationEvent).as("event is wrong type").isTrue(); + assertThat(((UnknownRemoteApplicationEvent) event).getTypeInfo()).as("type information is wrong") + .isEqualTo("NotDefinedTestRemoteApplicationEvent"); + assertThat(((UnknownRemoteApplicationEvent) event).getPayloadAsString()).as("payload is wrong") + .isEqualTo("{\"type\":\"NotDefinedTestRemoteApplicationEvent\"}"); + } + + @Test + public void testDeserializeJsonTypeWithMessageConverter() throws Exception { + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); + converter.afterPropertiesSet(); + Object event = converter.fromMessage(MessageBuilder.withPayload("{\"type\":\"typed\"}").build(), + RemoteApplicationEvent.class); + assertThat(event instanceof TypedRemoteApplicationEvent).as("event is wrong type").isTrue(); + } + + /** + * see https://github.com/spring-cloud/spring-cloud-bus/issues/74 + */ + @Test + public void testDeserializeAckRemoteApplicationEventWithKnownType() throws Exception { + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); + converter.afterPropertiesSet(); + Object event = converter + .fromMessage(MessageBuilder + .withPayload("{\"type\":\"AckRemoteApplicationEvent\", " + + "\"event\":\"org.springframework.cloud.bus.event.test.TestRemoteApplicationEvent\"}") + .build(), RemoteApplicationEvent.class); + assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue(); + AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); + assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") + .isEqualTo(TestRemoteApplicationEvent.class); + } + + /** + * see https://github.com/spring-cloud/spring-cloud-bus/issues/74 + */ + @Test + public void testDeserializeAckRemoteApplicationEventWithUnknownType() throws Exception { + BusJacksonMessageConverter converter = new BusJacksonMessageConverter(null); + converter.afterPropertiesSet(); + Object event = converter.fromMessage(MessageBuilder + .withPayload( + "{\"type\":\"AckRemoteApplicationEvent\", \"event\":\"foo.bar.TestRemoteApplicationEvent\"}") + .build(), RemoteApplicationEvent.class); + assertThat(event instanceof AckRemoteApplicationEvent).as("event is no ack").isTrue(); + AckRemoteApplicationEvent ackEvent = AckRemoteApplicationEvent.class.cast(event); + assertThat(ackEvent.getEvent()).as("inner ack event has wrong type") + .isEqualTo(UnknownRemoteApplicationEvent.class); + } + + @SuppressWarnings("serial") + @JsonTypeName("my") + public static class MyRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private MyRemoteApplicationEvent() { + } + + protected MyRemoteApplicationEvent(Object source, String originService, String destinationService) { + super(source, originService, destinationService); + } + + protected MyRemoteApplicationEvent(Object source, String originService) { + super(source, originService); + } + + } + + @SuppressWarnings("serial") + @JsonTypeName("another") + public static class AnotherRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private AnotherRemoteApplicationEvent() { + } + + protected AnotherRemoteApplicationEvent(Object source, String originService, String destinationService) { + super(source, originService, destinationService); + } + + protected AnotherRemoteApplicationEvent(Object source, String originService) { + super(source, originService); + } + + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java new file mode 100644 index 00000000..1e6cdf67 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/java/test/foo/bar/FooBarTestRemoteApplicationEvent.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.foo.bar; + +import org.springframework.cloud.bus.event.RemoteApplicationEvent; + +@SuppressWarnings("serial") +public class FooBarTestRemoteApplicationEvent extends RemoteApplicationEvent { + + @SuppressWarnings("unused") + private FooBarTestRemoteApplicationEvent() { + } + + protected FooBarTestRemoteApplicationEvent(final Object source, final String originService, + final String destinationService) { + super(source, originService, destinationService); + } + + protected FooBarTestRemoteApplicationEvent(final Object source, final String originService) { + super(source, originService); + } + +} diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/resources/application.properties b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/resources/application.properties new file mode 100644 index 00000000..c1902d29 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-bus/src/test/resources/application.properties @@ -0,0 +1 @@ +spring.main.web-environment:false diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-amqp/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-amqp/pom.xml new file mode 100644 index 00000000..0c5250a5 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-amqp/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + spring-cloud-starter-bus-amqp + spring-cloud-starter-bus-amqp + Spring Cloud Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.cloud + spring-cloud-starter-stream-rabbit + + + org.springframework.cloud + spring-cloud-bus + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-kafka/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-kafka/pom.xml new file mode 100644 index 00000000..bec06e47 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-kafka/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + spring-cloud-starter-bus-kafka + spring-cloud-starter-bus-kafka + Spring Cloud Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.cloud + spring-cloud-starter-stream-kafka + + + org.springframework.cloud + spring-cloud-bus + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-stream/pom.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-stream/pom.xml new file mode 100644 index 00000000..dc303bce --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/spring-cloud-starter-bus-stream/pom.xml @@ -0,0 +1,33 @@ + + + 4.0.0 + + org.springframework.cloud + spring-cloud-bus-parent + 4.1.2-SNAPSHOT + .. + + spring-cloud-starter-bus-stream + spring-cloud-starter-bus-stream + Spring Cloud Starter + https://projects.spring.io/spring-cloud + + Pivotal Software, Inc. + https://www.spring.io + + + ${basedir}/../.. + + + + org.springframework.cloud + spring-cloud-stream + + + org.springframework.cloud + spring-cloud-bus + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/src/checkstyle/checkstyle-suppressions.xml b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/src/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 00000000..9f9f71a8 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-bus/src/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,7 @@ + + + + + diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/FETCH_HEAD b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/FETCH_HEAD index 18b9353c..3dc64d07 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/FETCH_HEAD +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/FETCH_HEAD @@ -1,4 +1,4 @@ -3c340cb0fda1406905eb91a26b6ad37f3a228e65 branch 'main' of github.com:spring-cloud/spring-cloud-release +6180ef291f6ec01d97a3e3ad0f71648e08d9821e branch 'main' of github.com:spring-cloud/spring-cloud-release fb730db9b3999e45c350015c6cf83be35910a159 not-for-merge branch '1.0.0.M2' of github.com:spring-cloud/spring-cloud-release 474b03693496665434ab2615d6500bbb0b575a5b not-for-merge branch '1.0.0.M3' of github.com:spring-cloud/spring-cloud-release 7fdc875cb2b1620e8bc87ef8a27da2858eef7cd1 not-for-merge branch '1.0.0.RC1' of github.com:spring-cloud/spring-cloud-release @@ -24,14 +24,14 @@ cbbe80df445961eb193635e63394a3998243281b not-for-merge branch 'Greenwich' of git 2b7f449fa7d0e04a786ff097c6b1bfe3f322a28d not-for-merge branch 'Jenkins' of github.com:spring-cloud/spring-cloud-release 911fb79b2526a750d60c857d758dfbb834d3860a not-for-merge branch 'dependabot/maven/commons-io-commons-io-2.8.0' of github.com:spring-cloud/spring-cloud-release 6d60e974c9f0e454e6c11da99a61bd4cdcfcdea9 not-for-merge branch 'doc-as-pom' of github.com:spring-cloud/spring-cloud-release -75b4bfe286e37d0ac4ee2b08215b5fc0bc5823a7 not-for-merge branch 'docs-build' of github.com:spring-cloud/spring-cloud-release +64791a98052e66ef0cec08287349086b4822fa77 not-for-merge branch 'docs-build' of github.com:spring-cloud/spring-cloud-release 3d7d639afa258af09c5c08fd70322d43c95e4f03 not-for-merge branch 'fix-pom' of github.com:spring-cloud/spring-cloud-release 4b562d1f115d48170198e75d0bd592579d267a2c not-for-merge branch 'forHoxton.SR5' of github.com:spring-cloud/spring-cloud-release 1d3ec9b883f8b6c894ff0631d061e7df8f704e5f not-for-merge branch 'functionForStreamRelease' of github.com:spring-cloud/spring-cloud-release 3dc7bc208faf65ac6eb29031d8d01439f4e08511 not-for-merge branch 'functionForStreamRelease_3.0.x' of github.com:spring-cloud/spring-cloud-release 3b1a1270cc2a01012f663519fb7d4a1c7a26d394 not-for-merge branch 'functionForStreamRelease_4.0.x' of github.com:spring-cloud/spring-cloud-release 5f745590cb3f5ed43e9505515760a50075b4a61e not-for-merge branch 'gh-pages' of github.com:spring-cloud/spring-cloud-release -c7605514ca7be3e19247ff3b784e48f32eb3b60e not-for-merge branch 'jenkins-releaser-config' of github.com:spring-cloud/spring-cloud-release +b7b4cbfd3ef5f6898aac360ed08573db0bf779d0 not-for-merge branch 'jenkins-releaser-config' of github.com:spring-cloud/spring-cloud-release b603d412da7e68611e6701926be8a37694e43bd3 not-for-merge branch 'netflix4-eureka2' of github.com:spring-cloud/spring-cloud-release 8d9248d5a509a1df16f15074a73a2022697128e6 not-for-merge branch 'release/e-scc1355' of github.com:spring-cloud/spring-cloud-release fbf3b6368c26bc96b9958036156f37055f69ebf3 not-for-merge branch 'release/f-scc1355' of github.com:spring-cloud/spring-cloud-release @@ -47,3 +47,6 @@ fbf3b6368c26bc96b9958036156f37055f69ebf3 not-for-merge branch 'release/f-scc1355 8aa3cb92a11adedbc5acfb300e721e0c7c7cd875 not-for-merge branch 'scBuild214' of github.com:spring-cloud/spring-cloud-release da994d5600c15389f7fc7aa15f0414660d5343e1 not-for-merge branch 'springCloudBuildRelease' of github.com:spring-cloud/spring-cloud-release eedb764786313401e1058a8eda4e653d7eb89e01 not-for-merge branch 'unzipping' of github.com:spring-cloud/spring-cloud-release +635cf5cbd0410fc1159f6930f14b47062b44ae75 not-for-merge tag 'v2022.0.4' of github.com:spring-cloud/spring-cloud-release +07f01b8524b33590c95149e2048743573c1a0971 not-for-merge tag 'v2023.0.2' of github.com:spring-cloud/spring-cloud-release +725fdb10dc07c30a5cb356dc10cb44859b063907 not-for-merge tag 'v2023.0.3' of github.com:spring-cloud/spring-cloud-release diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/index b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/index index e84541e4..04b41df2 100644 Binary files a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/index and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/index differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/docs-build b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/docs-build index 8fa3f0bc..f2e8e637 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/docs-build +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/docs-build @@ -1 +1,2 @@ 0000000000000000000000000000000000000000 75b4bfe286e37d0ac4ee2b08215b5fc0bc5823a7 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1714588991 -0400 fetch origin: storing head +75b4bfe286e37d0ac4ee2b08215b5fc0bc5823a7 64791a98052e66ef0cec08287349086b4822fa77 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240827 -0400 fetch: fast-forward diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/jenkins-releaser-config b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/jenkins-releaser-config index 55f9eee4..cd09559a 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/jenkins-releaser-config +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/jenkins-releaser-config @@ -5,3 +5,4 @@ d2601d8c1eefd01a506c54c2f8cb6ed4492c95c4 60847c1d46bf8fc761b73337455105765d04496 4241e281e15c11b769a20606c5973a753c3f9151 04b6612cbeaf621808db2a0a66d6b78cc3bfbe34 Marcin Grzejszczak 1675782967 +0100 pull: fast-forward 04b6612cbeaf621808db2a0a66d6b78cc3bfbe34 c3deede8ccf0d1f58e84159c7e8d0748db104669 Marcin Grzejszczak 1686912310 +0200 pull: fast-forward c3deede8ccf0d1f58e84159c7e8d0748db104669 c7605514ca7be3e19247ff3b784e48f32eb3b60e Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1714588991 -0400 fetch origin: fast-forward +c7605514ca7be3e19247ff3b784e48f32eb3b60e b7b4cbfd3ef5f6898aac360ed08573db0bf779d0 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240827 -0400 fetch: fast-forward diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/main b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/main index f604f941..71f551b6 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/main +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/logs/refs/remotes/origin/main @@ -13,3 +13,4 @@ ecbeb68df64f1dcd9a45cd7dac70e857e2cde8a0 5812dd9ca14d6d61a76632662000c7a93c051c7 5812dd9ca14d6d61a76632662000c7a93c051c79 310b20cbb6f7fca74695b3ff6dc43cf4b3d4ba6a Marcin Grzejszczak 1686912310 +0200 pull: fast-forward 310b20cbb6f7fca74695b3ff6dc43cf4b3d4ba6a 217e46bc4aa6df83f3a131c344d53bf02dd28a9c Marcin Grzejszczak 1686912337 +0200 update by push 217e46bc4aa6df83f3a131c344d53bf02dd28a9c 3c340cb0fda1406905eb91a26b6ad37f3a228e65 Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1714588991 -0400 fetch origin: fast-forward +3c340cb0fda1406905eb91a26b6ad37f3a228e65 6180ef291f6ec01d97a3e3ad0f71648e08d9821e Ryan Baxter <524254+ryanjbaxter@users.noreply.github.com> 1721240827 -0400 fetch: fast-forward diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.idx b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.idx new file mode 100644 index 00000000..edda7d10 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.idx differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.pack b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.pack new file mode 100644 index 00000000..f3a51ad1 Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.pack differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.rev b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.rev new file mode 100644 index 00000000..100bd6fa Binary files /dev/null and b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/objects/pack/pack-d55c66f387202f5b610f8e26e086ecebe8de3ed5.rev differ diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/docs-build b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/docs-build index 92ed97d8..5ce2a6b8 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/docs-build +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/docs-build @@ -1 +1 @@ -75b4bfe286e37d0ac4ee2b08215b5fc0bc5823a7 +64791a98052e66ef0cec08287349086b4822fa77 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/jenkins-releaser-config b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/jenkins-releaser-config index 56c40c3a..c7de440a 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/jenkins-releaser-config +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/jenkins-releaser-config @@ -1 +1 @@ -c7605514ca7be3e19247ff3b784e48f32eb3b60e +b7b4cbfd3ef5f6898aac360ed08573db0bf779d0 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/main b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/main index 7beef763..29d222b4 100644 --- a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/main +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/remotes/origin/main @@ -1 +1 @@ -3c340cb0fda1406905eb91a26b6ad37f3a228e65 +6180ef291f6ec01d97a3e3ad0f71648e08d9821e diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2022.0.4 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2022.0.4 new file mode 100644 index 00000000..0fecf973 --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2022.0.4 @@ -0,0 +1 @@ +635cf5cbd0410fc1159f6930f14b47062b44ae75 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.2 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.2 new file mode 100644 index 00000000..aac34eec --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.2 @@ -0,0 +1 @@ +07f01b8524b33590c95149e2048743573c1a0971 diff --git a/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.3 b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.3 new file mode 100644 index 00000000..c0a80a3d --- /dev/null +++ b/projects/spring-cloud/src/test/resources/projects/spring-cloud-release/git/refs/tags/v2023.0.3 @@ -0,0 +1 @@ +725fdb10dc07c30a5cb356dc10cb44859b063907 diff --git a/releaser-core/src/main/java/releaser/internal/Releaser.java b/releaser-core/src/main/java/releaser/internal/Releaser.java index f52f60b2..3d848107 100644 --- a/releaser-core/src/main/java/releaser/internal/Releaser.java +++ b/releaser-core/src/main/java/releaser/internal/Releaser.java @@ -186,7 +186,13 @@ public class Releaser { ProjectVersion bumpedProject = bumpProject(originalVersion, newProjects); log.info("Will bump versions \n{}", newProjects); updateProjectFromBom(project, newProjects, originalVersion, SKIP_SNAPSHOT_ASSERTION); - this.projectGitHandler.commitAfterBumpingVersions(project, bumpedProject); + if (newProjects.size() == 1) { + // We are just updating the project version and not dependencies + this.projectGitHandler.commitAfterBumpingVersions(project, bumpedProject); + } + else { + this.projectGitHandler.commitAfterBumpingDependencyVersions(project, bumpedProject); + } log.info("\nSuccessfully reverted the commit and bumped snapshot versions"); return ExecutionResult.success(); } 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 3be1842d..ba6b08a0 100644 --- a/releaser-core/src/main/java/releaser/internal/git/GitRepo.java +++ b/releaser-core/src/main/java/releaser/internal/git/GitRepo.java @@ -410,7 +410,8 @@ class GitRepo { printLog(git); } catch (Exception e) { - throw new IllegalStateException(e); + log.warn("Exception occurred while reverting the commit", e); + // throw new IllegalStateException(e); } } 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 618b1ed0..463f2b9b 100644 --- a/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java +++ b/releaser-core/src/main/java/releaser/internal/git/ProjectGitHandler.java @@ -56,6 +56,8 @@ public class ProjectGitHandler implements Closeable { private static final String POST_RELEASE_BUMP_MSG = "Bumping versions to %s after release"; + private static final String POST_RELEASE_DEPENDENCY_BUMP_MSG = "Bumping dependency versions after release"; + private final ReleaserProperties properties; public ProjectGitHandler(ReleaserProperties properties) { @@ -93,6 +95,16 @@ public class ProjectGitHandler implements Closeable { } } + public void commitAfterBumpingDependencyVersions(File project, ProjectVersion bumpedVersion) { + if (bumpedVersion.isSnapshot()) { + log.info("Snapshot version [{}] found. Will only commit the changed poms", bumpedVersion); + commit(project, POST_RELEASE_DEPENDENCY_BUMP_MSG); + } + else { + log.info("Non snapshot version [{}] found. Won't do anything", bumpedVersion); + } + } + public void commit(File project, String message) { GitRepo gitRepo = gitRepo(project); gitRepo.commit(message); 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 d285fbfd..c1cc1f48 100644 --- a/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java +++ b/releaser-core/src/test/java/releaser/internal/git/GitRepoTests.java @@ -25,7 +25,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import org.assertj.core.api.BDDAssertions; import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; @@ -293,8 +292,19 @@ public class GitRepoTests { File project = new GitRepo(this.tmpFolder) .cloneProject(new URIish(this.springCloudReleaseProject.toURI().toURL())); - BDDAssertions.thenThrownBy(() -> new GitRepo(project).revert("some message")) - .hasMessageContaining("Won't revert the commit with id"); + String lastCommitMessage = ""; + try (Git git = openGitProject(project)) { + lastCommitMessage = git.log().call().iterator().next().getShortMessage(); + } + then(lastCommitMessage).isNotEqualTo(""); + + new GitRepo(project).revert("some message"); + + // Verify that the last commit message is still the same + try (Git git = openGitProject(project)) { + RevCommit revCommit = git.log().call().iterator().next(); + then(revCommit.getShortMessage()).isEqualTo(lastCommitMessage); + } } } diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotReleaseTask.java index 0e28de30..ce9ed967 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotReleaseTask.java @@ -26,7 +26,7 @@ public class BumpBackToSnapshotReleaseTask implements ReleaseReleaserTask { /** * Order of this task. The higher value, the lower order. */ - public static final int ORDER = 50; + public static final int ORDER = 70; private final Releaser releaser; diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotsProjectOnlyReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotsProjectOnlyReleaseTask.java new file mode 100644 index 00000000..702ecfdf --- /dev/null +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/BumpBackToSnapshotsProjectOnlyReleaseTask.java @@ -0,0 +1,72 @@ +/* + * Copyright 2013-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package releaser.internal.tasks.release; + +import releaser.internal.Releaser; +import releaser.internal.project.Projects; +import releaser.internal.spring.Arguments; +import releaser.internal.tasks.ReleaseReleaserTask; +import releaser.internal.tech.ExecutionResult; + +/** + * @author Ryan Baxter + */ +public class BumpBackToSnapshotsProjectOnlyReleaseTask implements ReleaseReleaserTask { + + /** + * Order of this task. The higher value, the lower order. + */ + public static final int ORDER = 40; + + private final Releaser releaser; + + public BumpBackToSnapshotsProjectOnlyReleaseTask(Releaser releaser) { + this.releaser = releaser; + } + + @Override + public String name() { + return "bumpBackToSnapshotsProjectOnly"; + } + + @Override + public String shortName() { + return "bbspo"; + } + + @Override + public String header() { + return "BUMPING BACK TO SNAPSHOT (PROJECT ONLY)"; + } + + @Override + public String description() { + return "Bumps just the project version back to the next snapshot version."; + } + + @Override + public ExecutionResult runTask(Arguments args) throws RuntimeException { + return this.releaser.rollbackReleaseVersion(args.project, + new Projects(args.projects.forNameStartingWith(args.versionFromBom.projectName)), args.versionFromBom); + } + + @Override + public int getOrder() { + return BumpBackToSnapshotsProjectOnlyReleaseTask.ORDER; + } + +} diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java index 17d7a9c8..b6b6d2bd 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/PublishDocsReleaseTask.java @@ -26,7 +26,7 @@ public class PublishDocsReleaseTask implements ReleaseReleaserTask { /** * Order of this task. The higher value, the lower order. */ - public static final int ORDER = 40; + public static final int ORDER = 60; private final Releaser releaser; diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/PushChangesReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/PushChangesReleaseTask.java index be1f4e1a..532b51d6 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/PushChangesReleaseTask.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/PushChangesReleaseTask.java @@ -26,7 +26,7 @@ public class PushChangesReleaseTask implements ReleaseReleaserTask { /** * Order of this task. The higher value, the lower order. */ - public static final int ORDER = 60; + public static final int ORDER = 80; private final Releaser releaser; diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/PushSnapshotChangesForProjectOnlyReleaseTask.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/PushSnapshotChangesForProjectOnlyReleaseTask.java new file mode 100644 index 00000000..debcf90c --- /dev/null +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/PushSnapshotChangesForProjectOnlyReleaseTask.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package releaser.internal.tasks.release; + +import releaser.internal.Releaser; +import releaser.internal.spring.Arguments; +import releaser.internal.tasks.ReleaseReleaserTask; +import releaser.internal.tech.ExecutionResult; + +/** + * @author Ryan Baxter + */ +public class PushSnapshotChangesForProjectOnlyReleaseTask implements ReleaseReleaserTask { + + /** + * Order of this task. The higher value, the lower order. + */ + public static final int ORDER = 50; + + private final Releaser releaser; + + public PushSnapshotChangesForProjectOnlyReleaseTask(Releaser releaser) { + this.releaser = releaser; + } + + @Override + public String name() { + return "pushSnapshotChangesForProjectOnlyReleaseTask"; + } + + @Override + public String shortName() { + return "pscfpo"; + } + + @Override + public String header() { + return "PUSHING SNAPSHOT CHANGES (PROJECT ONLY)"; + } + + @Override + public String description() { + return "Push commit after updating project version to snapshot version."; + } + + @Override + public ExecutionResult runTask(Arguments args) throws RuntimeException { + return this.releaser.pushCurrentBranch(args.project); + } + + @Override + public int getOrder() { + return PushSnapshotChangesForProjectOnlyReleaseTask.ORDER; + } + +} diff --git a/releaser-spring/src/main/java/releaser/internal/tasks/release/ReleaseTasksConfiguration.java b/releaser-spring/src/main/java/releaser/internal/tasks/release/ReleaseTasksConfiguration.java index fa35fec3..c339b813 100644 --- a/releaser-spring/src/main/java/releaser/internal/tasks/release/ReleaseTasksConfiguration.java +++ b/releaser-spring/src/main/java/releaser/internal/tasks/release/ReleaseTasksConfiguration.java @@ -69,4 +69,16 @@ class ReleaseTasksConfiguration { return new UpdatingPomsReleaseTask(releaser); } + @Bean + @ConditionalOnMissingBean + BumpBackToSnapshotsProjectOnlyReleaseTask bumpBackToSnapshotsProjectOnlyReleaseTask(Releaser releaser) { + return new BumpBackToSnapshotsProjectOnlyReleaseTask(releaser); + } + + @Bean + @ConditionalOnMissingBean + PushSnapshotChangesForProjectOnlyReleaseTask pushSnapshotChangesForProjectOnlyReleaseTask(Releaser releaser) { + return new PushSnapshotChangesForProjectOnlyReleaseTask(releaser); + } + } diff --git a/releaser-test/src/main/java/releaser/internal/buildsystem/TestUtils.java b/releaser-test/src/main/java/releaser/internal/buildsystem/TestUtils.java index 4bead814..b5a094e3 100644 --- a/releaser-test/src/main/java/releaser/internal/buildsystem/TestUtils.java +++ b/releaser-test/src/main/java/releaser/internal/buildsystem/TestUtils.java @@ -38,6 +38,7 @@ public final class TestUtils { prepareLocalRepo("target/test-classes/projects/", "spring-cloud-build"); prepareLocalRepo("target/test-classes/projects/", "spring-cloud-static-angel"); prepareLocalRepo("target/test-classes/projects/", "spring-docs-actions"); + prepareLocalRepo("target/test-classes/projects/", "spring-cloud-bus"); } private static void prepareLocalRepo(String buildDir, String repoPath) throws IOException { diff --git a/releaser-test/src/main/java/releaser/internal/spring/ArgsBuilder.java b/releaser-test/src/main/java/releaser/internal/spring/ArgsBuilder.java index 2f8a4952..cbce3f6d 100644 --- a/releaser-test/src/main/java/releaser/internal/spring/ArgsBuilder.java +++ b/releaser-test/src/main/java/releaser/internal/spring/ArgsBuilder.java @@ -229,6 +229,18 @@ public class ArgsBuilder { return this; } + public ArgsBuilder antoraCommand(String command) { + removeIfPresent("releaser.maven.run-antora-command"); + this.args.add("releaser.maven.run-antora-command=" + command); + return this; + } + + public ArgsBuilder syncAntoraDocsCommand(String command) { + removeIfPresent("releaser.antora.sync-antora-docs-command"); + this.args.add("releaser.antora.sync-antora-docs-command=" + command); + return this; + } + public String[] build() { return args.toArray(new String[0]); } diff --git a/releaser-test/src/main/java/releaser/internal/spring/meta/AbstractSpringMetaReleaseAcceptanceTests.java b/releaser-test/src/main/java/releaser/internal/spring/meta/AbstractSpringMetaReleaseAcceptanceTests.java index e94b1930..e4b8c633 100644 --- a/releaser-test/src/main/java/releaser/internal/spring/meta/AbstractSpringMetaReleaseAcceptanceTests.java +++ b/releaser-test/src/main/java/releaser/internal/spring/meta/AbstractSpringMetaReleaseAcceptanceTests.java @@ -77,7 +77,7 @@ public abstract class AbstractSpringMetaReleaseAcceptanceTests extends AbstractS .releaseTrainBomUrl(file("/projects/spring-cloud-release/").toURI().toString()); } - public Map v2022_0_4() { + public Map v2022_0_6() { Map versions = new LinkedHashMap<>(); versions.put("spring-boot", "3.0.7"); versions.put("spring-cloud-build", "4.0.3"); @@ -96,7 +96,7 @@ public abstract class AbstractSpringMetaReleaseAcceptanceTests extends AbstractS versions.put("spring-cloud-contract", "4.0.3"); versions.put("spring-cloud-kubernetes", "3.0.3"); versions.put("spring-cloud-vault", "4.0.1"); - versions.put("spring-cloud-release", "2022.0.4"); + versions.put("spring-cloud-release", "2022.0.6"); return versions; }