Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 72 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ name: Release
# and IDE plugins, the native binaries and the WebAssembly module, which a job of its own builds on Oracle
# GraalVM.
#
# The release notes, release-notes/<version>.md, are on the tag before it is pushed: they are the text of
# the GitHub release and the IntelliJ plugin's change notes, and a tag without them publishes nothing.
#
# Needs seven repository secrets: JRELEASER_MAVENCENTRAL_USERNAME and JRELEASER_MAVENCENTRAL_PASSWORD (the
# Central Portal user token), JRELEASER_GPG_SECRET_KEY and JRELEASER_GPG_PASSPHRASE, GRADLE_PUBLISH_KEY and
# GRADLE_PUBLISH_SECRET (the Gradle Plugin Portal key) and JETBRAINS_MARKETPLACE_TOKEN (a permanent token of
Expand All @@ -31,6 +34,47 @@ concurrency:
cancel-in-progress: false

jobs:
# The release notes are the IntelliJ plugin's change notes, which the Marketplace shows for the version and
# the IDE under What's New, and the Marketplace never lets the change notes of an uploaded version change: so
# the publish job waits for this one. The IDE does not render Markdown. GitHub's Markdown API renders the
# notes as GitHub renders a release, with the runner's gh and jq, so the build needs no converter; sed then
# drops the attributes GitHub adds for its own pages, such as its hovercards'. release-notes/README.md says
# how to write them.
release-notes:
name: release notes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

# The shell named, since only then does GitHub run bash with pipefail: a failed gh api fails the step
# instead of leaving sed an empty file.
- name: Render the release notes for the IDE
shell: bash
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ github.ref_name }}
run: |
notes="release-notes/${VERSION}.md"
if [ ! -s "$notes" ]; then
echo "::error::No release notes for ${VERSION}: add ${notes} to the release line, then move the tag onto that commit"
exit 1
fi
mkdir change-notes
jq --null-input --rawfile text "$notes" '{text: $text, mode: "gfm"}' \
| gh api markdown --input - \
| sed -E 's/ (dir|class|rel|data-[a-z-]+)="[^"]*"//g' > change-notes/change-notes.html
cat change-notes/change-notes.html

- name: Hand the change notes to the IntelliJ plugin's jobs
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: change-notes
path: change-notes/change-notes.html
if-no-files-found: error
retention-days: 1

jars:
name: jars
runs-on: ubuntu-latest
Expand Down Expand Up @@ -260,11 +304,12 @@ jobs:
if-no-files-found: error
retention-days: 1

# Both deployments are uploaded and validated by now. Publishing one is a JReleaser run given its ID,
# which builds nothing. One leg per deployment, so that a re-run repeats only the leg that failed.
# Both deployments are uploaded and validated by now, and the release notes rendered. Publishing one is a
# JReleaser run given its ID, which builds nothing. One leg per deployment, so that a re-run repeats only
# the leg that failed.
publish:
name: publish (${{ matrix.deployment }})
needs: [jars, native-deploy]
needs: [jars, native-deploy, release-notes]
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -351,7 +396,7 @@ jobs:
# fails once the upload went through.
jetbrains-plugin:
name: JetBrains Marketplace
needs: publish
needs: [publish, release-notes]
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
Expand All @@ -366,8 +411,16 @@ jobs:
distribution: temurin
java-version: '21'

- name: Collect the change notes
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: change-notes
path: change-notes

# Both runs get the change notes, so that the zip verified is the zip uploaded: without them in one,
# patchPluginXml would run again and build another.
- name: Verify the plugin against the IDEs it supports
run: ./gradlew :open-java-format-idea-plugin:verifyPlugin
run: ./gradlew -PchangeNotes=change-notes/change-notes.html :open-java-format-idea-plugin:verifyPlugin

- name: Keep the verifier's report
if: ${{ failure() }}
Expand All @@ -379,18 +432,19 @@ jobs:
retention-days: 7

- name: Upload the plugin
run: ./gradlew :open-java-format-idea-plugin:publishPlugin
run: ./gradlew -PchangeNotes=change-notes/change-notes.html :open-java-format-idea-plugin:publishPlugin
env:
JETBRAINS_MARKETPLACE_TOKEN: ${{ secrets.JETBRAINS_MARKETPLACE_TOKEN }}

