2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* 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, derived from Akka.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-12 01:41:54 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2019-2022 Lightbend Inc. <https://www.lightbend.com>
|
2019-01-12 01:41:54 +08:00
|
|
|
*/
|
|
|
|
|
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.ProjectFileIgnoreSupport
|
2019-01-12 01:41:54 +08:00
|
|
|
import com.lightbend.sbt.JavaFormatterPlugin
|
2020-04-24 15:12:01 +03:00
|
|
|
import sbt.{ AutoPlugin, PluginTrigger, Plugins }
|
2019-01-12 01:41:54 +08:00
|
|
|
|
2019-01-16 11:44:07 +01:00
|
|
|
object JavaFormatter extends AutoPlugin {
|
2019-01-12 01:41:54 +08:00
|
|
|
|
|
|
|
|
override def trigger = PluginTrigger.AllRequirements
|
|
|
|
|
|
|
|
|
|
override def requires: Plugins = JavaFormatterPlugin
|
|
|
|
|
|
2019-01-16 11:44:07 +01:00
|
|
|
private val ignoreConfigFileName: String = ".sbt-java-formatter.conf"
|
|
|
|
|
private val descriptor: String = "sbt-java-formatter"
|
2019-01-12 01:41:54 +08:00
|
|
|
|
2023-02-16 10:39:18 +01:00
|
|
|
private val formatOnCompile = !sys.props.contains("pekko.no.discipline")
|
2020-04-24 15:12:01 +03:00
|
|
|
|
2019-01-12 01:41:54 +08:00
|
|
|
import JavaFormatterPlugin.autoImport._
|
|
|
|
|
import sbt.Keys._
|
|
|
|
|
import sbt._
|
|
|
|
|
import sbt.io._
|
|
|
|
|
|
2021-02-01 15:38:29 +00:00
|
|
|
override def projectSettings: Seq[Def.Setting[_]] =
|
|
|
|
|
Seq(
|
2022-11-03 09:46:22 +01:00
|
|
|
// below is for sbt java formatter
|
2021-05-25 12:50:51 +02:00
|
|
|
javafmt / excludeFilter := {
|
2021-02-01 15:38:29 +00:00
|
|
|
val ignoreSupport =
|
2021-05-25 12:50:51 +02:00
|
|
|
new ProjectFileIgnoreSupport((ThisBuild / baseDirectory).value / ignoreConfigFileName, descriptor)
|
2021-02-01 15:38:29 +00:00
|
|
|
val simpleFileFilter = new SimpleFileFilter(file => ignoreSupport.isIgnoredByFileOrPackages(file))
|
2021-05-25 12:50:51 +02:00
|
|
|
simpleFileFilter || (javafmt / excludeFilter).value
|
2021-02-01 15:38:29 +00:00
|
|
|
},
|
|
|
|
|
javafmtOnCompile := formatOnCompile)
|
2019-01-12 01:41:54 +08:00
|
|
|
}
|