Merge pull request #35 from alexarchambault/develop

Less flaky handling of special project org.scala-sbt:global-plugins…
This commit is contained in:
Alexandre Archambault 2019-02-18 14:52:11 +01:00 committed by GitHub
commit bb3e0f398a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 141 additions and 50 deletions

View File

@ -106,19 +106,8 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
}
.map(withAuthenticationByHost(_, conf.authenticationByHost.toMap))
val globalPluginsRepos =
for (p <- ResolutionParams.globalPluginPatterns(sbtBinaryVersion))
yield IvyRepository.fromPattern(
p,
withChecksums = false,
withSignatures = false,
withArtifacts = false
)
val interProjectRepo = InterProjectRepository(conf.interProjectDependencies)
val internalRepositories = globalPluginsRepos :+ interProjectRepo
val dependencies = module0
.dependencies
.flatMap { d =>
@ -148,7 +137,7 @@ class CoursierDependencyResolution(conf: CoursierConfiguration) extends Dependen
mainRepositories = mainRepositories,
parentProjectCache = Map.empty,
interProjectDependencies = conf.interProjectDependencies,
internalRepositories = internalRepositories,
internalRepositories = Seq(interProjectRepo),
typelevel = typelevel,
sbtClassifiers = false,
projectName = projectName,

View File

@ -150,26 +150,6 @@ object ResolutionParams {
}
}
def globalPluginPatterns(sbtVersion: String): Seq[coursier.ivy.Pattern] = {
val defaultRawPattern = s"$${sbt.global.base.uri-$${user.home.uri}/.sbt/$sbtVersion}/plugins/target" +
"/resolution-cache/" +
"[organization]/[module](/scala_[scalaVersion])(/sbt_[sbtVersion])/[revision]/resolved.xml.[ext]"
// seems to be required in more recent versions of sbt (since 0.13.16?)
val extraRawPattern = s"$${sbt.global.base.uri-$${user.home.uri}/.sbt/$sbtVersion}/plugins/target" +
"(/scala-[scalaVersion])(/sbt-[sbtVersion])" +
"/resolution-cache/" +
"[organization]/[module](/scala_[scalaVersion])(/sbt_[sbtVersion])/[revision]/resolved.xml.[ext]"
val p = exceptionPatternParser()
Seq(
defaultRawPattern,
extraRawPattern
).map(p)
}
private val slowReposBase = Seq(
"https://repo.typesafe.com/",
"https://repo.scala-sbt.org/",

View File

@ -7,6 +7,8 @@ import coursier.sbtcoursiershared.Structure._
import sbt.Def
import sbt.Keys._
import scala.collection.JavaConverters._
object InputsTasks {
def coursierProjectTask: Def.Initialize[sbt.Task[Project]] =
@ -31,17 +33,123 @@ object InputsTasks {
}
}
private def moduleFromIvy(id: org.apache.ivy.core.module.id.ModuleRevisionId): Module =
Module(
Organization(id.getOrganisation),
ModuleName(id.getName),
id.getExtraAttributes
.asScala
.map {
case (k0, v0) => k0.asInstanceOf[String] -> v0.asInstanceOf[String]
}
.toMap
)
private def dependencyFromIvy(desc: org.apache.ivy.core.module.descriptor.DependencyDescriptor): Seq[(Configuration, Dependency)] = {
val id = desc.getDependencyRevisionId
val module = moduleFromIvy(id)
val exclusions = desc
.getAllExcludeRules
.map { rule =>
// we're ignoring rule.getConfigurations and rule.getMatcher here
val modId = rule.getId.getModuleId
// we're ignoring modId.getAttributes here
(Organization(modId.getOrganisation), ModuleName(modId.getName))
}
.toSet
val configurations = desc
.getModuleConfigurations
.toVector
.flatMap(s => coursier.ivy.IvyXml.mappings(s))
def dependency(conf: Configuration, attr: Attributes) = Dependency(
module,
id.getRevision,
conf,
exclusions,
attr,
optional = false,
desc.isTransitive
)
val attributes: Configuration => Attributes = {
val artifacts = desc.getAllDependencyArtifacts
val m = artifacts.toVector.flatMap { art =>
val attr = Attributes(Type(art.getType), Classifier.empty)
art.getConfigurations.map(Configuration(_)).toVector.map { conf =>
conf -> attr
}
}.toMap
c => m.getOrElse(c, Attributes.empty)
}
configurations.map {
case (from, to) =>
from -> dependency(to, attributes(to))
}
}
def coursierInterProjectDependenciesTask: Def.Initialize[sbt.Task[Seq[Project]]] =
Def.taskDyn {
val state = sbt.Keys.state.value
val projectRef = sbt.Keys.thisProjectRef.value
val projects = Structure.allRecursiveInterDependencies(state, projectRef)
val projectRefs = Structure.allRecursiveInterDependencies(state, projectRef)
val t = coursierProject.forAllProjects(state, projects).map(_.values.toVector)
val t = coursierProject.forAllProjectsOpt(state, projectRefs)
Def.task(t.value)
Def.task {
val projects = t.value.toVector.flatMap {
case (ref, None) =>
if (ref.build != projectRef.build)
state.log.warn(s"Cannot get coursier info for project under ${ref.build}, is sbt-coursier also added to it?")
Nil
case (_, Some(p)) =>
Seq(p)
}
val projectModules = projects.map(_.module).toSet
// this includes org.scala-sbt:global-plugins referenced from meta-builds in particular
val extraProjects = sbt.Keys.projectDescriptors.value
.map {
case (k, v) =>
moduleFromIvy(k) -> v
}
.filter {
case (module, _) =>
!projectModules(module)
}
.toVector
.map {
case (module, v) =>
val deps = v.getDependencies.flatMap(dependencyFromIvy)
Project(
module,
v.getModuleRevisionId.getRevision,
deps,
Map(),
None,
Nil,
Nil,
Nil,
None,
None,
None,
relocated = false,
None,
Nil,
Info.empty
)
}
projects ++ extraProjects
}
}
def coursierFallbackDependenciesTask: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =

View File

@ -54,5 +54,21 @@ object Structure {
val tasks = projects.flatMap(p => key.in(p).get(structure(state).data).map(_.map(it => (p, it))))
std.TaskExtra.joinTasks(tasks).join.map(_.toMap)
}
// ^^ things from sbt-structure ^^
def forAllProjectsOpt(state: State, projects: Seq[ProjectRef]): sbt.Task[Map[ProjectRef, Option[T]]] = {
val settings = structure(state).data
val tasks = projects.map { p =>
val taskOpt = key.in(p).get(settings)
taskOpt match {
case None =>
Def.task(p -> Option.empty[T]).evaluate(settings)
case Some(t) =>
t.map(p -> Option(_))
}
}
std.TaskExtra.joinTasks(tasks).join.map(_.toMap)
}
}
}

View File

@ -1,7 +1,5 @@
package coursier.sbtcoursier
import java.net.URL
import coursier.ProjectCache
import coursier.core._
import coursier.lmcoursier._

View File

@ -78,15 +78,6 @@ object ResolutionTasks {
val typelevel = Organization(scalaOrganization.value) == Typelevel.typelevelOrg
val globalPluginsRepos =
for (p <- ResolutionParams.globalPluginPatterns(sbtBinaryVersion.value))
yield IvyRepository.fromPattern(
p,
withChecksums = false,
withSignatures = false,
withArtifacts = false
)
val interProjectRepo = InterProjectRepository(interProjectDependencies)
val ivyProperties = ResolutionParams.defaultIvyProperties()
@ -103,8 +94,6 @@ object ResolutionTasks {
val authenticationByHost = authenticationByHostTask.value
val internalRepositories = globalPluginsRepos :+ interProjectRepo
val parentProjectCache: ProjectCache = coursierParentProjectCache.value
.get(resolvers)
.map(_.foldLeft[ProjectCache](Map.empty)(_ ++ _))
@ -130,7 +119,7 @@ object ResolutionTasks {
mainRepositories = mainRepositories,
parentProjectCache = parentProjectCache,
interProjectDependencies = interProjectDependencies,
internalRepositories = internalRepositories,
internalRepositories = Seq(interProjectRepo),
typelevel = typelevel,
sbtClassifiers = sbtClassifiers,
projectName = projectName,

View File

@ -1,4 +1,6 @@
import java.util.Locale
import sbt._
import sbt.Keys._
import sbt.ScriptedPlugin.autoImport.{scriptedBufferLog, scriptedLaunchOpts}
@ -22,7 +24,16 @@ object Settings {
"-language:higherKinds",
"-language:implicitConversions"
)
)
) ++ {
val prop = sys.props.getOrElse("publish.javadoc", "").toLowerCase(Locale.ROOT)
if (prop == "0" || prop == "false")
Seq(
sources in (Compile, doc) := Seq.empty,
publishArtifact in (Compile, packageDoc) := false
)
else
Nil
}
lazy val plugin =
shared ++