Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
1e8792f
Initial .prettierrc
koppor Aug 19, 2025
323bd6c
Port changes of previous PR
koppor Aug 19, 2025
63d7a6a
Enable prettier-java
koppor Aug 19, 2025
b848016
Fix plugin name
koppor Aug 19, 2025
679b91d
Debug
koppor Aug 19, 2025
eedfd45
Try quotes
koppor Aug 19, 2025
680c5d0
Try without braces
koppor Aug 19, 2025
cb717c6
Use file_pattern
koppor Aug 19, 2025
d0dae2e
Add permissions and concurrency
koppor Aug 19, 2025
fab6fc6
More debug
koppor Aug 19, 2025
2e7c4ec
Prettier does not output any files in dry run mode
koppor Aug 19, 2025
3860612
Remove debug
koppor Aug 19, 2025
2b1f153
Fix trigger
koppor Aug 19, 2025
8bf1d7b
Fix workflow
koppor Aug 19, 2025
716df05
Try other trigger
koppor Aug 19, 2025
28b8a0a
Try to fix pattern
koppor Aug 19, 2025
ab319bf
Try other quotes
koppor Aug 19, 2025
84c0ab9
No quotes around pattern
koppor Aug 19, 2025
7a08760
Try "manual" execution of prettier and commit+push
koppor Aug 19, 2025
de9b480
Also manual execution on check
koppor Aug 19, 2025
193dc7e
Try to get pretter-plugin-java running
koppor Aug 19, 2025
440d2e5
Prettier now outputs the violating files
koppor Aug 19, 2025
d3d05a0
Fix casing issue in checkstyle text
koppor Aug 19, 2025
6373c47
Add prettier to setup guide
koppor Aug 19, 2025
26b700d
Disable openrewrite rule
koppor Aug 19, 2025
603bc2f
Refine howto
koppor Aug 19, 2025
b144b0f
Do not cry on imports
koppor Aug 19, 2025
55298a6
Ignore non-working files
koppor Aug 19, 2025
7cdefde
Remove rules
koppor Aug 19, 2025
0e3a3f9
Place the operators at the beginning
koppor Aug 19, 2025
f40121c
Fix max line length of StringUtil
koppor Sep 11, 2025
0f356c3
Update codestyle
koppor Aug 19, 2025
a957abe
Rules disabled because of prettier-java
koppor Aug 19, 2025
9285138
Disable more rules
koppor Aug 19, 2025
63f4e9a
Remove empty JavaDoc
koppor Aug 19, 2025
b004d05
Fix filename
koppor Aug 19, 2025
e93c8df
Fix comment position
koppor Sep 11, 2025
7ecdb7e
Remove checkstyle rule EmptyLineSeparator
koppor Aug 19, 2025
bbd19d9
Even larger...
koppor Sep 11, 2025
6bfe088
Merge remote-tracking branch 'upstream/main' into use-prettier
koppor Sep 11, 2025
afabd26
Update style
koppor Sep 12, 2025
3ed08b7
Fix tab vs. spaces
koppor Sep 12, 2025
eb33dde
Add missing " in hint
koppor Sep 12, 2025
3b9fa6b
Update prettier-plugin-java from 2.7.4 to 2.7.5
koppor Sep 12, 2025
c6700b2
Reformat code
koppor Sep 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 12 additions & 0 deletions .github/ghprcomment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@

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).
Afterwards, please [run checkstyle locally](https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html#run-checkstyle) and fix the issues, commit, and push.
- jobName: prettier
workflowName: 'Source Code Tests'
message: >
Your code currently does not meet JabRef's code guidelines.
We use [prettier-java](https://www.jhipster.tech/prettier-java/) to ensure "modern" Java coding practices.
You can see which checks are failing by locating the box "Some checks were not successful" on the pull request page.
To see the test output, locate "Source Code Tests / prettier (pull_request)" and click on it.


The issues found can be **automatically fixed**.
Please execute `npx prettier --write "**/*.java"` on the command line check the results, commit, and push.
Alternativly, you can execute the workflow "Fix prettier" manually using GitHub actions.
- jobName: OpenRewrite
workflowName: 'Source Code Tests'
message: >
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/fix-prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Fix prettier

on:
push:
workflow_dispatch:

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
cancel-in-progress: true

permissions:
contents: write
pull-requests: read

jobs:
prettier:
# enable manual run - and automatic fix in the JabRef organization
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.repository_owner == 'JabRef')
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version: 'latest'
cache: 'npm'

- run: npm ci

- run: npx prettier --write "**/*.java"

- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
message: "Formatted using pretter-java"
16 changes: 16 additions & 0 deletions .github/workflows/tests-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ jobs:
- name: Run checkstyle using gradle
run: ./gradlew checkstyleMain checkstyleTest checkstyleJmh

prettier:
name: prettier
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v5

- uses: actions/setup-node@v4
with:
node-version: 'latest'
cache: 'npm'

- run: npm ci

- run: npx prettier "**/*.java" --check

openrewrite:
name: OpenRewrite
runs-on: ubuntu-latest
Expand Down
138 changes: 99 additions & 39 deletions .jbang/CheckoutPR.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import java.io.File;
import java.util.List;
import java.util.Optional;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
Expand All @@ -24,12 +23,15 @@
//DEPS org.eclipse.jgit:org.eclipse.jgit.pgm:7.3.0.202506031305-r

public class CheckoutPR {

public static void main(String[] args) throws Exception {
GitHub github = new GitHubBuilder().build();
GHRepository repo = github.getRepository("JabRef/jabref");

if (args.length != 1) {
System.err.println("Usage: jbang CheckoutPR.java <pull-request-number>|<contributor:branch-name>");
System.err.println(
"Usage: jbang CheckoutPR.java <pull-request-number>|<contributor:branch-name>"
);
System.exit(1);
}

Expand All @@ -43,7 +45,9 @@ public static void main(String[] args) throws Exception {

GHPullRequest pr;
if (prNumber == -1) {
System.out.println("Trying to find pull request with branch " + arg);
System.out.println(
"Trying to find pull request with branch " + arg
);
String[] parts = arg.split(":");
String contributor;
String branchName;
Expand All @@ -56,20 +60,34 @@ public static void main(String[] args) throws Exception {
}

// We need to query all pull requests to be able to handle closed and merged ones
PagedIterator<GHPullRequest> prIterator = repo.queryPullRequests().direction(GHDirection.DESC).state(GHIssueState.ALL).list().iterator();
PagedIterator<GHPullRequest> prIterator = repo
.queryPullRequests()
.direction(GHDirection.DESC)
.state(GHIssueState.ALL)
.list()
.iterator();
boolean found = false;
pr = null;
while (prIterator.hasNext()) {
pr = prIterator.next();
if ((contributor.isEmpty() || pr.getHead().getUser().getLogin().equals(contributor)) &&
pr.getHead().getRef().equals(branchName)) {
if (
(contributor.isEmpty()
|| pr
.getHead()
.getUser()
.getLogin()
.equals(contributor))
&& pr.getHead().getRef().equals(branchName)
) {
found = true;
System.out.println("Found pull request #" + pr.getNumber());
break;
}
}
if (!found) {
throw new IllegalArgumentException("Pull request not found for branch: " + branchName);
throw new IllegalArgumentException(
"Pull request not found for branch: " + branchName
);
}
} else {
pr = repo.getPullRequest(prNumber);
Expand All @@ -78,28 +96,41 @@ public static void main(String[] args) throws Exception {
System.out.println("Determined PR URL is " + pr.getUrl());

if (pr.isMerged()) {
System.out.println("Pull request is already merged - checking out main branch...");
System.out.println(
"Pull request is already merged - checking out main branch..."
);
checkoutUpstreamMain();
return;
}

if (pr.getState().equals(GHIssueState.CLOSED)) {
System.out.println("Warning: Pull request is closed. Trying to continue nevertheless.");
System.out.println(
"Warning: Pull request is closed. Trying to continue nevertheless."
);
}

String headRef = pr.getHead().getRef();
String headRepoCloneUrl = pr.getHead().getRepository().getHttpTransportUrl();
String headRepoCloneUrl = pr
.getHead()
.getRepository()
.getHttpTransportUrl();

final String remoteName = "tmp-remote";
final String localBranchName = "pr--" + pr.getNumber() + "--" + pr.getUser().getLogin() + "--" + headRef;
final String localBranchName =
"pr--"
+ pr.getNumber()
+ "--"
+ pr.getUser().getLogin()
+ "--"
+ headRef;

// Open the repository in the current directory (".")
File repoDir = new File(".");
Repository repository = new FileRepositoryBuilder()
.setGitDir(new File(repoDir, ".git"))
.readEnvironment()
.findGitDir()
.build();
.setGitDir(new File(repoDir, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
// If current branch is "tmp-branch", checkout "main"
Expand All @@ -111,71 +142,100 @@ public static void main(String[] args) throws Exception {

// Check if branch "tmp-branch" exists and remove it if present
List<org.eclipse.jgit.lib.Ref> branches = git.branchList().call();
boolean branchExists = branches.stream().anyMatch(branch -> branch.getName().endsWith(localBranchName));
boolean branchExists = branches
.stream()
.anyMatch(branch -> branch.getName().endsWith(localBranchName));
if (branchExists) {
System.out.println("Deleting branch 'tmp-branch'");
git.branchDelete().setBranchNames(localBranchName).setForce(true).call();
git
.branchDelete()
.setBranchNames(localBranchName)
.setForce(true)
.call();
}

// Check if the remote "tmp-remote" exists and remove it if present
List<RemoteConfig> remotes = git.remoteList().call();
boolean remoteExists = remotes.stream().anyMatch(remote -> remote.getName().equals(remoteName));
boolean remoteExists = remotes
.stream()
.anyMatch(remote -> remote.getName().equals(remoteName));
if (remoteExists) {
System.out.println("Removing remote 'tmp-remote'");
git.remoteRemove().setRemoteName(remoteName).call();
}

System.out.println("Adding remote 'tmp-remote'");
git.remoteAdd()
.setName(remoteName)
.setUri(new URIish(headRepoCloneUrl))
.call();
git
.remoteAdd()
.setName(remoteName)
.setUri(new URIish(headRepoCloneUrl))
.call();
}

// Has nice output, therefore we use pgm
System.out.println("Fetching...");
String[] jGitArgsFetch = {"fetch", remoteName};
String[] jGitArgsFetch = { "fetch", remoteName };
org.eclipse.jgit.pgm.Main.main(jGitArgsFetch);

try (Git git = new Git(repository)) {
System.out.println("Checking out...");
git.checkout()
.setCreateBranch(true)
.setName(localBranchName)
.setStartPoint(remoteName + "/" + headRef)
.call();
git
.checkout()
.setCreateBranch(true)
.setName(localBranchName)
.setStartPoint(remoteName + "/" + headRef)
.call();
}

System.out.println("Checked out PR #" + pr.getNumber() + " (" + pr.getTitle() + ") to branch " + localBranchName + ".");
System.out.println(
"Checked out PR #"
+ pr.getNumber()
+ " ("
+ pr.getTitle()
+ ") to branch "
+ localBranchName
+ "."
);
System.out.println("Checked out commit " + pr.getHead().getSha() + ".");
}

private static void checkoutUpstreamMain() throws Exception {
File repoDir = new File(".");
Repository repository = new FileRepositoryBuilder()
.setGitDir(new File(repoDir, ".git"))
.readEnvironment()
.findGitDir()
.build();
.setGitDir(new File(repoDir, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
final String upstreamName = "upstream";
final String jabrefRepoUrl = "https://github.com/JabRef/jabref.git";

// Check if a remote pointing to JabRef/jabref already exists
List<RemoteConfig> remotes = git.remoteList().call();
Optional<RemoteConfig> jabrefRemote = remotes.stream()
Optional<RemoteConfig> jabrefRemote = remotes
.stream()
// We use "contains", because there could be SSH remote URLs
.filter(r -> r.getURIs().stream().anyMatch(uri -> uri.toString().contains("JabRef/jabref")))
.filter(r ->
r
.getURIs()
.stream()
.anyMatch(uri ->
uri.toString().contains("JabRef/jabref")
)
)
.findFirst();

String remoteToUse;
if (jabrefRemote.isPresent()) {
remoteToUse = jabrefRemote.get().getName();
System.out.println("Using existing remote: " + remoteToUse);
} else {
System.out.println("Adding remote 'upstream' pointing to " + jabrefRepoUrl);
git.remoteAdd()
System.out.println(
"Adding remote 'upstream' pointing to " + jabrefRepoUrl
);
git
.remoteAdd()
.setName(upstreamName)
.setUri(new URIish(jabrefRepoUrl))
.call();
Expand All @@ -191,12 +251,12 @@ private static void checkoutUpstreamMain() throws Exception {

// Fetch from the selected remote
System.out.println("Fetching from " + remoteToUse);
String[] jGitArgsFetch = {"fetch", remoteToUse};
String[] jGitArgsFetch = { "fetch", remoteToUse };
org.eclipse.jgit.pgm.Main.main(jGitArgsFetch);

// Merge upstream/main
System.out.println("Merging " + remoteToUse + "/main into main");
String[] jGitArgsMerge = {"merge", remoteToUse + "/main"};
String[] jGitArgsMerge = { "merge", remoteToUse + "/main" };
org.eclipse.jgit.pgm.Main.main(jGitArgsMerge);
}
}
Expand Down
8 changes: 7 additions & 1 deletion .jbang/CloneJabRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//DEPS org.eclipse.jgit:org.eclipse.jgit.pgm:7.3.0.202506031305-r

public class CloneJabRef {

public static void main(String[] args) throws Exception {
Path targetDir;
if (args.length == 1) {
Expand All @@ -22,7 +23,12 @@ public static void main(String[] args) throws Exception {
return;
}

String[] jGitArgs = {"clone", "https://github.com/JabRef/jabref.git", "--recurse-submodules", targetDir.toString()};
String[] jGitArgs = {
"clone",
"https://github.com/JabRef/jabref.git",
"--recurse-submodules",
targetDir.toString(),
};
org.eclipse.jgit.pgm.Main.main(jGitArgs);

System.out.println("JabRef code available at: " + targetDir);
Expand Down
1 change: 1 addition & 0 deletions .jbang/JabKitLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

/// This class is required for [jbang](https://www.jbang.dev/)
public class JabKitLauncher {

public static void main(String[] args) {
org.jabref.JabKit.main(args);
}
Expand Down
1 change: 1 addition & 0 deletions .jbang/JabLsLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

/// This class is required for [jbang](https://www.jbang.dev/)
public class JabLsLauncher {

public static void main(String[] args) throws Exception {
org.jabref.languageserver.cli.ServerCli.main(args);
}
Expand Down
1 change: 1 addition & 0 deletions .jbang/JabSrvLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

/// This class is required for [jbang](https://www.jbang.dev/)
public class JabSrvLauncher {

public static void main(String[] args) throws Exception {
org.jabref.http.server.cli.ServerCli.main(args);
}
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins:
- prettier-plugin-java
tabWidth: 4
experimentalOperatorPosition: start
Loading