mirror of https://github.com/sbt/sbt.git
fix: Change URL usage to URI
This commit is contained in:
parent
1b056e71d7
commit
3581b4a05b
|
|
@ -1,13 +1,13 @@
|
||||||
package lmcoursier
|
package lmcoursier
|
||||||
|
|
||||||
import java.net.URL
|
import java.net.URI
|
||||||
|
|
||||||
import dataclass.data
|
import dataclass.data
|
||||||
import lmcoursier.definitions.Module
|
import lmcoursier.definitions.Module
|
||||||
//FIXME use URI instead of URL
|
|
||||||
@data class FallbackDependency(
|
@data class FallbackDependency(
|
||||||
module: Module,
|
module: Module,
|
||||||
version: String,
|
version: String,
|
||||||
url: URL,
|
uri: URI,
|
||||||
changing: Boolean
|
changing: Boolean
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -168,10 +168,10 @@ object FromSbt {
|
||||||
for {
|
for {
|
||||||
module <- allDependencies
|
module <- allDependencies
|
||||||
artifact <- module.explicitArtifacts
|
artifact <- module.explicitArtifacts
|
||||||
url <- artifact.url.toSeq
|
uri <- artifact.url.toSeq
|
||||||
} yield {
|
} yield {
|
||||||
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion)
|
val (module0, version) = moduleVersion(module, scalaVersion, scalaBinaryVersion)
|
||||||
FallbackDependency(module0, version, url.toURL, module.isChanging)
|
FallbackDependency(module0, version, uri, module.isChanging)
|
||||||
}
|
}
|
||||||
|
|
||||||
def project(
|
def project(
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ final case class ResolutionParams(
|
||||||
Nil
|
Nil
|
||||||
else {
|
else {
|
||||||
val map = fallbackDependencies.map { dep =>
|
val map = fallbackDependencies.map { dep =>
|
||||||
(ToCoursier.module(dep.module), dep.version) -> ((dep.url, dep.changing))
|
(ToCoursier.module(dep.module), dep.version) -> ((dep.uri, dep.changing))
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
Seq(
|
Seq(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package lmcoursier.internal
|
package lmcoursier.internal
|
||||||
|
|
||||||
import java.io.{ File, FileNotFoundException, IOException }
|
import java.io.{ File, FileNotFoundException, IOException }
|
||||||
import java.net.{ HttpURLConnection, URL, URLConnection }
|
import java.net.{ HttpURLConnection, URI, URLConnection }
|
||||||
|
|
||||||
import coursier.cache.{ ConnectionBuilder, FileCache }
|
import coursier.cache.{ ConnectionBuilder, FileCache }
|
||||||
import coursier.core.*
|
import coursier.core.*
|
||||||
|
|
@ -22,13 +22,13 @@ object TemporaryInMemoryRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
def exists(
|
def exists(
|
||||||
url: URL,
|
uri: URI,
|
||||||
localArtifactsShouldBeCached: Boolean
|
localArtifactsShouldBeCached: Boolean
|
||||||
): Boolean =
|
): Boolean =
|
||||||
exists(url, localArtifactsShouldBeCached, None)
|
exists(uri, localArtifactsShouldBeCached, None)
|
||||||
|
|
||||||
def exists(
|
def exists(
|
||||||
url: URL,
|
uri: URI,
|
||||||
localArtifactsShouldBeCached: Boolean,
|
localArtifactsShouldBeCached: Boolean,
|
||||||
cacheOpt: Option[FileCache[Nothing]]
|
cacheOpt: Option[FileCache[Nothing]]
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
|
|
@ -40,12 +40,12 @@ object TemporaryInMemoryRepository {
|
||||||
val protocolSpecificAttemptOpt = {
|
val protocolSpecificAttemptOpt = {
|
||||||
|
|
||||||
def ifFile: Option[Boolean] = {
|
def ifFile: Option[Boolean] = {
|
||||||
if (localArtifactsShouldBeCached && !new File(url.toURI).exists()) {
|
if (localArtifactsShouldBeCached && !new File(uri).exists()) {
|
||||||
val cachePath = coursier.cache.CacheDefaults.location
|
val cachePath = coursier.cache.CacheDefaults.location
|
||||||
// 'file' here stands for the protocol (e.g. it's https instead for https:// URLs)
|
// 'file' here stands for the protocol (e.g. it's https instead for https:// URLs)
|
||||||
Some(new File(cachePath, s"file/${url.getPath}").exists())
|
Some(new File(cachePath, s"file/${uri.getPath}").exists())
|
||||||
} else {
|
} else {
|
||||||
Some(new File(url.toURI).exists()) // FIXME Escaping / de-escaping needed here?
|
Some(new File(uri).exists()) // FIXME Escaping / de-escaping needed here?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ object TemporaryInMemoryRepository {
|
||||||
|
|
||||||
var conn: URLConnection = null
|
var conn: URLConnection = null
|
||||||
try {
|
try {
|
||||||
conn = ConnectionBuilder(url.toURI.toASCIIString)
|
conn = ConnectionBuilder(uri.toASCIIString)
|
||||||
.withFollowHttpToHttpsRedirections(
|
.withFollowHttpToHttpsRedirections(
|
||||||
cacheOpt.fold(false)(_.followHttpToHttpsRedirections)
|
cacheOpt.fold(false)(_.followHttpToHttpsRedirections)
|
||||||
)
|
)
|
||||||
|
|
@ -79,7 +79,7 @@ object TemporaryInMemoryRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
url.getProtocol match {
|
uri.getScheme match {
|
||||||
case "file" => ifFile
|
case "file" => ifFile
|
||||||
case "http" | "https" => ifHttp
|
case "http" | "https" => ifHttp
|
||||||
case _ => None
|
case _ => None
|
||||||
|
|
@ -89,7 +89,7 @@ object TemporaryInMemoryRepository {
|
||||||
def genericAttempt: Boolean = {
|
def genericAttempt: Boolean = {
|
||||||
var conn: URLConnection = null
|
var conn: URLConnection = null
|
||||||
try {
|
try {
|
||||||
conn = url.openConnection()
|
conn = uri.toURL.openConnection()
|
||||||
// NOT setting request type to HEAD here.
|
// NOT setting request type to HEAD here.
|
||||||
conn.getInputStream.close()
|
conn.getInputStream.close()
|
||||||
true
|
true
|
||||||
|
|
@ -106,18 +106,18 @@ object TemporaryInMemoryRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
def apply(
|
def apply(
|
||||||
fallbacks: Map[(Module, String), (URL, Boolean)]
|
fallbacks: Map[(Module, String), (URI, Boolean)]
|
||||||
): TemporaryInMemoryRepository =
|
): TemporaryInMemoryRepository =
|
||||||
new TemporaryInMemoryRepository(fallbacks, localArtifactsShouldBeCached = false, None)
|
new TemporaryInMemoryRepository(fallbacks, localArtifactsShouldBeCached = false, None)
|
||||||
|
|
||||||
def apply(
|
def apply(
|
||||||
fallbacks: Map[(Module, String), (URL, Boolean)],
|
fallbacks: Map[(Module, String), (URI, Boolean)],
|
||||||
localArtifactsShouldBeCached: Boolean
|
localArtifactsShouldBeCached: Boolean
|
||||||
): TemporaryInMemoryRepository =
|
): TemporaryInMemoryRepository =
|
||||||
new TemporaryInMemoryRepository(fallbacks, localArtifactsShouldBeCached, None)
|
new TemporaryInMemoryRepository(fallbacks, localArtifactsShouldBeCached, None)
|
||||||
|
|
||||||
def apply[F[_]](
|
def apply[F[_]](
|
||||||
fallbacks: Map[(Module, String), (URL, Boolean)],
|
fallbacks: Map[(Module, String), (URI, Boolean)],
|
||||||
cache: FileCache[F]
|
cache: FileCache[F]
|
||||||
): TemporaryInMemoryRepository =
|
): TemporaryInMemoryRepository =
|
||||||
new TemporaryInMemoryRepository(
|
new TemporaryInMemoryRepository(
|
||||||
|
|
@ -129,7 +129,7 @@ object TemporaryInMemoryRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
final class TemporaryInMemoryRepository private (
|
final class TemporaryInMemoryRepository private (
|
||||||
val fallbacks: Map[(Module, String), (URL, Boolean)],
|
val fallbacks: Map[(Module, String), (URI, Boolean)],
|
||||||
val localArtifactsShouldBeCached: Boolean,
|
val localArtifactsShouldBeCached: Boolean,
|
||||||
val cacheOpt: Option[FileCache[Nothing]]
|
val cacheOpt: Option[FileCache[Nothing]]
|
||||||
) extends Repository {
|
) extends Repository {
|
||||||
|
|
@ -145,16 +145,16 @@ final class TemporaryInMemoryRepository private (
|
||||||
def res = fallbacks
|
def res = fallbacks
|
||||||
.get((module, version))
|
.get((module, version))
|
||||||
.fold[Either[String, (ArtifactSource, Project)]](Left("No fallback URL found")) {
|
.fold[Either[String, (ArtifactSource, Project)]](Left("No fallback URL found")) {
|
||||||
case (url, _) =>
|
case (uri, _) =>
|
||||||
val urlStr = url.toExternalForm
|
val urlStr = uri.toURL.toExternalForm
|
||||||
val idx = urlStr.lastIndexOf('/')
|
val idx = urlStr.lastIndexOf('/')
|
||||||
|
|
||||||
if (idx < 0 || urlStr.endsWith("/"))
|
if (idx < 0 || urlStr.endsWith("/"))
|
||||||
Left(s"$url doesn't point to a file")
|
Left(s"$uri doesn't point to a file")
|
||||||
else {
|
else {
|
||||||
val (dirUrlStr, fileName) = urlStr.splitAt(idx + 1)
|
val (dirUrlStr, fileName) = urlStr.splitAt(idx + 1)
|
||||||
|
|
||||||
if (TemporaryInMemoryRepository.exists(url, localArtifactsShouldBeCached, cacheOpt)) {
|
if (TemporaryInMemoryRepository.exists(uri, localArtifactsShouldBeCached, cacheOpt)) {
|
||||||
val proj = Project(
|
val proj = Project(
|
||||||
module,
|
module,
|
||||||
version,
|
version,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue