mirror of https://github.com/sbt/sbt.git
Remove some uses of scalaz.Scalaz.*Ops
This commit is contained in:
parent
015e906481
commit
dc87950dc4
|
|
@ -4,7 +4,6 @@ package core
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.language.higherKinds
|
import scala.language.higherKinds
|
||||||
import scalaz.Monad
|
import scalaz.Monad
|
||||||
import scalaz.Scalaz.{ToFunctorOps, ToBindOps}
|
|
||||||
|
|
||||||
|
|
||||||
sealed abstract class ResolutionProcess {
|
sealed abstract class ResolutionProcess {
|
||||||
|
|
@ -191,8 +190,11 @@ object ResolutionProcess {
|
||||||
.toVector
|
.toVector
|
||||||
.foldLeft(F.point(Vector.empty[((Module, String), Either[Seq[String], (Artifact.Source, Project)])])) {
|
.foldLeft(F.point(Vector.empty[((Module, String), Either[Seq[String], (Artifact.Source, Project)])])) {
|
||||||
(acc, l) =>
|
(acc, l) =>
|
||||||
for (v <- acc; e <- fetch(l))
|
F.bind(acc) { v =>
|
||||||
yield v ++ e
|
F.map(fetch(l)) { e =>
|
||||||
|
v ++ e
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package coursier.maven
|
package coursier.maven
|
||||||
|
|
||||||
import coursier.core._
|
import coursier.core._
|
||||||
import scalaz.Scalaz.{eitherMonad, listInstance, ToTraverseOps}
|
import coursier.util.Traverse.TraverseOps
|
||||||
|
|
||||||
object Pom {
|
object Pom {
|
||||||
import coursier.util.Xml._
|
import coursier.util.Xml._
|
||||||
|
|
@ -57,7 +57,10 @@ object Pom {
|
||||||
.map(_.children.filter(_.label == "exclusion"))
|
.map(_.children.filter(_.label == "exclusion"))
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
|
|
||||||
xmlExclusions.toList.traverseU(module(_, defaultArtifactId = Some("*"))).right.map { exclusions =>
|
xmlExclusions
|
||||||
|
.eitherTraverse(module(_, defaultArtifactId = Some("*")))
|
||||||
|
.right
|
||||||
|
.map { exclusions =>
|
||||||
|
|
||||||
val optional = text(node, "optional", "").right.toSeq.contains("true")
|
val optional = text(node, "optional", "").right.toSeq.contains("true")
|
||||||
|
|
||||||
|
|
@ -125,7 +128,9 @@ object Pom {
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
deps <- xmlDeps.toList.traverseU(dependency).right
|
deps <- xmlDeps
|
||||||
|
.eitherTraverse(dependency)
|
||||||
|
.right
|
||||||
|
|
||||||
depMgmts <- node
|
depMgmts <- node
|
||||||
.children
|
.children
|
||||||
|
|
@ -133,8 +138,7 @@ object Pom {
|
||||||
.flatMap(_.children.find(_.label == "dependencies"))
|
.flatMap(_.children.find(_.label == "dependencies"))
|
||||||
.map(_.children.filter(_.label == "dependency"))
|
.map(_.children.filter(_.label == "dependency"))
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
.toList
|
.eitherTraverse(dependency)
|
||||||
.traverseU(dependency)
|
|
||||||
.right
|
.right
|
||||||
|
|
||||||
properties <- node
|
properties <- node
|
||||||
|
|
@ -142,8 +146,7 @@ object Pom {
|
||||||
.find(_.label == "properties")
|
.find(_.label == "properties")
|
||||||
.map(_.children.collect { case elem if elem.isElement => elem })
|
.map(_.children.collect { case elem if elem.isElement => elem })
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
.toList
|
.eitherTraverse(property)
|
||||||
.traverseU(property)
|
|
||||||
.right
|
.right
|
||||||
|
|
||||||
} yield Profile(id, activeByDefault, activation, deps, depMgmts, properties.toMap)
|
} yield Profile(id, activeByDefault, activation, deps, depMgmts, properties.toMap)
|
||||||
|
|
@ -176,7 +179,7 @@ object Pom {
|
||||||
.map(_.children.filter(_.label == "dependency"))
|
.map(_.children.filter(_.label == "dependency"))
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
)
|
)
|
||||||
deps <- xmlDeps.toList.traverseU(dependency).right
|
deps <- xmlDeps.eitherTraverse(dependency).right
|
||||||
|
|
||||||
xmlDepMgmts <- point(
|
xmlDepMgmts <- point(
|
||||||
pom.children
|
pom.children
|
||||||
|
|
@ -185,7 +188,7 @@ object Pom {
|
||||||
.map(_.children.filter(_.label == "dependency"))
|
.map(_.children.filter(_.label == "dependency"))
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
)
|
)
|
||||||
depMgmts <- xmlDepMgmts.toList.traverseU(dependency).right
|
depMgmts <- xmlDepMgmts.eitherTraverse(dependency).right
|
||||||
|
|
||||||
groupId <- Some(projModule.organization).filter(_.nonEmpty)
|
groupId <- Some(projModule.organization).filter(_.nonEmpty)
|
||||||
.orElse(parentModuleOpt.map(_.organization).filter(_.nonEmpty))
|
.orElse(parentModuleOpt.map(_.organization).filter(_.nonEmpty))
|
||||||
|
|
@ -211,7 +214,7 @@ object Pom {
|
||||||
.map(_.children.collect{case elem if elem.isElement => elem})
|
.map(_.children.collect{case elem if elem.isElement => elem})
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
)
|
)
|
||||||
properties <- xmlProperties.toList.traverseU(property).right
|
properties <- xmlProperties.eitherTraverse(property).right
|
||||||
|
|
||||||
xmlProfiles <- point(
|
xmlProfiles <- point(
|
||||||
pom
|
pom
|
||||||
|
|
@ -220,7 +223,7 @@ object Pom {
|
||||||
.map(_.children.filter(_.label == "profile"))
|
.map(_.children.filter(_.label == "profile"))
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
)
|
)
|
||||||
profiles <- xmlProfiles.toList.traverseU(profile).right
|
profiles <- xmlProfiles.eitherTraverse(profile).right
|
||||||
|
|
||||||
extraAttrs <- properties
|
extraAttrs <- properties
|
||||||
.collectFirst { case ("extraDependencyAttributes", s) => extraAttributes(s) }
|
.collectFirst { case ("extraDependencyAttributes", s) => extraAttributes(s) }
|
||||||
|
|
@ -307,7 +310,7 @@ object Pom {
|
||||||
Project(
|
Project(
|
||||||
finalProjModule,
|
finalProjModule,
|
||||||
version,
|
version,
|
||||||
(relocationDependencyOpt.toList ::: deps).map {
|
(relocationDependencyOpt.toSeq ++ deps).map {
|
||||||
case (config, dep0) =>
|
case (config, dep0) =>
|
||||||
val dep = extraAttrsMap.get(dep0.moduleVersion).fold(dep0)(attrs =>
|
val dep = extraAttrsMap.get(dep0.moduleVersion).fold(dep0)(attrs =>
|
||||||
dep0.copy(module = dep0.module.copy(attributes = attrs))
|
dep0.copy(module = dep0.module.copy(attributes = attrs))
|
||||||
|
|
@ -426,8 +429,7 @@ object Pom {
|
||||||
.getOrElse(Seq.empty)
|
.getOrElse(Seq.empty)
|
||||||
|
|
||||||
xmlSnapshotVersions
|
xmlSnapshotVersions
|
||||||
.toList
|
.eitherTraverse(snapshotVersion)
|
||||||
.traverseU(snapshotVersion)
|
|
||||||
.right
|
.right
|
||||||
}
|
}
|
||||||
} yield {
|
} yield {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package coursier.util
|
||||||
|
|
||||||
|
import scala.collection.mutable.ListBuffer
|
||||||
|
|
||||||
|
object Traverse {
|
||||||
|
|
||||||
|
implicit class TraverseOps[T](val seq: Seq[T]) {
|
||||||
|
def eitherTraverse[L, R](f: T => Either[L, R]): Either[L, Seq[R]] =
|
||||||
|
// Warning: iterates on the whole sequence no matter what, even if the first element is a Left
|
||||||
|
seq.foldLeft[Either[L, ListBuffer[R]]](Right(new ListBuffer)) {
|
||||||
|
case (l @ Left(_), _) => l
|
||||||
|
case (Right(b), elem) =>
|
||||||
|
f(elem) match {
|
||||||
|
case Left(l) => Left(l)
|
||||||
|
case Right(r) => Right(b += r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
package coursier
|
package coursier
|
||||||
package test
|
package test
|
||||||
|
|
||||||
import utest._
|
|
||||||
|
|
||||||
import coursier.maven.Pom
|
|
||||||
|
|
||||||
import coursier.core.compatibility._
|
import coursier.core.compatibility._
|
||||||
|
import coursier.util.Traverse.TraverseOps
|
||||||
|
import coursier.maven.Pom
|
||||||
|
import utest._
|
||||||
|
|
||||||
object PomParsingTests extends TestSuite {
|
object PomParsingTests extends TestSuite {
|
||||||
|
|
||||||
|
|
@ -217,7 +216,6 @@ object PomParsingTests extends TestSuite {
|
||||||
assert(result == expected)
|
assert(result == expected)
|
||||||
}
|
}
|
||||||
'beFineWithCommentsInProperties{
|
'beFineWithCommentsInProperties{
|
||||||
import scalaz.Scalaz.{eitherMonad, listInstance, ToTraverseOps}
|
|
||||||
|
|
||||||
val properties =
|
val properties =
|
||||||
"""
|
"""
|
||||||
|
|
@ -258,7 +256,7 @@ object PomParsingTests extends TestSuite {
|
||||||
assert(node.label == "properties")
|
assert(node.label == "properties")
|
||||||
|
|
||||||
val children = node.children.collect { case elem if elem.isElement => elem }
|
val children = node.children.collect { case elem if elem.isElement => elem }
|
||||||
val props0 = children.toList.traverseU(Pom.property)
|
val props0 = children.eitherTraverse(Pom.property)
|
||||||
|
|
||||||
assert(props0.isRight)
|
assert(props0.isRight)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue