Merge pull request #76 from dwijnand/cross-version-suffix

Allow for some customization in CrossVersion results
This commit is contained in:
eugene yokota 2017-03-31 10:20:13 -07:00 committed by GitHub
commit fcaea6787f
7 changed files with 44 additions and 21 deletions

View File

@ -138,11 +138,16 @@
"namespace": "sbt.librarymanagement", "namespace": "sbt.librarymanagement",
"target": "Scala", "target": "Scala",
"doc": [ "doc": [
"Cross-versions a module using the result of applying `remapVersion` to the binary version.", "Cross-versions a module using the result of",
"For example, if `remapVersion = v => \"2.10\"` and the binary version is \"2.9.2\" or \"2.10\",", "prepending `prefix` and appending `suffix` to the binary version.",
"the module is cross-versioned with \"2.10\"." "For example, if `prefix = \"foo_\"` and `suffix = \"_bar\"` and the binary version is \"2.10\",",
"the module is cross-versioned with \"foo_2.10_bar\"."
], ],
"type": "record" "type": "record",
"fields": [
{ "name": "prefix", "type": "String", "default": "\"\"", "since": "0.0.1" },
{ "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" }
]
}, },
{ {
"name": "Patch", "name": "Patch",
@ -150,7 +155,7 @@
"target": "Scala", "target": "Scala",
"doc": [ "doc": [
"Cross-versions a module by stripping off -bin-suffix.", "Cross-versions a module by stripping off -bin-suffix.",
"This is intented for patch-version compatible alternative replacements." "This is intended for patch-version compatible alternative replacements."
], ],
"type": "record" "type": "record"
}, },
@ -160,9 +165,14 @@
"target": "Scala", "target": "Scala",
"type": "record", "type": "record",
"doc": [ "doc": [
"Cross-versions a module with the result of applying `remapVersion` to the full version.", "Cross-versions a module with the result of",
"For example, if `remapVersion = v => \"2.10\"` and the full version is \"2.9.2\" or \"2.10.3\",", "prepending `prefix` and appending `suffix` to the full version.",
"the module is cross-versioned with \"2.10\"." "For example, if `prefix = \"foo_\"` and `suffix = \"_bar\"` and the full version is \"2.12.1\",",
"the module is cross-versioned with \"foo_2.12.1_bar\"."
],
"fields": [
{ "name": "prefix", "type": "String", "default": "\"\"", "since": "0.0.1" },
{ "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" }
] ]
} }
], ],

View File

