From ebb7e66a2648467520edc30ed453d87ac7e2d9be Mon Sep 17 00:00:00 2001 From: Olivier Deckers Date: Fri, 3 Nov 2017 15:21:39 +0100 Subject: [PATCH] Implemented clean task + added integration test. Fixes #685 --- .../src/main/scala/coursier/CoursierPlugin.scala | 7 ++++++- sbt-coursier/src/main/scala/coursier/Tasks.scala | 8 ++++---- .../src/sbt-test/sbt-coursier/clean/build.sbt | 13 +++++++++++++ .../sbt-coursier/clean/project/helper.scala | 9 +++++++++ .../sbt-test/sbt-coursier/clean/project/plugins.sbt | 11 +++++++++++ sbt-coursier/src/sbt-test/sbt-coursier/clean/test | 5 +++++ 6 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/clean/build.sbt create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/clean/project/helper.scala create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/clean/project/plugins.sbt create mode 100644 sbt-coursier/src/sbt-test/sbt-coursier/clean/test diff --git a/sbt-coursier/src/main/scala/coursier/CoursierPlugin.scala b/sbt-coursier/src/main/scala/coursier/CoursierPlugin.scala index 29bcb36ea..e8f209766 100644 --- a/sbt-coursier/src/main/scala/coursier/CoursierPlugin.scala +++ b/sbt-coursier/src/main/scala/coursier/CoursierPlugin.scala @@ -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 := { diff --git a/sbt-coursier/src/main/scala/coursier/Tasks.scala b/sbt-coursier/src/main/scala/coursier/Tasks.scala index ba213d7c5..c46ae9dd9 100644 --- a/sbt-coursier/src/main/scala/coursier/Tasks.scala +++ b/sbt-coursier/src/main/scala/coursier/Tasks.scala @@ -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, diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/clean/build.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/clean/build.sbt new file mode 100644 index 000000000..f0b2ed640 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/clean/build.sbt @@ -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) +} \ No newline at end of file diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/helper.scala b/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/helper.scala new file mode 100644 index 000000000..000111d37 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/helper.scala @@ -0,0 +1,9 @@ +package coursier + +object Helper { + + def checkEmpty(): Boolean = { + Tasks.resolutionsCache.isEmpty && Tasks.reportsCache.isEmpty + } + +} \ No newline at end of file diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/plugins.sbt b/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/plugins.sbt new file mode 100644 index 000000000..152225a9e --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/clean/project/plugins.sbt @@ -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) +} diff --git a/sbt-coursier/src/sbt-test/sbt-coursier/clean/test b/sbt-coursier/src/sbt-test/sbt-coursier/clean/test new file mode 100644 index 000000000..6dc6f6976 --- /dev/null +++ b/sbt-coursier/src/sbt-test/sbt-coursier/clean/test @@ -0,0 +1,5 @@ +> checkEmpty +> update +> checkNotEmpty +> clean +> checkEmpty