mirror of https://github.com/sbt/sbt.git
Refactor some code
This commit is contained in:
parent
1106422fb9
commit
788a864d83
|
|
@ -10,7 +10,7 @@ package internal
|
||||||
package librarymanagement
|
package librarymanagement
|
||||||
|
|
||||||
import lmcoursier.definitions.{
|
import lmcoursier.definitions.{
|
||||||
Classifier,
|
Classifier => CClassifier,
|
||||||
Configuration => CConfiguration,
|
Configuration => CConfiguration,
|
||||||
Extension => CExtension,
|
Extension => CExtension,
|
||||||
Publication => CPublication,
|
Publication => CPublication,
|
||||||
|
|
@ -120,7 +120,7 @@ object CoursierArtifactsTasks {
|
||||||
name,
|
name,
|
||||||
CType(artifact.`type`),
|
CType(artifact.`type`),
|
||||||
CExtension(artifact.extension),
|
CExtension(artifact.extension),
|
||||||
artifact.classifier.fold(Classifier(""))(Classifier(_))
|
artifact.classifier.fold(CClassifier(""))(CClassifier(_))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,20 @@ package sbt
|
||||||
package internal
|
package internal
|
||||||
package librarymanagement
|
package librarymanagement
|
||||||
|
|
||||||
|
import java.net.URL
|
||||||
import sbt.librarymanagement._
|
import sbt.librarymanagement._
|
||||||
import sbt.util.Logger
|
import sbt.util.Logger
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
import lmcoursier.definitions.{
|
import lmcoursier.definitions.{
|
||||||
Attributes => CAttributes,
|
Attributes => CAttributes,
|
||||||
Classifier,
|
Classifier => CClassifier,
|
||||||
Configuration => CConfiguration,
|
Configuration => CConfiguration,
|
||||||
Dependency => CDependency,
|
Dependency => CDependency,
|
||||||
// Extension => CExtension,
|
|
||||||
Info => CInfo,
|
Info => CInfo,
|
||||||
Module,
|
Module => CModule,
|
||||||
ModuleName,
|
ModuleName => CModuleName,
|
||||||
Organization => COrganization,
|
Organization => COrganization,
|
||||||
Project => CProject,
|
Project => CProject,
|
||||||
// Publication => CPublication,
|
|
||||||
Type => CType
|
Type => CType
|
||||||
}
|
}
|
||||||
import lmcoursier.credentials.DirectCredentials
|
import lmcoursier.credentials.DirectCredentials
|
||||||
|
|
@ -44,6 +43,7 @@ private[sbt] object CoursierInputsTasks {
|
||||||
configurations: Seq[sbt.librarymanagement.Configuration],
|
configurations: Seq[sbt.librarymanagement.Configuration],
|
||||||
sv: String,
|
sv: String,
|
||||||
sbv: String,
|
sbv: String,
|
||||||
|
auOpt: Option[URL],
|
||||||
log: Logger
|
log: Logger
|
||||||
): CProject = {
|
): CProject = {
|
||||||
|
|
||||||
|
|
@ -51,47 +51,45 @@ private[sbt] object CoursierInputsTasks {
|
||||||
|
|
||||||
val configMap = Inputs.configExtends(configurations)
|
val configMap = Inputs.configExtends(configurations)
|
||||||
|
|
||||||
val proj = FromSbt.project(
|
val proj0 = FromSbt.project(
|
||||||
projId,
|
projId,
|
||||||
dependencies,
|
dependencies,
|
||||||
configMap,
|
configMap,
|
||||||
sv,
|
sv,
|
||||||
sbv
|
sbv
|
||||||
)
|
)
|
||||||
|
val proj1 = proj0.copy(
|
||||||
proj.copy(
|
dependencies = proj0.dependencies.map {
|
||||||
dependencies = proj.dependencies.map {
|
|
||||||
case (config, dep) =>
|
case (config, dep) =>
|
||||||
(config, dep.copy(exclusions = dep.exclusions ++ exclusions0))
|
(config, dep.copy(exclusions = dep.exclusions ++ exclusions0))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
auOpt match {
|
||||||
|
case Some(au) =>
|
||||||
|
val props = proj1.properties :+ ("info.apiURL" -> au.toString)
|
||||||
|
proj1.copy(properties = props)
|
||||||
|
case _ => proj1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def coursierProjectTask: Def.Initialize[sbt.Task[CProject]] =
|
private[sbt] def coursierProjectTask: Def.Initialize[sbt.Task[CProject]] =
|
||||||
Def.task {
|
Def.task {
|
||||||
val auOpt = apiURL.value
|
coursierProject0(
|
||||||
val proj = coursierProject0(
|
|
||||||
projectID.value,
|
projectID.value,
|
||||||
allDependencies.value,
|
allDependencies.value,
|
||||||
allExcludeDependencies.value,
|
allExcludeDependencies.value,
|
||||||
// should projectID.configurations be used instead?
|
|
||||||
ivyConfigurations.value,
|
ivyConfigurations.value,
|
||||||
scalaVersion.value,
|
scalaVersion.value,
|
||||||
scalaBinaryVersion.value,
|
scalaBinaryVersion.value,
|
||||||
|
apiURL.value,
|
||||||
streams.value.log
|
streams.value.log
|
||||||
)
|
)
|
||||||
auOpt match {
|
|
||||||
case Some(au) =>
|
|
||||||
val props = proj.properties :+ ("info.apiURL" -> au.toString)
|
|
||||||
proj.copy(properties = props)
|
|
||||||
case _ => proj
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def moduleFromIvy(id: org.apache.ivy.core.module.id.ModuleRevisionId): Module =
|
private def moduleFromIvy(id: org.apache.ivy.core.module.id.ModuleRevisionId): CModule =
|
||||||
Module(
|
CModule(
|
||||||
COrganization(id.getOrganisation),
|
COrganization(id.getOrganisation),
|
||||||
ModuleName(id.getName),
|
CModuleName(id.getName),
|
||||||
id.getExtraAttributes.asScala.map {
|
id.getExtraAttributes.asScala.map {
|
||||||
case (k0, v0) => k0.asInstanceOf[String] -> v0.asInstanceOf[String]
|
case (k0, v0) => k0.asInstanceOf[String] -> v0.asInstanceOf[String]
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
@ -107,7 +105,7 @@ private[sbt] object CoursierInputsTasks {
|
||||||
// we're ignoring rule.getConfigurations and rule.getMatcher here
|
// we're ignoring rule.getConfigurations and rule.getMatcher here
|
||||||
val modId = rule.getId.getModuleId
|
val modId = rule.getId.getModuleId
|
||||||
// we're ignoring modId.getAttributes here
|
// we're ignoring modId.getAttributes here
|
||||||
(COrganization(modId.getOrganisation), ModuleName(modId.getName))
|
(COrganization(modId.getOrganisation), CModuleName(modId.getName))
|
||||||
}.toSet
|
}.toSet
|
||||||
|
|
||||||
val configurations = desc.getModuleConfigurations.toVector
|
val configurations = desc.getModuleConfigurations.toVector
|
||||||
|
|
@ -128,13 +126,13 @@ private[sbt] object CoursierInputsTasks {
|
||||||
val artifacts = desc.getAllDependencyArtifacts
|
val artifacts = desc.getAllDependencyArtifacts
|
||||||
|
|
||||||
val m = artifacts.toVector.flatMap { art =>
|
val m = artifacts.toVector.flatMap { art =>
|
||||||
val attr = CAttributes(CType(art.getType), Classifier(""))
|
val attr = CAttributes(CType(art.getType), CClassifier(""))
|
||||||
art.getConfigurations.map(CConfiguration(_)).toVector.map { conf =>
|
art.getConfigurations.map(CConfiguration(_)).toVector.map { conf =>
|
||||||
conf -> attr
|
conf -> attr
|
||||||
}
|
}
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
c => m.getOrElse(c, CAttributes(CType(""), Classifier("")))
|
c => m.getOrElse(c, CAttributes(CType(""), CClassifier("")))
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.map {
|
configurations.map {
|
||||||
|
|
@ -191,10 +189,9 @@ private[sbt] object CoursierInputsTasks {
|
||||||
private[sbt] def coursierFallbackDependenciesTask
|
private[sbt] def coursierFallbackDependenciesTask
|
||||||
: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
|
: Def.Initialize[sbt.Task[Seq[FallbackDependency]]] =
|
||||||
Def.taskDyn {
|
Def.taskDyn {
|
||||||
val state = sbt.Keys.state.value
|
val s = state.value
|
||||||
val projectRef = sbt.Keys.thisProjectRef.value
|
val projectRef = thisProjectRef.value
|
||||||
|
val projects = Project.transitiveInterDependencies(s, projectRef)
|
||||||
val projects = Project.transitiveInterDependencies(state, projectRef)
|
|
||||||
|
|
||||||
Def.task {
|
Def.task {
|
||||||
val allDeps =
|
val allDeps =
|
||||||
|
|
|
||||||
|
|
@ -120,9 +120,9 @@ private[sbt] object CoursierRepositoriesTasks {
|
||||||
|
|
||||||
def coursierRecursiveResolversTask: Def.Initialize[sbt.Task[Seq[Resolver]]] =
|
def coursierRecursiveResolversTask: Def.Initialize[sbt.Task[Seq[Resolver]]] =
|
||||||
Def.taskDyn {
|
Def.taskDyn {
|
||||||
val state = sbt.Keys.state.value
|
val s = state.value
|
||||||
val projectRef = sbt.Keys.thisProjectRef.value
|
val projectRef = thisProjectRef.value
|
||||||
val projects = Project.transitiveInterDependencies(state, projectRef)
|
val projects = Project.transitiveInterDependencies(s, projectRef)
|
||||||
Def.task {
|
Def.task {
|
||||||
csrResolvers.all(ScopeFilter(inProjects(projectRef +: projects: _*))).value.flatten
|
csrResolvers.all(ScopeFilter(inProjects(projectRef +: projects: _*))).value.flatten
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ object IvyXml {
|
||||||
|
|
||||||
val content0 = rawContent(currentProject, shadedConfigOpt)
|
val content0 = rawContent(currentProject, shadedConfigOpt)
|
||||||
cacheIvyFile.getParentFile.mkdirs()
|
cacheIvyFile.getParentFile.mkdirs()
|
||||||
log.info(s"Writing Ivy file $cacheIvyFile")
|
log.debug(s"writing Ivy file $cacheIvyFile")
|
||||||
Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8))
|
Files.write(cacheIvyFile.toPath, content0.getBytes(UTF_8))
|
||||||
|
|
||||||
// Just writing an empty file here... Are these only used?
|
// Just writing an empty file here... Are these only used?
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue