Skip to content

Commit ea598fc

Browse files
author
Anton Troshin
authored
Merge pull request #2 from SupersonicAds/fix/wrongSettingsScope
Fix Settings Scope Add test Update README.md
2 parents 5da35b3 + 3dcedbc commit ea598fc

File tree

5 files changed

+40
-22
lines changed

5 files changed

+40
-22
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ stages:
1313
jobs:
1414
include:
1515
- stage: build
16-
script: sbt ++$TRAVIS_SCALA_VERSION test
16+
script: sbt ++$TRAVIS_SCALA_VERSION scripted
1717
- stage: publish
1818
script: sbt ++$TRAVIS_SCALA_VERSION releaseEarly;
1919

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,27 @@ Add the plugin as SBT dependency to your `project/plugins.sbt`
1717
```
1818
resolvers += Resolver.bintrayRepo("ironsonic", "sbt-plugins")
1919
20-
addSbtPlugin("com.supersonic" % "sonic-dependency-tree" % "0.0.1")
20+
addSbtPlugin("com.supersonic" % "sonic-dependency-tree" % "0.0.2")
2121
```
2222

23-
Since it is an Auto Plugin, no need to explicitly enable it on the root project.
23+
Since it is an Auto Plugin, no need to explicitly enable it.
2424

2525
If you still wish to do so, you can do it like this:
2626
``` scala
2727
lazy val root = (project in file("."))
2828
.enablePlugins(SonicDependencyTreePlugin)
2929
```
3030

31+
## Important Note
32+
All Settings and Task are defined as `Global` and should be defined somewhere in `build.sbt` but not on individual projects.
33+
34+
For example:
35+
```scala
36+
sonicDependenciesS3BasePath in Global := "my-folder"
37+
sonicDependenciesS3Bucket in Global := "dependencies-bucket"
38+
sonicDependenciesUploadFilename in Global := "dependencies.json"
39+
```
40+
3141
## Settings
3242

3343
- `sonicDependenciesExcludeScalaLibrary` : `Boolean`
@@ -60,16 +70,12 @@ lazy val root = (project in file("."))
6070
## S3 configuration
6171
You can upload the dependency tree of the project to AWS S3 using this command `sbt sonicDependenciesUploadToS3`
6272

63-
Since the upload task is for the whole project, settings for it should be set on the root project.
73+
Reminder: Because the upload task is Global, the settings should be defined using `in Global` scope.
6474
For example:
6575
``` scala
66-
lazy val root = (project in file("."))
67-
.enablePlugins(SonicDependencyTreePlugin).
68-
.settings(
69-
sonicDependenciesS3BasePath := "my-folder",
70-
sonicDependenciesS3Bucket := "dependencies-bucket",
71-
sonicDependenciesUploadFilename := "dependencies.json"
72-
)
76+
sonicDependenciesS3BasePath in Global := "my-folder",
77+
sonicDependenciesS3Bucket in Global := "dependencies-bucket",
78+
sonicDependenciesUploadFilename in Global := "dependencies.json"
7379
```
7480
This will upload the file to `S3://dependencies-bucket/my-folder/dependencies.json`
7581

src/main/scala/com/supersonic/SonicDependencyTreePlugin.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.amazonaws.{ClientConfiguration, Protocol}
44
import com.amazonaws.auth.{AWSStaticCredentialsProvider, BasicAWSCredentials, DefaultAWSCredentialsProviderChain}
55
import com.amazonaws.services.s3.AmazonS3ClientBuilder
66
import play.api.libs.json.{Json, Writes}
7-
import sbt._
7+
import sbt.{Def, _}
88
import scala.sys.process.Process
99
import scala.util.{Failure, Success, Try}
1010

@@ -27,11 +27,13 @@ object SonicDependencyTreePlugin extends AutoPlugin {
2727

2828
override def trigger = allRequirements
2929

30-
override lazy val buildSettings = Seq(
31-
sonicDependenciesExcludeScalaLibrary in Global := false,
30+
override def globalSettings: Seq[Def.Setting[_]] = baseSettings
31+
32+
private lazy val baseSettings = Seq(
33+
sonicDependenciesExcludeScalaLibrary := false,
3234
sonicDependenciesGitCommit := println(commitHash),
33-
sonicDependenciesS3BasePath in Global := "",
34-
sonicDependenciesS3Bucket in Global := "",
35+
sonicDependenciesS3BasePath := "",
36+
sonicDependenciesS3Bucket := "",
3537
sonicDependenciesS3Credentials := Seq.empty,
3638
sonicDependenciesUploadFilename := s"$commitHash.json",
3739
sonicDependencies := printTreeTask.value,
@@ -41,15 +43,15 @@ object SonicDependencyTreePlugin extends AutoPlugin {
4143

4244
private def uploadDependenciesTask = Def.task {
4345

44-
val s3BasePathValue = sonicDependenciesS3BasePath.value
4546
val s3BucketValue = sonicDependenciesS3Bucket.value
47+
val s3BasePathValue = sonicDependenciesS3BasePath.value
4648

4749
val log = Keys.streams.value.log
4850

49-
if (Option(s3BucketValue).isEmpty) {
51+
if (s3BucketValue == null || s3BucketValue.isEmpty) {
5052
throw new MessageOnlyException("sonicDependenciesS3Bucket is not set")
5153
}
52-
if (Option(s3BasePathValue).isEmpty) {
54+
if (s3BasePathValue == null || s3BasePathValue.isEmpty) {
5355
throw new MessageOnlyException("sonicDependenciesS3BasePath is not set")
5456
}
5557

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
sonicDependenciesExcludeScalaLibrary in Global:= true
2+
sonicDependenciesS3BasePath in Global := "s3testPath"
3+
sonicDependenciesS3Bucket in Global := "s3testBucket"
4+
sonicDependenciesUploadFilename in Global := "testFileName.json"
15

26
lazy val root = (project in file("."))
3-
.enablePlugins(SonicDependencyTreePlugin)
47
.settings(
58
scalaVersion := "2.11.12",
6-
version := "0.1"
9+
version := "0.1",
10+
TaskKey[Unit]("check") in Global := {
11+
if(sonicDependenciesExcludeScalaLibrary.value != true) sys.error("sonicDependenciesExcludeScalaLibrary not correct")
12+
if(sonicDependenciesS3BasePath.value != "s3testPath") sys.error("sonicDependenciesS3BasePath not correct")
13+
if(sonicDependenciesS3Bucket.value != "s3testBucket") sys.error("sonicDependenciesS3Bucket not correct")
14+
if(sonicDependenciesUploadFilename.value != "testFileName.json") sys.error("sonicDependenciesUploadFilename not correct")
15+
()
16+
}
717
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
> sonicDependencies
1+
> check

0 commit comments

Comments
 (0)