-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit refactors the build to reflectively invoke scalafix instead of calling the API directly. This has the following benefits - works for 0.13 and 1.0 - avoids binary compatibility issues with sbt classpath (scalapb, fastparse, ...). We should shade scalafix dependencies but that would make it impossible support running custom rules that are published to Maven Central.
- Loading branch information
Showing
32 changed files
with
199 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
plugin/src/main/scala-sbt-0.13/sbt/internal/sbtscalafix/JLineAccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package sbt.internal.sbtscalafix | ||
|
||
/** Dummy for sbt 0.13 */ | ||
trait JLineAccess { | ||
def terminalWidth: Int = 80 | ||
} |
2 changes: 1 addition & 1 deletion
2
...n/scala/sbt/scalafixsbt/JLineAccess.scala → ...bt/internal/sbtscalafix/JLineAccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package scalafix.sbt | ||
|
||
object BuildInfo { | ||
def scala212: String = "2.12.6" | ||
def scala211: String = "2.11.12" | ||
def scalameta: String = "4.0.0-M6" | ||
def scalafix: String = "0.6.0-M12" | ||
def supportedScalaVersions: List[String] = List("2.12.6", "2.11.12") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
plugin/src/main/scala/scalafix/sbt/ScalafixInterface.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package scalafix.sbt | ||
|
||
import com.geirsson.coursiersmall._ | ||
import java.net.URLClassLoader | ||
import scala.language.reflectiveCalls | ||
|
||
trait ScalafixInterface { | ||
def main(args: Array[String]): Unit | ||
} | ||
|
||
object ScalafixInterface { | ||
|
||
def classloadInstance(): ScalafixInterface = { | ||
val dep = new Dependency( | ||
"ch.epfl.scala", | ||
s"scalafix-cli_${BuildInfo.scala212}", | ||
BuildInfo.scalafix | ||
) | ||
val settings = new Settings() | ||
.withDependencies(List(dep)) | ||
.withRepositories( | ||
List( | ||
Repository.MavenCentral, | ||
Repository.SonatypeSnapshots | ||
) | ||
) | ||
val jars = CoursierSmall.fetch(settings) | ||
type Main = { | ||
def main(args: Array[String]): Unit | ||
} | ||
val urls = jars.iterator.map(_.toUri.toURL).toArray | ||
val classloader = new URLClassLoader(urls, null) | ||
val cls = classloader.loadClass("scalafix.v1.Main$") | ||
val ctor = cls.getDeclaredConstructor() | ||
ctor.setAccessible(true) | ||
val cli = ctor.newInstance().asInstanceOf[Main] | ||
new ScalafixInterface { | ||
override def main(args: Array[String]): Unit = { | ||
cli.main(args) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rules = [ | ||
ExplicitResultTypes | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
inThisBuild( | ||
List( | ||
scalaVersion := "2.12.6", | ||
libraryDependencies ++= List( | ||
"org.scalameta" %% "testkit" % "4.0.0-M6" % Test, | ||
"org.scalacheck" %% "scalacheck" % "1.13.5" % Test, | ||
"org.scalatest" %% "scalatest" % "3.0.5" % Test | ||
) | ||
) | ||
) | ||
|
||
lazy val example = project | ||
.settings( | ||
Defaults.itSettings, | ||
inConfig(IntegrationTest)(scalafixConfigSettings), | ||
addCompilerPlugin(scalafixSemanticdb), | ||
scalacOptions += "-Yrangepos" | ||
) | ||
|
||
lazy val tests = project |
5 changes: 5 additions & 0 deletions
5
plugin/src/sbt-test/sbt-scalafix/basic/example/src/main/scala/example/Example.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package example | ||
|
||
object Example { | ||
implicit val str = null.asInstanceOf[java.util.Map.Entry[Int, String]] | ||
} |
4 changes: 1 addition & 3 deletions
4
...test-project-template/project/plugins.sbt → ...st/sbt-scalafix/basic/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" | ||
|
||
resolvers += Resolver.sonatypeRepo("releases") | ||
|
||
libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
1 change: 1 addition & 0 deletions
1
plugin/src/sbt-test/sbt-scalafix/basic/project/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M6") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-> scalafixTest | ||
> scalafix | ||
> scalafixTest | ||
> tests/test |
24 changes: 24 additions & 0 deletions
24
plugin/src/sbt-test/sbt-scalafix/basic/tests/src/test/scala/tests/CheckSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package tests | ||
|
||
import org.scalatest._ | ||
import scala.meta.internal.io._ | ||
import scala.meta.testkit._ | ||
|
||
class CheckSuite extends FunSuite with DiffAssertions { | ||
|
||
test("> scalafix") { | ||
val root = PathIO.workingDirectory.resolve("example").resolve("src") | ||
val obtained = StringFS.asString(root) | ||
val expected = | ||
""" | ||
|/main/scala/example/Example.scala | ||
|package example | ||
| | ||
|object Example { | ||
| implicit val str: _root_.java.util.Map.Entry[_root_.scala.Int, _root_.scala.Predef.String] = null.asInstanceOf[java.util.Map.Entry[Int, String]] | ||
|} | ||
|""".stripMargin | ||
assertNoDiff(obtained, expected) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
plugin/src/sbt-test/sbt-scalafix/cross-build/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
resolvers += Resolver.sonatypeRepo("releases") | ||
libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" | ||
|
||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
2 changes: 1 addition & 1 deletion
2
plugin/src/sbt-test/sbt-scalafix/cross-build/project/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) | ||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M6") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
plugin/src/sbt-test/sbt-scalafix/scalafixEnable/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
resolvers += Resolver.sonatypeRepo("releases") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) |
1 change: 0 additions & 1 deletion
1
plugin/src/sbt-test/sbt-scalafix/scalafixEnable/project/project/plugins.sbt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
plugin/src/sbt-test/sbt-scalafix/suppress/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" | ||
|
||
resolvers += Resolver.sonatypeRepo("releases") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) | ||
libraryDependencies += "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" |
2 changes: 1 addition & 1 deletion
2
plugin/src/sbt-test/sbt-scalafix/suppress/project/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) | ||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M6") |
Oops, something went wrong.