mirror of https://github.com/sbt/sbt.git
Merge pull request #213 from alexarchambault/topic/fix-version-property
Basic property substitution in version in POMs
This commit is contained in:
commit
0f0c245c77
|
|
@ -322,21 +322,7 @@ object Resolution {
|
|||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dependencies of `project`, knowing that it came from dependency
|
||||
* `from` (that is, `from.module == project.module`).
|
||||
*
|
||||
* Substitute properties, update scopes, apply exclusions, and get extra
|
||||
* parameters from dependency management along the way.
|
||||
*/
|
||||
def finalDependencies(
|
||||
from: Dependency,
|
||||
project: Project
|
||||
): Seq[Dependency] = {
|
||||
|
||||
// Here, we're substituting properties also in dependencies that
|
||||
// come from parents or dependency management. This may not be
|
||||
// the right thing to do.
|
||||
def projectProperties(project: Project): Seq[(String, String)] = {
|
||||
|
||||
// FIXME The extra properties should only be added for Maven projects, not Ivy ones
|
||||
val properties0 = Seq(
|
||||
|
|
@ -358,7 +344,39 @@ object Resolution {
|
|||
)
|
||||
}
|
||||
|
||||
val properties = propertiesMap(properties0)
|
||||
// loose attempt at substituting properties in each others in properties0
|
||||
// doesn't try to go recursive for now, but that could be made so if necessary
|
||||
|
||||
val (done, remaining) = properties0.partition {
|
||||
case (_, value) =>
|
||||
propRegex.findFirstIn(value).isEmpty
|
||||
}
|
||||
|
||||
lazy val doneMap = done.toMap
|
||||
|
||||
done ++ remaining.map {
|
||||
case (k, v) =>
|
||||
k -> substituteProps(v, doneMap)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dependencies of `project`, knowing that it came from dependency
|
||||
* `from` (that is, `from.module == project.module`).
|
||||
*
|
||||
* Substitute properties, update scopes, apply exclusions, and get extra
|
||||
* parameters from dependency management along the way.
|
||||
*/
|
||||
def finalDependencies(
|
||||
from: Dependency,
|
||||
project: Project
|
||||
): Seq[Dependency] = {
|
||||
|
||||
// Here, we're substituting properties also in dependencies that
|
||||
// come from parents or dependency management. This may not be
|
||||
// the right thing to do.
|
||||
|
||||
val properties = propertiesMap(projectProperties(project))
|
||||
|
||||
val (actualConfig, configurations) = withParentConfigurations(from.configuration, project.configurations)
|
||||
|
||||
|
|
@ -690,11 +708,7 @@ final case class Resolution(
|
|||
.map(_._2.properties)
|
||||
.fold(project.properties)(project.properties ++ _)
|
||||
|
||||
val approxProperties = propertiesMap(approxProperties0) ++ Seq(
|
||||
"project.groupId" -> project.module.organization,
|
||||
"project.artifactId" -> project.module.name,
|
||||
"project.version" -> project.version
|
||||
)
|
||||
val approxProperties = propertiesMap(approxProperties0) ++ projectProperties(project)
|
||||
|
||||
val profileDependencies =
|
||||
profiles(
|
||||
|
|
@ -775,11 +789,7 @@ final case class Resolution(
|
|||
.map(projectCache(_)._2.properties.toMap)
|
||||
.fold(project.properties)(project.properties ++ _)
|
||||
|
||||
val approxProperties = propertiesMap(approxProperties0) ++ Seq(
|
||||
"project.groupId" -> project.module.organization,
|
||||
"project.artifactId" -> project.module.name,
|
||||
"project.version" -> project.version
|
||||
)
|
||||
val approxProperties = propertiesMap(approxProperties0) ++ projectProperties(project)
|
||||
|
||||
val profiles0 = profiles(
|
||||
project,
|
||||
|
|
@ -827,6 +837,7 @@ final case class Resolution(
|
|||
val depsSet = deps.toSet
|
||||
|
||||
project.copy(
|
||||
version = substituteProps(project.version, approxProperties),
|
||||
dependencies =
|
||||
dependencies0
|
||||
.filterNot{case (config, dep) =>
|
||||
|
|
|
|||
|
|
@ -149,12 +149,20 @@ case class MavenSource(
|
|||
}
|
||||
|
||||
object MavenSource {
|
||||
|
||||
val typeExtensions: Map[String, String] = Map(
|
||||
"eclipse-plugin" -> "jar",
|
||||
"maven-plugin" -> "jar",
|
||||
"hk2-jar" -> "jar",
|
||||
"orbit" -> "jar",
|
||||
"scala-jar" -> "jar",
|
||||
"jar" -> "jar",
|
||||
"bundle" -> "jar",
|
||||
"doc" -> "jar",
|
||||
"src" -> "jar"
|
||||
)
|
||||
|
||||
def typeExtension(`type`: String): String =
|
||||
`type` match {
|
||||
// see similar things in sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala in SBT 0.13.8
|
||||
case "eclipse-plugin" | "hk2-jar" | "orbit" | "scala-jar" | "jar" | "bundle" | "doc" | "src" => "jar"
|
||||
case other => other
|
||||
}
|
||||
typeExtensions.getOrElse(`type`, `type`)
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
com.nativelibs4java:jnaerator-runtime:0.12:compile
|
||||
com.nativelibs4java:ochafik-util:0.12:compile
|
||||
net.java.dev.jna:jna:4.1.0:compile
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
org.bytedeco:javacpp:1.1:compile
|
||||
org.bytedeco.javacpp-presets:opencv:3.0.0-1.1:compile
|
||||
|
|
@ -105,7 +105,8 @@ object CentralTests extends TestSuite {
|
|||
}
|
||||
|
||||
val tests = TestSuite {
|
||||
'logback{
|
||||
|
||||
'logback - {
|
||||
async {
|
||||
val dep = Dependency(Module("ch.qos.logback", "logback-classic"), "1.1.3")
|
||||
val res = await(resolve(Set(dep))).clearCaches
|
||||
|
|
@ -120,7 +121,8 @@ object CentralTests extends TestSuite {
|
|||
assert(res == expected)
|
||||
}
|
||||
}
|
||||
'asm{
|
||||
|
||||
'asm - {
|
||||
async {
|
||||
val dep = Dependency(Module("org.ow2.asm", "asm-commons"), "5.0.2")
|
||||
val res = await(resolve(Set(dep))).clearCaches
|
||||
|
|
@ -135,7 +137,8 @@ object CentralTests extends TestSuite {
|
|||
assert(res == expected)
|
||||
}
|
||||
}
|
||||
'jodaVersionInterval{
|
||||
|
||||
'jodaVersionInterval - {
|
||||
async {
|
||||
val dep = Dependency(Module("joda-time", "joda-time"), "[2.2,2.8]")
|
||||
val res0 = await(resolve(Set(dep)))
|
||||
|
|
@ -153,19 +156,22 @@ object CentralTests extends TestSuite {
|
|||
assert(proj.version == "2.8")
|
||||
}
|
||||
}
|
||||
'spark{
|
||||
|
||||
'spark - {
|
||||
resolutionCheck(
|
||||
Module("org.apache.spark", "spark-core_2.11"),
|
||||
"1.3.1"
|
||||
)
|
||||
}
|
||||
'argonautShapeless{
|
||||
|
||||
'argonautShapeless - {
|
||||
resolutionCheck(
|
||||
Module("com.github.alexarchambault", "argonaut-shapeless_6.1_2.11"),
|
||||
"0.2.0"
|
||||
)
|
||||
}
|
||||
'snapshotMetadata{
|
||||
|
||||
'snapshotMetadata - {
|
||||
// Let's hope this one won't change too much
|
||||
resolutionCheck(
|
||||
Module("com.github.fommil", "java-logging"),
|
||||
|
|
@ -174,12 +180,29 @@ object CentralTests extends TestSuite {
|
|||
extraRepo = Some(MavenRepository("https://oss.sonatype.org/content/repositories/public/"))
|
||||
)
|
||||
}
|
||||
|
||||
'versionProperty - {
|
||||
// nasty one - in its POM, its version contains "${parent.project.version}"
|
||||
resolutionCheck(
|
||||
Module("org.bytedeco.javacpp-presets", "opencv"),
|
||||
"3.0.0-1.1"
|
||||
)
|
||||
}
|
||||
|
||||
'parentProjectProperties - {
|
||||
resolutionCheck(
|
||||
Module("com.github.fommil.netlib", "all"),
|
||||
"1.1.2"
|
||||
)
|
||||
}
|
||||
|
||||
'parentDependencyManagementProperties - {
|
||||
resolutionCheck(
|
||||
Module("com.nativelibs4java", "jnaerator-runtime"),
|
||||
"0.12"
|
||||
)
|
||||
}
|
||||
|
||||
'latestRevision - {
|
||||
* - resolutionCheck(
|
||||
Module("com.chuusai", "shapeless_2.11"),
|
||||
|
|
@ -201,6 +224,7 @@ object CentralTests extends TestSuite {
|
|||
"7.0.+"
|
||||
)
|
||||
}
|
||||
|
||||
'mavenScopes - {
|
||||
def check(config: String) = resolutionCheck(
|
||||
Module("com.android.tools", "sdklib"),
|
||||
|
|
@ -213,7 +237,7 @@ object CentralTests extends TestSuite {
|
|||
}
|
||||
|
||||
'packaging - {
|
||||
* - {
|
||||
'aar - {
|
||||
// random aar-based module found on Central
|
||||
ensureArtifactHasExtension(
|
||||
Module("com.yandex.android", "speechkit"),
|
||||
|
|
@ -222,7 +246,7 @@ object CentralTests extends TestSuite {
|
|||
)
|
||||
}
|
||||
|
||||
* - {
|
||||
'bundle - {
|
||||
// has packaging bundle - ensuring coursier gives its artifact the .jar extension
|
||||
ensureArtifactHasExtension(
|
||||
Module("com.google.guava", "guava"),
|
||||
|
|
@ -230,6 +254,15 @@ object CentralTests extends TestSuite {
|
|||
"jar"
|
||||
)
|
||||
}
|
||||
|
||||
'mavenPlugin - {
|
||||
// has packaging maven-plugin - ensuring coursier gives its artifact the .jar extension
|
||||
ensureArtifactHasExtension(
|
||||
Module("org.bytedeco", "javacpp"),
|
||||
"1.1",
|
||||
"jar"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue