Setup different fix alias on different sub projects and add support to ignore dedicated packages when do scalafix.
Because some sub projects does not enable the MultiNode plugin. Add ignore packages support for scalafix.
This commit is contained in:
parent
82dea881ce
commit
746d0adb45
6 changed files with 135 additions and 46 deletions
|
|
@ -14,3 +14,9 @@ ignored-files = [
|
|||
"FlowZipWithSpec.scala",
|
||||
"FlowZipWithIndexSpec.scala"
|
||||
]
|
||||
|
||||
//ignored pacakges
|
||||
ignored-packages = [
|
||||
"doc",
|
||||
"jdoc"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ enablePlugins(UnidocRoot, TimeStampede, UnidocWithPrValidation, NoPublish, Copyr
|
|||
ScalafixIgnoreFilePlugin)
|
||||
disablePlugins(MimaPlugin)
|
||||
addCommandAlias(
|
||||
name ="fix",
|
||||
name ="fixall",
|
||||
value = ";scalafixEnable;compile:scalafix;test:scalafix;multi-jvm:scalafix;test:compile")
|
||||
|
||||
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.MultiJvm
|
||||
import com.typesafe.tools.mima.plugin.MimaPlugin
|
||||
import spray.boilerplate.BoilerplatePlugin
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
package akka
|
||||
|
||||
import com.typesafe.sbt.MultiJvmPlugin
|
||||
import sbt.{AutoPlugin, Def, PluginTrigger, Plugins, Setting, inConfig}
|
||||
import sbt.{AutoPlugin, Def, PluginTrigger, Plugins, ScalafixSupport, Setting, inConfig}
|
||||
import scalafix.sbt.ScalafixPlugin.autoImport.scalafixConfigSettings
|
||||
|
||||
object ScalafixForMultiNodeScalaTestPlugin extends AutoPlugin with ScalafixIgnoreFileSupport {
|
||||
object ScalafixForMultiNodePlugin extends AutoPlugin with ScalafixSupport {
|
||||
override def trigger: PluginTrigger = allRequirements
|
||||
|
||||
override def requires: Plugins = MultiNodeScalaTest
|
||||
override def requires: Plugins = MultiNode
|
||||
|
||||
import MultiJvmPlugin.autoImport._
|
||||
|
||||
|
|
@ -20,5 +20,9 @@ object ScalafixForMultiNodeScalaTestPlugin extends AutoPlugin with ScalafixIgnor
|
|||
)
|
||||
|
||||
override def projectSettings: Seq[Def.Setting[_]] =
|
||||
Seq(MultiJvm).flatMap(c => inConfig(c)(scalafixConfigSettings(c))) ++ scalafixIgnoredSetting
|
||||
Seq(MultiJvm).flatMap(c => inConfig(c)(scalafixConfigSettings(c))) ++
|
||||
scalafixIgnoredSetting ++ Seq(
|
||||
updateProjectCommands(
|
||||
alias = "fix",
|
||||
value = ";scalafixEnable;compile:scalafix;test:scalafix;multi-jvm:scalafix;test:compile"))
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@
|
|||
package akka
|
||||
|
||||
import sbt.plugins.JvmPlugin
|
||||
import sbt.{AutoPlugin, PluginTrigger, Plugins}
|
||||
import sbt.{AutoPlugin, PluginTrigger, Plugins, ScalafixSupport}
|
||||
|
||||
object ScalafixIgnoreFilePlugin extends AutoPlugin with ScalafixIgnoreFileSupport {
|
||||
object ScalafixIgnoreFilePlugin extends AutoPlugin with ScalafixSupport {
|
||||
override def trigger: PluginTrigger = allRequirements
|
||||
|
||||
override def requires: Plugins = JvmPlugin
|
||||
|
|
@ -15,5 +15,8 @@ object ScalafixIgnoreFilePlugin extends AutoPlugin with ScalafixIgnoreFileSuppor
|
|||
ignore(Test)
|
||||
)
|
||||
|
||||
override def projectSettings: Seq[Def.Setting[_]] = scalafixIgnoredSetting
|
||||
override def projectSettings: Seq[Def.Setting[_]] = scalafixIgnoredSetting ++ Seq(
|
||||
addProjectCommandsIfAbsent(
|
||||
alias = "fix",
|
||||
value = ";scalafixEnable;compile:scalafix;test:scalafix;test:compile"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
package akka
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import sbt.Keys.unmanagedSources
|
||||
import sbt.{ConfigKey, file}
|
||||
import sbt.internal.sbtscalafix.Compat
|
||||
|
||||
trait ScalafixIgnoreFileSupport {
|
||||
import scalafix.sbt.ScalafixPlugin.autoImport._
|
||||
protected def ignore(configKey:ConfigKey) = {
|
||||
lazy val stdoutLogger = Compat.ConsoleLogger(System.out)
|
||||
|
||||
lazy val ignoredFiles:Set[String] = {
|
||||
import scala.collection.JavaConverters._
|
||||
val config = ConfigFactory.parseFile(file(".scalafix.conf"))
|
||||
stdoutLogger.info("ignored-files from .scalaifx.config:" + config.origin().filename())
|
||||
config
|
||||
.getStringList("ignored-files")
|
||||
.asScala
|
||||
.toSet
|
||||
}
|
||||
unmanagedSources.in(configKey, scalafix) :=
|
||||
unmanagedSources.in(configKey, scalafix).value
|
||||
.filterNot(file => {
|
||||
val ignored = ignoredFiles(file.getName)
|
||||
if (ignored){
|
||||
stdoutLogger.info("scalafix ignored file:"+file.toURI)
|
||||
}
|
||||
ignored
|
||||
})
|
||||
}
|
||||
}
|
||||
112
project/ScalafixSupport.scala
Normal file
112
project/ScalafixSupport.scala
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (C) 2018 Lightbend Inc. <https://www.lightbend.com>
|
||||
*/
|
||||
package sbt
|
||||
|
||||
import java.io.File
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import sbt.Keys.unmanagedSources
|
||||
import sbt.internal.sbtscalafix.Compat
|
||||
|
||||
trait ScalafixSupport {
|
||||
|
||||
import scalafix.sbt.ScalafixPlugin.autoImport._
|
||||
|
||||
protected def ignore(configKey: ConfigKey): Def.Setting[Task[Seq[File]]] = {
|
||||
lazy val stdoutLogger = Compat.ConsoleLogger(System.out)
|
||||
|
||||
lazy val ignoredFiles: Set[String] = {
|
||||
import scala.collection.JavaConverters._
|
||||
val config = ConfigFactory.parseFile(file(".scalafix.conf"))
|
||||
stdoutLogger.info(s"Loading ignored-files from .scalaifx.config:[${config.origin().url().toURI.getPath}]")
|
||||
config
|
||||
.getStringList("ignored-files")
|
||||
.asScala
|
||||
.toSet
|
||||
}
|
||||
|
||||
lazy val ignoredPackages: Set[String] = {
|
||||
import scala.collection.JavaConverters._
|
||||
val config = ConfigFactory.parseFile(file(".scalafix.conf"))
|
||||
stdoutLogger.info(s"Loading ignored-packages from .scalaifx.config:[${config.origin().url().toURI.getPath}]")
|
||||
config
|
||||
.getStringList("ignored-packages")
|
||||
.asScala
|
||||
.toSet
|
||||
}
|
||||
|
||||
unmanagedSources.in(configKey, scalafix) :=
|
||||
unmanagedSources.in(configKey, scalafix).value
|
||||
.filterNot(file => {
|
||||
val ignoredByFile = ignoredFiles(file.getName)
|
||||
if (ignoredByFile) {
|
||||
stdoutLogger.info(s"scalafix ignored file: ${file.toURI} with file name: ${file.getName}")
|
||||
}
|
||||
val ignoredByPackages = ignoredPackages.exists(pkg => {
|
||||
getPackageName(file.toURI.toString) match {
|
||||
case Some(packageName) =>
|
||||
val ignored = packageName.startsWith(pkg)
|
||||
if (ignored) {
|
||||
stdoutLogger.info(s"scalafix ignored file with pkg:$pkg file:[${file.toPath}] ")
|
||||
}
|
||||
ignored
|
||||
case None => false
|
||||
}
|
||||
})
|
||||
ignoredByFile || ignoredByPackages
|
||||
})
|
||||
}
|
||||
|
||||
private def getPackageName(fileName: String): Option[String] = {
|
||||
def getPackageName0(fileType: String): String = {
|
||||
fileName.split(File.separatorChar)
|
||||
.dropWhile(part ⇒ part != fileType)
|
||||
.drop(1)
|
||||
.dropRight(1)
|
||||
.mkString(".")
|
||||
}
|
||||
|
||||
fileName.split('.').lastOption match {
|
||||
case Some(fileType) ⇒
|
||||
fileType match {
|
||||
case "java" ⇒
|
||||
Option(getPackageName0("java"))
|
||||
case "scala" ⇒
|
||||
Option(getPackageName0("scala"))
|
||||
case _ ⇒ None
|
||||
}
|
||||
case None ⇒ None
|
||||
}
|
||||
}
|
||||
|
||||
import sbt.Keys._
|
||||
|
||||
def addProjectCommandsIfAbsent(alias: String, value: String): Def.Setting[Seq[Command]] = {
|
||||
commands := {
|
||||
val currentCommands = commands.value.collect {
|
||||
case command: SimpleCommand => command.name
|
||||
}.toSet
|
||||
val isPresent = currentCommands(alias)
|
||||
if (isPresent)
|
||||
commands.value
|
||||
else
|
||||
commands.value :+ BasicCommands.newAlias(
|
||||
name = alias,
|
||||
value = value
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
def updateProjectCommands(alias: String, value: String): Def.Setting[Seq[Command]] = {
|
||||
commands := {
|
||||
commands.value.filterNot({
|
||||
case command: SimpleCommand => command.name == alias
|
||||
case _ => false
|
||||
}) :+ BasicCommands.newAlias(
|
||||
name = alias,
|
||||
value = value
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue