Additional updates, should be clean now.

This commit is contained in:
Brian Topping 2014-09-17 15:24:33 -04:00
parent ad7d9ce42b
commit 31acddf856
2 changed files with 17 additions and 7 deletions

View File

@ -5,7 +5,7 @@ package sbt
import java.io.File
import java.net.URL
import scala.xml.{ XML, NodeSeq }
import scala.xml.{ Text, NodeSeq, Elem, XML }
import org.apache.ivy.plugins.resolver.DependencyResolver
sealed trait Resolver {
@ -303,17 +303,19 @@ object Resolver {
private[this] def mavenLocalDir: File = {
def loadHomeFromSettings(f: () => File): Option[File] =
try {
XML.loadFile(f()) \ "settings" \ "localRepository" match {
case scala.xml.Text(loc) => Some(new File(loc))
case _ => None
val file = XML.loadFile(f())
(file \ "localRepository").text match {
case "" => None
case e @ _ => Some(new File(e))
}
} catch {
case _: Throwable => None
// Occurs inside File constructor when property or environment variable does not exist
case _: NullPointerException => None
}
loadHomeFromSettings(() => new File(Path.userHome, ".m2/settings.xml")) orElse
loadHomeFromSettings(() => new File(Path.fileProperty("M2_HOME"), "conf/settings.xml")) getOrElse
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.