From 1bb0647f22f38b8af2f2b5b6871d0e2ef436a409 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Wed, 15 May 2019 18:33:17 +0700 Subject: [PATCH 01/22] Update readme --- README.md | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 1b99cf8..5d634c6 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -# Java CQRS -[![Build Status](https://travis-ci.com/dathoangse/java-cqrs.svg?branch=develop)](https://travis-ci.com/dathoangse/java-cqrs) +# Java CQRS CommandBus +[![Build Status](https://travis-ci.com/dathoangse/java-cqrs-commandbus.svg?branch=develop)](https://travis-ci.com/dathoangse/java-cqrs) [![codecov](https://codecov.io/gh/dathoangse/java-cqrs/branch/develop/graph/badge.svg)](https://codecov.io/gh/dathoangse/java-cqrs) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.dathoang.cqrs.commandbus/core/badge.svg)](https://mvnrepository.com/artifact/net.dathoang.cqrs.commandbus/core) -A lightweight & highly extensible CQRS framework for implementing CQRS architectural pattern in java +A lightweight & highly extensible CQRS framework for implementing application layer and CQRS architectural pattern in Java. -## Who uses Java CQRS +## Who uses Java CQRS CommandBus * [YouthDev](https://youthdev.net/en/) ## Code style @@ -16,8 +17,6 @@ The project uses [Git flow](https://nvie.com/posts/a-successful-git-branching-mo ## Versioning The project uses [Semantic Versioning 2.0.0 | Semantic Versioning](https://semver.org/) for versioning releases. -Special note: When the major version of the project is still 0 (ex: v0.1.3), the framework is not ready for production use, and the framework interface is still not stable (which means there might be some breaking changes between minor versions when the major version is still 0). - ## Libs/frameworks used * [JUnit 5](https://junit.org/junit5/) for unit testing. * [AssertJ](http://joel-costigliola.github.io/assertj/) for assertions in unit test. @@ -28,26 +27,31 @@ Built with: * [Gradle Build Tool](https://gradle.org/). # Features -`Java CQRS` is a very lightweight and highly extensible CQRS framework that help you implement the CQRS architecture into your project. -Characteristics: -1. `Lightweight`: The core interfaces of the framework is minimized, making it easy to swap out the implementation of the whole framework, and you can easily integrate into your project with little efforts. -2. `Highly extensible`: The lib provide a very high extensibility via a *middleware pipeline* and well-structured modules. -3. `Architecturally unoptionated`: The framework doesn't make any assumption about the architecture you're building, thus it doesn't force you to design your architecture in a certain architectural style. CQRS can be implemented at different levels & scales, depending on your project requirement. -So: -* You can simply take the command bus and use it to implement your application layer to act as a bridge between your UI/presentation layer & domain layer, and simply have the read side (read models/operations) and write side (write models/operations) separated. -* Or you can take it to the next level and have a separated read database & write database that keep in sync using event projection mechanism, which can help to make the read side massively scalable & extremely high performance. -* Or you can even design using full-blown CQRS & Event Sourcing architectural pattern that use event store as the single source of truth. - -## Build -To build, run the command in terminal at the root of the project: +`Java CQRS CommandBus` is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: +1. `Lightweight`: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library's implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it's possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. +2. `Highly extensible`: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. + +## Integrate into your project + +### For maven project + +Add the dependency: + ``` -./gradlew clean build + + net.dathoang.cqrs.commandbus + core + 0.1.0 + pom + ``` -## Tests -To run unit test, run the command in terminal at the root of the project: +### For gradle project + +Add the dependency: + ``` -./gradlew clean test +compile group: 'net.dathoang.cqrs.commandbus', name: 'core', version: '0.1.0', ext: 'pom' ``` ## Contribute @@ -58,4 +62,4 @@ Before creating pull request, please make sure: * There is 100% code coverage on all new codes. ## License -Java CQRS is an Open Source Software released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0.html) +Java CQRS CommandBus is an Open Source Software released under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) From efc0a3bf7bd10f93370133edfc8cb39aa16e0bb7 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 25 May 2019 12:11:43 +0700 Subject: [PATCH 02/22] Append -SNAPSHOT to version when publish to snapshot repository --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 09f5576..d3e7129 100644 --- a/build.gradle +++ b/build.gradle @@ -82,6 +82,9 @@ allprojects { customizePom(pom) groupId 'net.dathoang.cqrs.commandbus' version '0.1.1' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } from components.java From a231329e801eeef1a3831eb4425adeb15a276b2a Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 25 May 2019 12:13:46 +0700 Subject: [PATCH 03/22] Publish to snapshot repository for release and hotfix branch --- .travis.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 247a5af..afc3934 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,10 +38,10 @@ jobs: - ./gradlew core:publish - ./cleanup_after_publish - # - stage: release - # name: "Publish snapshot" - # if: branch =~ ^(hotfix|release)\/.* - # script: - # - ./prepare_before_publish - # - ./gradlew core:publish -PSNAPSHOT=true - # - ./cleanup_after_publish \ No newline at end of file + - stage: release + name: "Publish snapshot" + if: branch =~ ^(hotfix|release)\/.* + script: + - ./prepare_before_publish + - ./gradlew core:publish -PSNAPSHOT=true + - ./cleanup_after_publish \ No newline at end of file From a1af4955434745ebe008487d02777cf4f6d3e49b Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 2 Jun 2019 16:48:49 +0700 Subject: [PATCH 04/22] Bump version to 0.2.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index d3e7129..7508830 100644 --- a/build.gradle +++ b/build.gradle @@ -81,7 +81,7 @@ allprojects { mavenJava(MavenPublication) { customizePom(pom) groupId 'net.dathoang.cqrs.commandbus' - version '0.1.1' + version '0.2.0' if (project.properties['SNAPSHOT'] == 'true') { version (version + '-SNAPSHOT') } From 8471771ed32e3b74d545e7de3c5e8953216e0786 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 2 Jun 2019 16:50:32 +0700 Subject: [PATCH 05/22] Also publish to snapshot on develop branch --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index afc3934..bb8586b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,7 @@ jobs: - stage: release name: "Publish snapshot" - if: branch =~ ^(hotfix|release)\/.* + if: branch =~ ^(develop|hotfix|release).* script: - ./prepare_before_publish - ./gradlew core:publish -PSNAPSHOT=true From 2a50dd063deeb512f7c876e8d6fe2a545df49875 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 2 Jun 2019 17:13:27 +0700 Subject: [PATCH 06/22] Make CommandHandler and QueryHandler extend MessageHandler --- .../dathoang/cqrs/commandbus/command/CommandHandler.java | 6 ++++-- .../dathoang/cqrs/commandbus/command/DefaultCommandBus.java | 2 +- .../dathoang/cqrs/commandbus/message/DefaultMessageBus.java | 2 +- .../net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java | 2 +- .../net/dathoang/cqrs/commandbus/query/QueryHandler.java | 4 +++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java b/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java index 12165a4..4e16efb 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java @@ -1,5 +1,7 @@ package net.dathoang.cqrs.commandbus.command; -public interface CommandHandler, R> { +import net.dathoang.cqrs.commandbus.message.MessageHandler; + +public interface CommandHandler, R> extends MessageHandler { R handle(C command) throws Exception; -} +} \ No newline at end of file diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java b/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java index cc93fac..889c2d8 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java @@ -8,7 +8,7 @@ import net.dathoang.cqrs.commandbus.message.MessageHandlerFactory; import net.dathoang.cqrs.commandbus.middleware.Middleware; -final class DefaultCommandBus implements CommandBus { +public final class DefaultCommandBus implements CommandBus { private final MessageBus defaultMessageBus; DefaultCommandBus(CommandHandlerFactory commandHandlerFactory, diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java b/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java index 8d0b5e0..359dae8 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java @@ -15,7 +15,7 @@ -final class DefaultMessageBus implements MessageBus { +public final class DefaultMessageBus implements MessageBus { private static final Log log = LogFactory.getLog(DefaultMessageBus.class); private final List middlewarePipeline; diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java b/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java index 5ce625c..e9bbf85 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java @@ -8,7 +8,7 @@ import net.dathoang.cqrs.commandbus.message.MessageHandlerFactory; import net.dathoang.cqrs.commandbus.middleware.Middleware; -final class DefaultQueryBus implements QueryBus { +public final class DefaultQueryBus implements QueryBus { private final MessageBus defaultMessageBus; diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java b/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java index cebab9a..aee6548 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java @@ -1,5 +1,7 @@ package net.dathoang.cqrs.commandbus.query; -public interface QueryHandler, R> { +import net.dathoang.cqrs.commandbus.message.MessageHandler; + +public interface QueryHandler, R> extends MessageHandler { R handle(Q query) throws Exception; } From 3f7be7e19789125109b1eb6dfab7b225c5fc3e53 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 2 Jun 2019 18:54:15 +0700 Subject: [PATCH 07/22] Change method name of CommandHandlerFactory and QueryHandlerFactory to prevent method name collision --- .../cqrs/commandbus/command/CommandHandlerFactory.java | 2 +- .../cqrs/commandbus/command/DefaultCommandBus.java | 2 +- .../dathoang/cqrs/commandbus/query/DefaultQueryBus.java | 2 +- .../cqrs/commandbus/query/QueryHandlerFactory.java | 2 +- .../cqrs/commandbus/command/DefaultCommandBusTest.java | 8 ++------ .../cqrs/commandbus/query/DefaultQueryBusTest.java | 7 +------ 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java b/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java index fc2cdf2..400bfc4 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java @@ -1,5 +1,5 @@ package net.dathoang.cqrs.commandbus.command; public interface CommandHandlerFactory { - CommandHandler, R> createHandler(String commandName); + CommandHandler, R> createCommandHandler(String commandName); } diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java b/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java index 889c2d8..2648453 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java @@ -35,7 +35,7 @@ public MessageHandlerFactoryAdapter(CommandHandlerFactory commandHandlerFactory) @Override public MessageHandler, R> createHandler(String messageName) { return new MessageHandlerAdapter<>( - commandHandlerFactory.createHandler(messageName) + commandHandlerFactory.createCommandHandler(messageName) ); } } diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java b/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java index e9bbf85..80d2eac 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java @@ -37,7 +37,7 @@ public QueryHandlerFactoryToMessageHandlerFactoryAdapter( @Override public MessageHandler, R> createHandler(String messageName) { return new QueryHandlerToMessageHandlerAdapter<>( - queryHandlerFactory.createHandler(messageName) + queryHandlerFactory.createQueryHandler(messageName) ); } } diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java b/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java index cdab0cd..2280dac 100644 --- a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java +++ b/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java @@ -1,5 +1,5 @@ package net.dathoang.cqrs.commandbus.query; public interface QueryHandlerFactory { - QueryHandler, R> createHandler(String queryName); + QueryHandler, R> createQueryHandler(String queryName); } diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java b/core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java index 22a650b..4765456 100644 --- a/core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java +++ b/core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java @@ -10,11 +10,7 @@ import static org.mockito.Mockito.verify; import java.util.List; -import net.dathoang.cqrs.commandbus.command.Command; -import net.dathoang.cqrs.commandbus.command.CommandBus; -import net.dathoang.cqrs.commandbus.command.CommandHandler; -import net.dathoang.cqrs.commandbus.command.CommandHandlerFactory; -import net.dathoang.cqrs.commandbus.command.DefaultCommandBus; + import net.dathoang.cqrs.commandbus.middleware.Middleware; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -36,7 +32,7 @@ void shouldDispatchThroughMiddlewarePipelineAndTocommandHandlerSuccessfully() th .when(dummyCommandHandler).handle(dummyCommand); CommandHandlerFactory commandHandlerFactory = mock(CommandHandlerFactory.class); doReturn(dummyCommandHandler) - .when(commandHandlerFactory).createHandler(dummyCommand.getClass().getName()); + .when(commandHandlerFactory).createCommandHandler(dummyCommand.getClass().getName()); List middlewareList = asList( mock(Middleware.class), mock(Middleware.class), diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java b/core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java index 36cb5d2..04c6554 100644 --- a/core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java +++ b/core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java @@ -11,11 +11,6 @@ import java.util.List; import net.dathoang.cqrs.commandbus.middleware.Middleware; -import net.dathoang.cqrs.commandbus.query.DefaultQueryBus; -import net.dathoang.cqrs.commandbus.query.Query; -import net.dathoang.cqrs.commandbus.query.QueryBus; -import net.dathoang.cqrs.commandbus.query.QueryHandler; -import net.dathoang.cqrs.commandbus.query.QueryHandlerFactory; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -36,7 +31,7 @@ void shouldDispatchThroughMiddlewarePipelineAndToQueryHandlerSuccessfully() thro .when(dummyQueryHandler).handle(dummyQuery); QueryHandlerFactory queryHandlerFactory = mock(QueryHandlerFactory.class); doReturn(dummyQueryHandler) - .when(queryHandlerFactory).createHandler(dummyQuery.getClass().getName()); + .when(queryHandlerFactory).createQueryHandler(dummyQuery.getClass().getName()); List middlewareList = asList( mock(Middleware.class), mock(Middleware.class), From 78c59fa1bb581bee805836a30825ec14b2b96197 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 13 Jul 2019 18:33:20 +0700 Subject: [PATCH 08/22] Rename modules --- build.gradle | 4 ++-- .../build.gradle | 2 +- .../cqrs/commandbus/middleware/logging/LoggingMiddleware.java | 0 .../commandbus/middleware/logging/LoggingMiddlewareTest.java | 0 {core => commandbus-core}/build.gradle | 0 .../java/net/dathoang/cqrs/commandbus/command/Command.java | 0 .../java/net/dathoang/cqrs/commandbus/command/CommandBus.java | 0 .../dathoang/cqrs/commandbus/command/CommandBusFactory.java | 0 .../net/dathoang/cqrs/commandbus/command/CommandHandler.java | 0 .../cqrs/commandbus/command/CommandHandlerFactory.java | 0 .../dathoang/cqrs/commandbus/command/DefaultCommandBus.java | 0 .../cqrs/commandbus/exceptions/CommandBusException.java | 0 .../cqrs/commandbus/exceptions/NoHandlerFoundException.java | 0 .../dathoang/cqrs/commandbus/message/DefaultMessageBus.java | 0 .../commandbus/message/DefaultPipelineContextContainer.java | 0 .../net/dathoang/cqrs/commandbus/message/ExceptionUtils.java | 0 .../java/net/dathoang/cqrs/commandbus/message/Message.java | 0 .../java/net/dathoang/cqrs/commandbus/message/MessageBus.java | 0 .../dathoang/cqrs/commandbus/message/MessageBusFactory.java | 0 .../net/dathoang/cqrs/commandbus/message/MessageHandler.java | 0 .../cqrs/commandbus/message/MessageHandlerFactory.java | 0 .../cqrs/commandbus/message/MiddlewareContextInjector.java | 0 .../net/dathoang/cqrs/commandbus/message/ReflectionUtils.java | 0 .../net/dathoang/cqrs/commandbus/middleware/Middleware.java | 0 .../cqrs/commandbus/middleware/MiddlewareContext.java | 0 .../cqrs/commandbus/middleware/PipelineContextContainer.java | 0 .../cqrs/commandbus/middleware/ResultAndExceptionHolder.java | 0 .../net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java | 0 .../main/java/net/dathoang/cqrs/commandbus/query/Query.java | 0 .../java/net/dathoang/cqrs/commandbus/query/QueryBus.java | 0 .../net/dathoang/cqrs/commandbus/query/QueryBusFactory.java | 0 .../java/net/dathoang/cqrs/commandbus/query/QueryHandler.java | 0 .../dathoang/cqrs/commandbus/query/QueryHandlerFactory.java | 0 .../cqrs/commandbus/command/CommandBusFactoryTest.java | 0 .../cqrs/commandbus/command/DefaultCommandBusTest.java | 0 .../cqrs/commandbus/message/DefaultMessageBusTest.java | 0 .../message/DefaultPipelineContextContainerTest.java | 0 .../dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java | 0 .../commandbus/message/MiddlewareContextInjectorTest.java | 0 .../dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java | 0 .../dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java | 0 .../dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java | 0 settings.gradle | 4 ++-- 43 files changed, 5 insertions(+), 5 deletions(-) rename {simple-middlewares => commandbus-basic-middleware}/build.gradle (96%) rename {simple-middlewares => commandbus-basic-middleware}/src/main/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddleware.java (100%) rename {simple-middlewares => commandbus-basic-middleware}/src/test/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddlewareTest.java (100%) rename {core => commandbus-core}/build.gradle (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/exceptions/CommandBusException.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainer.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/ExceptionUtils.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjector.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/message/ReflectionUtils.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java (100%) rename {core => commandbus-core}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBusTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainerTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjectorTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java (100%) rename {core => commandbus-core}/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java (100%) diff --git a/build.gradle b/build.gradle index 7508830..c858509 100644 --- a/build.gradle +++ b/build.gradle @@ -16,8 +16,8 @@ repositories { } dependencies { - compile project(':core') - compile project(':simple-middlewares') + compile project(':commandbus-core') + compile project(':commandbus-basic-middleware') } allprojects { diff --git a/simple-middlewares/build.gradle b/commandbus-basic-middleware/build.gradle similarity index 96% rename from simple-middlewares/build.gradle rename to commandbus-basic-middleware/build.gradle index e753a0d..d1dac3c 100644 --- a/simple-middlewares/build.gradle +++ b/commandbus-basic-middleware/build.gradle @@ -10,7 +10,7 @@ repositories { dependencies { implementation 'commons-logging:commons-logging:1.2' - compile project(':core') + compile project(':commandbus-core') testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' testImplementation 'org.assertj:assertj-core:3.11.1' diff --git a/simple-middlewares/src/main/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddleware.java b/commandbus-basic-middleware/src/main/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddleware.java similarity index 100% rename from simple-middlewares/src/main/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddleware.java rename to commandbus-basic-middleware/src/main/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddleware.java diff --git a/simple-middlewares/src/test/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddlewareTest.java b/commandbus-basic-middleware/src/test/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddlewareTest.java similarity index 100% rename from simple-middlewares/src/test/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddlewareTest.java rename to commandbus-basic-middleware/src/test/java/net/dathoang/cqrs/commandbus/middleware/logging/LoggingMiddlewareTest.java diff --git a/core/build.gradle b/commandbus-core/build.gradle similarity index 100% rename from core/build.gradle rename to commandbus-core/build.gradle diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/CommandBusException.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/CommandBusException.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/CommandBusException.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/CommandBusException.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainer.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainer.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainer.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainer.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/ExceptionUtils.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/ExceptionUtils.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/ExceptionUtils.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/ExceptionUtils.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjector.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjector.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjector.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjector.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/message/ReflectionUtils.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/ReflectionUtils.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/message/ReflectionUtils.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/ReflectionUtils.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java diff --git a/core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java similarity index 100% rename from core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java rename to commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBusTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBusTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBusTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBusTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBusTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainerTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainerTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainerTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/DefaultPipelineContextContainerTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/ExceptionUtilsTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjectorTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjectorTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjectorTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/MiddlewareContextInjectorTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/message/ReflectionUtilsTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBusTest.java diff --git a/core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java similarity index 100% rename from core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java rename to commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java diff --git a/settings.gradle b/settings.gradle index 990b66e..bdd75f6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,6 +8,6 @@ */ rootProject.name = 'java-cqrs-commandbus' -include 'core' -include 'simple-middlewares' +include 'commandbus-core' +include 'commandbus-basic-middleware' From cb37d84352728e72b68ab247930e9be2bb931bd5 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 13 Jul 2019 18:52:59 +0700 Subject: [PATCH 09/22] Move all interfaces from commandbus-core module to commandbus-spec module --- commandbus-core/build.gradle | 2 ++ commandbus-spec/build.gradle | 15 +++++++++++++++ .../dathoang/cqrs/commandbus/command/Command.java | 0 .../cqrs/commandbus/command/CommandBus.java | 0 .../cqrs/commandbus/command/CommandHandler.java | 0 .../commandbus/command/CommandHandlerFactory.java | 0 .../dathoang/cqrs/commandbus/message/Message.java | 0 .../cqrs/commandbus/message/MessageBus.java | 0 .../cqrs/commandbus/message/MessageHandler.java | 0 .../commandbus/message/MessageHandlerFactory.java | 0 .../cqrs/commandbus/middleware/Middleware.java | 0 .../commandbus/middleware/MiddlewareContext.java | 0 .../middleware/PipelineContextContainer.java | 0 .../middleware/ResultAndExceptionHolder.java | 0 .../net/dathoang/cqrs/commandbus/query/Query.java | 0 .../dathoang/cqrs/commandbus/query/QueryBus.java | 0 .../cqrs/commandbus/query/QueryHandler.java | 0 .../commandbus/query/QueryHandlerFactory.java | 0 settings.gradle | 1 + 19 files changed, 18 insertions(+) create mode 100644 commandbus-spec/build.gradle rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java (100%) rename {commandbus-core => commandbus-spec}/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java (100%) diff --git a/commandbus-core/build.gradle b/commandbus-core/build.gradle index 27c0bf5..d91d219 100644 --- a/commandbus-core/build.gradle +++ b/commandbus-core/build.gradle @@ -9,6 +9,8 @@ repositories { } dependencies { + compile project(':commandbus-spec') + implementation 'commons-logging:commons-logging:1.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' diff --git a/commandbus-spec/build.gradle b/commandbus-spec/build.gradle new file mode 100644 index 0000000..0081910 --- /dev/null +++ b/commandbus-spec/build.gradle @@ -0,0 +1,15 @@ +plugins { + id 'java' +} + +version 'unspecified' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/Command.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBus.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandler.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/command/CommandHandlerFactory.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/Message.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBus.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandler.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/message/MessageHandlerFactory.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/Middleware.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/MiddlewareContext.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/PipelineContextContainer.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/middleware/ResultAndExceptionHolder.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/Query.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBus.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandler.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java similarity index 100% rename from commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java rename to commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/query/QueryHandlerFactory.java diff --git a/settings.gradle b/settings.gradle index bdd75f6..98ae1d9 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,4 +10,5 @@ rootProject.name = 'java-cqrs-commandbus' include 'commandbus-core' include 'commandbus-basic-middleware' +include 'commandbus-spec' From b2f3fb28d2f6d9471e25d46a6dc7850976de3ff5 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:04:35 +0700 Subject: [PATCH 10/22] Update project dependencies --- commandbus-basic-middleware/build.gradle | 3 ++- commandbus-core/build.gradle | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/commandbus-basic-middleware/build.gradle b/commandbus-basic-middleware/build.gradle index d1dac3c..b3c432c 100644 --- a/commandbus-basic-middleware/build.gradle +++ b/commandbus-basic-middleware/build.gradle @@ -10,7 +10,8 @@ repositories { dependencies { implementation 'commons-logging:commons-logging:1.2' - compile project(':commandbus-core') + implementation project(':commandbus-core') + implementation project(':commandbus-spec') testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' testImplementation 'org.assertj:assertj-core:3.11.1' diff --git a/commandbus-core/build.gradle b/commandbus-core/build.gradle index d91d219..897d0fc 100644 --- a/commandbus-core/build.gradle +++ b/commandbus-core/build.gradle @@ -9,7 +9,7 @@ repositories { } dependencies { - compile project(':commandbus-spec') + implementation project(':commandbus-spec') implementation 'commons-logging:commons-logging:1.2' From c430148f4e35a8544c02c25438767cb9b8784c66 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:07:48 +0700 Subject: [PATCH 11/22] Implement commandbus-spring with basic spring integration --- commandbus-core/build.gradle | 1 + .../autoscan/AutoScanHandlerFactory.java | 95 +++++++++++++++++++ .../commandbus/command/DefaultCommandBus.java | 15 +-- .../exceptions/NoHandlerFoundException.java | 4 + .../commandbus/query/DefaultQueryBus.java | 13 ++- .../commandbus/autoscan/CommandMapping.java | 12 +++ .../cqrs/commandbus/autoscan/HandlerScan.java | 9 ++ .../commandbus/autoscan/QueryMapping.java | 11 +++ commandbus-spring/build.gradle | 23 +++++ .../spring/CommandBusSpringConfiguration.java | 74 +++++++++++++++ .../spring/DefaultHandlerFactoryConfig.java | 23 +++++ .../spring/DefaultMiddlewareConfig.java | 24 +++++ .../spring/HandlerFactoryConfig.java | 9 ++ .../commandbus/spring/MiddlewareConfig.java | 10 ++ .../spring/SpringAutoScanHandlerFactory.java | 42 ++++++++ settings.gradle | 1 + 16 files changed, 356 insertions(+), 10 deletions(-) create mode 100644 commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java create mode 100644 commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/CommandMapping.java create mode 100644 commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/HandlerScan.java create mode 100644 commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/QueryMapping.java create mode 100644 commandbus-spring/build.gradle create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultHandlerFactoryConfig.java create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultMiddlewareConfig.java create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/HandlerFactoryConfig.java create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/MiddlewareConfig.java create mode 100644 commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java diff --git a/commandbus-core/build.gradle b/commandbus-core/build.gradle index 897d0fc..11826dd 100644 --- a/commandbus-core/build.gradle +++ b/commandbus-core/build.gradle @@ -12,6 +12,7 @@ dependencies { implementation project(':commandbus-spec') implementation 'commons-logging:commons-logging:1.2' + implementation 'org.reflections:reflections:0.9.11' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.0' testImplementation 'org.assertj:assertj-core:3.11.1' diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java new file mode 100644 index 0000000..99909ef --- /dev/null +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java @@ -0,0 +1,95 @@ +package net.dathoang.cqrs.commandbus.autoscan; + +import net.dathoang.cqrs.commandbus.command.Command; +import net.dathoang.cqrs.commandbus.command.CommandHandler; +import net.dathoang.cqrs.commandbus.command.CommandHandlerFactory; +import net.dathoang.cqrs.commandbus.query.Query; +import net.dathoang.cqrs.commandbus.query.QueryHandler; +import net.dathoang.cqrs.commandbus.query.QueryHandlerFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.reflections.Reflections; + +import java.util.*; +import java.util.function.Function; + +public abstract class AutoScanHandlerFactory implements QueryHandlerFactory, CommandHandlerFactory { + private static final Log log = LogFactory.getLog(AutoScanHandlerFactory.class); + + private Map> handlerClassByQueryNameMap = new HashMap<>(); + private Map> handlerClassByCommandNameMap = new HashMap<>(); + + public AutoScanHandlerFactory() {} + + public void startScanningHandler() { + try { + scanHandlers(); + } catch (Exception ex) { + log.error("Error while scanning packages for query handlers", ex); + } + } + + private void scanAndRegisterHandler(String packageToScan) { + log.info("Scanning query & command handlers in the package: " + packageToScan); + Reflections reflections = new Reflections(packageToScan); + Set> queryClasses = reflections.getSubTypesOf(QueryHandler.class); + Set> commandClasses = reflections.getSubTypesOf(CommandHandler.class); + + queryClasses.forEach(queryClass -> { + QueryMapping mappingAnnotation = queryClass.getAnnotation(QueryMapping.class); + if (mappingAnnotation != null) { + log.info(String.format("Registering handler %s to handle the query %s", + queryClass.getSimpleName(), mappingAnnotation.value().getName())); + + handlerClassByQueryNameMap.put(mappingAnnotation.value().getName(), queryClass); + } + }); + + commandClasses.forEach(commandClass -> { + CommandMapping mappingAnnotation = commandClass.getAnnotation(CommandMapping.class); + if (mappingAnnotation != null) { + log.info(String.format("Registering handler %s to handle the command %s", + commandClass.getSimpleName(), mappingAnnotation.value().getName())); + + handlerClassByCommandNameMap.put(mappingAnnotation.value().getName(), commandClass); + } + }); + } + + @Override + public QueryHandler, R> createQueryHandler(String queryName) { + Class handlerClass = handlerClassByQueryNameMap.get(queryName); + if (handlerClass == null) { + return null; + } + + return QueryHandler.class.cast(getBeanFactory().apply(handlerClass)); + } + + @Override + public CommandHandler, R> createCommandHandler(String commandName) { + Class handlerClass = handlerClassByCommandNameMap.get(commandName); + if (handlerClass == null) { + return null; + } + + return CommandHandler.class.cast(getBeanFactory().apply(handlerClass)); + } + + protected abstract Function getBeanFactory(); + + protected abstract Set getPackagesToScanConfig(); + + private void scanHandlers() { + // Get packages to scan via annotation + Set packagesToScan = getPackagesToScanConfig(); + + if (packagesToScan.isEmpty()) { + log.warn("No packages to scan for query handlers. Please put the packages to scan in @ComponentScan annotation of SpringBootApplication class."); + } + packagesToScan.forEach(packageToScan -> { + log.info("Scanning query handler in the package " + packageToScan); + scanAndRegisterHandler(packageToScan); + }); + } +} diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java index 2648453..93c1a41 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java @@ -1,6 +1,8 @@ package net.dathoang.cqrs.commandbus.command; import java.util.List; + +import net.dathoang.cqrs.commandbus.exceptions.NoHandlerFoundException; import net.dathoang.cqrs.commandbus.message.Message; import net.dathoang.cqrs.commandbus.message.MessageBus; import net.dathoang.cqrs.commandbus.message.MessageBusFactory; @@ -11,7 +13,7 @@ public final class DefaultCommandBus implements CommandBus { private final MessageBus defaultMessageBus; - DefaultCommandBus(CommandHandlerFactory commandHandlerFactory, + public DefaultCommandBus(CommandHandlerFactory commandHandlerFactory, List middlewareList) { this.defaultMessageBus = MessageBusFactory.create( new MessageHandlerFactoryAdapter(commandHandlerFactory), middlewareList @@ -23,7 +25,6 @@ public R dispatch(Command command) throws Exception { return defaultMessageBus.dispatch(command); } - // region adapter classes static class MessageHandlerFactoryAdapter implements MessageHandlerFactory { private final CommandHandlerFactory commandHandlerFactory; @@ -34,9 +35,12 @@ public MessageHandlerFactoryAdapter(CommandHandlerFactory commandHandlerFactory) @Override public MessageHandler, R> createHandler(String messageName) { - return new MessageHandlerAdapter<>( - commandHandlerFactory.createCommandHandler(messageName) - ); + CommandHandler handler = commandHandlerFactory.createCommandHandler(messageName); + if (handler == null) { + throw new NoHandlerFoundException(messageName); + } + + return new MessageHandlerAdapter<>(handler); } } @@ -54,5 +58,4 @@ public R handle(M message) throws Exception { return commandHandler.handle((Command)message); } } - // endregion } diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java index 22ab24e..fdddfcb 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/exceptions/NoHandlerFoundException.java @@ -6,4 +6,8 @@ public class NoHandlerFoundException extends CommandBusException { public NoHandlerFoundException(Class messageClass) { super(String.format("No handler found for %s", messageClass.getName())); } + + public NoHandlerFoundException(String messageClassName) { + super(String.format("No handler found for %s", messageClassName)); + } } diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java index 80d2eac..f416cb5 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java @@ -1,6 +1,8 @@ package net.dathoang.cqrs.commandbus.query; import java.util.List; + +import net.dathoang.cqrs.commandbus.exceptions.NoHandlerFoundException; import net.dathoang.cqrs.commandbus.message.Message; import net.dathoang.cqrs.commandbus.message.MessageBus; import net.dathoang.cqrs.commandbus.message.MessageBusFactory; @@ -12,7 +14,7 @@ public final class DefaultQueryBus implements QueryBus { private final MessageBus defaultMessageBus; - DefaultQueryBus(QueryHandlerFactory queryHandlerFactory, List middlewareList) { + public DefaultQueryBus(QueryHandlerFactory queryHandlerFactory, List middlewareList) { defaultMessageBus = MessageBusFactory.create( new QueryHandlerFactoryToMessageHandlerFactoryAdapter(queryHandlerFactory), middlewareList @@ -36,9 +38,12 @@ public QueryHandlerFactoryToMessageHandlerFactoryAdapter( @Override public MessageHandler, R> createHandler(String messageName) { - return new QueryHandlerToMessageHandlerAdapter<>( - queryHandlerFactory.createQueryHandler(messageName) - ); + QueryHandler queryHandler = queryHandlerFactory.createQueryHandler(messageName); + if (queryHandler == null) { + throw new NoHandlerFoundException(messageName); + } + + return new QueryHandlerToMessageHandlerAdapter<>(queryHandler); } } diff --git a/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/CommandMapping.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/CommandMapping.java new file mode 100644 index 0000000..39191f3 --- /dev/null +++ b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/CommandMapping.java @@ -0,0 +1,12 @@ +package net.dathoang.cqrs.commandbus.autoscan; + +import net.dathoang.cqrs.commandbus.command.Command; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CommandMapping { + Class value(); +} diff --git a/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/HandlerScan.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/HandlerScan.java new file mode 100644 index 0000000..ed7e80a --- /dev/null +++ b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/HandlerScan.java @@ -0,0 +1,9 @@ +package net.dathoang.cqrs.commandbus.autoscan; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface HandlerScan { + String[] basePackages() default {}; +} diff --git a/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/QueryMapping.java b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/QueryMapping.java new file mode 100644 index 0000000..ea07e2b --- /dev/null +++ b/commandbus-spec/src/main/java/net/dathoang/cqrs/commandbus/autoscan/QueryMapping.java @@ -0,0 +1,11 @@ +package net.dathoang.cqrs.commandbus.autoscan; + +import net.dathoang.cqrs.commandbus.query.Query; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface QueryMapping { + Class value(); +} diff --git a/commandbus-spring/build.gradle b/commandbus-spring/build.gradle new file mode 100644 index 0000000..d6ef7c9 --- /dev/null +++ b/commandbus-spring/build.gradle @@ -0,0 +1,23 @@ +plugins { + id 'java' +} + +version 'unspecified' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + implementation project(':commandbus-spec') + implementation project(':commandbus-core') + implementation project(':commandbus-basic-middleware') + + implementation 'org.reflections:reflections:0.9.11' + + compile group: 'org.springframework', name: 'spring-context', version: '5.1.8.RELEASE' + + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java new file mode 100644 index 0000000..dc48ca9 --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java @@ -0,0 +1,74 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.command.CommandBus; +import net.dathoang.cqrs.commandbus.command.DefaultCommandBus; +import net.dathoang.cqrs.commandbus.query.DefaultQueryBus; +import net.dathoang.cqrs.commandbus.query.QueryBus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; + +@Configuration +public class CommandBusSpringConfiguration { + private final Log log = LogFactory.getLog(CommandBusSpringConfiguration.class); + + private ApplicationContext applicationContext; + + @Autowired + public CommandBusSpringConfiguration(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Bean + public CommandBus getCommandBus() { + return new DefaultCommandBus( + findHandlerFactoryConfig().getCommandHandlerFactory(), + findMiddlewareConfig().getQueryMiddlewarePipeline() + ); + } + + @Bean + public QueryBus getQueryBus() { + return new DefaultQueryBus( + findHandlerFactoryConfig().getQueryhandlerFactory(), + findMiddlewareConfig().getQueryMiddlewarePipeline() + ); + } + + private HandlerFactoryConfig findHandlerFactoryConfig() { + HandlerFactoryConfig scannedHandlerFactoryConfig = scanHandlerFactoryConfig(); + if (scannedHandlerFactoryConfig != null) { + return scannedHandlerFactoryConfig; + } + + log.info("Custom @Configuration-annotated HandlerFactoryConfig not found, using DefaultHandlerFactoryConfig"); + return new DefaultHandlerFactoryConfig(applicationContext); + } + + private MiddlewareConfig findMiddlewareConfig() { + MiddlewareConfig scannedMiddlewareConfig = scanMiddlewareConfig(); + if (scannedMiddlewareConfig != null) { + return scannedMiddlewareConfig; + } + + log.info("Custom @Configuration-annotated MiddlewareConfig not found, using DefaultMiddlewareConfig"); + return new DefaultMiddlewareConfig(); + } + + private HandlerFactoryConfig scanHandlerFactoryConfig() { + // TODO: Implement + + return null; + } + + private MiddlewareConfig scanMiddlewareConfig() { + // TODO: Implement + + return null; + } +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultHandlerFactoryConfig.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultHandlerFactoryConfig.java new file mode 100644 index 0000000..f25aae2 --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultHandlerFactoryConfig.java @@ -0,0 +1,23 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.command.CommandHandlerFactory; +import net.dathoang.cqrs.commandbus.query.QueryHandlerFactory; +import org.springframework.context.ApplicationContext; + +public class DefaultHandlerFactoryConfig implements HandlerFactoryConfig { + private SpringAutoScanHandlerFactory springAutoScanHandlerFactory; + + public DefaultHandlerFactoryConfig(ApplicationContext context) { + this.springAutoScanHandlerFactory = new SpringAutoScanHandlerFactory(context); + } + + @Override + public CommandHandlerFactory getCommandHandlerFactory() { + return springAutoScanHandlerFactory; + } + + @Override + public QueryHandlerFactory getQueryhandlerFactory() { + return springAutoScanHandlerFactory; + } +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultMiddlewareConfig.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultMiddlewareConfig.java new file mode 100644 index 0000000..129b958 --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/DefaultMiddlewareConfig.java @@ -0,0 +1,24 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.middleware.Middleware; +import net.dathoang.cqrs.commandbus.middleware.logging.LoggingMiddleware; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class DefaultMiddlewareConfig implements MiddlewareConfig { + @Override + public List getCommandMiddlewarePipeline() { + return Collections.singletonList( + new LoggingMiddleware() + ); + } + + @Override + public List getQueryMiddlewarePipeline() { + return Collections.singletonList( + new LoggingMiddleware() + ); + } +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/HandlerFactoryConfig.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/HandlerFactoryConfig.java new file mode 100644 index 0000000..fd1d86a --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/HandlerFactoryConfig.java @@ -0,0 +1,9 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.command.CommandHandlerFactory; +import net.dathoang.cqrs.commandbus.query.QueryHandlerFactory; + +public interface HandlerFactoryConfig { + CommandHandlerFactory getCommandHandlerFactory(); + QueryHandlerFactory getQueryhandlerFactory(); +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/MiddlewareConfig.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/MiddlewareConfig.java new file mode 100644 index 0000000..a1a5596 --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/MiddlewareConfig.java @@ -0,0 +1,10 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.middleware.Middleware; + +import java.util.List; + +public interface MiddlewareConfig { + List getCommandMiddlewarePipeline(); + List getQueryMiddlewarePipeline(); +} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java new file mode 100644 index 0000000..ec5d76f --- /dev/null +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java @@ -0,0 +1,42 @@ +package net.dathoang.cqrs.commandbus.spring; + +import net.dathoang.cqrs.commandbus.autoscan.AutoScanHandlerFactory; +import net.dathoang.cqrs.commandbus.autoscan.HandlerScan; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.context.ApplicationContext; + +import java.util.*; +import java.util.function.Function; + +public class SpringAutoScanHandlerFactory extends AutoScanHandlerFactory { + + private final ApplicationContext context; + + public SpringAutoScanHandlerFactory(ApplicationContext context) { + this.context = context; + + this.startScanningHandler(); + } + + @Override + protected Function getBeanFactory() { + return (cls) -> { + context.getAutowireCapableBeanFactory().autowireBean(cls); + return context.getAutowireCapableBeanFactory().createBean(cls); + }; + } + + @Override + protected Set getPackagesToScanConfig() { + Set packagesToScan = new HashSet<>(); + Map springApplicationInstances = context.getBeansWithAnnotation(HandlerScan.class); + for (Object appInstance : springApplicationInstances.values()) { + HandlerScan scanAnnotation = appInstance.getClass().getAnnotation(HandlerScan.class); + if (scanAnnotation != null) { + packagesToScan.addAll(Arrays.asList(scanAnnotation.basePackages())); + } + } + return packagesToScan; + } +} diff --git a/settings.gradle b/settings.gradle index 98ae1d9..2a65f15 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,4 +11,5 @@ rootProject.name = 'java-cqrs-commandbus' include 'commandbus-core' include 'commandbus-basic-middleware' include 'commandbus-spec' +include 'commandbus-spring' From dc30685e8adb6b2f54cca3063fef8ad1a866291b Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:08:21 +0700 Subject: [PATCH 12/22] Remove MessageBusFactory, QueryBusFactory, CommandBusFactory --- .../autoscan/AutoScanHandlerFactory.java | 3 ++ .../commandbus/command/CommandBusFactory.java | 11 ------ .../commandbus/command/DefaultCommandBus.java | 9 ++--- .../commandbus/message/DefaultMessageBus.java | 2 +- .../commandbus/message/MessageBusFactory.java | 11 ------ .../commandbus/query/DefaultQueryBus.java | 9 ++--- .../commandbus/query/QueryBusFactory.java | 11 ------ .../command/CommandBusFactoryTest.java | 36 ------------------- .../commandbus/query/QueryBusFactoryTest.java | 35 ------------------ .../spring/SpringAutoScanHandlerFactory.java | 1 + 10 files changed, 11 insertions(+), 117 deletions(-) delete mode 100644 commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java delete mode 100644 commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java delete mode 100644 commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java delete mode 100644 commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java delete mode 100644 commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java index 99909ef..ad47dcc 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/autoscan/AutoScanHandlerFactory.java @@ -56,6 +56,7 @@ private void scanAndRegisterHandler(String packageToScan) { }); } + @SuppressWarnings("unchecked") @Override public QueryHandler, R> createQueryHandler(String queryName) { Class handlerClass = handlerClassByQueryNameMap.get(queryName); @@ -66,6 +67,8 @@ public QueryHandler, R> createQueryHandler(String queryName) { return QueryHandler.class.cast(getBeanFactory().apply(handlerClass)); } + + @SuppressWarnings("unchecked") @Override public CommandHandler, R> createCommandHandler(String commandName) { Class handlerClass = handlerClassByCommandNameMap.get(commandName); diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java deleted file mode 100644 index d719b1e..0000000 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/CommandBusFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.dathoang.cqrs.commandbus.command; - -import java.util.List; -import net.dathoang.cqrs.commandbus.middleware.Middleware; - -public class CommandBusFactory { - public static CommandBus create(CommandHandlerFactory commandHandlerFactory, - List middlewareList) { - return new DefaultCommandBus(commandHandlerFactory, middlewareList); - } -} diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java index 93c1a41..7441785 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/command/DefaultCommandBus.java @@ -3,11 +3,7 @@ import java.util.List; import net.dathoang.cqrs.commandbus.exceptions.NoHandlerFoundException; -import net.dathoang.cqrs.commandbus.message.Message; -import net.dathoang.cqrs.commandbus.message.MessageBus; -import net.dathoang.cqrs.commandbus.message.MessageBusFactory; -import net.dathoang.cqrs.commandbus.message.MessageHandler; -import net.dathoang.cqrs.commandbus.message.MessageHandlerFactory; +import net.dathoang.cqrs.commandbus.message.*; import net.dathoang.cqrs.commandbus.middleware.Middleware; public final class DefaultCommandBus implements CommandBus { @@ -15,7 +11,7 @@ public final class DefaultCommandBus implements CommandBus { public DefaultCommandBus(CommandHandlerFactory commandHandlerFactory, List middlewareList) { - this.defaultMessageBus = MessageBusFactory.create( + this.defaultMessageBus = new DefaultMessageBus( new MessageHandlerFactoryAdapter(commandHandlerFactory), middlewareList ); } @@ -33,6 +29,7 @@ public MessageHandlerFactoryAdapter(CommandHandlerFactory commandHandlerFactory) this.commandHandlerFactory = commandHandlerFactory; } + @SuppressWarnings("unchecked") @Override public MessageHandler, R> createHandler(String messageName) { CommandHandler handler = commandHandlerFactory.createCommandHandler(messageName); diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java index 359dae8..dae3d24 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/DefaultMessageBus.java @@ -21,7 +21,7 @@ public final class DefaultMessageBus implements MessageBus { private final List middlewarePipeline; private MessageHandlerFactory messageHandlerFactory; - DefaultMessageBus(MessageHandlerFactory handlerFactory, List middlewareList) { + public DefaultMessageBus(MessageHandlerFactory handlerFactory, List middlewareList) { messageHandlerFactory = handlerFactory; middlewarePipeline = new ArrayList<>(middlewareList); } diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java deleted file mode 100644 index 6ce1ead..0000000 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/message/MessageBusFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.dathoang.cqrs.commandbus.message; - -import java.util.List; -import net.dathoang.cqrs.commandbus.middleware.Middleware; - -public class MessageBusFactory { - public static MessageBus create(MessageHandlerFactory messageHandlerFactory, - List middlewareList) { - return new DefaultMessageBus(messageHandlerFactory, middlewareList); - } -} diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java index f416cb5..846566b 100644 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java +++ b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/DefaultQueryBus.java @@ -3,11 +3,7 @@ import java.util.List; import net.dathoang.cqrs.commandbus.exceptions.NoHandlerFoundException; -import net.dathoang.cqrs.commandbus.message.Message; -import net.dathoang.cqrs.commandbus.message.MessageBus; -import net.dathoang.cqrs.commandbus.message.MessageBusFactory; -import net.dathoang.cqrs.commandbus.message.MessageHandler; -import net.dathoang.cqrs.commandbus.message.MessageHandlerFactory; +import net.dathoang.cqrs.commandbus.message.*; import net.dathoang.cqrs.commandbus.middleware.Middleware; public final class DefaultQueryBus implements QueryBus { @@ -15,7 +11,7 @@ public final class DefaultQueryBus implements QueryBus { private final MessageBus defaultMessageBus; public DefaultQueryBus(QueryHandlerFactory queryHandlerFactory, List middlewareList) { - defaultMessageBus = MessageBusFactory.create( + defaultMessageBus = new DefaultMessageBus( new QueryHandlerFactoryToMessageHandlerFactoryAdapter(queryHandlerFactory), middlewareList ); @@ -36,6 +32,7 @@ public QueryHandlerFactoryToMessageHandlerFactoryAdapter( this.queryHandlerFactory = queryHandlerFactory; } + @SuppressWarnings("unchecked") @Override public MessageHandler, R> createHandler(String messageName) { QueryHandler queryHandler = queryHandlerFactory.createQueryHandler(messageName); diff --git a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java b/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java deleted file mode 100644 index 0d2cb51..0000000 --- a/commandbus-core/src/main/java/net/dathoang/cqrs/commandbus/query/QueryBusFactory.java +++ /dev/null @@ -1,11 +0,0 @@ -package net.dathoang.cqrs.commandbus.query; - -import java.util.List; -import net.dathoang.cqrs.commandbus.middleware.Middleware; - -public class QueryBusFactory { - public static QueryBus create(QueryHandlerFactory queryHandlerFactory, - List middlewareList) { - return new DefaultQueryBus(queryHandlerFactory, middlewareList); - } -} diff --git a/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java deleted file mode 100644 index ac413d7..0000000 --- a/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/command/CommandBusFactoryTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.dathoang.cqrs.commandbus.command; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; - -import java.util.Collections; -import java.util.List; -import net.dathoang.cqrs.commandbus.middleware.Middleware; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -class CommandBusFactoryTest { - @Nested - @DisplayName("create()") - static class CreateTest { - @Test - @DisplayName("should create DefaultCommandBus instance successfully") - void shouldCreateDefaultCommandBusInstanceSuccessfully() { - // Arrange - CommandHandlerFactory commandHandlerFactory = mock(CommandHandlerFactory.class); - List middlewareList = singletonList(mock(Middleware.class)); - - // Act - CommandBus commandBus = CommandBusFactory.create(commandHandlerFactory, middlewareList); - - // Assert - assertThat(commandBus) - .isNotNull() - .isInstanceOf(DefaultCommandBus.class); - } - } -} diff --git a/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java b/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java deleted file mode 100644 index 55ef2c4..0000000 --- a/commandbus-core/src/test/java/net/dathoang/cqrs/commandbus/query/QueryBusFactoryTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.dathoang.cqrs.commandbus.query; - -import static java.util.Collections.singletonList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.mock; - -import java.util.Collections; -import java.util.List; -import net.dathoang.cqrs.commandbus.middleware.Middleware; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - -class QueryBusFactoryTest { - @Nested - @DisplayName("create()") - static class CreateTest { - @Test - @DisplayName("should create DefaultQueryBus instance successfully") - void shouldCreateDefaultQueryBusInstanceSuccessfully() { - // Arrange - QueryHandlerFactory queryHandlerFactory = mock(QueryHandlerFactory.class); - List middlewareList = singletonList(mock(Middleware.class)); - - // Act - QueryBus queryBus = QueryBusFactory.create(queryHandlerFactory, middlewareList); - - // Assert - assertThat(queryBus) - .isNotNull() - .isInstanceOf(DefaultQueryBus.class); - } - } -} diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java index ec5d76f..5c5339b 100644 --- a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/SpringAutoScanHandlerFactory.java @@ -19,6 +19,7 @@ public SpringAutoScanHandlerFactory(ApplicationContext context) { this.startScanningHandler(); } + @SuppressWarnings("unchecked") @Override protected Function getBeanFactory() { return (cls) -> { From afd5f760eb1a67698badbf636b765d2b654c10b7 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:08:52 +0700 Subject: [PATCH 13/22] Handle scanning for custom HandlerFactoryConfig & MiddlewareConfig --- .../spring/CommandBusSpringConfiguration.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java index dc48ca9..1088625 100644 --- a/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java +++ b/commandbus-spring/src/main/java/net/dathoang/cqrs/commandbus/spring/CommandBusSpringConfiguration.java @@ -61,14 +61,16 @@ private MiddlewareConfig findMiddlewareConfig() { } private HandlerFactoryConfig scanHandlerFactoryConfig() { - // TODO: Implement - - return null; + return (HandlerFactoryConfig) applicationContext.getBeansWithAnnotation(Configuration.class).values().stream() + .filter(c -> c instanceof HandlerFactoryConfig) + .findFirst() + .orElse(null); } private MiddlewareConfig scanMiddlewareConfig() { - // TODO: Implement - - return null; + return (MiddlewareConfig) applicationContext.getBeansWithAnnotation(Configuration.class).values().stream() + .filter(c -> c instanceof MiddlewareConfig) + .findFirst() + .orElse(null); } } From fd4634a8f3b618eae92d8556d2a8c7637a3e114a Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:09:19 +0700 Subject: [PATCH 14/22] Switch to openjdk8 in travis ci script --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bb8586b..a01084c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: java install: true jdk: - - oraclejdk8 + - openjdk8 stages: - analyze From 973247d70f38ab82f031a70962adc551b3a07c57 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 14:25:12 +0700 Subject: [PATCH 15/22] Add quick-start artifacts (modules) --- commandbus-core-full/build.gradle | 19 +++++++++++++++++++ commandbus-spring-full/build.gradle | 20 ++++++++++++++++++++ settings.gradle | 2 ++ 3 files changed, 41 insertions(+) create mode 100644 commandbus-core-full/build.gradle create mode 100644 commandbus-spring-full/build.gradle diff --git a/commandbus-core-full/build.gradle b/commandbus-core-full/build.gradle new file mode 100644 index 0000000..c12e1ca --- /dev/null +++ b/commandbus-core-full/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'java' +} + +version 'unspecified' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + compile project(':commandbus-spec') + compile project(':commandbus-core') + compile project(':commandbus-basic-middleware') + + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/commandbus-spring-full/build.gradle b/commandbus-spring-full/build.gradle new file mode 100644 index 0000000..e5d8768 --- /dev/null +++ b/commandbus-spring-full/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'java' +} + +version 'unspecified' + +sourceCompatibility = 1.8 + +repositories { + mavenCentral() +} + +dependencies { + compile project(':commandbus-spec') + compile project(':commandbus-core') + compile project(':commandbus-basic-middleware') + compile project(':commandbus-spring') + + testCompile group: 'junit', name: 'junit', version: '4.12' +} diff --git a/settings.gradle b/settings.gradle index 2a65f15..d5750e8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,6 @@ include 'commandbus-core' include 'commandbus-basic-middleware' include 'commandbus-spec' include 'commandbus-spring' +include 'commandbus-core-full' +include 'commandbus-spring-full' From 47dc068e647a42f1e6f03c40d141f04c09ce24d3 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 15:45:43 +0700 Subject: [PATCH 16/22] Update publish scripts --- .travis.yml | 14 ++++++++++++-- build.gradle | 5 ----- commandbus-basic-middleware/build.gradle | 8 ++++++++ commandbus-core-full/build.gradle | 8 ++++++++ commandbus-core/build.gradle | 2 +- commandbus-spec/build.gradle | 8 ++++++++ commandbus-spring-full/build.gradle | 8 ++++++++ commandbus-spring/build.gradle | 8 ++++++++ 8 files changed, 53 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index a01084c..f58a992 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,7 +35,12 @@ jobs: if: tag =~ ^v script: - ./prepare_before_publish - - ./gradlew core:publish + - ./gradlew commandbus-spec:publish + - ./gradlew commandbus-core:publish + - ./gradlew commandbus-basic-middleware:publish + - ./gradlew commandbus-core-full:publish + - ./gradlew commandbus-spring:publish + - ./gradlew commandbus-spring-full:publish - ./cleanup_after_publish - stage: release @@ -43,5 +48,10 @@ jobs: if: branch =~ ^(develop|hotfix|release).* script: - ./prepare_before_publish - - ./gradlew core:publish -PSNAPSHOT=true + - ./gradlew commandbus-spec:publish -PSNAPSHOT=true + - ./gradlew commandbus-core:publish -PSNAPSHOT=true + - ./gradlew commandbus-basic-middleware:publish -PSNAPSHOT=true + - ./gradlew commandbus-core-full:publish -PSNAPSHOT=true + - ./gradlew commandbus-spring:publish -PSNAPSHOT=true + - ./gradlew commandbus-spring-full:publish -PSNAPSHOT=true - ./cleanup_after_publish \ No newline at end of file diff --git a/build.gradle b/build.gradle index c858509..a9c0bce 100644 --- a/build.gradle +++ b/build.gradle @@ -15,11 +15,6 @@ repositories { jcenter() } -dependencies { - compile project(':commandbus-core') - compile project(':commandbus-basic-middleware') -} - allprojects { apply plugin: 'jacoco' apply plugin: 'checkstyle' diff --git a/commandbus-basic-middleware/build.gradle b/commandbus-basic-middleware/build.gradle index b3c432c..7670fbf 100644 --- a/commandbus-basic-middleware/build.gradle +++ b/commandbus-basic-middleware/build.gradle @@ -46,3 +46,11 @@ jacocoTestReport { html.enabled false } } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId 'commandbus-basic-middleware' + } + } +} diff --git a/commandbus-core-full/build.gradle b/commandbus-core-full/build.gradle index c12e1ca..9c00afa 100644 --- a/commandbus-core-full/build.gradle +++ b/commandbus-core-full/build.gradle @@ -17,3 +17,11 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId 'commandbus-core-full' + } + } +} diff --git a/commandbus-core/build.gradle b/commandbus-core/build.gradle index 11826dd..59e6175 100644 --- a/commandbus-core/build.gradle +++ b/commandbus-core/build.gradle @@ -50,7 +50,7 @@ jacocoTestReport { publishing { publications { mavenJava(MavenPublication) { - artifactId 'core' + artifactId 'commandbus-core' } } } diff --git a/commandbus-spec/build.gradle b/commandbus-spec/build.gradle index 0081910..8a1f31f 100644 --- a/commandbus-spec/build.gradle +++ b/commandbus-spec/build.gradle @@ -13,3 +13,11 @@ repositories { dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId 'commandbus-spec' + } + } +} diff --git a/commandbus-spring-full/build.gradle b/commandbus-spring-full/build.gradle index e5d8768..3f19027 100644 --- a/commandbus-spring-full/build.gradle +++ b/commandbus-spring-full/build.gradle @@ -18,3 +18,11 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId 'commandbus-spring-full' + } + } +} diff --git a/commandbus-spring/build.gradle b/commandbus-spring/build.gradle index d6ef7c9..5ac073a 100644 --- a/commandbus-spring/build.gradle +++ b/commandbus-spring/build.gradle @@ -21,3 +21,11 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId 'commandbus-spring' + } + } +} From b60b1be8266d796fe1712fde34c5bb8dd88aa3a5 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 16:11:55 +0700 Subject: [PATCH 17/22] Copy secret_ring to sub modules --- cleanup_after_publish | 3 ++- prepare_before_publish | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cleanup_after_publish b/cleanup_after_publish index 7451241..ffbd628 100755 --- a/cleanup_after_publish +++ b/cleanup_after_publish @@ -1,3 +1,4 @@ #!/bin/bash -rm -f core/.secret_ring \ No newline at end of file +rm -f .secret_ring +rm -f */.secret_ring \ No newline at end of file diff --git a/prepare_before_publish b/prepare_before_publish index 488b372..d98fa9d 100755 --- a/prepare_before_publish +++ b/prepare_before_publish @@ -1,3 +1,9 @@ #!/bin/bash -echo $CQRS_COMMANDBUS_GPG_SECRET_RING_BASE64 | base64 --decode > core/.secret_ring \ No newline at end of file +echo $CQRS_COMMANDBUS_GPG_SECRET_RING_BASE64 | base64 --decode > .secret_ring +cp .secret_ring commandbus-spec/ +cp .secret_ring commandbus-core/ +cp .secret_ring commandbus-basic-middleware/ +cp .secret_ring commandbus-core-full/ +cp .secret_ring commandbus-spring/ +cp .secret_ring commandbus-spring-full/ \ No newline at end of file From 0a98c334a85b2d59f32b961dfa845902698faf0d Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 17:28:53 +0700 Subject: [PATCH 18/22] Update README --- README.md | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5d634c6..758bdf0 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,43 @@ # Java CQRS CommandBus -[![Build Status](https://travis-ci.com/dathoangse/java-cqrs-commandbus.svg?branch=develop)](https://travis-ci.com/dathoangse/java-cqrs) -[![codecov](https://codecov.io/gh/dathoangse/java-cqrs/branch/develop/graph/badge.svg)](https://codecov.io/gh/dathoangse/java-cqrs) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.dathoang.cqrs.commandbus/core/badge.svg)](https://mvnrepository.com/artifact/net.dathoang.cqrs.commandbus/core) +[![Build Status](https://travis-ci.com/dathoangse/java-cqrs-commandbus.svg?branch=develop)](/https://travis-ci.com/dathoangse/java-cqrs-commandbus/) +[![codecov](https://codecov.io/gh/dathoangse/java-cqrs-commandbus/branch/develop/graph/badge.svg)](/https://codecov.io/gh/dathoangse/java-cqrs-commandbus/) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.dathoang.cqrs.commandbus/core/badge.svg)](/https://mvnrepository.com/artifact/net.dathoang.cqrs.commandbus/core/) A lightweight & highly extensible CQRS framework for implementing application layer and CQRS architectural pattern in Java. ## Who uses Java CQRS CommandBus -* [YouthDev](https://youthdev.net/en/) +* [YouthDev](/https://youthdev.net/en//) ## Code style -The project follows [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) for code style & convention. +The project follows [Google Java Style Guide](/https://google.github.io/styleguide/javaguide.html/) for code style & convention. ## Git workflow -The project uses [Git flow](https://nvie.com/posts/a-successful-git-branching-model/) for git workflow. +The project uses [Git flow](/https://nvie.com/posts/a-successful-git-branching-model//) for git workflow. ## Versioning -The project uses [Semantic Versioning 2.0.0 | Semantic Versioning](https://semver.org/) for versioning releases. +The project uses [Semantic Versioning 2.0.0 | Semantic Versioning](/https://semver.org//) for versioning releases. -## Libs/frameworks used -* [JUnit 5](https://junit.org/junit5/) for unit testing. -* [AssertJ](http://joel-costigliola.github.io/assertj/) for assertions in unit test. -* [Mockito](https://github.com/mockito/mockito) for mocking in unit test. -* [Apache Commons Logging](https://commons.apache.org/proper/commons-logging/) as logging interface. +/## Libs/frameworks used/ +* [JUnit 5](/https://junit.org/junit5//) for unit testing. +* [AssertJ](/http://joel-costigliola.github.io/assertj//) for assertions in unit test. +* [Mockito](/https://github.com/mockito/mockito/) for mocking in unit test. +* [Apache Commons Logging](/https://commons.apache.org/proper/commons-logging//) as logging interface. Built with: -* [Gradle Build Tool](https://gradle.org/). +* [Gradle Build Tool](/https://gradle.org//). -# Features -`Java CQRS CommandBus` is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: -1. `Lightweight`: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library's implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it's possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. -2. `Highly extensible`: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. +## Features +*Java CQRS CommandBus* is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: +* *Lightweight*: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library’s implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it’s possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. +* *Highly extensible*: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. + +## Benefits of using Command Bus +Command Bus pattern (a.k.a Command Dispatcher Pattern) help to: +* *Decouple architecture from framework*: Good architecture does not depend on framework, it also does not depends on how the system is used (Our architecture should be the same whether we’re building a Restful API, WebSocket, TCP-socket or CLI applications.). By modeling all the interactions (business use-case) via Commands, application layer (or service layer) no longer need to depend on framework, and it also doesn’t depend on the protocol which was used to communicate with the system. +* *Make the architecture scream*: Good architecture is the screaming architecture, which means we can easily know the system use-cases just by looking at the architecture. By presenting all the business user-case/intent and user interaction (with the system) via Command, we can quickly understand what the system can do just by looking at all the Commands available in the system, thus all the Commands have already screamed about the system use-cases. +* *Unified communication interface*: With Command Bus pattern, the communication interface of application layer (service layer) is unified into only one method: the `dispatch()` method of Command Bus. This simplified interface will help to increase maintainability. +* *Handle application layer (service layer) cross-cutting concerns in one place*: Because all the interactions to the system go through the `dispatch()` method of Command Bus, we can easily handle all the application layer (service layer) cross-cutting concerns like: logging, audit-logging, auto-restarting transaction (ex: restart on database deadlock exception), rate-limiting. Because of this, the `middleware pipeline` feature of `Java CQRS CommandBus` will help you to easily add middleware to handle cross-cutting concerns easily, as well as to extend functionalities. +* *Built-in natural audit-log*: Because all the interactions to the system are modeled as Command (which represent business use-case/intent), the Command naturally represent system audit-log. By adding a middleware to log succeeded command, it naturally becomes the audit-log of the system. ## Integrate into your project @@ -62,4 +70,5 @@ Before creating pull request, please make sure: * There is 100% code coverage on all new codes. ## License -Java CQRS CommandBus is an Open Source Software released under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) +Java CQRS CommandBus is an Open Source Software released under the [Apache License 2.0](/https://www.apache.org/licenses/LICENSE-2.0.html/) + From 41ed117b176814bd5b94f1be9cc1696f80888ee9 Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 17:34:00 +0700 Subject: [PATCH 19/22] Update README --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 758bdf0..4f7bcbe 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,17 @@ Built with: * [Gradle Build Tool](/https://gradle.org//). ## Features -*Java CQRS CommandBus* is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: -* *Lightweight*: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library’s implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it’s possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. -* *Highly extensible*: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. +**Java CQRS CommandBus** is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: +* **Lightweight**: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library’s implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it’s possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. +* **Highly extensible**: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. ## Benefits of using Command Bus Command Bus pattern (a.k.a Command Dispatcher Pattern) help to: -* *Decouple architecture from framework*: Good architecture does not depend on framework, it also does not depends on how the system is used (Our architecture should be the same whether we’re building a Restful API, WebSocket, TCP-socket or CLI applications.). By modeling all the interactions (business use-case) via Commands, application layer (or service layer) no longer need to depend on framework, and it also doesn’t depend on the protocol which was used to communicate with the system. -* *Make the architecture scream*: Good architecture is the screaming architecture, which means we can easily know the system use-cases just by looking at the architecture. By presenting all the business user-case/intent and user interaction (with the system) via Command, we can quickly understand what the system can do just by looking at all the Commands available in the system, thus all the Commands have already screamed about the system use-cases. -* *Unified communication interface*: With Command Bus pattern, the communication interface of application layer (service layer) is unified into only one method: the `dispatch()` method of Command Bus. This simplified interface will help to increase maintainability. -* *Handle application layer (service layer) cross-cutting concerns in one place*: Because all the interactions to the system go through the `dispatch()` method of Command Bus, we can easily handle all the application layer (service layer) cross-cutting concerns like: logging, audit-logging, auto-restarting transaction (ex: restart on database deadlock exception), rate-limiting. Because of this, the `middleware pipeline` feature of `Java CQRS CommandBus` will help you to easily add middleware to handle cross-cutting concerns easily, as well as to extend functionalities. -* *Built-in natural audit-log*: Because all the interactions to the system are modeled as Command (which represent business use-case/intent), the Command naturally represent system audit-log. By adding a middleware to log succeeded command, it naturally becomes the audit-log of the system. +* **Decouple architecture from framework**: Good architecture does not depend on framework, it also does not depends on how the system is used (Our architecture should be the same whether we’re building a Restful API, WebSocket, TCP-socket or CLI applications.). By modeling all the interactions (business use-case) via Commands, application layer (or service layer) no longer need to depend on framework, and it also doesn’t depend on the protocol which was used to communicate with the system. +* **Make the architecture scream**: Good architecture is the screaming architecture, which means we can easily know the system use-cases just by looking at the architecture. By presenting all the business user-case/intent and user interaction (with the system) via Command, we can quickly understand what the system can do just by looking at all the Commands available in the system, thus all the Commands have already screamed about the system use-cases. +* **Unified communication interface**: With Command Bus pattern, the communication interface of application layer (service layer) is unified into only one method: the `dispatch()` method of Command Bus. This simplified interface will help to increase maintainability. +* **Handle application layer (service layer) cross-cutting concerns in one place**: Because all the interactions to the system go through the `dispatch()` method of Command Bus, we can easily handle all the application layer (service layer) cross-cutting concerns like: logging, audit-logging, auto-restarting transaction (ex: restart on database deadlock exception), rate-limiting. Because of this, the `middleware pipeline` feature of `Java CQRS CommandBus` will help you to easily add middleware to handle cross-cutting concerns easily, as well as to extend functionalities. +* **Built-in natural audit-log**: Because all the interactions to the system are modeled as Command (which represent business use-case/intent), the Command naturally represent system audit-log. By adding a middleware to log succeeded command, it naturally becomes the audit-log of the system. ## Integrate into your project @@ -64,7 +64,7 @@ compile group: 'net.dathoang.cqrs.commandbus', name: 'core', version: '0.1.0', e ## Contribute We welcome all contributions. -Please fork the repository and base your work on `develop` branch. +Please fork the repository and base your work on **develop** branch. Before creating pull request, please make sure: * All tests passed. * There is 100% code coverage on all new codes. From 72605af13d8584d7fc834f6575b4a71aeee5349a Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sun, 14 Jul 2019 17:45:40 +0700 Subject: [PATCH 20/22] Update README --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4f7bcbe..8c9a662 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,38 @@ # Java CQRS CommandBus -[![Build Status](https://travis-ci.com/dathoangse/java-cqrs-commandbus.svg?branch=develop)](/https://travis-ci.com/dathoangse/java-cqrs-commandbus/) -[![codecov](https://codecov.io/gh/dathoangse/java-cqrs-commandbus/branch/develop/graph/badge.svg)](/https://codecov.io/gh/dathoangse/java-cqrs-commandbus/) -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.dathoang.cqrs.commandbus/core/badge.svg)](/https://mvnrepository.com/artifact/net.dathoang.cqrs.commandbus/core/) +[![Build Status](https://travis-ci.com/dathoangse/java-cqrs-commandbus.svg?branch=develop)](https://travis-ci.com/dathoangse/java-cqrs-commandbus) +[![codecov](https://codecov.io/gh/dathoangse/java-cqrs-commandbus/branch/develop/graph/badge.svg)](https://codecov.io/gh/dathoangse/java-cqrs-commandbus) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.dathoang.cqrs.commandbus/core/badge.svg)](https://mvnrepository.com/artifact/net.dathoang.cqrs.commandbus/core) A lightweight & highly extensible CQRS framework for implementing application layer and CQRS architectural pattern in Java. ## Who uses Java CQRS CommandBus -* [YouthDev](/https://youthdev.net/en//) +* [YouthDev](https://youthdev.net/en/) ## Code style -The project follows [Google Java Style Guide](/https://google.github.io/styleguide/javaguide.html/) for code style & convention. +The project follows [Google Java Style Guide](https://google.github.io/styleguide/javaguide.html) for code style & convention. ## Git workflow -The project uses [Git flow](/https://nvie.com/posts/a-successful-git-branching-model//) for git workflow. +The project uses [Git flow](https://nvie.com/posts/a-successful-git-branching-model/) for git workflow. ## Versioning -The project uses [Semantic Versioning 2.0.0 | Semantic Versioning](/https://semver.org//) for versioning releases. +The project uses [Semantic Versioning 2.0.0](https://semver.org/) for versioning releases. -/## Libs/frameworks used/ -* [JUnit 5](/https://junit.org/junit5//) for unit testing. -* [AssertJ](/http://joel-costigliola.github.io/assertj//) for assertions in unit test. -* [Mockito](/https://github.com/mockito/mockito/) for mocking in unit test. -* [Apache Commons Logging](/https://commons.apache.org/proper/commons-logging//) as logging interface. +## Libs/frameworks used +* [JUnit 5](https://junit.org/junit5/) for unit testing. +* [AssertJ](http://joel-costigliola.github.io/assertj/) for assertions in unit test. +* [Mockito](https://github.com/mockito/mockito) for mocking in unit test. +* [Apache Commons Logging](https://commons.apache.org/proper/commons-logging/) as logging interface. Built with: -* [Gradle Build Tool](/https://gradle.org//). +* [Gradle Build Tool](https://gradle.org/). ## Features **Java CQRS CommandBus** is a very lightweight and highly extensible CQRS CommandBus library that help you implement your application layer and CQRS architectural pattern: -* **Lightweight**: The library comes with 2 distinct core modules: the `spec` module and the `core` module. The `spec` module (will be available in the future) contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `spec` module. The `core` module contains the library’s implementation of the `spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `core` module to the interfaces in the `spec` module. With this design, it’s possible and easy to swap out or reimplement the whole library with minimal efforts and without affecting your codebase. +* **Lightweight**: The library comes with 2 distinct core modules: the `commandbus-spec` module and the `commandbus-core` module. The `commandbus-spec` module contains all the public interfaces of the framework, these interfaces are minimized to reduce the dependency of your project on the library, and your project only need to depends on the `commandbus-spec` module. The `commandbus-core` module contains the library’s implementation of the `commandbus-spec` module, your code will not need to depends on this module at all, dependency injection framework will automatically bind the implementation of the `commandbus-core` module to the interfaces in the `commandbus-spec` module. With this design, it’s possible and easy to swap out or reimplement the whole library with minimal efforts without affecting your codebase. * **Highly extensible**: We consider extensibility as the core value of the library, so we design it to make it highly extensible via: middleware pipeline. You can inject any custom middleware to intercept the handling of the commands dispatched into the bus. ## Benefits of using Command Bus -Command Bus pattern (a.k.a Command Dispatcher Pattern) help to: +Command Bus pattern (a.k.a **Command Dispatcher Pattern**) help to: * **Decouple architecture from framework**: Good architecture does not depend on framework, it also does not depends on how the system is used (Our architecture should be the same whether we’re building a Restful API, WebSocket, TCP-socket or CLI applications.). By modeling all the interactions (business use-case) via Commands, application layer (or service layer) no longer need to depend on framework, and it also doesn’t depend on the protocol which was used to communicate with the system. * **Make the architecture scream**: Good architecture is the screaming architecture, which means we can easily know the system use-cases just by looking at the architecture. By presenting all the business user-case/intent and user interaction (with the system) via Command, we can quickly understand what the system can do just by looking at all the Commands available in the system, thus all the Commands have already screamed about the system use-cases. * **Unified communication interface**: With Command Bus pattern, the communication interface of application layer (service layer) is unified into only one method: the `dispatch()` method of Command Bus. This simplified interface will help to increase maintainability. @@ -70,5 +70,5 @@ Before creating pull request, please make sure: * There is 100% code coverage on all new codes. ## License -Java CQRS CommandBus is an Open Source Software released under the [Apache License 2.0](/https://www.apache.org/licenses/LICENSE-2.0.html/) +Java CQRS CommandBus is an Open Source Software released under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html) From df86c9fdbc87278237a2164a7484d8cce01045de Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 27 Jul 2019 12:36:04 +0700 Subject: [PATCH 21/22] Fix issue causing wrong jar signature --- build.gradle | 107 +---------------------- commandbus-basic-middleware/build.gradle | 104 ++++++++++++++++++++++ commandbus-core-full/build.gradle | 104 ++++++++++++++++++++++ commandbus-core/build.gradle | 104 ++++++++++++++++++++++ commandbus-spec/build.gradle | 104 ++++++++++++++++++++++ commandbus-spring-full/build.gradle | 104 ++++++++++++++++++++++ commandbus-spring/build.gradle | 104 ++++++++++++++++++++++ 7 files changed, 628 insertions(+), 103 deletions(-) diff --git a/build.gradle b/build.gradle index a9c0bce..83b244d 100644 --- a/build.gradle +++ b/build.gradle @@ -20,8 +20,6 @@ allprojects { apply plugin: 'checkstyle' apply plugin: 'pmd' apply plugin: 'findbugs' - apply plugin: 'maven-publish' - apply plugin: 'signing' checkstyle { toolVersion = '8.18' @@ -54,108 +52,11 @@ allprojects { options.compilerArgs << "-Werror" } } +} - task sourceJar(type: Jar) { - classifier "sources" - from sourceSets.main.allJava - } - - task javadocJar(type: Jar, dependsOn: javadoc) { - classifier "javadoc" - from javadoc.destinationDir - } - - artifacts { - archives jar - archives sourceJar - archives javadocJar - } - - publishing { - publications { - mavenJava(MavenPublication) { - customizePom(pom) - groupId 'net.dathoang.cqrs.commandbus' - version '0.2.0' - if (project.properties['SNAPSHOT'] == 'true') { - version (version + '-SNAPSHOT') - } - - from components.java - - artifact(sourceJar) { - classifier = 'sources' - } - artifact(javadocJar) { - classifier = 'javadoc' - } - - // Create the sign pom artifact - pom.withXml { - def pomFile = file("${project.buildDir}/generated-pom.xml") - writeTo(pomFile) - def pomAscFile = signing.sign(pomFile).signatureFiles[0] - artifact(pomAscFile) { - classifier = null - extension = 'pom.asc' - } - } - - // Create the signed artifacts - project.tasks.signArchives.signatureFiles.each { - artifact(it) { - def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ - if (matcher.find()) { - classifier = matcher.group(1) - } else { - classifier = null - } - extension = 'jar.asc' - } - } - } - } - repositories { - maven { - if (project.properties['SNAPSHOT'] != 'true') { - url "https://oss.sonatype.org/service/local/staging/deploy/maven2" - } else { - url "https://oss.sonatype.org/content/repositories/snapshots" - } - credentials { - username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] - password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] - } - } - } - } - - model { - tasks.generatePomFileForMavenJavaPublication { - destination = file("$buildDir/generated-pom.xml") - } - - tasks.publishMavenJavaPublicationToMavenLocal { - dependsOn project.tasks.signArchives - } - tasks.publishMavenJavaPublicationToMavenRepository { - dependsOn project.tasks.signArchives - } - } - - signing { - sign configurations.archives - } - - gradle.taskGraph.whenReady { taskGraph -> - if (taskGraph.allTasks.any { it instanceof Sign }) { - allprojects { - ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] - ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] - ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] - } - } - } +subprojects { + apply plugin: 'maven-publish' + apply plugin: 'signing' } def customizePom(pom) { diff --git a/commandbus-basic-middleware/build.gradle b/commandbus-basic-middleware/build.gradle index 7670fbf..7b6dfb5 100644 --- a/commandbus-basic-middleware/build.gradle +++ b/commandbus-basic-middleware/build.gradle @@ -54,3 +54,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion \ No newline at end of file diff --git a/commandbus-core-full/build.gradle b/commandbus-core-full/build.gradle index 9c00afa..f9811f3 100644 --- a/commandbus-core-full/build.gradle +++ b/commandbus-core-full/build.gradle @@ -25,3 +25,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion \ No newline at end of file diff --git a/commandbus-core/build.gradle b/commandbus-core/build.gradle index 59e6175..c80948e 100644 --- a/commandbus-core/build.gradle +++ b/commandbus-core/build.gradle @@ -54,3 +54,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion \ No newline at end of file diff --git a/commandbus-spec/build.gradle b/commandbus-spec/build.gradle index 8a1f31f..50db0f9 100644 --- a/commandbus-spec/build.gradle +++ b/commandbus-spec/build.gradle @@ -21,3 +21,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion \ No newline at end of file diff --git a/commandbus-spring-full/build.gradle b/commandbus-spring-full/build.gradle index 3f19027..5489638 100644 --- a/commandbus-spring-full/build.gradle +++ b/commandbus-spring-full/build.gradle @@ -26,3 +26,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion \ No newline at end of file diff --git a/commandbus-spring/build.gradle b/commandbus-spring/build.gradle index 5ac073a..6514dcd 100644 --- a/commandbus-spring/build.gradle +++ b/commandbus-spring/build.gradle @@ -29,3 +29,107 @@ publishing { } } } + +// region Handle publishing +task sourceJar(type: Jar) { + classifier "sources" + from sourceSets.main.allJava +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier "javadoc" + from javadoc.destinationDir +} + +artifacts { + archives jar + archives sourceJar + archives javadocJar +} + +publishing { + publications { + mavenJava(MavenPublication) { + customizePom(pom) + groupId 'net.dathoang.cqrs.commandbus' + version '0.2.0' + if (project.properties['SNAPSHOT'] == 'true') { + version (version + '-SNAPSHOT') + } + + from components.java + + artifact(sourceJar) { + classifier = 'sources' + } + artifact(javadocJar) { + classifier = 'javadoc' + } + + // Create the sign pom artifact + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' + } + } + + // Create the signed artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' + } + } + } + } + repositories { + maven { + if (project.properties['SNAPSHOT'] != 'true') { + url "https://oss.sonatype.org/service/local/staging/deploy/maven2" + } else { + url "https://oss.sonatype.org/content/repositories/snapshots" + } + credentials { + username project.properties['CQRS_COMMANDBUS_SONATYPE_USERNAME'] + password project.properties['CQRS_COMMANDBUS_SONATYPE_PASSWORD'] + } + } + } +} + +model { + tasks.generatePomFileForMavenJavaPublication { + destination = file("$buildDir/generated-pom.xml") + } + + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn project.tasks.signArchives + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn project.tasks.signArchives + } +} + +signing { + sign configurations.archives +} + +gradle.taskGraph.whenReady { taskGraph -> + if (taskGraph.allTasks.any { it instanceof Sign }) { + allprojects { + ext."signing.keyId" = project.properties['CQRS_COMMANDBUS_SIGNING_KEY_ID'] + ext."signing.secretKeyRingFile" = project.properties['CQRS_COMMANDBUS_SECRET_KEYRING_FILE'] + ext."signing.password" = project.properties['CQRS_COMMANDBUS_SIGNING_PASSWORD'] + } + } +} +//endregion From c61181bc1b5877cdcebd31c9f0636cf64b266eea Mon Sep 17 00:00:00 2001 From: Dat Hoang Date: Sat, 27 Jul 2019 12:37:55 +0700 Subject: [PATCH 22/22] Refactor CI script --- .travis.yml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index f58a992..45657d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,12 +35,7 @@ jobs: if: tag =~ ^v script: - ./prepare_before_publish - - ./gradlew commandbus-spec:publish - - ./gradlew commandbus-core:publish - - ./gradlew commandbus-basic-middleware:publish - - ./gradlew commandbus-core-full:publish - - ./gradlew commandbus-spring:publish - - ./gradlew commandbus-spring-full:publish + - ./gradlew publish - ./cleanup_after_publish - stage: release @@ -48,10 +43,5 @@ jobs: if: branch =~ ^(develop|hotfix|release).* script: - ./prepare_before_publish - - ./gradlew commandbus-spec:publish -PSNAPSHOT=true - - ./gradlew commandbus-core:publish -PSNAPSHOT=true - - ./gradlew commandbus-basic-middleware:publish -PSNAPSHOT=true - - ./gradlew commandbus-core-full:publish -PSNAPSHOT=true - - ./gradlew commandbus-spring:publish -PSNAPSHOT=true - - ./gradlew commandbus-spring-full:publish -PSNAPSHOT=true + - ./gradlew publish -PSNAPSHOT=true - ./cleanup_after_publish \ No newline at end of file