-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-183 - Initial draft of Spring CLI support
- Loading branch information
Showing
10 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
jmolecules-spring-cli/.spring/commands/jmolecules/add-aggregate/Aggregate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package {{root-package}}.{{module}}; | ||
|
||
import java.util.UUID; | ||
|
||
import org.jmolecules.ddd.types.AggregateRoot; | ||
import org.jmolecules.ddd.types.Identifier; | ||
|
||
import {{root-package}}.{{module}}.{{capitalizeFirst name}}.{{capitalizeFirst name}}Identifier; | ||
|
||
|
||
/** | ||
* A {{capitalizeFirst name}}. | ||
*/ | ||
public class {{capitalizeFirst name}} implements AggregateRoot<{{capitalizeFirst name}}, {{capitalizeFirst name}}Identifier> { | ||
|
||
private final {{capitalizeFirst name}}Identifier id; | ||
|
||
public {{capitalizeFirst name}}() { | ||
this.id = new {{capitalizeFirst name}}Identifier(UUID.randomUUID()); | ||
} | ||
|
||
@Override | ||
public {{capitalizeFirst name}}Identifier getId() { | ||
return id; | ||
} | ||
|
||
record {{capitalizeFirst name}}Identifier(UUID id) implements Identifier {} | ||
} |
19 changes: 19 additions & 0 deletions
19
jmolecules-spring-cli/.spring/commands/jmolecules/add-aggregate/AggregateUnitTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package {{root-package}}.{{module}}; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Unit tests for {{capitalizeFirst name}}. | ||
*/ | ||
class {{capitalizeFirst name}}UnitTests { | ||
|
||
@Test | ||
void createsSimple{{capitalizeFirst name}}Instance() { | ||
|
||
var {{name}} = new {{capitalizeFirst name}}(); | ||
|
||
assertThat({{name}}.getId()).isNotNull(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
jmolecules-spring-cli/.spring/commands/jmolecules/add-aggregate/Repository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package {{root-package}}.{{module}}; | ||
|
||
import org.jmolecules.ddd.types.Repository; | ||
import {{root-package}}.{{module}}.{{capitalizeFirst name}}.{{capitalizeFirst name}}Identifier; | ||
|
||
/** | ||
* A repository to manage {{capitalizeFirst name}} instances. | ||
*/ | ||
interface {{capitalizeFirst name}}Repository extends Repository<{{capitalizeFirst name}}, {{capitalizeFirst name}}Identifier> { | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...ules-spring-cli/.spring/commands/jmolecules/add-aggregate/RepositoryIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package {{root-package}}.{{module}}; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
/** | ||
* Integration tests for {{capitalizeFirst name}}Repository. | ||
*/ | ||
@SpringBootTest | ||
class {{capitalizeFirst name}}RepositoryIntegrationTests { | ||
|
||
@Autowired {{capitalizeFirst name}}Repository repository; | ||
|
||
@Test | ||
void repositoryBootstrapped() { | ||
assertThat(repository).isNotNull(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
jmolecules-spring-cli/.spring/commands/jmolecules/add-aggregate/command.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
command: | ||
description: Add a jMolecules aggregate | ||
options: | ||
|
||
- name: name | ||
description: The name of the aggregate (camel case) | ||
dataType: string | ||
inputType: text | ||
required: true | ||
|
||
- name: module | ||
description: The name of the module to create the aggregate in. | ||
dataType: string | ||
inputType: text | ||
required: true |
13 changes: 13 additions & 0 deletions
13
...spring-cli/.spring/commands/jmolecules/add-aggregate/create-aggregate-and-repository.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
actions: | ||
- generate: | ||
to: src/main/java/{{root-package-dir}}/{{module}}/{{capitalizeFirst name}}.java | ||
from: Aggregate.java | ||
- generate: | ||
to: src/test/java/{{root-package-dir}}/{{module}}/{{capitalizeFirst name}}UnitTests.java | ||
from: AggregateUnitTests.java | ||
- generate: | ||
to: src/main/java/{{root-package-dir}}/{{module}}/{{capitalizeFirst name}}Repository.java | ||
from: Repository.java | ||
- generate: | ||
to: src/test/java/{{root-package-dir}}/{{module}}/{{capitalizeFirst name}}RepositoryIntegrationTests.java | ||
from: RepositoryIntegrationTests.java |
15 changes: 15 additions & 0 deletions
15
jmolecules-spring-cli/.spring/commands/jmolecules/init/command.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
command: | ||
description: Initializes the project to use jMolecules | ||
options: | ||
|
||
- name: with-architecture | ||
description: Which architectural stype to use (onion, hexagonal, clean) | ||
dataType: string | ||
|
||
- name: with-ddd | ||
description: Whether to enable the Domain-Driven Design support | ||
dataType: boolean | ||
|
||
- name: with-codegen | ||
description: Whether to enable the ByteBuddy based code generation for boilerplate persistence | ||
dataType: boolean |
24 changes: 24 additions & 0 deletions
24
jmolecules-spring-cli/.spring/commands/jmolecules/init/init-jmolecules.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
actions: | ||
- inject-maven-dependency-management: | ||
text: | | ||
<dependency> | ||
<groupId>org.jmolecules</groupId> | ||
<artifactId>jmolecules-bom</artifactId> | ||
<version>2022.3.0</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
- inject-maven-dependency: | ||
text: | | ||
{{#if with-ddd}} | ||
<dependency> | ||
<groupId>org.jmolecules.integrations</groupId> | ||
<artifactId>jmolecules-starter-ddd</artifactId> | ||
</dependency> | ||
{{/if}} | ||
{{#if with-architecture}} | ||
<dependency> | ||
<groupId>org.jmolecules</groupId> | ||
<artifactId>jmolecules-{{with-architecture}}-architecture</artifactId> | ||
</dependency> | ||
{{/if}} |
40 changes: 40 additions & 0 deletions
40
jmolecules-spring-cli/.spring/commands/jmolecules/init/setup-bytebuddy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
actions: | ||
- exec: | ||
command: ./mvnw dependency:list | grep 'jakarta.persistence-api' -q | ||
define: | ||
name: jpa-present | ||
- inject-maven-build-plugin: | ||
text: | | ||
{{#if with-codegen}} | ||
<plugin> | ||
<groupId>net.bytebuddy</groupId> | ||
<artifactId>byte-buddy-maven-plugin</artifactId> | ||
<version>1.14.4</version> | ||
<configuration> | ||
<classPathDiscovery>true</classPathDiscovery> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>transform-extended</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
{{/if}} | ||
- inject-maven-dependency: | ||
text: | | ||
{{#if with-codegen}} | ||
{{#if jpa-present = 0}} | ||
<dependency> | ||
<groupId>org.jmolecules.integrations</groupId> | ||
<artifactId>jmolecules-jpa</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
{{/if}} | ||
<dependency> | ||
<groupId>org.jmolecules.integrations</groupId> | ||
<artifactId>jmolecules-bytebuddy-nodep</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
= Spring CLI Integration | ||
|
||
This module of jMolecules Integration provides integration with https://github.com/spring-projects-experimental/spring-cli[Spring CLI]. | ||
|
||
== Installation | ||
|
||
Run Spring CLI and issue the `command add` command pointing it to this particular module of the repository. | ||
|
||
``` | ||
$ spring | ||
spring:> command add … | ||
``` | ||
|
||
== Usage | ||
|
||
The integration provides the following commands. | ||
|
||
=== Initializing jMolecules | ||
|
||
`jmolecules init` adds all artifacts necessary to the POM of the project, depending on which features you'd like to use. | ||
|
||
``` | ||
NAME | ||
jmolecules init - Initializes the project to use jMolecules | ||
|
||
SYNOPSIS | ||
jmolecules init --with-architecture String --with-ddd Boolean --with-codegen Boolean --help | ||
|
||
OPTIONS | ||
--with-architecture String | ||
Which architectural stype to use (onion, hexagonal, clean) | ||
[Optional] | ||
|
||
--with-ddd Boolean | ||
Whether to enable the Domain-Driven Design support | ||
[Optional] | ||
|
||
--with-codegen Boolean | ||
Whether to enable the ByteBuddy based code generation for boilerplate persistence | ||
[Optional] | ||
|
||
--help or -h | ||
help for jmolecules init | ||
[Optional] | ||
``` | ||
|
||
=== Adding a DDD aggregate to the project | ||
|
||
Adding an aggregate to the project results in three new files generated in the project: | ||
|
||
* The aggregate file implementing `AggregateRoot` using a custom, record-based `Identifier` implementation backed by a `UUID`. | ||
* A repository declaration to persist instances of the aggregate. | ||
* A unit test class for the aggregate itself | ||
|
||
``` | ||
NAME | ||
jmolecules add-aggregate - Add a jMolecules aggregate | ||
|
||
SYNOPSIS | ||
jmolecules add-aggregate [--name String] [--module String] --help | ||
|
||
OPTIONS | ||
--name String | ||
The name of the aggregate (camel case) | ||
[Mandatory] | ||
|
||
--module String | ||
The name of the module to create the aggregate in. | ||
[Mandatory] | ||
|
||
--help or -h | ||
help for jmolecules add-aggregate | ||
[Optional] | ||
``` |