Skip to content

Commit

Permalink
Merge pull request #48 from rolang/main
Browse files Browse the repository at this point in the history
Prevent from failing using an extra protocol in resolver's URL
  • Loading branch information
fthomas authored Mar 2, 2024
2 parents e1c26ae + f9bb1ed commit 0b0f9a6
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ object StewardPlugin_1_3_11 extends AutoPlugin {
)
val dependencies = libraryDeps ++ scalafixDeps

def getCredentials(url: URL, name: String): Option[Resolver.Credentials] =
def getCredentials(host: String, name: String): Option[Resolver.Credentials] =
(for {
allDirect <- Try(Credentials.allDirect(sbtCredentials)).toOption
maybeRealmAndHost = allDirect.find(c => c.realm == name && c.host == url.getHost)
maybeRealmAndHost = allDirect.find(c => c.realm == name && c.host == host)
maybeRealm = allDirect.find(_.realm == name)
maybeHost = allDirect.find(_.host == url.getHost)
maybeHost = allDirect.find(_.host == host)
} yield maybeRealmAndHost.orElse(maybeRealm).orElse(maybeHost)).flatten
.map(c => Resolver.Credentials(c.userName, c.passwd))

Expand All @@ -69,13 +69,17 @@ object StewardPlugin_1_3_11 extends AutoPlugin {
(headerKey, headerValue) <- authentication.headers
} yield Resolver.Header(headerKey, headerValue)

// may include protocols other than http/https which may fail on constructing a java.net.URL
def getHost(uri: String): Option[String] =
Try(new URL(uri).getHost).orElse(Try(new URI(uri).getHost)).toOption

val resolvers = fullResolvers.value.collect {
case repo: MavenRepository if !repo.root.startsWith("file:") =>
val creds = getCredentials(new URL(repo.root), repo.name)
val creds = getHost(repo.root).flatMap(getCredentials(_, repo.name))
Resolver.MavenRepository(repo.name, repo.root, creds, getHeaders(repo.name))
case repo: URLRepository =>
val ivyPatterns = repo.patterns.ivyPatterns.mkString
val creds = getCredentials(new URL(ivyPatterns), repo.name)
val creds = getHost(ivyPatterns).flatMap(getCredentials(_, repo.name))
Resolver.IvyRepository(repo.name, ivyPatterns, creds, getHeaders(repo.name))
}

Expand Down

0 comments on commit 0b0f9a6

Please sign in to comment.