From 643a2ad91c481b8a70463347e89723b52124fc5e Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 08:22:51 +1300 Subject: [PATCH 1/8] Add compile then check task --- src/main/scala/org/scalastyle/sbt/Plugin.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala index 17a5b27..3b79265 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") @@ -84,6 +88,11 @@ object ScalastylePlugin extends AutoPlugin { val streamsValue = streams.value val configValue = scalastyleConfig.value Tasks.doGenerateConfig(configValue, streamsValue) + }, + compileThenCheckStyle := { + val analysis = compile.value + val _ = scalastyle.toTask("").value + analysis } ) From f9686569f7ad4dd00b0e7fc2ef6e8a5224bb8fae Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 08:23:28 +1300 Subject: [PATCH 2/8] Add failing test to verify task execution order --- scripted.sbt | 1 + .../compile-task/compiles-first/build.sbt | 27 +++++++++++++++++++ .../compiles-first/project/plugins.sbt | 9 +++++++ .../compiles-first/scalastyle-config.xml | 1 + .../compiles-first/src/main/scala/Hello.scala | 1 + src/sbt-test/compile-task/compiles-first/test | 3 +++ 6 files changed, 42 insertions(+) create mode 100644 src/sbt-test/compile-task/compiles-first/build.sbt create mode 100644 src/sbt-test/compile-task/compiles-first/project/plugins.sbt create mode 100644 src/sbt-test/compile-task/compiles-first/scalastyle-config.xml create mode 100644 src/sbt-test/compile-task/compiles-first/src/main/scala/Hello.scala create mode 100644 src/sbt-test/compile-task/compiles-first/test 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/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 From c7f1cceae27bd1628e2b5b0e72121ea2906aa82e Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 09:17:10 +1300 Subject: [PATCH 3/8] Enforce the execution order for compileThenCheckStyle --- src/main/scala/org/scalastyle/sbt/Plugin.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala index 3b79265..38f7cc9 100644 --- a/src/main/scala/org/scalastyle/sbt/Plugin.scala +++ b/src/main/scala/org/scalastyle/sbt/Plugin.scala @@ -89,11 +89,13 @@ object ScalastylePlugin extends AutoPlugin { val configValue = scalastyleConfig.value Tasks.doGenerateConfig(configValue, streamsValue) }, - compileThenCheckStyle := { + compileThenCheckStyle := Def.taskDyn { val analysis = compile.value - val _ = scalastyle.toTask("").value - analysis - } + Def.task { + val _ = scalastyle.toTask("").value + analysis + } + }.value ) override def requires: Plugins = sbt.plugins.JvmPlugin From 28f0a99d6d853a4cb08053307423b8aa0b2a7c06 Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 17:11:52 +1300 Subject: [PATCH 4/8] Add test to check that compilation failures are preserved --- .../compile-task/retains-compilation-error/build.sbt | 3 +++ .../retains-compilation-error/project/plugins.sbt | 9 +++++++++ .../retains-compilation-error/scalastyle-config.xml | 1 + .../retains-compilation-error/src/main/scala/Hello.scala | 1 + src/sbt-test/compile-task/retains-compilation-error/test | 3 +++ 5 files changed, 17 insertions(+) create mode 100644 src/sbt-test/compile-task/retains-compilation-error/build.sbt create mode 100644 src/sbt-test/compile-task/retains-compilation-error/project/plugins.sbt create mode 100644 src/sbt-test/compile-task/retains-compilation-error/scalastyle-config.xml create mode 100644 src/sbt-test/compile-task/retains-compilation-error/src/main/scala/Hello.scala create mode 100644 src/sbt-test/compile-task/retains-compilation-error/test 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 From e60375db5051f0b5c2939a0ebfb65deaa94ca0bc Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 17:21:23 +1300 Subject: [PATCH 5/8] Add scalastyleCompileArgs setting --- src/main/scala/org/scalastyle/sbt/Plugin.scala | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala index 38f7cc9..e5719ea 100644 --- a/src/main/scala/org/scalastyle/sbt/Plugin.scala +++ b/src/main/scala/org/scalastyle/sbt/Plugin.scala @@ -53,7 +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 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") @@ -63,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[Seq[String]]("The arguments that are passed to scalastyle when using compileThenCheckStyle") } import autoImport._ @@ -119,7 +120,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 := Seq.empty, + (scalastyleCompileArgs in Test) := (scalastyleCompileArgs in scalastyle).value ) ++ Project.inConfig(Compile)(rawScalastyleSettings()) ++ Project.inConfig(Test)(rawScalastyleSettings()) From e1929c9dec3769fa85ff7c074b6d5a1da2d9905f Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Mon, 12 Mar 2018 17:27:08 +1300 Subject: [PATCH 6/8] Add failing test to verify use of scalastyleCompileArgs setting --- src/main/scala/org/scalastyle/sbt/Plugin.scala | 4 ++-- src/sbt-test/config/compile-args/build.sbt | 6 ++++++ src/sbt-test/config/compile-args/project/plugins.sbt | 9 +++++++++ src/sbt-test/config/compile-args/scalastyle-config.xml | 8 ++++++++ .../config/compile-args/src/main/scala/hello.scala | 3 +++ src/sbt-test/config/compile-args/test | 2 ++ 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/sbt-test/config/compile-args/build.sbt create mode 100644 src/sbt-test/config/compile-args/project/plugins.sbt create mode 100644 src/sbt-test/config/compile-args/scalastyle-config.xml create mode 100644 src/sbt-test/config/compile-args/src/main/scala/hello.scala create mode 100644 src/sbt-test/config/compile-args/test diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala index e5719ea..f25e995 100644 --- a/src/main/scala/org/scalastyle/sbt/Plugin.scala +++ b/src/main/scala/org/scalastyle/sbt/Plugin.scala @@ -63,7 +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[Seq[String]]("The arguments that are passed to scalastyle when using compileThenCheckStyle") + val scalastyleCompileArgs = settingKey[String]("The arguments that are passed to scalastyle when using compileThenCheckStyle") } import autoImport._ @@ -121,7 +121,7 @@ object ScalastylePlugin extends AutoPlugin { (scalastyleFailOnWarning in Test) := (scalastyleFailOnWarning in scalastyle).value, scalastyleSources := (unmanagedSourceDirectories in Compile).value, (scalastyleSources in Test) := (unmanagedSourceDirectories in Test).value, - scalastyleCompileArgs := Seq.empty, + scalastyleCompileArgs := "", (scalastyleCompileArgs in Test) := (scalastyleCompileArgs in scalastyle).value ) ++ Project.inConfig(Compile)(rawScalastyleSettings()) ++ 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..dbbb491 --- /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 From 9be80df403faf60bd7b129a9d057eda802a859d2 Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Tue, 13 Mar 2018 08:00:52 +1300 Subject: [PATCH 7/8] Use scalastyleCompileArgs in compileThenCheckStyle --- src/main/scala/org/scalastyle/sbt/Plugin.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/scala/org/scalastyle/sbt/Plugin.scala b/src/main/scala/org/scalastyle/sbt/Plugin.scala index f25e995..692a537 100644 --- a/src/main/scala/org/scalastyle/sbt/Plugin.scala +++ b/src/main/scala/org/scalastyle/sbt/Plugin.scala @@ -92,8 +92,9 @@ object ScalastylePlugin extends AutoPlugin { }, compileThenCheckStyle := Def.taskDyn { val analysis = compile.value + val args = scalastyleCompileArgs.value Def.task { - val _ = scalastyle.toTask("").value + val _ = scalastyle.toTask(args).value analysis } }.value From ecb71a97801f093d4a7082bd3cbfd8700a75e766 Mon Sep 17 00:00:00 2001 From: Jason Steenstra-Pickens Date: Tue, 13 Mar 2018 08:21:58 +1300 Subject: [PATCH 8/8] Add more tests for compileThenCheckStyle --- src/sbt-test/compile-task/scoped/build.sbt | 17 ++++++++++++ .../compile-task/scoped/project/plugins.sbt | 9 +++++++ .../compile-task/scoped/scalastyle-config.xml | 1 + .../scoped/src/main/scala/Hello.scala | 1 + src/sbt-test/compile-task/scoped/test | 5 ++++ .../compile-args/src/main/scala/hello.scala | 2 +- .../compiles-first/build.sbt | 27 +++++++++++++++++++ .../compiles-first/project/plugins.sbt | 9 +++++++ .../compiles-first/scalastyle-config.xml | 1 + .../compiles-first/src/test/scala/Hello.scala | 1 + .../test-compile-task/compiles-first/test | 3 +++ .../retains-compilation-error/build.sbt | 3 +++ .../project/plugins.sbt | 9 +++++++ .../scalastyle-config.xml | 1 + .../src/test/scala/Hello.scala | 1 + .../retains-compilation-error/test | 3 +++ .../test-compile-task/scoped/build.sbt | 17 ++++++++++++ .../scoped/project/plugins.sbt | 9 +++++++ .../scoped/scalastyle-config.xml | 1 + .../scoped/src/test/scala/Hello.scala | 1 + src/sbt-test/test-compile-task/scoped/test | 5 ++++ .../test-config/compile-args/build.sbt | 6 +++++ .../compile-args/project/plugins.sbt | 9 +++++++ .../compile-args/scalastyle-config.xml | 8 ++++++ .../compile-args/src/test/scala/hello.scala | 3 +++ src/sbt-test/test-config/compile-args/test | 2 ++ 26 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 src/sbt-test/compile-task/scoped/build.sbt create mode 100644 src/sbt-test/compile-task/scoped/project/plugins.sbt create mode 100644 src/sbt-test/compile-task/scoped/scalastyle-config.xml create mode 100644 src/sbt-test/compile-task/scoped/src/main/scala/Hello.scala create mode 100644 src/sbt-test/compile-task/scoped/test create mode 100644 src/sbt-test/test-compile-task/compiles-first/build.sbt create mode 100644 src/sbt-test/test-compile-task/compiles-first/project/plugins.sbt create mode 100644 src/sbt-test/test-compile-task/compiles-first/scalastyle-config.xml create mode 100644 src/sbt-test/test-compile-task/compiles-first/src/test/scala/Hello.scala create mode 100644 src/sbt-test/test-compile-task/compiles-first/test create mode 100644 src/sbt-test/test-compile-task/retains-compilation-error/build.sbt create mode 100644 src/sbt-test/test-compile-task/retains-compilation-error/project/plugins.sbt create mode 100644 src/sbt-test/test-compile-task/retains-compilation-error/scalastyle-config.xml create mode 100644 src/sbt-test/test-compile-task/retains-compilation-error/src/test/scala/Hello.scala create mode 100644 src/sbt-test/test-compile-task/retains-compilation-error/test create mode 100644 src/sbt-test/test-compile-task/scoped/build.sbt create mode 100644 src/sbt-test/test-compile-task/scoped/project/plugins.sbt create mode 100644 src/sbt-test/test-compile-task/scoped/scalastyle-config.xml create mode 100644 src/sbt-test/test-compile-task/scoped/src/test/scala/Hello.scala create mode 100644 src/sbt-test/test-compile-task/scoped/test create mode 100644 src/sbt-test/test-config/compile-args/build.sbt create mode 100644 src/sbt-test/test-config/compile-args/project/plugins.sbt create mode 100644 src/sbt-test/test-config/compile-args/scalastyle-config.xml create mode 100644 src/sbt-test/test-config/compile-args/src/test/scala/hello.scala create mode 100644 src/sbt-test/test-config/compile-args/test 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/src/main/scala/hello.scala b/src/sbt-test/config/compile-args/src/main/scala/hello.scala index dbbb491..c2b8452 100644 --- a/src/sbt-test/config/compile-args/src/main/scala/hello.scala +++ b/src/sbt-test/config/compile-args/src/main/scala/hello.scala @@ -1,3 +1,3 @@ object hello { - + } 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