This is an automated email from the ASF dual-hosted git repository.
fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-persistence-jdbc.git
The following commit(s) were added to refs/heads/main by this push:
new 1faff6d Javafmt upgrade (#438)
1faff6d is described below
commit 1faff6de3cc6a0cf8d8a0e84033178ea9f611d8e
Author: PJ Fanning <[email protected]>
AuthorDate: Thu Jan 29 10:17:14 2026 +0100
Javafmt upgrade (#438)
* Update sbt-java-formatter to 0.10.0
* don't reformat JavadslSnippets.java
---------
Co-authored-by: Scala Steward <[email protected]>
---
.sbt-java-formatter.conf | 9 ++++
.scala-steward.conf | 2 +
project/JavaFormatter.scala | 40 ++++++++++++++
project/ProjectFileIgnoreSupport.scala | 97 ++++++++++++++++++++++++++++++++++
project/plugins.sbt | 2 +-
5 files changed, 149 insertions(+), 1 deletion(-)
diff --git a/.sbt-java-formatter.conf b/.sbt-java-formatter.conf
new file mode 100644
index 0000000..341a8c0
--- /dev/null
+++ b/.sbt-java-formatter.conf
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: Apache-2.0
+
+ignored-files = [
+ // snippets used in docs and we don't want the imports reordered
+ "JavadslSnippets.java"
+]
+
+ignored-packages = [
+]
diff --git a/.scala-steward.conf b/.scala-steward.conf
index 278282a..4c8f5d8 100644
--- a/.scala-steward.conf
+++ b/.scala-steward.conf
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: Apache-2.0
+
updates.ignore = [
]
diff --git a/project/JavaFormatter.scala b/project/JavaFormatter.scala
new file mode 100644
index 0000000..f842266
--- /dev/null
+++ b/project/JavaFormatter.scala
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2019-2022 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+import com.github.sbt.JavaFormatterPlugin
+import sbt.{ AutoPlugin, PluginTrigger, Plugins }
+
+object JavaFormatter extends AutoPlugin {
+
+ override lazy val trigger = PluginTrigger.AllRequirements
+
+ override lazy val requires: Plugins = JavaFormatterPlugin
+
+ private val ignoreConfigFileName: String = ".sbt-java-formatter.conf"
+ private val descriptor: String = "sbt-java-formatter"
+
+ import JavaFormatterPlugin.autoImport._
+ import sbt.Keys._
+ import sbt._
+ import sbt.io._
+
+ override lazy val projectSettings: Seq[Def.Setting[_]] =
+ Seq(
+ // below is for sbt java formatter
+ javafmt / excludeFilter := {
+ val ignoreSupport =
+ new ProjectFileIgnoreSupport((ThisBuild / baseDirectory).value /
ignoreConfigFileName, descriptor)
+ val simpleFileFilter = new SimpleFileFilter(file =>
ignoreSupport.isIgnoredByFileOrPackages(file))
+ simpleFileFilter || (javafmt / excludeFilter).value
+ })
+}
diff --git a/project/ProjectFileIgnoreSupport.scala
b/project/ProjectFileIgnoreSupport.scala
new file mode 100644
index 0000000..c56bab6
--- /dev/null
+++ b/project/ProjectFileIgnoreSupport.scala
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2019-2022 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+import java.io.File
+
+import com.typesafe.config.ConfigFactory
+import sbt.ConsoleLogger
+
+class ProjectFileIgnoreSupport(ignoreConfigFile: File, descriptor: String) {
+ private lazy val stdoutLogger = ConsoleLogger(System.out)
+
+ private val javaSourceDirectories = Set("java")
+
+ private val scalaSourceDirectories = Set("scala")
+
+ private lazy val ignoreConfig = {
+ require(
+ ignoreConfigFile.exists(),
+ s"Expected ignore configuration for $descriptor at
${ignoreConfigFile.getAbsolutePath} but was missing")
+ ConfigFactory.parseFile(ignoreConfigFile)
+ }
+
+ private lazy val ignoredFiles: Set[String] = {
+ import scala.jdk.CollectionConverters._
+ stdoutLogger.debug(s"Loading ignored-files from
$ignoreConfigFile:[${ignoreConfig.origin().url().toURI.getPath}]")
+ ignoreConfig.getStringList("ignored-files").asScala.toSet
+ }
+
+ private lazy val ignoredPackages: Set[String] = {
+ import scala.jdk.CollectionConverters._
+ stdoutLogger.debug(
+ s"Loading ignored-packages from
$ignoreConfigFile:[${ignoreConfig.origin().url().toURI.getPath}]")
+ ignoreConfig.getStringList("ignored-packages").asScala.toSet
+ }
+
+ def isIgnoredByFileOrPackages(file: File): Boolean =
+ isIgnoredByFile(file) || isIgnoredByPackages(file)
+
+ private def isIgnoredByFile(file: File): Boolean = {
+ val ignoredByFile = ignoredFiles(file.getName)
+ if (ignoredByFile) {
+ stdoutLogger.debug(s"$descriptor ignored file with file
name:${file.getName} file:[${file.toPath}]")
+ }
+ ignoredByFile
+ }
+
+ private def isIgnoredByPackages(file: File): Boolean = {
+ val ignoredByPackages = ignoredPackages.exists(pkg => {
+ getPackageName(file.toURI.toString) match {
+ case Some(packageName) =>
+ val ignored = packageName.startsWith(pkg)
+ if (ignored) {
+ stdoutLogger.debug(
+ s"$descriptor ignored file with pkg:$pkg for
package:$packageName file:[${file.toPath}] ")
+ }
+ ignored
+ case None => false
+ }
+ })
+ ignoredByPackages
+ }
+
+ private def getPackageName(fileName: String): Option[String] = {
+ def getPackageName0(sourceDirectories: Set[String]): String = {
+ import java.io.{ File => JFile }
+ val packageName = fileName
+ .split(JFile.separatorChar)
+ .dropWhile(part => !sourceDirectories(part))
+ .drop(1)
+ .dropRight(1)
+ .mkString(".")
+ packageName
+ }
+
+ fileName.split('.').lastOption match {
+ case Some(fileType) =>
+ fileType match {
+ case "java" =>
+ Option(getPackageName0(javaSourceDirectories))
+ case "scala" =>
+ Option(getPackageName0(scalaSourceDirectories))
+ case _ => None
+ }
+ case None => None
+ }
+ }
+}
diff --git a/project/plugins.sbt b/project/plugins.sbt
index 88dae41..282deea 100644
--- a/project/plugins.sbt
+++ b/project/plugins.sbt
@@ -11,7 +11,7 @@
addSbtPlugin("com.github.sbt" % "sbt-header" % "5.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")
-addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % "0.9.0")
+addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % "0.10.0")
// release
addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.1")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]