Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
a67bad9
bump java
eholmer1 Oct 19, 2024
e658a4f
Remove tests for handling of extra semi-colons
cushon Apr 20, 2023
065c379
Add support for guard clauses in Java 21 switch expressions
TheCK Dec 7, 2023
2f58013
Initial support for pattern matching in switches
cushon Dec 8, 2023
640ca01
format
CRogers Oct 22, 2024
52712d6
add benchmarks
crogoz Jan 22, 2025
217a7b0
.
crogoz Jan 22, 2025
0618efc
.
crogoz Jan 22, 2025
fa35c61
spotlessApply
crogoz Jan 23, 2025
ef7b081
test?
crogoz Jan 24, 2025
25d20ea
some nativeImage
crogoz Jan 27, 2025
e5e8492
execute permissions
crogoz Jan 27, 2025
a73f12f
executable
crogoz Jan 27, 2025
5de0181
working transforms
crogoz Jan 28, 2025
c475f83
add replacement reflect classes for native-image
crogoz Jan 30, 2025
07a2d0e
.
crogoz Jan 30, 2025
b1119e2
bump gradle-jdks version
crogoz Jan 30, 2025
0fbf044
Add generated changelog entries
svc-changelog Jan 30, 2025
782f075
Add generated changelog entries
svc-changelog Jan 30, 2025
25bce25
natieImage
crogoz Jan 30, 2025
6d346d9
Merge branch 'cr/graal-1' of github.com:palantir/palantir-java-format…
crogoz Jan 30, 2025
2a2d086
spotless
crogoz Jan 31, 2025
320c77e
gradlew
crogoz Jan 31, 2025
d1323a4
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz Jan 31, 2025
12f2b1d
compatibility
crogoz Jan 31, 2025
4c058df
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz Jan 31, 2025
b9a2cc5
OS as part of classifier
crogoz Jan 31, 2025
cbccc19
configurable
crogoz Feb 3, 2025
2b0d8f9
fix tests
crogoz Feb 3, 2025
ce67ada
no log line
crogoz Feb 3, 2025
0f01291
no logging
crogoz Feb 3, 2025
ddad367
use gradle utils
crogoz Feb 4, 2025
f7fe10c
publishing
crogoz Feb 10, 2025
374729d
cleanup circle configs
crogoz Feb 10, 2025
09cd140
configurations
crogoz Feb 11, 2025
6fd3877
cleanup
crogoz Feb 11, 2025
7e0c6c7
cleanup
crogoz Feb 11, 2025
bb5c552
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz Feb 11, 2025
e37e8e3
wip
crogoz Feb 11, 2025
be60611
wip
crogoz Feb 11, 2025
7113b17
wip
crogoz Feb 12, 2025
760922c
spotless
crogoz Feb 12, 2025
1191756
different plugin
crogoz Feb 12, 2025
ca6969b
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz Feb 12, 2025
a399b9e
.
crogoz Feb 12, 2025
1336054
wip
crogoz Feb 12, 2025
b0a1950
using gradle-utils
crogoz Feb 12, 2025
975ba5d
separate project
crogoz Feb 12, 2025
65bc162
Merge branch 'develop' into cr/graal-1
crogoz Feb 12, 2025
23b563f
name
crogoz Feb 12, 2025
8db364f
keep :
crogoz Feb 12, 2025
22a9f7d
fix path
crogoz Feb 13, 2025
8456625
publication
crogoz Feb 13, 2025
0825b1b
osExtension
crogoz Feb 13, 2025
561286d
change
crogoz Feb 13, 2025
c492501
circleci check publishLocal
crogoz Feb 13, 2025
4e1e128
glibc or musl
crogoz Feb 13, 2025
ecbc2ed
only bin or exe
crogoz Feb 13, 2025
cc3a0f2
publishing
crogoz Feb 14, 2025
adf33ac
if else CI
crogoz Feb 14, 2025
76ea3fc
fix getEnv
crogoz Feb 14, 2025
c8bc7a5
fix
crogoz Feb 14, 2025
3a8850d
typo
crogoz Feb 14, 2025
6b9fa1f
old circle-all job
crogoz Feb 14, 2025
072f22c
Merge branch 'cr/graal-1' into cr/use-graal-image
crogoz Feb 14, 2025
fa45c1e
fix native
crogoz Feb 14, 2025
67ab915
fix
crogoz Feb 17, 2025
0f28770
Merge branch 'develop' into cr/use-graal-image
crogoz Feb 17, 2025
c9e4c0f
.
crogoz Feb 17, 2025
fbf59e7
gradle utils
crogoz Feb 17, 2025
0d39ef0
spotless
crogoz Feb 17, 2025
25330df
formatDiff
crogoz Feb 18, 2025
0937083
cleanup
crogoz Feb 18, 2025
9421d1a
Merge branch 'cr/use-graal-image' into cr/21-with-graal
crogoz Feb 18, 2025
e92581d
reflection
crogoz Feb 18, 2025
8f22a3a
wip
crogoz Feb 18, 2025
53484ad
cleanup
crogoz Feb 18, 2025
d47bc98
cleanup
crogoz Feb 18, 2025
7e40b3a
cleanup
crogoz Feb 18, 2025
509e0d8
separate 21
crogoz Feb 18, 2025
c149cd0
rm file
crogoz Feb 18, 2025
b800735
.
crogoz Feb 18, 2025
1119558
.
crogoz Feb 19, 2025
3baf58a
transform
crogoz Feb 19, 2025
1f084a1
no usenativeImageClasspath
crogoz Feb 20, 2025
c3186d0
Merge branch 'cr/use-graal-image' into cr/21-with-graal
crogoz Feb 20, 2025
9d34e07
Merge branch 'develop' into cr/21-with-graal
crogoz Feb 28, 2025
9fc2a0e
reflection, tests on 21, configuration of palantir-java-format
crogoz Mar 3, 2025
6b91edb
Add generated changelog entries
svc-changelog Mar 3, 2025
56e0514
fixes
crogoz Mar 3, 2025
d52e27b
Merge branch 'cr/21-with-graal' of github.com:palantir/palantir-java-…
crogoz Mar 3, 2025
76ff02b
fix test
crogoz Mar 3, 2025
75cc00f
fixes
crogoz Mar 3, 2025
95cf36a
fix dependencies
crogoz Mar 4, 2025
a91bb6e
fix
crogoz Mar 4, 2025
ab167a3
run tests with java21
crogoz Mar 4, 2025
cf73515
spotless
crogoz Mar 4, 2025
f4417c4
allow _ in binding pattern
crogoz Mar 5, 2025
8c9e58c
palantir java format
crogoz Mar 5, 2025
a36dd7b
tests not working?
crogoz Mar 5, 2025
69f5bbc
tests not working?
crogoz Mar 5, 2025
eca861b
Merge branch 'cr/21-with-graal' of github.com:palantir/palantir-java-…
crogoz Mar 5, 2025
8c34ee5
test
crogoz Mar 5, 2025
494d543
one last test is failing
crogoz Mar 6, 2025
0bb310b
move to palantir-java-format-tests
crogoz Mar 6, 2025
2ca81c6
.
crogoz Mar 7, 2025
c70baf8
Merge branch 'develop' into cr/21-with-graal
crogoz Mar 10, 2025
73f14e3
Merge branch 'develop' into cr/21-with-graal
crogoz Mar 10, 2025
2987918
reflowing is not currently supported in intellij plugin - fix in anot…
crogoz Mar 10, 2025
5ca751c
back to 17
crogoz Mar 10, 2025
ff54182
javaVersion
crogoz Mar 10, 2025
e1eba56
no newlines
crogoz Mar 10, 2025
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
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ apply plugin: 'com.palantir.git-version'
apply plugin: 'com.palantir.jdks'
apply plugin: 'com.palantir.jdks.latest'
apply plugin: 'com.palantir.baseline'
apply plugin: 'com.palantir.baseline-java-versions'
apply plugin: 'com.palantir.consistent-versions'
apply plugin: 'com.palantir.baseline-java-versions'

