Implemented clean task + added integration test. Fixes #685

This commit is contained in:
Olivier Deckers 2017-11-03 15:21:39 +01:00
parent 86de793517
commit ebb7e66a26
6 changed files with 48 additions and 5 deletions

View File

@ -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 := {

View File

@ -398,7 +398,7 @@ object Tasks {
}
}
private final case class ResolutionCacheKey(
private[coursier] final case class ResolutionCacheKey(
project: Project,
repositories: Seq[Repository],
userEnabledProfiles: Set[String],
@ -406,7 +406,7 @@ object Tasks {
sbtClassifiers: Boolean
)
private final case class ReportCacheKey(
private[coursier] final case class ReportCacheKey(
project: Project,
resolution: Map[Set[String], Resolution],
withClassifiers: Boolean,
@ -414,10 +414,10 @@ object Tasks {
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,

View File

@ -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)
}

View File

@ -0,0 +1,9 @@
package coursier
object Helper {
def checkEmpty(): Boolean = {
Tasks.resolutionsCache.isEmpty && Tasks.reportsCache.isEmpty
}
}

View File

@ -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)
}

View File

@ -0,0 +1,5 @@
> checkEmpty
> update
> checkNotEmpty
> clean
> checkEmpty