Skip to content

Commit 0bcb2a0

Browse files
authored
Ci/setup pipeline, enforce test coverage and improve tests (#3)
* Reformat files to comply with Checkstyle rules * chore: align project formatting and config with HMCTS standards - Add private constructor - Refactor all Java files to comply with HMCTS checkstyle rules - Expand wildcard imports and fix indentation/line-length violations - Add .editorconfig using HMCTS formatting conventions - Update .gitignore to include HMCTS-relevant patterns - Remove Spotless plugin from build.gradle (not used in HMCTS projects) - Ensure Checkstyle uses HMCTS-provided configuration files This brings the project into alignment with the HMCTS engineering standards and eliminates conflicting or redundant formatting tools. * Update file to aggregate tasks to run with one check cmd './gradlew clean check' * Remove redundant ReturnNull check + update Javadoc string * Add CI workflow for merge to main * Apply grammatical typo/fixes from Copilot * 200~Remove @activeprofiles since all envs currently use H2 * Update Javadoc to reflect use of record vs lombok @value
1 parent 8f87c0a commit 0bcb2a0

File tree

18 files changed

+928
-288
lines changed

18 files changed

+928
-288
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
max_line_length = 120
12+
13+
[*.java]
14+
indent_size = 4
15+
ij_continuation_indent_size = 4
16+
ij_java_align_multiline_parameters = true
17+
ij_java_align_multiline_parameters_in_calls = true
18+
ij_java_call_parameters_new_line_after_left_paren = true
19+
ij_java_call_parameters_right_paren_on_new_line = true
20+
ij_java_call_parameters_wrap = on_every_item

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build & Quality Checks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up JDK 21
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '21'
19+
distribution: 'temurin'
20+
21+
- name: Make gradlew executable
22+
run: chmod +x ./gradlew
23+
24+
- name: Run Gradle checks
25+
run: ./gradlew clean check

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
HELP.md
22
.gradle
33
build/
4+
**/build/
5+
*.class
46
!gradle/wrapper/gradle-wrapper.jar
57
!**/src/main/**/build/
68
!**/src/test/**/build/
9+
bin/main/application.yaml
10+
**/target
711

812

913
### STS ###
@@ -26,6 +30,12 @@ bin/
2630
out/
2731
!**/src/main/**/out/
2832
!**/src/test/**/out/
33+
.mirrord
34+
.DS_Store
35+
36+
# node_modules
37+
package-lock.json
38+
node_modules/
2939

3040
### NetBeans ###
3141
/nbproject/private/
@@ -53,4 +63,5 @@ out/
5363
*.pem
5464

5565
# Environment variables
56-
.env
66+
.env
67+

README.md

Lines changed: 189 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,189 @@
1-
# S_BookAPIJAVA
1+
# S_BookAPIJAVA
2+
3+
# Code Quality & Static Analysis
4+
5+
This project follows HMCTS engineering standards for formatting, style, static analysis, and code coverage.
6+
The following tools are configured and integrated with Gradle:
7+
8+
- Checkstyle – HMCTS Java code conventions
9+
10+
- SpotBugs – static analysis for potential defects
11+
12+
- JaCoCo – code coverage reporting
13+
14+
- EditorConfig – consistent whitespace and formatting rules
15+
16+
17+
----------
18+
19+
## Checkstyle (HMCTS rules)
20+
21+
Checkstyle uses the HMCTS `checkstyle.xml`, enforcing naming, formatting, Javadoc, and structural rules.
22+
23+
### Run Checkstyle
24+
25+
`./gradlew checkstyleMain`
26+
or
27+
`./gradlew checkstyleTest`
28+
29+
### Run ALL Checkstyle tasks
30+
31+
`./gradlew checkstyle`
32+
33+
### Checkstyle reports
34+
35+
Reports are generated at:
36+
37+
`build/reports/checkstyle/`
38+
39+
----------
40+
41+
## SpotBugs (static analysis)
42+
43+
SpotBugs analyses compiled bytecode and flags potential null pointer issues, performance problems, and common Java defects.
44+
45+
### List SpotBugs tasks
46+
47+
`./gradlew tasks --all | grep spotbugs`
48+
49+
### Run SpotBugs on main code
50+
51+
`./gradlew spotbugsMain`
52+
53+
### Run SpotBugs on test code
54+
55+
`./gradlew spotbugsTest`
56+
57+
### Run all SpotBugs tasks
58+
59+
`./gradlew spotbugs`
60+
61+
### SpotBugs reports
62+
63+
`build/reports/spotbugs/`
64+
65+
----------
66+
67+
## JaCoCo (test coverage)
68+
69+
JaCoCo generates unit test and integration test coverage reports in XML and HTML.
70+
71+
### Run tests and generate JaCoCo reports
72+
73+
`./gradlew test jacocoTestReport`
74+
75+
### Coverage report location
76+
77+
`build/reports/jacoco/test/jacocoTestReport.html`
78+
79+
----------
80+
81+
## EditorConfig (formatting and whitespace)
82+
83+
The project uses HMCTS `.editorconfig` rules, enforcing:
84+
85+
- 2-space indentation for most files
86+
87+
- 4-space indentation for `.java` files
88+
89+
- `LF` line endings
90+
91+
- UTF-8 charset
92+
93+
- No trailing whitespace
94+
95+
- A newline at the end of every file
96+
97+
98+
Most IDEs (including IntelliJ) apply these rules automatically.
99+
100+
----------
101+
102+
## Running all verification tasks
103+
104+
To verify everything before committing:
105+
106+
`./gradlew clean build`
107+
108+
This runs:
109+
110+
- Checkstyle
111+
112+
- SpotBugs
113+
114+
- Tests
115+
116+
- JaCoCo
117+
118+
- Compilation
119+
120+
- Packaging
121+
122+
----------
123+
124+
### Gradle Daemon: Stop the Daemon and Force a Clean Run
125+
126+
**Step 1: Forcefully stop all running Gradle daemons.**
127+
This command tells Gradle to find any background processes it has running and terminate them.
128+
```Bash
129+
./gradlew --stop
130+
```
131+
132+
**Step 2: Run a clean build.**
133+
The clean task deletes the entire build directory. This removes any old, compiled artifacts and cached results, ensuring nothing stale is left over. We will combine it with the checkstyleMain task.
134+
```Bash
135+
./gradlew clean [checkstyleMain]
136+
```
137+
138+
----------
139+
140+
## IntelliJ Setup
141+
142+
### Enable Checkstyle in IntelliJ
143+
144+
1. Install the **Checkstyle-IDEA** plugin
145+
146+
2. Open IntelliJ settings:
147+
148+
`Settings → Tools → Checkstyle`
149+
150+
3. Add the configuration file:
151+
152+
`config/checkstyle/checkstyle.xml`
153+
154+
4. Set it as the default configuration
155+
156+
5. (Optional) Enable “Scan before check-in”
157+
158+
159+
----------
160+
161+
### Enable EditorConfig support
162+
163+
Verify the following setting is enabled:
164+
165+
`Settings → Editor → Code Style → Enable EditorConfig support`
166+
167+
----------
168+
169+
### Reformat code according to project rules
170+
171+
Use IntelliJ’s reformat command:
172+
173+
`Windows/Linux: Ctrl + Alt + L macOS: Cmd + Option + L`
174+
175+
----------
176+
177+
## Summary
178+
179+
This project aligns with HMCTS engineering standards:
180+
181+
- HMCTS Checkstyle enforcement
182+
183+
- SpotBugs static analysis
184+
185+
- JaCoCo coverage reports
186+
187+
- HMCTS EditorConfig formatting
188+
189+
- Spotless removed (not used by HMCTS)

0 commit comments

Comments
 (0)