From dcc7d875037692a9677d051c6e336d95be115270 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Fri, 21 Jun 2019 17:13:32 +0200 Subject: [PATCH] Follow http to https redirections by default (#85) --- .../lmcoursier/CoursierConfiguration.scala | 28 +++++++++++++++---- .../CoursierDependencyResolution.scala | 1 + .../coursier/sbtcoursier/ArtifactsTasks.scala | 3 +- .../sbtcoursier/ResolutionTasks.scala | 3 +- .../src/sbt-test/shared-2/url/README.md | 1 + .../src/sbt-test/shared-2/url/build.sbt | 22 +++++++++++++++ .../sbt-test/shared-2/url/project/plugins.sbt | 13 +++++++++ .../src/sbt-test/shared-2/url/test | 2 ++ 8 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 modules/sbt-coursier/src/sbt-test/shared-2/url/README.md create mode 100644 modules/sbt-coursier/src/sbt-test/shared-2/url/build.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-2/url/project/plugins.sbt create mode 100644 modules/sbt-coursier/src/sbt-test/shared-2/url/test diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala index e1241d623..c2fe434f7 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierConfiguration.scala @@ -33,7 +33,8 @@ final class CoursierConfiguration private ( val credentials: Seq[Credentials], val logger: Option[CacheLogger], val cache: Option[File], - val ivyHome: Option[File] + val ivyHome: Option[File], + val followHttpToHttpsRedirections: Option[Boolean] ) extends Serializable { private def this() = @@ -58,6 +59,7 @@ final class CoursierConfiguration private ( Vector.empty, None, None, + None, None ) @@ -84,7 +86,8 @@ final class CoursierConfiguration private ( credentials == other.credentials && logger == other.logger && cache == other.cache && - ivyHome == other.ivyHome + ivyHome == other.ivyHome && + followHttpToHttpsRedirections == other.followHttpToHttpsRedirections case _ => false } @@ -111,11 +114,12 @@ final class CoursierConfiguration private ( code = 37 * (code + logger.##) code = 37 * (code + cache.##) code = 37 * (code + ivyHome.##) + code = 37 * (code + followHttpToHttpsRedirections.##) 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, $ivyHome)" + s"CoursierConfiguration($log, $resolvers, $parallelDownloads, $maxIterations, $sbtScalaOrganization, $sbtScalaVersion, $sbtScalaJars, $interProjectDependencies, $excludeDependencies, $fallbackDependencies, $autoScalaLibrary, $hasClassifiers, $classifiers, $mavenProfiles, $scalaOrganization, $scalaVersion, $authenticationByRepositoryId, $credentials, $logger, $cache, $ivyHome, $followHttpToHttpsRedirections)" private[this] def copy( log: Option[Logger] = log, @@ -138,7 +142,8 @@ final class CoursierConfiguration private ( credentials: Seq[Credentials] = credentials, logger: Option[CacheLogger] = logger, cache: Option[File] = cache, - ivyHome: Option[File] = ivyHome + ivyHome: Option[File] = ivyHome, + followHttpToHttpsRedirections: Option[Boolean] = followHttpToHttpsRedirections ): CoursierConfiguration = new CoursierConfiguration( log, @@ -161,7 +166,8 @@ final class CoursierConfiguration private ( credentials, logger, cache, - ivyHome + ivyHome, + followHttpToHttpsRedirections ) def withLog(log: Option[Logger]): CoursierConfiguration = @@ -249,6 +255,13 @@ final class CoursierConfiguration private ( copy(ivyHome = ivyHomeOpt) def withIvyHome(ivyHome: File): CoursierConfiguration = copy(ivyHome = Option(ivyHome)) + + def withFollowHttpToHttpsRedirections(followHttpToHttpsRedirectionsOpt: Option[Boolean]): CoursierConfiguration = + copy(followHttpToHttpsRedirections = followHttpToHttpsRedirectionsOpt) + def withFollowHttpToHttpsRedirections(followHttpToHttpsRedirections: Boolean): CoursierConfiguration = + copy(followHttpToHttpsRedirections = Some(followHttpToHttpsRedirections)) + def withFollowHttpToHttpsRedirections(): CoursierConfiguration = + copy(followHttpToHttpsRedirections = Some(true)) } object CoursierConfiguration { @@ -299,6 +312,7 @@ object CoursierConfiguration { credentials, logger, cache, + None, None ) @@ -345,6 +359,7 @@ object CoursierConfiguration { credentials, Option(logger), Option(cache), + None, None ) @@ -392,6 +407,7 @@ object CoursierConfiguration { credentials, logger, cache, - ivyHome + ivyHome, + None ) } diff --git a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala index d8b955345..3aa0c2622 100644 --- a/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala +++ b/modules/lm-coursier/src/main/scala/lmcoursier/CoursierDependencyResolution.scala @@ -122,6 +122,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen .withTtl(ttl) .withChecksums(checksums) .withCredentials(conf.credentials.map(ToCoursier.credentials)) + .withFollowHttpToHttpsRedirections(conf.followHttpToHttpsRedirections.getOrElse(true)) val resolutionParams = ResolutionParams( dependencies = dependencies, diff --git a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala index 32250daf3..4f1a16aba 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ArtifactsTasks.scala @@ -68,7 +68,8 @@ object ArtifactsTasks { .withChecksums(artifactsChecksums) .withTtl(ttl) .withCachePolicies(cachePolicies) - .withCredentials(credentials), + .withCredentials(credentials) + .withFollowHttpToHttpsRedirections(true), parallel = parallelDownloads ) 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 c6da8ae35..f35c6ea3d 100644 --- a/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala +++ b/modules/sbt-coursier/src/main/scala/coursier/sbtcoursier/ResolutionTasks.scala @@ -140,7 +140,8 @@ object ResolutionTasks { .withCachePolicies(cachePolicies) .withTtl(ttl) .withChecksums(checksums) - .withCredentials(credentials), + .withCredentials(credentials) + .withFollowHttpToHttpsRedirections(true), parallel = parallelDownloads, params = coursier.params.ResolutionParams() .withMaxIterations(maxIterations) diff --git a/modules/sbt-coursier/src/sbt-test/shared-2/url/README.md b/modules/sbt-coursier/src/sbt-test/shared-2/url/README.md new file mode 100644 index 000000000..ef566da2e --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-2/url/README.md @@ -0,0 +1 @@ +Originally from https://github.com/sbt/sbt/tree/57a86e60f6d7c6fd428fb73a6786b62972fdae54/sbt/src/sbt-test/dependency-management/url diff --git a/modules/sbt-coursier/src/sbt-test/shared-2/url/build.sbt b/modules/sbt-coursier/src/sbt-test/shared-2/url/build.sbt new file mode 100644 index 000000000..f3b8f6fa2 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-2/url/build.sbt @@ -0,0 +1,22 @@ +import sbt.internal.inc.classpath.ClasspathUtilities + +lazy val root = (project in file(".")). + settings( + ivyPaths := IvyPaths(baseDirectory.value, Some(target.value / "ivy-cache")), + libraryDependencies += "org.jsoup" % "jsoup" % "1.9.1" % Test from "http://jsoup.org/packages/jsoup-1.9.1.jar", + ivyLoggingLevel := UpdateLogging.Full, + TaskKey[Unit]("checkInTest") := checkClasspath(Test).value, + TaskKey[Unit]("checkInCompile") := checkClasspath(Compile).value + ) + +def checkClasspath(conf: Configuration) = + fullClasspath in conf map { cp => + try { + val loader = ClasspathUtilities.toLoader(cp.files) + Class.forName("org.jsoup.Jsoup", false, loader) + () + } + catch { + case _: ClassNotFoundException => sys.error(s"could not instantiate org.jsoup.Jsoup: ${cp.files}") + } + } diff --git a/modules/sbt-coursier/src/sbt-test/shared-2/url/project/plugins.sbt b/modules/sbt-coursier/src/sbt-test/shared-2/url/project/plugins.sbt new file mode 100644 index 000000000..71a44ffd3 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-2/url/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-2/url/test b/modules/sbt-coursier/src/sbt-test/shared-2/url/test new file mode 100644 index 000000000..691336b66 --- /dev/null +++ b/modules/sbt-coursier/src/sbt-test/shared-2/url/test @@ -0,0 +1,2 @@ +> checkInTest +-> checkInCompile