Skip to content

Commit 9c226ac

Browse files
committed
Support Palantir Java Format
1 parent 01c87a7 commit 9c226ac

File tree

11 files changed

+90
-6
lines changed

11 files changed

+90
-6
lines changed

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ lazy val plugin = project
1616
ScmInfo(url("https://github.com/sbt/sbt-java-formatter"), "scm:git:git@github.com:sbt/sbt-java-formatter.git")),
1717
developers := List(
1818
Developer("ktoso", "Konrad 'ktoso' Malawski", "<ktoso@project13.pl>", url("https://github.com/ktoso"))),
19-
libraryDependencies ++= Seq("com.google.googlejavaformat" % "google-java-format" % "1.24.0"),
19+
libraryDependencies ++= Seq(
20+
// "com.google.googlejavaformat" % "google-java-format" % "1.24.0",
21+
"com.palantir.javaformat" % "palantir-java-format" % "2.62.0"
22+
),
2023
startYear := Some(2015),
2124
description := "Formats Java code in your project.",
2225
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0.html")),

plugin/src/main/scala/com/github/sbt/JavaFormatterPlugin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ package com.github.sbt
1818

1919
import _root_.sbt.Keys._
2020
import _root_.sbt.{ Def, _ }
21-
import com.google.googlejavaformat.java.JavaFormatterOptions
2221
import com.github.sbt.javaformatter.JavaFormatter
22+
import com.palantir.javaformat.java.JavaFormatterOptions
2323

2424
@deprecated("Use javafmtOnCompile setting instead", "0.5.1")
2525
object AutomateJavaFormatterPlugin extends AutoPlugin {

plugin/src/main/scala/com/github/sbt/javaformatter/JavaFormatter.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import _root_.sbt.Keys._
2020
import _root_.sbt._
2121
import _root_.sbt.util.CacheImplicits._
2222
import _root_.sbt.util.{ CacheStoreFactory, FileInfo, Logger }
23-
import com.google.googlejavaformat.java.{ Formatter, JavaFormatterOptions }
23+
import com.palantir.javaformat.java.{ Formatter, JavaFormatterOptions }
2424
import scala.collection.immutable.Seq
2525

2626
object JavaFormatter {
@@ -33,7 +33,7 @@ object JavaFormatter {
3333
cacheStoreFactory: CacheStoreFactory,
3434
options: JavaFormatterOptions): Unit = {
3535
val files = sourceDirectories.descendantsExcept(includeFilter, excludeFilter).get().toList
36-
cachedFormatSources(cacheStoreFactory, files, streams.log)(new Formatter(options))
36+
cachedFormatSources(cacheStoreFactory, files, streams.log)(Formatter.createFormatter(options))
3737
}
3838

3939
def check(
@@ -45,7 +45,8 @@ object JavaFormatter {
4545
cacheStoreFactory: CacheStoreFactory,
4646
options: JavaFormatterOptions): Boolean = {
4747
val files = sourceDirectories.descendantsExcept(includeFilter, excludeFilter).get().toList
48-
val analysis = cachedCheckSources(cacheStoreFactory, baseDir, files, streams.log)(new Formatter(options))
48+
val analysis =
49+
cachedCheckSources(cacheStoreFactory, baseDir, files, streams.log)(Formatter.createFormatter(options))
4950
trueOrBoom(analysis)
5051
}
5152

plugin/src/sbt-test/sbt-java-formatter/aosp-style/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import com.google.googlejavaformat.java.JavaFormatterOptions
1+
import com.palantir.javaformat.java.JavaFormatterOptions
22
// no settings needed
33

44
ThisBuild / javafmtStyle := JavaFormatterOptions.Style.AOSP
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import com.palantir.javaformat.java.JavaFormatterOptions
2+
// no settings needed
3+
4+
ThisBuild / javafmtStyle := JavaFormatterOptions.Style.PALANTIR
5+
ThisBuild / javafmtOnCompile := true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % System.getProperty("plugin.version"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lightbend;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import java.util.stream.Collectors;
6+
7+
public class BadFormatting {
8+
BadFormatting() {
9+
example();
10+
}
11+
12+
public void example() {
13+
var a = List.of("", "a", "b", "c", "d").stream()
14+
.filter(s -> !s.isEmpty())
15+
.map(s -> String.format("%s-%s-%s", s, s.toLowerCase(), s.toUpperCase()))
16+
.map(Objects::toString)
17+
.collect(Collectors.joining());
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.lightbend;
2+
3+
import java.util.stream.Collectors;
4+
import java.util.Objects;
5+
import java.util.List;
6+
7+
public class BadFormatting {
8+
BadFormatting () {example();}
9+
public void example () {
10+
var a = List.of("", "a", "b", "c", "d").stream().filter(s -> !s.isEmpty()).map(s -> String.format("%s-%s-%s", s, s.toLowerCase(), s.toUpperCase())).map(Objects::toString).collect(Collectors.joining());
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lightbend;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import java.util.stream.Collectors;
6+
7+
public class BadFormatting {
8+
BadFormatting() {
9+
example();
10+
}
11+
12+
public void example() {
13+
var a = List.of("", "a", "b", "c", "d").stream()
14+
.filter(s -> !s.isEmpty())
15+
.map(s -> String.format("%s-%s-%s", s, s.toLowerCase(), s.toUpperCase()))
16+
.map(Objects::toString)
17+
.collect(Collectors.joining());
18+
}
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.lightbend;
2+
3+
import java.util.stream.Collectors;
4+
import java.util.Objects;
5+
import java.util.List;
6+
7+
public class BadFormatting {
8+
BadFormatting () {example();}
9+
public void example () {
10+
var a = List.of("", "a", "b", "c", "d").stream().filter(s -> !s.isEmpty()).map(s -> String.format("%s-%s-%s", s, s.toLowerCase(), s.toUpperCase())).map(Objects::toString).collect(Collectors.joining());
11+
}
12+
}

0 commit comments

Comments
 (0)