From a2f2fdb6a4b6e0b82fb648733e732bdb65e35873 Mon Sep 17 00:00:00 2001
From: Michael Hoennig <michael@hoennig.de>
Date: Thu, 4 Aug 2022 09:41:27 +0200
Subject: [PATCH] add spotless

---
 README.md                                     | 48 +++++++++++++++++++
 TODO.md                                       | 10 ++--
 build.gradle                                  | 13 ++++-
 .../rbac/rbacrole/RbacRoleRepository.java     |  1 -
 .../hsadminng/hs/hscustomer/TestCustomer.java |  1 -
 .../hsadminng/hs/hspackage/TestPackage.java   |  1 -
 6 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md
index 319988be..7b471a5c 100644
--- a/README.md
+++ b/README.md
@@ -236,6 +236,54 @@ You can explore the prototype as follows:
 - then run `historization.sql` in the database,
 - finally run `examples.sql` in the database.
 
+## Coding Guidelines
+
+### Directory and Package Structure
+
+Generally, the standard Java directory structure is used, where productive and test code are sparated like this:
+
+```
+src
+    main/
+        java/
+            net.hostsharing.hasadminng/
+        resources/
+        
+    test/
+        java/
+            net.hostsharing.hasadminng/
+        resources/
+```
+
+The Java package structure below contains:
+
+- config and global (utility) packages,
+  these should not access any other packages within the project
+- rbac, containing all packages related to the RBAC subsystem
+- hs, containing Hostsharing business object related packages
+
+Underneath of rbac and hs, the structure is business oriented, NOT technical / layer -oriented.
+
+Some of these rules are checked with *ArchUnit* unit tests.
+
+### Spotless Code Formatting
+
+Code formatting for Java is checked via *spotless*.
+The formatting style can be checked with this command:
+
+```shell
+gw spotlessCheck
+```
+
+This task is also included in `gw build`.
+
+To apply formatting rules, use:
+
+```shell
+gw spotlessApply
+```
+
+
 ## How To
 
 ### How to Use a Persistent Database for Integration Tests?
diff --git a/TODO.md b/TODO.md
index 96c2a7b7..0670559d 100644
--- a/TODO.md
+++ b/TODO.md
@@ -23,13 +23,13 @@ This document is just for tracking the initial development project and thus only
 
 | ID  | Beschreibung                                               |   Budget | Aufwand | Leistung |
 |:----|:-----------------------------------------------------------|---------:|--------:|---------:|
-| DEV | Aufbau der Entwicklungsumgebung (bis inkl. Unit-Tests)     |       16 |         |          |
-| ATN | Entwurf des Authorisierungs-Systems                        |       40 |     100 |       36 |
+| DEV | Aufbau der Entwicklungsumgebung (bis inkl. Unit-Tests)     |       16 |      12 |       16 |
+| ATN | Entwurf des Authorisierungs-Systems                        |       40 |      68 |       36 |
 | ATZ | Auswahl und Implementierung des Authentifizierungs-Systems |       20 |         |          |
-| ITS | Aufbau einer Umgebung für Integrationstests (*1)           |        4 |       4 |       20 |
-| ATS | Aufbau einer Umgebung für Akzeptanzteste (*1)              |       16 |       3 |        4 |
+| ITS | Aufbau einer Umgebung für Integrationstests (*1)           |        4 |       4 |        4 |
+| ATS | Aufbau einer Umgebung für Akzeptanztests (*1)              |       16 |       3 |          |
 | PIP | Aufbau einer Build- und Testpipeline                       |       20 |         |          |
-| ARC | Aufbau einer Architekturkontrolle                          |        8 |         |          |
+| ARC | Aufbau einer Architekturkontrolle                          |        8 |       2 |        2 |
 |     |                                                            |          |         |          |
 
 (*1: ITS+ATS sind aufgesplittet aus TST mit 20 geplanten Stunden entstanden)
diff --git a/build.gradle b/build.gradle
index 575110be..1554c337 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,8 @@
 plugins {
+    id 'java'
     id 'org.springframework.boot' version '2.7.2'
     id 'io.spring.dependency-management' version '1.0.12.RELEASE'
-    id 'java'
+    id "com.diffplug.spotless" version "6.9.0"
 }
 
 group = 'net.hostsharing'
@@ -22,6 +23,8 @@ ext {
     set('testcontainersVersion', "1.17.3")
 }
 
+// wrapper
+
 dependencies {
     implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
     implementation 'org.springframework.boot:spring-boot-starter-data-rest'
@@ -55,3 +58,11 @@ dependencyManagement {
 tasks.named('test') {
     useJUnitPlatform()
 }
+
+spotless {
+    java {
+        removeUnusedImports()
+        endWithNewline()
+        toggleOffOn()
+    }
+}
diff --git a/src/main/java/net/hostsharing/hsadminng/rbac/rbacrole/RbacRoleRepository.java b/src/main/java/net/hostsharing/hsadminng/rbac/rbacrole/RbacRoleRepository.java
index 0af5091c..abe6738c 100644
--- a/src/main/java/net/hostsharing/hsadminng/rbac/rbacrole/RbacRoleRepository.java
+++ b/src/main/java/net/hostsharing/hsadminng/rbac/rbacrole/RbacRoleRepository.java
@@ -14,4 +14,3 @@ public interface RbacRoleRepository extends Repository<RbacRoleEntity, UUID> {
      */
     List<RbacRoleEntity> findAll();
 }
-
diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java
index c77b0f91..c92cad82 100644
--- a/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java
+++ b/src/test/java/net/hostsharing/hsadminng/hs/hscustomer/TestCustomer.java
@@ -1,6 +1,5 @@
 package net.hostsharing.hsadminng.hs.hscustomer;
 
-import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity;
 
 import static java.util.UUID.randomUUID;
 
diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java
index e586cc1c..f2fde56f 100644
--- a/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java
+++ b/src/test/java/net/hostsharing/hsadminng/hs/hspackage/TestPackage.java
@@ -1,7 +1,6 @@
 package net.hostsharing.hsadminng.hs.hspackage;
 
 import net.hostsharing.hsadminng.hs.hscustomer.CustomerEntity;
-import net.hostsharing.hsadminng.hs.hspackage.PackageEntity;
 import net.hostsharing.hsadminng.hs.hscustomer.TestCustomer;
 
 import static java.util.UUID.randomUUID;