mirror of https://github.com/sbt/sbt.git
Merge pull request #413 from nrinaudo/7195-maven-settings
This commit is contained in:
commit
48dc7b24ea
|
|
@ -391,6 +391,17 @@ private[librarymanagement] abstract class ResolverFunctions {
|
|||
def defaultRetrievePattern =
|
||||
"[type]s/[organisation]/[module]/" + PluginPattern + "[artifact](-[revision])(-[classifier]).[ext]"
|
||||
final val PluginPattern = "(scala_[scalaVersion]/)(sbt_[sbtVersion]/)"
|
||||
private[librarymanagement] def expandMavenSettings(str: String): String = {
|
||||
// Aren't regular expressions beautifully clear and concise.
|
||||
// This means "find all ${...}" blocks, with the first group of each being the text between curly brackets.
|
||||
val findQuoted = "\\$\\{([^\\}]*)\\}".r
|
||||
val env = "env\\.(.*)".r
|
||||
|
||||
findQuoted.replaceAllIn(str, _.group(1) match {
|
||||
case env(variable) => sys.env.getOrElse(variable, "")
|
||||
case property => sys.props.getOrElse(property, "")
|
||||
})
|
||||
}
|
||||
private[this] def mavenLocalDir: File = {
|
||||
def loadHomeFromSettings(f: () => File): Option[File] =
|
||||
try {
|
||||
|
|
@ -399,7 +410,7 @@ private[librarymanagement] abstract class ResolverFunctions {
|
|||
else
|
||||
((XML.loadFile(file) \ "localRepository").text match {
|
||||
case "" => None
|
||||
case e @ _ => Some(new File(e))
|
||||
case e @ _ => Some(new File(expandMavenSettings(e)))
|
||||
})
|
||||
} catch {
|
||||
// Occurs inside File constructor when property or environment variable does not exist
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package sbt.librarymanagement
|
||||
|
||||
import verify.BasicTestSuite
|
||||
import scala.annotation.nowarn
|
||||
|
||||
@nowarn // Necessary because our test cases look like interpolated strings.
|
||||
object ResolverExtraTest extends BasicTestSuite {
|
||||
test("expandMavenSettings should expand existing environment variables") {
|
||||
assertExpansion(
|
||||
input = "User home: ${env.HOME}",
|
||||
expected = s"User home: ${env("HOME")}"
|
||||
)
|
||||
}
|
||||
|
||||
test("expandMavenSettings should expand existing system properties") {
|
||||
assertExpansion(
|
||||
input = "User dir: ${user.dir}",
|
||||
expected = s"User dir: ${prop("user.dir")}"
|
||||
)
|
||||
}
|
||||
|
||||
test("expandMavenSettings should expand unknown system properties to the empty string") {
|
||||
assertExpansion(
|
||||
input = "Unknown system property: ${IF_THIS_EXISTS_WE_NEED_TO_HAVE_A_CHAT}",
|
||||
expected = s"Unknown system property: "
|
||||
)
|
||||
}
|
||||
|
||||
test("expandMavenSettings should expand unknown environment variables to the empty string") {
|
||||
assertExpansion(
|
||||
input = "Unknown environment variable: ${IF_THIS_EXISTS_I_WORRY_ABOUT_YOU}",
|
||||
expected = s"Unknown environment variable: "
|
||||
)
|
||||
}
|
||||
|
||||
// - Helper functions ----------------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
def assertExpansion(input: String, expected: String) =
|
||||
assert(Resolver.expandMavenSettings(input) == s"$expected")
|
||||
|
||||
def env(name: String) = sys.env.getOrElse(name, "")
|
||||
def prop(name: String) = sys.props.getOrElse(name, "")
|
||||
}
|
||||
Loading…
Reference in New Issue