Skip to content

Commit c3e740b

Browse files
committed
Describe 2.98.0.2: one style, exit code 2 and a Windows binary
2.98.0.2 formats in the open-java-format style without being asked, so --ojf leaves every command on the site. The Command line page says why it went and that scripts still passing it get a warning, not a failure. The formatter now exits with 2 when it cannot read, parse or write a file or when an option is wrong, which the Command line page lists next to 0 and 1. The Claude Code hook drops its `|| exit 2` for the same reason. On the Migrate page a leftover --palantir now fails the run instead of passing unchecked, so the warning there becomes a note. The release adds a native binary for Windows on x86-64: it is listed for download, and the pages that named Linux and macOS as the only native platforms name Windows too. The GitHub Action and the pre-commit hook still know only Linux and macOS, which their page now says as it is. The Gradle page is unchanged: the plugin does not run the native formatter on Windows yet. Every changed command was run against a build of the formatter with the 2.98.0.2 changes, the hook taken from the built page.
1 parent db42626 commit c3e740b

7 files changed

Lines changed: 42 additions & 31 deletions

File tree

‎docs/ai-agents.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ and [`jq`](https://jqlang.org/), which takes the path of the file out of that JS
8181
"hooks": [
8282
{
8383
"type": "command",
84-
"command": "open-java-format --ojf --skip-removing-unused-imports --replace \"$(jq -r '.tool_input.file_path')\" || exit 2"
84+
"command": "open-java-format --skip-removing-unused-imports --replace \"$(jq -r '.tool_input.file_path')\""
8585
}
8686
]
8787
}
@@ -102,8 +102,8 @@ it in the next. A full format after the first edit would delete that import, so
102102
imports that really are unused.
103103

104104
**A file that does not parse goes back to the agent.** The formatter leaves the file as it is,
105-
prints the error and exits with 1. `|| exit 2` turns that into 2, the exit code that makes Claude
106-
Code show a hook's message to the model, so Claude sees it right after its edit:
105+
prints the error and exits with 2, the exit code that makes Claude Code show a hook's message to
106+
the model, so Claude sees it right after its edit:
107107

