Move ivy xml generation

In the hope that this might address issues with shading plugin on single core machines
This commit is contained in:
Alexandre Archambault 2017-01-31 15:19:08 +01:00
parent 4b3923d3e5
commit 5583efffd0
5 changed files with 64 additions and 39 deletions

View File

@ -55,6 +55,21 @@ object CoursierPlugin extends AutoPlugin {
)
)
def makeIvyXmlBefore[T](
task: TaskKey[T],
shadedConfigOpt: Option[(String, String)]
): Setting[Task[T]] =
// not 100% sure that make writeFiles below happen before the actions triggered by task.value...
task := {
val currentProject = {
val proj = coursierProject.value
val publications = coursierPublications.value
proj.copy(publications = publications)
}
IvyXml.writeFiles(currentProject, shadedConfigOpt, ivySbt.value, streams.value.log)
task.value
}
def coursierSettings(
shadedConfigOpt: Option[(String, String)],
packageConfigs: Seq[(Configuration, String)]
@ -83,6 +98,8 @@ object CoursierPlugin extends AutoPlugin {
withClassifiers = true,
sbtClassifiers = true
),
makeIvyXmlBefore(deliverLocalConfiguration, shadedConfigOpt),
makeIvyXmlBefore(deliverConfiguration, shadedConfigOpt),
update <<= Tasks.updateTask(
shadedConfigOpt,
withClassifiers = false

View File

@ -1,6 +1,7 @@
package coursier
import coursier.ivy.{ IvyXml, IvyRepository }
import coursier.ivy.IvyRepository
import coursier.ivy.IvyXml.{ mappings => ivyXmlMappings }
import java.net.{ MalformedURLException, URL }
@ -71,7 +72,7 @@ object FromSbt {
)
val mapping = module.configurations.getOrElse("compile")
val allMappings = IvyXml.mappings(mapping)
val allMappings = ivyXmlMappings(mapping)
val attributes =
if (module.explicitArtifacts.isEmpty)

View File

@ -1,10 +1,49 @@
package coursier
import scala.xml.{ Node, PrefixedAttribute }
import coursier.internal.FileUtil
import org.apache.ivy.core.module.id.ModuleRevisionId
object MakeIvyXml {
import scala.collection.JavaConverters._
import scala.xml.{Node, PrefixedAttribute}
def apply(project0: Project, shadedConfigOpt: Option[String]): Node = {
object IvyXml {
// These are required for publish to be fine, later on.
def writeFiles(
currentProject: Project,
shadedConfigOpt: Option[(String, String)],
ivySbt: sbt.IvySbt,
log: sbt.Logger
): Unit = {
val ivyCacheManager = ivySbt.withIvy(log)(ivy =>
ivy.getResolutionCacheManager
)
val ivyModule = ModuleRevisionId.newInstance(
currentProject.module.organization,
currentProject.module.name,
currentProject.version,
currentProject.module.attributes.asJava
)
val cacheIvyFile = ivyCacheManager.getResolvedIvyFileInCache(ivyModule)
val cacheIvyPropertiesFile = ivyCacheManager.getResolvedIvyPropertiesInCache(ivyModule)
val printer = new scala.xml.PrettyPrinter(80, 2)
val content0 = """<?xml version="1.0" encoding="UTF-8"?>""" + '\n' +
printer.format(content(currentProject, shadedConfigOpt.map(_._2)))
cacheIvyFile.getParentFile.mkdirs()
log.info(s"Writing Ivy file $cacheIvyFile")
FileUtil.write(cacheIvyFile, content0.getBytes("UTF-8"))
// Just writing an empty file here... Are these only used?
cacheIvyPropertiesFile.getParentFile.mkdirs()
FileUtil.write(cacheIvyPropertiesFile, Array())
}
def content(project0: Project, shadedConfigOpt: Option[String]): Node = {
val filterOutDependencies =
shadedConfigOpt.toSet[String].flatMap { shadedConfig =>

View File

@ -844,42 +844,10 @@ object Tasks {
proj.copy(publications = publications)
}
val ivySbt0 = ivySbt.value
val ivyCacheManager = ivySbt0.withIvy(streams.value.log)(ivy =>
ivy.getResolutionCacheManager
)
val ivyModule = ModuleRevisionId.newInstance(
currentProject.module.organization,
currentProject.module.name,
currentProject.version,
currentProject.module.attributes.asJava
)
val cacheIvyFile = ivyCacheManager.getResolvedIvyFileInCache(ivyModule)
val cacheIvyPropertiesFile = ivyCacheManager.getResolvedIvyPropertiesInCache(ivyModule)
val log = streams.value.log
val verbosityLevel = coursierVerbosity.value
// required for publish to be fine, later on
def writeIvyFiles() = {
val printer = new scala.xml.PrettyPrinter(80, 2)
val b = new StringBuilder
b ++= """<?xml version="1.0" encoding="UTF-8"?>"""
b += '\n'
b ++= printer.format(MakeIvyXml(currentProject, shadedConfigOpt.map(_._2)))
cacheIvyFile.getParentFile.mkdirs()
FileUtil.write(cacheIvyFile, b.result().getBytes("UTF-8"))
// Just writing an empty file here... Are these only used?
cacheIvyPropertiesFile.getParentFile.mkdirs()
FileUtil.write(cacheIvyPropertiesFile, "".getBytes("UTF-8"))
}
writeIvyFiles()
val res = {
if (withClassifiers && sbtClassifiers)
coursierSbtClassifiersResolution

View File

@ -1,6 +1,6 @@
package coursier
import coursier.ivy.IvyXml
import coursier.ivy.IvyXml.{ mappings => ivyXmlMappings }
import sbt.Keys._
import sbt.{AutoPlugin, Compile, Configuration, TaskKey, inConfig}
@ -69,7 +69,7 @@ object ShadingPlugin extends AutoPlugin {
.map(c => c.copy(extendsConfigs = c.extendsConfigs.filter(_.name != Shaded.name))),
libraryDependencies := libraryDependencies.in(baseSbtConfiguration).value.filter { dep =>
val isShaded = dep.configurations.exists { mappings =>
IvyXml.mappings(mappings).exists(_._1 == Shaded.name)
ivyXmlMappings(mappings).exists(_._1 == Shaded.name)
}
!isShaded