Merge pull request #1600 from topping/0.13

PR for #1589
This commit is contained in:
Josh Suereth 2014-09-24 09:11:57 -04:00
commit e8a2fcc26f
2 changed files with 27 additions and 3 deletions

View File

@ -5,8 +5,9 @@ package sbt
import java.io.File
import java.net.URL
import scala.xml.NodeSeq
import scala.xml.{ Text, NodeSeq, Elem, XML }
import org.apache.ivy.plugins.resolver.DependencyResolver
import org.xml.sax.SAXParseException
sealed trait Resolver {
def name: String
@ -300,8 +301,23 @@ object Resolver {
def localBasePattern = "[organisation]/[module]/" + PluginPattern + "[revision]/[type]s/[artifact](-[classifier]).[ext]"
def defaultRetrievePattern = "[type]s/[organisation]/[module]/" + PluginPattern + "[artifact](-[revision])(-[classifier]).[ext]"
final val PluginPattern = "(scala_[scalaVersion]/)(sbt_[sbtVersion]/)"
private[this] def mavenLocalDir = new File(Path.userHome, ".m2/repository/")
private[this] def mavenLocalDir: File = {
def loadHomeFromSettings(f: () => File): Option[File] =
try {
val file = XML.loadFile(f())
(file \ "localRepository").text match {
case "" => None
case e @ _ => Some(new File(e))
}
} catch {
// Occurs inside File constructor when property or environment variable does not exist
case _: NullPointerException => None
case e: SAXParseException => System.err.println(s"WARNING: Problem parsing ${f().getAbsolutePath}, ${e.getMessage}"); None
}
loadHomeFromSettings(() => new File(Path.userHome, ".m2/settings.xml")) orElse
loadHomeFromSettings(() => new File(new File(System.getenv("M2_HOME")), "conf/settings.xml")) getOrElse
new File(Path.userHome, ".m2/repository")
}
def publishMavenLocal = Resolver.file("publish-m2-local", mavenLocalDir)
def mavenLocal = MavenRepository("Maven2 Local", mavenLocalDir.toURI.toString)
def defaultLocal = defaultUserFileRepository("local")

View File

@ -0,0 +1,8 @@
[1600]: https://github.com/sbt/sbt/pull/1600
[@topping]: https://github.com/topping
### Improvements
* Maven local repository is now resolved from the first of the <localRepository/> element in ~/.m2/settings.xml, $M2_HOME/conf/settings.xml or the default of
~/.m2/repository if neither of those configuration elements exist. If more Maven settings are required to be recovered, the proper thing to do is merge
the two possible settings.xml files, then query against the element path of the merge. This code avoids the merge by checking sequentially.