108108
``` text
109109
src/main/java/com/example/Broken.java:5:22: error: ';' expected
@@ -128,13 +128,13 @@ for coding agents. Add a section that matches how the project runs the formatter
128128
After you create or edit a `.java` file, format it:
129129

130130
```sh
131-
open-java-format --ojf --replace path/to/File.java
131+
open-java-format --replace path/to/File.java
132132
```
133133

134134
Before you commit, run this check. It must print nothing, so format every file it lists:
135135

136136
```sh
137-
open-java-format --ojf --dry-run --set-exit-if-changed $(git ls-files '*.java')
137+
open-java-format --dry-run --set-exit-if-changed $(git ls-files '*.java')
138138
```
139139
````
140140

‎docs/get-started/command-line.md‎

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ Pick the file for your platform from the
1414
| Linux AArch64, glibc | `open-java-format-linux-glibc_aarch64` |
1515
| macOS, Apple silicon | `open-java-format-macos_aarch64` |
1616
| macOS, Intel | `open-java-format-macos_x86-64` |
17+
| Windows, x86-64 | `open-java-format-windows_x86-64.exe` |
1718
| Anything else with Java 21 or later | `open-java-format-{{ ojf_version }}-all.jar` |
1819

19-
There is no native binary for Windows or for musl-based Linux such as Alpine. Use the jar there.
20+
There is no native binary for Windows on ARM or for musl-based Linux such as Alpine. Use the jar
21+
there.
2022

2123
``` sh title="Native binary, here for Apple silicon"
2224
curl -LO https://github.com/openjavaformat/open-java-format/releases/download/{{ ojf_version }}/open-java-format-macos_aarch64
2325
chmod +x open-java-format-macos_aarch64
2426
./open-java-format-macos_aarch64 --version
2527
```
2628

27-
Rename the file to `open-java-format` and move it to a directory on your `PATH`. The examples below
28-
assume you did.
29+
Rename the file to `open-java-format`, or `open-java-format.exe` on Windows, and move it to a
30+
directory on your `PATH`. The examples below assume you did.
2931

3032
!!! note "macOS and files downloaded with a browser"
3133

@@ -59,33 +61,32 @@ Every release has a `checksums_sha256.txt`. Download it next to your file and ch
5961

6062
## Format and check
6163

62-
Pass `--ojf` every time. Without a style flag the formatter uses Google Java Style, and the old
63-
`--palantir` flag is no longer accepted.
64+
There is one style, so no flag chooses it. Version 2.98.0.1 needed `--ojf`: later versions still
65+
accept it, print a warning and format as usual, so drop it from your scripts.
6466

6567
``` sh title="Format files in place"
66-
open-java-format --ojf --replace src/main/java/com/example/Hello.java
68+
open-java-format --replace src/main/java/com/example/Hello.java
6769
```
6870

6971
``` sh title="Format every tracked Java file"
70-
open-java-format --ojf --replace $(git ls-files '*.java')
72+
open-java-format --replace $(git ls-files '*.java')
7173
```
7274

7375
``` sh title="Check without changing anything"
74-
open-java-format --ojf --dry-run --set-exit-if-changed $(git ls-files '*.java')
76+
open-java-format --dry-run --set-exit-if-changed $(git ls-files '*.java')
7577
```
7678

7779
The check prints the files that would change and exits with 1 if there are any, which is what a CI
7880
step needs.
7981

8082
``` sh title="Format standard input"
81-
cat Hello.java | open-java-format --ojf -
83+
cat Hello.java | open-java-format -
8284
```
8385

8486
## Options
8587

8688
| Option | What it does |
8789
| --- | --- |
88-
| `--ojf` | Use the open-java-format style: 120 columns, 4-space indents |
8990
| `--replace`, `-i` | Write the result back to the files instead of printing it |
9091
| `--dry-run`, `-n` | Print the files that would change, change nothing |
9192
| `--set-exit-if-changed` | Exit with 1 if anything would change |
@@ -97,3 +98,14 @@ cat Hello.java | open-java-format --ojf -
9798
| `--skip-reflowing-long-strings` | Do not rewrap string literals that pass the column limit |
9899
| `@file` | Read options and file names from a file |
99100
| `--version`, `--help` | Print the version, or every option |
101+
102+
## Exit codes
103+
104+
| Code | Meaning |
105+
| --- | --- |
106+
| 0 | Every file was formatted or checked without a problem |
107+
| 1 | With `--set-exit-if-changed`: a file is not formatted |
108+
| 2 | A file could not be read, parsed or written, or an option is wrong. The reason is on standard error |
109+
110+
A file that does not parse is left as it is. When a run hits both, a file that is not formatted and
111+
one it cannot format, the exit code is 2.

‎docs/get-started/github-actions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# GitHub Action and pre-commit
22

33
Both checks run the native binary, so they need no Java, Maven or Gradle. They work on Linux with
4-
glibc and on macOS. There is no native binary for Windows or for musl-based Linux such as Alpine.
4+
glibc and on macOS, and stop with an error on Windows and on musl-based Linux such as Alpine.
55

66
## Check pull requests and pushes
77

@@ -41,7 +41,7 @@ Run the formatter locally with the same version, then commit the result. See
4141
[Command line](command-line.md) for the download.
4242

4343
``` sh
44-
open-java-format --ojf --replace path/to/File.java
44+
open-java-format --replace path/to/File.java
4545
```
4646

4747
## Exclude files

‎docs/get-started/index.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ the same formatter, so they all produce the same files. Set up the ones your pro
2727

2828
---
2929

30-
A native binary for Linux and macOS, or a runnable jar anywhere else. Formats files in place or
31-
checks them.
30+
A native binary for Linux, macOS and Windows, or a runnable jar anywhere else. Formats files in
31+
place or checks them.
3232

3333
- :simple-intellijidea:{ .lg .middle } __[IntelliJ IDEA](intellij-idea.md)__
3434

‎docs/index.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ a native binary on Linux and macOS. For Windows and for multi-project builds see
122122
### On the command line
123123

124124
Every [release](https://github.com/openjavaformat/open-java-format/releases/latest) carries native
125-
binaries for Linux and macOS, and a runnable jar for Java 21 or later.
125+
binaries for Linux, macOS and Windows, and a runnable jar for Java 21 or later.
126126

127127
``` sh title="Format files in place"
128-
open-java-format --ojf --replace src/main/java/com/example/Hello.java
128+
open-java-format --replace src/main/java/com/example/Hello.java
129129
```
130130

131131
``` sh title="Fail when anything is not formatted"
132-
open-java-format --ojf --dry-run --set-exit-if-changed $(git ls-files '*.java')
132+
open-java-format --dry-run --set-exit-if-changed $(git ls-files '*.java')
133133
```
134134

135135
Downloads, checksums and every option are on the [Command line](get-started/command-line.md) page.

‎docs/migrate.md‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The Java packages are unchanged as well. Only the names in your build and your s
1616
| SPI | `palantir-java-format-spi` | `open-java-format-spi` |
1717
| Gradle plugin | `com.palantir.java-format` | `dev.openjavaformat.java-format` |
1818
| Gradle property | `palantir.native.formatter` | `openjavaformat.native.formatter` |
19-
| Command-line style flag | `--palantir` | `--ojf` |
19+
| Command-line style flag | `--palantir` | none: there is one style |
2020
| Style in the API | `PALANTIR` | `OJF` |
2121
| IntelliJ plugin | `palantir-java-format` | `open-java-format` |
2222
| Java packages | `com.palantir.javaformat.*` | the same, for the whole 2.x line |
@@ -43,15 +43,14 @@ settings and multi-project builds.
4343

4444
### Command line and scripts
4545

46-
Replace `--palantir` with `--ojf`, and take the binary or the jar from
46+
Remove `--palantir`: there is one style, so no flag chooses it. Take the binary or the jar from
4747
[our releases](get-started/command-line.md).
4848

49-
!!! warning "The old flag does not fail"
49+
!!! note "A leftover flag fails the run"
5050

51-
`--palantir` is no longer accepted, but it is not an error either: the formatter prints
52-
`unexpected flag: --palantir` with its usage text and exits with 0. A CI step that still passes
53-
the old flag would go green without checking anything. Search your scripts and workflows for
54-
it.
51+
An unknown flag such as `--palantir` stops the formatter with exit code 2, so a CI step that
52+
still passes it fails instead of going green. Version 2.98.0.1 printed its usage text there and
53+
exited with 0, without checking anything.
5554

5655
### Libraries that call the formatter
5756

@@ -95,7 +94,7 @@ the same method in both styles.
9594
2. Format everything once and commit only that:
9695

9796
``` sh
98-
open-java-format --ojf --replace $(git ls-files '*.java')
97+
open-java-format --replace $(git ls-files '*.java')
9998
git commit -am "Reformat with open-java-format"
10099
```
101100

‎zensical.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ toggle.name = "Switch to system preference"
105105
# plugin puts it in before the Markdown is rendered, so it lands in code blocks too. The key is not
106106
# extra.version: the theme reads that one as the switch for a version selector.
107107
[project.extra]
108-
ojf_version = "2.98.0.1"
108+
ojf_version = "2.98.0.2"
109109

110110
# Renders every page as a Jinja template, for {{ ojf_version }}. A misspelt variable or a stray {{
111111
# fails the build instead of leaving a gap or the raw text on the site.

0 commit comments

Comments
 (0)