From bb73730c005c6a3067a0c388ff0bff14844d4129 Mon Sep 17 00:00:00 2001 From: Ethan Atkins Date: Sat, 30 Nov 2019 14:18:41 -0800 Subject: [PATCH] Run scalafmtSbt Also add scalafmtSbtCheck to travis. --- build.sbt | 31 +++++++++++-------- project/Release.scala | 15 ++++++---- project/SbtLauncherPlugin.scala | 3 +- project/StatusPlugin.scala | 10 ++++--- project/Transform.scala | 11 +++---- project/Util.scala | 53 +++++++++++++++++++-------------- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/build.sbt b/build.sbt index 361c78838..1c20edbf4 100644 --- a/build.sbt +++ b/build.sbt @@ -67,7 +67,10 @@ def commonSettings: Seq[Setting[_]] = Def.settings( resolvers += Resolver.typesafeIvyRepo("releases").withName("typesafe-sbt-build-ivy-releases"), resolvers += Resolver.sonatypeRepo("snapshots"), resolvers += "bintray-sbt-maven-releases" at "https://dl.bintray.com/sbt/maven-releases/", - resolvers += Resolver.url("bintray-scala-hedgehog", url("https://dl.bintray.com/hedgehogqa/scala-hedgehog"))(Resolver.ivyStylePatterns), + resolvers += Resolver.url( + "bintray-scala-hedgehog", + url("https://dl.bintray.com/hedgehogqa/scala-hedgehog") + )(Resolver.ivyStylePatterns), addCompilerPlugin("org.spire-math" % "kind-projector" % "0.9.4" cross CrossVersion.binary), testFrameworks += TestFramework("hedgehog.sbt.Framework"), concurrentRestrictions in Global += Util.testExclusiveRestriction, @@ -242,7 +245,6 @@ val collectionProj = (project in file("internal") / "util-collection") // it's now abstract in KList and defined in both KCons & KNil. exclude[FinalMethodProblem]("sbt.internal.util.KNil.foldr"), exclude[DirectAbstractMethodProblem]("sbt.internal.util.KList.foldr"), - exclude[IncompatibleSignatureProblem]("sbt.internal.util.Init*.*"), exclude[IncompatibleSignatureProblem]("sbt.internal.util.Settings0.*"), exclude[IncompatibleSignatureProblem]("sbt.internal.util.EvaluateSettings#INode.*"), @@ -251,7 +253,9 @@ val collectionProj = (project in file("internal") / "util-collection") exclude[IncompatibleSignatureProblem]("sbt.internal.util.Settings.*"), exclude[IncompatibleSignatureProblem]("sbt.internal.util.EvaluateSettings#MixedNode.*"), exclude[IncompatibleSignatureProblem]("sbt.internal.util.EvaluateSettings#BindNode.this"), - exclude[IncompatibleSignatureProblem]("sbt.internal.util.EvaluateSettings#BindNode.dependsOn"), + exclude[IncompatibleSignatureProblem]( + "sbt.internal.util.EvaluateSettings#BindNode.dependsOn" + ), exclude[IncompatibleSignatureProblem]("sbt.internal.util.Types.some") ), ) @@ -736,7 +740,6 @@ lazy val mainProj = (project in file("main")) exclude[ReversedMissingMethodProblem]("sbt.internal.KeyIndex.*"), // internal exclude[IncompatibleMethTypeProblem]("sbt.internal.server.LanguageServerReporter.*"), - // Changed signature or removed private[sbt] methods exclude[DirectMissingMethodProblem]("sbt.Classpaths.unmanagedLibs0"), exclude[DirectMissingMethodProblem]("sbt.Defaults.allTestGroupsTask"), @@ -755,11 +758,14 @@ lazy val mainProj = (project in file("main")) exclude[IncompatibleSignatureProblem]("sbt.plugins.SbtPlugin.*Settings"), // Removed private internal classes exclude[MissingClassProblem]("sbt.internal.ReverseLookupClassLoaderHolder$BottomClassLoader"), - exclude[MissingClassProblem]("sbt.internal.ReverseLookupClassLoaderHolder$ReverseLookupClassLoader$ResourceLoader"), + exclude[MissingClassProblem]( + "sbt.internal.ReverseLookupClassLoaderHolder$ReverseLookupClassLoader$ResourceLoader" + ), exclude[MissingClassProblem]("sbt.internal.ReverseLookupClassLoaderHolder$ClassLoadingLock"), - exclude[MissingClassProblem]("sbt.internal.ReverseLookupClassLoaderHolder$ReverseLookupClassLoader"), + exclude[MissingClassProblem]( + "sbt.internal.ReverseLookupClassLoaderHolder$ReverseLookupClassLoader" + ), exclude[MissingClassProblem]("sbt.internal.LayeredClassLoaderImpl"), - // false positives exclude[DirectMissingMethodProblem]("sbt.plugins.IvyPlugin.requires"), exclude[DirectMissingMethodProblem]("sbt.plugins.JUnitXmlReportPlugin.requires"), @@ -769,17 +775,19 @@ lazy val mainProj = (project in file("main")) exclude[DirectMissingMethodProblem]("sbt.ResolvedClasspathDependency.apply"), exclude[DirectMissingMethodProblem]("sbt.ClasspathDependency.apply"), exclude[IncompatibleSignatureProblem]("sbt.plugins.SemanticdbPlugin.globalSettings"), - // File -> Source exclude[DirectMissingMethodProblem]("sbt.Defaults.cleanFilesTask"), exclude[IncompatibleSignatureProblem]("sbt.Defaults.resourceConfigPaths"), exclude[IncompatibleSignatureProblem]("sbt.Defaults.sourceConfigPaths"), exclude[IncompatibleSignatureProblem]("sbt.Defaults.configPaths"), exclude[IncompatibleSignatureProblem]("sbt.Defaults.paths"), - exclude[IncompatibleSignatureProblem]("sbt.Keys.csrPublications"), - exclude[IncompatibleSignatureProblem]("sbt.coursierint.CoursierArtifactsTasks.coursierPublicationsTask"), - exclude[IncompatibleSignatureProblem]("sbt.coursierint.CoursierArtifactsTasks.coursierPublicationsTask"), + exclude[IncompatibleSignatureProblem]( + "sbt.coursierint.CoursierArtifactsTasks.coursierPublicationsTask" + ), + exclude[IncompatibleSignatureProblem]( + "sbt.coursierint.CoursierArtifactsTasks.coursierPublicationsTask" + ), exclude[IncompatibleSignatureProblem]("sbt.coursierint.LMCoursier.coursierConfiguration"), exclude[IncompatibleSignatureProblem]("sbt.coursierint.LMCoursier.publicationsSetting"), exclude[IncompatibleSignatureProblem]("sbt.Project.inThisBuild"), @@ -790,7 +798,6 @@ lazy val mainProj = (project in file("main")) exclude[IncompatibleSignatureProblem]("sbt.ProjectExtra.inConfig"), exclude[IncompatibleSignatureProblem]("sbt.ProjectExtra.inTask"), exclude[IncompatibleSignatureProblem]("sbt.ProjectExtra.inScope"), - exclude[MissingTypesProblem]("sbt.internal.Load*"), exclude[IncompatibleSignatureProblem]("sbt.internal.Load*"), ) diff --git a/project/Release.scala b/project/Release.scala index 74accb3a0..25cea8595 100644 --- a/project/Release.scala +++ b/project/Release.scala @@ -8,7 +8,8 @@ object Release { lazy val launcherRemotePath = SettingKey[String]("launcher-remote-path") lazy val deployLauncher = TaskKey[Unit]( "deploy-launcher", - "Upload the launcher to its traditional location for compatibility with existing scripts.") + "Upload the launcher to its traditional location for compatibility with existing scripts." + ) def launcherSettings(launcher: TaskKey[File]): Seq[Setting[_]] = Seq( launcherRemotePath := { @@ -17,11 +18,13 @@ object Release { }, deployLauncher := { val repo = bintrayRepo.value - repo.upload(bintrayPackage.value, - version.value, - launcherRemotePath.value, - launcher.value, - sLog.value) + repo.upload( + bintrayPackage.value, + version.value, + launcherRemotePath.value, + launcher.value, + sLog.value + ) } ) diff --git a/project/SbtLauncherPlugin.scala b/project/SbtLauncherPlugin.scala index 7d95ed9ee..0c24d2de5 100644 --- a/project/SbtLauncherPlugin.scala +++ b/project/SbtLauncherPlugin.scala @@ -45,8 +45,7 @@ object SbtLauncherPlugin extends AutoPlugin { // TODO - is the ok for creating a jar? val rebase: File => Seq[(File, String)] = { val path = dir.toPath - f => - if (f != dir) f -> path.relativize(f.toPath).toString :: Nil else Nil + f => if (f != dir) f -> path.relativize(f.toPath).toString :: Nil else Nil } IO.zip(dir.allPaths.get().flatMap(rebase), target) } diff --git a/project/StatusPlugin.scala b/project/StatusPlugin.scala index 6edd9cc5e..d2c0d2a6f 100644 --- a/project/StatusPlugin.scala +++ b/project/StatusPlugin.scala @@ -31,10 +31,12 @@ object StatusPlugin extends AutoPlugin { val status = extracted.get(publishStatus) // Set new version AND lock down the publishStatus to what it was, as // our release regexes no longer support ivy data format, due to other issues. - extracted.appendWithSession((version in ThisBuild ~= stamp) :: - (publishStatus in ThisBuild := status) :: - Nil, - state) + extracted.appendWithSession( + (version in ThisBuild ~= stamp) :: + (publishStatus in ThisBuild := status) :: + Nil, + state + ) } def stamp(v: String): String = { val Snapshot = "-SNAPSHOT" diff --git a/project/Transform.scala b/project/Transform.scala index e6d61676d..fde66b01c 100644 --- a/project/Transform.scala +++ b/project/Transform.scala @@ -38,11 +38,12 @@ object Transform { def get(key: String) = props.getOrElse(key, sys.error(s"No value defined for key '$key'")) val Property = """\$\{\{([\w.-]+)\}\}""".r val catcher = scala.util.control.Exception.catching(classOf[java.io.IOException]) - rs.map { case (in, out) => - val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1))) - if (Some(newString) != catcher.opt(IO.read(out))) - IO.write(out, newString) - out + rs.map { + case (in, out) => + val newString = Property.replaceAllIn(IO.read(in), mtch => get(mtch.group(1))) + if (Some(newString) != catcher.opt(IO.read(out))) + IO.write(out, newString) + out } }.taskValue, ) diff --git a/project/Util.scala b/project/Util.scala index 09714ca15..94d5ec0a1 100644 --- a/project/Util.scala +++ b/project/Util.scala @@ -44,24 +44,28 @@ object Util { lazy val apiDefinitions = TaskKey[Seq[File]]("api-definitions") - def generateAPICached(defs: Seq[File], - cp: Classpath, - out: File, - main: Option[String], - run: ScalaRun, - s: TaskStreams): Seq[File] = { + def generateAPICached( + defs: Seq[File], + cp: Classpath, + out: File, + main: Option[String], + run: ScalaRun, + s: TaskStreams + ): Seq[File] = { def gen() = generateAPI(defs, cp, out, main, run, s) val f = FileFunction.cached(s.cacheDirectory / "gen-api", FilesInfo.hash) { _ => gen().toSet } // TODO: check if output directory changed f(defs.toSet).toSeq } - def generateAPI(defs: Seq[File], - cp: Classpath, - out: File, - main: Option[String], - run: ScalaRun, - s: TaskStreams): Seq[File] = { + def generateAPI( + defs: Seq[File], + cp: Classpath, + out: File, + main: Option[String], + run: ScalaRun, + s: TaskStreams + ): Seq[File] = { IO.delete(out) IO.createDirectory(out) val args = "xsbti.api" :: out.getAbsolutePath :: defs.map(_.getAbsolutePath).toList @@ -73,10 +77,12 @@ object Util { val lastCompilation = analysis.compilations.allCompilations.lastOption lastCompilation.map(_.getStartTime) getOrElse 0L } - def generateVersionFile(version: String, - dir: File, - s: TaskStreams, - analysis: Analysis): Seq[File] = { + def generateVersionFile( + version: String, + dir: File, + s: TaskStreams, + analysis: Analysis + ): Seq[File] = { import java.util.{ Date, TimeZone } val formatter = new java.text.SimpleDateFormat("yyyyMMdd'T'HHmmss") formatter.setTimeZone(TimeZone.getTimeZone("GMT")) @@ -105,8 +111,7 @@ object Util { def cleanPom(pomNode: scala.xml.Node) = { import scala.xml._ def cleanNodes(nodes: Seq[Node]): Seq[Node] = nodes flatMap { - case elem @ Elem(_, "dependency", _, _, _*) - if excludePomDependency(elem) => + case elem @ Elem(_, "dependency", _, _, _*) if excludePomDependency(elem) => NodeSeq.Empty case Elem(_, "classifier", _, _, _*) => NodeSeq.Empty @@ -178,14 +183,18 @@ object Licensed { def settings: Seq[Setting[_]] = Seq( notice := (baseDirectory.value / "NOTICE"), unmanagedResources in Compile ++= notice.value +: extractLicenses.value, - extractLicenses := extractLicenses0((baseDirectory in ThisBuild).value, - notice.value, - streams.value) + extractLicenses := extractLicenses0( + (baseDirectory in ThisBuild).value, + notice.value, + streams.value + ) ) def extractLicenses0(base: File, note: File, s: TaskStreams): Seq[File] = if (!note.exists) Nil else - try { seePaths(base, IO.read(note)) } catch { + try { + seePaths(base, IO.read(note)) + } catch { case NonFatal(_) => s.log.warn("Could not read NOTICE"); Nil } }