build: make sure ignore files are searched for in base directory
Previously, the paths were just relative paths and depended on the working directory of the sbt process. However, that's unreliable when the akka sources are included in another build as in the akka-http nightlies.
This commit is contained in:
parent
75cb436ce7
commit
f44b777e76
3 changed files with 35 additions and 33 deletions
|
|
@ -6,15 +6,14 @@ import akka.ProjectFileIgnoreSupport
|
||||||
import com.lightbend.sbt.JavaFormatterPlugin
|
import com.lightbend.sbt.JavaFormatterPlugin
|
||||||
import sbt.{AutoPlugin, PluginTrigger, Plugins}
|
import sbt.{AutoPlugin, PluginTrigger, Plugins}
|
||||||
|
|
||||||
object JavaFormatter extends AutoPlugin with ProjectFileIgnoreSupport {
|
object JavaFormatter extends AutoPlugin {
|
||||||
|
|
||||||
override def trigger = PluginTrigger.AllRequirements
|
override def trigger = PluginTrigger.AllRequirements
|
||||||
|
|
||||||
override def requires: Plugins = JavaFormatterPlugin
|
override def requires: Plugins = JavaFormatterPlugin
|
||||||
|
|
||||||
final override protected val ignoreConfigFileName: String = ".sbt-java-formatter.conf"
|
private val ignoreConfigFileName: String = ".sbt-java-formatter.conf"
|
||||||
|
private val descriptor: String = "sbt-java-formatter"
|
||||||
final override protected val descriptor: String = "sbt-java-formatter"
|
|
||||||
|
|
||||||
import JavaFormatterPlugin.autoImport._
|
import JavaFormatterPlugin.autoImport._
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
|
|
@ -24,7 +23,8 @@ object JavaFormatter extends AutoPlugin with ProjectFileIgnoreSupport {
|
||||||
override def projectSettings: Seq[Def.Setting[_]] = Seq(
|
override def projectSettings: Seq[Def.Setting[_]] = Seq(
|
||||||
//below is for sbt java formatter
|
//below is for sbt java formatter
|
||||||
(excludeFilter in format) := {
|
(excludeFilter in format) := {
|
||||||
val simpleFileFilter = new SimpleFileFilter(file => isIgnoredByFileOrPackages(file))
|
val ignoreSupport = new ProjectFileIgnoreSupport((baseDirectory in ThisBuild).value / ignoreConfigFileName, descriptor)
|
||||||
|
val simpleFileFilter = new SimpleFileFilter(file => ignoreSupport.isIgnoredByFileOrPackages(file))
|
||||||
simpleFileFilter || (excludeFilter in format).value
|
simpleFileFilter || (excludeFilter in format).value
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,37 +7,41 @@ package akka
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import com.typesafe.config.ConfigFactory
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import sbt.AutoPlugin
|
||||||
|
import sbt.Def
|
||||||
import sbt.file
|
import sbt.file
|
||||||
import sbt.internal.sbtscalafix.Compat
|
import sbt.internal.sbtscalafix.Compat
|
||||||
|
|
||||||
trait ProjectFileIgnoreSupport {
|
class ProjectFileIgnoreSupport(ignoreConfigFile: File, descriptor: String) {
|
||||||
protected val stdoutLogger = Compat.ConsoleLogger(System.out)
|
private val stdoutLogger = Compat.ConsoleLogger(System.out)
|
||||||
|
|
||||||
protected def ignoreConfigFileName: String
|
private lazy val ignoreConfig = {
|
||||||
|
require(ignoreConfigFile.exists(), s"Expected ignore configuration for $descriptor at ${ignoreConfigFile.getAbsolutePath} but was missing")
|
||||||
|
ConfigFactory.parseFile(ignoreConfigFile)
|
||||||
|
}
|
||||||
|
|
||||||
protected def descriptor: String
|
private lazy val ignoredFiles: Set[String] = {
|
||||||
|
|
||||||
lazy val ignoredFiles: Set[String] = {
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
val config = ConfigFactory.parseFile(file(ignoreConfigFileName))
|
stdoutLogger.debug(s"Loading ignored-files from $ignoreConfigFile:[${ignoreConfig.origin().url().toURI.getPath}]")
|
||||||
stdoutLogger.debug(s"Loading ignored-files from $ignoreConfigFileName:[${config.origin().url().toURI.getPath}]")
|
ignoreConfig
|
||||||
config
|
|
||||||
.getStringList("ignored-files")
|
.getStringList("ignored-files")
|
||||||
.asScala
|
.asScala
|
||||||
.toSet
|
.toSet
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy val ignoredPackages: Set[String] = {
|
private lazy val ignoredPackages: Set[String] = {
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
val config = ConfigFactory.parseFile(file(ignoreConfigFileName))
|
stdoutLogger.debug(s"Loading ignored-packages from $ignoreConfigFile:[${ignoreConfig.origin().url().toURI.getPath}]")
|
||||||
stdoutLogger.debug(s"Loading ignored-packages from $ignoreConfigFileName:[${config.origin().url().toURI.getPath}]")
|
ignoreConfig
|
||||||
config
|
|
||||||
.getStringList("ignored-packages")
|
.getStringList("ignored-packages")
|
||||||
.asScala
|
.asScala
|
||||||
.toSet
|
.toSet
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def isIgnoredByFile(file: File): Boolean = {
|
def isIgnoredByFileOrPackages(file: File): Boolean =
|
||||||
|
isIgnoredByFile(file) || isIgnoredByPackages(file)
|
||||||
|
|
||||||
|
private def isIgnoredByFile(file: File): Boolean = {
|
||||||
val ignoredByFile = ignoredFiles(file.getName)
|
val ignoredByFile = ignoredFiles(file.getName)
|
||||||
if (ignoredByFile) {
|
if (ignoredByFile) {
|
||||||
stdoutLogger.debug(s"$descriptor ignored file with file name:${file.getName} file:[${file.toPath}]")
|
stdoutLogger.debug(s"$descriptor ignored file with file name:${file.getName} file:[${file.toPath}]")
|
||||||
|
|
@ -45,7 +49,7 @@ trait ProjectFileIgnoreSupport {
|
||||||
ignoredByFile
|
ignoredByFile
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def isIgnoredByPackages(file: File): Boolean = {
|
private def isIgnoredByPackages(file: File): Boolean = {
|
||||||
val ignoredByPackages = ignoredPackages.exists(pkg => {
|
val ignoredByPackages = ignoredPackages.exists(pkg => {
|
||||||
getPackageName(file.toURI.toString) match {
|
getPackageName(file.toURI.toString) match {
|
||||||
case Some(packageName) =>
|
case Some(packageName) =>
|
||||||
|
|
@ -60,11 +64,7 @@ trait ProjectFileIgnoreSupport {
|
||||||
ignoredByPackages
|
ignoredByPackages
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def isIgnoredByFileOrPackages(file: File): Boolean = {
|
private def getPackageName(fileName: String): Option[String] = {
|
||||||
isIgnoredByFile(file) || isIgnoredByPackages(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected def getPackageName(fileName: String): Option[String] = {
|
|
||||||
def getPackageName0(fileType: String): String = {
|
def getPackageName0(fileType: String): String = {
|
||||||
import java.io.{File => JFile}
|
import java.io.{File => JFile}
|
||||||
fileName.split(JFile.separatorChar)
|
fileName.split(JFile.separatorChar)
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,24 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sbt
|
package sbt
|
||||||
|
import Keys.baseDirectory
|
||||||
|
|
||||||
import akka.ProjectFileIgnoreSupport
|
import akka.ProjectFileIgnoreSupport
|
||||||
import sbt.Keys.unmanagedSources
|
import sbt.Keys.unmanagedSources
|
||||||
|
|
||||||
trait ScalafixSupport extends ProjectFileIgnoreSupport {
|
trait ScalafixSupport {
|
||||||
|
private val ignoreConfigFileName: String = ".scalafix.conf"
|
||||||
final override protected val ignoreConfigFileName: String = ".scalafix.conf"
|
private val descriptor: String = "scalafix"
|
||||||
|
|
||||||
final override protected val descriptor: String = "scalafix"
|
|
||||||
|
|
||||||
protected def ignore(configKey: ConfigKey): Def.Setting[Task[Seq[File]]] = {
|
protected def ignore(configKey: ConfigKey): Def.Setting[Task[Seq[File]]] = {
|
||||||
import scalafix.sbt.ScalafixPlugin.autoImport._
|
import scalafix.sbt.ScalafixPlugin.autoImport._
|
||||||
|
|
||||||
unmanagedSources.in(configKey, scalafix) :=
|
unmanagedSources.in(configKey, scalafix) := {
|
||||||
|
val ignoreSupport = new ProjectFileIgnoreSupport((baseDirectory in ThisBuild).value / ignoreConfigFileName, descriptor)
|
||||||
|
|
||||||
unmanagedSources.in(configKey, scalafix).value
|
unmanagedSources.in(configKey, scalafix).value
|
||||||
.filterNot(file => isIgnoredByFileOrPackages(file))
|
.filterNot(file => ignoreSupport.isIgnoredByFileOrPackages(file))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue