diff --git a/.travis.yml b/.travis.yml index 22ce62e..25c070c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ stages: jobs: include: - stage: build - script: sbt ++$TRAVIS_SCALA_VERSION test + script: sbt ++$TRAVIS_SCALA_VERSION scripted - stage: publish script: sbt ++$TRAVIS_SCALA_VERSION releaseEarly; diff --git a/README.md b/README.md index d944c68..1be63e1 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,10 @@ Add the plugin as SBT dependency to your `project/plugins.sbt` ``` resolvers += Resolver.bintrayRepo("ironsonic", "sbt-plugins") -addSbtPlugin("com.supersonic" % "sonic-dependency-tree" % "0.0.1") +addSbtPlugin("com.supersonic" % "sonic-dependency-tree" % "0.0.2") ``` -Since it is an Auto Plugin, no need to explicitly enable it on the root project. +Since it is an Auto Plugin, no need to explicitly enable it. If you still wish to do so, you can do it like this: ``` scala @@ -28,6 +28,16 @@ lazy val root = (project in file(".")) .enablePlugins(SonicDependencyTreePlugin) ``` +## Important Note +All Settings and Task are defined as `Global` and should be defined somewhere in `build.sbt` but not on individual projects. + +For example: +```scala +sonicDependenciesS3BasePath in Global := "my-folder" +sonicDependenciesS3Bucket in Global := "dependencies-bucket" +sonicDependenciesUploadFilename in Global := "dependencies.json" +``` + ## Settings - `sonicDependenciesExcludeScalaLibrary` : `Boolean` @@ -60,16 +70,12 @@ lazy val root = (project in file(".")) ## S3 configuration You can upload the dependency tree of the project to AWS S3 using this command `sbt sonicDependenciesUploadToS3` -Since the upload task is for the whole project, settings for it should be set on the root project. +Reminder: Because the upload task is Global, the settings should be defined using `in Global` scope. For example: ``` scala -lazy val root = (project in file(".")) - .enablePlugins(SonicDependencyTreePlugin). - .settings( - sonicDependenciesS3BasePath := "my-folder", - sonicDependenciesS3Bucket := "dependencies-bucket", - sonicDependenciesUploadFilename := "dependencies.json" - ) +sonicDependenciesS3BasePath in Global := "my-folder", +sonicDependenciesS3Bucket in Global := "dependencies-bucket", +sonicDependenciesUploadFilename in Global := "dependencies.json" ``` This will upload the file to `S3://dependencies-bucket/my-folder/dependencies.json` diff --git a/src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala b/src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala index 41c45a6..70ec1f6 100644 --- a/src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala +++ b/src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala @@ -4,7 +4,7 @@ import com.amazonaws.{ClientConfiguration, Protocol} import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials, DefaultAWSCredentialsProviderChain} import com.amazonaws.services.s3.AmazonS3ClientBuilder import play.api.libs.json.{Json, Writes} -import sbt._ +import sbt.{Def, _} import scala.sys.process.Process import scala.util.{Failure, Success, Try} @@ -27,11 +27,13 @@ object SonicDependencyTreePlugin extends AutoPlugin { override def trigger = allRequirements - override lazy val buildSettings = Seq( - sonicDependenciesExcludeScalaLibrary in Global := false, + override def globalSettings: Seq[Def.Setting[_]] = baseSettings + + private lazy val baseSettings = Seq( + sonicDependenciesExcludeScalaLibrary := false, sonicDependenciesGitCommit := println(commitHash), - sonicDependenciesS3BasePath in Global := "", - sonicDependenciesS3Bucket in Global := "", + sonicDependenciesS3BasePath := "", + sonicDependenciesS3Bucket := "", sonicDependenciesS3Credentials := Seq.empty, sonicDependenciesUploadFilename := s"$commitHash.json", sonicDependencies := printTreeTask.value, @@ -41,15 +43,15 @@ object SonicDependencyTreePlugin extends AutoPlugin { private def uploadDependenciesTask = Def.task { - val s3BasePathValue = sonicDependenciesS3BasePath.value val s3BucketValue = sonicDependenciesS3Bucket.value + val s3BasePathValue = sonicDependenciesS3BasePath.value val log = Keys.streams.value.log - if (Option(s3BucketValue).isEmpty) { + if (s3BucketValue == null || s3BucketValue.isEmpty) { throw new MessageOnlyException("sonicDependenciesS3Bucket is not set") } - if (Option(s3BasePathValue).isEmpty) { + if (s3BasePathValue == null || s3BasePathValue.isEmpty) { throw new MessageOnlyException("sonicDependenciesS3BasePath is not set") } diff --git a/src/sbt-test/sonic-dependency-tree/simple/build.sbt b/src/sbt-test/sonic-dependency-tree/simple/build.sbt index e1466e7..eda94e6 100644 --- a/src/sbt-test/sonic-dependency-tree/simple/build.sbt +++ b/src/sbt-test/sonic-dependency-tree/simple/build.sbt @@ -1,7 +1,17 @@ +sonicDependenciesExcludeScalaLibrary in Global:= true +sonicDependenciesS3BasePath in Global := "s3testPath" +sonicDependenciesS3Bucket in Global := "s3testBucket" +sonicDependenciesUploadFilename in Global := "testFileName.json" lazy val root = (project in file(".")) - .enablePlugins(SonicDependencyTreePlugin) .settings( scalaVersion := "2.11.12", - version := "0.1" + version := "0.1", + TaskKey[Unit]("check") in Global := { + if(sonicDependenciesExcludeScalaLibrary.value != true) sys.error("sonicDependenciesExcludeScalaLibrary not correct") + if(sonicDependenciesS3BasePath.value != "s3testPath") sys.error("sonicDependenciesS3BasePath not correct") + if(sonicDependenciesS3Bucket.value != "s3testBucket") sys.error("sonicDependenciesS3Bucket not correct") + if(sonicDependenciesUploadFilename.value != "testFileName.json") sys.error("sonicDependenciesUploadFilename not correct") + () + } ) diff --git a/src/sbt-test/sonic-dependency-tree/simple/test b/src/sbt-test/sonic-dependency-tree/simple/test index ffdbd6c..a5912a3 100644 --- a/src/sbt-test/sonic-dependency-tree/simple/test +++ b/src/sbt-test/sonic-dependency-tree/simple/test @@ -1 +1 @@ -> sonicDependencies \ No newline at end of file +> check \ No newline at end of file