@ -21,7 +21,6 @@ import sbt.util.{ Logger, ShowLines }
import sbt.internal.util.{ SourcePosition, LinePosition, RangePosition, LineRange } import sbt.internal.util.{ SourcePosition, LinePosition, RangePosition, LineRange }
import sbt.librarymanagement._ import sbt.librarymanagement._
import sbt.internal.librarymanagement.syntax._ import sbt.internal.librarymanagement.syntax._
import sbt.internal.librarymanagement._
final class DeliverConfiguration(val deliverIvyPattern: String, val status: String, val configurations: Option[Vector[Configuration]], val logging: UpdateLogging) final class DeliverConfiguration(val deliverIvyPattern: String, val status: String, val configurations: Option[Vector[Configuration]], val logging: UpdateLogging)
final class PublishConfiguration(val ivyFile: Option[File], val resolverName: String, val artifacts: Map[Artifact, File], val checksums: Vector[String], val logging: UpdateLogging, final class PublishConfiguration(val ivyFile: Option[File], val resolverName: String, val artifacts: Map[Artifact, File], val checksums: Vector[String], val logging: UpdateLogging,

View File

@ -123,13 +123,13 @@ private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore)
} }
def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] = def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] =
{ {
import scala.collection.JavaConversions._ import scala.collection.JavaConverters._
(md0.getAllDependencyDescriptorMediators.getAllRules).toSeq.toVector sortBy { md0.getAllDependencyDescriptorMediators.getAllRules.asScala.toSeq.toVector sortBy {
case (k, v) => case (k, v) =>
k.toString k.toString
} collect { } collect {
case (k: MapMatcher, v: OverrideDependencyDescriptorMediator) => case (k: MapMatcher, v: OverrideDependencyDescriptorMediator) =>
val attr: Map[Any, Any] = k.getAttributes.toMap val attr: Map[Any, Any] = k.getAttributes.asScala.toMap
val module = IvyModuleId.newInstance(attr(IvyPatternHelper.ORGANISATION_KEY).toString, attr(IvyPatternHelper.MODULE_KEY).toString) val module = IvyModuleId.newInstance(attr(IvyPatternHelper.ORGANISATION_KEY).toString, attr(IvyPatternHelper.MODULE_KEY).toString)
val pm = k.getPatternMatcher val pm = k.getPatternMatcher
IvyOverride(module, pm, v) IvyOverride(module, pm, v)

View File

@ -58,12 +58,12 @@ object Credentials {
private[this] val UserKeys = List("user", "user.name", "username") private[this] val UserKeys = List("user", "user.name", "username")
private[this] val PasswordKeys = List("password", "pwd", "pass", "passwd") private[this] val PasswordKeys = List("password", "pwd", "pass", "passwd")
import collection.JavaConversions._ import collection.JavaConverters._
private[this] def read(from: File): Map[String, String] = private[this] def read(from: File): Map[String, String] =
{ {
val properties = new java.util.Properties val properties = new java.util.Properties
IO.load(properties, from) IO.load(properties, from)
properties.map { case (k, v) => (k.toString, v.toString.trim) }.toMap properties.asScala.map { case (k, v) => (k.toString, v.toString.trim) }.toMap
} }
} }

View File

@ -15,9 +15,21 @@ abstract class CrossVersionFunctions {
/** Cross-versions a module with the full version (typically the full Scala version). */ /** Cross-versions a module with the full version (typically the full Scala version). */
def full: CrossVersion = Full() def full: CrossVersion = Full()
/**
* Cross-versions a module with the result of prepending `prefix` and appending `suffix` to the full version.
* (typically the full Scala version). See also [[sbt.librarymanagement.Full]]
*/
def fullWith(prefix: String, suffix: String): CrossVersion = Full(prefix, suffix)
/** Cross-versions a module with the binary version (typically the binary Scala version). */ /** Cross-versions a module with the binary version (typically the binary Scala version). */
def binary: CrossVersion = Binary() def binary: CrossVersion = Binary()
/**
* Cross-versions a module with the result of prepending `prefix` and appending `suffix` to the binary version
* (typically the binary Scala version). See also [[sbt.librarymanagement.Binary]].
*/
def binaryWith(prefix: String, suffix: String): CrossVersion = Binary(prefix, suffix)
/** /**
* Cross-versions a module with the full Scala version excluding any `-bin` suffix. * Cross-versions a module with the full Scala version excluding any `-bin` suffix.
*/ */
@ -41,9 +53,9 @@ abstract class CrossVersionFunctions {
def apply(cross: CrossVersion, fullVersion: String, binaryVersion: String): Option[String => String] = def apply(cross: CrossVersion, fullVersion: String, binaryVersion: String): Option[String => String] =
cross match { cross match {
case _: Disabled => None case _: Disabled => None
case _: Binary => append(binaryVersion) case b: Binary => append(b.prefix + binaryVersion + b.suffix)
case _: Patch => append(patchFun(fullVersion)) case _: Patch => append(patchFun(fullVersion))
case _: Full => append(fullVersion) case f: Full => append(f.prefix + fullVersion + f.suffix)
} }
/** Constructs the cross-version function defined by `module` and `is`, if one is configured. */ /** Constructs the cross-version function defined by `module` and `is`, if one is configured. */

View File

@ -2,7 +2,6 @@ package sbt
package librarymanagement package librarymanagement
import java.io.File import java.io.File
import scala.util.Try
import sbt.internal.librarymanagement._ import sbt.internal.librarymanagement._
import sbt.util.Logger import sbt.util.Logger
import sbt.io.Hash import sbt.io.Hash
@ -61,7 +60,7 @@ class DefaultLibraryManagement(ivyConfiguration: IvyConfiguration, log: Logger)
log.debug(s"Attempting to fetch ${dependenciesNames(module)}. This operation may fail.") log.debug(s"Attempting to fetch ${dependenciesNames(module)}. This operation may fail.")
IvyActions.updateEither(module, updateConfiguration, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) match { IvyActions.updateEither(module, updateConfiguration, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) match {
case Left(unresolvedWarning) => case Left(unresolvedWarning) =>
log.debug("Couldn't retrieve module ${dependenciesNames(module)}.") log.debug(s"Couldn't retrieve module ${dependenciesNames(module)}.")
None None
case Right(updateReport) => case Right(updateReport) =>

View File

@ -6,6 +6,7 @@ import java.io.File
import sbt.internal._, librarymanagement._, util.UnitSpec import sbt.internal._, librarymanagement._, util.UnitSpec
import scala.json.ast.unsafe._ import scala.json.ast.unsafe._
import sjsonnew._, support.scalajson.unsafe._ import sjsonnew._, support.scalajson.unsafe._
import org.scalatest.Assertion
import LibraryManagementCodec._ import LibraryManagementCodec._
@ -61,11 +62,13 @@ class DMSerializationSpec extends UnitSpec {
lazy val moduleReportExample = lazy val moduleReportExample =
ModuleReport(ModuleID("org", "name", "1.0"), Vector.empty, Vector.empty) ModuleReport(ModuleID("org", "name", "1.0"), Vector.empty, Vector.empty)
def roundtrip[A: JsonReader: JsonWriter](a: A): Unit = def roundtrip[A: JsonReader: JsonWriter](a: A): Assertion =
roundtripBuilder(a) { _ shouldBe _ } roundtripBuilder(a) { _ shouldBe _ }
def roundtripStr[A: JsonReader: JsonWriter](a: A): Unit =
def roundtripStr[A: JsonReader: JsonWriter](a: A): Assertion =
roundtripBuilder(a) { _.toString shouldBe _.toString } roundtripBuilder(a) { _.toString shouldBe _.toString }
def roundtripBuilder[A: JsonReader: JsonWriter](a: A)(f: (A, A) => Unit): Unit =
def roundtripBuilder[A: JsonReader: JsonWriter](a: A)(f: (A, A) => Assertion): Assertion =
{ {
val json = isoString to (Converter toJsonUnsafe a) val json = isoString to (Converter toJsonUnsafe a)
println(json) println(json)