mirror of https://github.com/sbt/sbt.git
credentials and patterns for resolvers
This commit is contained in:
parent
f2270262d2
commit
159a3fe8f3
|
|
@ -8,11 +8,16 @@ import org.apache.ivy.util.url.CredentialsStore
|
|||
|
||||
object Credentials
|
||||
{
|
||||
def apply(realm: String, host: String, userName: String, passwd: String): Credentials =
|
||||
new DirectCredentials(realm, host, userName, passwd)
|
||||
def apply(file: File): Credentials =
|
||||
new FileCredentials(file)
|
||||
|
||||
/** Add the provided credentials to Ivy's credentials cache.*/
|
||||
def add(realm: String, host: String, userName: String, passwd: String): Unit =
|
||||
CredentialsStore.INSTANCE.addCredentials(realm, host, userName, passwd)
|
||||
/** Load credentials from the given file into Ivy's credentials cache.*/
|
||||
def apply(path: File, log: Logger): Unit =
|
||||
def add(path: File, log: Logger): Unit =
|
||||
if(path.exists)
|
||||
{
|
||||
val properties = read(path)
|
||||
|
|
@ -20,13 +25,19 @@ object Credentials
|
|||
|
||||
List.separate( List(RealmKeys, HostKeys, UserKeys, PasswordKeys).map(get) ) match
|
||||
{
|
||||
case (Nil, List(realm, host, user, pass)) => add(realm, host, user, pass); None
|
||||
case (Nil, List(realm, host, user, pass)) => add(realm, host, user, pass)
|
||||
case (errors, _) => log.warn(errors.mkString("\n"))
|
||||
}
|
||||
}
|
||||
else
|
||||
log.warn("Credentials file " + path + " does not exist")
|
||||
|
||||
def register(cs: Seq[Credentials], log: Logger): Unit =
|
||||
cs foreach {
|
||||
case f: FileCredentials => add(f.path, log)
|
||||
case d: DirectCredentials => add(d.realm, d.host, d.userName, d.passwd)
|
||||
}
|
||||
|
||||
private[this] val RealmKeys = List("realm")
|
||||
private[this] val HostKeys = List("host", "hostname")
|
||||
private[this] val UserKeys = List("user", "user.name", "username")
|
||||
|
|
@ -39,4 +50,8 @@ object Credentials
|
|||
IO.load(properties, from)
|
||||
properties map { case (k,v) => (k.toString, v.toString) } toMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed trait Credentials
|
||||
final class FileCredentials(val path: File) extends Credentials
|
||||
final class DirectCredentials(val realm: String, val host: String, val userName: String, val passwd: String) extends Credentials
|
||||
|
|
@ -55,6 +55,8 @@ final class Patterns(val ivyPatterns: Seq[String], val artifactPatterns: Seq[Str
|
|||
}
|
||||
object Patterns
|
||||
{
|
||||
implicit def defaultPatterns: Patterns = Resolver.defaultPatterns
|
||||
|
||||
def apply(artifactPatterns: String*): Patterns = Patterns(true, artifactPatterns : _*)
|
||||
def apply(isMavenCompatible: Boolean, artifactPatterns: String*): Patterns = Patterns(Nil, artifactPatterns, isMavenCompatible)
|
||||
def apply(ivyPatterns: Seq[String], artifactPatterns: Seq[String], isMavenCompatible: Boolean): Patterns = new Patterns(ivyPatterns, artifactPatterns, isMavenCompatible)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ object Defaults
|
|||
def globalCore: Seq[Setting[_]] = inScope(GlobalScope)(Seq(
|
||||
pollInterval :== 500,
|
||||
initialize :== (),
|
||||
credentials :== Nil,
|
||||
scalaHome :== None,
|
||||
javaHome :== None,
|
||||
outputStrategy :== None,
|
||||
|
|
@ -531,11 +532,13 @@ object Classpaths
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
def deliverTask(config: TaskKey[PublishConfiguration]): Initialize[Task[Unit]] =
|
||||
(ivyModule, config, deliverDepends, streams) map { (module, config, _, s) => IvyActions.deliver(module, config, s.log) }
|
||||
def publishTask(config: TaskKey[PublishConfiguration], deliverKey: TaskKey[_]): Initialize[Task[Unit]] =
|
||||
(ivyModule, config, deliverKey, streams) map { (module, config, _, s) => IvyActions.publish(module, config, s.log) }
|
||||
(ivyModule, config, deliverKey, credentials, streams) map { (module, config, _, creds, s) =>
|
||||
Credentials.register(creds, s.log)
|
||||
IvyActions.publish(module, config, s.log)
|
||||
}
|
||||
|
||||
import Cache._
|
||||
import CacheIvy.{classpathFormat, publishIC, updateIC, updateReportF}
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ object Keys
|
|||
val packageToPublish = TaskKey[Unit]("package-to-publish")
|
||||
val deliverDepends = TaskKey[Unit]("deliver-depends")
|
||||
val publishMavenStyle = SettingKey[Boolean]("publish-maven-style")
|
||||
val credentials = TaskKey[Seq[Credentials]]("credentials")
|
||||
|
||||
val makePom = TaskKey[File]("make-pom")
|
||||
val deliver = TaskKey[Unit]("deliver")
|
||||
|
|
|
|||
Loading…
Reference in New Issue