Skip to content

Commit

Permalink
GH-183 - Initial draft of Spring CLI support
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Jul 21, 2023
1 parent b806bab commit 159827e
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 0 deletions.
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 {}
}
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();
}
}
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> {

}
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();
}
}
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
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
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
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}}
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}}
74 changes: 74 additions & 0 deletions jmolecules-spring-cli/readme.adoc
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]
```

0 comments on commit 159827e

Please sign in to comment.