Skip to content

Commit eb6da53

Browse files
authored
Merge pull request #73 from anilkumarmyla/easier_path
Support sbt 1.4.0
2 parents bb89199 + 835146a commit eb6da53

File tree

5 files changed

+52
-11
lines changed

5 files changed

+52
-11
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ matrix:
1010
- env: SBT_VERSION="1.2.8"
1111
scala: 2.12.11
1212

13-
- env: SBT_VERSION="1.3.8"
13+
- env: SBT_VERSION="1.3.13"
14+
scala: 2.12.11
15+
16+
- env: SBT_VERSION="1.4.0"
1417
scala: 2.12.11
1518

1619
cache:

build.sbt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import ReleaseTransformations._
22

33
enablePlugins(SbtPlugin)
4-
val latestSbt_0_13_version = "0.13.18"
5-
val latestSbt_1_x_version = "1.3.8"
6-
crossSbtVersions := Seq(latestSbt_0_13_version, "1.2.8", latestSbt_1_x_version)
4+
5+
val latestSbt_0_13_x_version = "0.13.18"
6+
val latestSbt_1_2_x_version = "1.2.8"
7+
val latestSbt_1_3_x_version = "1.3.13"
8+
val latestSbt_1_4_x_version = "1.4.0"
9+
10+
crossSbtVersions := Seq(
11+
latestSbt_0_13_x_version,
12+
latestSbt_1_2_x_version,
13+
latestSbt_1_3_x_version,
14+
latestSbt_1_4_x_version
15+
)
716

817
scalaVersion := "2.12.11"
918
organization := "com.github.cb372"
@@ -24,8 +33,8 @@ releaseProcess := Seq[ReleaseStep](
2433
setReleaseVersion,
2534
commitReleaseVersion,
2635
tagRelease,
27-
releaseStepCommandAndRemaining(s"^^$latestSbt_0_13_version publish"),
28-
releaseStepCommandAndRemaining(s"^^$latestSbt_1_x_version publish"),
36+
releaseStepCommandAndRemaining(s"^^$latestSbt_0_13_x_version publish"),
37+
releaseStepCommandAndRemaining(s"^^$latestSbt_1_3_x_version publish"), // Note: if we publish with 1.4.0, the plugin will only work with 1.4.x
2938
releaseStepTask(updateVersionInExampleProject),
3039
setNextVersion,
3140
commitNextVersion,

src/main/scala-sbt-0.13/explicitdeps/package.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ package object explicitdeps {
66

77
val defaultModuleFilter: ModuleFilter = sbt.DependencyFilter.moduleFilter()
88

9-
def getAllLibraryDeps(analysis: Analysis, log: sbt.util.Logger): Set[java.io.File] = {
9+
// csrCacheDirectoryValueOpt is unused and only present for forward compatibility
10+
def getAllLibraryDeps(analysis: Analysis, log: sbt.util.Logger)(csrCacheDirectoryValueOpt: Option[String]): Set[java.io.File] = {
1011
log.debug(
1112
s"Source to library relations:\n${analysis.relations.binaryDep.all.map(r => s" ${r._1} -> ${r._2}").mkString("\n")}"
1213
)

src/main/scala-sbt-1.0/explicitdeps/package.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,25 @@ package object explicitdeps {
66

77
val defaultModuleFilter: ModuleFilter = sbt.librarymanagement.DependencyFilter.moduleFilter()
88

9-
def getAllLibraryDeps(analysis: Analysis, log: sbt.util.Logger): Set[java.io.File] = {
9+
private def toFile(x: AnyRef, csrCacheDirectoryValueOpt: Option[String]): java.io.File = {
10+
if (x.getClass.getSimpleName.contains("VirtualFile")) {
11+
// sbt 1.4.0 or newer
12+
val id = x.getClass.getMethod("id").invoke(x).toString
13+
val path = id.replaceAllLiterally("${CSR_CACHE}", csrCacheDirectoryValueOpt.mkString)
14+
new java.io.File(path)
15+
} else {
16+
// sbt 1.3.x or older
17+
x.asInstanceOf[java.io.File]
18+
}
19+
}
20+
21+
def getAllLibraryDeps(analysis: Analysis, log: sbt.util.Logger)(csrCacheDirectoryValueOpt: Option[String]): Set[java.io.File] = {
1022
log.debug(
1123
s"Source to library relations:\n${analysis.relations.libraryDep.all.map(r => s" ${r._1} -> ${r._2}").mkString("\n")}"
1224
)
13-
val allLibraryDeps = analysis.relations.allLibraryDeps.toSet
25+
val allLibraryDeps = analysis.relations.allLibraryDeps.asInstanceOf[Set[AnyRef]]
26+
.map(x => toFile(x, csrCacheDirectoryValueOpt))
27+
.toSet
1428
log.debug(s"Library dependencies:\n${allLibraryDeps.mkString(" ", "\n ", "")}")
1529
allLibraryDeps
1630
}

src/main/scala/explicitdeps/ExplicitDepsPlugin.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,23 @@ object ExplicitDepsPlugin extends AutoPlugin {
3535
unusedCompileDependenciesFilter := defaultModuleFilter
3636
)
3737

38+
// Evaluate "csrCacheDirectory" setting which is present only in sbt 1.3.0 or newer
39+
private lazy val csrCacheDirectoryValueTask = Def.task {
40+
val extracted: Extracted = Project.extract(state.value)
41+
val settings = extracted.session.original
42+
settings.find(_.key.key.label == "csrCacheDirectory") match {
43+
case Some(csrCacheDirectorySetting) =>
44+
val csrCacheDirectoryValue = csrCacheDirectorySetting.init.evaluate(extracted.structure.data).toString
45+
Some(csrCacheDirectoryValue)
46+
case _ => None
47+
}
48+
}
49+
3850
lazy val undeclaredCompileDependenciesTask = Def.task {
3951
val log = streams.value.log
4052
val projectName = name.value
41-
val allLibraryDeps = getAllLibraryDeps(compile.in(Compile).value.asInstanceOf[Analysis], log)
53+
val csrCacheDirectoryValueOpt = csrCacheDirectoryValueTask.value
54+
val allLibraryDeps = getAllLibraryDeps(compile.in(Compile).value.asInstanceOf[Analysis], log)(csrCacheDirectoryValueOpt)
4255
val libraryDeps = libraryDependencies.value
4356
val scalaBinaryVer = scalaBinaryVersion.value
4457
val filter = undeclaredCompileDependenciesFilter.value
@@ -62,7 +75,8 @@ object ExplicitDepsPlugin extends AutoPlugin {
6275
lazy val unusedCompileDependenciesTask = Def.task {
6376
val log = streams.value.log
6477
val projectName = name.value
65-
val allLibraryDeps = getAllLibraryDeps(compile.in(Compile).value.asInstanceOf[Analysis], log)
78+
val csrCacheDirectoryValueOpt = csrCacheDirectoryValueTask.value
79+
val allLibraryDeps = getAllLibraryDeps(compile.in(Compile).value.asInstanceOf[Analysis], log)(csrCacheDirectoryValueOpt)
6680
val libraryDeps = libraryDependencies.value
6781
val scalaBinaryVer = scalaBinaryVersion.value
6882
val filter = unusedCompileDependenciesFilter.value

0 commit comments

Comments
 (0)