Merge pull request #196 from avalade/0.11

Adding parsing of a credentials file to add Ivy Credentials to the keyring
This commit is contained in:
Mark Harrah 2011-09-21 08:51:44 -07:00
commit c23b21148b
2 changed files with 15 additions and 5 deletions

View File

@ -12,7 +12,7 @@ object ResolveValues
def apply(conf: LaunchConfiguration): LaunchConfiguration = (new ResolveValues(conf))()
private def trim(s: String) = if(s eq null) None else notEmpty(s.trim)
private def notEmpty(s: String) = if(isEmpty(s)) None else Some(s)
private def readProperties(propertiesFile: File) =
private[boot] def readProperties(propertiesFile: File) =
{
val properties = new Properties
if(propertiesFile.exists)

View File

@ -7,6 +7,7 @@ import Pre._
import java.io.{File, FileWriter, PrintWriter, Writer}
import java.util.concurrent.Callable
import java.util.regex.Pattern
import java.util.Properties
import org.apache.ivy.{core, plugins, util, Ivy}
import core.LogOptions
@ -45,10 +46,19 @@ final class Update(config: UpdateConfiguration)
private def addCredentials()
{
val List(realm, host, user, password) = List("sbt.boot.realm", "sbt.boot.host", "sbt.boot.user", "sbt.boot.password") map System.getProperty
if(realm != null && host != null && user != null && password != null)
CredentialsStore.INSTANCE.addCredentials(realm, host, user, password)
val optionProps =
Option(System.getProperty("sbt.boot.credentials")) orElse
Option(System.getenv("SBT_CREDENTIALS")) map ( path =>
ResolveValues.readProperties(new File(path))
)
optionProps foreach extractCredentials("realm","host","user","password")
extractCredentials("sbt.boot.realm","sbt.boot.host","sbt.boot.user","sbt.boot.password")(System.getProperties)
}
private def extractCredentials(keys: (String,String,String,String))(props: Properties) {
val List(realm, host, user, password) = keys.productIterator.map(key => props.getProperty(key.toString)).toList
if (realm != null && host != null && user != null && password != null)
CredentialsStore.INSTANCE.addCredentials(realm, host, user, password)
}
private lazy val settings =
{
addCredentials()
@ -359,4 +369,4 @@ private object SbtIvyLogger
val UnknownResolver = "unknown resolver"
def acceptError(msg: String) = acceptMessage(msg) && !msg.startsWith(UnknownResolver)
def acceptMessage(msg: String) = (msg ne null) && !msg.startsWith(IgnorePrefix)
}
}