diff --git a/docs/about.md b/docs/about.md index 04d9c48..e686f24 100644 --- a/docs/about.md +++ b/docs/about.md @@ -56,7 +56,7 @@ Central and the Gradle Plugin Portal. They are made with the project's release k The key is published on [keys.openpgp.org](https://keys.openpgp.org). Import it once, then check the checksum file of a release, and the checksum file against your download as shown on the -[Command line](get-started/command-line.md#verify-the-download) page. +[Download](get-started/command-line/download.md#verify-the-download) page. ``` sh curl -sSL https://keys.openpgp.org/vks/v1/by-fingerprint/13A6BDF2DAA98D3D573B33EA100481FDAEE94DE9 | gpg --import diff --git a/docs/ai-agents.md b/docs/ai-agents.md index 3a5452a..aa67694 100644 --- a/docs/ai-agents.md +++ b/docs/ai-agents.md @@ -69,7 +69,7 @@ The four layers back each other up, so use as many as you can. session. A `PostToolUse` hook on the `Edit` and `Write` tools runs after every file the agent changes, and it gets the tool call as JSON on its standard input. -The hook needs `open-java-format` on the `PATH`, see [Command line](get-started/command-line.md), +The hook needs `open-java-format` on the `PATH`, see [Command line](get-started/command-line/index.md), and [`jq`](https://jqlang.org/), which takes the path of the file out of that JSON. ``` json title=".claude/settings.json" diff --git a/docs/get-started/command-line.md b/docs/get-started/command-line.md deleted file mode 100644 index 456a11b..0000000 --- a/docs/get-started/command-line.md +++ /dev/null @@ -1,194 +0,0 @@ -# Command line - -The formatter comes as a native binary that needs no Java, and as a runnable jar for every platform -the binaries do not cover. Homebrew on macOS and Linux, apt on Ubuntu and Debian and Scoop on -Windows install the binary and keep it current; mise installs it on all three and pins its version -per project. - -## Homebrew - -``` sh -brew install openjavaformat/tap/open-java-format -open-java-format --version -``` - -The formula comes from our tap, [openjavaformat/homebrew-tap](https://github.com/openjavaformat/homebrew-tap). -It downloads the native binary of the latest release from GitHub, checks it against the release's -checksums and puts `open-java-format` on your `PATH`. It covers macOS on Apple silicon and Intel and -Linux on x86-64 and AArch64; on Windows, use [Scoop](#scoop) or [mise](#mise). Homebrew fetches the -file with `curl`, so macOS does not quarantine it. - -`brew upgrade` takes each new release, at the latest an hour after it is published. A new minor -version can change the output (see [Versions](../about.md#versions)): `brew pin open-java-format` -holds the installed one. - -## apt - -``` sh -sudo install -d -m 0755 /etc/apt/keyrings -curl -fsSL https://apt.openjavaformat.dev/key.asc | sudo tee /etc/apt/keyrings/open-java-format.asc > /dev/null -echo "deb [signed-by=/etc/apt/keyrings/open-java-format.asc] https://apt.openjavaformat.dev stable main" \ - | sudo tee /etc/apt/sources.list.d/open-java-format.list -sudo apt update -sudo apt install open-java-format -``` - -The lines add our apt repository, [openjavaformat/apt](https://github.com/openjavaformat/apt), with -the key that signs it, and install the native binary of the latest release as -`/usr/bin/open-java-format`. The package is there for amd64 and arm64 and needs glibc 2.34 or later: -Ubuntu 22.04 or Debian 12 and newer. - -`sudo apt upgrade` takes each new release, at the latest an hour after it is published. A new minor -version can change the output (see [Versions](../about.md#versions)): -`sudo apt-mark hold open-java-format` holds the installed one. The repository carries the latest -version only; older versions are binaries to download, as below. - -## Scoop - -``` powershell -scoop bucket add openjavaformat https://github.com/openjavaformat/scoop-bucket -scoop install openjavaformat/open-java-format -open-java-format --version -``` - -The manifest comes from our bucket, [openjavaformat/scoop-bucket](https://github.com/openjavaformat/scoop-bucket). -It downloads the Windows x64 binary of the latest release from GitHub, checks it against the release's -checksums and puts `open-java-format` on your `PATH`, for your user and without administrator rights. -Scoop needs Git to add a bucket: run `scoop install git` first if you have none. On Windows 11 on -ARM, Scoop installs the same x64 binary, and Windows runs it under emulation. - -`scoop update` fetches the bucket, and `scoop update open-java-format` then takes the new release, at -the latest an hour after it is published. `scoop hold open-java-format` holds the installed version. - -## mise - -``` sh -mise use github:openjavaformat/open-java-format@{{ ojf_version }} -open-java-format --version -``` - -[mise](https://mise.jdx.dev) installs the tool from the GitHub release with its -[github backend](https://mise.jdx.dev/dev-tools/backends/github.html): it picks the native binary for -your platform, checks it against the digest GitHub publishes and the release's build attestation, and -puts `open-java-format` on your `PATH`. That works on macOS, on Linux with glibc and on Windows -x86-64. On Windows on ARM and on musl-based Linux it would pick the wrong file, so use the jar there. - -`mise use` writes the version into the project's `mise.toml`, so everyone on the project formats with -the same one: - -``` toml title="mise.toml" -[tools] -"github:openjavaformat/open-java-format" = "{{ ojf_version }}" -``` - -Add `-g` to install it for your user instead of one project. Without a version, `mise use` writes -`latest`, and `mise upgrade` then takes each new release. A new minor version can change the output -(see [Versions](../about.md#versions)), which is why the example pins one. - -## Download - -Pick the file for your platform from the -[latest release](https://github.com/openjavaformat/open-java-format/releases/latest). - -| Platform | File | -| --- | --- | -| Linux x86-64, glibc | `open-java-format-linux-glibc_x86-64` | -| Linux AArch64, glibc | `open-java-format-linux-glibc_aarch64` | -| macOS, Apple silicon | `open-java-format-macos_aarch64` | -| macOS, Intel | `open-java-format-macos_x86-64` | -| Windows, x86-64 | `open-java-format-windows_x86-64.exe` | -| Anything else with Java 21 or later | `open-java-format-{{ ojf_version }}-all.jar` | - -The Linux binaries need glibc 2.34 or later. There is no native binary for Windows on ARM, but -Windows 11 runs the x64 one under emulation. For musl-based Linux such as Alpine there is none: use -the jar there. - -``` sh title="Native binary, here for Apple silicon" -curl -LO https://github.com/openjavaformat/open-java-format/releases/download/{{ ojf_version }}/open-java-format-macos_aarch64 -chmod +x open-java-format-macos_aarch64 -./open-java-format-macos_aarch64 --version -``` - -Rename the file to `open-java-format`, or `open-java-format.exe` on Windows, and move it to a -directory on your `PATH`. The examples below assume you did. - -!!! note "macOS and files downloaded with a browser" - - macOS refuses to run a binary that a browser downloaded. Clear the quarantine flag first with - `xattr -d com.apple.quarantine open-java-format-macos_aarch64`. A file fetched with `curl` does - not get the flag. - -``` sh title="Runnable jar" -curl -LO https://github.com/openjavaformat/open-java-format/releases/download/{{ ojf_version }}/open-java-format-{{ ojf_version }}-all.jar -java -jar open-java-format-{{ ojf_version }}-all.jar --version -``` - -The jar carries its dependencies and the `Add-Exports` entries the formatter needs, so it runs -without JVM flags. - -## Verify the download - -Every release has a `checksums_sha256.txt`. Download it next to your file and check: - -=== "macOS" - - ``` sh - shasum -a 256 --ignore-missing -c checksums_sha256.txt - ``` - -=== "Linux" - - ``` sh - sha256sum --ignore-missing -c checksums_sha256.txt - ``` - -## Format and check - -There is one style, so no flag chooses it. Version 2.98.0.1 needed `--ojf`: later versions still -accept it, print a warning and format as usual, so drop it from your scripts. - -``` sh title="Format files in place" -open-java-format --replace src/main/java/com/example/Hello.java -``` - -``` sh title="Format every tracked Java file" -open-java-format --replace $(git ls-files '*.java') -``` - -``` sh title="Check without changing anything" -open-java-format --dry-run --set-exit-if-changed $(git ls-files '*.java') -``` - -The check prints the files that would change and exits with 1 if there are any, which is what a CI -step needs. - -``` sh title="Format standard input" -cat Hello.java | open-java-format - -``` - -## Options - -| Option | What it does | -| --- | --- | -| `--replace`, `-i` | Write the result back to the files instead of printing it | -| `--dry-run`, `-n` | Print the files that would change, change nothing | -| `--set-exit-if-changed` | Exit with 1 if anything would change | -| `-` | Format standard input to standard output | -| `--lines 5:10` | Format only these lines, counted from 1 | -| `--fix-imports-only` | Sort imports and remove unused ones, format nothing else | -| `--skip-sorting-imports` | Leave the import order alone | -| `--skip-removing-unused-imports` | Keep unused imports | -| `--skip-reflowing-long-strings` | Do not rewrap string literals that pass the column limit | -| `@file` | Read options and file names from a file | -| `--version`, `--help` | Print the version, or every option | - -## Exit codes - -| Code | Meaning | -| --- | --- | -| 0 | Every file was formatted or checked without a problem | -| 1 | With `--set-exit-if-changed`: a file is not formatted | -| 2 | A file could not be read, parsed or written, or an option is wrong. The reason is on standard error | - -A file that does not parse is left as it is. When a run hits both, a file that is not formatted and -one it cannot format, the exit code is 2. diff --git a/docs/get-started/command-line/apt.md b/docs/get-started/command-line/apt.md new file mode 100644 index 0000000..57fb947 --- /dev/null +++ b/docs/get-started/command-line/apt.md @@ -0,0 +1,44 @@ +# apt + +apt installs the native binary on Ubuntu and Debian, for amd64 and arm64, and `apt upgrade` takes each +new release. + +``` sh +sudo install -d -m 0755 /etc/apt/keyrings +curl -fsSL https://apt.openjavaformat.dev/key.asc | sudo tee /etc/apt/keyrings/open-java-format.asc > /dev/null +echo "deb [signed-by=/etc/apt/keyrings/open-java-format.asc] https://apt.openjavaformat.dev stable main" \ + | sudo tee /etc/apt/sources.list.d/open-java-format.list +sudo apt update +sudo apt install open-java-format +open-java-format --version +``` + +The lines add our apt repository, [openjavaformat/apt](https://github.com/openjavaformat/apt), with +the key that signs it, and install the native binary of the latest release as +`/usr/bin/open-java-format`. The package needs glibc 2.34 or later: Ubuntu 22.04 or Debian 12 and +newer. + +## Check the key + +The repository is signed by a key of its own, not by the +[release key](../../about.md#verify-a-download) that signs the files of a GitHub release. Its +fingerprint is: + +``` text +5098 A90C 44ED 5129 8CB5 C476 D8F1 EFB5 9EE1 EB3C +``` + +To compare it with the key you downloaded, run +`gpg --show-keys /etc/apt/keyrings/open-java-format.asc`, which prints the fingerprint without the +spaces. + +## Update and hold + +`sudo apt upgrade` takes each new release, at the latest an hour after it is published. A new minor +version can change the output (see [Versions](../../about.md#versions)): +`sudo apt-mark hold open-java-format` holds the installed one. The repository carries the latest +version only; older versions are binaries to [download](download.md). + +## Next + +[Format and check](index.md#format-and-check) shows what to run once it is installed. diff --git a/docs/get-started/command-line/download.md b/docs/get-started/command-line/download.md new file mode 100644 index 0000000..b7690ce --- /dev/null +++ b/docs/get-started/command-line/download.md @@ -0,0 +1,68 @@ +# Download + +Every release has a native binary for each platform it covers, and a runnable jar for all the rest. +Take the file by hand when none of the package managers fits: [mise](mise.md), +[Homebrew](homebrew.md), [Scoop](scoop.md) and [apt](apt.md) install the same binary and keep it +current. + +Pick the file for your platform from the +[latest release](https://github.com/openjavaformat/open-java-format/releases/latest). + +| Platform | File | +| --- | --- | +| Linux x86-64, glibc | `open-java-format-linux-glibc_x86-64` | +| Linux AArch64, glibc | `open-java-format-linux-glibc_aarch64` | +| macOS, Apple silicon | `open-java-format-macos_aarch64` | +| macOS, Intel | `open-java-format-macos_x86-64` | +| Windows, x86-64 | `open-java-format-windows_x86-64.exe` | +| Anything else with Java 21 or later | `open-java-format-{{ ojf_version }}-all.jar` | + +The Linux binaries need glibc 2.34 or later. There is no native binary for Windows on ARM, but +Windows 11 runs the x64 one under emulation. For musl-based Linux such as Alpine there is none: use +the jar there. + +## Native binary + +``` sh title="Native binary, here for Apple silicon" +curl -LO https://github.com/openjavaformat/open-java-format/releases/download/{{ ojf_version }}/open-java-format-macos_aarch64 +chmod +x open-java-format-macos_aarch64 +./open-java-format-macos_aarch64 --version +``` + +Rename the file to `open-java-format`, or `open-java-format.exe` on Windows, and move it to a +directory on your `PATH`. The examples on the [Command line](index.md#format-and-check) page assume +you did. + +!!! note "macOS and files downloaded with a browser" + + macOS refuses to run a binary that a browser downloaded. Clear the quarantine flag first with + `xattr -d com.apple.quarantine open-java-format-macos_aarch64`. A file fetched with `curl` does + not get the flag. + +## Runnable jar + +``` sh title="Runnable jar" +curl -LO https://github.com/openjavaformat/open-java-format/releases/download/{{ ojf_version }}/open-java-format-{{ ojf_version }}-all.jar +java -jar open-java-format-{{ ojf_version }}-all.jar --version +``` + +The jar carries its dependencies and the `Add-Exports` entries the formatter needs, so it runs +without JVM flags. It needs Java 21 or later. + +## Verify the download + +Every release has a `checksums_sha256.txt`. Download it next to your file and check: + +=== "macOS" + + ``` sh + shasum -a 256 --ignore-missing -c checksums_sha256.txt + ``` + +=== "Linux" + + ``` sh + sha256sum --ignore-missing -c checksums_sha256.txt + ``` + +The files are signed too: [About](../../about.md#verify-a-download) shows how to check the signature. diff --git a/docs/get-started/command-line/homebrew.md b/docs/get-started/command-line/homebrew.md new file mode 100644 index 0000000..048e5e8 --- /dev/null +++ b/docs/get-started/command-line/homebrew.md @@ -0,0 +1,24 @@ +# Homebrew + +Homebrew installs the native binary on macOS and Linux, and `brew upgrade` takes each new release. + +``` sh +brew install openjavaformat/tap/open-java-format +open-java-format --version +``` + +The formula comes from our tap, [openjavaformat/homebrew-tap](https://github.com/openjavaformat/homebrew-tap). +It downloads the native binary of the latest release from GitHub, checks it against the release's +checksums and puts `open-java-format` on your `PATH`. It covers macOS on Apple silicon and Intel and +Linux on x86-64 and AArch64; on Windows, use [Scoop](scoop.md) or [mise](mise.md). Homebrew fetches +the file with `curl`, so macOS does not quarantine it. + +## Update and hold + +`brew upgrade` takes each new release, at the latest an hour after it is published. A new minor +version can change the output (see [Versions](../../about.md#versions)): `brew pin open-java-format` +holds the installed one. + +## Next + +[Format and check](index.md#format-and-check) shows what to run once it is installed. diff --git a/docs/get-started/command-line/index.md b/docs/get-started/command-line/index.md new file mode 100644 index 0000000..086862d --- /dev/null +++ b/docs/get-started/command-line/index.md @@ -0,0 +1,94 @@ +# Command line + +The formatter comes as a native binary that needs no Java, and as a runnable jar for every platform +the binaries do not cover. A package manager installs the binary and keeps it current; the other way +is to download it from the release. + +## Install + +