aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Christopher Vogt <oss.nsp@cvogt.org>2016-09-14 14:36:42 +0100
committerGitHub <noreply@github.com>2016-09-14 14:36:42 +0100
commit32abe161b5454e2c9e9265bb5b95e8fad3c09bb3 (patch)
tree141900693a428be1bbab775a613205a7dfd67f78
parent1630cdae28c8d29a4502446a2d14d7bb5b30fb98 (diff)
parent1e529cab0dc04bebf924934d6680c605fb78a175 (diff)
downloadcbt-32abe161b5454e2c9e9265bb5b95e8fad3c09bb3.tar.gz
cbt-32abe161b5454e2c9e9265bb5b95e8fad3c09bb3.tar.bz2
cbt-32abe161b5454e2c9e9265bb5b95e8fad3c09bb3.zip
Merge pull request #225 from cvogt/wartremover
WartRemover plugin implementation
-rw-r--r--examples/wartremover-example/build/build.scala9
-rw-r--r--examples/wartremover-example/build/build/build.scala5
-rw-r--r--examples/wartremover-example/src/Main.scala5
-rw-r--r--plugins/wartremover/WartRemover.scala51
-rw-r--r--plugins/wartremover/build/build.scala9
-rw-r--r--stage2/BuildBuild.scala1
-rw-r--r--test/test.scala8
7 files changed, 88 insertions, 0 deletions
diff --git a/examples/wartremover-example/build/build.scala b/examples/wartremover-example/build/build.scala
new file mode 100644
index 0000000..c715f20
--- /dev/null
+++ b/examples/wartremover-example/build/build.scala
@@ -0,0 +1,9 @@
+import cbt._
+
+import org.wartremover.warts.{ Null, Var }
+import org.wartremover.WartTraverser
+
+class Build(val context: Context) extends BuildBuild with WartRemover {
+
+ override def wartremoverErrors: Seq[WartTraverser] = Seq(Var, Null)
+}
diff --git a/examples/wartremover-example/build/build/build.scala b/examples/wartremover-example/build/build/build.scala
new file mode 100644
index 0000000..eb2f193
--- /dev/null
+++ b/examples/wartremover-example/build/build/build.scala
@@ -0,0 +1,5 @@
+import cbt._
+
+class Build(val context: Context) extends BuildBuild {
+ override def dependencies = super.dependencies :+ plugins.wartremover
+}
diff --git a/examples/wartremover-example/src/Main.scala b/examples/wartremover-example/src/Main.scala
new file mode 100644
index 0000000..dc4b3da
--- /dev/null
+++ b/examples/wartremover-example/src/Main.scala
@@ -0,0 +1,5 @@
+object Main {
+ def main(args: Array[String]): Unit = {
+ var nastyVar = null
+ }
+}
diff --git a/plugins/wartremover/WartRemover.scala b/plugins/wartremover/WartRemover.scala
new file mode 100644
index 0000000..d5bbcd0
--- /dev/null
+++ b/plugins/wartremover/WartRemover.scala
@@ -0,0 +1,51 @@
+package cbt
+
+import org.wartremover.WartTraverser
+import java.io.File
+
+trait WartRemover extends BaseBuild {
+
+ override def scalacOptions =
+ super.scalacOptions ++ wartremoverScalacOptions
+
+ private[this] def wartremoverCompilerDependency: String =
+ MavenResolver(
+ context.cbtHasChanged,
+ context.paths.mavenCache,
+ mavenCentral).bindOne(
+ ScalaDependency("org.wartremover", "wartremover", "1.1.1")
+ ).jar.string
+
+ private[this] def wartremoverScalacOptions: Seq[String] =
+ Seq("-Xplugin:" ++ wartremoverCompilerDependency) ++
+ wartremoverErrorsScalacOptions ++
+ wartremoverWarningsScalacOptions ++
+ wartremoverExcludedScalacOptions ++
+ wartremoverClasspathsScalacOptions
+
+ private[this] def wartremoverErrorsScalacOptions: Seq[String] =
+ wartremoverErrors.distinct.map(w => s"-P:wartremover:traverser:${w.className}")
+
+ private[this] def wartremoverWarningsScalacOptions: Seq[String] =
+ wartremoverWarnings.distinct
+ .filterNot(wartremoverErrors contains _)
+ .map(w => s"-P:wartremover:only-warn-traverser:${w.className}")
+
+ private[this] def wartremoverExcludedScalacOptions: Seq[String] =
+ wartremoverExcluded.distinct.map(c => s"-P:wartremover:excluded:${c.getAbsolutePath}")
+
+ private[this] def wartremoverClasspathsScalacOptions: Seq[String] =
+ wartremoverClasspaths.distinct.map(cp => s"-P:wartremover:cp:$cp")
+
+ /** List of Warts that will be reported as compilation errors. */
+ def wartremoverErrors: Seq[WartTraverser] = Seq.empty
+
+ /** List of Warts that will be reported as compilation warnings. */
+ def wartremoverWarnings: Seq[WartTraverser] = Seq.empty
+
+ /** List of files to be excluded from all checks. */
+ def wartremoverExcluded: Seq[File] = Seq.empty
+
+ /** List of classpaths for custom Warts. */
+ def wartremoverClasspaths: Seq[String] = Seq.empty
+}
diff --git a/plugins/wartremover/build/build.scala b/plugins/wartremover/build/build.scala
new file mode 100644
index 0000000..d62c571
--- /dev/null
+++ b/plugins/wartremover/build/build.scala
@@ -0,0 +1,9 @@
+import cbt._
+
+class Build(val context: Context) extends Plugin {
+ override def dependencies =
+ super.dependencies ++
+ Resolver( mavenCentral ).bind(
+ ScalaDependency("org.wartremover", "wartremover", "1.1.1")
+ )
+}
diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala
index 91181d9..f444803 100644
--- a/stage2/BuildBuild.scala
+++ b/stage2/BuildBuild.scala
@@ -13,6 +13,7 @@ trait BuildBuild extends BaseBuild{
final lazy val scalaJs = DirectoryDependency( managedContext.cbtHome ++ "/plugins/scalajs" )
final lazy val scalariform = DirectoryDependency( managedContext.cbtHome ++ "/plugins/scalariform" )
final lazy val scalafmt = DirectoryDependency( managedContext.cbtHome ++ "/plugins/scalafmt" )
+ final lazy val wartremover = DirectoryDependency( managedContext.cbtHome ++ "/plugins/wartremover" )
final lazy val uberJar = DirectoryDependency( managedContext.cbtHome ++ "/plugins/uber-jar" )
}
diff --git a/test/test.scala b/test/test.scala
index 4f332ea..4f0afcd 100644
--- a/test/test.scala
+++ b/test/test.scala
@@ -185,6 +185,7 @@ object Main{
compile("../plugins/scalajs")
compile("../plugins/scalariform")
compile("../plugins/scalatest")
+ compile("../plugins/wartremover")
compile("../plugins/uber-jar")
compile("../examples/scalafmt-example")
compile("../examples/scalariform-example")
@@ -220,6 +221,13 @@ object Main{
assert(res.err contains "You need to define a class Build in build.scala in", res.err)
}
+ {
+ val res = runCbt("../examples/wartremover-example", Seq("compile"))
+ assert(!res.exit0)
+ assert(res.err.contains("var is disabled"), res.out)
+ assert(res.err.contains("null is disabled"), res.out)
+ }
+
System.err.println(" DONE!")
System.err.println( successes.toString ++ " succeeded, "++ failures.toString ++ " failed" )
if(failures > 0) System.exit(1) else System.exit(0)