# What Maven Central does not carry — the runnable formatter jar, the Gradle plugins' jar, the IntelliJ
# plugin zip, the Eclipse plugin jar, every platform's native binary as a plain download, and the
# WebAssembly module — goes into a draft GitHub release on the tag, each file signed with the release key.
# Only once both deployments are published and the module is built; publishing the draft is a click on
# GitHub, and a re-run fails while a release for the tag exists.
# Its text is release-notes/<version>.md, and the plugin zip has the same change notes as the one on the
# Marketplace. Only once both deployments are published and the module is built; publishing the draft is a
# click on GitHub, and a re-run fails while a release for the tag exists.
github-release:
name: draft GitHub release
needs: [publish, wasm]
needs: [publish, wasm, release-notes]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down Expand Up @@ -419,8 +473,16 @@ jobs:
name: wasm-module
path: wasm-module

- name: Collect the change notes
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: change-notes
path: change-notes

- name: Build the plugins and open the draft release
run: ./gradlew -PreleaseTarget=github -PnativeImages=native-images -PwasmModule=wasm-module jreleaserRelease
run: >-
./gradlew -PreleaseTarget=github -PnativeImages=native-images -PwasmModule=wasm-module
-PchangeNotes=change-notes/change-notes.html jreleaserRelease
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.JRELEASER_GPG_SECRET_KEY }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
// release on the tag with what Maven Central does not carry — the runnable formatter jar, the Gradle
// plugins' jar, the IntelliJ plugin zip, the Eclipse plugin jar, every platform's native binary as a
// plain download and the WebAssembly module for openjavaformat.dev's playground — each file signed, plus a
// checksum file.
// checksum file. Its text is release-notes/<version>.md.
//
// Publishing is a run of its own: with JRELEASER_MAVENCENTRAL_DEPLOYMENT_ID set, JReleaser publishes that
// deployment, which an earlier run uploaded and the Portal validated, and nothing is built. The ID has to
Expand Down Expand Up @@ -75,6 +75,10 @@ if (releaseTarget == 'github') {
}
}

// A provider: the root project sets its version only after applying this plugin, and JReleaser reads the
// file when its task runs.
def releaseNotes = layout.projectDirectory.file(provider { "release-notes/${version}.md" })

