From 92cc7c4cb1a648c7830d9a63da8957dff9c7fc1c Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 31 Mar 2017 10:10:37 +0100 Subject: [PATCH 1/3] Remove some compile warnings --- .../sbt/internal/librarymanagement/IvyActions.scala | 1 - .../ivyint/CachedResolutionResolveEngine.scala | 6 +++--- .../main/scala/sbt/librarymanagement/Credentials.scala | 4 ++-- .../sbt/librarymanagement/DefaultLibraryManagement.scala | 3 +-- .../src/test/scala/DMSerializationSpec.scala | 9 ++++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/IvyActions.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/IvyActions.scala index 2157f9113..0230b5791 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/IvyActions.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/IvyActions.scala @@ -21,7 +21,6 @@ import sbt.util.{ Logger, ShowLines } import sbt.internal.util.{ SourcePosition, LinePosition, RangePosition, LineRange } import sbt.librarymanagement._ 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 PublishConfiguration(val ivyFile: Option[File], val resolverName: String, val artifacts: Map[Artifact, File], val checksums: Vector[String], val logging: UpdateLogging, diff --git a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala index 7dcc35d65..ddff21597 100644 --- a/librarymanagement/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala +++ b/librarymanagement/src/main/scala/sbt/internal/librarymanagement/ivyint/CachedResolutionResolveEngine.scala @@ -123,13 +123,13 @@ private[sbt] class CachedResolutionResolveCache(fileToStore: File => CacheStore) } def extractOverrides(md0: ModuleDescriptor): Vector[IvyOverride] = { - import scala.collection.JavaConversions._ - (md0.getAllDependencyDescriptorMediators.getAllRules).toSeq.toVector sortBy { + import scala.collection.JavaConverters._ + md0.getAllDependencyDescriptorMediators.getAllRules.asScala.toSeq.toVector sortBy { case (k, v) => k.toString } collect { 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 pm = k.getPatternMatcher IvyOverride(module, pm, v) diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/Credentials.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/Credentials.scala index 3f075f2b7..55dffa367 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/Credentials.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/Credentials.scala @@ -58,12 +58,12 @@ object Credentials { private[this] val UserKeys = List("user", "user.name", "username") private[this] val PasswordKeys = List("password", "pwd", "pass", "passwd") - import collection.JavaConversions._ + import collection.JavaConverters._ private[this] def read(from: File): Map[String, String] = { val properties = new java.util.Properties 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 } } diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/DefaultLibraryManagement.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/DefaultLibraryManagement.scala index 127084e30..01a87378b 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/DefaultLibraryManagement.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/DefaultLibraryManagement.scala @@ -2,7 +2,6 @@ package sbt package librarymanagement import java.io.File -import scala.util.Try import sbt.internal.librarymanagement._ import sbt.util.Logger 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.") IvyActions.updateEither(module, updateConfiguration, UnresolvedWarningConfiguration(), LogicalClock.unknown, None, log) match { case Left(unresolvedWarning) => - log.debug("Couldn't retrieve module ${dependenciesNames(module)}.") + log.debug(s"Couldn't retrieve module ${dependenciesNames(module)}.") None case Right(updateReport) => diff --git a/librarymanagement/src/test/scala/DMSerializationSpec.scala b/librarymanagement/src/test/scala/DMSerializationSpec.scala index bbbeef4f8..5c6a89db7 100644 --- a/librarymanagement/src/test/scala/DMSerializationSpec.scala +++ b/librarymanagement/src/test/scala/DMSerializationSpec.scala @@ -6,6 +6,7 @@ import java.io.File import sbt.internal._, librarymanagement._, util.UnitSpec import scala.json.ast.unsafe._ import sjsonnew._, support.scalajson.unsafe._ +import org.scalatest.Assertion import LibraryManagementCodec._ @@ -61,11 +62,13 @@ class DMSerializationSpec extends UnitSpec { lazy val moduleReportExample = 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 _ } - def roundtripStr[A: JsonReader: JsonWriter](a: A): Unit = + + def roundtripStr[A: JsonReader: JsonWriter](a: A): Assertion = 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) println(json) From 87e8d878114ea4c6e1b7da4851ea67f03b11ed7c Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 31 Mar 2017 10:24:16 +0100 Subject: [PATCH 2/3] Allow for some customization in CrossVersion results The old way to customize CrossVersion results was a `String => String` function called 'remapVersion', removed in 301ec787f2f17367064cda5eef3a9009ba66e21f. That was removed because it's not possible to serialise Function1s, and we want to serialise CrossVersion (and therefore ModuleID, etc) to be able to transfer them in sbt server. This commit reintroduces a less-powerful way to vary the results of apply CrossVersion, but just providing the opportunity to define a suffix. From looking at the users of CrossVersion (Scala.js' sbt-scalajs-plugin & Scala Native's sbt-crossproject) this looks to be sufficient. --- .../main/contraband/librarymanagement.json | 20 ++++++++++--------- .../librarymanagement/CrossVersionExtra.scala | 16 +++++++++++++-- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/librarymanagement/src/main/contraband/librarymanagement.json b/librarymanagement/src/main/contraband/librarymanagement.json index 6497a557f..34d1c8e63 100644 --- a/librarymanagement/src/main/contraband/librarymanagement.json +++ b/librarymanagement/src/main/contraband/librarymanagement.json @@ -138,11 +138,12 @@ "namespace": "sbt.librarymanagement", "target": "Scala", "doc": [ - "Cross-versions a module using the result of applying `remapVersion` to the binary version.", - "For example, if `remapVersion = v => \"2.10\"` and the binary version is \"2.9.2\" or \"2.10\",", - "the module is cross-versioned with \"2.10\"." + "Cross-versions a module using the result of appending `suffix` to the binary version.", + "For example, if `suffix = \"_foo\"` and the binary version is \"2.10\",", + "the module is cross-versioned with \"2.10_foo\"." ], - "type": "record" + "type": "record", + "fields": [ { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } ] }, { "name": "Patch", @@ -150,7 +151,7 @@ "target": "Scala", "doc": [ "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" }, @@ -160,10 +161,11 @@ "target": "Scala", "type": "record", "doc": [ - "Cross-versions a module with the result of applying `remapVersion` to the full version.", - "For example, if `remapVersion = v => \"2.10\"` and the full version is \"2.9.2\" or \"2.10.3\",", - "the module is cross-versioned with \"2.10\"." - ] + "Cross-versions a module with the result of appending `suffix` to the full version.", + "For example, if `suffix = \"_foo\"` and the full version is \"2.12.1\",", + "the module is cross-versioned with \"2.12.1_foo\"." + ], + "fields": [ { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } ] } ], "parentsCompanion": "sbt.librarymanagement.CrossVersionFunctions" diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index d8d63b7a8..d9227b841 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -15,9 +15,21 @@ abstract class CrossVersionFunctions { /** Cross-versions a module with the full version (typically the full Scala version). */ def full: CrossVersion = Full() + /** + * Cross-versions a module with the result of appending `suffix` to the full version. + * (typically the full Scala version). See also [[sbt.librarymanagement.Full]] + */ + def fullSuffixed(suffix: String): CrossVersion = Full(suffix) + /** Cross-versions a module with the binary version (typically the binary Scala version). */ def binary: CrossVersion = Binary() + /** + * Cross-versions a module with the result of appending `suffix` to the binary version + * (typically the binary Scala version). See also [[sbt.librarymanagement.Binary]]. + */ + def binarySuffixed(suffix: String): CrossVersion = Binary(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] = cross match { case _: Disabled => None - case _: Binary => append(binaryVersion) + case b: Binary => append(binaryVersion + b.suffix) case _: Patch => append(patchFun(fullVersion)) - case _: Full => append(fullVersion) + case f: Full => append(fullVersion + f.suffix) } /** Constructs the cross-version function defined by `module` and `is`, if one is configured. */ From fb049d181b4a30a10ab11e67aa06411cad0db74b Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 31 Mar 2017 10:47:35 +0100 Subject: [PATCH 3/3] Add prefix support to Binary/Full --- .../main/contraband/librarymanagement.json | 24 ++++++++++++------- .../librarymanagement/CrossVersionExtra.scala | 12 +++++----- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/librarymanagement/src/main/contraband/librarymanagement.json b/librarymanagement/src/main/contraband/librarymanagement.json index 34d1c8e63..2880c89e1 100644 --- a/librarymanagement/src/main/contraband/librarymanagement.json +++ b/librarymanagement/src/main/contraband/librarymanagement.json @@ -138,12 +138,16 @@ "namespace": "sbt.librarymanagement", "target": "Scala", "doc": [ - "Cross-versions a module using the result of appending `suffix` to the binary version.", - "For example, if `suffix = \"_foo\"` and the binary version is \"2.10\",", - "the module is cross-versioned with \"2.10_foo\"." + "Cross-versions a module using the result of", + "prepending `prefix` and appending `suffix` to the binary version.", + "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", - "fields": [ { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } ] + "fields": [ + { "name": "prefix", "type": "String", "default": "\"\"", "since": "0.0.1" }, + { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } + ] }, { "name": "Patch", @@ -161,11 +165,15 @@ "target": "Scala", "type": "record", "doc": [ - "Cross-versions a module with the result of appending `suffix` to the full version.", - "For example, if `suffix = \"_foo\"` and the full version is \"2.12.1\",", - "the module is cross-versioned with \"2.12.1_foo\"." + "Cross-versions a module with the result of", + "prepending `prefix` and appending `suffix` to the full version.", + "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": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } ] + "fields": [ + { "name": "prefix", "type": "String", "default": "\"\"", "since": "0.0.1" }, + { "name": "suffix", "type": "String", "default": "\"\"", "since": "0.0.1" } + ] } ], "parentsCompanion": "sbt.librarymanagement.CrossVersionFunctions" diff --git a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala index d9227b841..e4d172b7a 100644 --- a/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala +++ b/librarymanagement/src/main/scala/sbt/librarymanagement/CrossVersionExtra.scala @@ -16,19 +16,19 @@ abstract class CrossVersionFunctions { def full: CrossVersion = Full() /** - * Cross-versions a module with the result of appending `suffix` to the full version. + * 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 fullSuffixed(suffix: String): CrossVersion = Full(suffix) + def fullWith(prefix: String, suffix: String): CrossVersion = Full(prefix, suffix) /** Cross-versions a module with the binary version (typically the binary Scala version). */ def binary: CrossVersion = Binary() /** - * Cross-versions a module with the result of appending `suffix` to the binary version + * 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 binarySuffixed(suffix: String): CrossVersion = Binary(suffix) + def binaryWith(prefix: String, suffix: String): CrossVersion = Binary(prefix, suffix) /** * Cross-versions a module with the full Scala version excluding any `-bin` suffix. @@ -53,9 +53,9 @@ abstract class CrossVersionFunctions { def apply(cross: CrossVersion, fullVersion: String, binaryVersion: String): Option[String => String] = cross match { case _: Disabled => None - case b: Binary => append(binaryVersion + b.suffix) + case b: Binary => append(b.prefix + binaryVersion + b.suffix) case _: Patch => append(patchFun(fullVersion)) - case f: Full => append(fullVersion + f.suffix) + case f: Full => append(f.prefix + fullVersion + f.suffix) } /** Constructs the cross-version function defined by `module` and `is`, if one is configured. */