Address deprecation warning

This commit is contained in:
Alexandre Archambault 2020-09-15 11:00:08 +02:00
parent 90f44bc5cc
commit f8c75d7033
1 changed files with 9 additions and 11 deletions

View File

@ -3,7 +3,7 @@ package lmcoursier.internal
import java.io.{File, FileNotFoundException, IOException}
import java.net.{HttpURLConnection, URL, URLConnection}
import coursier.cache.{CacheUrl, FileCache}
import coursier.cache.{ConnectionBuilder, FileCache}
import coursier.core._
import coursier.util.{Artifact, EitherT, Monad}
@ -54,16 +54,14 @@ object TemporaryInMemoryRepository {
var conn: URLConnection = null
try {
conn = CacheUrl.urlConnection(
url.toString,
None,
followHttpToHttpsRedirections = cacheOpt.fold(false)(_.followHttpToHttpsRedirections),
followHttpsToHttpRedirections = cacheOpt.fold(false)(_.followHttpsToHttpRedirections),
sslSocketFactoryOpt = cacheOpt.flatMap(_.sslSocketFactoryOpt),
hostnameVerifierOpt = cacheOpt.flatMap(_.hostnameVerifierOpt),
method = "HEAD",
maxRedirectionsOpt = cacheOpt.flatMap(_.maxRedirections)
)
conn = ConnectionBuilder(url.toURI.toASCIIString)
.withFollowHttpToHttpsRedirections(cacheOpt.fold(false)(_.followHttpToHttpsRedirections))
.withFollowHttpsToHttpRedirections(cacheOpt.fold(false)(_.followHttpsToHttpRedirections))
.withSslSocketFactoryOpt(cacheOpt.flatMap(_.sslSocketFactoryOpt))
.withHostnameVerifierOpt(cacheOpt.flatMap(_.hostnameVerifierOpt))
.withMethod("HEAD")
.withMaxRedirectionsOpt(cacheOpt.flatMap(_.maxRedirections))
.connection()
// Even though the finally clause handles this too, this has to be run here, so that we return Some(true)
// iff this doesn't throw.
conn.getInputStream.close()