jreleaser {
dependsOnAssemble = false

Expand Down Expand Up @@ -106,9 +110,12 @@ jreleaser {
branch = '21.X.X'
// Published by hand after a look.
draft = true
changelog {
formatted = 'ALWAYS'
format = '- {{commitShortHash}} {{commitTitle}}'
// The text is release-notes/<version>.md as written; see release-notes/README.md. JReleaser fails
// when the file is missing.
if (releaseTarget == 'github') {
changelog {
external.set(releaseNotes)
}
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions open-java-format-idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ dependencies {
implementation libs.jspecify
}

// The change notes, which the Marketplace shows for the version and the IDE under What's New, are the
// release notes, release-notes/<version>.md. The IDE does not render Markdown, so the release workflow
// renders them to HTML and passes the file as -PchangeNotes=<file>; see .github/workflows/release.yml.
// Every other build leaves plugin.xml without change notes.
def changeNotesPath = providers.gradleProperty('changeNotes').getOrNull()
def changeNotesFile = changeNotesPath == null ? null : rootProject.layout.projectDirectory.file(changeNotesPath)
if (changeNotesFile != null && !changeNotesFile.asFile.isFile()) {
throw new GradleException("-PchangeNotes=${changeNotesPath}: no such file")
}

intellijPlatform {
// Bytecode instrumentation (@NotNull assertions, GUI forms) needs the platform's
// java-compiler-ant-tasks, whose version the plugin cannot derive from a non-installer
Expand All @@ -103,6 +113,9 @@ intellijPlatform {
name = 'open-java-format'
// No description here: patchPluginXml would overwrite the one in plugin.xml, which is the
// marketplace listing and is written in HTML.
if (changeNotesFile != null) {
changeNotes = providers.fileContents(changeNotesFile).asText
}
ideaVersion {
sinceBuild = '242' // JBR 21: the first IDEs that can load this plugin's bytecode
untilBuild = provider { null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<description><![CDATA[
<p>Formats Java code with <a href="https://github.com/openjavaformat/open-java-format">open-java-format</a>, a maintained fork of palantir-java-format: 120 columns, 4-space indents and lambda-friendly line breaking.</p>
<p>With the plugin enabled, <b>Reformat Code</b> runs open-java-format instead of the IDE's built-in Java formatter, and <b>Optimize Imports</b> removes unused imports and sorts the others as open-java-format does, so the IDE and your build produce identical files. The IDE's own Java code style settings no longer apply.</p>
<p>To format and fix imports on every save, tick <b>Reformat code</b> and <b>Optimize imports</b> under <b>Tools → Actions on Save</b>; <b>Optimize imports</b> before a commit and in the Reformat Code dialog runs open-java-format too. Imports the IDE adds as you type follow the same layout, unless the project's <code>.editorconfig</code> sets Java code style properties.</p>
<p>The formatter runs inside the IDE, with no process to start for a file, whatever version the project SDK is. A project that applies the <code>dev.openjavaformat.java-format</code> Gradle plugin takes the formatter version from the build; every other project uses the version bundled with this plugin.</p>
<p>The plugin's settings page offers two other ways to run it. <b>In a separate JVM</b> runs it on the IDE's runtime, the project SDK or another JDK of the IDE, Java 21 or later, and parses the syntax of that JDK's version. <b>Native binary</b> runs the formatter compiled for your platform, which the plugin downloads, in a Maven, Gradle or any other project; a binary of your own works too.</p>
<p>Requires IntelliJ IDEA 2024.2 or later, or another IDE with Java support such as Android Studio.</p>
Expand Down
23 changes: 23 additions & 0 deletions release-notes/21.1.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The IntelliJ IDEA plugin now formats inside the IDE and optimizes imports with open-java-format. The output differs from 21.0.2 in a few narrow cases, so take this release with one reformatting run, in a commit of its own.

## IntelliJ IDEA plugin

Reformat Code and Optimize Imports run the formatter inside the IDE's own JVM, with no process to start, and take milliseconds where a file used to take up to a second. The IDE's Java then decides which syntax parses: Java 21 in IntelliJ IDEA 2024.2, Java 25 in 2026.3. For newer syntax, choose **In a separate JVM** with a newer JDK under **Run the formatter** in the plugin's settings, next to **Native binary**; a project that used the native binary keeps it.

**Optimize Imports**, and everything that runs it, such as Actions on Save, now removes and sorts imports as the command line does. Imports the IDE inserts follow the same layout.

## Formatter

A line comment that starts with a no-break space or another Unicode space keeps it, and a long string literal under a cast, a qualified `.new` or a method reference no longer fails the whole file. A misplaced Unicode escape and a stray `;` between imports fail with an error at their line. With the `formatJavadoc` option, a comment loses the `<p>` tags at its end, and a `<div>` gets no `<p>` in front of it.

## Command line, build plugins and Eclipse

Formatting ranges leaves the imports alone and reflows long strings only in the code it rewrites, the same on the command line, in `formatDiff`, in Eclipse and in IntelliJ IDEA. The Maven plugin and the Spotless step now write what the command line writes, and `formatDiff` no longer fails on a diff larger than 64 KB.

## Library

`Formatter.getFormatReplacements`, `Input.getPositionTokenMap` and `SnippetFormatter.format` return `java.util.List` and Guava's `RangeMap` instead of `ImmutableList` and `ImmutableRangeMap`, so code that calls them has to be compiled again.

## Thanks

To Liam Miller-Cushon of google-java-format, whose three fixes are ported here, and to [joaonsk203](https://github.com/joaonsk203) and [doomfrawen](https://github.com/doomfrawen), whose pull requests to google-java-format, [#1526](https://github.com/google/google-java-format/pull/1526) and [#1534](https://github.com/google/google-java-format/pull/1534), proposed the two Javadoc changes.
22 changes: 22 additions & 0 deletions release-notes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Release notes

One file per release, named after its tag: `21.1.0.md` for the tag `21.1.0`. It goes onto the release line in a
pull request before the tag is pushed, and the release workflow publishes nothing for a tag without one.

The file is used twice, as it is written:

- **The GitHub release.** JReleaser makes it the text of the draft release, which is then published by hand.
- **The IntelliJ plugin's change notes**, which the JetBrains Marketplace shows for the version and the IDE shows
under **What's New**. The IDE does not render Markdown, so the workflow renders the file to HTML with GitHub's
Markdown API, as GitHub renders a release. The Marketplace never lets the change notes of an uploaded version
change.

For the notes to read the same in both places:

- Write each paragraph and each list item on one line. GitHub renders a release with a line break at every newline,
and so does the API here.
- Write every link in full, `[#259](https://github.com/openjavaformat/open-java-format/pull/259)`. The IDE gets no
link for a bare `#259` or `@name`, and a relative link leads nowhere outside the repository.
- Keep to paragraphs, `##` headings, lists, links, `code` and **bold**: what the IDE's plugin page shows.

The release workflow, [`.github/workflows/release.yml`](../.github/workflows/release.yml), has the rest.
Loading