aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-27 19:33:59 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-28 09:39:14 -0400
commit2c792df95d36d61c55b07ddfa13387cf79371bdb (patch)
tree4b6b4dbcdfd9b9a71a7a9f461ee665b855bc3b43 /plugins
parentc9be8fe67010094d21505ca05ab1363a5abba06d (diff)
downloadcbt-2c792df95d36d61c55b07ddfa13387cf79371bdb.tar.gz
cbt-2c792df95d36d61c55b07ddfa13387cf79371bdb.tar.bz2
cbt-2c792df95d36d61c55b07ddfa13387cf79371bdb.zip
add scala meta and scalafix plugin
Diffstat (limited to 'plugins')
-rw-r--r--plugins/scalafix/Scalafix.scala66
-rw-r--r--plugins/scalafix/build/build.scala27
2 files changed, 93 insertions, 0 deletions
diff --git a/plugins/scalafix/Scalafix.scala b/plugins/scalafix/Scalafix.scala
new file mode 100644
index 0000000..e95840c
--- /dev/null
+++ b/plugins/scalafix/Scalafix.scala
@@ -0,0 +1,66 @@
+package cbt
+
+import java.io.File
+
+import scala.meta._
+import scala.meta.semantic.v1._
+import scala.meta.{ Symbol => _, _ }
+import scalafix._, rewrite._, config._, util._
+import org.scalameta.{logger => scalametaLogger}
+
+import cbt._
+
+trait Scalafix extends Scalameta{
+ def scalafix = Scalafix.apply( lib ).config(
+ classpath,
+ sourceFiles zip sourceFiles
+ )
+}
+
+object Scalafix{
+ case class apply( lib: Lib ){
+ case class config(
+ classpath: ClassPath,
+ files: Seq[(File,File)],
+ patches: Seq[Patch] = Seq(),
+ rewrites: Seq[ Rewrite[ScalafixMirror] ] = Seq(),
+ allowEmpty: Boolean = false
+ ){
+ def mirror =
+ Mirror(
+ classpath.string,
+ files.map(_._1).mkString(File.pathSeparator)
+ )
+
+ def context(file: File): ( RewriteCtx[Mirror], RewriteCtx[ScalafixMirror] ) = (
+ scalafix.rewrite.RewriteCtx(
+ mirror.dialect(file).parse[Source].get, ScalafixConfig(), mirror
+ ),
+ scalafix.rewrite.RewriteCtx(
+ mirror.dialect(file).parse[Source].get, ScalafixConfig(), ScalafixMirror.fromMirror( mirror )
+ )
+ )
+
+ def apply: Unit = {
+ require(
+ allowEmpty || rewrites.nonEmpty || patches.nonEmpty,
+ "You need to provide some rewrites via: `override def scalafix = super.scalafix.copy( rewrites = Seq(...) )`"
+ )
+ files.foreach{ case (from, to) =>
+ implicit val ( ctx, ctx2 ) = context(from)
+ lib.writeIfChanged(
+ to,
+ Patch(
+ (
+ patches
+ ++ rewrites.flatMap(
+ _.rewrite( ctx2 ).to
+ )
+ ).to
+ )
+ )
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/scalafix/build/build.scala b/plugins/scalafix/build/build.scala
new file mode 100644
index 0000000..02dcc0c
--- /dev/null
+++ b/plugins/scalafix/build/build.scala
@@ -0,0 +1,27 @@
+package scalafix_build
+
+import cbt._
+
+class Build(val context: Context) extends Plugin {
+ override def dependencies = super.dependencies ++ Seq(
+ //plugins.scalameta
+ ) :+ Resolver( mavenCentral ).bindOne(
+ ScalaDependency(
+ "ch.epfl.scala", "scalafix-core", "0.3.2"
+ )
+ ).copy(
+ // required until https://github.com/scalacenter/scalafix/issues/100 is fixed
+ replace = _ => _.flatMap{
+ case m@MavenDependency("org.scalameta", artifactId,_,_,_)
+ if (artifactId startsWith "scalahost_")
+ || (artifactId startsWith "contrib_")
+ => Seq( m )
+ case MavenDependency("org.scalameta", _,_,_,_) => Seq(
+ MavenDependency(
+ "org.scalameta", "scalahost_" ++ scalaVersion, "1.6.0"
+ )
+ )
+ case other => Seq( other )
+ }
+ )
+}