Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent from failing using an extra protocol in resolver's URL #48

Merged
merged 5 commits into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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