Expand Down Expand Up @@ -68,6 +69,7 @@ subprojects {

javaVersions {
libraryTarget = 17
runtime = 21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libraryTarget implies runtime, I think we can just leave this out to keep it like our other Gradle plugins.

}

jdks {
Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1211.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Java 21 with Graal support
links:
- https://github.com/palantir/palantir-java-format/pull/1211
6 changes: 3 additions & 3 deletions gradle-palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ dependencies {
implementation project(':palantir-java-format-jdk-bootstrap')
implementation 'com.palantir.gradle.utils:platform'

testImplementation project(':palantir-java-format')
testImplementation 'com.netflix.nebula:nebula-test'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.junit.vintage:junit-vintage-engine'
testImplementation 'org.assertj:assertj-core'
testImplementation project(':palantir-java-format')

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

pluginClasspath 'com.diffplug.spotless:spotless-plugin-gradle'
}
Expand Down Expand Up @@ -90,7 +91,6 @@ dependencies {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements, 'nativeImage'))
}
}

}

tasks.register("copyNativeImage", Copy.class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static final class State implements Serializable {
* Build a cacheable state for spotless from the given jars, that uses the given {@link FormatterService}.
*
* @param jars The jars that contain the palantir-java-format implementation. This is only used for caching and
* up-to-dateness purposes.
* up-to-dateness purposes.
*/
State(Iterable<File> jars, Supplier<FormatterService> memoizedFormatter) throws IOException {
this.jarsSignature = FileSignature.signAsSet(jars);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright 2019 Palantir Technologies Inc. All rights reserved.
* (c) Copyright 2025 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,27 +16,36 @@

package com.palantir.javaformat.gradle;

import com.google.common.base.Splitter
import com.palantir.javaformat.bootstrap.BootstrappingFormatterService
import com.palantir.javaformat.java.FormatterService
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource

import java.util.stream.Stream

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.io.ByteStreams;
import com.palantir.javaformat.java.FormatterServiceImpl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import com.palantir.javaformat.bootstrap.NativeImageFormatterService;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class FormatDiffTest {

private static final CLASSPATH_FILE = new File("build/impl.classpath")
private static final NATIVE_IMAGE_FILE = new File("build/nativeImage.path")

@TempDir
Path repo;

Expand All @@ -58,8 +67,9 @@ void parsing_git_diff_output_works() throws IOException {
strings);
}

@Test
void reformat_a_subpath_of_a_git_directory_for_only_changed_lines() throws IOException, InterruptedException {
@ParameterizedTest
@MethodSource("getFormatters")
void reformat_a_subpath_of_a_git_directory_for_only_changed_lines(FormatterService formatterService) throws IOException, InterruptedException {
runCommandInRepo("git", "init");
runCommandInRepo("git", "config", "user.name", "Test User");
runCommandInRepo("git", "config", "user.email", "[email protected]");
Expand All @@ -77,7 +87,7 @@ void reformat_a_subpath_of_a_git_directory_for_only_changed_lines() throws IOExc

runCommandInRepo("git", "add", "-N", ".");

FormatDiff.formatDiff(subdir, new FormatterServiceImpl());
FormatDiff.formatDiff(subdir, formatterService);

assertThat(reformatMe).hasContent("class ReformatMe {}");
assertThat(dontTouchMe).hasContent(" class DontTouchMe {}");
Expand All @@ -95,4 +105,27 @@ private void runCommandInRepo(String... args) throws IOException, InterruptedExc

Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0: " + stderr);
}

private static Stream<FormatterService> getFormatters() {
return Stream.of(
new BootstrappingFormatterService(
javaBinPath(), Runtime.version().feature(), getClasspath()),
new NativeImageFormatterService(
Path.of(NATIVE_IMAGE_FILE.text)));
}

private static getClasspath() {
return Splitter.on(':')
.trimResults()
.omitEmptyStrings()
.splitToStream(CLASSPATH_FILE.text)
.map(Path::of)
.collect(Collectors.toList());
}

private static Path javaBinPath() {
String javaHome = Preconditions.checkNotNull(System.getProperty("java.home"), "java.home property not set");
return Path.of(javaHome).resolve("bin").resolve("java");
}

}
1 change: 1 addition & 0 deletions idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

apply plugin: 'java'
apply plugin: 'com.palantir.external-publish-intellij'

def name = "palantir-java-format"
Expand Down
2 changes: 1 addition & 1 deletion palantir-java-format-benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
jmhImplementation 'org.openjdk.jmh:jmh-core'
jmhImplementation 'org.openjdk.jmh:jmh-generator-annprocess'
formatterNativeJars project(':palantir-java-format')
formatterNativeImage(project(':palantir-java-format')) {
formatterNativeImage(project(':palantir-java-format-native')) {
attributes {
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, project.objects.named(LibraryElements, 'nativeImage'))
}
Expand Down
1 change: 0 additions & 1 deletion palantir-java-format-jdk-bootstrap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ tasks.named('test', Test.class) {
inputs.files(configurations.named('formatterNativeImage'))
environment.put('NATIVE_IMAGE_CLASSPATH', configurations.formatterNativeImage.asPath)
}

2 changes: 1 addition & 1 deletion palantir-java-format-native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ graalvmNative {
sharedLibrary = false
classpath.setFrom(configurations.named('runtimeClasspath'))
configurationFileDirectories.from(file('src/main/resources/META-INF/native-image'))
buildArgs.addAll("-H:ConfigurationFileDirectories=${projectDir}/src/main/resources/META-INF/native-image",
buildArgs.addAll(
'-H:+UnlockExperimentalVMOptions',
'-H:IncludeResourceBundles=com.sun.tools.javac.resources.compiler',
'-H:IncludeResourceBundles=com.sun.tools.javac.resources.javac',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
}
]
},
{
"type": "com.palantir.javaformat.java.java21.Java21InputAstVisitor",
"methods": [
{
"name": "<init>",
"parameterTypes": [
"com.palantir.javaformat.OpsBuilder",
"int"
]
}
]
},
{
"type": "com.sun.source.tree.BindingPatternTree"
},
Expand Down
4 changes: 4 additions & 0 deletions palantir-java-format-spi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ tasks.withType(JavaCompile).named('compileJava') {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

javaVersion {
target = 21
}
4 changes: 4 additions & 0 deletions palantir-java-format/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ tasks.named("test") {
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
}

javaVersion {
target = 21
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,10 @@ static JavaOutput format(
OpsBuilder opsBuilder = new OpsBuilder(javaInput);

JavaInputAstVisitor visitor;
if (getRuntimeVersion() >= 14) {
try {
visitor = Class.forName("com.palantir.javaformat.java.java14.Java14InputAstVisitor")
.asSubclass(JavaInputAstVisitor.class)
.getConstructor(OpsBuilder.class, int.class)
.newInstance(opsBuilder, options.indentationMultiplier());
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (getRuntimeVersion() >= 21) {
visitor = createVisitor("com.palantir.javaformat.java.java21.Java21InputAstVisitor", opsBuilder, options);
} else if (getRuntimeVersion() >= 14) {
visitor = createVisitor("com.palantir.javaformat.java.java14.Java14InputAstVisitor", opsBuilder, options);
} else {
visitor = new JavaInputAstVisitor(opsBuilder, options.indentationMultiplier());
}
Expand Down Expand Up @@ -206,6 +201,18 @@ static int getRuntimeVersion() {
return Runtime.version().feature();
}

private static JavaInputAstVisitor createVisitor(
final String className, final OpsBuilder builder, final JavaFormatterOptions options) {
try {
return Class.forName(className)
.asSubclass(JavaInputAstVisitor.class)
.getConstructor(OpsBuilder.class, int.class)
.newInstance(builder, options.indentationMultiplier());
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage());
}
}

static boolean errorDiagnostic(Diagnostic<?> input) {
if (input.getKind() != Diagnostic.Kind.ERROR) {
return false;
Expand Down Expand Up @@ -254,7 +261,7 @@ public String formatSource(String input) throws FormatterException {
* @return the output string
* @throws FormatterException if the input string cannot be parsed
* @see <a href="https://google.github.io/styleguide/javaguide.html#s3.3.3-import-ordering-and-spacing">Google Java
* Style Guide - 3.3.3 Import ordering and spacing</a>
* Style Guide - 3.3.3 Import ordering and spacing</a>
*/
public String formatSourceAndFixImports(String input) throws FormatterException {
input = ImportOrderer.reorderImports(input, options.style());
Expand All @@ -271,7 +278,7 @@ public String formatSourceAndFixImports(String input) throws FormatterException
* @return the output string
* @throws FormatterException if the input string cannot be parsed
* @see <a href="https://google.github.io/styleguide/javaguide.html#s3.3.3-import-ordering-and-spacing">Google Java
* Style Guide - 3.3.3 Import ordering and spacing</a>
* Style Guide - 3.3.3 Import ordering and spacing</a>
*/
public String fixImports(String input) throws FormatterException {
return ImportOrderer.reorderImports(RemoveUnusedImports.removeUnusedImports(input), options.style());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1869,13 +1869,13 @@ protected void visitSwitch(ExpressionTree expression, List<? extends CaseTree> c
tokenBreakTrailingComment("{", plusTwo);
builder.blankLineWanted(BlankLineWanted.NO);
builder.open(plusTwo);
boolean first = true;
boolean afterFirstToken = false;
for (CaseTree caseTree : cases) {
if (!first) {
if (afterFirstToken) {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
scan(caseTree, null);
first = false;
afterFirstToken = true;
}
builder.close();
builder.forcedBreak();
Expand Down Expand Up @@ -2928,7 +2928,7 @@ private void visitDotWithPrefix(
* <li>{@code foo().bar()[0]}
* <li>{@code foo().bar()[0][0]}
* </ul>
*
* <p>
* Whereas an expression like a name {@code com.palantir.foo.bar.Baz} would not.
*/
private boolean shouldHaveColumnLimit(ExpressionTree expr) {
Expand Down Expand Up @@ -3523,7 +3523,7 @@ private void maybeAddDims(Deque<List<? extends AnnotationTree>> annotations) {
*
* @param dimExpressions an ordered list of dimension expressions (e.g. the {@code 0} in {@code new int[0]}
* @param annotations an ordered list of type annotations grouped by dimension (e.g. {@code [[@A, @B], [@C]]} for
* {@code int @A [] @B @C []}
* {@code int @A [] @B @C []}
*/
private void maybeAddDims(Deque<ExpressionTree> dimExpressions, Deque<List<? extends AnnotationTree>> annotations) {
boolean lastWasAnnotation = false;
Expand Down Expand Up @@ -3679,6 +3679,7 @@ protected void addBodyDeclarations(
}
}
}

/** Gets the permits clause for the given node. This is only available in Java 15 and later. */
protected List<? extends Tree> getPermitsClause(ClassTree node) {
return ImmutableList.of();
Expand Down
Loading