From 54368093231a3706e0542ec30401b294f147e87b Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 14 May 2019 13:31:12 +0200 Subject: [PATCH] Take ivyPaths into account --- .../lmcoursier/CoursierConfiguration.scala | 74 +++++++++++++++++-- .../CoursierDependencyResolution.scala | 2 +- .../internal/ResolutionParams.scala | 10 +-- .../sbtcoursier/ResolutionTasks.scala | 2 +- .../src/sbt-test/sbt-coursier/s3/build.sbt | 4 +- .../sbt-test/shared-1/cache-local/README.md | 1 + .../sbt-test/shared-1/cache-local/cache.sbt | 1 + .../shared-1/cache-local/changes/def.sbt | 7 ++ .../shared-1/cache-local/changes/resolver.sbt | 5 ++ .../shared-1/cache-local/changes/use.sbt | 9 +++ .../shared-1/cache-local/project/plugins.sbt | 13 ++++ .../src/sbt-test/shared-1/cache-local/test | 21 ++++++ .../sbtlmcoursier/LmCoursierPlugin.scala | 3 +- 13 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/README.md create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/cache.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/def.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/resolver.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/use.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/project/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-1/cache-local/test diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala index 2c24538df..e1241d623 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala @@ -32,7 +32,8 @@ final class CoursierConfiguration private ( val authenticationByRepositoryId: Vector[(String, Authentication)], val credentials: Seq[Credentials], val logger: Option[CacheLogger], - val cache: Option[File] + val cache: Option[File], + val ivyHome: Option[File] ) extends Serializable { private def this() = @@ -56,6 +57,7 @@ final class CoursierConfiguration private ( Vector.empty, Vector.empty, None, + None, None ) @@ -81,7 +83,8 @@ final class CoursierConfiguration private ( authenticationByRepositoryId == other.authenticationByRepositoryId && credentials == other.credentials && logger == other.logger && - cache == other.cache + cache == other.cache && + ivyHome == other.ivyHome case _ => false } @@ -107,11 +110,12 @@ final class CoursierConfiguration private ( code = 37 * (code + credentials.##) code = 37 * (code + logger.##) code = 37 * (code + cache.##) + code = 37 * (code + ivyHome.##) code } override def toString: String = - s"CoursierConfiguration($log, $resolvers, $parallelDownloads, $maxIterations, $sbtScalaOrganization, $sbtScalaVersion, $sbtScalaJars, $interProjectDependencies, $excludeDependencies, $fallbackDependencies, $autoScalaLibrary, $hasClassifiers, $classifiers, $mavenProfiles, $scalaOrganization, $scalaVersion, $authenticationByRepositoryId, $credentials, $logger, $cache)" + s"CoursierConfiguration($log, $resolvers, $parallelDownloads, $maxIterations, $sbtScalaOrganization, $sbtScalaVersion, $sbtScalaJars, $interProjectDependencies, $excludeDependencies, $fallbackDependencies, $autoScalaLibrary, $hasClassifiers, $classifiers, $mavenProfiles, $scalaOrganization, $scalaVersion, $authenticationByRepositoryId, $credentials, $logger, $cache, $ivyHome)" private[this] def copy( log: Option[Logger] = log, @@ -133,7 +137,8 @@ final class CoursierConfiguration private ( authenticationByRepositoryId: Vector[(String, Authentication)] = authenticationByRepositoryId, credentials: Seq[Credentials] = credentials, logger: Option[CacheLogger] = logger, - cache: Option[File] = cache + cache: Option[File] = cache, + ivyHome: Option[File] = ivyHome ): CoursierConfiguration = new CoursierConfiguration( log, @@ -155,7 +160,8 @@ final class CoursierConfiguration private ( authenticationByRepositoryId, credentials, logger, - cache + cache, + ivyHome ) def withLog(log: Option[Logger]): CoursierConfiguration = @@ -238,6 +244,11 @@ final class CoursierConfiguration private ( def withCache(cache: File): CoursierConfiguration = copy(cache = Option(cache)) + + def withIvyHome(ivyHomeOpt: Option[File]): CoursierConfiguration = + copy(ivyHome = ivyHomeOpt) + def withIvyHome(ivyHome: File): CoursierConfiguration = + copy(ivyHome = Option(ivyHome)) } object CoursierConfiguration { @@ -287,7 +298,8 @@ object CoursierConfiguration { authenticationByRepositoryId, credentials, logger, - cache + cache, + None ) def apply( @@ -332,6 +344,54 @@ object CoursierConfiguration { authenticationByRepositoryId, credentials, Option(logger), - Option(cache) + Option(cache), + None + ) + + def apply( + log: Option[Logger], + resolvers: Vector[Resolver], + parallelDownloads: Int, + maxIterations: Int, + sbtScalaOrganization: Option[String], + sbtScalaVersion: Option[String], + sbtScalaJars: Vector[File], + interProjectDependencies: Vector[Project], + excludeDependencies: Vector[(String, String)], + fallbackDependencies: Vector[FallbackDependency], + autoScalaLibrary: Boolean, + hasClassifiers: Boolean, + classifiers: Vector[String], + mavenProfiles: Vector[String], + scalaOrganization: Option[String], + scalaVersion: Option[String], + authenticationByRepositoryId: Vector[(String, Authentication)], + credentials: Seq[Credentials], + logger: Option[CacheLogger], + cache: Option[File], + ivyHome: Option[File] + ): CoursierConfiguration = + new CoursierConfiguration( + log, + resolvers, + parallelDownloads, + maxIterations, + sbtScalaOrganization, + sbtScalaVersion, + sbtScalaJars, + interProjectDependencies, + excludeDependencies, + fallbackDependencies, + autoScalaLibrary, + hasClassifiers, + classifiers, + mavenProfiles, + scalaOrganization, + scalaVersion, + authenticationByRepositoryId, + credentials, + logger, + cache, + ivyHome ) } diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala index b8a327682..0e0541df3 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala @@ -74,7 +74,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen val checksums = CacheDefaults.checksums val projectName = "" // used for logging only… - val ivyProperties = ResolutionParams.defaultIvyProperties() + val ivyProperties = ResolutionParams.defaultIvyProperties(conf.ivyHome) val classifiers = if (conf.hasClassifiers) diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionParams.scala b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionParams.scala index 69e807d79..281b18edf 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionParams.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/internal/ResolutionParams.scala @@ -84,12 +84,12 @@ object ResolutionParams { private def cacheKey(cache: FileCache[Task]): Object = m.invoke(cache) - def defaultIvyProperties(): Map[String, String] = { + def defaultIvyProperties(ivyHomeOpt: Option[File]): Map[String, String] = { - val ivyHome = sys.props.getOrElse( - "ivy.home", - new File(sys.props("user.home")).toURI.getPath + ".ivy2" - ) + val ivyHome = sys.props + .get("ivy.home") + .orElse(ivyHomeOpt.map(_.getAbsoluteFile.toURI.getPath)) + .getOrElse(new File(sys.props("user.home")).toURI.getPath + ".ivy2") val sbtIvyHome = sys.props.getOrElse( "sbt.ivy.home", diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala index 51ffd8546..799858bc8 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala @@ -86,7 +86,7 @@ object ResolutionTasks { val interProjectRepo = InterProjectRepository(interProjectDependencies) - val ivyProperties = ResolutionParams.defaultIvyProperties() + val ivyProperties = ResolutionParams.defaultIvyProperties(ivyPaths.value.ivyHome) val authenticationByRepositoryId = coursierCredentials.value.mapValues(_.authentication) diff --git a/modules/sbt-coursier/src/sbt-test/sbt-coursier/s3/build.sbt b/modules/sbt-coursier/src/sbt-test/sbt-coursier/s3/build.sbt index 77b86764a..0cab491bf 100644 --- a/modules/sbt-coursier/src/sbt-test/sbt-coursier/s3/build.sbt +++ b/modules/sbt-coursier/src/sbt-test/sbt-coursier/s3/build.sbt @@ -25,7 +25,9 @@ check := { sbtResolvers.flatMap{ sbtResolver: sbt.librarymanagement.Resolver => lmcoursier.internal.Resolvers.repository( resolver = sbtResolver, - ivyProperties = lmcoursier.internal.ResolutionParams.defaultIvyProperties(), + ivyProperties = lmcoursier.internal.ResolutionParams.defaultIvyProperties( + ivyPaths.value.ivyHome + ), log = s.log, authentication = None, ) diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/README.md b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/README.md new file mode 100644 index 000000000..51a739067 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/README.md @@ -0,0 +1 @@ +Imported from https://github.com/sbt/sbt/tree/f5edeec2fdabd4313d2976b389bb6101775a5554/sbt/src/sbt-test/dependency-management/cache-local diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/cache.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/cache.sbt new file mode 100644 index 000000000..869c6d489 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/cache.sbt @@ -0,0 +1 @@ +ivyPaths := { IvyPaths(baseDirectory.value, Some(target.value / ".ivy2")) } diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/def.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/def.sbt new file mode 100644 index 000000000..3e64f64c9 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/def.sbt @@ -0,0 +1,7 @@ +organization := "org.example" + +name := "def" + +version := "1.0" + +autoScalaLibrary := false diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/resolver.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/resolver.sbt new file mode 100644 index 000000000..642794849 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/resolver.sbt @@ -0,0 +1,5 @@ + +publishTo := baseDirectory(base => Some(Resolver.file("filesys-publish", base / "repo")) ).value + +resolvers += baseDirectory(base => "filesys" at (base / "repo").toURI.toString).value + diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/use.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/use.sbt new file mode 100644 index 000000000..d1b96f297 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/changes/use.sbt @@ -0,0 +1,9 @@ +organization := "org.example" + +name := "use" + +version := "1.0" + +autoScalaLibrary := false + +libraryDependencies += "org.example" %% "def" % "1.0" diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/project/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/project/plugins.sbt @@ -0,0 +1,13 @@ +addSbtPlugin { + + val name = sys.props.getOrElse( + "plugin.name", + sys.error("plugin.name Java property not set") + ) + val version = sys.props.getOrElse( + "plugin.version", + sys.error("plugin.version Java property not set") + ) + + "io.get-coursier" % name % version +} \ No newline at end of file diff --git a/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/test b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/test new file mode 100644 index 000000000..faf195ef2 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-1/cache-local/test @@ -0,0 +1,21 @@ +$ copy-file changes/def.sbt build.sbt +$ copy-file changes/resolver.sbt resolver.sbt +> reload +> publishLocal +> publish + +$ delete build.sbt +$ delete resolver.sbt +$ copy-file changes/use.sbt build.sbt +> reload +> update +> update + +# needed for sbt-coursier (clear in-memory cache) +> clean +$ delete target/.ivy2/local +-> update + +$ copy-file changes/resolver.sbt resolver.sbt +> reload +> update diff --git a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala index 995d86c1b..7bc0dd914 100644 --- a/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala +++ b/modules/sbt-lm-coursier/src/main/scala/coursier/sbtlmcoursier/LmCoursierPlugin.scala @@ -7,7 +7,7 @@ import coursier.sbtcoursiershared.{InputsTasks, SbtCoursierShared} import sbt.{AutoPlugin, Classpaths, Def, Setting, Task, taskKey} import sbt.Project.inTask import sbt.KeyRanks.DTask -import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyResolution, scalaBinaryVersion, scalaModuleInfo, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers} +import sbt.Keys.{appConfiguration, autoScalaLibrary, classpathTypes, dependencyResolution, ivyPaths, scalaBinaryVersion, scalaModuleInfo, scalaOrganization, scalaVersion, streams, updateClassifiers, updateSbtClassifiers} import sbt.librarymanagement.DependencyResolution import scala.language.reflectiveCalls @@ -133,6 +133,7 @@ object LmCoursierPlugin extends AutoPlugin { .withLogger(createLogger) .withCache(cache) .withLog(s.log) + .withIvyHome(ivyPaths.value.ivyHome) } } private def mkDependencyResolution: Def.Initialize[Task[DependencyResolution]] =