mirror of https://github.com/sbt/sbt.git
Support configuring a subset of configurations from which to retrieve dependencies when retrieveManaged is true
This commit is contained in:
parent
5b7f41e300
commit
b617b41ae1
|
|
@ -31,8 +31,9 @@ final class UpdateConfiguration(val retrieve: Option[RetrieveConfiguration], val
|
|||
logging: UpdateLogging.Value = this.logging): UpdateConfiguration =
|
||||
new UpdateConfiguration(retrieve, missingOk, logging)
|
||||
}
|
||||
final class RetrieveConfiguration(val retrieveDirectory: File, val outputPattern: String, val sync: Boolean) {
|
||||
def this(retrieveDirectory: File, outputPattern: String) = this(retrieveDirectory, outputPattern, false)
|
||||
final class RetrieveConfiguration(val retrieveDirectory: File, val outputPattern: String, val sync: Boolean, val configurationsToRetrieve: Option[Set[Configuration]]) {
|
||||
def this(retrieveDirectory: File, outputPattern: String) = this(retrieveDirectory, outputPattern, false, None)
|
||||
def this(retrieveDirectory: File, outputPattern: String, sync: Boolean) = this(retrieveDirectory, outputPattern, sync, None)
|
||||
}
|
||||
final case class MakePomConfiguration(file: File, moduleInfo: ModuleInfo, configurations: Option[Seq[Configuration]] = None, extra: NodeSeq = NodeSeq.Empty, process: XNode => XNode = n => n, filterRepositories: MavenRepository => Boolean = _ => true, allRepositories: Boolean, includeTypes: Set[String] = Set(Artifact.DefaultType, Artifact.PomType))
|
||||
// exclude is a map on a restricted ModuleID
|
||||
|
|
@ -295,16 +296,22 @@ object IvyActions {
|
|||
(resolveReport, err)
|
||||
}
|
||||
private def retrieve(log: Logger, ivy: Ivy, report: UpdateReport, config: RetrieveConfiguration): UpdateReport =
|
||||
retrieve(log, ivy, report, config.retrieveDirectory, config.outputPattern, config.sync)
|
||||
retrieve(log, ivy, report, config.retrieveDirectory, config.outputPattern, config.sync, config.configurationsToRetrieve)
|
||||
|
||||
private def retrieve(log: Logger, ivy: Ivy, report: UpdateReport, base: File, pattern: String, sync: Boolean): UpdateReport =
|
||||
private def retrieve(log: Logger, ivy: Ivy, report: UpdateReport, base: File, pattern: String, sync: Boolean, configurationsToRetrieve: Option[Set[Configuration]]): UpdateReport =
|
||||
{
|
||||
val configurationNames = configurationsToRetrieve match {
|
||||
case None => None
|
||||
case Some(configs) => Some(configs.map(_.name))
|
||||
}
|
||||
val existingFiles = PathFinder(base).***.get filterNot { _.isDirectory }
|
||||
val toCopy = new collection.mutable.HashSet[(File, File)]
|
||||
val retReport = report retrieve { (conf, mid, art, cached) =>
|
||||
val to = retrieveTarget(conf, mid, art, base, pattern)
|
||||
toCopy += ((cached, to))
|
||||
to
|
||||
configurationNames match {
|
||||
case None => performRetrieve(conf, mid, art, base, pattern, cached, toCopy)
|
||||
case Some(names) if names(conf) => performRetrieve(conf, mid, art, base, pattern, cached, toCopy)
|
||||
case _ => cached
|
||||
}
|
||||
}
|
||||
IO.copy(toCopy)
|
||||
val resolvedFiles = toCopy.map(_._2)
|
||||
|
|
@ -318,6 +325,13 @@ object IvyActions {
|
|||
|
||||
retReport
|
||||
}
|
||||
|
||||
private def performRetrieve(conf: String, mid: ModuleID, art: Artifact, base: File, pattern: String, cached: File, toCopy: collection.mutable.HashSet[(File, File)]): File = {
|
||||
val to = retrieveTarget(conf, mid, art, base, pattern)
|
||||
toCopy += ((cached, to))
|
||||
to
|
||||
}
|
||||
|
||||
private def retrieveTarget(conf: String, mid: ModuleID, art: Artifact, base: File, pattern: String): File =
|
||||
new File(base, substitute(conf, mid, art, pattern))
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ object Defaults extends BuildCommon {
|
|||
exportJars :== false,
|
||||
retrieveManaged :== false,
|
||||
retrieveManagedSync :== false,
|
||||
configurationsToRetrieve :== None,
|
||||
scalaOrganization :== ScalaArtifacts.Organization,
|
||||
sbtResolver := { if (sbtVersion.value endsWith "-SNAPSHOT") Classpaths.typesafeSnapshots else Classpaths.typesafeReleases },
|
||||
crossVersion :== CrossVersion.Disabled,
|
||||
|
|
@ -1136,7 +1137,7 @@ object Classpaths {
|
|||
projectDescriptors <<= depMap,
|
||||
updateConfiguration := new UpdateConfiguration(retrieveConfiguration.value, false, ivyLoggingLevel.value),
|
||||
updateOptions := (updateOptions in Global).value,
|
||||
retrieveConfiguration := { if (retrieveManaged.value) Some(new RetrieveConfiguration(managedDirectory.value, retrievePattern.value, retrieveManagedSync.value)) else None },
|
||||
retrieveConfiguration := { if (retrieveManaged.value) Some(new RetrieveConfiguration(managedDirectory.value, retrievePattern.value, retrieveManagedSync.value, configurationsToRetrieve.value)) else None },
|
||||
ivyConfiguration <<= mkIvyConfiguration,
|
||||
ivyConfigurations := {
|
||||
val confs = thisProject.value.configurations
|
||||
|
|
|
|||
|
|
@ -317,6 +317,7 @@ object Keys {
|
|||
val autoUpdate = SettingKey[Boolean]("auto-update", "<unimplemented>", Invisible)
|
||||
val retrieveManaged = SettingKey[Boolean]("retrieve-managed", "If true, enables retrieving dependencies to the current build. Otherwise, dependencies are used directly from the cache.", BSetting)
|
||||
val retrieveManagedSync = SettingKey[Boolean]("retrieve-managed-sync", "If true, enables synchronizing the dependencies retrieved to the current build by removed unneeded files.", BSetting)
|
||||
val configurationsToRetrieve = SettingKey[Option[Set[Configuration]]]("configurations-to-retrieve", "An optional set of configurations from which to retrieve dependencies if retrieveManaged is set to true", BSetting)
|
||||
val managedDirectory = SettingKey[File]("managed-directory", "Directory to which managed dependencies are retrieved.", BSetting)
|
||||
val classpathTypes = SettingKey[Set[String]]("classpath-types", "Artifact types that are included on the classpath.", BSetting)
|
||||
val publishArtifact = SettingKey[Boolean]("publish-artifact", "Enables (true) or disables (false) publishing an artifact.", AMinusSetting)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
[@ajsquared]: https://github.com/ajsquared
|
||||
|
||||
|
||||
### Changes with compatibility implications
|
||||
|
||||
### Improvements
|
||||
- Adds configurationsToRetrieve key, that takes values of `Option[Set[Configuration]]`. If set, when retrieveManaged is true only artifacts in the specified configurations will be retrieved to the current build. By [@ajsquared][@ajsquared]
|
||||
|
||||
### Fixes
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
configurationsToRetrieve := Some(Set(Compile))
|
||||
|
||||
retrieveManaged := true
|
||||
|
||||
libraryDependencies += "log4j" % "log4j" % "1.2.16" % "compile"
|
||||
|
||||
autoScalaLibrary := false
|
||||
|
||||
managedDirectory := file("dependencies")
|
||||
|
||||
retrievePattern := "[conf]/[artifact]-[revision](-[classifier]).[ext]"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
> update
|
||||
$ exists dependencies/compile
|
||||
$ absent dependencies/compile-internal
|
||||
$ absent dependencies/runtime
|
||||
$ absent dependencies/runtime-internal
|
||||
$ absent dependencies/scala-tool
|
||||
$ absent dependencies/test
|
||||
$ absent dependencies/test-internal
|
||||
Loading…
Reference in New Issue