diff --git a/scripted.sbt b/scripted.sbt
index 03eff0d..bf7ff41 100644
--- a/scripted.sbt
+++ b/scripted.sbt
@@ -2,6 +2,7 @@ ScriptedPlugin.scriptedSettings
scriptedLaunchOpts ++= {
Seq("-Xmx1024M",
+ "-XX:MaxPermSize=256M",
"-Dplugin.version=" + version.value,
"-Dsbt.version=" + (sbtVersion in pluginCrossBuild).value)
}
diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala
index 17a5b27..692a537 100644
--- a/src/main/scala/org/scalastyle/sbt/Plugin.scala
+++ b/src/main/scala/org/scalastyle/sbt/Plugin.scala
@@ -33,10 +33,13 @@ import org.scalastyle.ScalastyleChecker
import org.scalastyle.ScalastyleConfiguration
import org.scalastyle.XmlOutput
import sbt.ConfigKey.configurationToKey
+import sbt.Def.Initialize
+import sbt.Keys.compile
import sbt.Keys.streams
import sbt.Keys.target
import sbt.Keys.unmanagedSourceDirectories
import sbt._
+import sbt.inc.Analysis
import sbt.std.TaskStreams
import scala.io.Codec
@@ -50,6 +53,7 @@ object ScalastylePlugin extends AutoPlugin {
object autoImport {
val scalastyle = inputKey[Unit]("Run scalastyle on your code")
val scalastyleGenerateConfig = taskKey[Unit]("Generate a default configuration files for scalastyle")
+ val compileThenCheckStyle = taskKey[Analysis]("Compiles sources and then runs scalastyle on your code")
val scalastyleTarget = settingKey[File]("XML output file from scalastyle")
val scalastyleConfig = settingKey[File]("Scalastyle configuration file")
@@ -59,6 +63,7 @@ object ScalastylePlugin extends AutoPlugin {
val scalastyleConfigRefreshHours = settingKey[Integer]("How many hours until next run will fetch the scalastyle-config.xml again if location is a URI.")
val scalastyleConfigUrlCacheFile = settingKey[String]("If scalastyleConfigUrl is set, it will be cached here")
val scalastyleSources = settingKey[Seq[File]]("Which sources will scalastyle check")
+ val scalastyleCompileArgs = settingKey[String]("The arguments that are passed to scalastyle when using compileThenCheckStyle")
}
import autoImport._
@@ -84,7 +89,15 @@ object ScalastylePlugin extends AutoPlugin {
val streamsValue = streams.value
val configValue = scalastyleConfig.value
Tasks.doGenerateConfig(configValue, streamsValue)
- }
+ },
+ compileThenCheckStyle := Def.taskDyn {
+ val analysis = compile.value
+ val args = scalastyleCompileArgs.value
+ Def.task {
+ val _ = scalastyle.toTask(args).value
+ analysis
+ }
+ }.value
)
override def requires: Plugins = sbt.plugins.JvmPlugin
@@ -108,7 +121,9 @@ object ScalastylePlugin extends AutoPlugin {
scalastyleFailOnWarning := false,
(scalastyleFailOnWarning in Test) := (scalastyleFailOnWarning in scalastyle).value,
scalastyleSources := (unmanagedSourceDirectories in Compile).value,
- (scalastyleSources in Test) := (unmanagedSourceDirectories in Test).value
+ (scalastyleSources in Test) := (unmanagedSourceDirectories in Test).value,
+ scalastyleCompileArgs := "",
+ (scalastyleCompileArgs in Test) := (scalastyleCompileArgs in scalastyle).value
) ++
Project.inConfig(Compile)(rawScalastyleSettings()) ++
Project.inConfig(Test)(rawScalastyleSettings())
diff --git a/src/sbt-test/compile-task/compiles-first/build.sbt b/src/sbt-test/compile-task/compiles-first/build.sbt
new file mode 100644
index 0000000..f9c9994
--- /dev/null
+++ b/src/sbt-test/compile-task/compiles-first/build.sbt
@@ -0,0 +1,27 @@
+import scala.concurrent.duration._
+
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
+inConfig(Compile) {
+ Seq(
+ compile := {
+ val log = streams.value.log
+ log.debug("Pausing compile task for 1 second")
+ Thread.sleep(1.second.toMillis)
+ log.debug("Checking if scalastyle has already executed")
+ val file = target.value / "scalastyle"
+ if (file.exists()) {
+ throw new RuntimeException("scalastyle task executed before or during the compile task")
+ }
+ compile.value
+ },
+ scalastyle := {
+ val log = streams.value.log
+ log.debug("Running scalastyle")
+ val file = target.value / "scalastyle"
+ IO.write(file, "scalastyle")
+ }
+ )
+}
diff --git a/src/sbt-test/compile-task/compiles-first/project/plugins.sbt b/src/sbt-test/compile-task/compiles-first/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/compile-task/compiles-first/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/compile-task/compiles-first/scalastyle-config.xml b/src/sbt-test/compile-task/compiles-first/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/compile-task/compiles-first/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/compile-task/compiles-first/src/main/scala/Hello.scala b/src/sbt-test/compile-task/compiles-first/src/main/scala/Hello.scala
new file mode 100644
index 0000000..9307fd8
--- /dev/null
+++ b/src/sbt-test/compile-task/compiles-first/src/main/scala/Hello.scala
@@ -0,0 +1 @@
+class Hello
diff --git a/src/sbt-test/compile-task/compiles-first/test b/src/sbt-test/compile-task/compiles-first/test
new file mode 100644
index 0000000..eeb9704
--- /dev/null
+++ b/src/sbt-test/compile-task/compiles-first/test
@@ -0,0 +1,3 @@
+# compileThenCheckStyle compiles first then if successful checks the style
+> clean
+> compileThenCheckStyle
diff --git a/src/sbt-test/compile-task/retains-compilation-error/build.sbt b/src/sbt-test/compile-task/retains-compilation-error/build.sbt
new file mode 100644
index 0000000..401d300
--- /dev/null
+++ b/src/sbt-test/compile-task/retains-compilation-error/build.sbt
@@ -0,0 +1,3 @@
+version := "0.1"
+
+scalaVersion := "2.10.0"
diff --git a/src/sbt-test/compile-task/retains-compilation-error/project/plugins.sbt b/src/sbt-test/compile-task/retains-compilation-error/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/compile-task/retains-compilation-error/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/compile-task/retains-compilation-error/scalastyle-config.xml b/src/sbt-test/compile-task/retains-compilation-error/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/compile-task/retains-compilation-error/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/compile-task/retains-compilation-error/src/main/scala/Hello.scala b/src/sbt-test/compile-task/retains-compilation-error/src/main/scala/Hello.scala
new file mode 100644
index 0000000..e965047
--- /dev/null
+++ b/src/sbt-test/compile-task/retains-compilation-error/src/main/scala/Hello.scala
@@ -0,0 +1 @@
+Hello
diff --git a/src/sbt-test/compile-task/retains-compilation-error/test b/src/sbt-test/compile-task/retains-compilation-error/test
new file mode 100644
index 0000000..adbceaf
--- /dev/null
+++ b/src/sbt-test/compile-task/retains-compilation-error/test
@@ -0,0 +1,3 @@
+# compileThenCheckStyle fails if the compile task fails
+> clean
+-> compileThenCheckStyle
diff --git a/src/sbt-test/compile-task/scoped/build.sbt b/src/sbt-test/compile-task/scoped/build.sbt
new file mode 100644
index 0000000..3161478
--- /dev/null
+++ b/src/sbt-test/compile-task/scoped/build.sbt
@@ -0,0 +1,17 @@
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
+inConfig(Compile) {
+ Seq(
+ compile := {
+ val file = target.value / "compile"
+ IO.write(file, "compile")
+ compile.value
+ },
+ scalastyle := {
+ val file = target.value / "scalastyle"
+ IO.write(file, "scalastyle")
+ }
+ )
+}
diff --git a/src/sbt-test/compile-task/scoped/project/plugins.sbt b/src/sbt-test/compile-task/scoped/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/compile-task/scoped/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/compile-task/scoped/scalastyle-config.xml b/src/sbt-test/compile-task/scoped/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/compile-task/scoped/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/compile-task/scoped/src/main/scala/Hello.scala b/src/sbt-test/compile-task/scoped/src/main/scala/Hello.scala
new file mode 100644
index 0000000..9307fd8
--- /dev/null
+++ b/src/sbt-test/compile-task/scoped/src/main/scala/Hello.scala
@@ -0,0 +1 @@
+class Hello
diff --git a/src/sbt-test/compile-task/scoped/test b/src/sbt-test/compile-task/scoped/test
new file mode 100644
index 0000000..137cd87
--- /dev/null
+++ b/src/sbt-test/compile-task/scoped/test
@@ -0,0 +1,5 @@
+# compileThenCheckStyle depends on tasks in the same scope
+> clean
+> compileThenCheckStyle
+$ exists target/compile
+$ exists target/scalastyle
diff --git a/src/sbt-test/config/compile-args/build.sbt b/src/sbt-test/config/compile-args/build.sbt
new file mode 100644
index 0000000..f2b898a
--- /dev/null
+++ b/src/sbt-test/config/compile-args/build.sbt
@@ -0,0 +1,6 @@
+scalastyleCompileArgs := " w"
+
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
diff --git a/src/sbt-test/config/compile-args/project/plugins.sbt b/src/sbt-test/config/compile-args/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/config/compile-args/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/config/compile-args/scalastyle-config.xml b/src/sbt-test/config/compile-args/scalastyle-config.xml
new file mode 100644
index 0000000..27dc8ea
--- /dev/null
+++ b/src/sbt-test/config/compile-args/scalastyle-config.xml
@@ -0,0 +1,8 @@
+
+ Scalastyle standard configuration
+
+
+
+
+
+
diff --git a/src/sbt-test/config/compile-args/src/main/scala/hello.scala b/src/sbt-test/config/compile-args/src/main/scala/hello.scala
new file mode 100644
index 0000000..c2b8452
--- /dev/null
+++ b/src/sbt-test/config/compile-args/src/main/scala/hello.scala
@@ -0,0 +1,3 @@
+object hello {
+
+}
diff --git a/src/sbt-test/config/compile-args/test b/src/sbt-test/config/compile-args/test
new file mode 100644
index 0000000..372725d
--- /dev/null
+++ b/src/sbt-test/config/compile-args/test
@@ -0,0 +1,2 @@
+# compileThenCheckStyle uses the scalastyleCompileArgs
+-> compileThenCheckStyle
diff --git a/src/sbt-test/test-compile-task/compiles-first/build.sbt b/src/sbt-test/test-compile-task/compiles-first/build.sbt
new file mode 100644
index 0000000..af295da
--- /dev/null
+++ b/src/sbt-test/test-compile-task/compiles-first/build.sbt
@@ -0,0 +1,27 @@
+import scala.concurrent.duration._
+
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
+inConfig(Test) {
+ Seq(
+ compile := {
+ val log = streams.value.log
+ log.debug("Pausing compile task for 1 second")
+ Thread.sleep(1.second.toMillis)
+ log.debug("Checking if scalastyle has already executed")
+ val file = target.value / "scalastyle"
+ if (file.exists()) {
+ throw new RuntimeException("scalastyle task executed before or during the compile task")
+ }
+ compile.value
+ },
+ scalastyle := {
+ val log = streams.value.log
+ log.debug("Running scalastyle")
+ val file = target.value / "scalastyle"
+ IO.write(file, "scalastyle")
+ }
+ )
+}
diff --git a/src/sbt-test/test-compile-task/compiles-first/project/plugins.sbt b/src/sbt-test/test-compile-task/compiles-first/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/test-compile-task/compiles-first/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/test-compile-task/compiles-first/scalastyle-config.xml b/src/sbt-test/test-compile-task/compiles-first/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/test-compile-task/compiles-first/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/test-compile-task/compiles-first/src/test/scala/Hello.scala b/src/sbt-test/test-compile-task/compiles-first/src/test/scala/Hello.scala
new file mode 100644
index 0000000..9307fd8
--- /dev/null
+++ b/src/sbt-test/test-compile-task/compiles-first/src/test/scala/Hello.scala
@@ -0,0 +1 @@
+class Hello
diff --git a/src/sbt-test/test-compile-task/compiles-first/test b/src/sbt-test/test-compile-task/compiles-first/test
new file mode 100644
index 0000000..ae21959
--- /dev/null
+++ b/src/sbt-test/test-compile-task/compiles-first/test
@@ -0,0 +1,3 @@
+# compileThenCheckStyle compiles first then if successful checks the style
+> clean
+> test:compileThenCheckStyle
diff --git a/src/sbt-test/test-compile-task/retains-compilation-error/build.sbt b/src/sbt-test/test-compile-task/retains-compilation-error/build.sbt
new file mode 100644
index 0000000..401d300
--- /dev/null
+++ b/src/sbt-test/test-compile-task/retains-compilation-error/build.sbt
@@ -0,0 +1,3 @@
+version := "0.1"
+
+scalaVersion := "2.10.0"
diff --git a/src/sbt-test/test-compile-task/retains-compilation-error/project/plugins.sbt b/src/sbt-test/test-compile-task/retains-compilation-error/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/test-compile-task/retains-compilation-error/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/test-compile-task/retains-compilation-error/scalastyle-config.xml b/src/sbt-test/test-compile-task/retains-compilation-error/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/test-compile-task/retains-compilation-error/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/test-compile-task/retains-compilation-error/src/test/scala/Hello.scala b/src/sbt-test/test-compile-task/retains-compilation-error/src/test/scala/Hello.scala
new file mode 100644
index 0000000..e965047
--- /dev/null
+++ b/src/sbt-test/test-compile-task/retains-compilation-error/src/test/scala/Hello.scala
@@ -0,0 +1 @@
+Hello
diff --git a/src/sbt-test/test-compile-task/retains-compilation-error/test b/src/sbt-test/test-compile-task/retains-compilation-error/test
new file mode 100644
index 0000000..c35932d
--- /dev/null
+++ b/src/sbt-test/test-compile-task/retains-compilation-error/test
@@ -0,0 +1,3 @@
+# compileThenCheckStyle fails if the compile task fails
+> clean
+-> test:compileThenCheckStyle
diff --git a/src/sbt-test/test-compile-task/scoped/build.sbt b/src/sbt-test/test-compile-task/scoped/build.sbt
new file mode 100644
index 0000000..81ecbea
--- /dev/null
+++ b/src/sbt-test/test-compile-task/scoped/build.sbt
@@ -0,0 +1,17 @@
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
+inConfig(Test) {
+ Seq(
+ compile := {
+ val file = target.value / "compile"
+ IO.write(file, "compile")
+ compile.value
+ },
+ scalastyle := {
+ val file = target.value / "scalastyle"
+ IO.write(file, "scalastyle")
+ }
+ )
+}
diff --git a/src/sbt-test/test-compile-task/scoped/project/plugins.sbt b/src/sbt-test/test-compile-task/scoped/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/test-compile-task/scoped/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/test-compile-task/scoped/scalastyle-config.xml b/src/sbt-test/test-compile-task/scoped/scalastyle-config.xml
new file mode 100644
index 0000000..14b0b57
--- /dev/null
+++ b/src/sbt-test/test-compile-task/scoped/scalastyle-config.xml
@@ -0,0 +1 @@
+
diff --git a/src/sbt-test/test-compile-task/scoped/src/test/scala/Hello.scala b/src/sbt-test/test-compile-task/scoped/src/test/scala/Hello.scala
new file mode 100644
index 0000000..9307fd8
--- /dev/null
+++ b/src/sbt-test/test-compile-task/scoped/src/test/scala/Hello.scala
@@ -0,0 +1 @@
+class Hello
diff --git a/src/sbt-test/test-compile-task/scoped/test b/src/sbt-test/test-compile-task/scoped/test
new file mode 100644
index 0000000..ae92e32
--- /dev/null
+++ b/src/sbt-test/test-compile-task/scoped/test
@@ -0,0 +1,5 @@
+# compileThenCheckStyle depends on tasks in the same scope
+> clean
+> test:compileThenCheckStyle
+$ exists target/compile
+$ exists target/scalastyle
diff --git a/src/sbt-test/test-config/compile-args/build.sbt b/src/sbt-test/test-config/compile-args/build.sbt
new file mode 100644
index 0000000..e1cacfc
--- /dev/null
+++ b/src/sbt-test/test-config/compile-args/build.sbt
@@ -0,0 +1,6 @@
+scalastyleCompileArgs in Test := " w"
+
+version := "0.1"
+
+scalaVersion := "2.10.0"
+
diff --git a/src/sbt-test/test-config/compile-args/project/plugins.sbt b/src/sbt-test/test-config/compile-args/project/plugins.sbt
new file mode 100644
index 0000000..1061e94
--- /dev/null
+++ b/src/sbt-test/test-config/compile-args/project/plugins.sbt
@@ -0,0 +1,9 @@
+resolvers += "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
+
+{
+ val pluginVersion = System.getProperty("plugin.version")
+ if(pluginVersion == null)
+ throw new RuntimeException("""|The system property 'plugin.version' is not defined.
+ |Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
+ else addSbtPlugin("org.scalastyle" % "scalastyle-sbt-plugin" % pluginVersion)
+}
diff --git a/src/sbt-test/test-config/compile-args/scalastyle-config.xml b/src/sbt-test/test-config/compile-args/scalastyle-config.xml
new file mode 100644
index 0000000..27dc8ea
--- /dev/null
+++ b/src/sbt-test/test-config/compile-args/scalastyle-config.xml
@@ -0,0 +1,8 @@
+
+ Scalastyle standard configuration
+
+
+
+
+
+
diff --git a/src/sbt-test/test-config/compile-args/src/test/scala/hello.scala b/src/sbt-test/test-config/compile-args/src/test/scala/hello.scala
new file mode 100644
index 0000000..c2b8452
--- /dev/null
+++ b/src/sbt-test/test-config/compile-args/src/test/scala/hello.scala
@@ -0,0 +1,3 @@
+object hello {
+
+}
diff --git a/src/sbt-test/test-config/compile-args/test b/src/sbt-test/test-config/compile-args/test
new file mode 100644
index 0000000..bc139e6
--- /dev/null
+++ b/src/sbt-test/test-config/compile-args/test
@@ -0,0 +1,2 @@
+# compileThenCheckStyle uses the scalastyleCompileArgs
+-> test:compileThenCheckStyle