Skip to content

Commit

Permalink
Palantir support Java 21+ as well
Browse files Browse the repository at this point in the history
  • Loading branch information
eirnym committed Jul 3, 2024
1 parent 4ca55b7 commit b879caa
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/bump_external_releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ def bump_palantir_java_formatter():
)


bump_functions = (
bump_ktfmt,
bump_ktlint,
bump_google_java_formatter,
bump_palantir_java_formatter
)

if __name__ == "__main__":
something_is_bumped = False
for bumper in (bump_ktfmt, bump_ktlint, bump_google_java_formatter):
for bumper in bump_functions:
something_is_bumped |= bumper()

if not something_is_bumped:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
language: python
types: [kotlin]
minimum_pre_commit_version: '1'
# this is needed because the hook downloads ktlint and we don't have yet a
# this is needed because the hook downloads ktfmt/ktlint and we don't have yet a
# nice way of ensuring a single download over multiple runs
require_serial: true
- id: pretty-format-rust
Expand Down
2 changes: 1 addition & 1 deletion language_formatters_pre_commit_hooks/palantir.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.43.0
2.47.0
15 changes: 5 additions & 10 deletions language_formatters_pre_commit_hooks/pretty_format_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,19 +200,14 @@ def format_google(args):
return 0 if status == 0 else 1


def format_palantir(args): # pragma: no cover
def format_palantir(args):
# Palantir Java Formatter starting from 2.0.0 does not support Java 1.8,
# before that version the tool can only be executed on Java up to version 20.
# Context: https://github.com/palantir/palantir-java-format/releases/tag/v2.0.0
if Version(args.palantir_java_formatter_version) >= Version("2.0.0"):
assert_min_jdk_version(Version("11.0")) # pragma: no cover

# Palantir Java formatter is not compatible with Java 21 and above yet.
# https://github.com/palantir/palantir-java-format/issues/977 contains
# more links for Java compatibility
assert_max_jdk_version(Version("21.0"))

if args.palantir_java_formatter_jar is None:
if args.palantir_java_formatter_jar is None: # pragma: no cover
palantir_java_formatter_jar = _download_palantir_java_formatter_jar(
args.palantir_java_formatter_version,
)
Expand All @@ -228,13 +223,13 @@ def format_palantir(args): # pragma: no cover
]
if args.aosp: # pragma: no cover
cmd_args.append("--aosp")
if args.autofix:
cmd_args.append("--replace") # pragma: no cover
if args.autofix: # pragma: no cover
cmd_args.append("--replace")
else:
cmd_args.append("--dry-run")
status, output, _ = run_command(*(cmd_args + args.filenames))

if output:
if output: # pragma: no cover|'
message = (
"The following files have been fixed by palantir-java-formatter"
if args.autofix
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ exclude =
[options.package_data]
language_formatters_pre_commit_hooks =
google_java_formatter.version
palantir_java_formatter.version
palantir.version
ktlint.version
ktfmt.version
8 changes: 0 additions & 8 deletions tests/pretty_format_java_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,10 @@ def test_palantir_pretty_format_java_up_to_1_9_is_allowed_on_jdk_11_and_above(un
undecorate_method(["--palantir", "--palantir-java-formatter-version=1.9", "pretty-formatted.java"])


@pytest.mark.skipif(condition=get_jdk_version() <= Version("21"), reason="Skipping test because it requires Java JDK before 21")
def test_palantir_pretty_format_is_not_allowed_on_jdk_above_21(undecorate_method):
with pytest.raises(ToolNotInstalled, match="JRE: version < 21.0 is required to run this pre-commit hook."):
undecorate_method(["--palantir", "pretty-formatted.java"])


def test_google_pretty_format_java_autofix(tmpdir, undecorate_method):
run_autofix_test(tmpdir, undecorate_method, "not-pretty-formatted.java", "not-pretty-formatted_fixed.java")


@pytest.mark.skipif(condition=get_jdk_version() >= Version("21"), reason="Skipping test because it requires Java JDK before 21")
def test_palantir_pretty_format_java_autofix(tmpdir, undecorate_method):
run_autofix_test(tmpdir, undecorate_method, "not-pretty-formatted.java", "not-pretty-formatted_fixed.java")

Expand All @@ -151,7 +144,6 @@ def test_google_pretty_format_java_jar(mock_run_command, undecorate_method, cli_
assert not in_args


@pytest.mark.skipif(condition=get_jdk_version() >= Version("21"), reason="Skipping test because it requires Java JDK before 21")
@pytest.mark.parametrize(
("cli_arg", "expected_retval"),
(
Expand Down
2 changes: 0 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ passenv =
HOME
HOMEPATH
PROGRAMDATA
JAVA_HOME

setenv =
GIT_AUTHOR_NAME = "test"
GIT_COMMITTER_NAME = "test"
Expand Down

0 comments on commit b879caa

Please sign in to comment.