Permalink
Browse files

Merge pull request #690 from olivierdeckers/clean-inmemory-caches

Implemented clean task + added integration test. Fixes #685
  • Loading branch information...
alexarchambault committed Nov 3, 2017
2 parents 86de793 + ebb7e66 commit 06322622188f2e458b15204e05f4cefa99321df3
@@ -9,7 +9,7 @@ object CoursierPlugin extends AutoPlugin {
override def trigger = allRequirements
override def requires = sbt.plugins.IvyPlugin
override def requires = sbt.plugins.JvmPlugin
object autoImport {
val coursierParallelDownloads = Keys.coursierParallelDownloads
@@ -153,6 +153,11 @@ object CoursierPlugin extends AutoPlugin {
shadedConfigOpt: Option[(String, String)],
packageConfigs: Seq[(Configuration, String)]
) = hackHack ++ Seq(
clean := {
clean.value
Tasks.resolutionsCache.clear()
Tasks.reportsCache.clear()
},
coursierResolvers := Tasks.coursierResolversTask.value,
coursierRecursiveResolvers := Tasks.coursierRecursiveResolversTask.value,
coursierSbtResolvers := {
@@ -398,26 +398,26 @@ object Tasks {
}
}
private final case class ResolutionCacheKey(
private[coursier] final case class ResolutionCacheKey(
project: Project,
repositories: Seq[Repository],
userEnabledProfiles: Set[String],
resolution: Map[Set[String], Resolution],
sbtClassifiers: Boolean
)
private final case class ReportCacheKey(
private[coursier] final case class ReportCacheKey(
project: Project,
resolution: Map[Set[String], Resolution],
withClassifiers: Boolean,
sbtClassifiers: Boolean,
ignoreArtifactErrors: Boolean
)
private val resolutionsCache = new mutable.HashMap[ResolutionCacheKey, Map[Set[String], Resolution]]
private[coursier] val resolutionsCache = new mutable.HashMap[ResolutionCacheKey, Map[Set[String], Resolution]]
// these may actually not need to be cached any more, now that the resolutions
// are cached
private val reportsCache = new mutable.HashMap[ReportCacheKey, UpdateReport]
private[coursier] val reportsCache = new mutable.HashMap[ReportCacheKey, UpdateReport]
private def forcedScalaModules(
scalaOrganization: String,
@@ -0,0 +1,13 @@
scalaVersion := "2.11.8"
val checkEmpty = TaskKey[Unit]("checkEmpty")
checkEmpty := {
assert(coursier.Helper.checkEmpty)
}
val checkNotEmpty = TaskKey[Unit]("checkNotEmpty")
checkNotEmpty := {
assert(!coursier.Helper.checkEmpty)
}
@@ -0,0 +1,9 @@
package coursier
object Helper {
def checkEmpty(): Boolean = {
Tasks.resolutionsCache.isEmpty && Tasks.reportsCache.isEmpty
}
}
@@ -0,0 +1,11 @@
{
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)
addSbtPlugin("io.get-coursier" % "sbt-coursier" % pluginVersion)
}
@@ -0,0 +1,5 @@
> checkEmpty
> update
> checkNotEmpty
> clean
> checkEmpty

0 comments on commit 0632262

Please sign in to comment.