Skip to content

Commit

Permalink
Merge pull request #2 from SupersonicAds/fix/wrongSettingsScope
Browse files Browse the repository at this point in the history
Fix Settings Scope
Add test
Update README.md
  • Loading branch information
Anton Troshin authored Dec 30, 2019
2 parents 5da35b3 + 3dcedbc commit ea598fc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ 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
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`
Expand Down Expand Up @@ -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`

Expand Down
18 changes: 10 additions & 8 deletions src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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,
Expand All @@ -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")
}

Expand Down
14 changes: 12 additions & 2 deletions src/sbt-test/sonic-dependency-tree/simple/build.sbt
Original file line number Diff line number Diff line change
@@ -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")
()
}
)
2 changes: 1 addition & 1 deletion src/sbt-test/sonic-dependency-tree/simple/test
Original file line number Diff line number Diff line change
@@ -1 +1 @@
> sonicDependencies
> check

0 comments on commit ea598fc

Please sign in to comment.