diff --git a/.travis.yml b/.travis.yml index dcd49020c8..c77f5fde0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ env: CI_PUBLISH: true - CI_TEST: ci-fast CI_SCALA_VERSION: 2.12.2 - - CI_TEST: ci-sbt-scalafmt - CI_SCALA_VERSION: 2.12.2 - CI_TEST: mima cache: diff --git a/build.sbt b/build.sbt index 33345741ef..aa34b938b6 100644 --- a/build.sbt +++ b/build.sbt @@ -39,7 +39,8 @@ lazy val core = crossProject .settings( moduleName := "scalafmt-core", addCompilerPlugin( - "org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full), + "org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full + ), allSettings, buildInfoSettings, fork.in(run).in(Test) := true, @@ -72,66 +73,57 @@ lazy val cli = project ) .dependsOn(coreJVM) -def isOnly(scalaV: String) = Seq( - scalaVersion := scalaV, - crossScalaVersions := Seq(scalaV) -) - -lazy val `scalafmt-cli-sbt` = project - .configs(IntegrationTest) +lazy val big = project + .in(file("scalafmt-big")) .settings( allSettings, - Defaults.itSettings, - mimaPreviousArtifacts := Set.empty, - moduleName := "sbt-cli-scalafmt", - isOnly(scala212), - sbtPlugin := true, - sbtVersion in Global := "1.0.0", - test.in(IntegrationTest) := RunSbtCommand( - Seq( - s"plz $scala212 publishLocal", - """set sbtVersion in Global := "0.13.16" """, - "such scalafmt-sbt-tests/scripted", - """set sbtVersion in Global := "1.0.0" """ - ).mkString("; ", "; ", "") - )(state.value) + moduleName := "scalafmt-big", + crossScalaVersions := List(scala212), + mimaReportBinaryIssues := {}, + shadeSettings ) .dependsOn(cli) -lazy val `scalafmt-sbt` = project - .settings( - allSettings, - mimaPreviousArtifacts := Set.empty, - moduleName := "sbt-scalafmt", - isOnly(scala212), - sbtPlugin := true, - sbtVersion in Global := "1.0.0" - ) - .dependsOn(coreJVM) +def isOnly(scalaV: String) = Seq( + scalaVersion := scalaV, + crossScalaVersions := Seq(scalaV) +) -lazy val `scalafmt-sbt-tests` = project - .settings( - allSettings, - noPublish, - isOnly(scala210), - sbtPlugin := true, - ScriptedPlugin.scriptedSettings, - sbtVersion := "0.13.15", - scriptedSbt := "0.13.15", - scriptedLaunchOpts := Seq( - "-Dplugin.version=" + version.value, - "-Dscalafmt.scripted=true", - // .jvmopts is ignored, simulate here - "-XX:MaxPermSize=256m", - "-Xmx2g", - "-Xss2m" - ) ++ { - // pass along custom boot properties if specified - val bootProps = "sbt.boot.properties" - sys.props.get(bootProps).map(x => s"-D$bootProps=$x").toList - }, - scriptedBufferLog := false - ) +lazy val shadeSettings: List[Setting[_]] = List( + assemblyOption.in(assembly) ~= { _.copy(includeScala = false) }, + assemblyShadeRules.in(assembly) := Seq( + ShadeRule + .rename( + "scala.meta.**" -> "org.scalafmt.shaded.meta.@1", + "fastparse.**" -> "org.scalafmt.shaded.fastparse.@1" + ) + .inAll, + ShadeRule + .zap( + "scalapb.**", + "com.trueaccord.**" + ) + .inAll + ), + artifact.in(Compile, packageBin) := artifact.in(Compile, assembly).value, + pomPostProcess := { (node: scala.xml.Node) => + new scala.xml.transform.RuleTransformer( + new scala.xml.transform.RewriteRule { + override def transform(node: scala.xml.Node): scala.xml.NodeSeq = + node match { + case e: scala.xml.Elem + if e.label == "dependency" && + e.child.exists { child => + child.label == "artifactId" && + child.text.startsWith("scalafmt") + } => + scala.xml.Comment(s"shaded scalafmt-cli dependency.") + case _ => node + } + } + ).transform(node).head + } +) ++ addArtifact(artifact.in(Compile, packageBin), assembly).settings lazy val intellij = project .in(file("scalafmt-intellij")) @@ -205,7 +197,8 @@ lazy val readme = scalatex projectId = "readme", wd = file(""), url = "https://github.com/scalameta/scalafmt/tree/master", - source = "Readme") + source = "Readme" + ) .settings( git.remoteRepo := "git@github.com:scalameta/scalafmt.git", siteSourceDirectory := target.value / "scalatex", @@ -286,7 +279,8 @@ lazy val publishSettings = Seq( ), mimaBinaryIssueFilters ++= Mima.ignoredABIProblems, licenses := Seq( - "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), + "Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0") + ), homepage := Some(url("https://github.com/scalameta/scalafmt")), autoAPIMappings := true, apiURL := Some(url("https://olafurpg.github.io/scalafmt/docs/")), @@ -356,14 +350,6 @@ def ciCommands = Seq( "test" :: Nil ), - CiCommand("ci-slow")( - "tests/test:runMain org.scalafmt.ScalafmtProps" :: - Nil - ), - Command.command("ci-sbt-scalafmt") { s => - "scalafmt-cli-sbt/it:test" :: - s - }, Command.command("ci-publish") { s => s"very publish" :: s } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 56a7aa563a..eead60fe8e 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -9,6 +9,7 @@ object Dependencies { val scalatestV = "3.2.0-SNAP10" val scalacheckV = "1.13.5" val coursier = "1.0.0-RC12" + val sbtV = "1.1.6" val scalapb = Def.setting { ExclusionRule( diff --git a/project/plugins.sbt b/project/plugins.sbt index b81f760249..c207b85f38 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -18,5 +18,3 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0") addSbtPlugin("com.dancingrobot84" % "sbt-idea-plugin" % "0.4.2") addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.1.18") - -libraryDependencies += "org.scala-sbt" % "scripted-plugin" % sbtVersion.value diff --git a/scalafmt-cli-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala b/scalafmt-cli-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala deleted file mode 100644 index 1a3e46230f..0000000000 --- a/scalafmt-cli-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala +++ /dev/null @@ -1,25 +0,0 @@ -package org.scalafmt.sbt -import sbt._ -import Keys._ - -object ScalafmtPlugin extends AutoPlugin { - override def trigger: PluginTrigger = allRequirements - object autoImport { - val scalafmt: Command = - Command.args("scalafmt", "run the scalafmt command line interface.") { - case (s, args) => - org.scalafmt.cli.Cli.exceptionThrowingMain( - "--non-interactive" +: args.toArray - ) - s - } - } - override def globalSettings: Seq[Def.Setting[_]] = - Seq( - commands += autoImport.scalafmt - ) ++ - addCommandAlias("scalafmtTest", "scalafmt --test") ++ - addCommandAlias("scalafmtDiffTest", "scalafmt --diff --test") ++ - addCommandAlias("scalafmtDiff", "scalafmt --diff") - -} diff --git a/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala b/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala index 1aa4d72f72..cf20e7385c 100644 --- a/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala +++ b/scalafmt-cli/src/main/scala/org/scalafmt/cli/TermDisplay.scala @@ -511,7 +511,7 @@ class TermDisplay( } override def completedTask(url: String, success: Boolean): Unit = - updateThread.removeEntry(url, success, s"Downloaded $url\n")(x => x) + updateThread.removeEntry(url, success, s"$url\n")(x => x) override def checkingUpdates( url: String, @@ -519,7 +519,7 @@ class TermDisplay( updateThread.newEntry( url, CheckUpdateInfo(currentTimeOpt, None, isDone = false), - s"Checking $url\n" + s"$url\n" ) } diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.gitignore b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.gitignore deleted file mode 100644 index 0064e95172..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -*.class -*.log - -# sbt specific -.cache -.history -.lib/ -dist/* -target/ -lib_managed/ -src_managed/ -project/boot/ -project/plugins/project/ - -# Scala-IDE specific -.scala_dependencies -.worksheet - -.idea - -# ENSIME specific -.ensime_cache/ -.ensime diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.scalafmt.conf b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.scalafmt.conf deleted file mode 100644 index d681cc1884..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/.scalafmt.conf +++ /dev/null @@ -1,2 +0,0 @@ -style = IntelliJ -project.git = true diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/build.sbt b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/build.sbt deleted file mode 100644 index 66f23f8e3b..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/build.sbt +++ /dev/null @@ -1,66 +0,0 @@ -import java.io.File - -fork in ThisBuild := true - -lazy val root = project - .in(file(".")) - .aggregate( - p1, - p2, - p3 - ) - -lazy val p1 = project.settings(scalaVersion := "2.10.5") -lazy val p2 = project.settings(scalaVersion := "2.11.8") -lazy val p3 = project.settings(scalaVersion := "2.12.1") - -def assertContentsEqual(file: File, expected: String): Unit = { - val obtained = - scala.io.Source.fromFile(file).getLines().mkString("\n") - - if (obtained.trim != expected.trim) { - val msg = - s"""File: $file - |Obtained output: - |$obtained - |Expected: - |$expected - |""".stripMargin - System.err.println(msg) - throw new Exception(msg) - } -} - -TaskKey[Unit]("setupGitRepo") := { - import sys.process._ - Seq("git", "init").!! - Seq("git", "config", "user.email", "a@a.is").!! - Seq("git", "config", "user.name", "a").!! - Seq("git", "add", ".").!! - Seq("git", "commit", "-m", "wip").!! -} - -TaskKey[Unit]("check") := { - (1 to 3).foreach { i => - val expected = - """ - |object Test { - | foo( - | a, // comment - | b - | ) - |} - """.stripMargin - val expected2 = expected.replaceFirst("Test", "MainTest") - assertContentsEqual(file(s"p$i/src/main/scala/Test.scala"), expected) - assertContentsEqual(file(s"p$i/src/test/scala/MainTest.scala"), expected2) - } - assertContentsEqual( - new File("project/plugins.sbt"), - """ - |addSbtPlugin( - | "com.geirsson" % "sbt-cli-scalafmt" % System.getProperty("plugin.version") - |) - """.stripMargin - ) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/main/scala/Test.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/main/scala/Test.scala deleted file mode 100644 index a96ec3f1fa..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/main/scala/Test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/test/scala/MainTest.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/test/scala/MainTest.scala deleted file mode 100644 index 7d4e15448b..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p1/src/test/scala/MainTest.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -MainTest -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/main/scala/Test.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/main/scala/Test.scala deleted file mode 100644 index a96ec3f1fa..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/main/scala/Test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/test/scala/MainTest.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/test/scala/MainTest.scala deleted file mode 100644 index 7d4e15448b..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p2/src/test/scala/MainTest.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -MainTest -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/java/TestJava.java b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/java/TestJava.java deleted file mode 100644 index b74418b3f9..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/java/TestJava.java +++ /dev/null @@ -1,6 +0,0 @@ -public class TestJava -{ - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/scala/Test.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/scala/Test.scala deleted file mode 100644 index a96ec3f1fa..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/main/scala/Test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/java/MainTestJava.java b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/java/MainTestJava.java deleted file mode 100644 index 1d77ec9372..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/java/MainTestJava.java +++ /dev/null @@ -1,6 +0,0 @@ -public class MainTestJava -{ - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/scala/MainTest.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/scala/MainTest.scala deleted file mode 100644 index 7d4e15448b..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/p3/src/test/scala/MainTest.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -MainTest -{ - foo(a, // comment - b) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/build.properties b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/build.properties deleted file mode 100644 index 94005e587c..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.0.0 diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/plugins.sbt b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/plugins.sbt deleted file mode 100644 index 72bea2da5c..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/project/plugins.sbt +++ /dev/null @@ -1,3 +0,0 @@ -addSbtPlugin ( - "com.geirsson" % "sbt-cli-scalafmt" % System.getProperty("plugin.version")) - diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/test b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/test deleted file mode 100644 index 392519cf36..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt-cli/test +++ /dev/null @@ -1,12 +0,0 @@ -> setupGitRepo -> scalafmt -> scalafmtTest -> check -> scalafmtDiff -> scalafmtDiffTest -> check -> scalafmt --diff-branch master -> scalafmt --diff -> scalafmt --diff --test -> check - diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt.conf b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt.conf deleted file mode 100644 index 84f13659a0..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt.conf +++ /dev/null @@ -1 +0,0 @@ -style = IntelliJ diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt6.conf b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt6.conf deleted file mode 100644 index 5ae2d1e7f6..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/.scalafmt6.conf +++ /dev/null @@ -1,4 +0,0 @@ -style = default -project.excludeFilters = [ - MainTest -] \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/build.sbt b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/build.sbt deleted file mode 100644 index 8aab6b8611..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/build.sbt +++ /dev/null @@ -1,200 +0,0 @@ -import java.io.File - -fork in ThisBuild := true - -lazy val p123 = project - .in(file(".")) - .aggregate( - p1, - p2, - p3 - ) - -lazy val p1 = project.settings( - scalaVersion := "2.10.5" -) -lazy val p2 = project.settings( - scalaVersion := "2.11.8" -) -lazy val p3 = project.settings( - scalaVersion := "2.12.1" -) -lazy val p4 = project.settings( - scalaVersion := "2.12.1" -) -lazy val p5 = project.settings( - scalaVersion := "2.12.1", - scalafmtOnCompile := true -) -lazy val p6 = project.settings( - scalaVersion := "2.12.1", - scalafmtConfig := Some(file(".scalafmt6.conf")) -) -lazy val p7 = project.settings( - scalaVersion := "2.12.1", - scalafmtConfig := None -) - -lazy val p8 = project.settings( - scalaVersion := "2.12.1" -) - -def assertContentsEqual(file: File, expected: String): Unit = { - val obtained = - scala.io.Source.fromFile(file).getLines().mkString("\n") - - if (obtained.trim != expected.trim) { - val msg = - s"""File: $file - |Obtained output: - |$obtained - |Expected: - |$expected - |""".stripMargin - System.err.println(msg) - throw new Exception(msg) - } -} - -TaskKey[Unit]("changeTest2") := { - IO.write(file(s"p8/src/main/scala/Test2.scala"), - """ - |object - |Test2 - |{ - | def foo2(a: Int, // comment - | b: Double) = ??? - |} - | - """.stripMargin - ) -} - -TaskKey[Unit]("check") := { - (1 to 4).foreach { i => - val expectedTest = - """ - |object Test { - | foo( - | a, // comment - | b - | ) - |} - """.stripMargin - val expectedMainTest = expectedTest.replaceFirst("Test", "MainTest") - assertContentsEqual( - file(s"p$i/src/main/scala/Test.scala"), - expectedTest - ) - assertContentsEqual( - file(s"p$i/src/test/scala/MainTest.scala"), - expectedMainTest - ) - } - - - assertContentsEqual( - file(s"p5/src/main/scala/Test.scala"), - """ - |object Test { - | def foo( - | a: Int, // comment - | b: Double - | ) = ??? - |} - """.stripMargin - ) - assertContentsEqual( - file(s"p5/src/test/scala/MainTest.scala"), - """ - |object MainTest { - | def foo( - | a: Int, // comment - | b: Double - | ) = ??? - |} - """.stripMargin - ) - - - assertContentsEqual( - file(s"p6/src/main/scala/Test.scala"), - """ - |object Test { - | foo( - | a, // comment - | b - | ) - |} - """.stripMargin - ) - assertContentsEqual( - file(s"p6/src/test/scala/MainTest.scala"), - """ - |object - |MainTest - |{ - | foo(a, // comment - | b) - |} - | - """.stripMargin - ) - - - assertContentsEqual( - file(s"p7/src/main/scala/Test.scala"), - """ - |object Test { - | foo( - | a, // comment - | b - | ) - |} - """.stripMargin - ) - assertContentsEqual( - file(s"p7/src/test/scala/MainTest.scala"), - """ - |object MainTest { - | foo( - | a, // comment - | b - | ) - |} - """.stripMargin - ) - - assertContentsEqual( - file(s"p8/src/main/scala/Test.scala"), - """ - |object Test { - | def foo( - | a: Int, // comment - | b: Double - | ) = ??? - |} - """.stripMargin - ) - - assertContentsEqual( - file(s"p8/src/main/scala/Test2.scala"), - """ - |object Test2 { - | def foo2( - | a: Int, // comment - | b: Double - | ) = ??? - |} - """.stripMargin - ) - - assertContentsEqual( - file("project/plugins.sbt"), - """ - |addSbtPlugin( - | "com.geirsson" % "sbt-scalafmt" % System.getProperty("plugin.version") - |) - """.stripMargin - ) -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p1 b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p1 deleted file mode 120000 index c84e7ded70..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p1 +++ /dev/null @@ -1 +0,0 @@ -../sbt-cli/p1 \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p2 b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p2 deleted file mode 120000 index 52bef95218..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p2 +++ /dev/null @@ -1 +0,0 @@ -../sbt-cli/p2 \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p3 b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p3 deleted file mode 120000 index e0c44641c8..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p3 +++ /dev/null @@ -1 +0,0 @@ -../sbt-cli/p3 \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/p4.sbt b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/p4.sbt deleted file mode 100644 index 19856ebd14..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/p4.sbt +++ /dev/null @@ -1,4 +0,0 @@ -lazy val settings = - Seq( - scalaVersion := - "2.12.1") \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/src b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/src deleted file mode 120000 index aca4df1db7..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p4/src +++ /dev/null @@ -1 +0,0 @@ -../p3/src \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/main/scala/Test.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/main/scala/Test.scala deleted file mode 100644 index d7a1ffe57f..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/main/scala/Test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test -{ - def foo(a: Int, // comment - b: Double) = ??? -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/test/scala/MainTest.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/test/scala/MainTest.scala deleted file mode 100644 index 16abf1979e..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p5/src/test/scala/MainTest.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -MainTest -{ - def foo(a: Int, // comment - b: Double) = ??? -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p6/src b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p6/src deleted file mode 120000 index aca4df1db7..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p6/src +++ /dev/null @@ -1 +0,0 @@ -../p3/src \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p7/src b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p7/src deleted file mode 120000 index aca4df1db7..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p7/src +++ /dev/null @@ -1 +0,0 @@ -../p3/src \ No newline at end of file diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test.scala deleted file mode 100644 index d7a1ffe57f..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test -{ - def foo(a: Int, // comment - b: Double) = ??? -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test2.scala b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test2.scala deleted file mode 100644 index 551d493c6f..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/p8/src/main/scala/Test2.scala +++ /dev/null @@ -1,6 +0,0 @@ -object -Test2 -{ - def foo2(a: Int, // comment - b: Double) = ??? -} diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/build.properties b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/build.properties deleted file mode 100644 index 94005e587c..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.0.0 diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/plugins.sbt b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/plugins.sbt deleted file mode 100644 index 87eecfd5e1..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/project/plugins.sbt +++ /dev/null @@ -1,3 +0,0 @@ -addSbtPlugin ( - "com.geirsson" % "sbt-scalafmt" % System.getProperty("plugin.version")) - diff --git a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/test b/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/test deleted file mode 100644 index 196b00a853..0000000000 --- a/scalafmt-sbt-tests/src/sbt-test/scalafmt-sbt/sbt/test +++ /dev/null @@ -1,41 +0,0 @@ --> p123/compile:scalafmtCheck --> p123/test:scalafmtCheck -> p123/compile:scalafmt -> p123/test:scalafmt -> p123/compile:scalafmtCheck -> p123/test:scalafmtCheck - -> scalafmtSbt -> scalafmtSbtCheck - -> p4/scalafmtOnly src/main/scala/Test.scala src/test/scala/MainTest.scala p4.sbt -> p4/compile:scalafmtCheck -> p4/test:scalafmtCheck -> p4/scalafmtSbtCheck - -> p5/compile -> p5/test:compile -> p5/compile:scalafmtCheck -> p5/test:scalafmtCheck - -> p6/compile:scalafmt -> p6/test:scalafmt -> p6/compile:scalafmtCheck -> p6/test:scalafmtCheck - -> p7/compile:scalafmt -> p7/test:scalafmt -> p7/compile:scalafmtCheck -> p7/test:scalafmtCheck - -> p8/compile:scalafmt -> check -$ sleep 1000 -$ touch timestamp -$ sleep 1000 -> changeTest2 -> p8/compile:scalafmt -$ newer timestamp p8/src/main/scala/Test.scala -$ newer p8/src/main/scala/Test2.scala timestamp - -> check diff --git a/scalafmt-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala b/scalafmt-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala deleted file mode 100644 index 4ae063b6ff..0000000000 --- a/scalafmt-sbt/src/main/scala/org/scalafmt/sbt/ScalafmtPlugin.scala +++ /dev/null @@ -1,233 +0,0 @@ -package org.scalafmt.sbt - -import org.scalafmt.config.{Config, ScalafmtConfig} -import org.scalafmt.{Formatted, Scalafmt} -import sbt.Keys._ -import sbt.{Def, _} -import complete.DefaultParsers._ -import metaconfig.Configured -import sbt.util.Logger - -import scala.meta.internal.tokenizers.PlatformTokenizerCache -import scala.util.{Failure, Success, Try} -import org.scalafmt.util.{FormattingCache, StyleCache} - -object ScalafmtPlugin extends AutoPlugin { - override def trigger: PluginTrigger = allRequirements - - object autoImport { - val scalafmt = taskKey[Unit]("Format Scala sources with scalafmt.") - val scalafmtCheck = - taskKey[Boolean]( - "Fails if a Scala source is mis-formatted. Does not write to files.") - val scalafmtOnCompile = - settingKey[Boolean]( - "Format Scala source files on compile, off by default.") - val scalafmtConfig = taskKey[Option[File]]( - "Optional location of .scalafmt.conf file. " + - "If None the default config is used.") - val scalafmtSbt = taskKey[Unit]( - "Format *.sbt and project/*.scala files for this sbt build.") - val scalafmtSbtCheck = - taskKey[Boolean]( - "Fails if a *.sbt or project/*.scala source is mis-formatted. " + - "Does not write to files.") - val scalafmtOnly = inputKey[Unit]("Format a single given file.") - } - import autoImport._ - - private val scalafmtDoFormatOnCompile = - taskKey[Unit]("Format Scala source files if scalafmtOnCompile is on.") - - private val scalaConfig = - scalafmtConfig - .map( - _.flatMap(f => StyleCache.getStyleForFile(f.toString)) - .getOrElse(ScalafmtConfig.default)) - private val sbtConfig = scalaConfig.map(_.forSbt) - - private def filterSource(source: File, config: ScalafmtConfig): Boolean = - config.project.matcher.matches(source.toString) - private def filterScala(source: File): Boolean = - source.toString.endsWith(".scala") - private def filterSbt(source: File): Boolean = - source.toString.endsWith(".sbt") - private def filterSc(source: File): Boolean = - source.toString.endsWith(".sc") - - private type Input = String - private type Output = String - - private def withFormattedSources[T]( - sources: Seq[File], - config: ScalafmtConfig - )( - onError: (File, Throwable) => T, - onFormat: (File, Input, Output) => T - ): Seq[Option[T]] = { - sources - .withFilter(filterSource(_, config)) - .map( - file => { - val input = IO.read(file) - val output = Scalafmt.format(input, config) - - output match { - case Formatted.Failure(e) => - if (config.runner.fatalWarnings) { - throw e - } else if (config.runner.ignoreWarnings) { - // do nothing - None - } else { - Some(onError(file, e)) - } - case Formatted.Success(code) => - Some(onFormat(file, input, code)) - } - } - ) - } - - private def formatSources( - sources: Seq[File], - config: ScalafmtConfig, - log: Logger - ): Unit = { - val cnt = withFormattedSources( - sources.filter(FormattingCache.outdatedFormatting), - config - )( - (file, e) => { - log.error(s"Error in ${file.toString}: $e") - 0 - }, - (file, input, output) => { - if (input != output) { - IO.write(file, output) - FormattingCache.updateFormatting(file, System.currentTimeMillis()) - 1 - } else { - 0 - } - } - ).flatten.sum - - if (cnt > 1) { - log.info(s"Reformatted $cnt Scala sources") - } - - PlatformTokenizerCache.megaCache.clear() - } - - private def checkSources( - sources: Seq[File], - config: ScalafmtConfig, - log: Logger - ): Boolean = { - val res = withFormattedSources(sources, config)( - (file, e) => { - log.error(s"Error in ${file.toString}: $e") - false - }, - (file, input, output) => { - val diff = input != output - if (diff) { - throw new MessageOnlyException( - s"${file.toString} isn't formatted properly!") - } - diff - } - ).flatten.forall(x => x) - PlatformTokenizerCache.megaCache.clear() - res - } - - private lazy val sbtSources = thisProject.map( - proj => { - val rootSbt = - BuildPaths.configurationSources(proj.base).filterNot(_.isHidden) - val projectSbt = - (BuildPaths.projectStandard(proj.base) * GlobFilter("*.sbt")).get - .filterNot(_.isHidden) - rootSbt ++ projectSbt - } - ) - private lazy val projectSources = thisProject.map(proj => - (BuildPaths.projectStandard(proj.base) * GlobFilter("*.scala")).get) - - lazy val scalafmtConfigSettings: Seq[Def.Setting[_]] = Seq( - scalafmt := formatSources( - (unmanagedSources in scalafmt).value.filter(filterScala), - scalaConfig.value, - streams.value.log - ), - scalafmtSbt := { - formatSources( - sbtSources.value, - sbtConfig.value, - streams.value.log - ) - formatSources( - projectSources.value, - scalaConfig.value, - streams.value.log - ) - }, - scalafmtCheck := - checkSources( - (unmanagedSources in scalafmt).value.filter(filterScala), - scalaConfig.value, - streams.value.log), - scalafmtSbtCheck := { - checkSources(sbtSources.value, sbtConfig.value, streams.value.log) - checkSources(projectSources.value, scalaConfig.value, streams.value.log) - }, - scalafmtDoFormatOnCompile := Def.settingDyn { - if (scalafmtOnCompile.value) { - scalafmt in resolvedScoped.value.scope - } else { - Def.task(()) - } - }.value, - compileInputs in compile := (compileInputs in compile) - .dependsOn(scalafmtDoFormatOnCompile) - .value, - scalafmtOnly := { - val files = spaceDelimited("").parsed - val absFiles = files.flatMap(fileS => { - Try { IO.resolve(baseDirectory.value, new File(fileS)) } match { - case Failure(e) => - streams.value.log.error(s"Error with $fileS file: $e") - None - case Success(file) => Some(file) - } - }) - - val scalaFiles = absFiles.filter(filterScala) - formatSources(scalaFiles, scalaConfig.value, streams.value.log) - val sbtFiles = absFiles.filter(filterSbt) - formatSources(sbtFiles, sbtConfig.value, streams.value.log) - val scFiles = absFiles.filter(filterSc) - formatSources(scFiles, sbtConfig.value, streams.value.log) - } - ) - - override def projectSettings: Seq[Def.Setting[_]] = - Seq(Compile, Test).flatMap(inConfig(_)(scalafmtConfigSettings)) - - override def buildSettings: Seq[Def.Setting[_]] = Seq( - scalafmtConfig := { - val path = (baseDirectory in ThisBuild).value / ".scalafmt.conf" - if (path.exists()) { - Some(path) - } else { - None - } - } - ) - - override def globalSettings: Seq[Def.Setting[_]] = Seq( - scalafmtOnCompile := false - ) -}