Skip to content

Commit 11adc82

Browse files
committed
feat: allow dynamic version selection for pjf
1 parent e7c2206 commit 11adc82

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -546,16 +546,6 @@ spotless --target '**/src/**/*.java' license-header --header='/* (c) DiffPlug $Y
546546

547547
### palantir-java-format
548548

549-
<!---freshmark pjfshields
550-
output = [
551-
link(shield('Palantir Java Format version', 'palantir-java-format', '{{libs.versions.native.include.palantirJavaFormat}}', 'blue'), 'https://github.com/palantir/palantir-java-format'),
552-
].join('\n')
553-
-->
554-
555-
[![Palantir Java Format version](https://img.shields.io/badge/palantir--java--format-2.67.0-blue.svg)](https://github.com/palantir/palantir-java-format)
556-
557-
<!---freshmark /pjfshields -->
558-
559549
Formats java files according to the [palantir-java-format](https://github.com/palantir/palantir-java-format) style guide. Palantir Java Format is a modern, lambda-friendly,
560550
120 character Java formatter. It is based on the Google Java Format project.
561551

@@ -569,14 +559,17 @@ output =
569559
-->
570560

571561
```
572-
Usage: spotless palantir-java-format [-hjV] [-s=<style>]
562+
Usage: spotless palantir-java-format [-hjV] [-s=<style>] [-v=<useVersion>]
573563
Runs palantir java format
574564
-h, --help Show this help message and exit.
575565
-j, --format-javadoc Format javadoc.
576566
(default: false)
577567
-s, --style=<style> The style to use for the palantir java format.
578568
One of: PALANTIR, AOSP, GOOGLE
579569
(default: PALANTIR)
570+
-v, --use-version=<useVersion>
571+
The version of palantir java format to use.
572+
(default: 2.80.0)
580573
-V, --version Print version information and exit.
581574
582575
✅ This step supports the following file type: Java

app/src/main/java/com/diffplug/spotless/cli/steps/PalantirJavaFormat.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
@AdditionalInfoLinks("https://github.com/palantir/palantir-java-format")
3434
public class PalantirJavaFormat extends SpotlessFormatterStep {
3535

36+
private static final String DEFAULT_VERSION_SYSPROP = "steps.palantir-java-format.default-version";
37+
38+
static {
39+
// workaround for dynamic property values in annotations
40+
System.setProperty(DEFAULT_VERSION_SYSPROP, PalantirJavaFormatStep.defaultVersion());
41+
}
42+
3643
@CommandLine.Option(
3744
names = {"--style", "-s"},
3845
defaultValue = "PALANTIR",
@@ -46,6 +53,12 @@ public class PalantirJavaFormat extends SpotlessFormatterStep {
4653
description = "Format javadoc." + OptionConstants.DEFAULT_VALUE_SUFFIX)
4754
boolean formatJavadoc;
4855

56+
@CommandLine.Option(
57+
names = {"--use-version", "-v"},
58+
defaultValue = "${sys:" + DEFAULT_VERSION_SYSPROP + "}",
59+
description = "The version of palantir java format to use." + OptionConstants.DEFAULT_VALUE_SUFFIX)
60+
String useVersion;
61+
4962
public enum Style {
5063
PALANTIR,
5164
AOSP,

gradle/libs.versions.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ junit = "5.8.1"
88
maven-resolver = "2.0.13"
99
mockito = "5.17.0"
1010
native-include-cleanThat = "2.23"
11-
native-include-palantirJavaFormat = "2.67.0"
1211
# to find required version here check eclipse_wtp_formatter/v4.21.0.lockfile
1312
# where <4.21.0> is the default version of com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep#defaultVersion
1413
native-include-spotlessEclipseWtp = "3.23.0"
@@ -39,7 +38,6 @@ maven-resolver-transport-file = { module = "org.apache.maven.resolver:maven-reso
3938
maven-resolver-util = { module = "org.apache.maven.resolver:maven-resolver-util" } # version from bom
4039
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
4140
native-include-cleanThat = { module = "io.github.solven-eu.cleanthat:java", version.ref = "native-include-cleanThat" }
42-
native-include-palantirJavaFormat = { module = "com.palantir.javaformat:palantir-java-format", version.ref = "native-include-palantirJavaFormat" }
4341
native-include-spotlessEclipseWtp = { module = "com.diffplug.spotless:spotless-eclipse-wtp", version.ref = "native-include-spotlessEclipseWtp" }
4442
picocli = { module = "info.picocli:picocli", version.ref = "picocli" }
4543
picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
@@ -64,7 +62,6 @@ maven-resolver-impl-libs = [
6462
]
6563
native-includes = [
6664
"native-include-cleanThat",
67-
"native-include-palantirJavaFormat",
6865
"native-include-spotlessEclipseWtp",
6966
]
7067
spotless-libs = ["spotless-lib", "spotless-lib-extra"]

0 commit comments

Comments
 (0)