diff --git a/spring-modulith-cli/.spring/commands/modulith/add-listener/ApplicationModuleListener.java b/spring-modulith-cli/.spring/commands/modulith/add-listener/ApplicationModuleListener.java new file mode 100644 index 000000000..06fb1961f --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-listener/ApplicationModuleListener.java @@ -0,0 +1,12 @@ +package {{root-package}}.{{module}}; + +import org.springframework.stereotype.Component; + +@Component +class {{capitalize name}}EventListener { + + @ApplicationModuleListener + void on({{eventType}} event) { + + } +} diff --git a/spring-modulith-cli/.spring/commands/modulith/add-listener/command.yaml b/spring-modulith-cli/.spring/commands/modulith/add-listener/command.yaml new file mode 100644 index 000000000..ac0a485bb --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-listener/command.yaml @@ -0,0 +1,15 @@ +command: + description: Add an application module listener + options: + + - name: module + description: The name of the module to create the listener in. + required: true + + - name: name + description: The name of the listener type. + required: true + + - name: eventType + description: The event type to listen to. + required: true diff --git a/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleComponent.java b/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleComponent.java new file mode 100644 index 000000000..bc10996c4 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleComponent.java @@ -0,0 +1,8 @@ +package {{root-package}}.{{name}}; + +import org.springframework.stereotype.Component; + +@Component +class {{capitalize name}}Component { + +} diff --git a/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleIntegrationTests.java b/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleIntegrationTests.java new file mode 100644 index 000000000..800700830 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-module/ApplicationModuleIntegrationTests.java @@ -0,0 +1,11 @@ +package {{root-package}}.{{name}}; + +import org.junit.jupiter.api.Test; +import org.springframework.modulith.test.ApplicationModuleTest; + +@ApplicationModuleTest +class {{capitalizeFirst name}}ModuleIntegrationTests { + + @Test + void bootstrapsModule() {} +} \ No newline at end of file diff --git a/spring-modulith-cli/.spring/commands/modulith/add-module/add-module.yaml b/spring-modulith-cli/.spring/commands/modulith/add-module/add-module.yaml new file mode 100644 index 000000000..7d24456c6 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-module/add-module.yaml @@ -0,0 +1,7 @@ +actions: + - generate: + to: src/main/java/{{root-package-dir}}/{{name}}/{{capitalize name}}Component.java + from: ApplicationModuleComponent.java + - generate: + to: src/test/java/{{root-package-dir}}/{{name}}/{{capitalize name}}ModuleIntegrationTests.java + from: ApplicationModuleIntegrationTests.java diff --git a/spring-modulith-cli/.spring/commands/modulith/add-module/command.yaml b/spring-modulith-cli/.spring/commands/modulith/add-module/command.yaml new file mode 100644 index 000000000..803a854d9 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/add-module/command.yaml @@ -0,0 +1,6 @@ +command: + description: Add an application module + options: + - name: name + description: The name of the application module. + required: true \ No newline at end of file diff --git a/spring-modulith-cli/.spring/commands/modulith/init/add-event-publication-registry.yaml b/spring-modulith-cli/.spring/commands/modulith/init/add-event-publication-registry.yaml new file mode 100644 index 000000000..08c1004ea --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/init/add-event-publication-registry.yaml @@ -0,0 +1,26 @@ +actions: + # if: enable-event-publication-registry + - exec: + command: ./mvnw dependency:list | grep 'jakarta.persistence-api' || echo '' + define: + name: jpa-present + - exec: + command: ./mvnw dependency:list | grep 'spring-jdbc' || echo '' + define: + name: spring-jdbc-present + - exec: + command: ./mvnw dependency:list | grep 'spring-data-mongodb' || echo '' + define: + name: spring-data-mongodb-present + - inject-maven-dependency: + text: | + + org.springframework.modulith + {{#if jpa-present}} + spring-modulith-starter-jpa + {{else if spring-jdbc-present}} + spring-modulith-starter-jdbc + {{else if spring-jdbc-present}} + spring-modulith-starter-mongodb + {{/if}} + diff --git a/spring-modulith-cli/.spring/commands/modulith/init/command.yaml b/spring-modulith-cli/.spring/commands/modulith/init/command.yaml new file mode 100644 index 000000000..d9f572a98 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/init/command.yaml @@ -0,0 +1,10 @@ +command: + description: Initializes Spring Modulith + options: + - name: enable-event-publication-registry + description: Valid values ["jdbc", "jpa", "mongodb"] + dataType: string + - name: enable-observability + description: Whether to include the modules for observability. + dataType: boolean + defaultValue: false diff --git a/spring-modulith-cli/.spring/commands/modulith/init/init-spring-modulith.yaml b/spring-modulith-cli/.spring/commands/modulith/init/init-spring-modulith.yaml new file mode 100644 index 000000000..0ab3b8898 --- /dev/null +++ b/spring-modulith-cli/.spring/commands/modulith/init/init-spring-modulith.yaml @@ -0,0 +1,24 @@ +actions: + - inject-maven-dependency-management: + text: | + + org.springframework.modulith + spring-modulith-bom + 1.1.0 + pom + import + + - inject-maven-dependency: + text: | + + org.springframework.modulith + spring-modulith-starter-test + test + + {{#if enable-observability}} + + org.springframework.modulith + spring-modulith-starter-insight + runtime + + {{/if}} diff --git a/spring-modulith-cli/readme.adoc b/spring-modulith-cli/readme.adoc new file mode 100644 index 000000000..48afaf491 --- /dev/null +++ b/spring-modulith-cli/readme.adoc @@ -0,0 +1,96 @@ += Spring Modulith CLI Integration + +This module contains the Spring CLI integration for Spring Modulith. +To install the Spring Modulith support into the CLI, issue `command add` and point it to this repo: + +[source, bash] +---- +$ command add https://github.com/spring-projects/spring-modulith/tree/main/spring-modulith-cli +---- + +Verify the commands have been installed correctly by issuing `help`. + +== Commands + +=== Initializing Spring Modulith + +`modulith init` initializes Spring Modulith with the current project. + + +[source] +---- +NAME + modulith init - Initializes Spring Modulith + +SYNOPSIS + modulith init --enable-event-publication-registry String --enable-observability Boolean --help + +OPTIONS + --enable-event-publication-registry String + Valid values ["jdbc", "jpa", "mongodb"] + [Optional] + + --enable-observability Boolean + Whether to include the modules for observability. + [Optional, default = false] + + --help or -h + help for modulith init + [Optional] +---- + +=== Adding an Application Module + +`modulith add-module` adds a new application module to the application, including: + +* A new Java package with the given name. +* A Spring component named after the module. +* An `@ApplicationModuleTest` in the application module package in the test sources. + +[source] +---- +NAME + modulith add-module - Add an application module + +SYNOPSIS + modulith add-module [--name String] --help + +OPTIONS + --name String + The name of the application module. + [Mandatory] + + --help or -h + help for modulith add-module + [Optional] +---- + +=== Adding an Application Module Listener + +`modulith add-listener` + +[source] +---- +NAME + modulith add-listener - Add an application module listener + +SYNOPSIS + modulith add-listener [--module String] [--name String] [--eventType String] --help + +OPTIONS + --module String + The name of the module to create the listener in. + [Mandatory] + + --name String + The name of the listener type. + [Mandatory] + + --eventType String + The event type to listen to. + [Mandatory] + + --help or -h + help for modulith add-listener + [Optional] +----