Skip to content

Commit 003cdcc

Browse files
authored
Split Java code style checks (#10532)
1 parent 1fb17d3 commit 003cdcc

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed

.github/workflows/tests.yml

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ concurrency:
2323

2424
jobs:
2525
checkstyle:
26-
name: Code style check
26+
name: Checkstyle
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: Checkout source
@@ -52,22 +52,77 @@ jobs:
5252
with:
5353
message: >
5454
Your code currently does not meet JabRef's code guidelines.
55+
We use [Checkstyle](https://checkstyle.sourceforge.io/) to identify issues.
5556
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
5657
Please carefully follow [the setup guide for the codestyle](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html).
5758
Afterwards, please run checkstyle locally and fix the issues.
5859
5960
6061
More information on code quality in JabRef is available at <https://devdocs.jabref.org/getting-into-the-code/development-strategy.html>.
6162
comment_tag: checkstyle
62-
reactions: eyes
63+
openrewrite:
64+
name: OpenRewrite
65+
runs-on: ubuntu-latest
66+
steps:
67+
- name: Checkout source
68+
uses: actions/checkout@v4
69+
with:
70+
submodules: 'true'
71+
show-progress: 'false'
72+
- name: Set up JDK
73+
uses: actions/setup-java@v3
74+
with:
75+
java-version: 21.0.1
76+
distribution: 'liberica'
77+
cache: 'gradle'
6378
- name: Run OpenRewrite
6479
run: |
6580
./gradlew rewriteDryRun
81+
- name: Add comment on pull request
82+
if: ${{ failure() }}
83+
uses: thollander/actions-comment-pull-request@v2
84+
with:
85+
message: >
86+
Your code currently does not meet JabRef's code guidelines.
87+
We use [OpenRewrite](https://docs.openrewrite.org/) to ensure "modern" Java coding practices.
88+
The issues found can be **automatically fixed**.
89+
Please execute the gradle task *`rewriteRun`*, check the results, commit, and push.
90+
91+
92+
You can check the detailed error output at the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".
93+
comment_tag: openrewrite
94+
modernizer:
95+
name: Modernizer
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout source
99+
uses: actions/checkout@v4
100+
with:
101+
submodules: 'true'
102+
show-progress: 'false'
103+
- name: Set up JDK
104+
uses: actions/setup-java@v3
105+
with:
106+
java-version: 21.0.1
107+
distribution: 'liberica'
108+
cache: 'gradle'
66109
- name: Run modernizer
67110
run: |
68111
# enable failing of this task if modernizer complains
69112
sed -i "s/failOnViolations = false/failOnViolations = true/" build.gradle
70113
./gradlew modernizer
114+
- name: Add comment on pull request
115+
if: ${{ failure() }}
116+
uses: thollander/actions-comment-pull-request@v2
117+
with:
118+
message: >
119+
Your code currently does not meet JabRef's code guidelines.
120+
We use [Gradle Modernizer Plugin](https://github.com/andygoossens/gradle-modernizer-plugin#gradle-modernizer-plugin) to ensure "modern" Java coding practices.
121+
Please fix the detected errors, commit, and push.
122+
123+
124+
You can check the detailed error output at the tab "Checks", section "Tests" (on the left), subsection "Modernizer".
125+
comment_tag: modernizer
71126
markdown-checks:
72127
name: Markdown style check
73128
runs-on: ubuntu-latest

.vscode/ltex.dictionary.en-US.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Checkstyle
2+
CouchDB
13
JabDrive
24
JabRef
3-
CouchDB
5+
OpenRewrite

docs/code-howtos/code-quality.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ parent: Code Howtos
33
---
44
# Code Quality
55

6+
## Code style checkers
7+
8+
JabRef has three code style checkers in place:
9+
10+
* [Checkstyle](https://checkstyle.sourceforge.io/) for basic checks, such as wrong import order.
11+
* [Gradle Modernizer Plugin](https://github.com/andygoossens/gradle-modernizer-plugin#gradle-modernizer-plugin) for Java library usage checks. It ensures that "modern" Java concepts are used (e.g., [one should use `Deque` instead of `Stack`](https://stackoverflow.com/a/73021741/873282)).
12+
* [OpenRewrite](https://docs.openrewrite.org/) for advanced rules. OpenRewrite can also automatically fix issues. JabRef's CI toolchain does NOT automatically rewrite the source code, but checks whether OpenRewrite would rewrite something. As developer, one can execute `./gradlew rewriteRun` to fix the issues.
13+
14+
In case a check fails, [the CI](https://github.com/JabRef/jabref/blob/main/.github/workflows/tests.yml#L24C6-L24C6) automatically adds a comment on the pull request.
15+
16+
## Monitoring
17+
618
We monitor the general source code quality at three places:
719

820
* [codacy](https://www.codacy.com) is a hosted service to monitor code quality. It thereby combines the results of available open source code quality checkers such as [Checkstyle](https://checkstyle.sourceforge.io) or [PMD](https://pmd.github.io). The code quality analysis for JabRef is available at [https://app.codacy.com/gh/JabRef/jabref/dashboard](https://app.codacy.com/gh/JabRef/jabref/dashboard), especially the [list of open issues](https://app.codacy.com/gh/JabRef/jabref/issues/index). In case a rule feels wrong, it is most likely a PMD rule. The JabRef team can change the configuration at [https://app.codacy.com/p/306789/patterns/list?engine=9ed24812-b6ee-4a58-9004-0ed183c45b8f](https://app.codacy.com/p/306789/patterns/list?engine=9ed24812-b6ee-4a58-9004-0ed183c45b8f).
921
* [codecov](https://codecov.io) is a solution to check code coverage of test cases. The code coverage metrics for JabRef are available at [https://codecov.io/github/JabRef/jabref](https://codecov.io/github/JabRef/jabref).
1022
* [Teamscale](https://www.cqse.eu/en/teamscale/overview/) is a popular German product analyzing code quality. The analysis results are available at <https://demo.teamscale.com/findings.html#/jabref/?>.
1123

24+
## Background literature
25+
1226
We strongly recommend reading following two books on code quality:
1327

1428
* [Java by Comparison](http://java.by-comparison.com) is a book by three JabRef developers which focuses on code improvements close to single statements. It is fast to read and one gains much information from each recommendation discussed in the book.

0 commit comments

Comments
 (0)